@gearbox-protocol/sdk 16.2.0 → 16.3.0-next.2
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/abi/rwa/iMidasAccessControl.js +23 -0
- package/dist/cjs/abi/rwa/iMidasDegenNFT.js +92 -0
- 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 +45 -2
- package/dist/cjs/model/opportunities.schema.js +3 -1
- package/dist/cjs/model/positions.js +1 -1
- package/dist/cjs/model/result.js +0 -8
- package/dist/cjs/model/rwa.js +53 -0
- package/dist/cjs/model/rwa.schema.js +20 -0
- package/dist/cjs/offchain/opportunities/OffchainOpportunities.js +1 -1
- 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 +6 -4
- 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/liquidations/LiquidationsService.js +2 -2
- package/dist/cjs/onchain/accounts/withdrawal-compressor/index.js +0 -1
- package/dist/cjs/onchain/index.js +130 -38
- package/dist/cjs/onchain/market/MarketSuite.js +10 -4
- package/dist/cjs/onchain/market/adapters/index.js +1 -0
- package/dist/cjs/onchain/market/credit/CreditSuite.js +77 -15
- package/dist/cjs/onchain/market/index.js +8 -8
- 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/createDegenNFT.js +53 -0
- package/dist/cjs/onchain/market/rwa/index.js +7 -5
- package/dist/cjs/onchain/market/rwa/midas/MidasDegenNFT.js +56 -0
- package/dist/cjs/onchain/market/rwa/midas/constants.js +2 -0
- package/dist/cjs/onchain/market/rwa/midas/index.js +3 -0
- package/dist/cjs/onchain/market/rwa/securitize/SecuritizeDegenNFT.js +22 -3
- package/dist/cjs/onchain/market/rwa/securitize/SecuritizeRWAFactory.js +9 -9
- package/dist/cjs/onchain/market/rwa/securitize/constants.js +2 -2
- package/dist/cjs/onchain/market/rwa/securitize/index.js +4 -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/opportunities/MultichainOpportunitiesService.js +2 -2
- package/dist/cjs/onchain/opportunities/OpportunitiesService.js +11 -3
- 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/index.js +6 -11
- package/dist/cjs/sdk/liquidations/LiquidationsNamespace.js +9 -0
- package/dist/cjs/sdk/opportunities/OpportunitiesNamespace.js +19 -4
- package/dist/cjs/sdk/prepare/PrepareApi.js +40 -50
- package/dist/cjs/sdk/prepare/index.js +7 -11
- package/dist/cjs/sdk/prepare/types.js +0 -4
- package/dist/cjs/sdk/preview/PreviewNamespace.js +24 -13
- package/dist/esm/abi/rwa/iMidasAccessControl.js +22 -0
- package/dist/esm/abi/rwa/iMidasDegenNFT.js +91 -0
- package/dist/esm/dev/AccountOpener.js +1 -1
- package/dist/esm/dev/withdrawalUtils.js +1 -1
- 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 +2 -2
- 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 +10 -3
- package/dist/esm/model/opportunities.schema.js +3 -1
- package/dist/esm/model/positions.js +1 -1
- package/dist/esm/model/result.js +1 -8
- package/dist/esm/model/rwa.js +48 -0
- package/dist/esm/model/rwa.schema.js +18 -0
- package/dist/esm/offchain/opportunities/OffchainOpportunities.js +1 -1
- 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 +8 -6
- 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/liquidations/LiquidationsService.js +3 -3
- package/dist/esm/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/index.js +0 -1
- package/dist/esm/onchain/base/TokensMeta.js +3 -3
- package/dist/esm/onchain/core/createAddressProvider.js +1 -1
- package/dist/esm/onchain/index.js +64 -11
- package/dist/esm/onchain/market/MarketSuite.js +10 -4
- package/dist/esm/onchain/market/adapters/contracts/AccountMigratorAdapterContract.js +1 -1
- package/dist/esm/onchain/market/adapters/contracts/ERC4626AdapterContract.js +1 -1
- package/dist/esm/onchain/market/adapters/index.js +1 -0
- package/dist/esm/onchain/market/credit/CreditFacadeV310BaseContract.js +1 -1
- package/dist/esm/onchain/market/credit/CreditSuite.js +77 -15
- package/dist/esm/onchain/market/index.js +6 -6
- 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/pool/PoolV310Contract.js +1 -1
- package/dist/esm/onchain/market/rwa/RWARegistry.js +2 -1
- package/dist/esm/onchain/market/rwa/createDegenNFT.js +52 -0
- package/dist/esm/onchain/market/rwa/index.js +6 -5
- package/dist/esm/onchain/market/rwa/midas/MidasDegenNFT.js +55 -0
- package/dist/esm/onchain/market/rwa/midas/constants.js +2 -1
- package/dist/esm/onchain/market/rwa/midas/index.js +3 -2
- package/dist/esm/onchain/market/rwa/securitize/SecuritizeDegenNFT.js +20 -2
- package/dist/esm/onchain/market/rwa/securitize/SecuritizeRWAFactory.js +4 -4
- package/dist/esm/onchain/market/rwa/securitize/constants.js +2 -2
- package/dist/esm/onchain/market/rwa/securitize/index.js +4 -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/IETHZapperContract.js +1 -1
- package/dist/esm/onchain/market/zapper/ZapperContract.js +1 -1
- package/dist/esm/onchain/market/zapper/index.js +0 -1
- package/dist/esm/onchain/opportunities/MultichainOpportunitiesService.js +2 -2
- package/dist/esm/onchain/opportunities/OpportunitiesService.js +11 -3
- 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/utils/viem/simulateWithPriceUpdates.js +1 -1
- 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/index.js +2 -3
- package/dist/esm/sdk/liquidations/LiquidationsNamespace.js +9 -0
- package/dist/esm/sdk/opportunities/OpportunitiesNamespace.js +19 -4
- package/dist/esm/sdk/prepare/PrepareApi.js +25 -35
- 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/abi/rwa/iMidasAccessControl.d.ts +22 -0
- package/dist/types/abi/rwa/iMidasDegenNFT.d.ts +82 -0
- 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 +12 -4
- package/dist/types/model/opportunities.d.ts +12 -2
- package/dist/types/model/opportunities.schema.d.ts +30 -0
- 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 +167 -0
- package/dist/types/model/rwa.schema.d.ts +29 -0
- package/dist/types/offchain/opportunities/OffchainOpportunities.d.ts +2 -1
- package/dist/types/offchain/opportunities/types.d.ts +4 -1
- 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/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/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 +2 -1
- 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 +73 -16
- 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 +30 -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 +11 -10
- 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/RWARegistry.d.ts +1 -1
- package/dist/types/onchain/market/rwa/createDegenNFT.d.ts +12 -0
- package/dist/types/onchain/market/rwa/index.d.ts +10 -8
- package/dist/types/onchain/market/rwa/midas/MidasDegenNFT.d.ts +98 -0
- package/dist/types/onchain/market/rwa/midas/constants.d.ts +2 -1
- package/dist/types/onchain/market/rwa/midas/index.d.ts +3 -2
- package/dist/types/onchain/market/rwa/securitize/SecuritizeDegenNFT.d.ts +8 -2
- package/dist/types/onchain/market/rwa/securitize/SecuritizeRWAFactory.d.ts +4 -3
- package/dist/types/onchain/market/rwa/securitize/constants.d.ts +2 -2
- package/dist/types/onchain/market/rwa/securitize/index.d.ts +5 -4
- package/dist/types/onchain/market/rwa/securitize/types.d.ts +4 -110
- package/dist/types/onchain/market/rwa/types.d.ts +24 -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/opportunities/MultichainOpportunitiesService.d.ts +2 -1
- package/dist/types/onchain/opportunities/OpportunitiesService.d.ts +5 -1
- package/dist/types/onchain/opportunities/types.d.ts +3 -2
- 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/opportunities/OpportunitiesNamespace.d.ts +2 -1
- package/dist/types/sdk/opportunities/types.d.ts +8 -2
- package/dist/types/sdk/prepare/PrepareApi.d.ts +5 -4
- package/dist/types/sdk/prepare/index.d.ts +5 -5
- package/dist/types/sdk/prepare/types.d.ts +41 -22
- 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 -114
- 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 -108
- 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 -343
- /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,8 +1,12 @@
|
|
|
1
1
|
import { SDKConstruct } from "../../base/SDKConstruct.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { unsupportedTokenPair } from "../../../model/errors/prepare-errors.js";
|
|
3
|
+
import { sdkErr } from "../../../model/result.js";
|
|
4
|
+
import "../../../model/index.js";
|
|
5
|
+
import { MIN_HF_LIMITED } from "../../validation/helpers/health-factor-limits.js";
|
|
6
|
+
import { IntentPreviewError } from "../../validation/raise.js";
|
|
7
|
+
import "../../validation/index.js";
|
|
4
8
|
import { isPhantomToken } from "./utils/pick-token.js";
|
|
5
|
-
import { assertMarketOperable
|
|
9
|
+
import { assertMarketOperable } from "./guards.js";
|
|
6
10
|
import { calcLeverageBand } from "./leverage-band.js";
|
|
7
11
|
import { maxProportionalWithdrawal } from "./math.js";
|
|
8
12
|
import { maxWithdrawCollateral } from "./maxWithdrawCollateral.js";
|
|
@@ -25,7 +29,7 @@ var CreditAccountOperationsService = class extends SDKConstruct {
|
|
|
25
29
|
* Previews an operation on an existing account.
|
|
26
30
|
*
|
|
27
31
|
* @param props - Intent plus account slice, quota reserve and slippage
|
|
28
|
-
* @returns Operations, projected state and calldata, or `{ ok: false,
|
|
32
|
+
* @returns Operations, projected state and calldata, or `{ ok: false, error }`
|
|
29
33
|
* when the intent cannot be satisfied (e.g. the account lacks the source
|
|
30
34
|
* balance)
|
|
31
35
|
*/
|
|
@@ -46,8 +50,8 @@ var CreditAccountOperationsService = class extends SDKConstruct {
|
|
|
46
50
|
}
|
|
47
51
|
/**
|
|
48
52
|
* Both ends of what a `WITHDRAW` can take out, in underlying: the largest
|
|
49
|
-
* partial withdrawal that keeps leverage and stays inside the facade's
|
|
50
|
-
*
|
|
53
|
+
* partial withdrawal that keeps leverage and stays inside the facade's
|
|
54
|
+
* `debtLimits`, and the net value an exit hands over. They are reported together
|
|
51
55
|
* because a withdraw form needs both — the range it may offer, and the one
|
|
52
56
|
* amount past it that is allowed — and because the distance between them is
|
|
53
57
|
* the account's own, not a constant a caller could assume.
|
|
@@ -63,7 +67,7 @@ var CreditAccountOperationsService = class extends SDKConstruct {
|
|
|
63
67
|
maxWithdraw(props) {
|
|
64
68
|
const view = accountView(props.creditAccount, props.sdk);
|
|
65
69
|
return {
|
|
66
|
-
partial: maxProportionalWithdrawal(view, view.
|
|
70
|
+
partial: maxProportionalWithdrawal(view, view.debtLimits),
|
|
67
71
|
exit: view.collateral > 0n ? view.collateral : 0n
|
|
68
72
|
};
|
|
69
73
|
}
|
|
@@ -88,8 +92,8 @@ var CreditAccountOperationsService = class extends SDKConstruct {
|
|
|
88
92
|
*
|
|
89
93
|
* A credit manager's `maxLeverage` follows from the liquidation threshold
|
|
90
94
|
* alone, so it is the same for a hundred dollars and for a million. What a
|
|
91
|
-
* given deposit reaches is decided by the debt it implies and by the
|
|
92
|
-
* the market puts that debt in — the range a leverage slider should offer.
|
|
95
|
+
* given deposit reaches is decided by the debt it implies and by the
|
|
96
|
+
* `debtLimits` the market puts that debt in — the range a leverage slider should offer.
|
|
93
97
|
*
|
|
94
98
|
* Unlike the other ceilings here this one reads no account: opening has none
|
|
95
99
|
* yet, and adjusting measures against the net value the caller already
|
|
@@ -108,9 +112,9 @@ var CreditAccountOperationsService = class extends SDKConstruct {
|
|
|
108
112
|
* while its health factor stays at `targetHF` — the ceiling a
|
|
109
113
|
* withdraw-collateral form should offer. Thresholds, prices and quota
|
|
110
114
|
* activity come from the account's market, valued the way the facade values
|
|
111
|
-
* a call that
|
|
115
|
+
* a call that withdraws collateral; zero debt frees the whole balance.
|
|
112
116
|
*
|
|
113
|
-
* The default is {@link MIN_HF_LIMITED}, the
|
|
117
|
+
* The default is {@link MIN_HF_LIMITED}, the threshold a form holds an
|
|
114
118
|
* account to.
|
|
115
119
|
*
|
|
116
120
|
* @param props - Account slice, the SDK holding its market, the collateral
|
|
@@ -130,8 +134,8 @@ var CreditAccountOperationsService = class extends SDKConstruct {
|
|
|
130
134
|
*
|
|
131
135
|
* Sits apart from {@link startIntent} because it is a different trade route,
|
|
132
136
|
* not a different intent: the request goes to the issuer instead of the
|
|
133
|
-
* router, and
|
|
134
|
-
* later. Both routes of one intent are quoted together by
|
|
137
|
+
* router, and what it sells for — hence the repayment and the withdrawal —
|
|
138
|
+
* arrives days later. Both routes of one intent are quoted together by
|
|
135
139
|
* {@link intentRoutes}; this is the one to call when the delayed route is the
|
|
136
140
|
* only one of interest.
|
|
137
141
|
*
|
|
@@ -143,7 +147,7 @@ var CreditAccountOperationsService = class extends SDKConstruct {
|
|
|
143
147
|
*
|
|
144
148
|
* @param props - Intent plus account slice, quota reserve and slippage
|
|
145
149
|
* @returns The request transaction, the state it ends in and what it recorded
|
|
146
|
-
* for the tail, or `{ ok: false,
|
|
150
|
+
* for the tail, or `{ ok: false, error }` — `noDelayedRoute` when this route
|
|
147
151
|
* does not exist for the account at all
|
|
148
152
|
*/
|
|
149
153
|
async startDelayedIntent(props) {
|
|
@@ -179,7 +183,7 @@ var CreditAccountOperationsService = class extends SDKConstruct {
|
|
|
179
183
|
delayed
|
|
180
184
|
};
|
|
181
185
|
} catch (e) {
|
|
182
|
-
return
|
|
186
|
+
return asSDKError(e);
|
|
183
187
|
}
|
|
184
188
|
}
|
|
185
189
|
/**
|
|
@@ -189,7 +193,7 @@ var CreditAccountOperationsService = class extends SDKConstruct {
|
|
|
189
193
|
* Which routes an account has depends on the intent and the token it sells,
|
|
190
194
|
* and a form has to know before it can offer a choice — so both are quoted
|
|
191
195
|
* from the same request and each is reported on its own. A route the account
|
|
192
|
-
* cannot take comes back `undefined` with its
|
|
196
|
+
* cannot take comes back `undefined` with its error in `errors`; only when
|
|
193
197
|
* neither answers is the whole result `{ ok: false }`.
|
|
194
198
|
*
|
|
195
199
|
* A route that could not be quoted at all — a pathfinder with no path out of
|
|
@@ -199,31 +203,31 @@ var CreditAccountOperationsService = class extends SDKConstruct {
|
|
|
199
203
|
*
|
|
200
204
|
* @param props - A withdraw or adjust-leverage intent plus account slice,
|
|
201
205
|
* quota reserve and slippage
|
|
202
|
-
* @returns Whichever routes are viable, or `{ ok: false,
|
|
206
|
+
* @returns Whichever routes are viable, or `{ ok: false, error }` when none is
|
|
203
207
|
*/
|
|
204
208
|
async intentRoutes(props) {
|
|
205
209
|
const [instant, delayed] = await Promise.allSettled([this.startIntent(props), this.startDelayedIntent(props)]);
|
|
206
210
|
const instantRoute = instant.status === "fulfilled" && instant.value.ok ? instant.value : void 0;
|
|
207
211
|
const delayedRoute = delayed.status === "fulfilled" && delayed.value.ok ? delayed.value : void 0;
|
|
208
|
-
const
|
|
209
|
-
const
|
|
210
|
-
const
|
|
211
|
-
instant:
|
|
212
|
-
delayed:
|
|
212
|
+
const instantError = instant.status === "fulfilled" && !instant.value.ok ? instant.value.error : void 0;
|
|
213
|
+
const delayedError = delayed.status === "fulfilled" && !delayed.value.ok ? delayed.value.error : void 0;
|
|
214
|
+
const errors = {
|
|
215
|
+
...instantError === void 0 ? {} : { instant: instantError },
|
|
216
|
+
...delayedError === void 0 ? {} : { delayed: delayedError }
|
|
213
217
|
};
|
|
214
218
|
if (instantRoute || delayedRoute) return {
|
|
215
219
|
ok: true,
|
|
216
220
|
instant: instantRoute,
|
|
217
221
|
delayed: delayedRoute,
|
|
218
|
-
|
|
222
|
+
errors
|
|
219
223
|
};
|
|
220
224
|
const failed = [instant, delayed].find((s) => s.status === "rejected");
|
|
221
225
|
if (failed?.status === "rejected") throw failed.reason;
|
|
222
|
-
const chosen =
|
|
226
|
+
const chosen = instantError ?? delayedError;
|
|
223
227
|
if (chosen === void 0) throw new Error("intentRoutes: a route neither answered nor refused");
|
|
224
228
|
return {
|
|
225
|
-
...chosen,
|
|
226
|
-
|
|
229
|
+
...sdkErr(chosen),
|
|
230
|
+
errors
|
|
227
231
|
};
|
|
228
232
|
}
|
|
229
233
|
/**
|
|
@@ -236,7 +240,7 @@ var CreditAccountOperationsService = class extends SDKConstruct {
|
|
|
236
240
|
* catch up.
|
|
237
241
|
*
|
|
238
242
|
* A claim that brought only part of what the request queued — a legacy Mellow
|
|
239
|
-
* multivault, which
|
|
243
|
+
* multivault, which hands over what it holds liquid and re-queues the rest — is
|
|
240
244
|
* served in proportion, and what it did not settle comes back as `remainder`:
|
|
241
245
|
* the withdrawal still in flight and the intent to finish it with.
|
|
242
246
|
*
|
|
@@ -275,7 +279,7 @@ var CreditAccountOperationsService = class extends SDKConstruct {
|
|
|
275
279
|
*
|
|
276
280
|
* @param props - Credit manager, wallet collateral, target token and leverage
|
|
277
281
|
* @returns Debt, position size, projected balances and quotas for both the
|
|
278
|
-
* expected and the floor branch, or `{ ok: false,
|
|
282
|
+
* expected and the floor branch, or `{ ok: false, error }` when the requested
|
|
279
283
|
* leverage or the resulting debt is not viable
|
|
280
284
|
*/
|
|
281
285
|
async openStrategyIntent(props) {
|
|
@@ -285,7 +289,7 @@ var CreditAccountOperationsService = class extends SDKConstruct {
|
|
|
285
289
|
state: await buildOpenStrategyState(props)
|
|
286
290
|
};
|
|
287
291
|
} catch (e) {
|
|
288
|
-
return
|
|
292
|
+
return asSDKError(e);
|
|
289
293
|
}
|
|
290
294
|
}
|
|
291
295
|
/** Plan → realise → wrap. Unviable requests become `{ ok: false }`. */
|
|
@@ -306,7 +310,7 @@ var CreditAccountOperationsService = class extends SDKConstruct {
|
|
|
306
310
|
delayed
|
|
307
311
|
};
|
|
308
312
|
} catch (e) {
|
|
309
|
-
return
|
|
313
|
+
return asSDKError(e);
|
|
310
314
|
}
|
|
311
315
|
}
|
|
312
316
|
};
|
|
@@ -322,16 +326,16 @@ function plain(result) {
|
|
|
322
326
|
};
|
|
323
327
|
}
|
|
324
328
|
/** Unviable requests are values; anything else is a genuine failure. */
|
|
325
|
-
function
|
|
326
|
-
if (e instanceof IntentPreviewError) return
|
|
327
|
-
if (isUnroutable(e)) return
|
|
329
|
+
function asSDKError(e) {
|
|
330
|
+
if (e instanceof IntentPreviewError) return sdkErr(e.error);
|
|
331
|
+
if (isUnroutable(e)) return sdkErr(unsupportedTokenPair());
|
|
328
332
|
throw e;
|
|
329
333
|
}
|
|
330
334
|
/**
|
|
331
335
|
* How the pathfinder says there is no route: it reverts instead of answering
|
|
332
336
|
* with an empty path, so viem raises a contract error where the rest of the
|
|
333
337
|
* engine raises an {@link IntentPreviewError}. Nothing is wrong — the trade
|
|
334
|
-
* asked for cannot be made, which is
|
|
338
|
+
* asked for cannot be made, which is an error the caller can act on, and one
|
|
335
339
|
* `intentRoutes` in particular must keep as a value so the other route can
|
|
336
340
|
* still be offered.
|
|
337
341
|
*/
|
|
@@ -340,4 +344,4 @@ function isUnroutable(e) {
|
|
|
340
344
|
return false;
|
|
341
345
|
}
|
|
342
346
|
//#endregion
|
|
343
|
-
export { CreditAccountOperationsService,
|
|
347
|
+
export { CreditAccountOperationsService, fetchCreditAccountSlice, isPhantomToken, toCreditAccountSlice };
|
|
@@ -7,7 +7,7 @@ import { LEVERAGE_DECIMALS } from "../../constants/math.js";
|
|
|
7
7
|
* A credit manager's `maxLeverage` follows from the liquidation threshold
|
|
8
8
|
* alone, so it is the same for a hundred dollars and for a million. What a
|
|
9
9
|
* given deposit reaches is decided by the debt it implies —
|
|
10
|
-
* `debt = netValue × (leverage − 1)` — and by the
|
|
10
|
+
* `debt = netValue × (leverage − 1)` — and by the `debtLimits` the market puts that
|
|
11
11
|
* debt in. This inverts that relation.
|
|
12
12
|
*
|
|
13
13
|
* Rounding is asymmetric because the forward direction truncates: the floor
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { BigIntMath } from "../../utils/bigint-math.js";
|
|
2
2
|
import { LEVERAGE_DECIMALS } from "../../constants/math.js";
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import { toToken } from "../../validation/token.js";
|
|
3
|
+
import { insufficientBalance } from "../../../model/errors/operation-errors.js";
|
|
4
|
+
import "../../../model/index.js";
|
|
5
|
+
import { toToken } from "../../validation/helpers/token.js";
|
|
6
|
+
import { checkDebtLimits } from "../../validation/checks/checkDebtLimits.js";
|
|
7
|
+
import { checkLeverage } from "../../validation/checks/checkLeverage.js";
|
|
8
|
+
import { IntentPreviewError, raise } from "../../validation/raise.js";
|
|
9
|
+
import "../../validation/index.js";
|
|
6
10
|
//#region src/onchain/accounts/intents/math.ts
|
|
7
11
|
/** Debt that realises `leverage` on `collateral`: `D = C · (L − 1)`. */
|
|
8
12
|
function debtForLeverage(collateral, leverage) {
|
|
@@ -16,30 +20,30 @@ function debtForLeverage(collateral, leverage) {
|
|
|
16
20
|
* it, so no rounding is introduced on the way.
|
|
17
21
|
*/
|
|
18
22
|
function proportionalDebt(position, collateralDelta) {
|
|
19
|
-
if (position.collateral <= 0n) throw new IntentPreviewError(
|
|
23
|
+
if (position.collateral <= 0n) throw new IntentPreviewError(insufficientBalance(), "cannot preserve leverage on an account with no collateral");
|
|
20
24
|
return position.debt * collateralDelta / position.collateral;
|
|
21
25
|
}
|
|
22
26
|
/**
|
|
23
27
|
* Largest withdrawal (in underlying) that {@link proportionalDebt} can still
|
|
24
28
|
* pay for: the repayment it implies leaves debt at or above `minDebt`, and
|
|
25
29
|
* strictly less than the collateral goes — the last unit closes the account
|
|
26
|
-
* rather than shrinks it. `0n` when the debt already sits below
|
|
30
|
+
* rather than shrinks it. `0n` when the debt already sits below `minDebt`.
|
|
27
31
|
*
|
|
28
32
|
* Solves `floor(D0 · W / C0) ≤ D0 − minDebt` for `W`.
|
|
29
33
|
*/
|
|
30
|
-
function maxProportionalWithdrawal(position,
|
|
34
|
+
function maxProportionalWithdrawal(position, debtLimits) {
|
|
31
35
|
const { debt, collateral } = position;
|
|
32
36
|
if (collateral <= 0n) return 0n;
|
|
33
37
|
const allButLast = collateral - 1n;
|
|
34
38
|
if (debt === 0n) return allButLast;
|
|
35
|
-
const repayable = debt -
|
|
39
|
+
const repayable = debt - debtLimits.minDebt;
|
|
36
40
|
if (repayable < 0n) return 0n;
|
|
37
41
|
const bound = BigIntMath.ceilDiv(collateral * (repayable + 1n), debt) - 1n;
|
|
38
42
|
return bound < allButLast ? bound : allButLast;
|
|
39
43
|
}
|
|
40
44
|
/** Total leverage cannot drop below 1x — that would be negative debt. */
|
|
41
45
|
function assertLeverageAtLeastOne(leverage) {
|
|
42
|
-
raise(
|
|
46
|
+
raise(checkLeverage({
|
|
43
47
|
leverage,
|
|
44
48
|
min: LEVERAGE_DECIMALS
|
|
45
49
|
}), `target leverage ${leverage} is below 1x`);
|
|
@@ -48,14 +52,14 @@ function assertLeverageAtLeastOne(leverage) {
|
|
|
48
52
|
* Rejects a debt the facade would revert on: zero is always fine (no loan at
|
|
49
53
|
* all), anything else has to sit inside `[minDebt, maxDebt]`.
|
|
50
54
|
*/
|
|
51
|
-
function
|
|
52
|
-
raise(
|
|
55
|
+
function assertDebtLimits(sdk, debt, debtLimits, underlying) {
|
|
56
|
+
raise(checkDebtLimits({
|
|
53
57
|
debt,
|
|
54
|
-
minDebt:
|
|
55
|
-
maxDebt:
|
|
58
|
+
minDebt: debtLimits.minDebt,
|
|
59
|
+
maxDebt: debtLimits.maxDebt,
|
|
56
60
|
underlying: toToken(sdk, underlying),
|
|
57
61
|
allowZero: true
|
|
58
|
-
}), debt >
|
|
62
|
+
}), debt > debtLimits.maxDebt ? `debt ${debt} exceeds maxDebt ${debtLimits.maxDebt}` : `debt ${debt} is below minDebt ${debtLimits.minDebt}`);
|
|
59
63
|
}
|
|
60
64
|
//#endregion
|
|
61
|
-
export {
|
|
65
|
+
export { assertDebtLimits, assertLeverageAtLeastOne, debtForLeverage, maxProportionalWithdrawal, proportionalDebt };
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
1
|
+
import { insufficientBalance } from "../../../model/errors/operation-errors.js";
|
|
2
|
+
import "../../../model/index.js";
|
|
3
|
+
import { IntentPreviewError } from "../../validation/raise.js";
|
|
4
|
+
import { assertCanBorrow, assertCollateralised, assertGrowthAllowed, assertMarketOperable, assertQuotaAvailable } from "./guards.js";
|
|
5
|
+
import { assertDebtLimits, assertLeverageAtLeastOne, debtForLeverage } from "./math.js";
|
|
4
6
|
import { collectPriceImpact } from "./utils/price-impact.js";
|
|
5
7
|
import { getQuotasForUpdate } from "./utils/quotas-for-update.js";
|
|
6
8
|
import { createRouterPaths } from "./utils/router-path.js";
|
|
@@ -33,7 +35,7 @@ async function buildOpenStrategyState(props) {
|
|
|
33
35
|
const underlying = market.pool.underlying.toLowerCase();
|
|
34
36
|
const convert = (from, to, amount) => market.priceOracle.safeConvert(from, to, amount).value;
|
|
35
37
|
const margin = collateral.reduce((acc, a) => acc + convert(a.token, underlying, a.balance), 0n);
|
|
36
|
-
if (margin <= 0n) throw new IntentPreviewError(
|
|
38
|
+
if (margin <= 0n) throw new IntentPreviewError(insufficientBalance(), "openStrategy: collateral is worth nothing in underlying");
|
|
37
39
|
const debt = debtForLeverage(margin, leverage);
|
|
38
40
|
const account = existing ?? {
|
|
39
41
|
creditAccount: NO_ACCOUNT,
|
|
@@ -45,7 +47,7 @@ async function buildOpenStrategyState(props) {
|
|
|
45
47
|
totalDebt: 0n,
|
|
46
48
|
tokens: []
|
|
47
49
|
};
|
|
48
|
-
|
|
50
|
+
assertDebtLimits(sdk, debt, suite.creditFacade, underlying);
|
|
49
51
|
assertCanBorrow(sdk, suite, debt);
|
|
50
52
|
const paths = createRouterPaths({
|
|
51
53
|
sdk,
|
|
@@ -81,7 +83,7 @@ async function buildOpenStrategyState(props) {
|
|
|
81
83
|
before: [],
|
|
82
84
|
after: averageAssets
|
|
83
85
|
});
|
|
84
|
-
|
|
86
|
+
assertQuotaAvailable(sdk, market, averageQuota);
|
|
85
87
|
const snapshot = {
|
|
86
88
|
creditManager,
|
|
87
89
|
assets: averageAssets,
|
|
@@ -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 };
|