@gearbox-protocol/sdk 16.1.2 → 16.3.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/history/assembleOperations.js +3 -3
- package/dist/cjs/history/classifyMulticallOperations.js +7 -7
- package/dist/cjs/history/index.js +13 -0
- package/dist/cjs/history/parseCreditAccountTransaction.js +5 -5
- package/dist/cjs/{preview → history}/trace/errors.js +1 -1
- package/dist/cjs/{preview → history}/trace/extractAdapterCallTraces.js +1 -1
- package/dist/cjs/{preview → history}/trace/extractTransfers.js +3 -3
- package/dist/cjs/{preview → history}/trace/findFacadeCalls.js +3 -3
- package/dist/cjs/history/trace/index.js +14 -0
- package/dist/cjs/model/errors/index.js +37 -0
- package/dist/cjs/model/errors/liquidation-errors.js +32 -0
- package/dist/cjs/model/errors/operation-errors.js +135 -0
- package/dist/cjs/{onchain/market/oracle/errors.js → model/errors/oracle-errors.js} +1 -1
- package/dist/cjs/model/errors/prepare-errors.js +108 -0
- package/dist/cjs/model/errors/preview-errors.js +12 -0
- package/dist/cjs/model/index.js +40 -2
- package/dist/cjs/model/positions.js +1 -1
- package/dist/cjs/model/result.js +0 -8
- package/dist/cjs/model/rwa.js +40 -0
- package/dist/cjs/onchain/accounts/CreditAccountsServiceV310.js +2 -2
- package/dist/cjs/onchain/accounts/index.js +0 -2
- package/dist/cjs/onchain/accounts/intents/guards.js +42 -66
- package/dist/cjs/onchain/accounts/intents/index.js +38 -35
- package/dist/cjs/onchain/accounts/intents/leverage-band.js +1 -1
- package/dist/cjs/onchain/accounts/intents/math.js +19 -15
- package/dist/cjs/onchain/accounts/intents/open-strategy.js +44 -8
- package/dist/cjs/onchain/accounts/intents/plan.js +52 -48
- package/dist/cjs/onchain/accounts/intents/realize.js +26 -24
- package/dist/cjs/onchain/accounts/intents/tail.js +15 -12
- package/dist/cjs/onchain/accounts/intents/testing/sdk-mock.js +7 -0
- package/dist/cjs/onchain/accounts/intents/tests/finish-withdraw.fixtures.js +6 -6
- package/dist/cjs/onchain/accounts/intents/tests/withdraw.fixtures.js +12 -12
- package/dist/cjs/onchain/accounts/intents/view.js +1 -1
- package/dist/cjs/onchain/accounts/withdrawal-compressor/index.js +0 -1
- package/dist/cjs/onchain/index.js +122 -36
- package/dist/cjs/onchain/market/MarketSuite.js +7 -1
- package/dist/cjs/onchain/market/adapters/index.js +1 -0
- package/dist/cjs/onchain/market/credit/CreditSuite.js +47 -15
- package/dist/cjs/onchain/market/index.js +0 -6
- package/dist/cjs/onchain/market/oracle/PriceOracleBaseContract.js +6 -6
- package/dist/cjs/onchain/market/oracle/index.js +0 -2
- package/dist/cjs/onchain/market/pool/PoolQuotaKeeperV310Contract.js +8 -0
- package/dist/cjs/onchain/market/rwa/RWARegistry.js +3 -2
- package/dist/cjs/onchain/market/rwa/index.js +0 -4
- package/dist/cjs/onchain/market/rwa/securitize/SecuritizeRWAFactory.js +7 -7
- package/dist/cjs/onchain/market/rwa/securitize/constants.js +0 -2
- package/dist/cjs/onchain/market/rwa/securitize/index.js +1 -3
- package/dist/cjs/onchain/market/rwa/securitize/types.js +0 -29
- package/dist/cjs/onchain/market/rwa/types.js +0 -7
- package/dist/cjs/onchain/market/zapper/index.js +0 -1
- package/dist/cjs/onchain/pools/PoolService.js +10 -16
- package/dist/cjs/onchain/preview/index.js +41 -0
- package/dist/cjs/{preview → onchain/preview}/parse/classifyInnerOperations.js +2 -3
- package/dist/cjs/onchain/preview/parse/index.js +14 -0
- package/dist/cjs/{preview → onchain/preview}/parse/parseFacadeOperationCalldata.js +3 -3
- package/dist/cjs/{preview → onchain/preview}/parse/parseOperationCalldata.js +16 -17
- package/dist/cjs/{preview → onchain/preview}/parse/parsePoolOperationCalldata.js +3 -3
- package/dist/cjs/{preview → onchain/preview}/parse/parseRWAFactoryOperationCalldata.js +11 -12
- package/dist/cjs/{preview → onchain/preview}/parse/types.js +1 -1
- package/dist/cjs/{preview → onchain/preview}/preview/CreditAccountState.js +3 -4
- package/dist/cjs/{preview → onchain/preview}/preview/buildDelayedStrategyPositionOperationPreview.js +10 -11
- package/dist/cjs/{preview → onchain/preview}/preview/detectCloseOrRepay.js +2 -3
- package/dist/cjs/{preview → onchain/preview}/preview/detectDelayedClaim.js +4 -5
- package/dist/cjs/{preview → onchain/preview}/preview/detectDelayedOperation.js +5 -6
- package/dist/cjs/{preview → onchain/preview}/preview/estimateClaimableAt.js +1 -1
- package/dist/cjs/onchain/preview/preview/index.js +26 -0
- package/dist/cjs/{preview → onchain/preview}/preview/previewAdjustStrategyPosition.js +18 -22
- package/dist/cjs/{preview → onchain/preview}/preview/previewExitOrRepayStrategyPosition.js +22 -28
- package/dist/cjs/onchain/preview/preview/previewOpenStrategyPosition.js +60 -0
- package/dist/cjs/onchain/preview/preview/previewOperation.js +119 -0
- package/dist/cjs/{preview/simulate/simulatePoolOperation.js → onchain/preview/preview/previewPoolPositionOperation.js} +46 -32
- package/dist/cjs/onchain/preview/preview/replayInnerOperations.js +109 -0
- package/dist/cjs/onchain/preview/preview/replayMulticall.js +22 -0
- package/dist/cjs/{preview → onchain/preview}/preview/unwrapNativeCollateral.js +11 -14
- package/dist/cjs/onchain/validation/bundles/checkAccountQuotas.js +20 -0
- package/dist/cjs/onchain/validation/bundles/checkCollateralFunding.js +59 -0
- package/dist/cjs/onchain/validation/bundles/checkCreditOperation.js +65 -0
- package/dist/cjs/onchain/validation/bundles/checkDraw.js +28 -0
- package/dist/cjs/onchain/validation/bundles/checkHealthFactors.js +27 -0
- package/dist/cjs/onchain/validation/bundles/checkLiquidationEligibility.js +33 -0
- package/dist/cjs/onchain/validation/bundles/checkLiquidationFunding.js +29 -0
- package/dist/cjs/onchain/validation/bundles/checkMarket.js +24 -0
- package/dist/cjs/onchain/validation/bundles/checkObtained.js +13 -0
- package/dist/cjs/onchain/validation/bundles/checkPoolFunding.js +22 -0
- package/dist/cjs/onchain/validation/bundles/checkPoolOperation.js +35 -0
- package/dist/cjs/onchain/validation/bundles/checkQuotasAsked.js +20 -0
- package/dist/cjs/onchain/validation/bundles/checkRWAOpenRequirements.js +33 -0
- package/dist/cjs/onchain/validation/bundles/checkRWAOpening.js +24 -0
- package/dist/cjs/onchain/validation/bundles/checkWallet.js +22 -0
- package/dist/cjs/onchain/validation/bundles/checkWalletAllowance.js +32 -0
- package/dist/cjs/onchain/validation/bundles/checkWalletBalance.js +41 -0
- package/dist/cjs/onchain/validation/bundles/index.js +35 -0
- package/dist/cjs/onchain/validation/checkLiquidation.js +22 -0
- package/dist/cjs/onchain/validation/checkOperation.js +62 -0
- package/dist/cjs/onchain/validation/checkSimulation.js +60 -0
- package/dist/cjs/onchain/validation/checks/checkBorrowLimit.js +25 -0
- package/dist/cjs/onchain/validation/checks/checkCollateralised.js +26 -0
- package/dist/cjs/onchain/validation/checks/checkCreditAccountFrozen.js +10 -0
- package/dist/cjs/onchain/validation/checks/checkCreditManagerPaused.js +10 -0
- package/dist/cjs/onchain/validation/checks/checkDebtLimits.js +18 -0
- package/dist/cjs/onchain/validation/checks/checkEmergencyLiquidator.js +13 -0
- package/dist/cjs/onchain/validation/checks/checkForbiddenToken.js +10 -0
- package/dist/cjs/onchain/validation/checks/checkLeverage.js +13 -0
- package/dist/cjs/onchain/validation/checks/checkLiquidatorEligible.js +10 -0
- package/dist/cjs/onchain/validation/checks/checkMarketExpired.js +10 -0
- package/dist/cjs/onchain/validation/checks/checkPoolLiquidity.js +25 -0
- package/dist/cjs/onchain/validation/checks/checkPoolPaused.js +10 -0
- package/dist/cjs/onchain/validation/checks/checkPoolSunset.js +10 -0
- package/dist/cjs/onchain/validation/checks/checkQuotaCount.js +10 -0
- package/dist/cjs/onchain/validation/checks/checkQuotaLimit.js +18 -0
- package/dist/cjs/onchain/validation/checks/index.js +31 -0
- package/dist/cjs/onchain/validation/helpers/amount.js +12 -0
- package/dist/cjs/onchain/validation/helpers/health-factor-limits.js +25 -0
- package/dist/cjs/onchain/validation/helpers/index.js +11 -0
- package/dist/cjs/onchain/validation/{token.js → helpers/token.js} +4 -4
- package/dist/cjs/onchain/validation/index.js +85 -27
- package/dist/cjs/onchain/validation/raise.js +33 -0
- package/dist/cjs/sdk/execute/ExecuteApi.js +1 -0
- package/dist/cjs/sdk/index.js +6 -9
- package/dist/cjs/sdk/liquidations/LiquidationsNamespace.js +9 -0
- package/dist/cjs/sdk/prepare/PrepareApi.js +55 -48
- package/dist/cjs/sdk/prepare/index.js +7 -9
- package/dist/cjs/sdk/prepare/types.js +0 -4
- package/dist/cjs/sdk/preview/PreviewNamespace.js +24 -13
- package/dist/esm/history/assembleOperations.js +2 -2
- package/dist/esm/history/classifyMulticallOperations.js +2 -2
- package/dist/esm/history/index.js +6 -1
- package/dist/esm/history/parseCreditAccountTransaction.js +3 -3
- package/dist/esm/{preview → history}/trace/errors.js +1 -1
- package/dist/esm/{preview → history}/trace/extractAdapterCallTraces.js +1 -1
- package/dist/esm/{preview → history}/trace/extractTransfers.js +1 -1
- package/dist/esm/{preview → history}/trace/findFacadeCalls.js +1 -1
- package/dist/esm/model/errors/index.js +7 -0
- package/dist/esm/model/errors/liquidation-errors.js +29 -0
- package/dist/esm/model/errors/operation-errors.js +121 -0
- package/dist/esm/{onchain/market/oracle/errors.js → model/errors/oracle-errors.js} +1 -1
- package/dist/esm/model/errors/prepare-errors.js +97 -0
- package/dist/esm/model/errors/preview-errors.js +11 -0
- package/dist/esm/model/index.js +9 -3
- package/dist/esm/model/positions.js +1 -1
- package/dist/esm/model/result.js +1 -8
- package/dist/esm/model/rwa.js +37 -0
- package/dist/esm/onchain/accounts/CreditAccountsServiceV310.js +2 -2
- package/dist/esm/onchain/accounts/index.js +1 -2
- package/dist/esm/onchain/accounts/intents/guards.js +29 -52
- package/dist/esm/onchain/accounts/intents/index.js +39 -35
- package/dist/esm/onchain/accounts/intents/leverage-band.js +1 -1
- package/dist/esm/onchain/accounts/intents/math.js +18 -14
- package/dist/esm/onchain/accounts/intents/open-strategy.js +46 -10
- package/dist/esm/onchain/accounts/intents/plan.js +51 -47
- package/dist/esm/onchain/accounts/intents/realize.js +26 -24
- package/dist/esm/onchain/accounts/intents/tail.js +14 -11
- package/dist/esm/onchain/accounts/intents/testing/sdk-mock.js +7 -0
- package/dist/esm/onchain/accounts/intents/tests/finish-withdraw.fixtures.js +6 -6
- package/dist/esm/onchain/accounts/intents/tests/withdraw.fixtures.js +12 -12
- package/dist/esm/onchain/accounts/intents/view.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/index.js +0 -1
- package/dist/esm/onchain/index.js +61 -10
- package/dist/esm/onchain/market/MarketSuite.js +7 -1
- package/dist/esm/onchain/market/adapters/index.js +1 -0
- package/dist/esm/onchain/market/credit/CreditSuite.js +47 -15
- package/dist/esm/onchain/market/index.js +3 -5
- package/dist/esm/onchain/market/oracle/PriceOracleBaseContract.js +1 -1
- package/dist/esm/onchain/market/oracle/index.js +1 -2
- package/dist/esm/onchain/market/pool/PoolQuotaKeeperV310Contract.js +8 -0
- package/dist/esm/onchain/market/rwa/RWARegistry.js +2 -1
- package/dist/esm/onchain/market/rwa/index.js +3 -4
- package/dist/esm/onchain/market/rwa/securitize/SecuritizeRWAFactory.js +2 -2
- package/dist/esm/onchain/market/rwa/securitize/constants.js +1 -2
- package/dist/esm/onchain/market/rwa/securitize/index.js +3 -3
- package/dist/esm/onchain/market/rwa/securitize/types.js +1 -29
- package/dist/esm/onchain/market/rwa/types.js +1 -7
- package/dist/esm/onchain/market/zapper/index.js +0 -1
- package/dist/esm/onchain/pools/PoolService.js +10 -16
- package/dist/esm/onchain/preview/index.js +20 -0
- package/dist/esm/{preview → onchain/preview}/parse/classifyInnerOperations.js +2 -3
- package/dist/esm/{preview → onchain/preview}/parse/index.js +0 -1
- package/dist/esm/{preview → onchain/preview}/parse/parseFacadeOperationCalldata.js +1 -1
- package/dist/esm/{preview → onchain/preview}/parse/parseOperationCalldata.js +10 -11
- package/dist/esm/{preview → onchain/preview}/parse/parsePoolOperationCalldata.js +3 -3
- package/dist/esm/{preview → onchain/preview}/parse/parseRWAFactoryOperationCalldata.js +8 -9
- package/dist/esm/{preview → onchain/preview}/parse/types.js +1 -1
- package/dist/esm/{preview → onchain/preview}/preview/CreditAccountState.js +3 -4
- package/dist/esm/{preview → onchain/preview}/preview/buildDelayedStrategyPositionOperationPreview.js +10 -11
- package/dist/esm/{preview → onchain/preview}/preview/detectCloseOrRepay.js +2 -3
- package/dist/esm/{preview → onchain/preview}/preview/detectDelayedClaim.js +4 -5
- package/dist/esm/{preview → onchain/preview}/preview/detectDelayedOperation.js +5 -6
- package/dist/esm/{preview → onchain/preview}/preview/estimateClaimableAt.js +1 -1
- package/dist/esm/{preview → onchain/preview}/preview/index.js +3 -4
- package/dist/esm/{preview → onchain/preview}/preview/previewAdjustStrategyPosition.js +17 -21
- package/dist/esm/{preview → onchain/preview}/preview/previewExitOrRepayStrategyPosition.js +20 -26
- package/dist/esm/{preview → onchain/preview}/preview/previewOpenStrategyPosition.js +25 -15
- package/dist/esm/{preview → onchain/preview}/preview/previewOperation.js +54 -35
- package/dist/esm/{preview/simulate/simulatePoolOperation.js → onchain/preview/preview/previewPoolPositionOperation.js} +46 -30
- package/dist/esm/onchain/preview/preview/replayInnerOperations.js +107 -0
- package/dist/esm/onchain/preview/preview/replayMulticall.js +21 -0
- package/dist/esm/{preview → onchain/preview}/preview/unwrapNativeCollateral.js +11 -14
- package/dist/esm/onchain/validation/bundles/checkAccountQuotas.js +19 -0
- package/dist/esm/onchain/validation/bundles/checkCollateralFunding.js +58 -0
- package/dist/esm/onchain/validation/bundles/checkCreditOperation.js +64 -0
- package/dist/esm/onchain/validation/bundles/checkDraw.js +27 -0
- package/dist/esm/onchain/validation/bundles/checkHealthFactors.js +26 -0
- package/dist/esm/onchain/validation/bundles/checkLiquidationEligibility.js +32 -0
- package/dist/esm/onchain/validation/bundles/checkLiquidationFunding.js +28 -0
- package/dist/esm/onchain/validation/bundles/checkMarket.js +23 -0
- package/dist/esm/onchain/validation/bundles/checkObtained.js +12 -0
- package/dist/esm/onchain/validation/bundles/checkPoolFunding.js +21 -0
- package/dist/esm/onchain/validation/bundles/checkPoolOperation.js +34 -0
- package/dist/esm/onchain/validation/bundles/checkQuotasAsked.js +19 -0
- package/dist/esm/onchain/validation/bundles/checkRWAOpenRequirements.js +32 -0
- package/dist/esm/onchain/validation/bundles/checkRWAOpening.js +23 -0
- package/dist/esm/onchain/validation/bundles/checkWallet.js +21 -0
- package/dist/esm/onchain/validation/bundles/checkWalletAllowance.js +31 -0
- package/dist/esm/onchain/validation/bundles/checkWalletBalance.js +40 -0
- package/dist/esm/onchain/validation/bundles/index.js +18 -0
- package/dist/esm/onchain/validation/checkLiquidation.js +21 -0
- package/dist/esm/onchain/validation/checkOperation.js +61 -0
- package/dist/esm/onchain/validation/checkSimulation.js +59 -0
- package/dist/esm/onchain/validation/checks/checkBorrowLimit.js +24 -0
- package/dist/esm/onchain/validation/checks/checkCollateralised.js +25 -0
- package/dist/esm/onchain/validation/checks/checkCreditAccountFrozen.js +9 -0
- package/dist/esm/onchain/validation/checks/checkCreditManagerPaused.js +9 -0
- package/dist/esm/onchain/validation/checks/checkDebtLimits.js +17 -0
- package/dist/esm/onchain/validation/checks/checkEmergencyLiquidator.js +12 -0
- package/dist/esm/onchain/validation/checks/checkForbiddenToken.js +9 -0
- package/dist/esm/onchain/validation/checks/checkLeverage.js +12 -0
- package/dist/esm/onchain/validation/checks/checkLiquidatorEligible.js +9 -0
- package/dist/esm/onchain/validation/checks/checkMarketExpired.js +9 -0
- package/dist/esm/onchain/validation/checks/checkPoolLiquidity.js +24 -0
- package/dist/esm/onchain/validation/checks/checkPoolPaused.js +9 -0
- package/dist/esm/onchain/validation/checks/checkPoolSunset.js +9 -0
- package/dist/esm/onchain/validation/checks/checkQuotaCount.js +9 -0
- package/dist/esm/onchain/validation/checks/checkQuotaLimit.js +17 -0
- package/dist/esm/onchain/validation/checks/index.js +16 -0
- package/dist/esm/onchain/validation/helpers/amount.js +11 -0
- package/dist/esm/onchain/validation/helpers/health-factor-limits.js +21 -0
- package/dist/esm/onchain/validation/helpers/index.js +4 -0
- package/dist/esm/onchain/validation/{token.js → helpers/token.js} +3 -3
- package/dist/esm/onchain/validation/index.js +43 -4
- package/dist/esm/onchain/validation/raise.js +31 -0
- package/dist/esm/sdk/execute/ExecuteApi.js +1 -0
- package/dist/esm/sdk/index.js +2 -3
- package/dist/esm/sdk/liquidations/LiquidationsNamespace.js +9 -0
- package/dist/esm/sdk/prepare/PrepareApi.js +43 -36
- package/dist/esm/sdk/prepare/index.js +3 -3
- package/dist/esm/sdk/prepare/types.js +1 -2
- package/dist/esm/sdk/preview/PreviewNamespace.js +24 -13
- package/dist/types/history/assembleOperations.d.ts +4 -5
- package/dist/types/history/classifyMulticallOperations.d.ts +3 -4
- package/dist/types/history/index.d.ts +8 -2
- package/dist/types/history/mapOperations.d.ts +1 -1
- package/dist/types/{preview → history}/trace/errors.d.ts +1 -1
- package/dist/types/{preview → history}/trace/extractAdapterCallTraces.d.ts +1 -1
- package/dist/types/{preview → history}/trace/extractTransfers.d.ts +2 -3
- package/dist/types/{preview → history}/trace/findFacadeCalls.d.ts +1 -1
- package/dist/types/{preview → history}/trace/types.d.ts +1 -1
- package/dist/types/history/types.d.ts +2 -3
- package/dist/types/model/errors/base.d.ts +28 -0
- package/dist/types/model/errors/index.d.ts +7 -0
- package/dist/types/model/errors/liquidation-errors.d.ts +45 -0
- package/dist/types/model/errors/operation-errors.d.ts +216 -0
- package/dist/types/{onchain/market/oracle/errors.d.ts → model/errors/oracle-errors.d.ts} +3 -5
- package/dist/types/model/errors/prepare-errors.d.ts +131 -0
- package/dist/types/model/errors/preview-errors.d.ts +72 -0
- package/dist/types/model/index.d.ts +11 -4
- package/dist/types/model/opportunities.d.ts +3 -2
- package/dist/types/model/positions.d.ts +2 -2
- package/dist/types/model/previews.d.ts +52 -113
- package/dist/types/model/result.d.ts +4 -8
- package/dist/types/model/rwa.d.ts +143 -0
- package/dist/types/onchain/accounts/CreditAccountsServiceV310.d.ts +3 -1
- package/dist/types/onchain/accounts/index.d.ts +2 -4
- package/dist/types/onchain/accounts/intents/guards.d.ts +8 -18
- package/dist/types/onchain/accounts/intents/index.d.ts +20 -19
- package/dist/types/onchain/accounts/intents/leverage-band.d.ts +1 -1
- package/dist/types/onchain/accounts/intents/math.d.ts +6 -6
- package/dist/types/onchain/accounts/intents/open-strategy.d.ts +34 -3
- package/dist/types/onchain/accounts/intents/operations.d.ts +2 -2
- package/dist/types/onchain/accounts/intents/plan.d.ts +9 -9
- package/dist/types/onchain/accounts/intents/tail.d.ts +2 -2
- package/dist/types/onchain/accounts/intents/testing/expect.d.ts +3 -3
- package/dist/types/onchain/accounts/intents/tests/finish-withdraw.fixtures.d.ts +6 -6
- package/dist/types/onchain/accounts/intents/tests/open-strategy.fixtures.d.ts +2 -2
- package/dist/types/onchain/accounts/intents/tests/withdraw.fixtures.d.ts +12 -12
- package/dist/types/onchain/accounts/intents/types.d.ts +32 -30
- package/dist/types/onchain/accounts/types.d.ts +4 -2
- package/dist/types/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.d.ts +1 -1
- package/dist/types/onchain/accounts/withdrawal-compressor/index.d.ts +1 -2
- package/dist/types/onchain/accounts/withdrawal-compressor/types.d.ts +1 -1
- package/dist/types/onchain/index.d.ts +68 -13
- package/dist/types/onchain/market/MarketSuite.d.ts +5 -1
- package/dist/types/onchain/market/adapters/index.d.ts +2 -1
- package/dist/types/onchain/market/adapters/transfers.d.ts +0 -7
- package/dist/types/onchain/market/credit/CreditSuite.d.ts +20 -8
- package/dist/types/onchain/market/credit/index.d.ts +2 -2
- package/dist/types/onchain/market/credit/types.d.ts +11 -1
- package/dist/types/onchain/market/index.d.ts +6 -7
- package/dist/types/onchain/market/oracle/PriceOracleBaseContract.d.ts +1 -1
- package/dist/types/onchain/market/oracle/index.d.ts +1 -2
- package/dist/types/onchain/market/oracle/types.d.ts +1 -1
- package/dist/types/onchain/market/pool/PoolQuotaKeeperV310Contract.d.ts +5 -0
- package/dist/types/onchain/market/rwa/index.d.ts +4 -4
- package/dist/types/onchain/market/rwa/securitize/SecuritizeRWAFactory.d.ts +3 -2
- package/dist/types/onchain/market/rwa/securitize/constants.d.ts +1 -2
- package/dist/types/onchain/market/rwa/securitize/index.d.ts +3 -3
- package/dist/types/onchain/market/rwa/securitize/types.d.ts +4 -110
- package/dist/types/onchain/market/rwa/types.d.ts +6 -32
- package/dist/types/onchain/market/zapper/ZapperContract.d.ts +1 -1
- package/dist/types/onchain/market/zapper/index.d.ts +1 -2
- package/dist/types/onchain/market/zapper/types.d.ts +1 -1
- package/dist/types/onchain/pools/types.d.ts +2 -2
- package/dist/types/onchain/preview/index.d.ts +24 -0
- package/dist/types/{preview → onchain/preview}/parse/classifyInnerOperations.d.ts +4 -4
- package/dist/types/{preview → onchain/preview}/parse/index.d.ts +2 -4
- package/dist/types/{preview → onchain/preview}/parse/parseFacadeOperationCalldata.d.ts +4 -4
- package/dist/types/onchain/preview/parse/parseOperationCalldata.d.ts +18 -0
- package/dist/types/{preview → onchain/preview}/parse/parsePoolOperationCalldata.d.ts +7 -7
- package/dist/types/{preview → onchain/preview}/parse/parseRWAFactoryOperationCalldata.d.ts +4 -4
- package/dist/types/{preview → onchain/preview}/parse/types-adapters.d.ts +5 -16
- package/dist/types/{preview → onchain/preview}/parse/types-facades.d.ts +3 -3
- package/dist/types/{preview → onchain/preview}/parse/types-pools.d.ts +1 -1
- package/dist/types/{preview → onchain/preview}/parse/types-rwa.d.ts +3 -3
- package/dist/types/{preview → onchain/preview}/parse/types.d.ts +3 -3
- package/dist/types/{preview → onchain/preview}/preview/CreditAccountState.d.ts +5 -5
- package/dist/types/{preview → onchain/preview}/preview/buildDelayedStrategyPositionOperationPreview.d.ts +5 -5
- package/dist/types/{preview → onchain/preview}/preview/detectCloseOrRepay.d.ts +1 -1
- package/dist/types/{preview → onchain/preview}/preview/detectDelayedClaim.d.ts +8 -8
- package/dist/types/{preview → onchain/preview}/preview/detectDelayedOperation.d.ts +9 -9
- package/dist/types/{preview → onchain/preview}/preview/estimateClaimableAt.d.ts +6 -6
- package/dist/types/{preview → onchain/preview}/preview/index.d.ts +3 -4
- package/dist/types/onchain/preview/preview/previewAdjustStrategyPosition.d.ts +20 -0
- package/dist/types/onchain/preview/preview/previewExitOrRepayStrategyPosition.d.ts +21 -0
- package/dist/types/onchain/preview/preview/previewOpenStrategyPosition.d.ts +14 -0
- package/dist/types/onchain/preview/preview/previewOperation.d.ts +32 -0
- package/dist/types/onchain/preview/preview/previewPoolPositionOperation.d.ts +13 -0
- package/dist/types/{preview → onchain/preview}/preview/replayInnerOperations.d.ts +11 -11
- package/dist/types/{preview → onchain/preview}/preview/replayMulticall.d.ts +10 -10
- package/dist/types/{preview → onchain/preview}/preview/unwrapNativeCollateral.d.ts +10 -20
- package/dist/types/onchain/validation/bundles/checkAccountQuotas.d.ts +16 -0
- package/dist/types/onchain/validation/bundles/checkCollateralFunding.d.ts +22 -0
- package/dist/types/onchain/validation/bundles/checkCreditOperation.d.ts +31 -0
- package/dist/types/onchain/validation/bundles/checkDraw.d.ts +20 -0
- package/dist/types/onchain/validation/bundles/checkHealthFactors.d.ts +39 -0
- package/dist/types/onchain/validation/bundles/checkLiquidationEligibility.d.ts +20 -0
- package/dist/types/onchain/validation/bundles/checkLiquidationFunding.d.ts +18 -0
- package/dist/types/onchain/validation/bundles/checkMarket.d.ts +15 -0
- package/dist/types/onchain/validation/bundles/checkObtained.d.ts +9 -0
- package/dist/types/onchain/validation/bundles/checkPoolFunding.d.ts +19 -0
- package/dist/types/onchain/validation/bundles/checkPoolOperation.d.ts +31 -0
- package/dist/types/onchain/validation/bundles/checkQuotasAsked.d.ts +10 -0
- package/dist/types/onchain/validation/bundles/checkRWAOpenRequirements.d.ts +21 -0
- package/dist/types/onchain/validation/bundles/checkRWAOpening.d.ts +19 -0
- package/dist/types/onchain/validation/bundles/checkWallet.d.ts +23 -0
- package/dist/types/onchain/validation/bundles/checkWalletAllowance.d.ts +18 -0
- package/dist/types/onchain/validation/bundles/checkWalletBalance.d.ts +17 -0
- package/dist/types/onchain/validation/bundles/index.d.ts +18 -0
- package/dist/types/onchain/validation/checkLiquidation.d.ts +23 -0
- package/dist/types/onchain/validation/checkOperation.d.ts +32 -0
- package/dist/types/onchain/validation/checkSimulation.d.ts +56 -0
- package/dist/types/onchain/validation/checks/checkBorrowLimit.d.ts +21 -0
- package/dist/types/onchain/validation/checks/checkCollateralised.d.ts +25 -0
- package/dist/types/onchain/validation/checks/checkCreditAccountFrozen.d.ts +12 -0
- package/dist/types/onchain/validation/checks/checkCreditManagerPaused.d.ts +12 -0
- package/dist/types/onchain/validation/checks/checkDebtLimits.d.ts +21 -0
- package/dist/types/onchain/validation/checks/checkEmergencyLiquidator.d.ts +17 -0
- package/dist/types/onchain/validation/checks/checkForbiddenToken.d.ts +12 -0
- package/dist/types/onchain/validation/checks/checkLeverage.d.ts +12 -0
- package/dist/types/onchain/validation/checks/checkLiquidatorEligible.d.ts +13 -0
- package/dist/types/onchain/validation/checks/checkMarketExpired.d.ts +14 -0
- package/dist/types/onchain/validation/checks/checkPoolLiquidity.d.ts +20 -0
- package/dist/types/onchain/validation/checks/checkPoolPaused.d.ts +12 -0
- package/dist/types/onchain/validation/checks/checkPoolSunset.d.ts +13 -0
- package/dist/types/onchain/validation/checks/checkQuotaCount.d.ts +11 -0
- package/dist/types/onchain/validation/checks/checkQuotaLimit.d.ts +18 -0
- package/dist/types/onchain/validation/checks/index.d.ts +16 -0
- package/dist/types/onchain/validation/helpers/amount.d.ts +7 -0
- package/dist/types/onchain/validation/helpers/health-factor-limits.d.ts +21 -0
- package/dist/types/onchain/validation/helpers/index.d.ts +4 -0
- package/dist/types/onchain/validation/{token.d.ts → helpers/token.d.ts} +4 -4
- package/dist/types/onchain/validation/index.d.ts +43 -4
- package/dist/types/onchain/validation/raise.d.ts +33 -0
- package/dist/types/sdk/execute/types.d.ts +2 -2
- package/dist/types/sdk/index.d.ts +5 -6
- package/dist/types/sdk/liquidations/LiquidationsNamespace.d.ts +5 -0
- package/dist/types/sdk/liquidations/types.d.ts +8 -0
- package/dist/types/sdk/prepare/PrepareApi.d.ts +6 -5
- package/dist/types/sdk/prepare/index.d.ts +5 -5
- package/dist/types/sdk/prepare/types.d.ts +65 -23
- package/dist/types/sdk/preview/PreviewNamespace.d.ts +13 -3
- package/dist/types/sdk/preview/index.d.ts +2 -2
- package/dist/types/sdk/preview/types.d.ts +30 -7
- package/package.json +1 -6
- package/dist/cjs/onchain/accounts/withdrawal-compressor/errors.js +0 -1
- package/dist/cjs/onchain/market/zapper/errors.js +0 -1
- package/dist/cjs/onchain/validation/checks.js +0 -258
- package/dist/cjs/onchain/validation/refusal.js +0 -39
- package/dist/cjs/preview/index.js +0 -86
- package/dist/cjs/preview/package.json +0 -1
- package/dist/cjs/preview/parse/errors.js +0 -1
- package/dist/cjs/preview/parse/index.js +0 -15
- package/dist/cjs/preview/prerequisites/AllowancePrerequisite.js +0 -38
- package/dist/cjs/preview/prerequisites/BalancePrerequisite.js +0 -52
- package/dist/cjs/preview/prerequisites/Prerequisite.js +0 -52
- package/dist/cjs/preview/prerequisites/RWAOpenRequirementsPrerequisite.js +0 -53
- package/dist/cjs/preview/prerequisites/buildCollateralPrerequisites.js +0 -63
- package/dist/cjs/preview/prerequisites/buildPartialLiquidationPrerequisites.js +0 -19
- package/dist/cjs/preview/prerequisites/buildPoolPrerequisites.js +0 -76
- package/dist/cjs/preview/prerequisites/buildRWAPrerequisites.js +0 -39
- package/dist/cjs/preview/prerequisites/checkPrerequisites.js +0 -74
- package/dist/cjs/preview/prerequisites/helpers.js +0 -23
- package/dist/cjs/preview/prerequisites/index.js +0 -12
- package/dist/cjs/preview/preview/errors.js +0 -85
- package/dist/cjs/preview/preview/index.js +0 -33
- package/dist/cjs/preview/preview/previewOpenStrategyPosition.js +0 -50
- package/dist/cjs/preview/preview/previewOperation.js +0 -100
- package/dist/cjs/preview/preview/previewPoolPositionOperation.js +0 -49
- package/dist/cjs/preview/preview/replayInnerOperations.js +0 -109
- package/dist/cjs/preview/preview/replayMulticall.js +0 -19
- package/dist/cjs/preview/simulate/errors.js +0 -73
- package/dist/cjs/preview/simulate/index.js +0 -11
- package/dist/cjs/preview/simulate/simulateFacadeOperation.js +0 -15
- package/dist/cjs/preview/simulate/simulateOperation.js +0 -29
- package/dist/cjs/preview/simulate/simulateRWAOperation.js +0 -15
- package/dist/cjs/preview/simulate/types.js +0 -1
- package/dist/cjs/preview/trace/index.js +0 -14
- package/dist/cjs/preview/trace/types.js +0 -1
- package/dist/cjs/preview/types.js +0 -1
- package/dist/cjs/preview/validate/checkOperation.js +0 -187
- package/dist/cjs/preview/validate/checkSimulation.js +0 -39
- package/dist/cjs/preview/validate/index.js +0 -8
- package/dist/cjs/sdk/prepare/errors.js +0 -93
- package/dist/esm/onchain/accounts/withdrawal-compressor/errors.js +0 -1
- package/dist/esm/onchain/market/zapper/errors.js +0 -1
- package/dist/esm/onchain/validation/checks.js +0 -238
- package/dist/esm/onchain/validation/refusal.js +0 -36
- package/dist/esm/preview/index.js +0 -38
- package/dist/esm/preview/package.json +0 -1
- package/dist/esm/preview/parse/errors.js +0 -1
- package/dist/esm/preview/prerequisites/AllowancePrerequisite.js +0 -37
- package/dist/esm/preview/prerequisites/BalancePrerequisite.js +0 -51
- package/dist/esm/preview/prerequisites/Prerequisite.js +0 -51
- package/dist/esm/preview/prerequisites/RWAOpenRequirementsPrerequisite.js +0 -52
- package/dist/esm/preview/prerequisites/buildCollateralPrerequisites.js +0 -62
- package/dist/esm/preview/prerequisites/buildPartialLiquidationPrerequisites.js +0 -18
- package/dist/esm/preview/prerequisites/buildPoolPrerequisites.js +0 -75
- package/dist/esm/preview/prerequisites/buildRWAPrerequisites.js +0 -38
- package/dist/esm/preview/prerequisites/checkPrerequisites.js +0 -73
- package/dist/esm/preview/prerequisites/helpers.js +0 -22
- package/dist/esm/preview/prerequisites/index.js +0 -7
- package/dist/esm/preview/preview/errors.js +0 -79
- package/dist/esm/preview/preview/previewPoolPositionOperation.js +0 -48
- package/dist/esm/preview/preview/replayInnerOperations.js +0 -107
- package/dist/esm/preview/preview/replayMulticall.js +0 -18
- package/dist/esm/preview/simulate/errors.js +0 -71
- package/dist/esm/preview/simulate/index.js +0 -6
- package/dist/esm/preview/simulate/simulateFacadeOperation.js +0 -14
- package/dist/esm/preview/simulate/simulateOperation.js +0 -28
- package/dist/esm/preview/simulate/simulateRWAOperation.js +0 -14
- package/dist/esm/preview/simulate/types.js +0 -1
- package/dist/esm/preview/trace/types.js +0 -1
- package/dist/esm/preview/types.js +0 -1
- package/dist/esm/preview/validate/checkOperation.js +0 -183
- package/dist/esm/preview/validate/checkSimulation.js +0 -38
- package/dist/esm/preview/validate/index.js +0 -3
- package/dist/esm/sdk/prepare/errors.js +0 -89
- package/dist/types/model/errors.d.ts +0 -46
- package/dist/types/onchain/accounts/withdrawal-compressor/errors.d.ts +0 -20
- package/dist/types/onchain/market/zapper/errors.d.ts +0 -18
- package/dist/types/onchain/validation/checks.d.ts +0 -164
- package/dist/types/onchain/validation/refusal.d.ts +0 -242
- package/dist/types/preview/index.d.ts +0 -47
- package/dist/types/preview/parse/errors.d.ts +0 -29
- package/dist/types/preview/parse/parseOperationCalldata.d.ts +0 -18
- package/dist/types/preview/prerequisites/AllowancePrerequisite.d.ts +0 -26
- package/dist/types/preview/prerequisites/BalancePrerequisite.d.ts +0 -29
- package/dist/types/preview/prerequisites/Prerequisite.d.ts +0 -26
- package/dist/types/preview/prerequisites/RWAOpenRequirementsPrerequisite.d.ts +0 -55
- package/dist/types/preview/prerequisites/buildCollateralPrerequisites.d.ts +0 -20
- package/dist/types/preview/prerequisites/buildPartialLiquidationPrerequisites.d.ts +0 -12
- package/dist/types/preview/prerequisites/buildPoolPrerequisites.d.ts +0 -12
- package/dist/types/preview/prerequisites/buildRWAPrerequisites.d.ts +0 -26
- package/dist/types/preview/prerequisites/checkPrerequisites.d.ts +0 -28
- package/dist/types/preview/prerequisites/helpers.d.ts +0 -10
- package/dist/types/preview/prerequisites/index.d.ts +0 -7
- package/dist/types/preview/prerequisites/types.d.ts +0 -53
- package/dist/types/preview/preview/errors.d.ts +0 -44
- package/dist/types/preview/preview/previewAdjustStrategyPosition.d.ts +0 -19
- package/dist/types/preview/preview/previewExitOrRepayStrategyPosition.d.ts +0 -18
- package/dist/types/preview/preview/previewOpenStrategyPosition.d.ts +0 -12
- package/dist/types/preview/preview/previewOperation.d.ts +0 -32
- package/dist/types/preview/preview/previewPoolPositionOperation.d.ts +0 -13
- package/dist/types/preview/simulate/errors.d.ts +0 -52
- package/dist/types/preview/simulate/index.d.ts +0 -7
- package/dist/types/preview/simulate/simulateFacadeOperation.d.ts +0 -16
- package/dist/types/preview/simulate/simulateOperation.d.ts +0 -12
- package/dist/types/preview/simulate/simulatePoolOperation.d.ts +0 -42
- package/dist/types/preview/simulate/simulateRWAOperation.d.ts +0 -16
- package/dist/types/preview/simulate/types.d.ts +0 -48
- package/dist/types/preview/types.d.ts +0 -65
- package/dist/types/preview/validate/checkOperation.d.ts +0 -71
- package/dist/types/preview/validate/checkSimulation.d.ts +0 -32
- package/dist/types/preview/validate/index.d.ts +0 -3
- package/dist/types/sdk/prepare/errors.d.ts +0 -319
- /package/dist/cjs/{preview/prerequisites → history/trace}/types.js +0 -0
- /package/dist/cjs/model/{errors.js → errors/base.js} +0 -0
- /package/dist/cjs/{preview → onchain/preview}/parse/types-adapters.js +0 -0
- /package/dist/cjs/{preview → onchain/preview}/parse/types-facades.js +0 -0
- /package/dist/cjs/{preview → onchain/preview}/parse/types-pools.js +0 -0
- /package/dist/cjs/{preview → onchain/preview}/parse/types-rwa.js +0 -0
- /package/dist/esm/{preview → history}/trace/index.js +0 -0
- /package/dist/esm/{preview/prerequisites → history/trace}/types.js +0 -0
- /package/dist/esm/model/{errors.js → errors/base.js} +0 -0
- /package/dist/esm/{preview → onchain/preview}/parse/types-adapters.js +0 -0
- /package/dist/esm/{preview → onchain/preview}/parse/types-facades.js +0 -0
- /package/dist/esm/{preview → onchain/preview}/parse/types-pools.js +0 -0
- /package/dist/esm/{preview → onchain/preview}/parse/types-rwa.js +0 -0
- /package/dist/types/{preview → history}/trace/index.d.ts +0 -0
|
@@ -61,7 +61,7 @@ function positionId(position) {
|
|
|
61
61
|
* A condition that does not apply to a position's kind keeps the row rather
|
|
62
62
|
* than dropping it: `isZeroDebt` says nothing about a pool position, and
|
|
63
63
|
* `underlyingType` says nothing about a liquidation position, which is
|
|
64
|
-
* denominated in whatever its withdrawal
|
|
64
|
+
* denominated in whatever its withdrawal settles in.
|
|
65
65
|
*
|
|
66
66
|
* @param position - Row to test.
|
|
67
67
|
* @param filter - Conditions to test against. An absent filter matches
|
package/dist/cjs/model/result.js
CHANGED
|
@@ -23,15 +23,7 @@ function sdkErr(error) {
|
|
|
23
23
|
error
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
|
-
/**
|
|
27
|
-
* Narrows a {@link SDKReturn} to its failure half. Trivial over `ok`, but it
|
|
28
|
-
* names the intent at call sites that would otherwise read `!r.ok`.
|
|
29
|
-
**/
|
|
30
|
-
function isSDKError(answer) {
|
|
31
|
-
return !answer.ok;
|
|
32
|
-
}
|
|
33
26
|
//#endregion
|
|
34
|
-
exports.isSDKError = isSDKError;
|
|
35
27
|
exports.safeValue = safeValue;
|
|
36
28
|
exports.sdkErr = sdkErr;
|
|
37
29
|
exports.sdkOk = sdkOk;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/model/rwa.ts
|
|
3
|
+
/**
|
|
4
|
+
* Discriminant of the Securitize RWA factory contract type.
|
|
5
|
+
**/
|
|
6
|
+
const RWA_FACTORY_SECURITIZE = "RWA_FACTORY::SECURITIZE";
|
|
7
|
+
/**
|
|
8
|
+
* Discriminated union of all known RWA factory contract type strings.
|
|
9
|
+
**/
|
|
10
|
+
const RWA_FACTORY_TYPES = [RWA_FACTORY_SECURITIZE];
|
|
11
|
+
/**
|
|
12
|
+
* EIP-712 type schema for the `RegisterVault` message expected by Securitize's
|
|
13
|
+
* VaultRegistrar. Matches the contract's `RegisterVault` typehash field order.
|
|
14
|
+
**/
|
|
15
|
+
const SECURITIZE_REGISTER_VAULT_TYPES = { RegisterVault: [
|
|
16
|
+
{
|
|
17
|
+
name: "investor",
|
|
18
|
+
type: "address"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: "operator",
|
|
22
|
+
type: "address"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: "token",
|
|
26
|
+
type: "address"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: "nonce",
|
|
30
|
+
type: "uint256"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: "deadline",
|
|
34
|
+
type: "uint256"
|
|
35
|
+
}
|
|
36
|
+
] };
|
|
37
|
+
//#endregion
|
|
38
|
+
exports.RWA_FACTORY_SECURITIZE = RWA_FACTORY_SECURITIZE;
|
|
39
|
+
exports.RWA_FACTORY_TYPES = RWA_FACTORY_TYPES;
|
|
40
|
+
exports.SECURITIZE_REGISTER_VAULT_TYPES = SECURITIZE_REGISTER_VAULT_TYPES;
|
|
@@ -205,7 +205,7 @@ var CreditAccountsServiceV310 = class extends require_onchain_base_SDKConstruct.
|
|
|
205
205
|
else if (typeof withdrawToken === "string") tokenToWithdraw = withdrawToken;
|
|
206
206
|
const { creditFacade } = cmSuite;
|
|
207
207
|
let calls = [
|
|
208
|
-
creditFacade.prepareIncreaseDebt(debt),
|
|
208
|
+
...debt > 0n ? [creditFacade.prepareIncreaseDebt(debt)] : [],
|
|
209
209
|
...creditFacade.prepareAddCollateral(collateral, permits),
|
|
210
210
|
...openPathCalls,
|
|
211
211
|
...tokenToWithdraw ? [creditFacade.prepareWithdrawCollateral(tokenToWithdraw, require_onchain_constants_math.MAX_UINT256, to)] : [],
|
|
@@ -217,7 +217,7 @@ var CreditAccountsServiceV310 = class extends require_onchain_base_SDKConstruct.
|
|
|
217
217
|
];
|
|
218
218
|
calls = await this.#prependMidasReceiveGreenlist(cm.address, calls);
|
|
219
219
|
calls = await this.prependPriceUpdates(cm.address, calls);
|
|
220
|
-
const tx = reopenCreditAccount ? cmSuite.multicallTx(reopenCreditAccount, calls) : cmSuite.openCreditAccountTx(to, calls, referralCode, rwaOptions);
|
|
220
|
+
const tx = reopenCreditAccount ? cmSuite.multicallTx(reopenCreditAccount, calls, rwaOptions) : cmSuite.openCreditAccountTx(to, calls, referralCode, rwaOptions);
|
|
221
221
|
tx.value = ethAmount.toString(10);
|
|
222
222
|
return tx;
|
|
223
223
|
}
|
|
@@ -7,7 +7,6 @@ const require_onchain_accounts_credit_account_compressor_CreditAccountCompressor
|
|
|
7
7
|
require("./credit-account-compressor/index.js");
|
|
8
8
|
const require_onchain_accounts_CreditAccountsServiceV310 = require("./CreditAccountsServiceV310.js");
|
|
9
9
|
const require_onchain_accounts_intents_utils_pick_token = require("./intents/utils/pick-token.js");
|
|
10
|
-
const require_onchain_accounts_intents_guards = require("./intents/guards.js");
|
|
11
10
|
const require_onchain_accounts_intents_utils_credit_account_slice = require("./intents/utils/credit-account-slice.js");
|
|
12
11
|
const require_onchain_accounts_quota_utils = require("./quota-utils.js");
|
|
13
12
|
const require_onchain_accounts_intents_index = require("./intents/index.js");
|
|
@@ -44,7 +43,6 @@ exports.RedemptionLoggerV310Contract = require_onchain_accounts_withdrawal_compr
|
|
|
44
43
|
exports.WithdrawalCompressorV310Contract = require_onchain_accounts_withdrawal_compressor_WithdrawalCompressorV310Contract.WithdrawalCompressorV310Contract;
|
|
45
44
|
exports.WithdrawalCompressorV311Contract = require_onchain_accounts_withdrawal_compressor_WithdrawalCompressorV311Contract.WithdrawalCompressorV311Contract;
|
|
46
45
|
exports.WithdrawalCompressorV313Contract = require_onchain_accounts_withdrawal_compressor_WithdrawalCompressorV313Contract.WithdrawalCompressorV313Contract;
|
|
47
|
-
exports.borrowable = require_onchain_accounts_intents_guards.borrowable;
|
|
48
46
|
exports.calcDefaultQuota = require_onchain_accounts_quota_utils.calcDefaultQuota;
|
|
49
47
|
exports.calcQuotaUpdate = require_onchain_accounts_quota_utils.calcQuotaUpdate;
|
|
50
48
|
exports.calcRecommendedQuota = require_onchain_accounts_quota_utils.calcRecommendedQuota;
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
2
|
+
const require_onchain_validation_helpers_health_factor_limits = require("../../validation/helpers/health-factor-limits.js");
|
|
3
|
+
const require_onchain_validation_helpers_token = require("../../validation/helpers/token.js");
|
|
4
|
+
const require_onchain_validation_checks_checkBorrowLimit = require("../../validation/checks/checkBorrowLimit.js");
|
|
5
|
+
const require_onchain_validation_checks_checkCollateralised = require("../../validation/checks/checkCollateralised.js");
|
|
6
|
+
const require_onchain_validation_checks_checkCreditManagerPaused = require("../../validation/checks/checkCreditManagerPaused.js");
|
|
7
|
+
const require_onchain_validation_checks_checkForbiddenToken = require("../../validation/checks/checkForbiddenToken.js");
|
|
8
|
+
const require_onchain_validation_checks_checkMarketExpired = require("../../validation/checks/checkMarketExpired.js");
|
|
9
|
+
const require_onchain_validation_checks_checkQuotaLimit = require("../../validation/checks/checkQuotaLimit.js");
|
|
10
|
+
const require_onchain_validation_raise = require("../../validation/raise.js");
|
|
11
|
+
require("../../validation/index.js");
|
|
5
12
|
const require_onchain_accounts_intents_utils_common = require("./utils/common.js");
|
|
6
13
|
const require_onchain_accounts_intents_utils_pick_token = require("./utils/pick-token.js");
|
|
7
14
|
//#region src/onchain/accounts/intents/guards.ts
|
|
@@ -25,54 +32,25 @@ const require_onchain_accounts_intents_utils_pick_token = require("./utils/pick-
|
|
|
25
32
|
*/
|
|
26
33
|
function assertMarketOperable(suite) {
|
|
27
34
|
const creditManager = suite.creditManager.address;
|
|
28
|
-
|
|
35
|
+
require_onchain_validation_raise.raise(require_onchain_validation_checks_checkCreditManagerPaused.checkCreditManagerPaused({
|
|
29
36
|
isPaused: suite.isPaused,
|
|
30
37
|
creditManager
|
|
31
38
|
}), `${creditManager} is paused`);
|
|
32
|
-
|
|
39
|
+
require_onchain_validation_raise.raise(require_onchain_validation_checks_checkMarketExpired.checkMarketExpired({
|
|
33
40
|
isExpired: suite.isExpired,
|
|
34
41
|
creditManager,
|
|
35
42
|
expirationDate: suite.creditFacade.expirationDate
|
|
36
43
|
}), `${creditManager} expired at ${suite.creditFacade.expirationDate}`);
|
|
37
44
|
}
|
|
38
|
-
/**
|
|
39
|
-
* What the pool will hand this manager in one transaction: the tightest of its
|
|
40
|
-
* free liquidity, the manager's remaining debt limit and the per-block cap the
|
|
41
|
-
* facade puts on a single borrow. A zero multiplier switches borrowing off
|
|
42
|
-
* outright, which reads here as nothing being available.
|
|
43
|
-
*/
|
|
44
|
-
function borrowable(suite) {
|
|
45
|
-
const { pool } = suite.market.pool;
|
|
46
|
-
const { maxDebtPerBlockMultiplier, maxDebt } = suite.creditFacade;
|
|
47
|
-
if (maxDebtPerBlockMultiplier === 0) return {
|
|
48
|
-
limit: 0n,
|
|
49
|
-
binding: "facadePerBlockCap"
|
|
50
|
-
};
|
|
51
|
-
const available = pool.creditManagerDebtParams.get(suite.creditManager.address)?.available;
|
|
52
|
-
return [
|
|
53
|
-
{
|
|
54
|
-
limit: pool.availableLiquidity,
|
|
55
|
-
binding: "poolAvailableLiquidity"
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
limit: maxDebt * BigInt(maxDebtPerBlockMultiplier),
|
|
59
|
-
binding: "facadePerBlockCap"
|
|
60
|
-
},
|
|
61
|
-
...available === void 0 ? [] : [{
|
|
62
|
-
limit: available,
|
|
63
|
-
binding: "managerDebtAvailable"
|
|
64
|
-
}]
|
|
65
|
-
].reduce((a, b) => b.limit < a.limit ? b : a);
|
|
66
|
-
}
|
|
67
45
|
/** The pool has to be able to lend what the plan means to draw. */
|
|
68
46
|
function assertCanBorrow(sdk, suite, amount) {
|
|
69
|
-
const {
|
|
70
|
-
|
|
47
|
+
const { value, limit } = suite.maxBorrowAmount();
|
|
48
|
+
require_onchain_validation_raise.raise(require_onchain_validation_checks_checkBorrowLimit.checkBorrowLimit({
|
|
71
49
|
requested: amount,
|
|
72
|
-
available:
|
|
73
|
-
|
|
74
|
-
underlying:
|
|
75
|
-
}), `borrow: ${amount} exceeds what the pool can lend now (${
|
|
50
|
+
available: value,
|
|
51
|
+
limit,
|
|
52
|
+
underlying: require_onchain_validation_helpers_token.toToken(sdk, suite.market.pool.underlying)
|
|
53
|
+
}), `borrow: ${amount} exceeds what the pool can lend now (${value})`);
|
|
76
54
|
}
|
|
77
55
|
/**
|
|
78
56
|
* What the account is allowed to end up holding more of than it started with.
|
|
@@ -88,20 +66,19 @@ function assertCanBorrow(sdk, suite, amount) {
|
|
|
88
66
|
*/
|
|
89
67
|
function assertGrowthAllowed(args) {
|
|
90
68
|
const { sdk, suite, market, before, after } = args;
|
|
91
|
-
const forbidden = suite.forbiddenTokens;
|
|
92
69
|
const underlying = market.pool.underlying;
|
|
93
70
|
for (const { token, balance } of after) {
|
|
94
71
|
if (balance <= (before.find((a) => require_onchain_accounts_intents_utils_common.eq(a.token, token))?.balance ?? 0n)) continue;
|
|
95
|
-
|
|
96
|
-
token:
|
|
97
|
-
isForbidden:
|
|
72
|
+
require_onchain_validation_raise.raise(require_onchain_validation_checks_checkForbiddenToken.checkForbiddenToken({
|
|
73
|
+
token: require_onchain_validation_helpers_token.toToken(sdk, token),
|
|
74
|
+
isForbidden: suite.isForbidden(token)
|
|
98
75
|
}), `${token} is forbidden in this market and the plan buys more of it`);
|
|
99
76
|
if (require_onchain_accounts_intents_utils_common.eq(token, underlying) || require_onchain_accounts_intents_utils_pick_token.isPhantomToken(sdk, token)) continue;
|
|
100
|
-
if (!market.pool.pqk.hasActiveQuota(token))
|
|
101
|
-
token:
|
|
77
|
+
if (!market.pool.pqk.hasActiveQuota(token)) require_onchain_validation_raise.raise(require_onchain_validation_checks_checkQuotaLimit.checkQuotaLimit({
|
|
78
|
+
token: require_onchain_validation_helpers_token.toToken(sdk, token),
|
|
102
79
|
requested: void 0,
|
|
103
80
|
available: 0n,
|
|
104
|
-
underlying:
|
|
81
|
+
underlying: require_onchain_validation_helpers_token.toToken(sdk, underlying)
|
|
105
82
|
}), `${token} takes no quota in this market, so it counts as no collateral`);
|
|
106
83
|
}
|
|
107
84
|
}
|
|
@@ -110,19 +87,20 @@ function assertGrowthAllowed(args) {
|
|
|
110
87
|
* and reverts if the collateral does not cover it, so a plan that lands the
|
|
111
88
|
* account below water is refused here.
|
|
112
89
|
*
|
|
113
|
-
* The
|
|
114
|
-
* would the transaction revert. It is deliberately not
|
|
115
|
-
* the three
|
|
90
|
+
* The threshold is the facade's own `1.0`, because this guard answers one
|
|
91
|
+
* question: would the transaction revert. It is deliberately not
|
|
92
|
+
* `MIN_HF_LIMITED`, and the three thresholds in this codebase are three
|
|
93
|
+
* different jobs:
|
|
116
94
|
*
|
|
117
95
|
* - here, `1.0` — what the facade enforces, so what a plan must clear to land;
|
|
118
96
|
* - `maxWithdrawCollateral` sizes at `MIN_HF_LIMITED + 2` — a *sizing* helper
|
|
119
|
-
* leaving
|
|
97
|
+
* leaving a margin, which is not the same as a validity check;
|
|
120
98
|
* - a form refuses at or below `MIN_HF_LIMITED` (`MIN_HEALTH_FACTOR_FORM`).
|
|
121
99
|
*
|
|
122
100
|
* Raising this one to `MIN_HF_LIMITED` was tried and reverted: it made
|
|
123
101
|
* `maxWithdraw` hand back a ceiling this guard then refused, and it blocked
|
|
124
102
|
* small top-ups of an account sitting in `[1.0, 1.01)` — the very operations
|
|
125
|
-
* that rescue it. A form wanting the stricter
|
|
103
|
+
* that rescue it. A form wanting the stricter threshold has `validateHF`.
|
|
126
104
|
*
|
|
127
105
|
* Note that a position already underwater cannot be nursed back one step at a
|
|
128
106
|
* time — the check is on where the transaction ends, not on whether it
|
|
@@ -135,29 +113,28 @@ function assertGrowthAllowed(args) {
|
|
|
135
113
|
* still be refused on-chain after passing here.
|
|
136
114
|
*/
|
|
137
115
|
function assertCollateralised(healthFactorBps, safePrices) {
|
|
138
|
-
const
|
|
139
|
-
|
|
116
|
+
const healthFactorThreshold = require_onchain_validation_helpers_health_factor_limits.MIN_HEALTH_FACTOR_FACADE;
|
|
117
|
+
require_onchain_validation_raise.raise(require_onchain_validation_checks_checkCollateralised.checkCollateralised({
|
|
140
118
|
healthFactor: healthFactorBps,
|
|
141
|
-
|
|
119
|
+
healthFactorThreshold,
|
|
142
120
|
safePrices
|
|
143
|
-
}), `the account would end at a health factor of ${healthFactorBps}, below ${
|
|
121
|
+
}), `the account would end at a health factor of ${healthFactorBps}, below ${healthFactorThreshold}`);
|
|
144
122
|
}
|
|
145
123
|
/**
|
|
146
124
|
* A quota can only be raised as far as the market still has room for: past the
|
|
147
125
|
* token's limit the keeper takes nothing more, whoever is asking.
|
|
148
126
|
*/
|
|
149
|
-
function
|
|
127
|
+
function assertQuotaAvailable(sdk, market, increases) {
|
|
150
128
|
const underlying = market.pool.underlying;
|
|
129
|
+
const { pqk } = market.pool;
|
|
151
130
|
for (const { token, balance } of increases) {
|
|
152
|
-
if (balance <= 0n) continue;
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
require_onchain_validation_refusal.raise(require_onchain_validation_checks.checkQuotaLimit({
|
|
157
|
-
token: require_onchain_validation_token.toToken(sdk, token),
|
|
131
|
+
if (balance <= 0n || !pqk.quotas.has(token)) continue;
|
|
132
|
+
const left = pqk.quotaAvailable(token);
|
|
133
|
+
require_onchain_validation_raise.raise(require_onchain_validation_checks_checkQuotaLimit.checkQuotaLimit({
|
|
134
|
+
token: require_onchain_validation_helpers_token.toToken(sdk, token),
|
|
158
135
|
requested: balance,
|
|
159
136
|
available: left,
|
|
160
|
-
underlying:
|
|
137
|
+
underlying: require_onchain_validation_helpers_token.toToken(sdk, underlying)
|
|
161
138
|
}), `${token} has ${left} of quota left, the plan needs ${balance}`);
|
|
162
139
|
}
|
|
163
140
|
}
|
|
@@ -166,5 +143,4 @@ exports.assertCanBorrow = assertCanBorrow;
|
|
|
166
143
|
exports.assertCollateralised = assertCollateralised;
|
|
167
144
|
exports.assertGrowthAllowed = assertGrowthAllowed;
|
|
168
145
|
exports.assertMarketOperable = assertMarketOperable;
|
|
169
|
-
exports.
|
|
170
|
-
exports.borrowable = borrowable;
|
|
146
|
+
exports.assertQuotaAvailable = assertQuotaAvailable;
|
|
@@ -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;
|