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