@gearbox-protocol/sdk 16.1.2 → 16.3.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/history/assembleOperations.js +3 -3
- package/dist/cjs/history/classifyMulticallOperations.js +7 -7
- package/dist/cjs/history/index.js +13 -0
- package/dist/cjs/history/parseCreditAccountTransaction.js +5 -5
- package/dist/cjs/{preview → history}/trace/errors.js +1 -1
- package/dist/cjs/{preview → history}/trace/extractAdapterCallTraces.js +1 -1
- package/dist/cjs/{preview → history}/trace/extractTransfers.js +3 -3
- package/dist/cjs/{preview → history}/trace/findFacadeCalls.js +3 -3
- package/dist/cjs/history/trace/index.js +14 -0
- package/dist/cjs/model/errors/index.js +37 -0
- package/dist/cjs/model/errors/liquidation-errors.js +32 -0
- package/dist/cjs/model/errors/operation-errors.js +135 -0
- package/dist/cjs/{onchain/market/oracle/errors.js → model/errors/oracle-errors.js} +1 -1
- package/dist/cjs/model/errors/prepare-errors.js +108 -0
- package/dist/cjs/model/errors/preview-errors.js +12 -0
- package/dist/cjs/model/index.js +40 -2
- package/dist/cjs/model/positions.js +1 -1
- package/dist/cjs/model/result.js +0 -8
- package/dist/cjs/model/rwa.js +40 -0
- package/dist/cjs/onchain/accounts/CreditAccountsServiceV310.js +2 -2
- package/dist/cjs/onchain/accounts/index.js +0 -2
- package/dist/cjs/onchain/accounts/intents/guards.js +42 -66
- package/dist/cjs/onchain/accounts/intents/index.js +38 -35
- package/dist/cjs/onchain/accounts/intents/leverage-band.js +1 -1
- package/dist/cjs/onchain/accounts/intents/math.js +19 -15
- package/dist/cjs/onchain/accounts/intents/open-strategy.js +44 -8
- package/dist/cjs/onchain/accounts/intents/plan.js +52 -48
- package/dist/cjs/onchain/accounts/intents/realize.js +26 -24
- package/dist/cjs/onchain/accounts/intents/tail.js +15 -12
- package/dist/cjs/onchain/accounts/intents/testing/sdk-mock.js +7 -0
- package/dist/cjs/onchain/accounts/intents/tests/finish-withdraw.fixtures.js +6 -6
- package/dist/cjs/onchain/accounts/intents/tests/withdraw.fixtures.js +12 -12
- package/dist/cjs/onchain/accounts/intents/view.js +1 -1
- package/dist/cjs/onchain/accounts/withdrawal-compressor/index.js +0 -1
- package/dist/cjs/onchain/index.js +122 -36
- package/dist/cjs/onchain/market/MarketSuite.js +7 -1
- package/dist/cjs/onchain/market/adapters/index.js +1 -0
- package/dist/cjs/onchain/market/credit/CreditSuite.js +47 -15
- package/dist/cjs/onchain/market/index.js +0 -6
- package/dist/cjs/onchain/market/oracle/PriceOracleBaseContract.js +6 -6
- package/dist/cjs/onchain/market/oracle/index.js +0 -2
- package/dist/cjs/onchain/market/pool/PoolQuotaKeeperV310Contract.js +8 -0
- package/dist/cjs/onchain/market/rwa/RWARegistry.js +3 -2
- package/dist/cjs/onchain/market/rwa/index.js +0 -4
- package/dist/cjs/onchain/market/rwa/securitize/SecuritizeRWAFactory.js +7 -7
- package/dist/cjs/onchain/market/rwa/securitize/constants.js +0 -2
- package/dist/cjs/onchain/market/rwa/securitize/index.js +1 -3
- package/dist/cjs/onchain/market/rwa/securitize/types.js +0 -29
- package/dist/cjs/onchain/market/rwa/types.js +0 -7
- package/dist/cjs/onchain/market/zapper/index.js +0 -1
- package/dist/cjs/onchain/pools/PoolService.js +10 -16
- package/dist/cjs/onchain/preview/index.js +41 -0
- package/dist/cjs/{preview → onchain/preview}/parse/classifyInnerOperations.js +2 -3
- package/dist/cjs/onchain/preview/parse/index.js +14 -0
- package/dist/cjs/{preview → onchain/preview}/parse/parseFacadeOperationCalldata.js +3 -3
- package/dist/cjs/{preview → onchain/preview}/parse/parseOperationCalldata.js +16 -17
- package/dist/cjs/{preview → onchain/preview}/parse/parsePoolOperationCalldata.js +3 -3
- package/dist/cjs/{preview → onchain/preview}/parse/parseRWAFactoryOperationCalldata.js +11 -12
- package/dist/cjs/{preview → onchain/preview}/parse/types.js +1 -1
- package/dist/cjs/{preview → onchain/preview}/preview/CreditAccountState.js +3 -4
- package/dist/cjs/{preview → onchain/preview}/preview/buildDelayedStrategyPositionOperationPreview.js +10 -11
- package/dist/cjs/{preview → onchain/preview}/preview/detectCloseOrRepay.js +2 -3
- package/dist/cjs/{preview → onchain/preview}/preview/detectDelayedClaim.js +4 -5
- package/dist/cjs/{preview → onchain/preview}/preview/detectDelayedOperation.js +5 -6
- package/dist/cjs/{preview → onchain/preview}/preview/estimateClaimableAt.js +1 -1
- package/dist/cjs/onchain/preview/preview/index.js +26 -0
- package/dist/cjs/{preview → onchain/preview}/preview/previewAdjustStrategyPosition.js +18 -22
- package/dist/cjs/{preview → onchain/preview}/preview/previewExitOrRepayStrategyPosition.js +22 -28
- package/dist/cjs/onchain/preview/preview/previewOpenStrategyPosition.js +60 -0
- package/dist/cjs/onchain/preview/preview/previewOperation.js +119 -0
- package/dist/cjs/{preview/simulate/simulatePoolOperation.js → onchain/preview/preview/previewPoolPositionOperation.js} +46 -32
- package/dist/cjs/onchain/preview/preview/replayInnerOperations.js +109 -0
- package/dist/cjs/onchain/preview/preview/replayMulticall.js +22 -0
- package/dist/cjs/{preview → onchain/preview}/preview/unwrapNativeCollateral.js +11 -14
- package/dist/cjs/onchain/validation/bundles/checkAccountQuotas.js +20 -0
- package/dist/cjs/onchain/validation/bundles/checkCollateralFunding.js +59 -0
- package/dist/cjs/onchain/validation/bundles/checkCreditOperation.js +65 -0
- package/dist/cjs/onchain/validation/bundles/checkDraw.js +28 -0
- package/dist/cjs/onchain/validation/bundles/checkHealthFactors.js +27 -0
- package/dist/cjs/onchain/validation/bundles/checkLiquidationEligibility.js +33 -0
- package/dist/cjs/onchain/validation/bundles/checkLiquidationFunding.js +29 -0
- package/dist/cjs/onchain/validation/bundles/checkMarket.js +24 -0
- package/dist/cjs/onchain/validation/bundles/checkObtained.js +13 -0
- package/dist/cjs/onchain/validation/bundles/checkPoolFunding.js +22 -0
- package/dist/cjs/onchain/validation/bundles/checkPoolOperation.js +35 -0
- package/dist/cjs/onchain/validation/bundles/checkQuotasAsked.js +20 -0
- package/dist/cjs/onchain/validation/bundles/checkRWAOpenRequirements.js +33 -0
- package/dist/cjs/onchain/validation/bundles/checkRWAOpening.js +24 -0
- package/dist/cjs/onchain/validation/bundles/checkWallet.js +22 -0
- package/dist/cjs/onchain/validation/bundles/checkWalletAllowance.js +32 -0
- package/dist/cjs/onchain/validation/bundles/checkWalletBalance.js +41 -0
- package/dist/cjs/onchain/validation/bundles/index.js +35 -0
- package/dist/cjs/onchain/validation/checkLiquidation.js +22 -0
- package/dist/cjs/onchain/validation/checkOperation.js +62 -0
- package/dist/cjs/onchain/validation/checkSimulation.js +60 -0
- package/dist/cjs/onchain/validation/checks/checkBorrowLimit.js +25 -0
- package/dist/cjs/onchain/validation/checks/checkCollateralised.js +26 -0
- package/dist/cjs/onchain/validation/checks/checkCreditAccountFrozen.js +10 -0
- package/dist/cjs/onchain/validation/checks/checkCreditManagerPaused.js +10 -0
- package/dist/cjs/onchain/validation/checks/checkDebtLimits.js +18 -0
- package/dist/cjs/onchain/validation/checks/checkEmergencyLiquidator.js +13 -0
- package/dist/cjs/onchain/validation/checks/checkForbiddenToken.js +10 -0
- package/dist/cjs/onchain/validation/checks/checkLeverage.js +13 -0
- package/dist/cjs/onchain/validation/checks/checkLiquidatorEligible.js +10 -0
- package/dist/cjs/onchain/validation/checks/checkMarketExpired.js +10 -0
- package/dist/cjs/onchain/validation/checks/checkPoolLiquidity.js +25 -0
- package/dist/cjs/onchain/validation/checks/checkPoolPaused.js +10 -0
- package/dist/cjs/onchain/validation/checks/checkPoolSunset.js +10 -0
- package/dist/cjs/onchain/validation/checks/checkQuotaCount.js +10 -0
- package/dist/cjs/onchain/validation/checks/checkQuotaLimit.js +18 -0
- package/dist/cjs/onchain/validation/checks/index.js +31 -0
- package/dist/cjs/onchain/validation/helpers/amount.js +12 -0
- package/dist/cjs/onchain/validation/helpers/health-factor-limits.js +25 -0
- package/dist/cjs/onchain/validation/helpers/index.js +11 -0
- package/dist/cjs/onchain/validation/{token.js → helpers/token.js} +4 -4
- package/dist/cjs/onchain/validation/index.js +85 -27
- package/dist/cjs/onchain/validation/raise.js +33 -0
- package/dist/cjs/sdk/execute/ExecuteApi.js +1 -0
- package/dist/cjs/sdk/index.js +6 -9
- package/dist/cjs/sdk/liquidations/LiquidationsNamespace.js +9 -0
- package/dist/cjs/sdk/prepare/PrepareApi.js +55 -48
- package/dist/cjs/sdk/prepare/index.js +7 -9
- package/dist/cjs/sdk/prepare/types.js +0 -4
- package/dist/cjs/sdk/preview/PreviewNamespace.js +24 -13
- package/dist/esm/history/assembleOperations.js +2 -2
- package/dist/esm/history/classifyMulticallOperations.js +2 -2
- package/dist/esm/history/index.js +6 -1
- package/dist/esm/history/parseCreditAccountTransaction.js +3 -3
- package/dist/esm/{preview → history}/trace/errors.js +1 -1
- package/dist/esm/{preview → history}/trace/extractAdapterCallTraces.js +1 -1
- package/dist/esm/{preview → history}/trace/extractTransfers.js +1 -1
- package/dist/esm/{preview → history}/trace/findFacadeCalls.js +1 -1
- package/dist/esm/model/errors/index.js +7 -0
- package/dist/esm/model/errors/liquidation-errors.js +29 -0
- package/dist/esm/model/errors/operation-errors.js +121 -0
- package/dist/esm/{onchain/market/oracle/errors.js → model/errors/oracle-errors.js} +1 -1
- package/dist/esm/model/errors/prepare-errors.js +97 -0
- package/dist/esm/model/errors/preview-errors.js +11 -0
- package/dist/esm/model/index.js +9 -3
- package/dist/esm/model/positions.js +1 -1
- package/dist/esm/model/result.js +1 -8
- package/dist/esm/model/rwa.js +37 -0
- package/dist/esm/onchain/accounts/CreditAccountsServiceV310.js +2 -2
- package/dist/esm/onchain/accounts/index.js +1 -2
- package/dist/esm/onchain/accounts/intents/guards.js +29 -52
- package/dist/esm/onchain/accounts/intents/index.js +39 -35
- package/dist/esm/onchain/accounts/intents/leverage-band.js +1 -1
- package/dist/esm/onchain/accounts/intents/math.js +18 -14
- package/dist/esm/onchain/accounts/intents/open-strategy.js +46 -10
- package/dist/esm/onchain/accounts/intents/plan.js +51 -47
- package/dist/esm/onchain/accounts/intents/realize.js +26 -24
- package/dist/esm/onchain/accounts/intents/tail.js +14 -11
- package/dist/esm/onchain/accounts/intents/testing/sdk-mock.js +7 -0
- package/dist/esm/onchain/accounts/intents/tests/finish-withdraw.fixtures.js +6 -6
- package/dist/esm/onchain/accounts/intents/tests/withdraw.fixtures.js +12 -12
- package/dist/esm/onchain/accounts/intents/view.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/index.js +0 -1
- package/dist/esm/onchain/index.js +61 -10
- package/dist/esm/onchain/market/MarketSuite.js +7 -1
- package/dist/esm/onchain/market/adapters/index.js +1 -0
- package/dist/esm/onchain/market/credit/CreditSuite.js +47 -15
- package/dist/esm/onchain/market/index.js +3 -5
- package/dist/esm/onchain/market/oracle/PriceOracleBaseContract.js +1 -1
- package/dist/esm/onchain/market/oracle/index.js +1 -2
- package/dist/esm/onchain/market/pool/PoolQuotaKeeperV310Contract.js +8 -0
- package/dist/esm/onchain/market/rwa/RWARegistry.js +2 -1
- package/dist/esm/onchain/market/rwa/index.js +3 -4
- package/dist/esm/onchain/market/rwa/securitize/SecuritizeRWAFactory.js +2 -2
- package/dist/esm/onchain/market/rwa/securitize/constants.js +1 -2
- package/dist/esm/onchain/market/rwa/securitize/index.js +3 -3
- package/dist/esm/onchain/market/rwa/securitize/types.js +1 -29
- package/dist/esm/onchain/market/rwa/types.js +1 -7
- package/dist/esm/onchain/market/zapper/index.js +0 -1
- package/dist/esm/onchain/pools/PoolService.js +10 -16
- package/dist/esm/onchain/preview/index.js +20 -0
- package/dist/esm/{preview → onchain/preview}/parse/classifyInnerOperations.js +2 -3
- package/dist/esm/{preview → onchain/preview}/parse/index.js +0 -1
- package/dist/esm/{preview → onchain/preview}/parse/parseFacadeOperationCalldata.js +1 -1
- package/dist/esm/{preview → onchain/preview}/parse/parseOperationCalldata.js +10 -11
- package/dist/esm/{preview → onchain/preview}/parse/parsePoolOperationCalldata.js +3 -3
- package/dist/esm/{preview → onchain/preview}/parse/parseRWAFactoryOperationCalldata.js +8 -9
- package/dist/esm/{preview → onchain/preview}/parse/types.js +1 -1
- package/dist/esm/{preview → onchain/preview}/preview/CreditAccountState.js +3 -4
- package/dist/esm/{preview → onchain/preview}/preview/buildDelayedStrategyPositionOperationPreview.js +10 -11
- package/dist/esm/{preview → onchain/preview}/preview/detectCloseOrRepay.js +2 -3
- package/dist/esm/{preview → onchain/preview}/preview/detectDelayedClaim.js +4 -5
- package/dist/esm/{preview → onchain/preview}/preview/detectDelayedOperation.js +5 -6
- package/dist/esm/{preview → onchain/preview}/preview/estimateClaimableAt.js +1 -1
- package/dist/esm/{preview → onchain/preview}/preview/index.js +3 -4
- package/dist/esm/{preview → onchain/preview}/preview/previewAdjustStrategyPosition.js +17 -21
- package/dist/esm/{preview → onchain/preview}/preview/previewExitOrRepayStrategyPosition.js +20 -26
- package/dist/esm/{preview → onchain/preview}/preview/previewOpenStrategyPosition.js +25 -15
- package/dist/esm/{preview → onchain/preview}/preview/previewOperation.js +54 -35
- package/dist/esm/{preview/simulate/simulatePoolOperation.js → onchain/preview/preview/previewPoolPositionOperation.js} +46 -30
- package/dist/esm/onchain/preview/preview/replayInnerOperations.js +107 -0
- package/dist/esm/onchain/preview/preview/replayMulticall.js +21 -0
- package/dist/esm/{preview → onchain/preview}/preview/unwrapNativeCollateral.js +11 -14
- package/dist/esm/onchain/validation/bundles/checkAccountQuotas.js +19 -0
- package/dist/esm/onchain/validation/bundles/checkCollateralFunding.js +58 -0
- package/dist/esm/onchain/validation/bundles/checkCreditOperation.js +64 -0
- package/dist/esm/onchain/validation/bundles/checkDraw.js +27 -0
- package/dist/esm/onchain/validation/bundles/checkHealthFactors.js +26 -0
- package/dist/esm/onchain/validation/bundles/checkLiquidationEligibility.js +32 -0
- package/dist/esm/onchain/validation/bundles/checkLiquidationFunding.js +28 -0
- package/dist/esm/onchain/validation/bundles/checkMarket.js +23 -0
- package/dist/esm/onchain/validation/bundles/checkObtained.js +12 -0
- package/dist/esm/onchain/validation/bundles/checkPoolFunding.js +21 -0
- package/dist/esm/onchain/validation/bundles/checkPoolOperation.js +34 -0
- package/dist/esm/onchain/validation/bundles/checkQuotasAsked.js +19 -0
- package/dist/esm/onchain/validation/bundles/checkRWAOpenRequirements.js +32 -0
- package/dist/esm/onchain/validation/bundles/checkRWAOpening.js +23 -0
- package/dist/esm/onchain/validation/bundles/checkWallet.js +21 -0
- package/dist/esm/onchain/validation/bundles/checkWalletAllowance.js +31 -0
- package/dist/esm/onchain/validation/bundles/checkWalletBalance.js +40 -0
- package/dist/esm/onchain/validation/bundles/index.js +18 -0
- package/dist/esm/onchain/validation/checkLiquidation.js +21 -0
- package/dist/esm/onchain/validation/checkOperation.js +61 -0
- package/dist/esm/onchain/validation/checkSimulation.js +59 -0
- package/dist/esm/onchain/validation/checks/checkBorrowLimit.js +24 -0
- package/dist/esm/onchain/validation/checks/checkCollateralised.js +25 -0
- package/dist/esm/onchain/validation/checks/checkCreditAccountFrozen.js +9 -0
- package/dist/esm/onchain/validation/checks/checkCreditManagerPaused.js +9 -0
- package/dist/esm/onchain/validation/checks/checkDebtLimits.js +17 -0
- package/dist/esm/onchain/validation/checks/checkEmergencyLiquidator.js +12 -0
- package/dist/esm/onchain/validation/checks/checkForbiddenToken.js +9 -0
- package/dist/esm/onchain/validation/checks/checkLeverage.js +12 -0
- package/dist/esm/onchain/validation/checks/checkLiquidatorEligible.js +9 -0
- package/dist/esm/onchain/validation/checks/checkMarketExpired.js +9 -0
- package/dist/esm/onchain/validation/checks/checkPoolLiquidity.js +24 -0
- package/dist/esm/onchain/validation/checks/checkPoolPaused.js +9 -0
- package/dist/esm/onchain/validation/checks/checkPoolSunset.js +9 -0
- package/dist/esm/onchain/validation/checks/checkQuotaCount.js +9 -0
- package/dist/esm/onchain/validation/checks/checkQuotaLimit.js +17 -0
- package/dist/esm/onchain/validation/checks/index.js +16 -0
- package/dist/esm/onchain/validation/helpers/amount.js +11 -0
- package/dist/esm/onchain/validation/helpers/health-factor-limits.js +21 -0
- package/dist/esm/onchain/validation/helpers/index.js +4 -0
- package/dist/esm/onchain/validation/{token.js → helpers/token.js} +3 -3
- package/dist/esm/onchain/validation/index.js +43 -4
- package/dist/esm/onchain/validation/raise.js +31 -0
- package/dist/esm/sdk/execute/ExecuteApi.js +1 -0
- package/dist/esm/sdk/index.js +2 -3
- package/dist/esm/sdk/liquidations/LiquidationsNamespace.js +9 -0
- package/dist/esm/sdk/prepare/PrepareApi.js +43 -36
- package/dist/esm/sdk/prepare/index.js +3 -3
- package/dist/esm/sdk/prepare/types.js +1 -2
- package/dist/esm/sdk/preview/PreviewNamespace.js +24 -13
- package/dist/types/history/assembleOperations.d.ts +4 -5
- package/dist/types/history/classifyMulticallOperations.d.ts +3 -4
- package/dist/types/history/index.d.ts +8 -2
- package/dist/types/history/mapOperations.d.ts +1 -1
- package/dist/types/{preview → history}/trace/errors.d.ts +1 -1
- package/dist/types/{preview → history}/trace/extractAdapterCallTraces.d.ts +1 -1
- package/dist/types/{preview → history}/trace/extractTransfers.d.ts +2 -3
- package/dist/types/{preview → history}/trace/findFacadeCalls.d.ts +1 -1
- package/dist/types/{preview → history}/trace/types.d.ts +1 -1
- package/dist/types/history/types.d.ts +2 -3
- package/dist/types/model/errors/base.d.ts +28 -0
- package/dist/types/model/errors/index.d.ts +7 -0
- package/dist/types/model/errors/liquidation-errors.d.ts +45 -0
- package/dist/types/model/errors/operation-errors.d.ts +216 -0
- package/dist/types/{onchain/market/oracle/errors.d.ts → model/errors/oracle-errors.d.ts} +3 -5
- package/dist/types/model/errors/prepare-errors.d.ts +131 -0
- package/dist/types/model/errors/preview-errors.d.ts +72 -0
- package/dist/types/model/index.d.ts +11 -4
- package/dist/types/model/opportunities.d.ts +3 -2
- package/dist/types/model/positions.d.ts +2 -2
- package/dist/types/model/previews.d.ts +52 -113
- package/dist/types/model/result.d.ts +4 -8
- package/dist/types/model/rwa.d.ts +143 -0
- package/dist/types/onchain/accounts/CreditAccountsServiceV310.d.ts +3 -1
- package/dist/types/onchain/accounts/index.d.ts +2 -4
- package/dist/types/onchain/accounts/intents/guards.d.ts +8 -18
- package/dist/types/onchain/accounts/intents/index.d.ts +20 -19
- package/dist/types/onchain/accounts/intents/leverage-band.d.ts +1 -1
- package/dist/types/onchain/accounts/intents/math.d.ts +6 -6
- package/dist/types/onchain/accounts/intents/open-strategy.d.ts +34 -3
- package/dist/types/onchain/accounts/intents/operations.d.ts +2 -2
- package/dist/types/onchain/accounts/intents/plan.d.ts +9 -9
- package/dist/types/onchain/accounts/intents/tail.d.ts +2 -2
- package/dist/types/onchain/accounts/intents/testing/expect.d.ts +3 -3
- package/dist/types/onchain/accounts/intents/tests/finish-withdraw.fixtures.d.ts +6 -6
- package/dist/types/onchain/accounts/intents/tests/open-strategy.fixtures.d.ts +2 -2
- package/dist/types/onchain/accounts/intents/tests/withdraw.fixtures.d.ts +12 -12
- package/dist/types/onchain/accounts/intents/types.d.ts +32 -30
- package/dist/types/onchain/accounts/types.d.ts +4 -2
- package/dist/types/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.d.ts +1 -1
- package/dist/types/onchain/accounts/withdrawal-compressor/index.d.ts +1 -2
- package/dist/types/onchain/accounts/withdrawal-compressor/types.d.ts +1 -1
- package/dist/types/onchain/index.d.ts +68 -13
- package/dist/types/onchain/market/MarketSuite.d.ts +5 -1
- package/dist/types/onchain/market/adapters/index.d.ts +2 -1
- package/dist/types/onchain/market/adapters/transfers.d.ts +0 -7
- package/dist/types/onchain/market/credit/CreditSuite.d.ts +20 -8
- package/dist/types/onchain/market/credit/index.d.ts +2 -2
- package/dist/types/onchain/market/credit/types.d.ts +11 -1
- package/dist/types/onchain/market/index.d.ts +6 -7
- package/dist/types/onchain/market/oracle/PriceOracleBaseContract.d.ts +1 -1
- package/dist/types/onchain/market/oracle/index.d.ts +1 -2
- package/dist/types/onchain/market/oracle/types.d.ts +1 -1
- package/dist/types/onchain/market/pool/PoolQuotaKeeperV310Contract.d.ts +5 -0
- package/dist/types/onchain/market/rwa/index.d.ts +4 -4
- package/dist/types/onchain/market/rwa/securitize/SecuritizeRWAFactory.d.ts +3 -2
- package/dist/types/onchain/market/rwa/securitize/constants.d.ts +1 -2
- package/dist/types/onchain/market/rwa/securitize/index.d.ts +3 -3
- package/dist/types/onchain/market/rwa/securitize/types.d.ts +4 -110
- package/dist/types/onchain/market/rwa/types.d.ts +6 -32
- package/dist/types/onchain/market/zapper/ZapperContract.d.ts +1 -1
- package/dist/types/onchain/market/zapper/index.d.ts +1 -2
- package/dist/types/onchain/market/zapper/types.d.ts +1 -1
- package/dist/types/onchain/pools/types.d.ts +2 -2
- package/dist/types/onchain/preview/index.d.ts +24 -0
- package/dist/types/{preview → onchain/preview}/parse/classifyInnerOperations.d.ts +4 -4
- package/dist/types/{preview → onchain/preview}/parse/index.d.ts +2 -4
- package/dist/types/{preview → onchain/preview}/parse/parseFacadeOperationCalldata.d.ts +4 -4
- package/dist/types/onchain/preview/parse/parseOperationCalldata.d.ts +18 -0
- package/dist/types/{preview → onchain/preview}/parse/parsePoolOperationCalldata.d.ts +7 -7
- package/dist/types/{preview → onchain/preview}/parse/parseRWAFactoryOperationCalldata.d.ts +4 -4
- package/dist/types/{preview → onchain/preview}/parse/types-adapters.d.ts +5 -16
- package/dist/types/{preview → onchain/preview}/parse/types-facades.d.ts +3 -3
- package/dist/types/{preview → onchain/preview}/parse/types-pools.d.ts +1 -1
- package/dist/types/{preview → onchain/preview}/parse/types-rwa.d.ts +3 -3
- package/dist/types/{preview → onchain/preview}/parse/types.d.ts +3 -3
- package/dist/types/{preview → onchain/preview}/preview/CreditAccountState.d.ts +5 -5
- package/dist/types/{preview → onchain/preview}/preview/buildDelayedStrategyPositionOperationPreview.d.ts +5 -5
- package/dist/types/{preview → onchain/preview}/preview/detectCloseOrRepay.d.ts +1 -1
- package/dist/types/{preview → onchain/preview}/preview/detectDelayedClaim.d.ts +8 -8
- package/dist/types/{preview → onchain/preview}/preview/detectDelayedOperation.d.ts +9 -9
- package/dist/types/{preview → onchain/preview}/preview/estimateClaimableAt.d.ts +6 -6
- package/dist/types/{preview → onchain/preview}/preview/index.d.ts +3 -4
- package/dist/types/onchain/preview/preview/previewAdjustStrategyPosition.d.ts +20 -0
- package/dist/types/onchain/preview/preview/previewExitOrRepayStrategyPosition.d.ts +21 -0
- package/dist/types/onchain/preview/preview/previewOpenStrategyPosition.d.ts +14 -0
- package/dist/types/onchain/preview/preview/previewOperation.d.ts +32 -0
- package/dist/types/onchain/preview/preview/previewPoolPositionOperation.d.ts +13 -0
- package/dist/types/{preview → onchain/preview}/preview/replayInnerOperations.d.ts +11 -11
- package/dist/types/{preview → onchain/preview}/preview/replayMulticall.d.ts +10 -10
- package/dist/types/{preview → onchain/preview}/preview/unwrapNativeCollateral.d.ts +10 -20
- package/dist/types/onchain/validation/bundles/checkAccountQuotas.d.ts +16 -0
- package/dist/types/onchain/validation/bundles/checkCollateralFunding.d.ts +22 -0
- package/dist/types/onchain/validation/bundles/checkCreditOperation.d.ts +31 -0
- package/dist/types/onchain/validation/bundles/checkDraw.d.ts +20 -0
- package/dist/types/onchain/validation/bundles/checkHealthFactors.d.ts +39 -0
- package/dist/types/onchain/validation/bundles/checkLiquidationEligibility.d.ts +20 -0
- package/dist/types/onchain/validation/bundles/checkLiquidationFunding.d.ts +18 -0
- package/dist/types/onchain/validation/bundles/checkMarket.d.ts +15 -0
- package/dist/types/onchain/validation/bundles/checkObtained.d.ts +9 -0
- package/dist/types/onchain/validation/bundles/checkPoolFunding.d.ts +19 -0
- package/dist/types/onchain/validation/bundles/checkPoolOperation.d.ts +31 -0
- package/dist/types/onchain/validation/bundles/checkQuotasAsked.d.ts +10 -0
- package/dist/types/onchain/validation/bundles/checkRWAOpenRequirements.d.ts +21 -0
- package/dist/types/onchain/validation/bundles/checkRWAOpening.d.ts +19 -0
- package/dist/types/onchain/validation/bundles/checkWallet.d.ts +23 -0
- package/dist/types/onchain/validation/bundles/checkWalletAllowance.d.ts +18 -0
- package/dist/types/onchain/validation/bundles/checkWalletBalance.d.ts +17 -0
- package/dist/types/onchain/validation/bundles/index.d.ts +18 -0
- package/dist/types/onchain/validation/checkLiquidation.d.ts +23 -0
- package/dist/types/onchain/validation/checkOperation.d.ts +32 -0
- package/dist/types/onchain/validation/checkSimulation.d.ts +56 -0
- package/dist/types/onchain/validation/checks/checkBorrowLimit.d.ts +21 -0
- package/dist/types/onchain/validation/checks/checkCollateralised.d.ts +25 -0
- package/dist/types/onchain/validation/checks/checkCreditAccountFrozen.d.ts +12 -0
- package/dist/types/onchain/validation/checks/checkCreditManagerPaused.d.ts +12 -0
- package/dist/types/onchain/validation/checks/checkDebtLimits.d.ts +21 -0
- package/dist/types/onchain/validation/checks/checkEmergencyLiquidator.d.ts +17 -0
- package/dist/types/onchain/validation/checks/checkForbiddenToken.d.ts +12 -0
- package/dist/types/onchain/validation/checks/checkLeverage.d.ts +12 -0
- package/dist/types/onchain/validation/checks/checkLiquidatorEligible.d.ts +13 -0
- package/dist/types/onchain/validation/checks/checkMarketExpired.d.ts +14 -0
- package/dist/types/onchain/validation/checks/checkPoolLiquidity.d.ts +20 -0
- package/dist/types/onchain/validation/checks/checkPoolPaused.d.ts +12 -0
- package/dist/types/onchain/validation/checks/checkPoolSunset.d.ts +13 -0
- package/dist/types/onchain/validation/checks/checkQuotaCount.d.ts +11 -0
- package/dist/types/onchain/validation/checks/checkQuotaLimit.d.ts +18 -0
- package/dist/types/onchain/validation/checks/index.d.ts +16 -0
- package/dist/types/onchain/validation/helpers/amount.d.ts +7 -0
- package/dist/types/onchain/validation/helpers/health-factor-limits.d.ts +21 -0
- package/dist/types/onchain/validation/helpers/index.d.ts +4 -0
- package/dist/types/onchain/validation/{token.d.ts → helpers/token.d.ts} +4 -4
- package/dist/types/onchain/validation/index.d.ts +43 -4
- package/dist/types/onchain/validation/raise.d.ts +33 -0
- package/dist/types/sdk/execute/types.d.ts +2 -2
- package/dist/types/sdk/index.d.ts +5 -6
- package/dist/types/sdk/liquidations/LiquidationsNamespace.d.ts +5 -0
- package/dist/types/sdk/liquidations/types.d.ts +8 -0
- package/dist/types/sdk/prepare/PrepareApi.d.ts +6 -5
- package/dist/types/sdk/prepare/index.d.ts +5 -5
- package/dist/types/sdk/prepare/types.d.ts +65 -23
- package/dist/types/sdk/preview/PreviewNamespace.d.ts +13 -3
- package/dist/types/sdk/preview/index.d.ts +2 -2
- package/dist/types/sdk/preview/types.d.ts +30 -7
- package/package.json +1 -6
- package/dist/cjs/onchain/accounts/withdrawal-compressor/errors.js +0 -1
- package/dist/cjs/onchain/market/zapper/errors.js +0 -1
- package/dist/cjs/onchain/validation/checks.js +0 -258
- package/dist/cjs/onchain/validation/refusal.js +0 -39
- package/dist/cjs/preview/index.js +0 -86
- package/dist/cjs/preview/package.json +0 -1
- package/dist/cjs/preview/parse/errors.js +0 -1
- package/dist/cjs/preview/parse/index.js +0 -15
- package/dist/cjs/preview/prerequisites/AllowancePrerequisite.js +0 -38
- package/dist/cjs/preview/prerequisites/BalancePrerequisite.js +0 -52
- package/dist/cjs/preview/prerequisites/Prerequisite.js +0 -52
- package/dist/cjs/preview/prerequisites/RWAOpenRequirementsPrerequisite.js +0 -53
- package/dist/cjs/preview/prerequisites/buildCollateralPrerequisites.js +0 -63
- package/dist/cjs/preview/prerequisites/buildPartialLiquidationPrerequisites.js +0 -19
- package/dist/cjs/preview/prerequisites/buildPoolPrerequisites.js +0 -76
- package/dist/cjs/preview/prerequisites/buildRWAPrerequisites.js +0 -39
- package/dist/cjs/preview/prerequisites/checkPrerequisites.js +0 -74
- package/dist/cjs/preview/prerequisites/helpers.js +0 -23
- package/dist/cjs/preview/prerequisites/index.js +0 -12
- package/dist/cjs/preview/preview/errors.js +0 -85
- package/dist/cjs/preview/preview/index.js +0 -33
- package/dist/cjs/preview/preview/previewOpenStrategyPosition.js +0 -50
- package/dist/cjs/preview/preview/previewOperation.js +0 -100
- package/dist/cjs/preview/preview/previewPoolPositionOperation.js +0 -49
- package/dist/cjs/preview/preview/replayInnerOperations.js +0 -109
- package/dist/cjs/preview/preview/replayMulticall.js +0 -19
- package/dist/cjs/preview/simulate/errors.js +0 -73
- package/dist/cjs/preview/simulate/index.js +0 -11
- package/dist/cjs/preview/simulate/simulateFacadeOperation.js +0 -15
- package/dist/cjs/preview/simulate/simulateOperation.js +0 -29
- package/dist/cjs/preview/simulate/simulateRWAOperation.js +0 -15
- package/dist/cjs/preview/simulate/types.js +0 -1
- package/dist/cjs/preview/trace/index.js +0 -14
- package/dist/cjs/preview/trace/types.js +0 -1
- package/dist/cjs/preview/types.js +0 -1
- package/dist/cjs/preview/validate/checkOperation.js +0 -187
- package/dist/cjs/preview/validate/checkSimulation.js +0 -39
- package/dist/cjs/preview/validate/index.js +0 -8
- package/dist/cjs/sdk/prepare/errors.js +0 -93
- package/dist/esm/onchain/accounts/withdrawal-compressor/errors.js +0 -1
- package/dist/esm/onchain/market/zapper/errors.js +0 -1
- package/dist/esm/onchain/validation/checks.js +0 -238
- package/dist/esm/onchain/validation/refusal.js +0 -36
- package/dist/esm/preview/index.js +0 -38
- package/dist/esm/preview/package.json +0 -1
- package/dist/esm/preview/parse/errors.js +0 -1
- package/dist/esm/preview/prerequisites/AllowancePrerequisite.js +0 -37
- package/dist/esm/preview/prerequisites/BalancePrerequisite.js +0 -51
- package/dist/esm/preview/prerequisites/Prerequisite.js +0 -51
- package/dist/esm/preview/prerequisites/RWAOpenRequirementsPrerequisite.js +0 -52
- package/dist/esm/preview/prerequisites/buildCollateralPrerequisites.js +0 -62
- package/dist/esm/preview/prerequisites/buildPartialLiquidationPrerequisites.js +0 -18
- package/dist/esm/preview/prerequisites/buildPoolPrerequisites.js +0 -75
- package/dist/esm/preview/prerequisites/buildRWAPrerequisites.js +0 -38
- package/dist/esm/preview/prerequisites/checkPrerequisites.js +0 -73
- package/dist/esm/preview/prerequisites/helpers.js +0 -22
- package/dist/esm/preview/prerequisites/index.js +0 -7
- package/dist/esm/preview/preview/errors.js +0 -79
- package/dist/esm/preview/preview/previewPoolPositionOperation.js +0 -48
- package/dist/esm/preview/preview/replayInnerOperations.js +0 -107
- package/dist/esm/preview/preview/replayMulticall.js +0 -18
- package/dist/esm/preview/simulate/errors.js +0 -71
- package/dist/esm/preview/simulate/index.js +0 -6
- package/dist/esm/preview/simulate/simulateFacadeOperation.js +0 -14
- package/dist/esm/preview/simulate/simulateOperation.js +0 -28
- package/dist/esm/preview/simulate/simulateRWAOperation.js +0 -14
- package/dist/esm/preview/simulate/types.js +0 -1
- package/dist/esm/preview/trace/types.js +0 -1
- package/dist/esm/preview/types.js +0 -1
- package/dist/esm/preview/validate/checkOperation.js +0 -183
- package/dist/esm/preview/validate/checkSimulation.js +0 -38
- package/dist/esm/preview/validate/index.js +0 -3
- package/dist/esm/sdk/prepare/errors.js +0 -89
- package/dist/types/model/errors.d.ts +0 -46
- package/dist/types/onchain/accounts/withdrawal-compressor/errors.d.ts +0 -20
- package/dist/types/onchain/market/zapper/errors.d.ts +0 -18
- package/dist/types/onchain/validation/checks.d.ts +0 -164
- package/dist/types/onchain/validation/refusal.d.ts +0 -242
- package/dist/types/preview/index.d.ts +0 -47
- package/dist/types/preview/parse/errors.d.ts +0 -29
- package/dist/types/preview/parse/parseOperationCalldata.d.ts +0 -18
- package/dist/types/preview/prerequisites/AllowancePrerequisite.d.ts +0 -26
- package/dist/types/preview/prerequisites/BalancePrerequisite.d.ts +0 -29
- package/dist/types/preview/prerequisites/Prerequisite.d.ts +0 -26
- package/dist/types/preview/prerequisites/RWAOpenRequirementsPrerequisite.d.ts +0 -55
- package/dist/types/preview/prerequisites/buildCollateralPrerequisites.d.ts +0 -20
- package/dist/types/preview/prerequisites/buildPartialLiquidationPrerequisites.d.ts +0 -12
- package/dist/types/preview/prerequisites/buildPoolPrerequisites.d.ts +0 -12
- package/dist/types/preview/prerequisites/buildRWAPrerequisites.d.ts +0 -26
- package/dist/types/preview/prerequisites/checkPrerequisites.d.ts +0 -28
- package/dist/types/preview/prerequisites/helpers.d.ts +0 -10
- package/dist/types/preview/prerequisites/index.d.ts +0 -7
- package/dist/types/preview/prerequisites/types.d.ts +0 -53
- package/dist/types/preview/preview/errors.d.ts +0 -44
- package/dist/types/preview/preview/previewAdjustStrategyPosition.d.ts +0 -19
- package/dist/types/preview/preview/previewExitOrRepayStrategyPosition.d.ts +0 -18
- package/dist/types/preview/preview/previewOpenStrategyPosition.d.ts +0 -12
- package/dist/types/preview/preview/previewOperation.d.ts +0 -32
- package/dist/types/preview/preview/previewPoolPositionOperation.d.ts +0 -13
- package/dist/types/preview/simulate/errors.d.ts +0 -52
- package/dist/types/preview/simulate/index.d.ts +0 -7
- package/dist/types/preview/simulate/simulateFacadeOperation.d.ts +0 -16
- package/dist/types/preview/simulate/simulateOperation.d.ts +0 -12
- package/dist/types/preview/simulate/simulatePoolOperation.d.ts +0 -42
- package/dist/types/preview/simulate/simulateRWAOperation.d.ts +0 -16
- package/dist/types/preview/simulate/types.d.ts +0 -48
- package/dist/types/preview/types.d.ts +0 -65
- package/dist/types/preview/validate/checkOperation.d.ts +0 -71
- package/dist/types/preview/validate/checkSimulation.d.ts +0 -32
- package/dist/types/preview/validate/index.d.ts +0 -3
- package/dist/types/sdk/prepare/errors.d.ts +0 -319
- /package/dist/cjs/{preview/prerequisites → history/trace}/types.js +0 -0
- /package/dist/cjs/model/{errors.js → errors/base.js} +0 -0
- /package/dist/cjs/{preview → onchain/preview}/parse/types-adapters.js +0 -0
- /package/dist/cjs/{preview → onchain/preview}/parse/types-facades.js +0 -0
- /package/dist/cjs/{preview → onchain/preview}/parse/types-pools.js +0 -0
- /package/dist/cjs/{preview → onchain/preview}/parse/types-rwa.js +0 -0
- /package/dist/esm/{preview → history}/trace/index.js +0 -0
- /package/dist/esm/{preview/prerequisites → history/trace}/types.js +0 -0
- /package/dist/esm/model/{errors.js → errors/base.js} +0 -0
- /package/dist/esm/{preview → onchain/preview}/parse/types-adapters.js +0 -0
- /package/dist/esm/{preview → onchain/preview}/parse/types-facades.js +0 -0
- /package/dist/esm/{preview → onchain/preview}/parse/types-pools.js +0 -0
- /package/dist/esm/{preview → onchain/preview}/parse/types-rwa.js +0 -0
- /package/dist/types/{preview → history}/trace/index.d.ts +0 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
//#region src/model/errors/operation-errors.ts
|
|
2
|
+
/** {@inheritDoc CreditManagerPausedError} */
|
|
3
|
+
function creditManagerPaused(creditManager) {
|
|
4
|
+
return {
|
|
5
|
+
code: "creditManagerPaused",
|
|
6
|
+
message: `Credit manager ${creditManager} is paused.`,
|
|
7
|
+
creditManager
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
/** {@inheritDoc PoolPausedError} */
|
|
11
|
+
function poolPaused(pool) {
|
|
12
|
+
return {
|
|
13
|
+
code: "poolPaused",
|
|
14
|
+
message: `Pool ${pool} is paused.`,
|
|
15
|
+
pool
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/** {@inheritDoc MarketExpiredError} */
|
|
19
|
+
function marketExpired(creditManager, expirationDate) {
|
|
20
|
+
return {
|
|
21
|
+
code: "marketExpired",
|
|
22
|
+
message: `Credit manager ${creditManager} expired at ${expirationDate}.`,
|
|
23
|
+
creditManager,
|
|
24
|
+
expirationDate
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/** {@inheritDoc PoolSunsetError} */
|
|
28
|
+
function poolSunset(pool) {
|
|
29
|
+
return {
|
|
30
|
+
code: "poolSunset",
|
|
31
|
+
message: `Pool ${pool} is winding down and takes no more deposits.`,
|
|
32
|
+
pool
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/** {@inheritDoc InsufficientPoolLiquidityError} */
|
|
36
|
+
function insufficientPoolLiquidity(args) {
|
|
37
|
+
return {
|
|
38
|
+
code: "insufficientPoolLiquidity",
|
|
39
|
+
message: `The pool cannot lend ${args.requested.value} ${args.requested.token.symbol}: ${args.available.value} left, stopped by ${args.limit}.`,
|
|
40
|
+
...args
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/** {@inheritDoc DebtOutOfRangeError} */
|
|
44
|
+
function debtOutOfRange(args) {
|
|
45
|
+
const { requested, minDebt, maxDebt } = args;
|
|
46
|
+
return {
|
|
47
|
+
code: "debtOutOfRange",
|
|
48
|
+
message: requested.value > maxDebt.value ? `Debt ${requested.value} exceeds maxDebt ${maxDebt.value}.` : `Debt ${requested.value} is below minDebt ${minDebt.value}.`,
|
|
49
|
+
...args
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/** {@inheritDoc LeverageOutOfRangeError} */
|
|
53
|
+
function leverageOutOfRange(args = {}) {
|
|
54
|
+
const { requested, min } = args;
|
|
55
|
+
return {
|
|
56
|
+
code: "leverageOutOfRange",
|
|
57
|
+
message: requested === void 0 || min === void 0 ? "The leverage asked for cannot be expressed as a plan." : `Target leverage ${requested} is below the floor of ${min}.`,
|
|
58
|
+
...args
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/** {@inheritDoc InsufficientCollateralError} */
|
|
62
|
+
function insufficientCollateral(args) {
|
|
63
|
+
return {
|
|
64
|
+
code: "insufficientCollateral",
|
|
65
|
+
message: `The account would end at a health factor of ${args.healthFactor}, below ${args.healthFactorThreshold}.`,
|
|
66
|
+
...args
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/** {@inheritDoc ForbiddenTokenError} */
|
|
70
|
+
function forbiddenToken(token) {
|
|
71
|
+
return {
|
|
72
|
+
code: "forbiddenToken",
|
|
73
|
+
message: `${token.symbol} is forbidden in this market and the operation buys more of it.`,
|
|
74
|
+
token
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/** {@inheritDoc QuotaLimitReachedError} */
|
|
78
|
+
function quotaLimitReached(args) {
|
|
79
|
+
const { token, requested, available } = args;
|
|
80
|
+
return {
|
|
81
|
+
code: "quotaLimitReached",
|
|
82
|
+
message: requested === void 0 ? `${token.symbol} takes no quota in this market, so it counts as no collateral.` : `${token.symbol} has ${available.value} of quota left, the operation needs ${requested.value}.`,
|
|
83
|
+
...args
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/** {@inheritDoc QuotaCountExceededError} */
|
|
87
|
+
function quotaCountExceeded(count, max) {
|
|
88
|
+
return {
|
|
89
|
+
code: "quotaCountExceeded",
|
|
90
|
+
message: `The account would hold ${count} quoted tokens, and the facade enables ${max} at once.`,
|
|
91
|
+
count,
|
|
92
|
+
max
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/** {@inheritDoc InsufficientBalanceError} */
|
|
96
|
+
function insufficientBalance(args = {}) {
|
|
97
|
+
const { required, held } = args;
|
|
98
|
+
return {
|
|
99
|
+
code: "insufficientBalance",
|
|
100
|
+
message: required === void 0 || held === void 0 ? "There is not enough to fund this operation." : `${required.value} of ${required.token.symbol} is needed and ${held.value} is held.`,
|
|
101
|
+
...args
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/** {@inheritDoc InsufficientAllowanceError} */
|
|
105
|
+
function insufficientAllowance(args) {
|
|
106
|
+
return {
|
|
107
|
+
code: "insufficientAllowance",
|
|
108
|
+
message: `${args.required.value} of ${args.required.token.symbol} must be approved to ${args.spender}, ${args.allowed.value} is.`,
|
|
109
|
+
...args
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/** {@inheritDoc RWAOpenRequirementsError} */
|
|
113
|
+
function rwaOpenRequirementsNotMet(args) {
|
|
114
|
+
return {
|
|
115
|
+
code: "rwaOpenRequirementsNotMet",
|
|
116
|
+
message: `The RWA factory still wants something from the borrower before ${args.token.symbol} can be opened on.`,
|
|
117
|
+
...args
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
//#endregion
|
|
121
|
+
export { creditManagerPaused, debtOutOfRange, forbiddenToken, insufficientAllowance, insufficientBalance, insufficientCollateral, insufficientPoolLiquidity, leverageOutOfRange, marketExpired, poolPaused, poolSunset, quotaCountExceeded, quotaLimitReached, rwaOpenRequirementsNotMet };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
//#region src/model/errors/prepare-errors.ts
|
|
2
|
+
/** {@inheritDoc UnsupportedCollateralTokenError} */
|
|
3
|
+
function unsupportedCollateralToken(token) {
|
|
4
|
+
return {
|
|
5
|
+
code: "unsupportedCollateralToken",
|
|
6
|
+
message: `This flow does not accept ${token.symbol}.`,
|
|
7
|
+
token
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
/** {@inheritDoc UnsupportedTokenPairError} */
|
|
11
|
+
function unsupportedTokenPair(args = {}) {
|
|
12
|
+
const { from, to } = args;
|
|
13
|
+
return {
|
|
14
|
+
code: "unsupportedTokenPair",
|
|
15
|
+
message: from === void 0 ? "No route exists between these two tokens." : to === void 0 ? `No route exists out of ${from.symbol}.` : `No route exists from ${from.symbol} to ${to.symbol}.`,
|
|
16
|
+
...args
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** {@inheritDoc NoDelayedRouteError} */
|
|
20
|
+
function noDelayedRoute(token) {
|
|
21
|
+
return {
|
|
22
|
+
code: "noDelayedRoute",
|
|
23
|
+
message: token === void 0 ? "This request cannot be served as a delayed redemption." : `${token.symbol} cannot be served as a delayed redemption.`,
|
|
24
|
+
...token === void 0 ? {} : { token }
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/** {@inheritDoc MultipleDelayedWithdrawalsError} */
|
|
28
|
+
function multipleDelayedWithdrawals(token, venues) {
|
|
29
|
+
return {
|
|
30
|
+
code: "multipleDelayedWithdrawals",
|
|
31
|
+
message: `${token.symbol} has ${venues} redemption venues and none was named.`,
|
|
32
|
+
token,
|
|
33
|
+
venues
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/** {@inheritDoc WithdrawalInProgressError} */
|
|
37
|
+
function withdrawalInProgress(inFlight) {
|
|
38
|
+
return {
|
|
39
|
+
code: "withdrawalInProgress",
|
|
40
|
+
message: `A redemption of ${inFlight.token.symbol} is already in flight on the account.`,
|
|
41
|
+
inFlight
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/** {@inheritDoc NoRecordedIntentError} */
|
|
45
|
+
function noRecordedIntent() {
|
|
46
|
+
return {
|
|
47
|
+
code: "noRecordedIntent",
|
|
48
|
+
message: "The claim names no operation to resume."
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/** {@inheritDoc NoStrategyTargetCollateralError} */
|
|
52
|
+
function noStrategyTargetCollateral(creditManager) {
|
|
53
|
+
return {
|
|
54
|
+
code: "noStrategyTargetCollateral",
|
|
55
|
+
message: `Credit manager ${creditManager} has no strategy target collateral, and none was named.`,
|
|
56
|
+
creditManager
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/** {@inheritDoc CreditAccountNotFoundError} */
|
|
60
|
+
function creditAccountNotFound(creditAccount) {
|
|
61
|
+
return {
|
|
62
|
+
code: "creditAccountNotFound",
|
|
63
|
+
message: `Credit account not found: ${creditAccount}.`,
|
|
64
|
+
creditAccount
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/** {@inheritDoc CreditAccountNotEmptyError} */
|
|
68
|
+
function creditAccountNotEmpty(creditAccount) {
|
|
69
|
+
return {
|
|
70
|
+
code: "creditAccountNotEmpty",
|
|
71
|
+
message: `Credit account ${creditAccount} carries debt or quotas.`,
|
|
72
|
+
creditAccount
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/** {@inheritDoc EmptyOpenTakesNothingError} */
|
|
76
|
+
function emptyOpenTakesNothing() {
|
|
77
|
+
return {
|
|
78
|
+
code: "emptyOpenTakesNothing",
|
|
79
|
+
message: "An empty opening takes no collateral, no account to reuse and no leverage."
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* {@inheritDoc UnexpectedFailureError}
|
|
84
|
+
*
|
|
85
|
+
* Takes what was thrown, whatever that is: a `throw` is not obliged to raise an
|
|
86
|
+
* `Error`, and `cause` promises one.
|
|
87
|
+
**/
|
|
88
|
+
function unexpectedFailure(thrown, action = "prepare this operation") {
|
|
89
|
+
const cause = thrown instanceof Error ? thrown : new Error(String(thrown));
|
|
90
|
+
return {
|
|
91
|
+
code: "unexpectedFailure",
|
|
92
|
+
message: `The SDK could not ${action}: ${cause.message}`,
|
|
93
|
+
cause
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
//#endregion
|
|
97
|
+
export { creditAccountNotEmpty, creditAccountNotFound, emptyOpenTakesNothing, multipleDelayedWithdrawals, noDelayedRoute, noRecordedIntent, noStrategyTargetCollateral, unexpectedFailure, unsupportedCollateralToken, unsupportedTokenPair, withdrawalInProgress };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/model/errors/preview-errors.ts
|
|
2
|
+
/** {@inheritDoc MalformedTransactionError} */
|
|
3
|
+
function malformedTransaction(detail, cause) {
|
|
4
|
+
return {
|
|
5
|
+
code: "malformedTransaction",
|
|
6
|
+
message: `The transaction could not be replayed: ${detail}`,
|
|
7
|
+
...cause ? { cause } : {}
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { malformedTransaction };
|
package/dist/esm/model/index.js
CHANGED
|
@@ -12,7 +12,12 @@ import { borrowRateBreakdownSchema, pnlBreakdownSchema, pointsProgramPnLSchema,
|
|
|
12
12
|
import { ANALYTICS_POSITIONS_DEFAULT_LIMIT, ANALYTICS_POSITIONS_MAX_LIMIT, analyticsChartQueryOptionsSchema, analyticsChartQueryParamsSchema, analyticsChartQuerySchema, analyticsPositionListOptionsSchema, analyticsPositionListQueryParamsSchema, analyticsPositionListQuerySchema, analyticsPositionPageSchema, analyticsPositionSchema, analyticsPositionSortFieldSchema, analyticsSortDirectionSchema } from "./analytics.schema.js";
|
|
13
13
|
import "./curators.js";
|
|
14
14
|
import "./delayed-intents.js";
|
|
15
|
-
import "./errors.js";
|
|
15
|
+
import { creditAccountFrozen, liquidatorNotEligible, notEmergencyLiquidator } from "./errors/liquidation-errors.js";
|
|
16
|
+
import { creditManagerPaused, debtOutOfRange, forbiddenToken, insufficientAllowance, insufficientBalance, insufficientCollateral, insufficientPoolLiquidity, leverageOutOfRange, marketExpired, poolPaused, poolSunset, quotaCountExceeded, quotaLimitReached, rwaOpenRequirementsNotMet } from "./errors/operation-errors.js";
|
|
17
|
+
import { unpriceableTokenError } from "./errors/oracle-errors.js";
|
|
18
|
+
import { creditAccountNotEmpty, creditAccountNotFound, emptyOpenTakesNothing, multipleDelayedWithdrawals, noDelayedRoute, noRecordedIntent, noStrategyTargetCollateral, unexpectedFailure, unsupportedCollateralToken, unsupportedTokenPair, withdrawalInProgress } from "./errors/prepare-errors.js";
|
|
19
|
+
import { malformedTransaction } from "./errors/preview-errors.js";
|
|
20
|
+
import "./errors/index.js";
|
|
16
21
|
import { matchesLiquidatableAccountFilter } from "./liquidations.js";
|
|
17
22
|
import "./notices.js";
|
|
18
23
|
import { noticeKindSchema, noticeSchema } from "./notices.schema.js";
|
|
@@ -22,7 +27,8 @@ import { asEstimated } from "./previews.js";
|
|
|
22
27
|
import "./primitives.js";
|
|
23
28
|
import "./response.js";
|
|
24
29
|
import { chainFailedSchema, chainMetadataSchema, chainSucceededSchema, dataSourceSchema, responseMetadataSchema, responseSchema } from "./response.schema.js";
|
|
25
|
-
import {
|
|
30
|
+
import { safeValue, sdkErr, sdkOk } from "./result.js";
|
|
31
|
+
import { RWA_FACTORY_SECURITIZE, RWA_FACTORY_TYPES, SECURITIZE_REGISTER_VAULT_TYPES } from "./rwa.js";
|
|
26
32
|
import "./withdrawals.js";
|
|
27
33
|
import { positionClaimableWithdrawalSchema, positionPendingWithdrawalSchema, positionWithdrawalsSchema, withdrawalOutputAmountSchema } from "./withdrawals.schema.js";
|
|
28
|
-
export { ANALYTICS_POSITIONS_DEFAULT_LIMIT, ANALYTICS_POSITIONS_MAX_LIMIT, CHART_METRIC_UNITS, CHART_RANGES, CHART_UNAVAILABLE_CODES, FILTER_ALL, POOL_OPPORTUNITY_CHART_METRICS, POOL_POSITION_CHART_METRICS, PROTOCOL_CHART_METRICS, STRATEGY_OPPORTUNITY_CHART_METRICS, STRATEGY_POSITION_CHART_METRICS, STRATEGY_POSITION_COLLATERAL_ERROR, amountSchema, analyticsChartQueryOptionsSchema, analyticsChartQueryParamsSchema, analyticsChartQuerySchema, analyticsPositionListOptionsSchema, analyticsPositionListQueryParamsSchema, analyticsPositionListQuerySchema, analyticsPositionPageSchema, analyticsPositionSchema, analyticsPositionSortFieldSchema, analyticsSortDirectionSchema, apyBreakdownSchema, asEstimated, assetTypeSchema, backendPreferred, booleanParamSchema, borrowRateBreakdownSchema, bpsSchema, chainFailedSchema, chainIdSchema, chainMetadataSchema, chainSucceededSchema, chartBundleSchemaFor, chartDenominationSchema, chartMetricSchema, chartQueryCodec, chartQueryParamsSchema, chartQuerySchema, chartRangeSchema, chartSeriesSchema, chartValueSchema, chartWindowSchema, compareTagOf, curatorNameSchema, curatorSchema, dataSourceSchema, delayedReceivedAssetSchema, encodeFlag, filterAllSchema, filterable, instantReceivedAssetSchema, isFilterSet,
|
|
34
|
+
export { ANALYTICS_POSITIONS_DEFAULT_LIMIT, ANALYTICS_POSITIONS_MAX_LIMIT, CHART_METRIC_UNITS, CHART_RANGES, CHART_UNAVAILABLE_CODES, FILTER_ALL, POOL_OPPORTUNITY_CHART_METRICS, POOL_POSITION_CHART_METRICS, PROTOCOL_CHART_METRICS, RWA_FACTORY_SECURITIZE, RWA_FACTORY_TYPES, SECURITIZE_REGISTER_VAULT_TYPES, STRATEGY_OPPORTUNITY_CHART_METRICS, STRATEGY_POSITION_CHART_METRICS, STRATEGY_POSITION_COLLATERAL_ERROR, amountSchema, analyticsChartQueryOptionsSchema, analyticsChartQueryParamsSchema, analyticsChartQuerySchema, analyticsPositionListOptionsSchema, analyticsPositionListQueryParamsSchema, analyticsPositionListQuerySchema, analyticsPositionPageSchema, analyticsPositionSchema, analyticsPositionSortFieldSchema, analyticsSortDirectionSchema, apyBreakdownSchema, asEstimated, assetTypeSchema, backendPreferred, booleanParamSchema, borrowRateBreakdownSchema, bpsSchema, chainFailedSchema, chainIdSchema, chainMetadataSchema, chainSucceededSchema, chartBundleSchemaFor, chartDenominationSchema, chartMetricSchema, chartQueryCodec, chartQueryParamsSchema, chartQuerySchema, chartRangeSchema, chartSeriesSchema, chartValueSchema, chartWindowSchema, compareTagOf, creditAccountFrozen, creditAccountNotEmpty, creditAccountNotFound, creditManagerPaused, curatorNameSchema, curatorSchema, dataSourceSchema, debtOutOfRange, delayedReceivedAssetSchema, emptyOpenTakesNothing, encodeFlag, filterAllSchema, filterable, forbiddenToken, instantReceivedAssetSchema, insufficientAllowance, insufficientBalance, insufficientCollateral, insufficientPoolLiquidity, isFilterSet, leverageOutOfRange, leverageSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionId, liquidationPositionSchema, liquidatorNotEligible, malformedTransaction, marketExpired, matchesLiquidatableAccountFilter, matchesOpportunityFilter, matchesPositionFilter, multipleDelayedWithdrawals, noDelayedRoute, noRecordedIntent, noStrategyTargetCollateral, notEmergencyLiquidator, noticeKindSchema, noticeSchema, offchainOnly, onchainOnly, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterQueryParamsSchema, opportunityFilterQuerySchema, opportunityFilterSchema, opportunityId, opportunityKeySchema, opportunityKindSchema, opportunitySchema, opportunityTotalsSchema, pnlBreakdownSchema, pointRewardsSchema, pointsProgramPnLSchema, pointsProgramSchema, pointsRewardsPnLSchema, poolOpportunityChartMetricSchema, poolOpportunityDetailSchema, poolOpportunityId, poolOpportunityKeySchema, poolOpportunitySchema, poolPaused, poolPositionChartMetricSchema, poolPositionId, poolPositionKeySchema, poolPositionSchema, poolSunset, positionClaimableWithdrawalSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionId, positionKeySchema, positionKindSchema, positionPendingWithdrawalSchema, positionSchema, positionTransactionKindSchema, positionTransactionSchema, positionWithdrawalsSchema, positionsTotalsSchema, priceFeedDataSchema, priceFeedSummarySchema, protocolChartMetricSchema, quotaAssetSchema, quotaCountExceeded, quotaLimitReached, rateCurvePointSchema, rateCurveSchema, receivedAssetSchema, responseMetadataSchema, responseSchema, rewardsPnLSchema, rewardsSchema, rwaOpenRequirementsNotMet, safeValue, sdkErr, sdkOk, strategyOpportunityChartMetricSchema, strategyOpportunityDetailSchema, strategyOpportunityId, strategyOpportunityKeySchema, strategyOpportunitySchema, strategyPositionChartMetricSchema, strategyPositionId, strategyPositionKeySchema, strategyPositionSchema, timestampSchema, tokenAmountSchema, tokenQuotaRateSchema, tokenRewardsPnLSchema, tokenRewardsSchema, tokenSchema, tolerance, txCallSchema, underlyingTokenSchema, unexpectedFailure, unpriceableTokenError, unsupportedCollateralToken, unsupportedTokenPair, withdrawalInProgress, withdrawalOutputAmountSchema };
|
|
@@ -60,7 +60,7 @@ function positionId(position) {
|
|
|
60
60
|
* A condition that does not apply to a position's kind keeps the row rather
|
|
61
61
|
* than dropping it: `isZeroDebt` says nothing about a pool position, and
|
|
62
62
|
* `underlyingType` says nothing about a liquidation position, which is
|
|
63
|
-
* denominated in whatever its withdrawal
|
|
63
|
+
* denominated in whatever its withdrawal settles in.
|
|
64
64
|
*
|
|
65
65
|
* @param position - Row to test.
|
|
66
66
|
* @param filter - Conditions to test against. An absent filter matches
|
package/dist/esm/model/result.js
CHANGED
|
@@ -22,12 +22,5 @@ function sdkErr(error) {
|
|
|
22
22
|
error
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
|
-
/**
|
|
26
|
-
* Narrows a {@link SDKReturn} to its failure half. Trivial over `ok`, but it
|
|
27
|
-
* names the intent at call sites that would otherwise read `!r.ok`.
|
|
28
|
-
**/
|
|
29
|
-
function isSDKError(answer) {
|
|
30
|
-
return !answer.ok;
|
|
31
|
-
}
|
|
32
25
|
//#endregion
|
|
33
|
-
export {
|
|
26
|
+
export { safeValue, sdkErr, sdkOk };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//#region src/model/rwa.ts
|
|
2
|
+
/**
|
|
3
|
+
* Discriminant of the Securitize RWA factory contract type.
|
|
4
|
+
**/
|
|
5
|
+
const RWA_FACTORY_SECURITIZE = "RWA_FACTORY::SECURITIZE";
|
|
6
|
+
/**
|
|
7
|
+
* Discriminated union of all known RWA factory contract type strings.
|
|
8
|
+
**/
|
|
9
|
+
const RWA_FACTORY_TYPES = [RWA_FACTORY_SECURITIZE];
|
|
10
|
+
/**
|
|
11
|
+
* EIP-712 type schema for the `RegisterVault` message expected by Securitize's
|
|
12
|
+
* VaultRegistrar. Matches the contract's `RegisterVault` typehash field order.
|
|
13
|
+
**/
|
|
14
|
+
const SECURITIZE_REGISTER_VAULT_TYPES = { RegisterVault: [
|
|
15
|
+
{
|
|
16
|
+
name: "investor",
|
|
17
|
+
type: "address"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: "operator",
|
|
21
|
+
type: "address"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: "token",
|
|
25
|
+
type: "address"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: "nonce",
|
|
29
|
+
type: "uint256"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: "deadline",
|
|
33
|
+
type: "uint256"
|
|
34
|
+
}
|
|
35
|
+
] };
|
|
36
|
+
//#endregion
|
|
37
|
+
export { RWA_FACTORY_SECURITIZE, RWA_FACTORY_TYPES, SECURITIZE_REGISTER_VAULT_TYPES };
|
|
@@ -204,7 +204,7 @@ var CreditAccountsServiceV310 = class extends SDKConstruct {
|
|
|
204
204
|
else if (typeof withdrawToken === "string") tokenToWithdraw = withdrawToken;
|
|
205
205
|
const { creditFacade } = cmSuite;
|
|
206
206
|
let calls = [
|
|
207
|
-
creditFacade.prepareIncreaseDebt(debt),
|
|
207
|
+
...debt > 0n ? [creditFacade.prepareIncreaseDebt(debt)] : [],
|
|
208
208
|
...creditFacade.prepareAddCollateral(collateral, permits),
|
|
209
209
|
...openPathCalls,
|
|
210
210
|
...tokenToWithdraw ? [creditFacade.prepareWithdrawCollateral(tokenToWithdraw, MAX_UINT256, to)] : [],
|
|
@@ -216,7 +216,7 @@ var CreditAccountsServiceV310 = class extends SDKConstruct {
|
|
|
216
216
|
];
|
|
217
217
|
calls = await this.#prependMidasReceiveGreenlist(cm.address, calls);
|
|
218
218
|
calls = await this.prependPriceUpdates(cm.address, calls);
|
|
219
|
-
const tx = reopenCreditAccount ? cmSuite.multicallTx(reopenCreditAccount, calls) : cmSuite.openCreditAccountTx(to, calls, referralCode, rwaOptions);
|
|
219
|
+
const tx = reopenCreditAccount ? cmSuite.multicallTx(reopenCreditAccount, calls, rwaOptions) : cmSuite.openCreditAccountTx(to, calls, referralCode, rwaOptions);
|
|
220
220
|
tx.value = ethAmount.toString(10);
|
|
221
221
|
return tx;
|
|
222
222
|
}
|
|
@@ -6,7 +6,6 @@ import { CreditAccountCompressor } from "./credit-account-compressor/CreditAccou
|
|
|
6
6
|
import "./credit-account-compressor/index.js";
|
|
7
7
|
import { CreditAccountsServiceV310 } from "./CreditAccountsServiceV310.js";
|
|
8
8
|
import { isPhantomToken } from "./intents/utils/pick-token.js";
|
|
9
|
-
import { borrowable } from "./intents/guards.js";
|
|
10
9
|
import { fetchCreditAccountSlice, toCreditAccountSlice } from "./intents/utils/credit-account-slice.js";
|
|
11
10
|
import { calcDefaultQuota, calcQuotaUpdate, calcRecommendedQuota, roundUpQuota } from "./quota-utils.js";
|
|
12
11
|
import { CreditAccountOperationsService } from "./intents/index.js";
|
|
@@ -26,4 +25,4 @@ import { toWithdrawalStatus } from "./withdrawal-compressor/types.js";
|
|
|
26
25
|
import { WithdrawalCompressorV313Contract } from "./withdrawal-compressor/WithdrawalCompressorV313Contract.js";
|
|
27
26
|
import { createWithdrawalCompressor } from "./withdrawal-compressor/createWithdrawalCompressor.js";
|
|
28
27
|
import "./withdrawal-compressor/index.js";
|
|
29
|
-
export { AbstractWithdrawalCompressorContract, AccountBotsService, CreditAccountCompressor, CreditAccountCompressorV310Contract, CreditAccountOperationsService, CreditAccountsServiceV310, DELAYED_INTENT_TYPES, DELAYED_INTENT_VERSION, LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS, LiquidationsService, MultichainLiquidationsService, PeripheryCompressorV310Contract, RedemptionLoggerV310Contract, WithdrawalCompressorV310Contract, WithdrawalCompressorV311Contract, WithdrawalCompressorV313Contract,
|
|
28
|
+
export { AbstractWithdrawalCompressorContract, AccountBotsService, CreditAccountCompressor, CreditAccountCompressorV310Contract, CreditAccountOperationsService, CreditAccountsServiceV310, DELAYED_INTENT_TYPES, DELAYED_INTENT_VERSION, LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS, LiquidationsService, MultichainLiquidationsService, PeripheryCompressorV310Contract, RedemptionLoggerV310Contract, WithdrawalCompressorV310Contract, WithdrawalCompressorV311Contract, WithdrawalCompressorV313Contract, calcDefaultQuota, calcQuotaUpdate, calcRecommendedQuota, createRedemptionLogger, createWithdrawalCompressor, decodeDelayedIntent, encodeDelayedIntent, fetchCreditAccountSlice, getWithdrawalCompressorAddress, iCreditAccountAbi, isPhantomToken, roundUpQuota, toClaimableWithdrawal, toCreditAccountSlice, toPendingWithdrawal, toRequestableWithdrawal, toWithdrawalStatus };
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
import { MIN_HEALTH_FACTOR_FACADE
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { MIN_HEALTH_FACTOR_FACADE } from "../../validation/helpers/health-factor-limits.js";
|
|
2
|
+
import { toToken } from "../../validation/helpers/token.js";
|
|
3
|
+
import { checkBorrowLimit } from "../../validation/checks/checkBorrowLimit.js";
|
|
4
|
+
import { checkCollateralised } from "../../validation/checks/checkCollateralised.js";
|
|
5
|
+
import { checkCreditManagerPaused } from "../../validation/checks/checkCreditManagerPaused.js";
|
|
6
|
+
import { checkForbiddenToken } from "../../validation/checks/checkForbiddenToken.js";
|
|
7
|
+
import { checkMarketExpired } from "../../validation/checks/checkMarketExpired.js";
|
|
8
|
+
import { checkQuotaLimit } from "../../validation/checks/checkQuotaLimit.js";
|
|
9
|
+
import { raise } from "../../validation/raise.js";
|
|
10
|
+
import "../../validation/index.js";
|
|
4
11
|
import { eq } from "./utils/common.js";
|
|
5
12
|
import { isPhantomToken } from "./utils/pick-token.js";
|
|
6
13
|
//#region src/onchain/accounts/intents/guards.ts
|
|
@@ -34,44 +41,15 @@ function assertMarketOperable(suite) {
|
|
|
34
41
|
expirationDate: suite.creditFacade.expirationDate
|
|
35
42
|
}), `${creditManager} expired at ${suite.creditFacade.expirationDate}`);
|
|
36
43
|
}
|
|
37
|
-
/**
|
|
38
|
-
* What the pool will hand this manager in one transaction: the tightest of its
|
|
39
|
-
* free liquidity, the manager's remaining debt limit and the per-block cap the
|
|
40
|
-
* facade puts on a single borrow. A zero multiplier switches borrowing off
|
|
41
|
-
* outright, which reads here as nothing being available.
|
|
42
|
-
*/
|
|
43
|
-
function borrowable(suite) {
|
|
44
|
-
const { pool } = suite.market.pool;
|
|
45
|
-
const { maxDebtPerBlockMultiplier, maxDebt } = suite.creditFacade;
|
|
46
|
-
if (maxDebtPerBlockMultiplier === 0) return {
|
|
47
|
-
limit: 0n,
|
|
48
|
-
binding: "facadePerBlockCap"
|
|
49
|
-
};
|
|
50
|
-
const available = pool.creditManagerDebtParams.get(suite.creditManager.address)?.available;
|
|
51
|
-
return [
|
|
52
|
-
{
|
|
53
|
-
limit: pool.availableLiquidity,
|
|
54
|
-
binding: "poolAvailableLiquidity"
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
limit: maxDebt * BigInt(maxDebtPerBlockMultiplier),
|
|
58
|
-
binding: "facadePerBlockCap"
|
|
59
|
-
},
|
|
60
|
-
...available === void 0 ? [] : [{
|
|
61
|
-
limit: available,
|
|
62
|
-
binding: "managerDebtAvailable"
|
|
63
|
-
}]
|
|
64
|
-
].reduce((a, b) => b.limit < a.limit ? b : a);
|
|
65
|
-
}
|
|
66
44
|
/** The pool has to be able to lend what the plan means to draw. */
|
|
67
45
|
function assertCanBorrow(sdk, suite, amount) {
|
|
68
|
-
const {
|
|
46
|
+
const { value, limit } = suite.maxBorrowAmount();
|
|
69
47
|
raise(checkBorrowLimit({
|
|
70
48
|
requested: amount,
|
|
71
|
-
available:
|
|
72
|
-
|
|
49
|
+
available: value,
|
|
50
|
+
limit,
|
|
73
51
|
underlying: toToken(sdk, suite.market.pool.underlying)
|
|
74
|
-
}), `borrow: ${amount} exceeds what the pool can lend now (${
|
|
52
|
+
}), `borrow: ${amount} exceeds what the pool can lend now (${value})`);
|
|
75
53
|
}
|
|
76
54
|
/**
|
|
77
55
|
* What the account is allowed to end up holding more of than it started with.
|
|
@@ -87,13 +65,12 @@ function assertCanBorrow(sdk, suite, amount) {
|
|
|
87
65
|
*/
|
|
88
66
|
function assertGrowthAllowed(args) {
|
|
89
67
|
const { sdk, suite, market, before, after } = args;
|
|
90
|
-
const forbidden = suite.forbiddenTokens;
|
|
91
68
|
const underlying = market.pool.underlying;
|
|
92
69
|
for (const { token, balance } of after) {
|
|
93
70
|
if (balance <= (before.find((a) => eq(a.token, token))?.balance ?? 0n)) continue;
|
|
94
71
|
raise(checkForbiddenToken({
|
|
95
72
|
token: toToken(sdk, token),
|
|
96
|
-
isForbidden:
|
|
73
|
+
isForbidden: suite.isForbidden(token)
|
|
97
74
|
}), `${token} is forbidden in this market and the plan buys more of it`);
|
|
98
75
|
if (eq(token, underlying) || isPhantomToken(sdk, token)) continue;
|
|
99
76
|
if (!market.pool.pqk.hasActiveQuota(token)) raise(checkQuotaLimit({
|
|
@@ -109,19 +86,20 @@ function assertGrowthAllowed(args) {
|
|
|
109
86
|
* and reverts if the collateral does not cover it, so a plan that lands the
|
|
110
87
|
* account below water is refused here.
|
|
111
88
|
*
|
|
112
|
-
* The
|
|
113
|
-
* would the transaction revert. It is deliberately not
|
|
114
|
-
* the three
|
|
89
|
+
* The threshold is the facade's own `1.0`, because this guard answers one
|
|
90
|
+
* question: would the transaction revert. It is deliberately not
|
|
91
|
+
* `MIN_HF_LIMITED`, and the three thresholds in this codebase are three
|
|
92
|
+
* different jobs:
|
|
115
93
|
*
|
|
116
94
|
* - here, `1.0` — what the facade enforces, so what a plan must clear to land;
|
|
117
95
|
* - `maxWithdrawCollateral` sizes at `MIN_HF_LIMITED + 2` — a *sizing* helper
|
|
118
|
-
* leaving
|
|
96
|
+
* leaving a margin, which is not the same as a validity check;
|
|
119
97
|
* - a form refuses at or below `MIN_HF_LIMITED` (`MIN_HEALTH_FACTOR_FORM`).
|
|
120
98
|
*
|
|
121
99
|
* Raising this one to `MIN_HF_LIMITED` was tried and reverted: it made
|
|
122
100
|
* `maxWithdraw` hand back a ceiling this guard then refused, and it blocked
|
|
123
101
|
* small top-ups of an account sitting in `[1.0, 1.01)` — the very operations
|
|
124
|
-
* that rescue it. A form wanting the stricter
|
|
102
|
+
* that rescue it. A form wanting the stricter threshold has `validateHF`.
|
|
125
103
|
*
|
|
126
104
|
* Note that a position already underwater cannot be nursed back one step at a
|
|
127
105
|
* time — the check is on where the transaction ends, not on whether it
|
|
@@ -134,24 +112,23 @@ function assertGrowthAllowed(args) {
|
|
|
134
112
|
* still be refused on-chain after passing here.
|
|
135
113
|
*/
|
|
136
114
|
function assertCollateralised(healthFactorBps, safePrices) {
|
|
137
|
-
const
|
|
115
|
+
const healthFactorThreshold = MIN_HEALTH_FACTOR_FACADE;
|
|
138
116
|
raise(checkCollateralised({
|
|
139
117
|
healthFactor: healthFactorBps,
|
|
140
|
-
|
|
118
|
+
healthFactorThreshold,
|
|
141
119
|
safePrices
|
|
142
|
-
}), `the account would end at a health factor of ${healthFactorBps}, below ${
|
|
120
|
+
}), `the account would end at a health factor of ${healthFactorBps}, below ${healthFactorThreshold}`);
|
|
143
121
|
}
|
|
144
122
|
/**
|
|
145
123
|
* A quota can only be raised as far as the market still has room for: past the
|
|
146
124
|
* token's limit the keeper takes nothing more, whoever is asking.
|
|
147
125
|
*/
|
|
148
|
-
function
|
|
126
|
+
function assertQuotaAvailable(sdk, market, increases) {
|
|
149
127
|
const underlying = market.pool.underlying;
|
|
128
|
+
const { pqk } = market.pool;
|
|
150
129
|
for (const { token, balance } of increases) {
|
|
151
|
-
if (balance <= 0n) continue;
|
|
152
|
-
const
|
|
153
|
-
if (!quota) continue;
|
|
154
|
-
const left = quota.limit - quota.totalQuoted;
|
|
130
|
+
if (balance <= 0n || !pqk.quotas.has(token)) continue;
|
|
131
|
+
const left = pqk.quotaAvailable(token);
|
|
155
132
|
raise(checkQuotaLimit({
|
|
156
133
|
token: toToken(sdk, token),
|
|
157
134
|
requested: balance,
|
|
@@ -161,4 +138,4 @@ function assertQuotaHeadroom(sdk, market, increases) {
|
|
|
161
138
|
}
|
|
162
139
|
}
|
|
163
140
|
//#endregion
|
|
164
|
-
export { assertCanBorrow, assertCollateralised, assertGrowthAllowed, assertMarketOperable,
|
|
141
|
+
export { assertCanBorrow, assertCollateralised, assertGrowthAllowed, assertMarketOperable, assertQuotaAvailable };
|