@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
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { MAX_UINT256, PERCENTAGE_FACTOR } from "../../constants/math.js";
|
|
2
2
|
import "../../constants/index.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { debtOutOfRange, insufficientBalance, leverageOutOfRange } from "../../../model/errors/operation-errors.js";
|
|
4
|
+
import { noDelayedRoute, unsupportedCollateralToken } from "../../../model/errors/prepare-errors.js";
|
|
5
|
+
import "../../../model/index.js";
|
|
6
|
+
import { toToken, toTokenAmount } from "../../validation/helpers/token.js";
|
|
7
|
+
import { IntentPreviewError } from "../../validation/raise.js";
|
|
5
8
|
import { eq } from "./utils/common.js";
|
|
6
|
-
import {
|
|
9
|
+
import { assertDebtLimits, assertLeverageAtLeastOne, debtForLeverage, proportionalDebt } from "./math.js";
|
|
7
10
|
//#region src/onchain/accounts/intents/plan.ts
|
|
8
11
|
/** Whatever the previous convert produced. */
|
|
9
12
|
const RAISED = { raised: true };
|
|
@@ -15,7 +18,7 @@ function planAddCollateral(intent) {
|
|
|
15
18
|
/** Intent 4: one asset out at fixed debt. */
|
|
16
19
|
function planWithdrawAsset(intent, view) {
|
|
17
20
|
assertPositive(intent.amount, "withdrawAsset");
|
|
18
|
-
return
|
|
21
|
+
return withdraw(view, intent.token, intent.amount, intent.to);
|
|
19
22
|
}
|
|
20
23
|
/** Intent 6: collateral fixed, debt retargeted to `C0 · (L1 − 1)`. */
|
|
21
24
|
function planAdjustLeverage(intent, view) {
|
|
@@ -24,21 +27,22 @@ function planAdjustLeverage(intent, view) {
|
|
|
24
27
|
const T = intent.token ?? positionToken(view, "adjustLeverage");
|
|
25
28
|
if (delta > 0n) return [borrow(delta), convert(U, T, delta)];
|
|
26
29
|
const shortfall = -delta - view.balanceOf(U);
|
|
27
|
-
if (shortfall > 0n && eq(T, U)) throw new IntentPreviewError(
|
|
30
|
+
if (shortfall > 0n && eq(T, U)) throw new IntentPreviewError(insufficientBalance({
|
|
28
31
|
required: toTokenAmount(view.sdk, U, -delta),
|
|
29
|
-
held: toTokenAmount(view.sdk, U, view.balanceOf(U))
|
|
30
|
-
|
|
32
|
+
held: toTokenAmount(view.sdk, U, view.balanceOf(U)),
|
|
33
|
+
holderKind: "creditAccount"
|
|
34
|
+
}), `adjustLeverage: needs ${-delta} underlying, account holds ${view.balanceOf(U)}`);
|
|
31
35
|
return [...shortfall > 0n ? [convert(T, U, view.price(U, T, shortfall))] : [], repay(-delta)];
|
|
32
36
|
}
|
|
33
37
|
/** Intents 1.1 / 1.2: collateral grows by `a`, debt grows to match. */
|
|
34
38
|
function planDeposit(intent, view) {
|
|
35
39
|
assertPositive(intent.amount, "deposit");
|
|
36
40
|
const U = view.underlying;
|
|
37
|
-
if (!eq(intent.token, U) && !(view.rwaAsset && eq(intent.token, view.rwaAsset))) throw new IntentPreviewError(
|
|
41
|
+
if (!eq(intent.token, U) && !(view.rwaAsset && eq(intent.token, view.rwaAsset))) throw new IntentPreviewError(unsupportedCollateralToken(toToken(view.sdk, intent.token)), `deposit: only ${U}${view.rwaAsset ? ` or ${view.rwaAsset}` : ""} can be deposited, got ${intent.token}`);
|
|
38
42
|
const aU = view.price(intent.token, U, intent.amount);
|
|
39
43
|
const debtDelta = intent.targetLeverage === void 0 ? proportionalDebt(view, aU) : debtForLeverage(view.collateral + aU, intent.targetLeverage) - view.debt;
|
|
40
|
-
if (debtDelta < 0n) throw new IntentPreviewError(
|
|
41
|
-
|
|
44
|
+
if (debtDelta < 0n) throw new IntentPreviewError(leverageOutOfRange(), `deposit: target leverage ${intent.targetLeverage} would require repaying debt`);
|
|
45
|
+
assertDebtLimits(view.sdk, view.debt + debtDelta, view.debtLimits, U);
|
|
42
46
|
const T = intent.positionToken ?? positionToken(view, "deposit");
|
|
43
47
|
const depositStays = eq(intent.token, T);
|
|
44
48
|
return [
|
|
@@ -65,15 +69,15 @@ function planRepay(intent, view) {
|
|
|
65
69
|
assertPositive(intent.amount, "repay");
|
|
66
70
|
const U = view.underlying;
|
|
67
71
|
const fundsInU = eq(intent.token, U);
|
|
68
|
-
if (!fundsInU && !(view.rwaAsset && eq(intent.token, view.rwaAsset))) throw new IntentPreviewError(
|
|
69
|
-
if (view.debt <= 0n) throw new IntentPreviewError(
|
|
72
|
+
if (!fundsInU && !(view.rwaAsset && eq(intent.token, view.rwaAsset))) throw new IntentPreviewError(unsupportedCollateralToken(toToken(view.sdk, intent.token)), `repay: only ${U}${view.rwaAsset ? ` or ${view.rwaAsset}` : ""} can be repaid with, got ${intent.token}`);
|
|
73
|
+
if (view.debt <= 0n) throw new IntentPreviewError(debtOutOfRange({
|
|
70
74
|
requested: toTokenAmount(view.sdk, U, view.debt),
|
|
71
|
-
minDebt: toTokenAmount(view.sdk, U, view.
|
|
72
|
-
maxDebt: toTokenAmount(view.sdk, U, view.
|
|
73
|
-
}, "repay: the account owes nothing");
|
|
75
|
+
minDebt: toTokenAmount(view.sdk, U, view.debtLimits.minDebt),
|
|
76
|
+
maxDebt: toTokenAmount(view.sdk, U, view.debtLimits.maxDebt)
|
|
77
|
+
}), "repay: the account owes nothing");
|
|
74
78
|
const funding = everything(intent.amount) ? view.price(U, intent.token, withMargin(view.debt)) : intent.amount;
|
|
75
79
|
const repaid = min(view.price(intent.token, U, funding), view.debt);
|
|
76
|
-
|
|
80
|
+
assertDebtLimits(view.sdk, view.debt - repaid, view.debtLimits, view.underlying);
|
|
77
81
|
return [
|
|
78
82
|
add(intent.token, funding, intent.value),
|
|
79
83
|
...fundsInU ? [] : [convert(intent.token, U, funding)],
|
|
@@ -99,21 +103,21 @@ function planWithdraw(intent, view) {
|
|
|
99
103
|
if (eq(T, U)) return [
|
|
100
104
|
convert(S, U, view.price(U, S, WU + dD)),
|
|
101
105
|
repay(dD, intent.amount),
|
|
102
|
-
...
|
|
106
|
+
...withdraw(view, U, intent.amount, intent.to)
|
|
103
107
|
];
|
|
104
108
|
return [
|
|
105
109
|
convert(S, U, view.price(U, S, dD)),
|
|
106
110
|
repay(dD),
|
|
107
111
|
convert(S, T, view.price(U, S, WU)),
|
|
108
|
-
...
|
|
112
|
+
...withdraw(view, T, RAISED, intent.to)
|
|
109
113
|
];
|
|
110
114
|
}
|
|
111
115
|
/**
|
|
112
116
|
* Intent 2.1 against a source that cannot be sold on a DEX.
|
|
113
117
|
*
|
|
114
118
|
* Some collateral only converts through its issuer — a Securitize dsToken, a
|
|
115
|
-
* Mellow share — which answers a redemption request now and
|
|
116
|
-
* later. The trade is unchanged; what changes is that the
|
|
119
|
+
* Mellow share — which answers a redemption request now and settles days
|
|
120
|
+
* later. The trade is unchanged; what changes is that the money does not exist
|
|
117
121
|
* yet, so this half only requests the redemption:
|
|
118
122
|
*
|
|
119
123
|
* ```
|
|
@@ -129,7 +133,7 @@ function planWithdrawDelayed(intent, view) {
|
|
|
129
133
|
const { U, T, S, WU, dD, all } = withdrawShape(intent, view);
|
|
130
134
|
if (all) {
|
|
131
135
|
const held = view.balanceOf(S);
|
|
132
|
-
if (held <= 0n) throw new IntentPreviewError(
|
|
136
|
+
if (held <= 0n) throw new IntentPreviewError(insufficientBalance(), `withdraw: account holds no ${S} to redeem`);
|
|
133
137
|
return [{
|
|
134
138
|
kind: "request",
|
|
135
139
|
token: S,
|
|
@@ -141,13 +145,13 @@ function planWithdrawDelayed(intent, view) {
|
|
|
141
145
|
}
|
|
142
146
|
}];
|
|
143
147
|
}
|
|
144
|
-
if (!eq(T, U) && !(view.rwaAsset && eq(T, view.rwaAsset))) throw new IntentPreviewError(
|
|
145
|
-
const
|
|
148
|
+
if (!eq(T, U) && !(view.rwaAsset && eq(T, view.rwaAsset))) throw new IntentPreviewError(noDelayedRoute(toToken(view.sdk, T)), `withdraw: a delayed route cannot withdraw in ${T}`);
|
|
149
|
+
const tokenOutIsSource = eq(T, S);
|
|
146
150
|
return [{
|
|
147
151
|
kind: "request",
|
|
148
152
|
token: S,
|
|
149
|
-
amount: view.price(U, S,
|
|
150
|
-
reserve:
|
|
153
|
+
amount: view.price(U, S, tokenOutIsSource ? dD : WU + dD),
|
|
154
|
+
reserve: tokenOutIsSource ? intent.amount : 0n,
|
|
151
155
|
record: {
|
|
152
156
|
type: "WITHDRAW_COLLATERAL",
|
|
153
157
|
to: intent.to,
|
|
@@ -167,9 +171,9 @@ function planWithdrawDelayed(intent, view) {
|
|
|
167
171
|
*/
|
|
168
172
|
function planAdjustLeverageDelayed(intent, view) {
|
|
169
173
|
const { U, delta } = leverageShape(intent, view);
|
|
170
|
-
if (delta >= 0n) throw new IntentPreviewError(
|
|
174
|
+
if (delta >= 0n) throw new IntentPreviewError(noDelayedRoute(), "adjustLeverage: only deleveraging can settle with a delay");
|
|
171
175
|
const shortfall = -delta - view.balanceOf(U);
|
|
172
|
-
if (shortfall <= 0n) throw new IntentPreviewError(
|
|
176
|
+
if (shortfall <= 0n) throw new IntentPreviewError(noDelayedRoute(), "adjustLeverage: idle underlying covers the repayment, nothing to redeem");
|
|
173
177
|
const T = intent.token ?? positionToken(view, "adjustLeverage");
|
|
174
178
|
return [{
|
|
175
179
|
kind: "request",
|
|
@@ -188,20 +192,20 @@ function planFinishDecreaseLeverage(claimable, claimed, view) {
|
|
|
188
192
|
];
|
|
189
193
|
}
|
|
190
194
|
/**
|
|
191
|
-
* The claim is split between the promised
|
|
192
|
-
* half deferred:
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
+
* The claim is split between the promised withdrawal `W` and the debt the
|
|
196
|
+
* leading half deferred: `W` is served first, the debt gets what is left, so a
|
|
197
|
+
* bad quote shows as leverage a touch above target rather than as a wallet paid
|
|
198
|
+
* less than it was promised.
|
|
195
199
|
*/
|
|
196
200
|
function planFinishWithdraw(intent, claimable, claimed, view) {
|
|
197
201
|
const U = view.underlying;
|
|
198
202
|
const T = intent.withdrawToken;
|
|
199
203
|
const W = intent.withdrawAmount;
|
|
200
|
-
if (!eq(T, U) && !(view.rwaAsset && eq(T, view.rwaAsset))) throw new IntentPreviewError(
|
|
204
|
+
if (!eq(T, U) && !(view.rwaAsset && eq(T, view.rwaAsset))) throw new IntentPreviewError(noDelayedRoute(toToken(view.sdk, T)), `finishWithdraw: cannot withdraw in ${T}`);
|
|
201
205
|
if (intent.debtRepaid === 0n) return [
|
|
202
206
|
claim(claimable),
|
|
203
207
|
convert(claimed.token, T, claimed.amount),
|
|
204
|
-
...
|
|
208
|
+
...withdraw(view, T, {
|
|
205
209
|
raised: true,
|
|
206
210
|
max: W
|
|
207
211
|
}, intent.to)
|
|
@@ -213,13 +217,13 @@ function planFinishWithdraw(intent, claimable, claimed, view) {
|
|
|
213
217
|
raised: true,
|
|
214
218
|
max: intent.debtRepaid
|
|
215
219
|
}),
|
|
216
|
-
...
|
|
220
|
+
...withdraw(view, T, W, intent.to)
|
|
217
221
|
];
|
|
218
222
|
if (eq(T, U)) return [
|
|
219
223
|
claim(claimable),
|
|
220
224
|
convert(claimed.token, U, claimed.amount),
|
|
221
225
|
repay(intent.debtRepaid, W),
|
|
222
|
-
...
|
|
226
|
+
...withdraw(view, U, {
|
|
223
227
|
raised: true,
|
|
224
228
|
max: W
|
|
225
229
|
}, intent.to)
|
|
@@ -233,7 +237,7 @@ function planFinishWithdraw(intent, claimable, claimed, view) {
|
|
|
233
237
|
max: intent.debtRepaid
|
|
234
238
|
}),
|
|
235
239
|
convert(claimed.token, T, reserved),
|
|
236
|
-
...
|
|
240
|
+
...withdraw(view, T, {
|
|
237
241
|
raised: true,
|
|
238
242
|
max: W
|
|
239
243
|
}, intent.to)
|
|
@@ -241,7 +245,7 @@ function planFinishWithdraw(intent, claimable, claimed, view) {
|
|
|
241
245
|
}
|
|
242
246
|
/**
|
|
243
247
|
* The tail of an exit: the claim lands, everything the account holds is sold
|
|
244
|
-
* into the underlying, the loan is settled out of
|
|
248
|
+
* into the underlying, the loan is settled out of what it sells for and the rest
|
|
245
249
|
* goes to the wallet. The account survives it, empty and owing nothing.
|
|
246
250
|
*
|
|
247
251
|
* Nothing is quoted from the request — the same shape {@link planWithdraw}
|
|
@@ -267,7 +271,7 @@ function planFinishClaimOnly(claimable) {
|
|
|
267
271
|
return [claim(claimable)];
|
|
268
272
|
}
|
|
269
273
|
/**
|
|
270
|
-
* What a withdrawal comes down to: the
|
|
274
|
+
* What a withdrawal comes down to: the withdrawal `W` of `T` priced in the
|
|
271
275
|
* underlying, the debt `dD` that keeps leverage flat, and the source `S` both
|
|
272
276
|
* are funded from. Shared so that the instant and the delayed leading half
|
|
273
277
|
* cannot disagree on the amounts.
|
|
@@ -289,7 +293,7 @@ function withdrawShape(intent, view) {
|
|
|
289
293
|
};
|
|
290
294
|
}
|
|
291
295
|
const WU = view.price(T, U, intent.amount);
|
|
292
|
-
if (WU <= 0n) throw new IntentPreviewError(
|
|
296
|
+
if (WU <= 0n) throw new IntentPreviewError(insufficientBalance(), `withdraw: cannot price ${intent.amount} of ${T}`);
|
|
293
297
|
if (WU >= view.collateral) {
|
|
294
298
|
assertHasValue(view);
|
|
295
299
|
return {
|
|
@@ -302,7 +306,7 @@ function withdrawShape(intent, view) {
|
|
|
302
306
|
};
|
|
303
307
|
}
|
|
304
308
|
const dD = proportionalDebt(view, WU);
|
|
305
|
-
|
|
309
|
+
assertDebtLimits(view.sdk, view.debt - dD, view.debtLimits, view.underlying);
|
|
306
310
|
return {
|
|
307
311
|
U,
|
|
308
312
|
T,
|
|
@@ -319,9 +323,9 @@ function withdrawShape(intent, view) {
|
|
|
319
323
|
*/
|
|
320
324
|
function leverageShape(intent, view) {
|
|
321
325
|
assertLeverageAtLeastOne(intent.targetLeverage);
|
|
322
|
-
if (view.collateral <= 0n) throw new IntentPreviewError(
|
|
326
|
+
if (view.collateral <= 0n) throw new IntentPreviewError(insufficientBalance(), "adjustLeverage: account has no collateral to lever");
|
|
323
327
|
const target = debtForLeverage(view.collateral, intent.targetLeverage);
|
|
324
|
-
|
|
328
|
+
assertDebtLimits(view.sdk, target, view.debtLimits, view.underlying);
|
|
325
329
|
return {
|
|
326
330
|
U: view.underlying,
|
|
327
331
|
delta: target - view.debt
|
|
@@ -371,7 +375,7 @@ const min = (a, b) => a < b ? a : b;
|
|
|
371
375
|
* Hands `amount` of `token` to `to`. The wrapped underlying of an RWA market
|
|
372
376
|
* cannot leave the account, so it is unwrapped into the raw asset on the way.
|
|
373
377
|
*/
|
|
374
|
-
function
|
|
378
|
+
function withdraw(view, token, amount, to) {
|
|
375
379
|
if (view.rwaAsset && eq(token, view.underlying)) return [convert(view.underlying, view.rwaAsset, amount), {
|
|
376
380
|
kind: "withdraw",
|
|
377
381
|
token: view.rwaAsset,
|
|
@@ -387,20 +391,20 @@ function payout(view, token, amount, to) {
|
|
|
387
391
|
}
|
|
388
392
|
function positionToken(view, flow) {
|
|
389
393
|
const pick = view.fattest([view.underlying]);
|
|
390
|
-
if (!pick) throw new IntentPreviewError(
|
|
394
|
+
if (!pick) throw new IntentPreviewError(insufficientBalance(), `${flow}: no position token on the account`);
|
|
391
395
|
return pick;
|
|
392
396
|
}
|
|
393
397
|
function sourceToken(view) {
|
|
394
398
|
const pick = view.fattest();
|
|
395
|
-
if (!pick) throw new IntentPreviewError(
|
|
399
|
+
if (!pick) throw new IntentPreviewError(insufficientBalance(), "withdraw: account has no spendable balance");
|
|
396
400
|
return pick;
|
|
397
401
|
}
|
|
398
402
|
/** An account whose debt has eaten its collateral has nothing to hand over. */
|
|
399
403
|
function assertHasValue(view) {
|
|
400
|
-
if (view.collateral <= 0n) throw new IntentPreviewError(
|
|
404
|
+
if (view.collateral <= 0n) throw new IntentPreviewError(insufficientBalance(), `withdraw: nothing to withdraw, net value is ${view.collateral}`);
|
|
401
405
|
}
|
|
402
406
|
function assertPositive(amount, flow) {
|
|
403
|
-
if (amount <= 0n) throw new IntentPreviewError(
|
|
407
|
+
if (amount <= 0n) throw new IntentPreviewError(insufficientBalance(), `${flow}: amount must be positive`);
|
|
404
408
|
}
|
|
405
409
|
//#endregion
|
|
406
410
|
export { RAISED, planAddCollateral, planAdjustLeverage, planAdjustLeverageDelayed, planDeposit, planFinishClaimOnly, planFinishCloseAccount, planFinishDecreaseLeverage, planFinishWithdraw, planRepay, planWithdraw, planWithdrawAsset, planWithdrawDelayed };
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { insufficientBalance } from "../../../model/errors/operation-errors.js";
|
|
2
|
+
import { multipleDelayedWithdrawals, noDelayedRoute, withdrawalInProgress } from "../../../model/errors/prepare-errors.js";
|
|
3
|
+
import "../../../model/index.js";
|
|
4
|
+
import { toToken, toTokenAmount } from "../../validation/helpers/token.js";
|
|
5
|
+
import { IntentPreviewError } from "../../validation/raise.js";
|
|
3
6
|
import { eq, toTargetDecimals } from "./utils/common.js";
|
|
4
7
|
import { isRedemptionPhantomToken } from "./utils/pick-token.js";
|
|
5
|
-
import { assertCanBorrow, assertCollateralised, assertGrowthAllowed,
|
|
8
|
+
import { assertCanBorrow, assertCollateralised, assertGrowthAllowed, assertQuotaAvailable } from "./guards.js";
|
|
6
9
|
import { OperationLedger } from "./utils/ledger.js";
|
|
7
10
|
import { collectPriceImpact } from "./utils/price-impact.js";
|
|
8
11
|
import { clearedQuotas, getQuotasForUpdate, quotasAfterUpdate } from "./utils/quotas-for-update.js";
|
|
@@ -41,8 +44,8 @@ async function realize(steps, props) {
|
|
|
41
44
|
* The floor: every routed leg counted at the amount it guarantees. This is
|
|
42
45
|
* what the calls are built from — a repayment may only spend underlying the
|
|
43
46
|
* route promises to have raised — and what the guards are answered on, since
|
|
44
|
-
* a floor that does not clear the facade's
|
|
45
|
-
* revert.
|
|
47
|
+
* a floor that does not clear the facade's threshold is a transaction that
|
|
48
|
+
* can revert.
|
|
46
49
|
*/
|
|
47
50
|
const ledger = new OperationLedger(start);
|
|
48
51
|
/**
|
|
@@ -77,14 +80,16 @@ async function realize(steps, props) {
|
|
|
77
80
|
* Whether anything leaves the account, which is what makes the credit manager
|
|
78
81
|
* judge the closing collateral check at safe prices.
|
|
79
82
|
*/
|
|
80
|
-
let
|
|
83
|
+
let withdrawsCollateral = false;
|
|
81
84
|
const amountOf = (a) => typeof a === "bigint" ? a : min(raised, a.max ?? raised);
|
|
82
85
|
const assertHolds = (token, amount, what) => {
|
|
83
86
|
const held = ledger.balanceOf(token);
|
|
84
|
-
if (amount <= 0n || held < amount) throw new IntentPreviewError(
|
|
87
|
+
if (amount <= 0n || held < amount) throw new IntentPreviewError(insufficientBalance({
|
|
85
88
|
required: toTokenAmount(sdk, token, amount),
|
|
86
|
-
held: toTokenAmount(sdk, token, held)
|
|
87
|
-
|
|
89
|
+
held: toTokenAmount(sdk, token, held),
|
|
90
|
+
holderKind: "creditAccount",
|
|
91
|
+
holder: creditAccount.creditAccount
|
|
92
|
+
}), `${what}: needs ${amount} of ${token}, account holds ${held}`);
|
|
88
93
|
};
|
|
89
94
|
for (const step of steps) switch (step.kind) {
|
|
90
95
|
case "add":
|
|
@@ -173,7 +178,7 @@ async function realize(steps, props) {
|
|
|
173
178
|
case "closeAll": {
|
|
174
179
|
const balances = ledger.snapshot().assets.filter((a) => !eq(a.token, underlying) && a.balance > DUST);
|
|
175
180
|
const pending = balances.find((a) => isRedemptionPhantomToken(sdk, a.token));
|
|
176
|
-
if (pending) throw new IntentPreviewError(
|
|
181
|
+
if (pending) throw new IntentPreviewError(withdrawalInProgress(toTokenAmount(sdk, pending.token, pending.balance)), `closeAll: ${pending.token} is a pending withdrawal, claim it first`);
|
|
177
182
|
if (balances.length > 0) {
|
|
178
183
|
const leg = await paths.closeAll({ balances });
|
|
179
184
|
if (leg.probe) probes.push(leg.probe);
|
|
@@ -200,7 +205,7 @@ async function realize(steps, props) {
|
|
|
200
205
|
case "withdraw": {
|
|
201
206
|
const amount = amountOf(step.amount);
|
|
202
207
|
assertHolds(step.token, amount, "withdraw");
|
|
203
|
-
|
|
208
|
+
withdrawsCollateral = true;
|
|
204
209
|
push(buildWithdrawCollateralOperation({
|
|
205
210
|
token: step.token,
|
|
206
211
|
amount,
|
|
@@ -212,7 +217,7 @@ async function realize(steps, props) {
|
|
|
212
217
|
}
|
|
213
218
|
case "request": {
|
|
214
219
|
const asset = await delayedConfig(sdk, creditAccount, step.token);
|
|
215
|
-
if (ledger.balanceOf(asset.withdrawalPhantomToken) > 0n) throw new IntentPreviewError(
|
|
220
|
+
if (ledger.balanceOf(asset.withdrawalPhantomToken) > 0n) throw new IntentPreviewError(withdrawalInProgress(toTokenAmount(sdk, asset.withdrawalPhantomToken, ledger.balanceOf(asset.withdrawalPhantomToken))), `request: ${asset.withdrawalPhantomToken} already holds a pending withdrawal`);
|
|
216
221
|
assertHolds(step.token, step.amount + step.reserve, "request");
|
|
217
222
|
const preview = await sdk.accounts.previewDelayedWithdrawal({
|
|
218
223
|
creditAccount: creditAccount.creditAccount,
|
|
@@ -248,7 +253,7 @@ async function realize(steps, props) {
|
|
|
248
253
|
raised = instantOutput(step.claimable.outputs)?.amount ?? 0n;
|
|
249
254
|
break;
|
|
250
255
|
case "sweep": {
|
|
251
|
-
|
|
256
|
+
withdrawsCollateral = true;
|
|
252
257
|
const wrapped = ledger.balanceOf(underlying);
|
|
253
258
|
if (rwaAsset && wrapped > 0n) push(await buildUnwrapRwaCollateralOperation({
|
|
254
259
|
tokenIn: underlying,
|
|
@@ -259,7 +264,7 @@ async function realize(steps, props) {
|
|
|
259
264
|
sdk
|
|
260
265
|
}));
|
|
261
266
|
for (const { token, balance } of ledger.snapshot().assets) {
|
|
262
|
-
const
|
|
267
|
+
const withdrawal = buildWithdrawCollateralOperation({
|
|
263
268
|
token,
|
|
264
269
|
amount: balance,
|
|
265
270
|
to: step.to,
|
|
@@ -267,8 +272,8 @@ async function realize(steps, props) {
|
|
|
267
272
|
creditAccount,
|
|
268
273
|
sdk
|
|
269
274
|
});
|
|
270
|
-
push(
|
|
271
|
-
...
|
|
275
|
+
push(withdrawal, {
|
|
276
|
+
...withdrawal,
|
|
272
277
|
amount: expected.balanceOf(token)
|
|
273
278
|
});
|
|
274
279
|
}
|
|
@@ -297,7 +302,7 @@ async function realize(steps, props) {
|
|
|
297
302
|
convert: price
|
|
298
303
|
});
|
|
299
304
|
if (!cleared && quotas.quotaIncrease.length + quotas.quotaDecrease.length > 0) {
|
|
300
|
-
|
|
305
|
+
assertQuotaAvailable(sdk, market, quotas.quotaIncrease);
|
|
301
306
|
push(buildQuotaUpdateOperation({
|
|
302
307
|
update: quotas,
|
|
303
308
|
creditAccount,
|
|
@@ -318,7 +323,7 @@ async function realize(steps, props) {
|
|
|
318
323
|
...snapshot,
|
|
319
324
|
assets,
|
|
320
325
|
totalValue: floor.totalValue
|
|
321
|
-
}, { safePrices:
|
|
326
|
+
}, { safePrices: withdrawsCollateral }), withdrawsCollateral);
|
|
322
327
|
const priceImpact = await collectPriceImpact(probes, {
|
|
323
328
|
totalValue: projected.totalValue,
|
|
324
329
|
netValue: projected.totalValue - debt,
|
|
@@ -347,13 +352,10 @@ async function realize(steps, props) {
|
|
|
347
352
|
*/
|
|
348
353
|
async function delayedConfig(sdk, creditAccount, token) {
|
|
349
354
|
const compressor = sdk.withdrawalCompressor;
|
|
350
|
-
if (!compressor) throw new IntentPreviewError(
|
|
355
|
+
if (!compressor) throw new IntentPreviewError(noDelayedRoute(toToken(sdk, token)), "request: chain has no withdrawal compressor");
|
|
351
356
|
const assets = await compressor.findWithdrawableAssets(creditAccount.creditManager, token);
|
|
352
|
-
if (assets.length === 0) throw new IntentPreviewError(
|
|
353
|
-
if (assets.length > 1) throw new IntentPreviewError(
|
|
354
|
-
token: toToken(sdk, token),
|
|
355
|
-
venues: assets.length
|
|
356
|
-
}, `request: ${token} has ${assets.length} delayed withdrawal configs`);
|
|
357
|
+
if (assets.length === 0) throw new IntentPreviewError(noDelayedRoute(toToken(sdk, token)), `request: ${token} has no delayed withdrawal config`);
|
|
358
|
+
if (assets.length > 1) throw new IntentPreviewError(multipleDelayedWithdrawals(toToken(sdk, token), assets.length), `request: ${token} has ${assets.length} delayed withdrawal configs`);
|
|
357
359
|
return assets[0];
|
|
358
360
|
}
|
|
359
361
|
const callsOf = (operations) => operations.flatMap((op) => op.calls);
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { insufficientBalance } from "../../../model/errors/operation-errors.js";
|
|
2
|
+
import { noRecordedIntent } from "../../../model/errors/prepare-errors.js";
|
|
3
|
+
import "../../../model/index.js";
|
|
4
|
+
import { toTokenAmount } from "../../validation/helpers/token.js";
|
|
5
|
+
import { IntentPreviewError } from "../../validation/raise.js";
|
|
3
6
|
import { toTargetDecimals } from "./utils/common.js";
|
|
4
7
|
import { createOraclePaths } from "./utils/router-path.js";
|
|
5
8
|
import { planFinishClaimOnly, planFinishCloseAccount, planFinishDecreaseLeverage, planFinishWithdraw } from "./plan.js";
|
|
@@ -16,14 +19,14 @@ import { accountView } from "./view.js";
|
|
|
16
19
|
* tail as it is projected the moment the request is made.
|
|
17
20
|
*
|
|
18
21
|
* A claim that brought only part of what was queued is served in proportion,
|
|
19
|
-
* see {@link partialTail}: the intent's
|
|
22
|
+
* see {@link partialTail}: the intent's withdrawal and its repayment are cut to the
|
|
20
23
|
* share that arrived, and the rest of both is handed to the next claim.
|
|
21
24
|
*/
|
|
22
25
|
function planTail(args) {
|
|
23
26
|
const { intent, claimable, view } = args;
|
|
24
27
|
const claimed = () => {
|
|
25
28
|
const output = instantOutput(claimable.outputs);
|
|
26
|
-
if (!output) throw new IntentPreviewError(
|
|
29
|
+
if (!output) throw new IntentPreviewError(insufficientBalance(), "finishIntent: the claim credits nothing to spend");
|
|
27
30
|
return output;
|
|
28
31
|
};
|
|
29
32
|
const queued = claimable.outputs.find((o) => o.isDelayed && o.amount > 0n);
|
|
@@ -51,12 +54,12 @@ const whole = (steps) => ({
|
|
|
51
54
|
/**
|
|
52
55
|
* The tail of a claim that settled only part of the withdrawal it matured.
|
|
53
56
|
*
|
|
54
|
-
* Only a legacy Mellow multivault answers one this way — it
|
|
57
|
+
* Only a legacy Mellow multivault answers one this way — it hands over what its
|
|
55
58
|
* subvaults hold liquid and queues the rest — and the engine cannot finish an
|
|
56
59
|
* intent it has been given a fraction of the funds for. So the fraction is what
|
|
57
|
-
* it serves: the
|
|
60
|
+
* it serves: the withdrawal and the repayment are cut in the proportion that
|
|
58
61
|
* arrived, which keeps the withdrawal at the fixed leverage it was asked for
|
|
59
|
-
* instead of paying the wallet
|
|
62
|
+
* instead of paying the wallet first and deleveraging a claim later, and
|
|
60
63
|
* the untouched half of each is carried to the next claim by the remainder.
|
|
61
64
|
*
|
|
62
65
|
* Two intents cannot be served in part at all. An exit sells the account whole,
|
|
@@ -123,7 +126,7 @@ function partialTail(args) {
|
|
|
123
126
|
* How much of the redemption this claim was: what it credited, over that plus
|
|
124
127
|
* what it left queued.
|
|
125
128
|
*
|
|
126
|
-
* The phantom stands for its
|
|
129
|
+
* The phantom stands for its claim one for one — the same reading the request
|
|
127
130
|
* side takes when it names the claim it expects — so only the decimals of the
|
|
128
131
|
* two have to be reconciled before they can be added up.
|
|
129
132
|
*/
|
|
@@ -143,7 +146,7 @@ function part(amount, share) {
|
|
|
143
146
|
*
|
|
144
147
|
* A request is only half a withdrawal, so the state it lands in is not the
|
|
145
148
|
* answer to "what does this do to my position": the debt is still there, the
|
|
146
|
-
*
|
|
149
|
+
* withdrawal has not been made, and the position sits in a phantom token. What the
|
|
147
150
|
* caller means is the far side — and that side can be walked now, because the
|
|
148
151
|
* request already fixes the claim it will be finished from.
|
|
149
152
|
*
|
|
@@ -160,7 +163,7 @@ async function projectTail(args) {
|
|
|
160
163
|
const { request, delayed, creditAccount, sdk, quotaReserve } = args;
|
|
161
164
|
const { claim } = delayed;
|
|
162
165
|
const queued = request.outputs.find((o) => o.isDelayed);
|
|
163
|
-
if (!queued || !claim) throw new IntentPreviewError(
|
|
166
|
+
if (!queued || !claim) throw new IntentPreviewError(noRecordedIntent(), "projectTail: the request queued nothing to claim");
|
|
164
167
|
const next = sliceAfter(creditAccount, delayed.afterRequest);
|
|
165
168
|
const { steps } = planTail({
|
|
166
169
|
intent: delayed.record,
|
|
@@ -184,7 +187,7 @@ async function projectTail(args) {
|
|
|
184
187
|
}
|
|
185
188
|
/**
|
|
186
189
|
* The matured withdrawal the tail will be built from, as the request implies
|
|
187
|
-
* it: the phantom it created is burned and the
|
|
190
|
+
* it: the phantom it created is burned and the claim takes its place.
|
|
188
191
|
* It carries no claim calls — those are read from the chain when the claim is
|
|
189
192
|
* real, and nothing here is going to be sent.
|
|
190
193
|
*/
|
|
@@ -122,6 +122,7 @@ function buildMockSdk(args) {
|
|
|
122
122
|
const quotaOf = (token) => args.quotas[token.toLowerCase()] ?? args.quotas[token];
|
|
123
123
|
const quotas = {
|
|
124
124
|
values: () => Object.values(args.quotas).map(fullQuota),
|
|
125
|
+
has: (token) => quotaOf(token) !== void 0,
|
|
125
126
|
get: (token) => {
|
|
126
127
|
const q = quotaOf(token);
|
|
127
128
|
return q === void 0 ? void 0 : fullQuota(q);
|
|
@@ -158,6 +159,10 @@ function buildMockSdk(args) {
|
|
|
158
159
|
hasActiveQuota: (token) => {
|
|
159
160
|
const q = quotaOf(token);
|
|
160
161
|
return !!q?.isActive && q.limit > 0n;
|
|
162
|
+
},
|
|
163
|
+
quotaAvailable: (token) => {
|
|
164
|
+
const q = quotas.get(token);
|
|
165
|
+
return q === void 0 ? 0n : q.limit - q.totalQuoted;
|
|
161
166
|
}
|
|
162
167
|
},
|
|
163
168
|
pool: {
|
|
@@ -191,6 +196,8 @@ function buildMockSdk(args) {
|
|
|
191
196
|
liquidationFees: () => MOCK_LIQUIDATION_FEES,
|
|
192
197
|
totalLiquidationDiscount: CreditSuite.prototype.totalLiquidationDiscount,
|
|
193
198
|
creditOperationMarket: CreditSuite.prototype.creditOperationMarket,
|
|
199
|
+
isForbidden: CreditSuite.prototype.isForbidden,
|
|
200
|
+
maxBorrowAmount: CreditSuite.prototype.maxBorrowAmount,
|
|
194
201
|
creditManager: {
|
|
195
202
|
address: args.creditManager,
|
|
196
203
|
liquidationThresholds,
|
|
@@ -109,11 +109,11 @@ const M4_LT = 9200n;
|
|
|
109
109
|
const m4QuotaOf = (balance) => balance * M4_LT / 10000n;
|
|
110
110
|
/** Matrix baseline debt: 8U. */
|
|
111
111
|
const M4_DEBT = 800000000n;
|
|
112
|
-
/** Matrix
|
|
112
|
+
/** Matrix withdrawal W: 1U. */
|
|
113
113
|
const M4_W = 100000000n;
|
|
114
114
|
/** Proportional repayment `dD = D0 * W / C0` = 4U. */
|
|
115
115
|
const M4_DD = 400000000n;
|
|
116
|
-
/**
|
|
116
|
+
/** Withdrawal plus repayment: 5U redeemed by the leading half. */
|
|
117
117
|
const M4_SPEND = 500000000n;
|
|
118
118
|
/** Quotable withdrawal phantom: `POS2`, 1:1 with `POS`. */
|
|
119
119
|
const M4_PHANTOM = POS2;
|
|
@@ -153,10 +153,10 @@ function m4PhantomQuotaResetOp() {
|
|
|
153
153
|
/**
|
|
154
154
|
* Matrix 4.3 tail — the claim pays `UND` directly.
|
|
155
155
|
*
|
|
156
|
-
* MATRIX MISMATCH: the matrix
|
|
156
|
+
* MATRIX MISMATCH: the matrix withdraws first — `claim →
|
|
157
157
|
* withdrawCollateral(min(W, claim.amount)) → decreaseDebt(rest) →
|
|
158
|
-
* changeQuota`. The engine repays before
|
|
159
|
-
* keep: W)` precedes the
|
|
158
|
+
* changeQuota`. The engine repays before withdrawing (`repay(debtRepaid,
|
|
159
|
+
* keep: W)` precedes the withdrawal leg in `planFinishWithdraw`):
|
|
160
160
|
* `claim → decreaseDebt(dD) → withdrawCollateral(W) → changeQuota`.
|
|
161
161
|
* Amounts are identical; only the order differs.
|
|
162
162
|
*/
|
|
@@ -216,7 +216,7 @@ const case_matrix_4_4_tail = {
|
|
|
216
216
|
]
|
|
217
217
|
};
|
|
218
218
|
/**
|
|
219
|
-
* Matrix 4.5 tail — 4.3 on the RWA market: unwrap before the
|
|
219
|
+
* Matrix 4.5 tail — 4.3 on the RWA market: unwrap before the withdrawal.
|
|
220
220
|
*
|
|
221
221
|
* MATRIX MISMATCH: same ordering divergence as 4.3 — the matrix expects
|
|
222
222
|
* `claim → unwrapRwaCollateral → withdrawCollateral(RWA) → decreaseDebt →
|
|
@@ -15,7 +15,7 @@ const LT = 9200n;
|
|
|
15
15
|
const quotaOf = (balance) => balance * LT / 10000n;
|
|
16
16
|
/** 100 UND of value leaving the account. */
|
|
17
17
|
const W = 10000000000n;
|
|
18
|
-
/**
|
|
18
|
+
/** Withdrawal plus proportional repayment. */
|
|
19
19
|
const SPEND = 2n * W;
|
|
20
20
|
const TVL_BEFORE = 200000000000n;
|
|
21
21
|
const DEBT_BEFORE = 100000000000n;
|
|
@@ -49,7 +49,7 @@ const case_und_und = {
|
|
|
49
49
|
to: WALLET
|
|
50
50
|
}]
|
|
51
51
|
};
|
|
52
|
-
/** Row 2 — S = U, T = POS: repay, then route the
|
|
52
|
+
/** Row 2 — S = U, T = POS: repay, then route the withdrawal out of the underlying. */
|
|
53
53
|
const case_und_pos = {
|
|
54
54
|
...base,
|
|
55
55
|
intent: {
|
|
@@ -215,8 +215,8 @@ const case_pos_pos2 = {
|
|
|
215
215
|
}
|
|
216
216
|
]
|
|
217
217
|
};
|
|
218
|
-
/** RWA market: the underlying
|
|
219
|
-
const
|
|
218
|
+
/** RWA market: the underlying withdrawal is force-unwrapped to the asset. */
|
|
219
|
+
const case_rwa_pos_und = {
|
|
220
220
|
...base,
|
|
221
221
|
intent: {
|
|
222
222
|
type: "WITHDRAW",
|
|
@@ -267,18 +267,18 @@ const case_rwa_payout = {
|
|
|
267
267
|
/** Matrix baseline: 10A of position against 8U of debt (2U collateral at 5x). */
|
|
268
268
|
const M4_BALANCE = 1000000000n;
|
|
269
269
|
const M4_DEBT = 800000000n;
|
|
270
|
-
/** Matrix
|
|
270
|
+
/** Matrix withdrawal W: 1U. */
|
|
271
271
|
const M4_W = 100000000n;
|
|
272
272
|
/** Proportional repayment `dD = D0 * W / C0` = 4U. */
|
|
273
273
|
const M4_DD = 400000000n;
|
|
274
|
-
/**
|
|
274
|
+
/** Withdrawal plus repayment: 5U liquidated in total. */
|
|
275
275
|
const M4_SPEND = 500000000n;
|
|
276
276
|
/**
|
|
277
|
-
* Matrix 4.1 — withdraw 1U, source `POS`,
|
|
277
|
+
* Matrix 4.1 — withdraw 1U, source `POS`, tokenOut `UND`.
|
|
278
278
|
*
|
|
279
|
-
* MATRIX MISMATCH: the matrix
|
|
280
|
-
* decreaseDebt → changeQuota`. The engine repays before
|
|
281
|
-
* (`repay(dD, keep: W)` precedes the
|
|
279
|
+
* MATRIX MISMATCH: the matrix withdraws first — `swap → withdrawCollateral →
|
|
280
|
+
* decreaseDebt → changeQuota`. The engine repays before withdrawing
|
|
281
|
+
* (`repay(dD, keep: W)` precedes the withdrawal leg in `planWithdraw`):
|
|
282
282
|
* `swap → decreaseDebt → withdrawCollateral → changeQuota`. Amounts are
|
|
283
283
|
* identical; only the order differs.
|
|
284
284
|
*/
|
|
@@ -325,7 +325,7 @@ const case_matrix_4_1 = {
|
|
|
325
325
|
]
|
|
326
326
|
};
|
|
327
327
|
/**
|
|
328
|
-
* Matrix 4.2 — 4.1 on the RWA market: the
|
|
328
|
+
* Matrix 4.2 — 4.1 on the RWA market: the withdrawal is unwrapped on the way out.
|
|
329
329
|
*
|
|
330
330
|
* MATRIX MISMATCH: same ordering divergence as 4.1 — the matrix expects
|
|
331
331
|
* `swap → unwrapRwaCollateral → withdrawCollateral(RWA) → decreaseDebt →
|
|
@@ -399,4 +399,4 @@ function buildWithdrawProps(c, sdk) {
|
|
|
399
399
|
};
|
|
400
400
|
}
|
|
401
401
|
//#endregion
|
|
402
|
-
export { DEBT_AFTER, DEBT_BEFORE, M4_BALANCE, M4_DD, M4_DEBT, M4_SPEND, M4_W, QUOTA_AFTER, QUOTA_BEFORE, QUOTA_DELTA, SPEND, TVL_AFTER, TVL_BEFORE, W, buildWithdrawProps, buildWithdrawSdk, case_matrix_4_1, case_matrix_4_2, case_pos_pos, case_pos_pos2, case_pos_und,
|
|
402
|
+
export { DEBT_AFTER, DEBT_BEFORE, M4_BALANCE, M4_DD, M4_DEBT, M4_SPEND, M4_W, QUOTA_AFTER, QUOTA_BEFORE, QUOTA_DELTA, SPEND, TVL_AFTER, TVL_BEFORE, W, buildWithdrawProps, buildWithdrawSdk, case_matrix_4_1, case_matrix_4_2, case_pos_pos, case_pos_pos2, case_pos_und, case_rwa_pos_und, case_und_pos, case_und_und };
|
|
@@ -21,7 +21,7 @@ function accountView(creditAccount, sdk) {
|
|
|
21
21
|
rwaAsset: sdk.tokensMeta.rwaUnderlyings.get(underlying)?.asset,
|
|
22
22
|
debt: creditAccount.totalDebt,
|
|
23
23
|
collateral: totalValue - creditAccount.totalDebt,
|
|
24
|
-
|
|
24
|
+
debtLimits: {
|
|
25
25
|
minDebt: creditFacade.minDebt,
|
|
26
26
|
maxDebt: creditFacade.maxDebt
|
|
27
27
|
},
|
|
@@ -8,5 +8,4 @@ import { WithdrawalCompressorV311Contract } from "./WithdrawalCompressorV311Cont
|
|
|
8
8
|
import { toWithdrawalStatus } from "./types.js";
|
|
9
9
|
import { WithdrawalCompressorV313Contract } from "./WithdrawalCompressorV313Contract.js";
|
|
10
10
|
import { createWithdrawalCompressor } from "./createWithdrawalCompressor.js";
|
|
11
|
-
import "./errors.js";
|
|
12
11
|
export { AbstractWithdrawalCompressorContract, DELAYED_INTENT_TYPES, DELAYED_INTENT_VERSION, RedemptionLoggerV310Contract, WithdrawalCompressorV310Contract, WithdrawalCompressorV311Contract, WithdrawalCompressorV313Contract, createRedemptionLogger, createWithdrawalCompressor, decodeDelayedIntent, encodeDelayedIntent, getWithdrawalCompressorAddress, iCreditAccountAbi, toClaimableWithdrawal, toPendingWithdrawal, toRequestableWithdrawal, toWithdrawalStatus };
|