@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,5 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
2
|
+
const require_model_errors_operation_errors = require("../../../model/errors/operation-errors.js");
|
|
3
|
+
require("../../../model/index.js");
|
|
4
|
+
const require_onchain_validation_raise = require("../../validation/raise.js");
|
|
3
5
|
const require_onchain_accounts_intents_guards = require("./guards.js");
|
|
4
6
|
const require_onchain_accounts_intents_math = require("./math.js");
|
|
5
7
|
const require_onchain_accounts_intents_utils_price_impact = require("./utils/price-impact.js");
|
|
@@ -7,7 +9,10 @@ const require_onchain_accounts_intents_utils_quotas_for_update = require("./util
|
|
|
7
9
|
const require_onchain_accounts_intents_utils_router_path = require("./utils/router-path.js");
|
|
8
10
|
require("./utils/index.js");
|
|
9
11
|
//#region src/onchain/accounts/intents/open-strategy.ts
|
|
10
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* Stand-in account address, used when the opening creates its own account:
|
|
14
|
+
* nothing exists on chain until the tx lands.
|
|
15
|
+
*/
|
|
11
16
|
const NO_ACCOUNT = "0x0000000000000000000000000000000000000000";
|
|
12
17
|
/**
|
|
13
18
|
* Builds the state opening a leveraged position out of wallet collateral would
|
|
@@ -22,7 +27,8 @@ const NO_ACCOUNT = "0x0000000000000000000000000000000000000000";
|
|
|
22
27
|
* `sdk.accounts.openCA`.
|
|
23
28
|
*/
|
|
24
29
|
async function buildOpenStrategyState(props) {
|
|
25
|
-
|
|
30
|
+
if (props.empty) return emptyOpenState(props);
|
|
31
|
+
const { sdk, creditManager, collateral, targetToken, leverage, slippage = 0, quotaReserve, leftoverBalances = [], creditAccount: existing } = props;
|
|
26
32
|
require_onchain_accounts_intents_math.assertLeverageAtLeastOne(leverage);
|
|
27
33
|
const suite = sdk.marketRegister.findCreditManager(creditManager);
|
|
28
34
|
const market = sdk.marketRegister.findByCreditManager(creditManager);
|
|
@@ -30,9 +36,9 @@ async function buildOpenStrategyState(props) {
|
|
|
30
36
|
const underlying = market.pool.underlying.toLowerCase();
|
|
31
37
|
const convert = (from, to, amount) => market.priceOracle.safeConvert(from, to, amount).value;
|
|
32
38
|
const margin = collateral.reduce((acc, a) => acc + convert(a.token, underlying, a.balance), 0n);
|
|
33
|
-
if (margin <= 0n) throw new
|
|
39
|
+
if (margin <= 0n) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_operation_errors.insufficientBalance(), "openStrategy: collateral is worth nothing in underlying");
|
|
34
40
|
const debt = require_onchain_accounts_intents_math.debtForLeverage(margin, leverage);
|
|
35
|
-
const account = {
|
|
41
|
+
const account = existing ?? {
|
|
36
42
|
creditAccount: NO_ACCOUNT,
|
|
37
43
|
creditManager: creditManager.toLowerCase(),
|
|
38
44
|
creditFacade: suite.creditFacade.address.toLowerCase(),
|
|
@@ -42,7 +48,7 @@ async function buildOpenStrategyState(props) {
|
|
|
42
48
|
totalDebt: 0n,
|
|
43
49
|
tokens: []
|
|
44
50
|
};
|
|
45
|
-
require_onchain_accounts_intents_math.
|
|
51
|
+
require_onchain_accounts_intents_math.assertDebtLimits(sdk, debt, suite.creditFacade, underlying);
|
|
46
52
|
require_onchain_accounts_intents_guards.assertCanBorrow(sdk, suite, debt);
|
|
47
53
|
const paths = require_onchain_accounts_intents_utils_router_path.createRouterPaths({
|
|
48
54
|
sdk,
|
|
@@ -78,7 +84,7 @@ async function buildOpenStrategyState(props) {
|
|
|
78
84
|
before: [],
|
|
79
85
|
after: averageAssets
|
|
80
86
|
});
|
|
81
|
-
require_onchain_accounts_intents_guards.
|
|
87
|
+
require_onchain_accounts_intents_guards.assertQuotaAvailable(sdk, market, averageQuota);
|
|
82
88
|
const snapshot = {
|
|
83
89
|
creditManager,
|
|
84
90
|
assets: averageAssets,
|
|
@@ -101,7 +107,37 @@ async function buildOpenStrategyState(props) {
|
|
|
101
107
|
minAssets: minAssets.map(priced),
|
|
102
108
|
averageQuota,
|
|
103
109
|
minQuota,
|
|
104
|
-
calls: [...leg.calls]
|
|
110
|
+
calls: [...leg.calls],
|
|
111
|
+
creditAccount: existing?.creditAccount
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The opening that holds an account and nothing else.
|
|
116
|
+
*
|
|
117
|
+
* Taken before the walk rather than threaded through it: the router has no
|
|
118
|
+
* guard for an empty basket and would still make its `eth_call`, and every
|
|
119
|
+
* assertion below reads amounts that are not there.
|
|
120
|
+
*/
|
|
121
|
+
async function emptyOpenState(props) {
|
|
122
|
+
const { sdk, creditManager } = props;
|
|
123
|
+
require_onchain_accounts_intents_guards.assertMarketOperable(sdk.marketRegister.findCreditManager(creditManager));
|
|
124
|
+
const snapshot = {
|
|
125
|
+
creditManager,
|
|
126
|
+
assets: [],
|
|
127
|
+
quotas: [],
|
|
128
|
+
totalDebt: 0n,
|
|
129
|
+
totalValue: 0n
|
|
130
|
+
};
|
|
131
|
+
const { assets: _assets, quotas: _quotas, ...projection } = sdk.positions.projection(snapshot, { availableLiquidityChange: 0n });
|
|
132
|
+
return {
|
|
133
|
+
...projection,
|
|
134
|
+
currentPrice: sdk.positions.currentPrice(snapshot),
|
|
135
|
+
priceImpact: void 0,
|
|
136
|
+
averageAssets: [],
|
|
137
|
+
minAssets: [],
|
|
138
|
+
averageQuota: [],
|
|
139
|
+
minQuota: [],
|
|
140
|
+
calls: []
|
|
105
141
|
};
|
|
106
142
|
}
|
|
107
143
|
/** Collateral plus the borrowed underlying, folded into one balance per token. */
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_onchain_constants_math = require("../../constants/math.js");
|
|
3
3
|
require("../../constants/index.js");
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const require_model_errors_operation_errors = require("../../../model/errors/operation-errors.js");
|
|
5
|
+
const require_model_errors_prepare_errors = require("../../../model/errors/prepare-errors.js");
|
|
6
|
+
require("../../../model/index.js");
|
|
7
|
+
const require_onchain_validation_helpers_token = require("../../validation/helpers/token.js");
|
|
8
|
+
const require_onchain_validation_raise = require("../../validation/raise.js");
|
|
6
9
|
const require_onchain_accounts_intents_utils_common = require("./utils/common.js");
|
|
7
10
|
const require_onchain_accounts_intents_math = require("./math.js");
|
|
8
11
|
//#region src/onchain/accounts/intents/plan.ts
|
|
@@ -16,7 +19,7 @@ function planAddCollateral(intent) {
|
|
|
16
19
|
/** Intent 4: one asset out at fixed debt. */
|
|
17
20
|
function planWithdrawAsset(intent, view) {
|
|
18
21
|
assertPositive(intent.amount, "withdrawAsset");
|
|
19
|
-
return
|
|
22
|
+
return withdraw(view, intent.token, intent.amount, intent.to);
|
|
20
23
|
}
|
|
21
24
|
/** Intent 6: collateral fixed, debt retargeted to `C0 · (L1 − 1)`. */
|
|
22
25
|
function planAdjustLeverage(intent, view) {
|
|
@@ -25,21 +28,22 @@ function planAdjustLeverage(intent, view) {
|
|
|
25
28
|
const T = intent.token ?? positionToken(view, "adjustLeverage");
|
|
26
29
|
if (delta > 0n) return [borrow(delta), convert(U, T, delta)];
|
|
27
30
|
const shortfall = -delta - view.balanceOf(U);
|
|
28
|
-
if (shortfall > 0n && require_onchain_accounts_intents_utils_common.eq(T, U)) throw new
|
|
29
|
-
required:
|
|
30
|
-
held:
|
|
31
|
-
|
|
31
|
+
if (shortfall > 0n && require_onchain_accounts_intents_utils_common.eq(T, U)) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_operation_errors.insufficientBalance({
|
|
32
|
+
required: require_onchain_validation_helpers_token.toTokenAmount(view.sdk, U, -delta),
|
|
33
|
+
held: require_onchain_validation_helpers_token.toTokenAmount(view.sdk, U, view.balanceOf(U)),
|
|
34
|
+
holderKind: "creditAccount"
|
|
35
|
+
}), `adjustLeverage: needs ${-delta} underlying, account holds ${view.balanceOf(U)}`);
|
|
32
36
|
return [...shortfall > 0n ? [convert(T, U, view.price(U, T, shortfall))] : [], repay(-delta)];
|
|
33
37
|
}
|
|
34
38
|
/** Intents 1.1 / 1.2: collateral grows by `a`, debt grows to match. */
|
|
35
39
|
function planDeposit(intent, view) {
|
|
36
40
|
assertPositive(intent.amount, "deposit");
|
|
37
41
|
const U = view.underlying;
|
|
38
|
-
if (!require_onchain_accounts_intents_utils_common.eq(intent.token, U) && !(view.rwaAsset && require_onchain_accounts_intents_utils_common.eq(intent.token, view.rwaAsset))) throw new
|
|
42
|
+
if (!require_onchain_accounts_intents_utils_common.eq(intent.token, U) && !(view.rwaAsset && require_onchain_accounts_intents_utils_common.eq(intent.token, view.rwaAsset))) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_prepare_errors.unsupportedCollateralToken(require_onchain_validation_helpers_token.toToken(view.sdk, intent.token)), `deposit: only ${U}${view.rwaAsset ? ` or ${view.rwaAsset}` : ""} can be deposited, got ${intent.token}`);
|
|
39
43
|
const aU = view.price(intent.token, U, intent.amount);
|
|
40
44
|
const debtDelta = intent.targetLeverage === void 0 ? require_onchain_accounts_intents_math.proportionalDebt(view, aU) : require_onchain_accounts_intents_math.debtForLeverage(view.collateral + aU, intent.targetLeverage) - view.debt;
|
|
41
|
-
if (debtDelta < 0n) throw new
|
|
42
|
-
require_onchain_accounts_intents_math.
|
|
45
|
+
if (debtDelta < 0n) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_operation_errors.leverageOutOfRange(), `deposit: target leverage ${intent.targetLeverage} would require repaying debt`);
|
|
46
|
+
require_onchain_accounts_intents_math.assertDebtLimits(view.sdk, view.debt + debtDelta, view.debtLimits, U);
|
|
43
47
|
const T = intent.positionToken ?? positionToken(view, "deposit");
|
|
44
48
|
const depositStays = require_onchain_accounts_intents_utils_common.eq(intent.token, T);
|
|
45
49
|
return [
|
|
@@ -66,15 +70,15 @@ function planRepay(intent, view) {
|
|
|
66
70
|
assertPositive(intent.amount, "repay");
|
|
67
71
|
const U = view.underlying;
|
|
68
72
|
const fundsInU = require_onchain_accounts_intents_utils_common.eq(intent.token, U);
|
|
69
|
-
if (!fundsInU && !(view.rwaAsset && require_onchain_accounts_intents_utils_common.eq(intent.token, view.rwaAsset))) throw new
|
|
70
|
-
if (view.debt <= 0n) throw new
|
|
71
|
-
requested:
|
|
72
|
-
minDebt:
|
|
73
|
-
maxDebt:
|
|
74
|
-
}, "repay: the account owes nothing");
|
|
73
|
+
if (!fundsInU && !(view.rwaAsset && require_onchain_accounts_intents_utils_common.eq(intent.token, view.rwaAsset))) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_prepare_errors.unsupportedCollateralToken(require_onchain_validation_helpers_token.toToken(view.sdk, intent.token)), `repay: only ${U}${view.rwaAsset ? ` or ${view.rwaAsset}` : ""} can be repaid with, got ${intent.token}`);
|
|
74
|
+
if (view.debt <= 0n) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_operation_errors.debtOutOfRange({
|
|
75
|
+
requested: require_onchain_validation_helpers_token.toTokenAmount(view.sdk, U, view.debt),
|
|
76
|
+
minDebt: require_onchain_validation_helpers_token.toTokenAmount(view.sdk, U, view.debtLimits.minDebt),
|
|
77
|
+
maxDebt: require_onchain_validation_helpers_token.toTokenAmount(view.sdk, U, view.debtLimits.maxDebt)
|
|
78
|
+
}), "repay: the account owes nothing");
|
|
75
79
|
const funding = everything(intent.amount) ? view.price(U, intent.token, withMargin(view.debt)) : intent.amount;
|
|
76
80
|
const repaid = min(view.price(intent.token, U, funding), view.debt);
|
|
77
|
-
require_onchain_accounts_intents_math.
|
|
81
|
+
require_onchain_accounts_intents_math.assertDebtLimits(view.sdk, view.debt - repaid, view.debtLimits, view.underlying);
|
|
78
82
|
return [
|
|
79
83
|
add(intent.token, funding, intent.value),
|
|
80
84
|
...fundsInU ? [] : [convert(intent.token, U, funding)],
|
|
@@ -100,21 +104,21 @@ function planWithdraw(intent, view) {
|
|
|
100
104
|
if (require_onchain_accounts_intents_utils_common.eq(T, U)) return [
|
|
101
105
|
convert(S, U, view.price(U, S, WU + dD)),
|
|
102
106
|
repay(dD, intent.amount),
|
|
103
|
-
...
|
|
107
|
+
...withdraw(view, U, intent.amount, intent.to)
|
|
104
108
|
];
|
|
105
109
|
return [
|
|
106
110
|
convert(S, U, view.price(U, S, dD)),
|
|
107
111
|
repay(dD),
|
|
108
112
|
convert(S, T, view.price(U, S, WU)),
|
|
109
|
-
...
|
|
113
|
+
...withdraw(view, T, RAISED, intent.to)
|
|
110
114
|
];
|
|
111
115
|
}
|
|
112
116
|
/**
|
|
113
117
|
* Intent 2.1 against a source that cannot be sold on a DEX.
|
|
114
118
|
*
|
|
115
119
|
* Some collateral only converts through its issuer — a Securitize dsToken, a
|
|
116
|
-
* Mellow share — which answers a redemption request now and
|
|
117
|
-
* later. The trade is unchanged; what changes is that the
|
|
120
|
+
* Mellow share — which answers a redemption request now and settles days
|
|
121
|
+
* later. The trade is unchanged; what changes is that the money does not exist
|
|
118
122
|
* yet, so this half only requests the redemption:
|
|
119
123
|
*
|
|
120
124
|
* ```
|
|
@@ -130,7 +134,7 @@ function planWithdrawDelayed(intent, view) {
|
|
|
130
134
|
const { U, T, S, WU, dD, all } = withdrawShape(intent, view);
|
|
131
135
|
if (all) {
|
|
132
136
|
const held = view.balanceOf(S);
|
|
133
|
-
if (held <= 0n) throw new
|
|
137
|
+
if (held <= 0n) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_operation_errors.insufficientBalance(), `withdraw: account holds no ${S} to redeem`);
|
|
134
138
|
return [{
|
|
135
139
|
kind: "request",
|
|
136
140
|
token: S,
|
|
@@ -142,13 +146,13 @@ function planWithdrawDelayed(intent, view) {
|
|
|
142
146
|
}
|
|
143
147
|
}];
|
|
144
148
|
}
|
|
145
|
-
if (!require_onchain_accounts_intents_utils_common.eq(T, U) && !(view.rwaAsset && require_onchain_accounts_intents_utils_common.eq(T, view.rwaAsset))) throw new
|
|
146
|
-
const
|
|
149
|
+
if (!require_onchain_accounts_intents_utils_common.eq(T, U) && !(view.rwaAsset && require_onchain_accounts_intents_utils_common.eq(T, view.rwaAsset))) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_prepare_errors.noDelayedRoute(require_onchain_validation_helpers_token.toToken(view.sdk, T)), `withdraw: a delayed route cannot withdraw in ${T}`);
|
|
150
|
+
const tokenOutIsSource = require_onchain_accounts_intents_utils_common.eq(T, S);
|
|
147
151
|
return [{
|
|
148
152
|
kind: "request",
|
|
149
153
|
token: S,
|
|
150
|
-
amount: view.price(U, S,
|
|
151
|
-
reserve:
|
|
154
|
+
amount: view.price(U, S, tokenOutIsSource ? dD : WU + dD),
|
|
155
|
+
reserve: tokenOutIsSource ? intent.amount : 0n,
|
|
152
156
|
record: {
|
|
153
157
|
type: "WITHDRAW_COLLATERAL",
|
|
154
158
|
to: intent.to,
|
|
@@ -168,9 +172,9 @@ function planWithdrawDelayed(intent, view) {
|
|
|
168
172
|
*/
|
|
169
173
|
function planAdjustLeverageDelayed(intent, view) {
|
|
170
174
|
const { U, delta } = leverageShape(intent, view);
|
|
171
|
-
if (delta >= 0n) throw new
|
|
175
|
+
if (delta >= 0n) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_prepare_errors.noDelayedRoute(), "adjustLeverage: only deleveraging can settle with a delay");
|
|
172
176
|
const shortfall = -delta - view.balanceOf(U);
|
|
173
|
-
if (shortfall <= 0n) throw new
|
|
177
|
+
if (shortfall <= 0n) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_prepare_errors.noDelayedRoute(), "adjustLeverage: idle underlying covers the repayment, nothing to redeem");
|
|
174
178
|
const T = intent.token ?? positionToken(view, "adjustLeverage");
|
|
175
179
|
return [{
|
|
176
180
|
kind: "request",
|
|
@@ -189,20 +193,20 @@ function planFinishDecreaseLeverage(claimable, claimed, view) {
|
|
|
189
193
|
];
|
|
190
194
|
}
|
|
191
195
|
/**
|
|
192
|
-
* The claim is split between the promised
|
|
193
|
-
* half deferred:
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
+
* The claim is split between the promised withdrawal `W` and the debt the
|
|
197
|
+
* leading half deferred: `W` is served first, the debt gets what is left, so a
|
|
198
|
+
* bad quote shows as leverage a touch above target rather than as a wallet paid
|
|
199
|
+
* less than it was promised.
|
|
196
200
|
*/
|
|
197
201
|
function planFinishWithdraw(intent, claimable, claimed, view) {
|
|
198
202
|
const U = view.underlying;
|
|
199
203
|
const T = intent.withdrawToken;
|
|
200
204
|
const W = intent.withdrawAmount;
|
|
201
|
-
if (!require_onchain_accounts_intents_utils_common.eq(T, U) && !(view.rwaAsset && require_onchain_accounts_intents_utils_common.eq(T, view.rwaAsset))) throw new
|
|
205
|
+
if (!require_onchain_accounts_intents_utils_common.eq(T, U) && !(view.rwaAsset && require_onchain_accounts_intents_utils_common.eq(T, view.rwaAsset))) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_prepare_errors.noDelayedRoute(require_onchain_validation_helpers_token.toToken(view.sdk, T)), `finishWithdraw: cannot withdraw in ${T}`);
|
|
202
206
|
if (intent.debtRepaid === 0n) return [
|
|
203
207
|
claim(claimable),
|
|
204
208
|
convert(claimed.token, T, claimed.amount),
|
|
205
|
-
...
|
|
209
|
+
...withdraw(view, T, {
|
|
206
210
|
raised: true,
|
|
207
211
|
max: W
|
|
208
212
|
}, intent.to)
|
|
@@ -214,13 +218,13 @@ function planFinishWithdraw(intent, claimable, claimed, view) {
|
|
|
214
218
|
raised: true,
|
|
215
219
|
max: intent.debtRepaid
|
|
216
220
|
}),
|
|
217
|
-
...
|
|
221
|
+
...withdraw(view, T, W, intent.to)
|
|
218
222
|
];
|
|
219
223
|
if (require_onchain_accounts_intents_utils_common.eq(T, U)) return [
|
|
220
224
|
claim(claimable),
|
|
221
225
|
convert(claimed.token, U, claimed.amount),
|
|
222
226
|
repay(intent.debtRepaid, W),
|
|
223
|
-
...
|
|
227
|
+
...withdraw(view, U, {
|
|
224
228
|
raised: true,
|
|
225
229
|
max: W
|
|
226
230
|
}, intent.to)
|
|
@@ -234,7 +238,7 @@ function planFinishWithdraw(intent, claimable, claimed, view) {
|
|
|
234
238
|
max: intent.debtRepaid
|
|
235
239
|
}),
|
|
236
240
|
convert(claimed.token, T, reserved),
|
|
237
|
-
...
|
|
241
|
+
...withdraw(view, T, {
|
|
238
242
|
raised: true,
|
|
239
243
|
max: W
|
|
240
244
|
}, intent.to)
|
|
@@ -242,7 +246,7 @@ function planFinishWithdraw(intent, claimable, claimed, view) {
|
|
|
242
246
|
}
|
|
243
247
|
/**
|
|
244
248
|
* The tail of an exit: the claim lands, everything the account holds is sold
|
|
245
|
-
* into the underlying, the loan is settled out of
|
|
249
|
+
* into the underlying, the loan is settled out of what it sells for and the rest
|
|
246
250
|
* goes to the wallet. The account survives it, empty and owing nothing.
|
|
247
251
|
*
|
|
248
252
|
* Nothing is quoted from the request — the same shape {@link planWithdraw}
|
|
@@ -268,7 +272,7 @@ function planFinishClaimOnly(claimable) {
|
|
|
268
272
|
return [claim(claimable)];
|
|
269
273
|
}
|
|
270
274
|
/**
|
|
271
|
-
* What a withdrawal comes down to: the
|
|
275
|
+
* What a withdrawal comes down to: the withdrawal `W` of `T` priced in the
|
|
272
276
|
* underlying, the debt `dD` that keeps leverage flat, and the source `S` both
|
|
273
277
|
* are funded from. Shared so that the instant and the delayed leading half
|
|
274
278
|
* cannot disagree on the amounts.
|
|
@@ -290,7 +294,7 @@ function withdrawShape(intent, view) {
|
|
|
290
294
|
};
|
|
291
295
|
}
|
|
292
296
|
const WU = view.price(T, U, intent.amount);
|
|
293
|
-
if (WU <= 0n) throw new
|
|
297
|
+
if (WU <= 0n) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_operation_errors.insufficientBalance(), `withdraw: cannot price ${intent.amount} of ${T}`);
|
|
294
298
|
if (WU >= view.collateral) {
|
|
295
299
|
assertHasValue(view);
|
|
296
300
|
return {
|
|
@@ -303,7 +307,7 @@ function withdrawShape(intent, view) {
|
|
|
303
307
|
};
|
|
304
308
|
}
|
|
305
309
|
const dD = require_onchain_accounts_intents_math.proportionalDebt(view, WU);
|
|
306
|
-
require_onchain_accounts_intents_math.
|
|
310
|
+
require_onchain_accounts_intents_math.assertDebtLimits(view.sdk, view.debt - dD, view.debtLimits, view.underlying);
|
|
307
311
|
return {
|
|
308
312
|
U,
|
|
309
313
|
T,
|
|
@@ -320,9 +324,9 @@ function withdrawShape(intent, view) {
|
|
|
320
324
|
*/
|
|
321
325
|
function leverageShape(intent, view) {
|
|
322
326
|
require_onchain_accounts_intents_math.assertLeverageAtLeastOne(intent.targetLeverage);
|
|
323
|
-
if (view.collateral <= 0n) throw new
|
|
327
|
+
if (view.collateral <= 0n) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_operation_errors.insufficientBalance(), "adjustLeverage: account has no collateral to lever");
|
|
324
328
|
const target = require_onchain_accounts_intents_math.debtForLeverage(view.collateral, intent.targetLeverage);
|
|
325
|
-
require_onchain_accounts_intents_math.
|
|
329
|
+
require_onchain_accounts_intents_math.assertDebtLimits(view.sdk, target, view.debtLimits, view.underlying);
|
|
326
330
|
return {
|
|
327
331
|
U: view.underlying,
|
|
328
332
|
delta: target - view.debt
|
|
@@ -372,7 +376,7 @@ const min = (a, b) => a < b ? a : b;
|
|
|
372
376
|
* Hands `amount` of `token` to `to`. The wrapped underlying of an RWA market
|
|
373
377
|
* cannot leave the account, so it is unwrapped into the raw asset on the way.
|
|
374
378
|
*/
|
|
375
|
-
function
|
|
379
|
+
function withdraw(view, token, amount, to) {
|
|
376
380
|
if (view.rwaAsset && require_onchain_accounts_intents_utils_common.eq(token, view.underlying)) return [convert(view.underlying, view.rwaAsset, amount), {
|
|
377
381
|
kind: "withdraw",
|
|
378
382
|
token: view.rwaAsset,
|
|
@@ -388,20 +392,20 @@ function payout(view, token, amount, to) {
|
|
|
388
392
|
}
|
|
389
393
|
function positionToken(view, flow) {
|
|
390
394
|
const pick = view.fattest([view.underlying]);
|
|
391
|
-
if (!pick) throw new
|
|
395
|
+
if (!pick) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_operation_errors.insufficientBalance(), `${flow}: no position token on the account`);
|
|
392
396
|
return pick;
|
|
393
397
|
}
|
|
394
398
|
function sourceToken(view) {
|
|
395
399
|
const pick = view.fattest();
|
|
396
|
-
if (!pick) throw new
|
|
400
|
+
if (!pick) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_operation_errors.insufficientBalance(), "withdraw: account has no spendable balance");
|
|
397
401
|
return pick;
|
|
398
402
|
}
|
|
399
403
|
/** An account whose debt has eaten its collateral has nothing to hand over. */
|
|
400
404
|
function assertHasValue(view) {
|
|
401
|
-
if (view.collateral <= 0n) throw new
|
|
405
|
+
if (view.collateral <= 0n) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_operation_errors.insufficientBalance(), `withdraw: nothing to withdraw, net value is ${view.collateral}`);
|
|
402
406
|
}
|
|
403
407
|
function assertPositive(amount, flow) {
|
|
404
|
-
if (amount <= 0n) throw new
|
|
408
|
+
if (amount <= 0n) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_operation_errors.insufficientBalance(), `${flow}: amount must be positive`);
|
|
405
409
|
}
|
|
406
410
|
//#endregion
|
|
407
411
|
exports.RAISED = RAISED;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
3
|
-
const
|
|
2
|
+
const require_model_errors_operation_errors = require("../../../model/errors/operation-errors.js");
|
|
3
|
+
const require_model_errors_prepare_errors = require("../../../model/errors/prepare-errors.js");
|
|
4
|
+
require("../../../model/index.js");
|
|
5
|
+
const require_onchain_validation_helpers_token = require("../../validation/helpers/token.js");
|
|
6
|
+
const require_onchain_validation_raise = require("../../validation/raise.js");
|
|
4
7
|
const require_onchain_accounts_intents_utils_common = require("./utils/common.js");
|
|
5
8
|
const require_onchain_accounts_intents_utils_pick_token = require("./utils/pick-token.js");
|
|
6
9
|
const require_onchain_accounts_intents_guards = require("./guards.js");
|
|
@@ -42,8 +45,8 @@ async function realize(steps, props) {
|
|
|
42
45
|
* The floor: every routed leg counted at the amount it guarantees. This is
|
|
43
46
|
* what the calls are built from — a repayment may only spend underlying the
|
|
44
47
|
* route promises to have raised — and what the guards are answered on, since
|
|
45
|
-
* a floor that does not clear the facade's
|
|
46
|
-
* revert.
|
|
48
|
+
* a floor that does not clear the facade's threshold is a transaction that
|
|
49
|
+
* can revert.
|
|
47
50
|
*/
|
|
48
51
|
const ledger = new require_onchain_accounts_intents_utils_ledger.OperationLedger(start);
|
|
49
52
|
/**
|
|
@@ -78,14 +81,16 @@ async function realize(steps, props) {
|
|
|
78
81
|
* Whether anything leaves the account, which is what makes the credit manager
|
|
79
82
|
* judge the closing collateral check at safe prices.
|
|
80
83
|
*/
|
|
81
|
-
let
|
|
84
|
+
let withdrawsCollateral = false;
|
|
82
85
|
const amountOf = (a) => typeof a === "bigint" ? a : min(raised, a.max ?? raised);
|
|
83
86
|
const assertHolds = (token, amount, what) => {
|
|
84
87
|
const held = ledger.balanceOf(token);
|
|
85
|
-
if (amount <= 0n || held < amount) throw new
|
|
86
|
-
required:
|
|
87
|
-
held:
|
|
88
|
-
|
|
88
|
+
if (amount <= 0n || held < amount) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_operation_errors.insufficientBalance({
|
|
89
|
+
required: require_onchain_validation_helpers_token.toTokenAmount(sdk, token, amount),
|
|
90
|
+
held: require_onchain_validation_helpers_token.toTokenAmount(sdk, token, held),
|
|
91
|
+
holderKind: "creditAccount",
|
|
92
|
+
holder: creditAccount.creditAccount
|
|
93
|
+
}), `${what}: needs ${amount} of ${token}, account holds ${held}`);
|
|
89
94
|
};
|
|
90
95
|
for (const step of steps) switch (step.kind) {
|
|
91
96
|
case "add":
|
|
@@ -174,7 +179,7 @@ async function realize(steps, props) {
|
|
|
174
179
|
case "closeAll": {
|
|
175
180
|
const balances = ledger.snapshot().assets.filter((a) => !require_onchain_accounts_intents_utils_common.eq(a.token, underlying) && a.balance > DUST);
|
|
176
181
|
const pending = balances.find((a) => require_onchain_accounts_intents_utils_pick_token.isRedemptionPhantomToken(sdk, a.token));
|
|
177
|
-
if (pending) throw new
|
|
182
|
+
if (pending) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_prepare_errors.withdrawalInProgress(require_onchain_validation_helpers_token.toTokenAmount(sdk, pending.token, pending.balance)), `closeAll: ${pending.token} is a pending withdrawal, claim it first`);
|
|
178
183
|
if (balances.length > 0) {
|
|
179
184
|
const leg = await paths.closeAll({ balances });
|
|
180
185
|
if (leg.probe) probes.push(leg.probe);
|
|
@@ -201,7 +206,7 @@ async function realize(steps, props) {
|
|
|
201
206
|
case "withdraw": {
|
|
202
207
|
const amount = amountOf(step.amount);
|
|
203
208
|
assertHolds(step.token, amount, "withdraw");
|
|
204
|
-
|
|
209
|
+
withdrawsCollateral = true;
|
|
205
210
|
push(require_onchain_accounts_intents_operations.buildWithdrawCollateralOperation({
|
|
206
211
|
token: step.token,
|
|
207
212
|
amount,
|
|
@@ -213,7 +218,7 @@ async function realize(steps, props) {
|
|
|
213
218
|
}
|
|
214
219
|
case "request": {
|
|
215
220
|
const asset = await delayedConfig(sdk, creditAccount, step.token);
|
|
216
|
-
if (ledger.balanceOf(asset.withdrawalPhantomToken) > 0n) throw new
|
|
221
|
+
if (ledger.balanceOf(asset.withdrawalPhantomToken) > 0n) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_prepare_errors.withdrawalInProgress(require_onchain_validation_helpers_token.toTokenAmount(sdk, asset.withdrawalPhantomToken, ledger.balanceOf(asset.withdrawalPhantomToken))), `request: ${asset.withdrawalPhantomToken} already holds a pending withdrawal`);
|
|
217
222
|
assertHolds(step.token, step.amount + step.reserve, "request");
|
|
218
223
|
const preview = await sdk.accounts.previewDelayedWithdrawal({
|
|
219
224
|
creditAccount: creditAccount.creditAccount,
|
|
@@ -249,7 +254,7 @@ async function realize(steps, props) {
|
|
|
249
254
|
raised = require_onchain_accounts_intents_operations.instantOutput(step.claimable.outputs)?.amount ?? 0n;
|
|
250
255
|
break;
|
|
251
256
|
case "sweep": {
|
|
252
|
-
|
|
257
|
+
withdrawsCollateral = true;
|
|
253
258
|
const wrapped = ledger.balanceOf(underlying);
|
|
254
259
|
if (rwaAsset && wrapped > 0n) push(await require_onchain_accounts_intents_operations.buildUnwrapRwaCollateralOperation({
|
|
255
260
|
tokenIn: underlying,
|
|
@@ -260,7 +265,7 @@ async function realize(steps, props) {
|
|
|
260
265
|
sdk
|
|
261
266
|
}));
|
|
262
267
|
for (const { token, balance } of ledger.snapshot().assets) {
|
|
263
|
-
const
|
|
268
|
+
const withdrawal = require_onchain_accounts_intents_operations.buildWithdrawCollateralOperation({
|
|
264
269
|
token,
|
|
265
270
|
amount: balance,
|
|
266
271
|
to: step.to,
|
|
@@ -268,8 +273,8 @@ async function realize(steps, props) {
|
|
|
268
273
|
creditAccount,
|
|
269
274
|
sdk
|
|
270
275
|
});
|
|
271
|
-
push(
|
|
272
|
-
...
|
|
276
|
+
push(withdrawal, {
|
|
277
|
+
...withdrawal,
|
|
273
278
|
amount: expected.balanceOf(token)
|
|
274
279
|
});
|
|
275
280
|
}
|
|
@@ -298,7 +303,7 @@ async function realize(steps, props) {
|
|
|
298
303
|
convert: price
|
|
299
304
|
});
|
|
300
305
|
if (!cleared && quotas.quotaIncrease.length + quotas.quotaDecrease.length > 0) {
|
|
301
|
-
require_onchain_accounts_intents_guards.
|
|
306
|
+
require_onchain_accounts_intents_guards.assertQuotaAvailable(sdk, market, quotas.quotaIncrease);
|
|
302
307
|
push(require_onchain_accounts_intents_operations.buildQuotaUpdateOperation({
|
|
303
308
|
update: quotas,
|
|
304
309
|
creditAccount,
|
|
@@ -319,7 +324,7 @@ async function realize(steps, props) {
|
|
|
319
324
|
...snapshot,
|
|
320
325
|
assets,
|
|
321
326
|
totalValue: floor.totalValue
|
|
322
|
-
}, { safePrices:
|
|
327
|
+
}, { safePrices: withdrawsCollateral }), withdrawsCollateral);
|
|
323
328
|
const priceImpact = await require_onchain_accounts_intents_utils_price_impact.collectPriceImpact(probes, {
|
|
324
329
|
totalValue: projected.totalValue,
|
|
325
330
|
netValue: projected.totalValue - debt,
|
|
@@ -348,13 +353,10 @@ async function realize(steps, props) {
|
|
|
348
353
|
*/
|
|
349
354
|
async function delayedConfig(sdk, creditAccount, token) {
|
|
350
355
|
const compressor = sdk.withdrawalCompressor;
|
|
351
|
-
if (!compressor) throw new
|
|
356
|
+
if (!compressor) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_prepare_errors.noDelayedRoute(require_onchain_validation_helpers_token.toToken(sdk, token)), "request: chain has no withdrawal compressor");
|
|
352
357
|
const assets = await compressor.findWithdrawableAssets(creditAccount.creditManager, token);
|
|
353
|
-
if (assets.length === 0) throw new
|
|
354
|
-
if (assets.length > 1) throw new
|
|
355
|
-
token: require_onchain_validation_token.toToken(sdk, token),
|
|
356
|
-
venues: assets.length
|
|
357
|
-
}, `request: ${token} has ${assets.length} delayed withdrawal configs`);
|
|
358
|
+
if (assets.length === 0) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_prepare_errors.noDelayedRoute(require_onchain_validation_helpers_token.toToken(sdk, token)), `request: ${token} has no delayed withdrawal config`);
|
|
359
|
+
if (assets.length > 1) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_prepare_errors.multipleDelayedWithdrawals(require_onchain_validation_helpers_token.toToken(sdk, token), assets.length), `request: ${token} has ${assets.length} delayed withdrawal configs`);
|
|
358
360
|
return assets[0];
|
|
359
361
|
}
|
|
360
362
|
const callsOf = (operations) => operations.flatMap((op) => op.calls);
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
3
|
-
const
|
|
2
|
+
const require_model_errors_operation_errors = require("../../../model/errors/operation-errors.js");
|
|
3
|
+
const require_model_errors_prepare_errors = require("../../../model/errors/prepare-errors.js");
|
|
4
|
+
require("../../../model/index.js");
|
|
5
|
+
const require_onchain_validation_helpers_token = require("../../validation/helpers/token.js");
|
|
6
|
+
const require_onchain_validation_raise = require("../../validation/raise.js");
|
|
4
7
|
const require_onchain_accounts_intents_utils_common = require("./utils/common.js");
|
|
5
8
|
const require_onchain_accounts_intents_utils_router_path = require("./utils/router-path.js");
|
|
6
9
|
const require_onchain_accounts_intents_plan = require("./plan.js");
|
|
@@ -17,14 +20,14 @@ const require_onchain_accounts_intents_view = require("./view.js");
|
|
|
17
20
|
* tail as it is projected the moment the request is made.
|
|
18
21
|
*
|
|
19
22
|
* A claim that brought only part of what was queued is served in proportion,
|
|
20
|
-
* see {@link partialTail}: the intent's
|
|
23
|
+
* see {@link partialTail}: the intent's withdrawal and its repayment are cut to the
|
|
21
24
|
* share that arrived, and the rest of both is handed to the next claim.
|
|
22
25
|
*/
|
|
23
26
|
function planTail(args) {
|
|
24
27
|
const { intent, claimable, view } = args;
|
|
25
28
|
const claimed = () => {
|
|
26
29
|
const output = require_onchain_accounts_intents_operations.instantOutput(claimable.outputs);
|
|
27
|
-
if (!output) throw new
|
|
30
|
+
if (!output) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_operation_errors.insufficientBalance(), "finishIntent: the claim credits nothing to spend");
|
|
28
31
|
return output;
|
|
29
32
|
};
|
|
30
33
|
const queued = claimable.outputs.find((o) => o.isDelayed && o.amount > 0n);
|
|
@@ -52,12 +55,12 @@ const whole = (steps) => ({
|
|
|
52
55
|
/**
|
|
53
56
|
* The tail of a claim that settled only part of the withdrawal it matured.
|
|
54
57
|
*
|
|
55
|
-
* Only a legacy Mellow multivault answers one this way — it
|
|
58
|
+
* Only a legacy Mellow multivault answers one this way — it hands over what its
|
|
56
59
|
* subvaults hold liquid and queues the rest — and the engine cannot finish an
|
|
57
60
|
* intent it has been given a fraction of the funds for. So the fraction is what
|
|
58
|
-
* it serves: the
|
|
61
|
+
* it serves: the withdrawal and the repayment are cut in the proportion that
|
|
59
62
|
* arrived, which keeps the withdrawal at the fixed leverage it was asked for
|
|
60
|
-
* instead of paying the wallet
|
|
63
|
+
* instead of paying the wallet first and deleveraging a claim later, and
|
|
61
64
|
* the untouched half of each is carried to the next claim by the remainder.
|
|
62
65
|
*
|
|
63
66
|
* Two intents cannot be served in part at all. An exit sells the account whole,
|
|
@@ -69,7 +72,7 @@ const whole = (steps) => ({
|
|
|
69
72
|
*/
|
|
70
73
|
function partialTail(args) {
|
|
71
74
|
const { intent, claimable, queued, view } = args;
|
|
72
|
-
const inFlight =
|
|
75
|
+
const inFlight = require_onchain_validation_helpers_token.toTokenAmount(view.sdk, queued.token, queued.amount);
|
|
73
76
|
const claimed = require_onchain_accounts_intents_operations.instantOutput(claimable.outputs);
|
|
74
77
|
if (!claimed) return {
|
|
75
78
|
steps: require_onchain_accounts_intents_plan.planFinishClaimOnly(claimable),
|
|
@@ -124,7 +127,7 @@ function partialTail(args) {
|
|
|
124
127
|
* How much of the redemption this claim was: what it credited, over that plus
|
|
125
128
|
* what it left queued.
|
|
126
129
|
*
|
|
127
|
-
* The phantom stands for its
|
|
130
|
+
* The phantom stands for its claim one for one — the same reading the request
|
|
128
131
|
* side takes when it names the claim it expects — so only the decimals of the
|
|
129
132
|
* two have to be reconciled before they can be added up.
|
|
130
133
|
*/
|
|
@@ -144,7 +147,7 @@ function part(amount, share) {
|
|
|
144
147
|
*
|
|
145
148
|
* A request is only half a withdrawal, so the state it lands in is not the
|
|
146
149
|
* answer to "what does this do to my position": the debt is still there, the
|
|
147
|
-
*
|
|
150
|
+
* withdrawal has not been made, and the position sits in a phantom token. What the
|
|
148
151
|
* caller means is the far side — and that side can be walked now, because the
|
|
149
152
|
* request already fixes the claim it will be finished from.
|
|
150
153
|
*
|
|
@@ -161,7 +164,7 @@ async function projectTail(args) {
|
|
|
161
164
|
const { request, delayed, creditAccount, sdk, quotaReserve } = args;
|
|
162
165
|
const { claim } = delayed;
|
|
163
166
|
const queued = request.outputs.find((o) => o.isDelayed);
|
|
164
|
-
if (!queued || !claim) throw new
|
|
167
|
+
if (!queued || !claim) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_prepare_errors.noRecordedIntent(), "projectTail: the request queued nothing to claim");
|
|
165
168
|
const next = sliceAfter(creditAccount, delayed.afterRequest);
|
|
166
169
|
const { steps } = planTail({
|
|
167
170
|
intent: delayed.record,
|
|
@@ -185,7 +188,7 @@ async function projectTail(args) {
|
|
|
185
188
|
}
|
|
186
189
|
/**
|
|
187
190
|
* The matured withdrawal the tail will be built from, as the request implies
|
|
188
|
-
* it: the phantom it created is burned and the
|
|
191
|
+
* it: the phantom it created is burned and the claim takes its place.
|
|
189
192
|
* It carries no claim calls — those are read from the chain when the claim is
|
|
190
193
|
* real, and nothing here is going to be sent.
|
|
191
194
|
*/
|
|
@@ -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: require_onchain_market_credit_CreditSuite.CreditSuite.prototype.totalLiquidationDiscount,
|
|
193
198
|
creditOperationMarket: require_onchain_market_credit_CreditSuite.CreditSuite.prototype.creditOperationMarket,
|
|
199
|
+
isForbidden: require_onchain_market_credit_CreditSuite.CreditSuite.prototype.isForbidden,
|
|
200
|
+
maxBorrowAmount: require_onchain_market_credit_CreditSuite.CreditSuite.prototype.maxBorrowAmount,
|
|
194
201
|
creditManager: {
|
|
195
202
|
address: args.creditManager,
|
|
196
203
|
liquidationThresholds,
|