@gearbox-protocol/sdk 16.1.2 → 16.3.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/history/assembleOperations.js +3 -3
- package/dist/cjs/history/classifyMulticallOperations.js +7 -7
- package/dist/cjs/history/index.js +13 -0
- package/dist/cjs/history/parseCreditAccountTransaction.js +5 -5
- package/dist/cjs/{preview → history}/trace/errors.js +1 -1
- package/dist/cjs/{preview → history}/trace/extractAdapterCallTraces.js +1 -1
- package/dist/cjs/{preview → history}/trace/extractTransfers.js +3 -3
- package/dist/cjs/{preview → history}/trace/findFacadeCalls.js +3 -3
- package/dist/cjs/history/trace/index.js +14 -0
- package/dist/cjs/model/errors/index.js +37 -0
- package/dist/cjs/model/errors/liquidation-errors.js +32 -0
- package/dist/cjs/model/errors/operation-errors.js +135 -0
- package/dist/cjs/{onchain/market/oracle/errors.js → model/errors/oracle-errors.js} +1 -1
- package/dist/cjs/model/errors/prepare-errors.js +108 -0
- package/dist/cjs/model/errors/preview-errors.js +12 -0
- package/dist/cjs/model/index.js +40 -2
- package/dist/cjs/model/positions.js +1 -1
- package/dist/cjs/model/result.js +0 -8
- package/dist/cjs/model/rwa.js +40 -0
- package/dist/cjs/onchain/accounts/CreditAccountsServiceV310.js +2 -2
- package/dist/cjs/onchain/accounts/index.js +0 -2
- package/dist/cjs/onchain/accounts/intents/guards.js +42 -66
- package/dist/cjs/onchain/accounts/intents/index.js +38 -35
- package/dist/cjs/onchain/accounts/intents/leverage-band.js +1 -1
- package/dist/cjs/onchain/accounts/intents/math.js +19 -15
- package/dist/cjs/onchain/accounts/intents/open-strategy.js +44 -8
- package/dist/cjs/onchain/accounts/intents/plan.js +52 -48
- package/dist/cjs/onchain/accounts/intents/realize.js +26 -24
- package/dist/cjs/onchain/accounts/intents/tail.js +15 -12
- package/dist/cjs/onchain/accounts/intents/testing/sdk-mock.js +7 -0
- package/dist/cjs/onchain/accounts/intents/tests/finish-withdraw.fixtures.js +6 -6
- package/dist/cjs/onchain/accounts/intents/tests/withdraw.fixtures.js +12 -12
- package/dist/cjs/onchain/accounts/intents/view.js +1 -1
- package/dist/cjs/onchain/accounts/withdrawal-compressor/index.js +0 -1
- package/dist/cjs/onchain/index.js +122 -36
- package/dist/cjs/onchain/market/MarketSuite.js +7 -1
- package/dist/cjs/onchain/market/adapters/index.js +1 -0
- package/dist/cjs/onchain/market/credit/CreditSuite.js +47 -15
- package/dist/cjs/onchain/market/index.js +0 -6
- package/dist/cjs/onchain/market/oracle/PriceOracleBaseContract.js +6 -6
- package/dist/cjs/onchain/market/oracle/index.js +0 -2
- package/dist/cjs/onchain/market/pool/PoolQuotaKeeperV310Contract.js +8 -0
- package/dist/cjs/onchain/market/rwa/RWARegistry.js +3 -2
- package/dist/cjs/onchain/market/rwa/index.js +0 -4
- package/dist/cjs/onchain/market/rwa/securitize/SecuritizeRWAFactory.js +7 -7
- package/dist/cjs/onchain/market/rwa/securitize/constants.js +0 -2
- package/dist/cjs/onchain/market/rwa/securitize/index.js +1 -3
- package/dist/cjs/onchain/market/rwa/securitize/types.js +0 -29
- package/dist/cjs/onchain/market/rwa/types.js +0 -7
- package/dist/cjs/onchain/market/zapper/index.js +0 -1
- package/dist/cjs/onchain/pools/PoolService.js +10 -16
- package/dist/cjs/onchain/preview/index.js +41 -0
- package/dist/cjs/{preview → onchain/preview}/parse/classifyInnerOperations.js +2 -3
- package/dist/cjs/onchain/preview/parse/index.js +14 -0
- package/dist/cjs/{preview → onchain/preview}/parse/parseFacadeOperationCalldata.js +3 -3
- package/dist/cjs/{preview → onchain/preview}/parse/parseOperationCalldata.js +16 -17
- package/dist/cjs/{preview → onchain/preview}/parse/parsePoolOperationCalldata.js +3 -3
- package/dist/cjs/{preview → onchain/preview}/parse/parseRWAFactoryOperationCalldata.js +11 -12
- package/dist/cjs/{preview → onchain/preview}/parse/types.js +1 -1
- package/dist/cjs/{preview → onchain/preview}/preview/CreditAccountState.js +3 -4
- package/dist/cjs/{preview → onchain/preview}/preview/buildDelayedStrategyPositionOperationPreview.js +10 -11
- package/dist/cjs/{preview → onchain/preview}/preview/detectCloseOrRepay.js +2 -3
- package/dist/cjs/{preview → onchain/preview}/preview/detectDelayedClaim.js +4 -5
- package/dist/cjs/{preview → onchain/preview}/preview/detectDelayedOperation.js +5 -6
- package/dist/cjs/{preview → onchain/preview}/preview/estimateClaimableAt.js +1 -1
- package/dist/cjs/onchain/preview/preview/index.js +26 -0
- package/dist/cjs/{preview → onchain/preview}/preview/previewAdjustStrategyPosition.js +18 -22
- package/dist/cjs/{preview → onchain/preview}/preview/previewExitOrRepayStrategyPosition.js +22 -28
- package/dist/cjs/onchain/preview/preview/previewOpenStrategyPosition.js +60 -0
- package/dist/cjs/onchain/preview/preview/previewOperation.js +119 -0
- package/dist/cjs/{preview/simulate/simulatePoolOperation.js → onchain/preview/preview/previewPoolPositionOperation.js} +46 -32
- package/dist/cjs/onchain/preview/preview/replayInnerOperations.js +109 -0
- package/dist/cjs/onchain/preview/preview/replayMulticall.js +22 -0
- package/dist/cjs/{preview → onchain/preview}/preview/unwrapNativeCollateral.js +11 -14
- package/dist/cjs/onchain/validation/bundles/checkAccountQuotas.js +20 -0
- package/dist/cjs/onchain/validation/bundles/checkCollateralFunding.js +59 -0
- package/dist/cjs/onchain/validation/bundles/checkCreditOperation.js +65 -0
- package/dist/cjs/onchain/validation/bundles/checkDraw.js +28 -0
- package/dist/cjs/onchain/validation/bundles/checkHealthFactors.js +27 -0
- package/dist/cjs/onchain/validation/bundles/checkLiquidationEligibility.js +33 -0
- package/dist/cjs/onchain/validation/bundles/checkLiquidationFunding.js +29 -0
- package/dist/cjs/onchain/validation/bundles/checkMarket.js +24 -0
- package/dist/cjs/onchain/validation/bundles/checkObtained.js +13 -0
- package/dist/cjs/onchain/validation/bundles/checkPoolFunding.js +22 -0
- package/dist/cjs/onchain/validation/bundles/checkPoolOperation.js +35 -0
- package/dist/cjs/onchain/validation/bundles/checkQuotasAsked.js +20 -0
- package/dist/cjs/onchain/validation/bundles/checkRWAOpenRequirements.js +33 -0
- package/dist/cjs/onchain/validation/bundles/checkRWAOpening.js +24 -0
- package/dist/cjs/onchain/validation/bundles/checkWallet.js +22 -0
- package/dist/cjs/onchain/validation/bundles/checkWalletAllowance.js +32 -0
- package/dist/cjs/onchain/validation/bundles/checkWalletBalance.js +41 -0
- package/dist/cjs/onchain/validation/bundles/index.js +35 -0
- package/dist/cjs/onchain/validation/checkLiquidation.js +22 -0
- package/dist/cjs/onchain/validation/checkOperation.js +62 -0
- package/dist/cjs/onchain/validation/checkSimulation.js +60 -0
- package/dist/cjs/onchain/validation/checks/checkBorrowLimit.js +25 -0
- package/dist/cjs/onchain/validation/checks/checkCollateralised.js +26 -0
- package/dist/cjs/onchain/validation/checks/checkCreditAccountFrozen.js +10 -0
- package/dist/cjs/onchain/validation/checks/checkCreditManagerPaused.js +10 -0
- package/dist/cjs/onchain/validation/checks/checkDebtLimits.js +18 -0
- package/dist/cjs/onchain/validation/checks/checkEmergencyLiquidator.js +13 -0
- package/dist/cjs/onchain/validation/checks/checkForbiddenToken.js +10 -0
- package/dist/cjs/onchain/validation/checks/checkLeverage.js +13 -0
- package/dist/cjs/onchain/validation/checks/checkLiquidatorEligible.js +10 -0
- package/dist/cjs/onchain/validation/checks/checkMarketExpired.js +10 -0
- package/dist/cjs/onchain/validation/checks/checkPoolLiquidity.js +25 -0
- package/dist/cjs/onchain/validation/checks/checkPoolPaused.js +10 -0
- package/dist/cjs/onchain/validation/checks/checkPoolSunset.js +10 -0
- package/dist/cjs/onchain/validation/checks/checkQuotaCount.js +10 -0
- package/dist/cjs/onchain/validation/checks/checkQuotaLimit.js +18 -0
- package/dist/cjs/onchain/validation/checks/index.js +31 -0
- package/dist/cjs/onchain/validation/helpers/amount.js +12 -0
- package/dist/cjs/onchain/validation/helpers/health-factor-limits.js +25 -0
- package/dist/cjs/onchain/validation/helpers/index.js +11 -0
- package/dist/cjs/onchain/validation/{token.js → helpers/token.js} +4 -4
- package/dist/cjs/onchain/validation/index.js +85 -27
- package/dist/cjs/onchain/validation/raise.js +33 -0
- package/dist/cjs/sdk/execute/ExecuteApi.js +1 -0
- package/dist/cjs/sdk/index.js +6 -9
- package/dist/cjs/sdk/liquidations/LiquidationsNamespace.js +9 -0
- package/dist/cjs/sdk/prepare/PrepareApi.js +55 -48
- package/dist/cjs/sdk/prepare/index.js +7 -9
- package/dist/cjs/sdk/prepare/types.js +0 -4
- package/dist/cjs/sdk/preview/PreviewNamespace.js +24 -13
- package/dist/esm/history/assembleOperations.js +2 -2
- package/dist/esm/history/classifyMulticallOperations.js +2 -2
- package/dist/esm/history/index.js +6 -1
- package/dist/esm/history/parseCreditAccountTransaction.js +3 -3
- package/dist/esm/{preview → history}/trace/errors.js +1 -1
- package/dist/esm/{preview → history}/trace/extractAdapterCallTraces.js +1 -1
- package/dist/esm/{preview → history}/trace/extractTransfers.js +1 -1
- package/dist/esm/{preview → history}/trace/findFacadeCalls.js +1 -1
- package/dist/esm/model/errors/index.js +7 -0
- package/dist/esm/model/errors/liquidation-errors.js +29 -0
- package/dist/esm/model/errors/operation-errors.js +121 -0
- package/dist/esm/{onchain/market/oracle/errors.js → model/errors/oracle-errors.js} +1 -1
- package/dist/esm/model/errors/prepare-errors.js +97 -0
- package/dist/esm/model/errors/preview-errors.js +11 -0
- package/dist/esm/model/index.js +9 -3
- package/dist/esm/model/positions.js +1 -1
- package/dist/esm/model/result.js +1 -8
- package/dist/esm/model/rwa.js +37 -0
- package/dist/esm/onchain/accounts/CreditAccountsServiceV310.js +2 -2
- package/dist/esm/onchain/accounts/index.js +1 -2
- package/dist/esm/onchain/accounts/intents/guards.js +29 -52
- package/dist/esm/onchain/accounts/intents/index.js +39 -35
- package/dist/esm/onchain/accounts/intents/leverage-band.js +1 -1
- package/dist/esm/onchain/accounts/intents/math.js +18 -14
- package/dist/esm/onchain/accounts/intents/open-strategy.js +46 -10
- package/dist/esm/onchain/accounts/intents/plan.js +51 -47
- package/dist/esm/onchain/accounts/intents/realize.js +26 -24
- package/dist/esm/onchain/accounts/intents/tail.js +14 -11
- package/dist/esm/onchain/accounts/intents/testing/sdk-mock.js +7 -0
- package/dist/esm/onchain/accounts/intents/tests/finish-withdraw.fixtures.js +6 -6
- package/dist/esm/onchain/accounts/intents/tests/withdraw.fixtures.js +12 -12
- package/dist/esm/onchain/accounts/intents/view.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/index.js +0 -1
- package/dist/esm/onchain/index.js +61 -10
- package/dist/esm/onchain/market/MarketSuite.js +7 -1
- package/dist/esm/onchain/market/adapters/index.js +1 -0
- package/dist/esm/onchain/market/credit/CreditSuite.js +47 -15
- package/dist/esm/onchain/market/index.js +3 -5
- package/dist/esm/onchain/market/oracle/PriceOracleBaseContract.js +1 -1
- package/dist/esm/onchain/market/oracle/index.js +1 -2
- package/dist/esm/onchain/market/pool/PoolQuotaKeeperV310Contract.js +8 -0
- package/dist/esm/onchain/market/rwa/RWARegistry.js +2 -1
- package/dist/esm/onchain/market/rwa/index.js +3 -4
- package/dist/esm/onchain/market/rwa/securitize/SecuritizeRWAFactory.js +2 -2
- package/dist/esm/onchain/market/rwa/securitize/constants.js +1 -2
- package/dist/esm/onchain/market/rwa/securitize/index.js +3 -3
- package/dist/esm/onchain/market/rwa/securitize/types.js +1 -29
- package/dist/esm/onchain/market/rwa/types.js +1 -7
- package/dist/esm/onchain/market/zapper/index.js +0 -1
- package/dist/esm/onchain/pools/PoolService.js +10 -16
- package/dist/esm/onchain/preview/index.js +20 -0
- package/dist/esm/{preview → onchain/preview}/parse/classifyInnerOperations.js +2 -3
- package/dist/esm/{preview → onchain/preview}/parse/index.js +0 -1
- package/dist/esm/{preview → onchain/preview}/parse/parseFacadeOperationCalldata.js +1 -1
- package/dist/esm/{preview → onchain/preview}/parse/parseOperationCalldata.js +10 -11
- package/dist/esm/{preview → onchain/preview}/parse/parsePoolOperationCalldata.js +3 -3
- package/dist/esm/{preview → onchain/preview}/parse/parseRWAFactoryOperationCalldata.js +8 -9
- package/dist/esm/{preview → onchain/preview}/parse/types.js +1 -1
- package/dist/esm/{preview → onchain/preview}/preview/CreditAccountState.js +3 -4
- package/dist/esm/{preview → onchain/preview}/preview/buildDelayedStrategyPositionOperationPreview.js +10 -11
- package/dist/esm/{preview → onchain/preview}/preview/detectCloseOrRepay.js +2 -3
- package/dist/esm/{preview → onchain/preview}/preview/detectDelayedClaim.js +4 -5
- package/dist/esm/{preview → onchain/preview}/preview/detectDelayedOperation.js +5 -6
- package/dist/esm/{preview → onchain/preview}/preview/estimateClaimableAt.js +1 -1
- package/dist/esm/{preview → onchain/preview}/preview/index.js +3 -4
- package/dist/esm/{preview → onchain/preview}/preview/previewAdjustStrategyPosition.js +17 -21
- package/dist/esm/{preview → onchain/preview}/preview/previewExitOrRepayStrategyPosition.js +20 -26
- package/dist/esm/{preview → onchain/preview}/preview/previewOpenStrategyPosition.js +25 -15
- package/dist/esm/{preview → onchain/preview}/preview/previewOperation.js +54 -35
- package/dist/esm/{preview/simulate/simulatePoolOperation.js → onchain/preview/preview/previewPoolPositionOperation.js} +46 -30
- package/dist/esm/onchain/preview/preview/replayInnerOperations.js +107 -0
- package/dist/esm/onchain/preview/preview/replayMulticall.js +21 -0
- package/dist/esm/{preview → onchain/preview}/preview/unwrapNativeCollateral.js +11 -14
- package/dist/esm/onchain/validation/bundles/checkAccountQuotas.js +19 -0
- package/dist/esm/onchain/validation/bundles/checkCollateralFunding.js +58 -0
- package/dist/esm/onchain/validation/bundles/checkCreditOperation.js +64 -0
- package/dist/esm/onchain/validation/bundles/checkDraw.js +27 -0
- package/dist/esm/onchain/validation/bundles/checkHealthFactors.js +26 -0
- package/dist/esm/onchain/validation/bundles/checkLiquidationEligibility.js +32 -0
- package/dist/esm/onchain/validation/bundles/checkLiquidationFunding.js +28 -0
- package/dist/esm/onchain/validation/bundles/checkMarket.js +23 -0
- package/dist/esm/onchain/validation/bundles/checkObtained.js +12 -0
- package/dist/esm/onchain/validation/bundles/checkPoolFunding.js +21 -0
- package/dist/esm/onchain/validation/bundles/checkPoolOperation.js +34 -0
- package/dist/esm/onchain/validation/bundles/checkQuotasAsked.js +19 -0
- package/dist/esm/onchain/validation/bundles/checkRWAOpenRequirements.js +32 -0
- package/dist/esm/onchain/validation/bundles/checkRWAOpening.js +23 -0
- package/dist/esm/onchain/validation/bundles/checkWallet.js +21 -0
- package/dist/esm/onchain/validation/bundles/checkWalletAllowance.js +31 -0
- package/dist/esm/onchain/validation/bundles/checkWalletBalance.js +40 -0
- package/dist/esm/onchain/validation/bundles/index.js +18 -0
- package/dist/esm/onchain/validation/checkLiquidation.js +21 -0
- package/dist/esm/onchain/validation/checkOperation.js +61 -0
- package/dist/esm/onchain/validation/checkSimulation.js +59 -0
- package/dist/esm/onchain/validation/checks/checkBorrowLimit.js +24 -0
- package/dist/esm/onchain/validation/checks/checkCollateralised.js +25 -0
- package/dist/esm/onchain/validation/checks/checkCreditAccountFrozen.js +9 -0
- package/dist/esm/onchain/validation/checks/checkCreditManagerPaused.js +9 -0
- package/dist/esm/onchain/validation/checks/checkDebtLimits.js +17 -0
- package/dist/esm/onchain/validation/checks/checkEmergencyLiquidator.js +12 -0
- package/dist/esm/onchain/validation/checks/checkForbiddenToken.js +9 -0
- package/dist/esm/onchain/validation/checks/checkLeverage.js +12 -0
- package/dist/esm/onchain/validation/checks/checkLiquidatorEligible.js +9 -0
- package/dist/esm/onchain/validation/checks/checkMarketExpired.js +9 -0
- package/dist/esm/onchain/validation/checks/checkPoolLiquidity.js +24 -0
- package/dist/esm/onchain/validation/checks/checkPoolPaused.js +9 -0
- package/dist/esm/onchain/validation/checks/checkPoolSunset.js +9 -0
- package/dist/esm/onchain/validation/checks/checkQuotaCount.js +9 -0
- package/dist/esm/onchain/validation/checks/checkQuotaLimit.js +17 -0
- package/dist/esm/onchain/validation/checks/index.js +16 -0
- package/dist/esm/onchain/validation/helpers/amount.js +11 -0
- package/dist/esm/onchain/validation/helpers/health-factor-limits.js +21 -0
- package/dist/esm/onchain/validation/helpers/index.js +4 -0
- package/dist/esm/onchain/validation/{token.js → helpers/token.js} +3 -3
- package/dist/esm/onchain/validation/index.js +43 -4
- package/dist/esm/onchain/validation/raise.js +31 -0
- package/dist/esm/sdk/execute/ExecuteApi.js +1 -0
- package/dist/esm/sdk/index.js +2 -3
- package/dist/esm/sdk/liquidations/LiquidationsNamespace.js +9 -0
- package/dist/esm/sdk/prepare/PrepareApi.js +43 -36
- package/dist/esm/sdk/prepare/index.js +3 -3
- package/dist/esm/sdk/prepare/types.js +1 -2
- package/dist/esm/sdk/preview/PreviewNamespace.js +24 -13
- package/dist/types/history/assembleOperations.d.ts +4 -5
- package/dist/types/history/classifyMulticallOperations.d.ts +3 -4
- package/dist/types/history/index.d.ts +8 -2
- package/dist/types/history/mapOperations.d.ts +1 -1
- package/dist/types/{preview → history}/trace/errors.d.ts +1 -1
- package/dist/types/{preview → history}/trace/extractAdapterCallTraces.d.ts +1 -1
- package/dist/types/{preview → history}/trace/extractTransfers.d.ts +2 -3
- package/dist/types/{preview → history}/trace/findFacadeCalls.d.ts +1 -1
- package/dist/types/{preview → history}/trace/types.d.ts +1 -1
- package/dist/types/history/types.d.ts +2 -3
- package/dist/types/model/errors/base.d.ts +28 -0
- package/dist/types/model/errors/index.d.ts +7 -0
- package/dist/types/model/errors/liquidation-errors.d.ts +45 -0
- package/dist/types/model/errors/operation-errors.d.ts +216 -0
- package/dist/types/{onchain/market/oracle/errors.d.ts → model/errors/oracle-errors.d.ts} +3 -5
- package/dist/types/model/errors/prepare-errors.d.ts +131 -0
- package/dist/types/model/errors/preview-errors.d.ts +72 -0
- package/dist/types/model/index.d.ts +11 -4
- package/dist/types/model/opportunities.d.ts +3 -2
- package/dist/types/model/positions.d.ts +2 -2
- package/dist/types/model/previews.d.ts +52 -113
- package/dist/types/model/result.d.ts +4 -8
- package/dist/types/model/rwa.d.ts +143 -0
- package/dist/types/onchain/accounts/CreditAccountsServiceV310.d.ts +3 -1
- package/dist/types/onchain/accounts/index.d.ts +2 -4
- package/dist/types/onchain/accounts/intents/guards.d.ts +8 -18
- package/dist/types/onchain/accounts/intents/index.d.ts +20 -19
- package/dist/types/onchain/accounts/intents/leverage-band.d.ts +1 -1
- package/dist/types/onchain/accounts/intents/math.d.ts +6 -6
- package/dist/types/onchain/accounts/intents/open-strategy.d.ts +34 -3
- package/dist/types/onchain/accounts/intents/operations.d.ts +2 -2
- package/dist/types/onchain/accounts/intents/plan.d.ts +9 -9
- package/dist/types/onchain/accounts/intents/tail.d.ts +2 -2
- package/dist/types/onchain/accounts/intents/testing/expect.d.ts +3 -3
- package/dist/types/onchain/accounts/intents/tests/finish-withdraw.fixtures.d.ts +6 -6
- package/dist/types/onchain/accounts/intents/tests/open-strategy.fixtures.d.ts +2 -2
- package/dist/types/onchain/accounts/intents/tests/withdraw.fixtures.d.ts +12 -12
- package/dist/types/onchain/accounts/intents/types.d.ts +32 -30
- package/dist/types/onchain/accounts/types.d.ts +4 -2
- package/dist/types/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.d.ts +1 -1
- package/dist/types/onchain/accounts/withdrawal-compressor/index.d.ts +1 -2
- package/dist/types/onchain/accounts/withdrawal-compressor/types.d.ts +1 -1
- package/dist/types/onchain/index.d.ts +68 -13
- package/dist/types/onchain/market/MarketSuite.d.ts +5 -1
- package/dist/types/onchain/market/adapters/index.d.ts +2 -1
- package/dist/types/onchain/market/adapters/transfers.d.ts +0 -7
- package/dist/types/onchain/market/credit/CreditSuite.d.ts +20 -8
- package/dist/types/onchain/market/credit/index.d.ts +2 -2
- package/dist/types/onchain/market/credit/types.d.ts +11 -1
- package/dist/types/onchain/market/index.d.ts +6 -7
- package/dist/types/onchain/market/oracle/PriceOracleBaseContract.d.ts +1 -1
- package/dist/types/onchain/market/oracle/index.d.ts +1 -2
- package/dist/types/onchain/market/oracle/types.d.ts +1 -1
- package/dist/types/onchain/market/pool/PoolQuotaKeeperV310Contract.d.ts +5 -0
- package/dist/types/onchain/market/rwa/index.d.ts +4 -4
- package/dist/types/onchain/market/rwa/securitize/SecuritizeRWAFactory.d.ts +3 -2
- package/dist/types/onchain/market/rwa/securitize/constants.d.ts +1 -2
- package/dist/types/onchain/market/rwa/securitize/index.d.ts +3 -3
- package/dist/types/onchain/market/rwa/securitize/types.d.ts +4 -110
- package/dist/types/onchain/market/rwa/types.d.ts +6 -32
- package/dist/types/onchain/market/zapper/ZapperContract.d.ts +1 -1
- package/dist/types/onchain/market/zapper/index.d.ts +1 -2
- package/dist/types/onchain/market/zapper/types.d.ts +1 -1
- package/dist/types/onchain/pools/types.d.ts +2 -2
- package/dist/types/onchain/preview/index.d.ts +24 -0
- package/dist/types/{preview → onchain/preview}/parse/classifyInnerOperations.d.ts +4 -4
- package/dist/types/{preview → onchain/preview}/parse/index.d.ts +2 -4
- package/dist/types/{preview → onchain/preview}/parse/parseFacadeOperationCalldata.d.ts +4 -4
- package/dist/types/onchain/preview/parse/parseOperationCalldata.d.ts +18 -0
- package/dist/types/{preview → onchain/preview}/parse/parsePoolOperationCalldata.d.ts +7 -7
- package/dist/types/{preview → onchain/preview}/parse/parseRWAFactoryOperationCalldata.d.ts +4 -4
- package/dist/types/{preview → onchain/preview}/parse/types-adapters.d.ts +5 -16
- package/dist/types/{preview → onchain/preview}/parse/types-facades.d.ts +3 -3
- package/dist/types/{preview → onchain/preview}/parse/types-pools.d.ts +1 -1
- package/dist/types/{preview → onchain/preview}/parse/types-rwa.d.ts +3 -3
- package/dist/types/{preview → onchain/preview}/parse/types.d.ts +3 -3
- package/dist/types/{preview → onchain/preview}/preview/CreditAccountState.d.ts +5 -5
- package/dist/types/{preview → onchain/preview}/preview/buildDelayedStrategyPositionOperationPreview.d.ts +5 -5
- package/dist/types/{preview → onchain/preview}/preview/detectCloseOrRepay.d.ts +1 -1
- package/dist/types/{preview → onchain/preview}/preview/detectDelayedClaim.d.ts +8 -8
- package/dist/types/{preview → onchain/preview}/preview/detectDelayedOperation.d.ts +9 -9
- package/dist/types/{preview → onchain/preview}/preview/estimateClaimableAt.d.ts +6 -6
- package/dist/types/{preview → onchain/preview}/preview/index.d.ts +3 -4
- package/dist/types/onchain/preview/preview/previewAdjustStrategyPosition.d.ts +20 -0
- package/dist/types/onchain/preview/preview/previewExitOrRepayStrategyPosition.d.ts +21 -0
- package/dist/types/onchain/preview/preview/previewOpenStrategyPosition.d.ts +14 -0
- package/dist/types/onchain/preview/preview/previewOperation.d.ts +32 -0
- package/dist/types/onchain/preview/preview/previewPoolPositionOperation.d.ts +13 -0
- package/dist/types/{preview → onchain/preview}/preview/replayInnerOperations.d.ts +11 -11
- package/dist/types/{preview → onchain/preview}/preview/replayMulticall.d.ts +10 -10
- package/dist/types/{preview → onchain/preview}/preview/unwrapNativeCollateral.d.ts +10 -20
- package/dist/types/onchain/validation/bundles/checkAccountQuotas.d.ts +16 -0
- package/dist/types/onchain/validation/bundles/checkCollateralFunding.d.ts +22 -0
- package/dist/types/onchain/validation/bundles/checkCreditOperation.d.ts +31 -0
- package/dist/types/onchain/validation/bundles/checkDraw.d.ts +20 -0
- package/dist/types/onchain/validation/bundles/checkHealthFactors.d.ts +39 -0
- package/dist/types/onchain/validation/bundles/checkLiquidationEligibility.d.ts +20 -0
- package/dist/types/onchain/validation/bundles/checkLiquidationFunding.d.ts +18 -0
- package/dist/types/onchain/validation/bundles/checkMarket.d.ts +15 -0
- package/dist/types/onchain/validation/bundles/checkObtained.d.ts +9 -0
- package/dist/types/onchain/validation/bundles/checkPoolFunding.d.ts +19 -0
- package/dist/types/onchain/validation/bundles/checkPoolOperation.d.ts +31 -0
- package/dist/types/onchain/validation/bundles/checkQuotasAsked.d.ts +10 -0
- package/dist/types/onchain/validation/bundles/checkRWAOpenRequirements.d.ts +21 -0
- package/dist/types/onchain/validation/bundles/checkRWAOpening.d.ts +19 -0
- package/dist/types/onchain/validation/bundles/checkWallet.d.ts +23 -0
- package/dist/types/onchain/validation/bundles/checkWalletAllowance.d.ts +18 -0
- package/dist/types/onchain/validation/bundles/checkWalletBalance.d.ts +17 -0
- package/dist/types/onchain/validation/bundles/index.d.ts +18 -0
- package/dist/types/onchain/validation/checkLiquidation.d.ts +23 -0
- package/dist/types/onchain/validation/checkOperation.d.ts +32 -0
- package/dist/types/onchain/validation/checkSimulation.d.ts +56 -0
- package/dist/types/onchain/validation/checks/checkBorrowLimit.d.ts +21 -0
- package/dist/types/onchain/validation/checks/checkCollateralised.d.ts +25 -0
- package/dist/types/onchain/validation/checks/checkCreditAccountFrozen.d.ts +12 -0
- package/dist/types/onchain/validation/checks/checkCreditManagerPaused.d.ts +12 -0
- package/dist/types/onchain/validation/checks/checkDebtLimits.d.ts +21 -0
- package/dist/types/onchain/validation/checks/checkEmergencyLiquidator.d.ts +17 -0
- package/dist/types/onchain/validation/checks/checkForbiddenToken.d.ts +12 -0
- package/dist/types/onchain/validation/checks/checkLeverage.d.ts +12 -0
- package/dist/types/onchain/validation/checks/checkLiquidatorEligible.d.ts +13 -0
- package/dist/types/onchain/validation/checks/checkMarketExpired.d.ts +14 -0
- package/dist/types/onchain/validation/checks/checkPoolLiquidity.d.ts +20 -0
- package/dist/types/onchain/validation/checks/checkPoolPaused.d.ts +12 -0
- package/dist/types/onchain/validation/checks/checkPoolSunset.d.ts +13 -0
- package/dist/types/onchain/validation/checks/checkQuotaCount.d.ts +11 -0
- package/dist/types/onchain/validation/checks/checkQuotaLimit.d.ts +18 -0
- package/dist/types/onchain/validation/checks/index.d.ts +16 -0
- package/dist/types/onchain/validation/helpers/amount.d.ts +7 -0
- package/dist/types/onchain/validation/helpers/health-factor-limits.d.ts +21 -0
- package/dist/types/onchain/validation/helpers/index.d.ts +4 -0
- package/dist/types/onchain/validation/{token.d.ts → helpers/token.d.ts} +4 -4
- package/dist/types/onchain/validation/index.d.ts +43 -4
- package/dist/types/onchain/validation/raise.d.ts +33 -0
- package/dist/types/sdk/execute/types.d.ts +2 -2
- package/dist/types/sdk/index.d.ts +5 -6
- package/dist/types/sdk/liquidations/LiquidationsNamespace.d.ts +5 -0
- package/dist/types/sdk/liquidations/types.d.ts +8 -0
- package/dist/types/sdk/prepare/PrepareApi.d.ts +6 -5
- package/dist/types/sdk/prepare/index.d.ts +5 -5
- package/dist/types/sdk/prepare/types.d.ts +65 -23
- package/dist/types/sdk/preview/PreviewNamespace.d.ts +13 -3
- package/dist/types/sdk/preview/index.d.ts +2 -2
- package/dist/types/sdk/preview/types.d.ts +30 -7
- package/package.json +1 -6
- package/dist/cjs/onchain/accounts/withdrawal-compressor/errors.js +0 -1
- package/dist/cjs/onchain/market/zapper/errors.js +0 -1
- package/dist/cjs/onchain/validation/checks.js +0 -258
- package/dist/cjs/onchain/validation/refusal.js +0 -39
- package/dist/cjs/preview/index.js +0 -86
- package/dist/cjs/preview/package.json +0 -1
- package/dist/cjs/preview/parse/errors.js +0 -1
- package/dist/cjs/preview/parse/index.js +0 -15
- package/dist/cjs/preview/prerequisites/AllowancePrerequisite.js +0 -38
- package/dist/cjs/preview/prerequisites/BalancePrerequisite.js +0 -52
- package/dist/cjs/preview/prerequisites/Prerequisite.js +0 -52
- package/dist/cjs/preview/prerequisites/RWAOpenRequirementsPrerequisite.js +0 -53
- package/dist/cjs/preview/prerequisites/buildCollateralPrerequisites.js +0 -63
- package/dist/cjs/preview/prerequisites/buildPartialLiquidationPrerequisites.js +0 -19
- package/dist/cjs/preview/prerequisites/buildPoolPrerequisites.js +0 -76
- package/dist/cjs/preview/prerequisites/buildRWAPrerequisites.js +0 -39
- package/dist/cjs/preview/prerequisites/checkPrerequisites.js +0 -74
- package/dist/cjs/preview/prerequisites/helpers.js +0 -23
- package/dist/cjs/preview/prerequisites/index.js +0 -12
- package/dist/cjs/preview/preview/errors.js +0 -85
- package/dist/cjs/preview/preview/index.js +0 -33
- package/dist/cjs/preview/preview/previewOpenStrategyPosition.js +0 -50
- package/dist/cjs/preview/preview/previewOperation.js +0 -100
- package/dist/cjs/preview/preview/previewPoolPositionOperation.js +0 -49
- package/dist/cjs/preview/preview/replayInnerOperations.js +0 -109
- package/dist/cjs/preview/preview/replayMulticall.js +0 -19
- package/dist/cjs/preview/simulate/errors.js +0 -73
- package/dist/cjs/preview/simulate/index.js +0 -11
- package/dist/cjs/preview/simulate/simulateFacadeOperation.js +0 -15
- package/dist/cjs/preview/simulate/simulateOperation.js +0 -29
- package/dist/cjs/preview/simulate/simulateRWAOperation.js +0 -15
- package/dist/cjs/preview/simulate/types.js +0 -1
- package/dist/cjs/preview/trace/index.js +0 -14
- package/dist/cjs/preview/trace/types.js +0 -1
- package/dist/cjs/preview/types.js +0 -1
- package/dist/cjs/preview/validate/checkOperation.js +0 -187
- package/dist/cjs/preview/validate/checkSimulation.js +0 -39
- package/dist/cjs/preview/validate/index.js +0 -8
- package/dist/cjs/sdk/prepare/errors.js +0 -93
- package/dist/esm/onchain/accounts/withdrawal-compressor/errors.js +0 -1
- package/dist/esm/onchain/market/zapper/errors.js +0 -1
- package/dist/esm/onchain/validation/checks.js +0 -238
- package/dist/esm/onchain/validation/refusal.js +0 -36
- package/dist/esm/preview/index.js +0 -38
- package/dist/esm/preview/package.json +0 -1
- package/dist/esm/preview/parse/errors.js +0 -1
- package/dist/esm/preview/prerequisites/AllowancePrerequisite.js +0 -37
- package/dist/esm/preview/prerequisites/BalancePrerequisite.js +0 -51
- package/dist/esm/preview/prerequisites/Prerequisite.js +0 -51
- package/dist/esm/preview/prerequisites/RWAOpenRequirementsPrerequisite.js +0 -52
- package/dist/esm/preview/prerequisites/buildCollateralPrerequisites.js +0 -62
- package/dist/esm/preview/prerequisites/buildPartialLiquidationPrerequisites.js +0 -18
- package/dist/esm/preview/prerequisites/buildPoolPrerequisites.js +0 -75
- package/dist/esm/preview/prerequisites/buildRWAPrerequisites.js +0 -38
- package/dist/esm/preview/prerequisites/checkPrerequisites.js +0 -73
- package/dist/esm/preview/prerequisites/helpers.js +0 -22
- package/dist/esm/preview/prerequisites/index.js +0 -7
- package/dist/esm/preview/preview/errors.js +0 -79
- package/dist/esm/preview/preview/previewPoolPositionOperation.js +0 -48
- package/dist/esm/preview/preview/replayInnerOperations.js +0 -107
- package/dist/esm/preview/preview/replayMulticall.js +0 -18
- package/dist/esm/preview/simulate/errors.js +0 -71
- package/dist/esm/preview/simulate/index.js +0 -6
- package/dist/esm/preview/simulate/simulateFacadeOperation.js +0 -14
- package/dist/esm/preview/simulate/simulateOperation.js +0 -28
- package/dist/esm/preview/simulate/simulateRWAOperation.js +0 -14
- package/dist/esm/preview/simulate/types.js +0 -1
- package/dist/esm/preview/trace/types.js +0 -1
- package/dist/esm/preview/types.js +0 -1
- package/dist/esm/preview/validate/checkOperation.js +0 -183
- package/dist/esm/preview/validate/checkSimulation.js +0 -38
- package/dist/esm/preview/validate/index.js +0 -3
- package/dist/esm/sdk/prepare/errors.js +0 -89
- package/dist/types/model/errors.d.ts +0 -46
- package/dist/types/onchain/accounts/withdrawal-compressor/errors.d.ts +0 -20
- package/dist/types/onchain/market/zapper/errors.d.ts +0 -18
- package/dist/types/onchain/validation/checks.d.ts +0 -164
- package/dist/types/onchain/validation/refusal.d.ts +0 -242
- package/dist/types/preview/index.d.ts +0 -47
- package/dist/types/preview/parse/errors.d.ts +0 -29
- package/dist/types/preview/parse/parseOperationCalldata.d.ts +0 -18
- package/dist/types/preview/prerequisites/AllowancePrerequisite.d.ts +0 -26
- package/dist/types/preview/prerequisites/BalancePrerequisite.d.ts +0 -29
- package/dist/types/preview/prerequisites/Prerequisite.d.ts +0 -26
- package/dist/types/preview/prerequisites/RWAOpenRequirementsPrerequisite.d.ts +0 -55
- package/dist/types/preview/prerequisites/buildCollateralPrerequisites.d.ts +0 -20
- package/dist/types/preview/prerequisites/buildPartialLiquidationPrerequisites.d.ts +0 -12
- package/dist/types/preview/prerequisites/buildPoolPrerequisites.d.ts +0 -12
- package/dist/types/preview/prerequisites/buildRWAPrerequisites.d.ts +0 -26
- package/dist/types/preview/prerequisites/checkPrerequisites.d.ts +0 -28
- package/dist/types/preview/prerequisites/helpers.d.ts +0 -10
- package/dist/types/preview/prerequisites/index.d.ts +0 -7
- package/dist/types/preview/prerequisites/types.d.ts +0 -53
- package/dist/types/preview/preview/errors.d.ts +0 -44
- package/dist/types/preview/preview/previewAdjustStrategyPosition.d.ts +0 -19
- package/dist/types/preview/preview/previewExitOrRepayStrategyPosition.d.ts +0 -18
- package/dist/types/preview/preview/previewOpenStrategyPosition.d.ts +0 -12
- package/dist/types/preview/preview/previewOperation.d.ts +0 -32
- package/dist/types/preview/preview/previewPoolPositionOperation.d.ts +0 -13
- package/dist/types/preview/simulate/errors.d.ts +0 -52
- package/dist/types/preview/simulate/index.d.ts +0 -7
- package/dist/types/preview/simulate/simulateFacadeOperation.d.ts +0 -16
- package/dist/types/preview/simulate/simulateOperation.d.ts +0 -12
- package/dist/types/preview/simulate/simulatePoolOperation.d.ts +0 -42
- package/dist/types/preview/simulate/simulateRWAOperation.d.ts +0 -16
- package/dist/types/preview/simulate/types.d.ts +0 -48
- package/dist/types/preview/types.d.ts +0 -65
- package/dist/types/preview/validate/checkOperation.d.ts +0 -71
- package/dist/types/preview/validate/checkSimulation.d.ts +0 -32
- package/dist/types/preview/validate/index.d.ts +0 -3
- package/dist/types/sdk/prepare/errors.d.ts +0 -319
- /package/dist/cjs/{preview/prerequisites → history/trace}/types.js +0 -0
- /package/dist/cjs/model/{errors.js → errors/base.js} +0 -0
- /package/dist/cjs/{preview → onchain/preview}/parse/types-adapters.js +0 -0
- /package/dist/cjs/{preview → onchain/preview}/parse/types-facades.js +0 -0
- /package/dist/cjs/{preview → onchain/preview}/parse/types-pools.js +0 -0
- /package/dist/cjs/{preview → onchain/preview}/parse/types-rwa.js +0 -0
- /package/dist/esm/{preview → history}/trace/index.js +0 -0
- /package/dist/esm/{preview/prerequisites → history/trace}/types.js +0 -0
- /package/dist/esm/model/{errors.js → errors/base.js} +0 -0
- /package/dist/esm/{preview → onchain/preview}/parse/types-adapters.js +0 -0
- /package/dist/esm/{preview → onchain/preview}/parse/types-facades.js +0 -0
- /package/dist/esm/{preview → onchain/preview}/parse/types-pools.js +0 -0
- /package/dist/esm/{preview → onchain/preview}/parse/types-rwa.js +0 -0
- /package/dist/types/{preview → history}/trace/index.d.ts +0 -0
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_onchain_utils_AssetsMap = require("../../onchain/utils/AssetsMap.js");
|
|
3
|
-
require("../../onchain/constants/math.js");
|
|
4
|
-
const require_onchain_market_adapters_contracts_AbstractAdapter = require("../../onchain/market/adapters/contracts/AbstractAdapter.js");
|
|
5
|
-
require("../../onchain/index.js");
|
|
6
|
-
const require_preview_preview_errors = require("./errors.js");
|
|
7
|
-
//#region src/preview/preview/replayInnerOperations.ts
|
|
8
|
-
/**
|
|
9
|
-
* Creates a {@link ReplayState} around the given account seed, with empty
|
|
10
|
-
* bookkeeping.
|
|
11
|
-
*/
|
|
12
|
-
function makeReplayState(account) {
|
|
13
|
-
return {
|
|
14
|
-
account,
|
|
15
|
-
collateralAdded: new require_onchain_utils_AssetsMap.AssetsMap(),
|
|
16
|
-
collateralWithdrawn: new require_onchain_utils_AssetsMap.AssetsMap()
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Replays a credit-facade multicall over `state`, mutating it in place in
|
|
21
|
-
* facade execution order. The result is the *minimal guaranteed* post-state.
|
|
22
|
-
*
|
|
23
|
-
* The function assumes that the call was generated by our frontend using
|
|
24
|
-
* router/withdrawal compressor, otherwise it returns a warning, but still
|
|
25
|
-
* proceeds best-effort.
|
|
26
|
-
*
|
|
27
|
-
* @returns `undefined` on success, the warning on a malformed multicall.
|
|
28
|
-
*/
|
|
29
|
-
function replayInnerOperations(sdk, multicall, state) {
|
|
30
|
-
let inBracket = false;
|
|
31
|
-
let warning;
|
|
32
|
-
for (const op of multicall) {
|
|
33
|
-
let opWarning;
|
|
34
|
-
switch (op.operation) {
|
|
35
|
-
case "AddCollateral":
|
|
36
|
-
applyAddCollateral(state, op);
|
|
37
|
-
break;
|
|
38
|
-
case "WithdrawCollateral":
|
|
39
|
-
applyWithdrawCollateral(state, op);
|
|
40
|
-
break;
|
|
41
|
-
case "IncreaseBorrowedAmount":
|
|
42
|
-
state.account.increaseDebt(op.amount);
|
|
43
|
-
break;
|
|
44
|
-
case "DecreaseBorrowedAmount":
|
|
45
|
-
state.account.repay(op.amount);
|
|
46
|
-
break;
|
|
47
|
-
case "UpdateQuota":
|
|
48
|
-
state.account.updateQuota(op.token, op.change);
|
|
49
|
-
break;
|
|
50
|
-
case "StoreExpectedBalances":
|
|
51
|
-
if (inBracket) opWarning = require_preview_preview_errors.malformedBracketError("nested");
|
|
52
|
-
inBracket = true;
|
|
53
|
-
for (const { token, balance } of op.deltas) state.account.balances.inc(token, balance);
|
|
54
|
-
break;
|
|
55
|
-
case "CompareBalances":
|
|
56
|
-
if (!inBracket) opWarning = require_preview_preview_errors.malformedBracketError("unmatchedCompare");
|
|
57
|
-
inBracket = false;
|
|
58
|
-
break;
|
|
59
|
-
case "Execute": opWarning = applyExecute(sdk, op, inBracket, state.account.balances);
|
|
60
|
-
}
|
|
61
|
-
warning ??= opWarning;
|
|
62
|
-
}
|
|
63
|
-
if (inBracket) warning ??= require_preview_preview_errors.malformedBracketError("unmatchedStore");
|
|
64
|
-
return warning;
|
|
65
|
-
}
|
|
66
|
-
function applyAddCollateral(state, op) {
|
|
67
|
-
state.collateralAdded.inc(op.token, op.amount);
|
|
68
|
-
state.account.balances.inc(op.token, op.amount);
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* `MAX_UINT256` is the facade sentinel for "withdraw the entire balance", so
|
|
72
|
-
* it is resolved against the running balance at the point of the call.
|
|
73
|
-
*/
|
|
74
|
-
function applyWithdrawCollateral(state, op) {
|
|
75
|
-
const running = state.account.balances.getOrZero(op.token);
|
|
76
|
-
const amount = op.amount === 115792089237316195423570985008687907853269984665640564039457584007913129639935n ? running > 0n ? running : 0n : op.amount;
|
|
77
|
-
state.account.balances.dec(op.token, amount);
|
|
78
|
-
state.collateralWithdrawn.inc(op.token, amount);
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Replays an adapter `Execute` call against the running balances.
|
|
82
|
-
*
|
|
83
|
-
* Inside a bracket, the adapter's balance changes are previewed via
|
|
84
|
-
* {@link AbstractAdapterContract.previewBalanceChanges}. Outside a bracket,
|
|
85
|
-
* only calls that {@link AbstractAdapterContract.replayOutOfBracketCall}
|
|
86
|
-
* accepts are allowed; nothing enforces the outcome of any other out-of-bracket
|
|
87
|
-
* adapter call on-chain, so its effect on balances cannot be previewed.
|
|
88
|
-
*/
|
|
89
|
-
function applyExecute(sdk, op, inBracket, balances) {
|
|
90
|
-
const adapter = sdk.getContract(op.adapter);
|
|
91
|
-
if (!inBracket) {
|
|
92
|
-
if (adapter instanceof require_onchain_market_adapters_contracts_AbstractAdapter.AbstractAdapterContract) try {
|
|
93
|
-
if (adapter.replayOutOfBracketCall(balances, op.calldata)) return;
|
|
94
|
-
} catch (e) {
|
|
95
|
-
return require_preview_preview_errors.unsupportedOutOfBracketCallError(op.adapter, e);
|
|
96
|
-
}
|
|
97
|
-
return require_preview_preview_errors.adapterCallOutsideBracketError(op.adapter);
|
|
98
|
-
}
|
|
99
|
-
if (!(adapter instanceof require_onchain_market_adapters_contracts_AbstractAdapter.AbstractAdapterContract)) return require_preview_preview_errors.nonAdapterCallInBracketError(op.adapter);
|
|
100
|
-
try {
|
|
101
|
-
adapter.previewBalanceChanges(balances, op.calldata);
|
|
102
|
-
return;
|
|
103
|
-
} catch (e) {
|
|
104
|
-
return require_preview_preview_errors.unpreviewableAdapterCallError(op.adapter, e);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
//#endregion
|
|
108
|
-
exports.makeReplayState = makeReplayState;
|
|
109
|
-
exports.replayInnerOperations = replayInnerOperations;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_preview_preview_CreditAccountState = require("./CreditAccountState.js");
|
|
3
|
-
const require_preview_preview_replayInnerOperations = require("./replayInnerOperations.js");
|
|
4
|
-
//#region src/preview/preview/replayMulticall.ts
|
|
5
|
-
/**
|
|
6
|
-
* Replays the operation's multicall over the account's pre-resolved
|
|
7
|
-
* pre-state (`options.creditAccount`) via {@link replayInnerOperations}.
|
|
8
|
-
*/
|
|
9
|
-
function replayMulticall(sdk, operation, options) {
|
|
10
|
-
const before = require_preview_preview_CreditAccountState.CreditAccountState.fromCreditAccountData(options.creditAccount);
|
|
11
|
-
const after = require_preview_preview_replayInnerOperations.makeReplayState(before.clone());
|
|
12
|
-
return {
|
|
13
|
-
before,
|
|
14
|
-
after,
|
|
15
|
-
warning: require_preview_preview_replayInnerOperations.replayInnerOperations(sdk, operation.multicall, after)
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
//#endregion
|
|
19
|
-
exports.replayMulticall = replayMulticall;
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_abi_errors = require("../../abi/errors.js");
|
|
3
|
-
let viem = require("viem");
|
|
4
|
-
//#region src/preview/simulate/errors.ts
|
|
5
|
-
function isPreviewSimulationError(value) {
|
|
6
|
-
return typeof value === "object" && value !== null && !(value instanceof Error) && value.code === "previewSimulationFailed";
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Normalises an unknown rejection reason into a {@link PreviewSimulationError}.
|
|
10
|
-
* Pass-through when it already is one; otherwise decodes it under `source`.
|
|
11
|
-
*/
|
|
12
|
-
function asPreviewSimulationError(reason, source) {
|
|
13
|
-
if (isPreviewSimulationError(reason)) return reason;
|
|
14
|
-
const error = reason instanceof Error ? reason : new Error(String(reason));
|
|
15
|
-
const detail = decodeSimulationError({ error });
|
|
16
|
-
return {
|
|
17
|
-
code: "previewSimulationFailed",
|
|
18
|
-
message: detail.reason,
|
|
19
|
-
failures: [{
|
|
20
|
-
source,
|
|
21
|
-
detail
|
|
22
|
-
}],
|
|
23
|
-
cause: error
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Decodes a simulated call revert into a {@link SimulationError}.
|
|
28
|
-
*
|
|
29
|
-
* We first try to decode any raw return bytes against the SDK's
|
|
30
|
-
* {@link errorAbis} (Gearbox protocol exceptions plus standard ERC-20 custom
|
|
31
|
-
* errors); failing that, we walk viem's error chain for a
|
|
32
|
-
* {@link ContractFunctionRevertedError} (covers `Error(string)` / `Panic`).
|
|
33
|
-
*/
|
|
34
|
-
function decodeSimulationError(revert) {
|
|
35
|
-
const { error, data } = revert;
|
|
36
|
-
if (data && data !== "0x") try {
|
|
37
|
-
const decoded = (0, viem.decodeErrorResult)({
|
|
38
|
-
abi: require_abi_errors.errorAbis,
|
|
39
|
-
data
|
|
40
|
-
});
|
|
41
|
-
return {
|
|
42
|
-
reason: formatDecodedError(decoded.errorName, decoded.args),
|
|
43
|
-
cause: error
|
|
44
|
-
};
|
|
45
|
-
} catch {}
|
|
46
|
-
if (error instanceof viem.BaseError) {
|
|
47
|
-
const reverted = error.walk((e) => e instanceof viem.ContractFunctionRevertedError);
|
|
48
|
-
if (reverted instanceof viem.ContractFunctionRevertedError) return {
|
|
49
|
-
reason: reverted.data?.errorName ?? reverted.reason ?? reverted.shortMessage ?? "reverted",
|
|
50
|
-
cause: error
|
|
51
|
-
};
|
|
52
|
-
return {
|
|
53
|
-
reason: error.shortMessage ?? error.name,
|
|
54
|
-
cause: error
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
if (error instanceof Error) return {
|
|
58
|
-
reason: error.message,
|
|
59
|
-
cause: error
|
|
60
|
-
};
|
|
61
|
-
return {
|
|
62
|
-
reason: "reverted",
|
|
63
|
-
cause: error
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
/** Renders `Name` or `Name(arg0, arg1)` for a decoded custom error. */
|
|
67
|
-
function formatDecodedError(errorName, args) {
|
|
68
|
-
if (!args || args.length === 0) return errorName;
|
|
69
|
-
return `${errorName}(${args.map((arg) => String(arg)).join(", ")})`;
|
|
70
|
-
}
|
|
71
|
-
//#endregion
|
|
72
|
-
exports.asPreviewSimulationError = asPreviewSimulationError;
|
|
73
|
-
exports.decodeSimulationError = decodeSimulationError;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_preview_simulate_errors = require("./errors.js");
|
|
3
|
-
const require_preview_simulate_simulatePoolOperation = require("./simulatePoolOperation.js");
|
|
4
|
-
const require_preview_simulate_simulateFacadeOperation = require("./simulateFacadeOperation.js");
|
|
5
|
-
const require_preview_simulate_simulateRWAOperation = require("./simulateRWAOperation.js");
|
|
6
|
-
const require_preview_simulate_simulateOperation = require("./simulateOperation.js");
|
|
7
|
-
exports.asPreviewSimulationError = require_preview_simulate_errors.asPreviewSimulationError;
|
|
8
|
-
exports.simulateFacadeOperation = require_preview_simulate_simulateFacadeOperation.simulateFacadeOperation;
|
|
9
|
-
exports.simulateOperation = require_preview_simulate_simulateOperation.simulateOperation;
|
|
10
|
-
exports.simulatePoolOperation = require_preview_simulate_simulatePoolOperation.simulatePoolOperation;
|
|
11
|
-
exports.simulateRWAOperation = require_preview_simulate_simulateRWAOperation.simulateRWAOperation;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
//#region src/preview/simulate/simulateFacadeOperation.ts
|
|
3
|
-
/**
|
|
4
|
-
* Simulates a credit-facade operation.
|
|
5
|
-
*
|
|
6
|
-
* Not yet implemented: credit-facade simulation requires multicall-aware
|
|
7
|
-
* balance/transfer accounting that the pool simulation does not cover. The
|
|
8
|
-
* signature mirrors {@link simulatePoolOperation} so the
|
|
9
|
-
* {@link simulateOperation} wrapper can delegate uniformly once implemented.
|
|
10
|
-
*/
|
|
11
|
-
async function simulateFacadeOperation(_input, _options) {
|
|
12
|
-
throw new Error("not yet implemented");
|
|
13
|
-
}
|
|
14
|
-
//#endregion
|
|
15
|
-
exports.simulateFacadeOperation = simulateFacadeOperation;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_model_result = require("../../model/result.js");
|
|
3
|
-
require("../../model/index.js");
|
|
4
|
-
const require_preview_parse_types = require("../parse/types.js");
|
|
5
|
-
require("../parse/index.js");
|
|
6
|
-
const require_preview_simulate_simulatePoolOperation = require("./simulatePoolOperation.js");
|
|
7
|
-
const require_preview_simulate_simulateFacadeOperation = require("./simulateFacadeOperation.js");
|
|
8
|
-
const require_preview_simulate_simulateRWAOperation = require("./simulateRWAOperation.js");
|
|
9
|
-
//#region src/preview/simulate/simulateOperation.ts
|
|
10
|
-
/**
|
|
11
|
-
* Simulates a parsed pool or credit account operation
|
|
12
|
-
*/
|
|
13
|
-
async function simulateOperation(input, options) {
|
|
14
|
-
const { operation } = input;
|
|
15
|
-
if (require_preview_parse_types.isPoolOperation(operation)) return require_preview_simulate_simulatePoolOperation.simulatePoolOperation({
|
|
16
|
-
...input,
|
|
17
|
-
operation
|
|
18
|
-
}, options);
|
|
19
|
-
if (require_preview_parse_types.isRWAOperation(operation)) return require_model_result.sdkOk(await require_preview_simulate_simulateRWAOperation.simulateRWAOperation({
|
|
20
|
-
...input,
|
|
21
|
-
operation
|
|
22
|
-
}, options));
|
|
23
|
-
return require_model_result.sdkOk(await require_preview_simulate_simulateFacadeOperation.simulateFacadeOperation({
|
|
24
|
-
...input,
|
|
25
|
-
operation
|
|
26
|
-
}, options));
|
|
27
|
-
}
|
|
28
|
-
//#endregion
|
|
29
|
-
exports.simulateOperation = simulateOperation;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
//#region src/preview/simulate/simulateRWAOperation.ts
|
|
3
|
-
/**
|
|
4
|
-
* Simulates an RWA-factory operation.
|
|
5
|
-
*
|
|
6
|
-
* Not yet implemented: like credit-facade simulation, it requires
|
|
7
|
-
* multicall-aware balance/transfer accounting that the pool simulation does
|
|
8
|
-
* not cover. The signature mirrors {@link simulatePoolOperation} so the
|
|
9
|
-
* {@link simulateOperation} wrapper can delegate uniformly once implemented.
|
|
10
|
-
*/
|
|
11
|
-
async function simulateRWAOperation(_input, _options) {
|
|
12
|
-
throw new Error("not yet implemented");
|
|
13
|
-
}
|
|
14
|
-
//#endregion
|
|
15
|
-
exports.simulateRWAOperation = simulateRWAOperation;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_preview_trace_errors = require("./errors.js");
|
|
3
|
-
const require_preview_trace_extractAdapterCallTraces = require("./extractAdapterCallTraces.js");
|
|
4
|
-
const require_preview_trace_extractTransfers = require("./extractTransfers.js");
|
|
5
|
-
const require_preview_trace_findFacadeCalls = require("./findFacadeCalls.js");
|
|
6
|
-
require("./types.js");
|
|
7
|
-
exports.TransferAlignmentError = require_preview_trace_errors.TransferAlignmentError;
|
|
8
|
-
exports.UnexpectedFacadeEventOrderError = require_preview_trace_errors.UnexpectedFacadeEventOrderError;
|
|
9
|
-
exports.UnknownAdapterError = require_preview_trace_errors.UnknownAdapterError;
|
|
10
|
-
exports.UnknownFacadeCallError = require_preview_trace_errors.UnknownFacadeCallError;
|
|
11
|
-
exports.WithdrawCollateralAlignmentError = require_preview_trace_errors.WithdrawCollateralAlignmentError;
|
|
12
|
-
exports.extractAdapterCallTraces = require_preview_trace_extractAdapterCallTraces.extractAdapterCallTraces;
|
|
13
|
-
exports.extractTransfers = require_preview_trace_extractTransfers.extractTransfers;
|
|
14
|
-
exports.findFacadeCalls = require_preview_trace_findFacadeCalls.findFacadeCalls;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_onchain_validation_checks = require("../../onchain/validation/checks.js");
|
|
3
|
-
const require_onchain_validation_token = require("../../onchain/validation/token.js");
|
|
4
|
-
const require_onchain_accounts_intents_guards = require("../../onchain/accounts/intents/guards.js");
|
|
5
|
-
require("../../onchain/index.js");
|
|
6
|
-
let viem = require("viem");
|
|
7
|
-
//#region src/preview/validate/checkOperation.ts
|
|
8
|
-
/**
|
|
9
|
-
* Whether a parsed operation may be signed at all — the protocol state that
|
|
10
|
-
* `checkPrerequisites` leaves out, since that one covers only what the sender
|
|
11
|
-
* can fix themselves.
|
|
12
|
-
*
|
|
13
|
-
* Synchronous: the preview carries the numbers and the market is attached.
|
|
14
|
-
* Reports the most fundamental issue it finds and stops there, which is the one
|
|
15
|
-
* a caller acts on.
|
|
16
|
-
*/
|
|
17
|
-
function checkOperation(input, options = {}) {
|
|
18
|
-
const { sdk, preview } = input;
|
|
19
|
-
const malformed = require_onchain_validation_checks.checkPreviewError("warning" in preview ? preview.warning : void 0);
|
|
20
|
-
if (malformed) return malformed;
|
|
21
|
-
switch (preview.operation) {
|
|
22
|
-
case "Deposit":
|
|
23
|
-
case "Mint": return poolIssues(sdk, preview, options, true);
|
|
24
|
-
case "Withdraw":
|
|
25
|
-
case "Redeem": return poolIssues(sdk, preview, options, false);
|
|
26
|
-
case "DelayedCreditAccountOperation": return checkOperation({
|
|
27
|
-
sdk,
|
|
28
|
-
preview: preview.instantPreview
|
|
29
|
-
}, options);
|
|
30
|
-
case "OpenCreditAccount":
|
|
31
|
-
case "RWAOpenCreditAccount":
|
|
32
|
-
case "AdjustCreditAccount": return creditIssues(sdk, preview, options);
|
|
33
|
-
case "CloseCreditAccount":
|
|
34
|
-
case "RepayCreditAccount": return marketIssues(sdk.marketRegister.findCreditManager(preview.creditManager));
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
function poolIssues(sdk, preview, options, isDeposit) {
|
|
38
|
-
const market = sdk.marketRegister.findByPool(preview.pool);
|
|
39
|
-
return require_onchain_validation_checks.checkPoolPaused({
|
|
40
|
-
isPaused: market.pool.pool.isPaused,
|
|
41
|
-
pool: preview.pool
|
|
42
|
-
}) || require_onchain_validation_checks.checkPoolSunset({
|
|
43
|
-
isSunset: market.sunset,
|
|
44
|
-
isDeposit,
|
|
45
|
-
pool: preview.pool
|
|
46
|
-
}) || (isDeposit ? null : require_onchain_validation_checks.checkPoolPayout({
|
|
47
|
-
requested: preview.tokenOut.value,
|
|
48
|
-
available: market.pool.pool.availableLiquidity,
|
|
49
|
-
underlying: preview.tokenOut.token
|
|
50
|
-
})) || fundingIssue(options, [preview.tokenIn]);
|
|
51
|
-
}
|
|
52
|
-
/** What the market itself refuses, whatever the operation does. */
|
|
53
|
-
function marketIssues(suite) {
|
|
54
|
-
const creditManager = suite.creditManager.address;
|
|
55
|
-
return require_onchain_validation_checks.checkCreditManagerPaused({
|
|
56
|
-
isPaused: suite.isPaused,
|
|
57
|
-
creditManager
|
|
58
|
-
}) || require_onchain_validation_checks.checkMarketExpired({
|
|
59
|
-
isExpired: suite.isExpired,
|
|
60
|
-
creditManager,
|
|
61
|
-
expirationDate: suite.creditFacade.expirationDate
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
function creditIssues(sdk, preview, options) {
|
|
65
|
-
const suite = sdk.marketRegister.findCreditManager(preview.creditManager);
|
|
66
|
-
const market = suite.market;
|
|
67
|
-
const underlying = require_onchain_validation_token.toToken(sdk, market.pool.underlying);
|
|
68
|
-
const isOpening = preview.operation === "OpenCreditAccount" || preview.operation === "RWAOpenCreditAccount";
|
|
69
|
-
return marketIssues(suite) || require_onchain_validation_checks.checkDebtInBand({
|
|
70
|
-
debt: preview.totalDebt.value,
|
|
71
|
-
minDebt: suite.creditFacade.minDebt,
|
|
72
|
-
maxDebt: suite.creditFacade.maxDebt,
|
|
73
|
-
underlying,
|
|
74
|
-
allowZero: !isOpening
|
|
75
|
-
}) || borrowIssue(suite, preview, underlying) || forbiddenIssue(suite, preview) || quotaCountIssue(suite, preview) || quotaIssue(market, preview, underlying) || collateralIssue({
|
|
76
|
-
totalDebt: preview.totalDebt,
|
|
77
|
-
healthFactor: preview.estHealthFactor,
|
|
78
|
-
safeHealthFactor: preview.estSafeHealthFactor
|
|
79
|
-
}, options) || fundingIssue(options, preview.collateralAdded);
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* A bar that reads nothing but the projected account, so a parsed transaction
|
|
83
|
-
* and a simulated one are held to it by the same code.
|
|
84
|
-
*
|
|
85
|
-
* These stay separate functions rather than one block because the order the
|
|
86
|
-
* checks run in is the answer: `checkOperation` interleaves the checks that
|
|
87
|
-
* need an operation's *delta* between them, and the caller acts on the first
|
|
88
|
-
* issue reported.
|
|
89
|
-
*/
|
|
90
|
-
function quotaCountIssue(suite, account) {
|
|
91
|
-
return require_onchain_validation_checks.checkQuotaCount({
|
|
92
|
-
count: account.quotas.filter((q) => q.value > 0n).length,
|
|
93
|
-
max: suite.creditManager.maxEnabledTokens
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* What the transaction draws, against what the market can lend right now.
|
|
98
|
-
*
|
|
99
|
-
* Only a draw is weighed: repaying, or leaving the debt alone, can never exceed
|
|
100
|
-
* a ceiling. Opening borrows the whole debt; adjusting borrows
|
|
101
|
-
* `totalDebtChange`.
|
|
102
|
-
*
|
|
103
|
-
* The engine holds every simulation to this already (`assertCanBorrow`), so
|
|
104
|
-
* this is here for the transactions it never saw — a pasted calldata reaches
|
|
105
|
-
* the confirm screen with nothing else standing between it and a revert.
|
|
106
|
-
*/
|
|
107
|
-
function borrowIssue(suite, preview, underlying) {
|
|
108
|
-
const drawn = preview.operation === "AdjustCreditAccount" ? preview.totalDebtChange.value : preview.totalDebt.value;
|
|
109
|
-
if (drawn <= 0n) return null;
|
|
110
|
-
const { limit, binding } = require_onchain_accounts_intents_guards.borrowable(suite);
|
|
111
|
-
return require_onchain_validation_checks.checkBorrowLimit({
|
|
112
|
-
requested: drawn,
|
|
113
|
-
available: limit,
|
|
114
|
-
binding,
|
|
115
|
-
underlying
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* The account against whichever bars the caller holds it to.
|
|
120
|
-
*
|
|
121
|
-
* A loan-free account is nothing to weigh: the health factor reports its
|
|
122
|
-
* zero-debt sentinel and no bar applies.
|
|
123
|
-
*
|
|
124
|
-
* {@inheritDoc quotaCountIssue}
|
|
125
|
-
*/
|
|
126
|
-
function collateralIssue(account, options) {
|
|
127
|
-
const { minHealthFactor, minSafeHealthFactor, currentHealthFactor } = options;
|
|
128
|
-
if (account.totalDebt.value === 0n) return null;
|
|
129
|
-
return (minHealthFactor === void 0 ? null : require_onchain_validation_checks.checkCollateralised({
|
|
130
|
-
healthFactor: account.healthFactor,
|
|
131
|
-
required: minHealthFactor,
|
|
132
|
-
safePrices: false,
|
|
133
|
-
improvesFrom: currentHealthFactor
|
|
134
|
-
})) || (minSafeHealthFactor === void 0 ? null : require_onchain_validation_checks.checkCollateralised({
|
|
135
|
-
healthFactor: account.safeHealthFactor,
|
|
136
|
-
required: minSafeHealthFactor,
|
|
137
|
-
safePrices: true
|
|
138
|
-
}));
|
|
139
|
-
}
|
|
140
|
-
/** The wallet's side of the operation, against the balances it was given. */
|
|
141
|
-
function fundingIssue(options, puts) {
|
|
142
|
-
const { balances } = options;
|
|
143
|
-
if (!balances) return null;
|
|
144
|
-
for (const { token, value } of puts) {
|
|
145
|
-
const issue = require_onchain_validation_checks.checkFunding({
|
|
146
|
-
token,
|
|
147
|
-
required: value,
|
|
148
|
-
held: balances.get(token.address) ?? 0n
|
|
149
|
-
});
|
|
150
|
-
if (issue) return issue;
|
|
151
|
-
}
|
|
152
|
-
return null;
|
|
153
|
-
}
|
|
154
|
-
function forbiddenIssue(suite, preview) {
|
|
155
|
-
const obtained = preview.operation === "AdjustCreditAccount" ? preview.assetsChange : preview.estAssets;
|
|
156
|
-
const forbidden = suite.forbiddenTokens;
|
|
157
|
-
for (const asset of obtained) {
|
|
158
|
-
if (asset.value <= 0n) continue;
|
|
159
|
-
const issue = require_onchain_validation_checks.checkForbiddenToken({
|
|
160
|
-
token: asset.token,
|
|
161
|
-
isForbidden: forbidden.some((f) => (0, viem.isAddressEqual)(f, asset.token.address))
|
|
162
|
-
});
|
|
163
|
-
if (issue) return issue;
|
|
164
|
-
}
|
|
165
|
-
return null;
|
|
166
|
-
}
|
|
167
|
-
function quotaIssue(market, preview, underlying) {
|
|
168
|
-
const increases = preview.operation === "AdjustCreditAccount" ? preview.quotasChange : preview.quotas;
|
|
169
|
-
const { pqk } = market.pool;
|
|
170
|
-
for (const q of increases) {
|
|
171
|
-
if (q.value <= 0n) continue;
|
|
172
|
-
const quota = pqk.hasActiveQuota(q.token.address) ? pqk.quotas.get(q.token.address) : void 0;
|
|
173
|
-
const issue = require_onchain_validation_checks.checkQuotaLimit({
|
|
174
|
-
token: q.token,
|
|
175
|
-
requested: quota ? q.value : void 0,
|
|
176
|
-
available: (quota?.limit ?? 0n) - (quota?.totalQuoted ?? 0n),
|
|
177
|
-
underlying
|
|
178
|
-
});
|
|
179
|
-
if (issue) return issue;
|
|
180
|
-
}
|
|
181
|
-
return null;
|
|
182
|
-
}
|
|
183
|
-
//#endregion
|
|
184
|
-
exports.checkOperation = checkOperation;
|
|
185
|
-
exports.collateralIssue = collateralIssue;
|
|
186
|
-
exports.marketIssues = marketIssues;
|
|
187
|
-
exports.quotaCountIssue = quotaCountIssue;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_onchain_validation_checks = require("../../onchain/validation/checks.js");
|
|
3
|
-
const require_onchain_validation_token = require("../../onchain/validation/token.js");
|
|
4
|
-
require("../../onchain/index.js");
|
|
5
|
-
const require_preview_validate_checkOperation = require("./checkOperation.js");
|
|
6
|
-
//#region src/preview/validate/checkSimulation.ts
|
|
7
|
-
/**
|
|
8
|
-
* Whether a simulated operation clears the caller's own bars.
|
|
9
|
-
*
|
|
10
|
-
* The engine holds an account to the facade's `1.0`, because its guards answer
|
|
11
|
-
* "would this revert". A form is wiser to ask for more, and the engine's own
|
|
12
|
-
* note says so — a caller wanting the stricter bar applies it itself. This is
|
|
13
|
-
* that second opinion, over the numbers the engine already reported.
|
|
14
|
-
*
|
|
15
|
-
* Three of the checks below the engine does not make at all: both health-factor
|
|
16
|
-
* bars are its own `1.0`, and the quota count it never weighs. The other two run
|
|
17
|
-
* against the same numbers the engine used, and are here so that a change in the
|
|
18
|
-
* engine cannot pass silently.
|
|
19
|
-
*
|
|
20
|
-
* What is deliberately absent: the forbidden-token, quota-limit and funding
|
|
21
|
-
* checks all need the *delta* an operation applies, and `OperationState` reports
|
|
22
|
-
* only the state after it. Weighing them against absolutes would refuse a
|
|
23
|
-
* forbidden token the account merely holds, or a quota the operation never
|
|
24
|
-
* touched. The engine performed all three during the walk, so a simulation that
|
|
25
|
-
* came back `ok` has already passed them.
|
|
26
|
-
*/
|
|
27
|
-
function checkSimulation(input, options = {}) {
|
|
28
|
-
const { sdk, state } = input;
|
|
29
|
-
const suite = sdk.marketRegister.findCreditManager(state.creditManager);
|
|
30
|
-
return require_preview_validate_checkOperation.marketIssues(suite) || require_onchain_validation_checks.checkDebtInBand({
|
|
31
|
-
debt: state.totalDebt.value,
|
|
32
|
-
minDebt: suite.creditFacade.minDebt,
|
|
33
|
-
maxDebt: suite.creditFacade.maxDebt,
|
|
34
|
-
underlying: require_onchain_validation_token.toToken(sdk, suite.market.pool.underlying),
|
|
35
|
-
allowZero: true
|
|
36
|
-
}) || require_preview_validate_checkOperation.quotaCountIssue(suite, state) || require_preview_validate_checkOperation.collateralIssue(state, options);
|
|
37
|
-
}
|
|
38
|
-
//#endregion
|
|
39
|
-
exports.checkSimulation = checkSimulation;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_preview_validate_checkOperation = require("./checkOperation.js");
|
|
3
|
-
const require_preview_validate_checkSimulation = require("./checkSimulation.js");
|
|
4
|
-
exports.checkOperation = require_preview_validate_checkOperation.checkOperation;
|
|
5
|
-
exports.checkSimulation = require_preview_validate_checkSimulation.checkSimulation;
|
|
6
|
-
exports.collateralIssue = require_preview_validate_checkOperation.collateralIssue;
|
|
7
|
-
exports.marketIssues = require_preview_validate_checkOperation.marketIssues;
|
|
8
|
-
exports.quotaCountIssue = require_preview_validate_checkOperation.quotaCountIssue;
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
//#region src/sdk/prepare/errors.ts
|
|
3
|
-
/**
|
|
4
|
-
* One sentence per refusal, naming what was ruled out rather than restating the
|
|
5
|
-
* numbers the error already carries.
|
|
6
|
-
*
|
|
7
|
-
* English and loggable, not a string to put on a screen: a form renders the
|
|
8
|
-
* code and the amounts in its own words, see {@link IGearboxError.message}.
|
|
9
|
-
**/
|
|
10
|
-
const MESSAGES = {
|
|
11
|
-
debtOutOfRange: "The debt this request implies is outside the market's band.",
|
|
12
|
-
leverageOutOfRange: "The leverage asked for cannot be expressed as a plan.",
|
|
13
|
-
insufficientSourceBalance: "Neither the account nor the wallet holds enough to fund this request.",
|
|
14
|
-
unsupportedCollateralToken: "This flow does not accept that token.",
|
|
15
|
-
unsupportedTokenPair: "No route exists between these two tokens.",
|
|
16
|
-
noDelayedRoute: "This request cannot be served as a delayed redemption.",
|
|
17
|
-
multipleDelayedWithdrawals: "The source asset has several redemption venues and none was named.",
|
|
18
|
-
withdrawalInProgress: "A redemption of this asset is already in flight on the account.",
|
|
19
|
-
noRecordedIntent: "The claim names no operation to resume.",
|
|
20
|
-
marketPaused: "The market is paused.",
|
|
21
|
-
marketExpired: "The market is past its expiration date.",
|
|
22
|
-
insufficientPoolLiquidity: "The pool cannot lend what this plan draws.",
|
|
23
|
-
quotaLimitReached: "The market takes no more quota for a token this plan holds.",
|
|
24
|
-
forbiddenToken: "This plan would increase the balance of a forbidden token.",
|
|
25
|
-
insufficientCollateral: "The account would end this transaction under-collateralised.",
|
|
26
|
-
poolSunset: "The pool is winding down and takes no more deposits.",
|
|
27
|
-
quotaCountExceeded: "The account would hold more quoted tokens than the facade enables at once.",
|
|
28
|
-
malformedTransaction: "The transaction could not be replayed."
|
|
29
|
-
};
|
|
30
|
-
/**
|
|
31
|
-
* The engine's refusal, as the error the namespace answers with.
|
|
32
|
-
*
|
|
33
|
-
* One place does the lifting, so the two shapes cannot drift: `reason` becomes
|
|
34
|
-
* `code`, the detail is spread onto the error, and the sentence comes from
|
|
35
|
-
* {@link MESSAGES}. A malformed transaction is spelled out rather than spread,
|
|
36
|
-
* because its detail names a `code` and a `message` of its own and they are not
|
|
37
|
-
* the envelope's.
|
|
38
|
-
*
|
|
39
|
-
* Generic over the issue it is handed, so a call site that already knows the
|
|
40
|
-
* reason gets that reason's error back rather than a union to narrow again.
|
|
41
|
-
**/
|
|
42
|
-
function toRefusalError(issue) {
|
|
43
|
-
if (issue.reason === "malformedTransaction") return {
|
|
44
|
-
code: "malformedTransaction",
|
|
45
|
-
message: MESSAGES.malformedTransaction,
|
|
46
|
-
previewCode: issue.detail.code,
|
|
47
|
-
detail: issue.detail.message
|
|
48
|
-
};
|
|
49
|
-
return {
|
|
50
|
-
code: issue.reason,
|
|
51
|
-
message: MESSAGES[issue.reason],
|
|
52
|
-
...issue.detail
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* {@inheritDoc NoStrategyTargetCollateralError}
|
|
57
|
-
**/
|
|
58
|
-
function noStrategyTargetCollateral(creditManager) {
|
|
59
|
-
return {
|
|
60
|
-
code: "noStrategyTargetCollateral",
|
|
61
|
-
message: `Credit manager ${creditManager} has no strategy target collateral, and none was named.`,
|
|
62
|
-
creditManager
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* {@inheritDoc CreditAccountNotFoundError}
|
|
67
|
-
**/
|
|
68
|
-
function creditAccountNotFound(creditAccount) {
|
|
69
|
-
return {
|
|
70
|
-
code: "creditAccountNotFound",
|
|
71
|
-
message: `Credit account not found: ${creditAccount}.`,
|
|
72
|
-
creditAccount
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* {@inheritDoc UnexpectedFailureError}
|
|
77
|
-
*
|
|
78
|
-
* Takes what was thrown, whatever that is: a `throw` is not obliged to raise an
|
|
79
|
-
* `Error`, and `cause` promises one.
|
|
80
|
-
**/
|
|
81
|
-
function unexpectedFailure(thrown) {
|
|
82
|
-
const cause = thrown instanceof Error ? thrown : new Error(String(thrown));
|
|
83
|
-
return {
|
|
84
|
-
code: "unexpectedFailure",
|
|
85
|
-
message: `The SDK could not prepare this operation: ${cause.message}`,
|
|
86
|
-
cause
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
//#endregion
|
|
90
|
-
exports.creditAccountNotFound = creditAccountNotFound;
|
|
91
|
-
exports.noStrategyTargetCollateral = noStrategyTargetCollateral;
|
|
92
|
-
exports.toRefusalError = toRefusalError;
|
|
93
|
-
exports.unexpectedFailure = unexpectedFailure;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|