@gearbox-protocol/sdk 16.2.0 → 16.3.0-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/abi/rwa/iMidasAccessControl.js +23 -0
- package/dist/cjs/abi/rwa/iMidasDegenNFT.js +92 -0
- package/dist/cjs/history/assembleOperations.js +3 -3
- package/dist/cjs/history/classifyMulticallOperations.js +7 -7
- package/dist/cjs/history/index.js +13 -0
- package/dist/cjs/history/parseCreditAccountTransaction.js +5 -5
- package/dist/cjs/{preview → history}/trace/errors.js +1 -1
- package/dist/cjs/{preview → history}/trace/extractAdapterCallTraces.js +1 -1
- package/dist/cjs/{preview → history}/trace/extractTransfers.js +3 -3
- package/dist/cjs/{preview → history}/trace/findFacadeCalls.js +3 -3
- package/dist/cjs/history/trace/index.js +14 -0
- package/dist/cjs/model/errors/index.js +37 -0
- package/dist/cjs/model/errors/liquidation-errors.js +32 -0
- package/dist/cjs/model/errors/operation-errors.js +135 -0
- package/dist/cjs/{onchain/market/oracle/errors.js → model/errors/oracle-errors.js} +1 -1
- package/dist/cjs/model/errors/prepare-errors.js +108 -0
- package/dist/cjs/model/errors/preview-errors.js +12 -0
- package/dist/cjs/model/index.js +45 -2
- package/dist/cjs/model/opportunities.schema.js +3 -1
- package/dist/cjs/model/positions.js +1 -1
- package/dist/cjs/model/result.js +0 -8
- package/dist/cjs/model/rwa.js +53 -0
- package/dist/cjs/model/rwa.schema.js +20 -0
- package/dist/cjs/offchain/opportunities/OffchainOpportunities.js +1 -1
- package/dist/cjs/onchain/accounts/index.js +0 -2
- package/dist/cjs/onchain/accounts/intents/guards.js +42 -66
- package/dist/cjs/onchain/accounts/intents/index.js +38 -35
- package/dist/cjs/onchain/accounts/intents/leverage-band.js +1 -1
- package/dist/cjs/onchain/accounts/intents/math.js +19 -15
- package/dist/cjs/onchain/accounts/intents/open-strategy.js +6 -4
- package/dist/cjs/onchain/accounts/intents/plan.js +52 -48
- package/dist/cjs/onchain/accounts/intents/realize.js +26 -24
- package/dist/cjs/onchain/accounts/intents/tail.js +15 -12
- package/dist/cjs/onchain/accounts/intents/testing/sdk-mock.js +7 -0
- package/dist/cjs/onchain/accounts/intents/tests/finish-withdraw.fixtures.js +6 -6
- package/dist/cjs/onchain/accounts/intents/tests/withdraw.fixtures.js +12 -12
- package/dist/cjs/onchain/accounts/intents/view.js +1 -1
- package/dist/cjs/onchain/accounts/liquidations/LiquidationsService.js +2 -2
- package/dist/cjs/onchain/accounts/withdrawal-compressor/index.js +0 -1
- package/dist/cjs/onchain/index.js +130 -38
- package/dist/cjs/onchain/market/MarketSuite.js +10 -4
- package/dist/cjs/onchain/market/adapters/index.js +1 -0
- package/dist/cjs/onchain/market/credit/CreditSuite.js +77 -15
- package/dist/cjs/onchain/market/index.js +8 -8
- package/dist/cjs/onchain/market/oracle/PriceOracleBaseContract.js +6 -6
- package/dist/cjs/onchain/market/oracle/index.js +0 -2
- package/dist/cjs/onchain/market/pool/PoolQuotaKeeperV310Contract.js +8 -0
- package/dist/cjs/onchain/market/rwa/RWARegistry.js +3 -2
- package/dist/cjs/onchain/market/rwa/createDegenNFT.js +53 -0
- package/dist/cjs/onchain/market/rwa/index.js +7 -5
- package/dist/cjs/onchain/market/rwa/midas/MidasDegenNFT.js +56 -0
- package/dist/cjs/onchain/market/rwa/midas/constants.js +2 -0
- package/dist/cjs/onchain/market/rwa/midas/index.js +3 -0
- package/dist/cjs/onchain/market/rwa/securitize/SecuritizeDegenNFT.js +22 -3
- package/dist/cjs/onchain/market/rwa/securitize/SecuritizeRWAFactory.js +9 -9
- package/dist/cjs/onchain/market/rwa/securitize/constants.js +2 -2
- package/dist/cjs/onchain/market/rwa/securitize/index.js +4 -3
- package/dist/cjs/onchain/market/rwa/securitize/types.js +0 -29
- package/dist/cjs/onchain/market/rwa/types.js +0 -7
- package/dist/cjs/onchain/market/zapper/index.js +0 -1
- package/dist/cjs/onchain/opportunities/MultichainOpportunitiesService.js +2 -2
- package/dist/cjs/onchain/opportunities/OpportunitiesService.js +11 -3
- package/dist/cjs/onchain/pools/PoolService.js +10 -16
- package/dist/cjs/onchain/preview/index.js +41 -0
- package/dist/cjs/{preview → onchain/preview}/parse/classifyInnerOperations.js +2 -3
- package/dist/cjs/onchain/preview/parse/index.js +14 -0
- package/dist/cjs/{preview → onchain/preview}/parse/parseFacadeOperationCalldata.js +3 -3
- package/dist/cjs/{preview → onchain/preview}/parse/parseOperationCalldata.js +16 -17
- package/dist/cjs/{preview → onchain/preview}/parse/parsePoolOperationCalldata.js +3 -3
- package/dist/cjs/{preview → onchain/preview}/parse/parseRWAFactoryOperationCalldata.js +11 -12
- package/dist/cjs/{preview → onchain/preview}/parse/types.js +1 -1
- package/dist/cjs/{preview → onchain/preview}/preview/CreditAccountState.js +3 -4
- package/dist/cjs/{preview → onchain/preview}/preview/buildDelayedStrategyPositionOperationPreview.js +10 -11
- package/dist/cjs/{preview → onchain/preview}/preview/detectCloseOrRepay.js +2 -3
- package/dist/cjs/{preview → onchain/preview}/preview/detectDelayedClaim.js +4 -5
- package/dist/cjs/{preview → onchain/preview}/preview/detectDelayedOperation.js +5 -6
- package/dist/cjs/{preview → onchain/preview}/preview/estimateClaimableAt.js +1 -1
- package/dist/cjs/onchain/preview/preview/index.js +26 -0
- package/dist/cjs/{preview → onchain/preview}/preview/previewAdjustStrategyPosition.js +18 -22
- package/dist/cjs/{preview → onchain/preview}/preview/previewExitOrRepayStrategyPosition.js +22 -28
- package/dist/cjs/onchain/preview/preview/previewOpenStrategyPosition.js +60 -0
- package/dist/cjs/onchain/preview/preview/previewOperation.js +119 -0
- package/dist/cjs/{preview/simulate/simulatePoolOperation.js → onchain/preview/preview/previewPoolPositionOperation.js} +46 -32
- package/dist/cjs/onchain/preview/preview/replayInnerOperations.js +109 -0
- package/dist/cjs/onchain/preview/preview/replayMulticall.js +22 -0
- package/dist/cjs/{preview → onchain/preview}/preview/unwrapNativeCollateral.js +11 -14
- package/dist/cjs/onchain/validation/bundles/checkAccountQuotas.js +20 -0
- package/dist/cjs/onchain/validation/bundles/checkCollateralFunding.js +59 -0
- package/dist/cjs/onchain/validation/bundles/checkCreditOperation.js +65 -0
- package/dist/cjs/onchain/validation/bundles/checkDraw.js +28 -0
- package/dist/cjs/onchain/validation/bundles/checkHealthFactors.js +27 -0
- package/dist/cjs/onchain/validation/bundles/checkLiquidationEligibility.js +33 -0
- package/dist/cjs/onchain/validation/bundles/checkLiquidationFunding.js +29 -0
- package/dist/cjs/onchain/validation/bundles/checkMarket.js +24 -0
- package/dist/cjs/onchain/validation/bundles/checkObtained.js +13 -0
- package/dist/cjs/onchain/validation/bundles/checkPoolFunding.js +22 -0
- package/dist/cjs/onchain/validation/bundles/checkPoolOperation.js +35 -0
- package/dist/cjs/onchain/validation/bundles/checkQuotasAsked.js +20 -0
- package/dist/cjs/onchain/validation/bundles/checkRWAOpenRequirements.js +33 -0
- package/dist/cjs/onchain/validation/bundles/checkRWAOpening.js +24 -0
- package/dist/cjs/onchain/validation/bundles/checkWallet.js +22 -0
- package/dist/cjs/onchain/validation/bundles/checkWalletAllowance.js +32 -0
- package/dist/cjs/onchain/validation/bundles/checkWalletBalance.js +41 -0
- package/dist/cjs/onchain/validation/bundles/index.js +35 -0
- package/dist/cjs/onchain/validation/checkLiquidation.js +22 -0
- package/dist/cjs/onchain/validation/checkOperation.js +62 -0
- package/dist/cjs/onchain/validation/checkSimulation.js +60 -0
- package/dist/cjs/onchain/validation/checks/checkBorrowLimit.js +25 -0
- package/dist/cjs/onchain/validation/checks/checkCollateralised.js +26 -0
- package/dist/cjs/onchain/validation/checks/checkCreditAccountFrozen.js +10 -0
- package/dist/cjs/onchain/validation/checks/checkCreditManagerPaused.js +10 -0
- package/dist/cjs/onchain/validation/checks/checkDebtLimits.js +18 -0
- package/dist/cjs/onchain/validation/checks/checkEmergencyLiquidator.js +13 -0
- package/dist/cjs/onchain/validation/checks/checkForbiddenToken.js +10 -0
- package/dist/cjs/onchain/validation/checks/checkLeverage.js +13 -0
- package/dist/cjs/onchain/validation/checks/checkLiquidatorEligible.js +10 -0
- package/dist/cjs/onchain/validation/checks/checkMarketExpired.js +10 -0
- package/dist/cjs/onchain/validation/checks/checkPoolLiquidity.js +25 -0
- package/dist/cjs/onchain/validation/checks/checkPoolPaused.js +10 -0
- package/dist/cjs/onchain/validation/checks/checkPoolSunset.js +10 -0
- package/dist/cjs/onchain/validation/checks/checkQuotaCount.js +10 -0
- package/dist/cjs/onchain/validation/checks/checkQuotaLimit.js +18 -0
- package/dist/cjs/onchain/validation/checks/index.js +31 -0
- package/dist/cjs/onchain/validation/helpers/amount.js +12 -0
- package/dist/cjs/onchain/validation/helpers/health-factor-limits.js +25 -0
- package/dist/cjs/onchain/validation/helpers/index.js +11 -0
- package/dist/cjs/onchain/validation/{token.js → helpers/token.js} +4 -4
- package/dist/cjs/onchain/validation/index.js +85 -27
- package/dist/cjs/onchain/validation/raise.js +33 -0
- package/dist/cjs/sdk/index.js +6 -11
- package/dist/cjs/sdk/liquidations/LiquidationsNamespace.js +9 -0
- package/dist/cjs/sdk/opportunities/OpportunitiesNamespace.js +19 -4
- package/dist/cjs/sdk/prepare/PrepareApi.js +40 -50
- package/dist/cjs/sdk/prepare/index.js +7 -11
- package/dist/cjs/sdk/prepare/types.js +0 -4
- package/dist/cjs/sdk/preview/PreviewNamespace.js +24 -13
- package/dist/esm/abi/rwa/iMidasAccessControl.js +22 -0
- package/dist/esm/abi/rwa/iMidasDegenNFT.js +91 -0
- package/dist/esm/dev/AccountOpener.js +1 -1
- package/dist/esm/dev/withdrawalUtils.js +1 -1
- package/dist/esm/history/assembleOperations.js +2 -2
- package/dist/esm/history/classifyMulticallOperations.js +2 -2
- package/dist/esm/history/index.js +6 -1
- package/dist/esm/history/parseCreditAccountTransaction.js +3 -3
- package/dist/esm/{preview → history}/trace/errors.js +1 -1
- package/dist/esm/{preview → history}/trace/extractAdapterCallTraces.js +1 -1
- package/dist/esm/{preview → history}/trace/extractTransfers.js +2 -2
- package/dist/esm/{preview → history}/trace/findFacadeCalls.js +1 -1
- package/dist/esm/model/errors/index.js +7 -0
- package/dist/esm/model/errors/liquidation-errors.js +29 -0
- package/dist/esm/model/errors/operation-errors.js +121 -0
- package/dist/esm/{onchain/market/oracle/errors.js → model/errors/oracle-errors.js} +1 -1
- package/dist/esm/model/errors/prepare-errors.js +97 -0
- package/dist/esm/model/errors/preview-errors.js +11 -0
- package/dist/esm/model/index.js +10 -3
- package/dist/esm/model/opportunities.schema.js +3 -1
- package/dist/esm/model/positions.js +1 -1
- package/dist/esm/model/result.js +1 -8
- package/dist/esm/model/rwa.js +48 -0
- package/dist/esm/model/rwa.schema.js +18 -0
- package/dist/esm/offchain/opportunities/OffchainOpportunities.js +1 -1
- package/dist/esm/onchain/accounts/CreditAccountsServiceV310.js +2 -2
- package/dist/esm/onchain/accounts/index.js +1 -2
- package/dist/esm/onchain/accounts/intents/guards.js +29 -52
- package/dist/esm/onchain/accounts/intents/index.js +39 -35
- package/dist/esm/onchain/accounts/intents/leverage-band.js +1 -1
- package/dist/esm/onchain/accounts/intents/math.js +18 -14
- package/dist/esm/onchain/accounts/intents/open-strategy.js +8 -6
- package/dist/esm/onchain/accounts/intents/plan.js +51 -47
- package/dist/esm/onchain/accounts/intents/realize.js +26 -24
- package/dist/esm/onchain/accounts/intents/tail.js +14 -11
- package/dist/esm/onchain/accounts/intents/testing/sdk-mock.js +7 -0
- package/dist/esm/onchain/accounts/intents/tests/finish-withdraw.fixtures.js +6 -6
- package/dist/esm/onchain/accounts/intents/tests/withdraw.fixtures.js +12 -12
- package/dist/esm/onchain/accounts/intents/view.js +1 -1
- package/dist/esm/onchain/accounts/liquidations/LiquidationsService.js +3 -3
- package/dist/esm/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/index.js +0 -1
- package/dist/esm/onchain/base/TokensMeta.js +3 -3
- package/dist/esm/onchain/core/createAddressProvider.js +1 -1
- package/dist/esm/onchain/index.js +64 -11
- package/dist/esm/onchain/market/MarketSuite.js +10 -4
- package/dist/esm/onchain/market/adapters/contracts/AccountMigratorAdapterContract.js +1 -1
- package/dist/esm/onchain/market/adapters/contracts/ERC4626AdapterContract.js +1 -1
- package/dist/esm/onchain/market/adapters/index.js +1 -0
- package/dist/esm/onchain/market/credit/CreditFacadeV310BaseContract.js +1 -1
- package/dist/esm/onchain/market/credit/CreditSuite.js +77 -15
- package/dist/esm/onchain/market/index.js +6 -6
- package/dist/esm/onchain/market/oracle/PriceOracleBaseContract.js +1 -1
- package/dist/esm/onchain/market/oracle/index.js +1 -2
- package/dist/esm/onchain/market/pool/PoolQuotaKeeperV310Contract.js +8 -0
- package/dist/esm/onchain/market/pool/PoolV310Contract.js +1 -1
- package/dist/esm/onchain/market/rwa/RWARegistry.js +2 -1
- package/dist/esm/onchain/market/rwa/createDegenNFT.js +52 -0
- package/dist/esm/onchain/market/rwa/index.js +6 -5
- package/dist/esm/onchain/market/rwa/midas/MidasDegenNFT.js +55 -0
- package/dist/esm/onchain/market/rwa/midas/constants.js +2 -1
- package/dist/esm/onchain/market/rwa/midas/index.js +3 -2
- package/dist/esm/onchain/market/rwa/securitize/SecuritizeDegenNFT.js +20 -2
- package/dist/esm/onchain/market/rwa/securitize/SecuritizeRWAFactory.js +4 -4
- package/dist/esm/onchain/market/rwa/securitize/constants.js +2 -2
- package/dist/esm/onchain/market/rwa/securitize/index.js +4 -3
- package/dist/esm/onchain/market/rwa/securitize/types.js +1 -29
- package/dist/esm/onchain/market/rwa/types.js +1 -7
- package/dist/esm/onchain/market/zapper/IETHZapperContract.js +1 -1
- package/dist/esm/onchain/market/zapper/ZapperContract.js +1 -1
- package/dist/esm/onchain/market/zapper/index.js +0 -1
- package/dist/esm/onchain/opportunities/MultichainOpportunitiesService.js +2 -2
- package/dist/esm/onchain/opportunities/OpportunitiesService.js +11 -3
- package/dist/esm/onchain/pools/PoolService.js +10 -16
- package/dist/esm/onchain/preview/index.js +20 -0
- package/dist/esm/{preview → onchain/preview}/parse/classifyInnerOperations.js +2 -3
- package/dist/esm/{preview → onchain/preview}/parse/index.js +0 -1
- package/dist/esm/{preview → onchain/preview}/parse/parseFacadeOperationCalldata.js +1 -1
- package/dist/esm/{preview → onchain/preview}/parse/parseOperationCalldata.js +10 -11
- package/dist/esm/{preview → onchain/preview}/parse/parsePoolOperationCalldata.js +3 -3
- package/dist/esm/{preview → onchain/preview}/parse/parseRWAFactoryOperationCalldata.js +8 -9
- package/dist/esm/{preview → onchain/preview}/parse/types.js +1 -1
- package/dist/esm/{preview → onchain/preview}/preview/CreditAccountState.js +3 -4
- package/dist/esm/{preview → onchain/preview}/preview/buildDelayedStrategyPositionOperationPreview.js +10 -11
- package/dist/esm/{preview → onchain/preview}/preview/detectCloseOrRepay.js +2 -3
- package/dist/esm/{preview → onchain/preview}/preview/detectDelayedClaim.js +4 -5
- package/dist/esm/{preview → onchain/preview}/preview/detectDelayedOperation.js +5 -6
- package/dist/esm/{preview → onchain/preview}/preview/estimateClaimableAt.js +1 -1
- package/dist/esm/{preview → onchain/preview}/preview/index.js +3 -4
- package/dist/esm/{preview → onchain/preview}/preview/previewAdjustStrategyPosition.js +17 -21
- package/dist/esm/{preview → onchain/preview}/preview/previewExitOrRepayStrategyPosition.js +20 -26
- package/dist/esm/{preview → onchain/preview}/preview/previewOpenStrategyPosition.js +25 -15
- package/dist/esm/{preview → onchain/preview}/preview/previewOperation.js +54 -35
- package/dist/esm/{preview/simulate/simulatePoolOperation.js → onchain/preview/preview/previewPoolPositionOperation.js} +46 -30
- package/dist/esm/onchain/preview/preview/replayInnerOperations.js +107 -0
- package/dist/esm/onchain/preview/preview/replayMulticall.js +21 -0
- package/dist/esm/{preview → onchain/preview}/preview/unwrapNativeCollateral.js +11 -14
- package/dist/esm/onchain/utils/viem/simulateWithPriceUpdates.js +1 -1
- package/dist/esm/onchain/validation/bundles/checkAccountQuotas.js +19 -0
- package/dist/esm/onchain/validation/bundles/checkCollateralFunding.js +58 -0
- package/dist/esm/onchain/validation/bundles/checkCreditOperation.js +64 -0
- package/dist/esm/onchain/validation/bundles/checkDraw.js +27 -0
- package/dist/esm/onchain/validation/bundles/checkHealthFactors.js +26 -0
- package/dist/esm/onchain/validation/bundles/checkLiquidationEligibility.js +32 -0
- package/dist/esm/onchain/validation/bundles/checkLiquidationFunding.js +28 -0
- package/dist/esm/onchain/validation/bundles/checkMarket.js +23 -0
- package/dist/esm/onchain/validation/bundles/checkObtained.js +12 -0
- package/dist/esm/onchain/validation/bundles/checkPoolFunding.js +21 -0
- package/dist/esm/onchain/validation/bundles/checkPoolOperation.js +34 -0
- package/dist/esm/onchain/validation/bundles/checkQuotasAsked.js +19 -0
- package/dist/esm/onchain/validation/bundles/checkRWAOpenRequirements.js +32 -0
- package/dist/esm/onchain/validation/bundles/checkRWAOpening.js +23 -0
- package/dist/esm/onchain/validation/bundles/checkWallet.js +21 -0
- package/dist/esm/onchain/validation/bundles/checkWalletAllowance.js +31 -0
- package/dist/esm/onchain/validation/bundles/checkWalletBalance.js +40 -0
- package/dist/esm/onchain/validation/bundles/index.js +18 -0
- package/dist/esm/onchain/validation/checkLiquidation.js +21 -0
- package/dist/esm/onchain/validation/checkOperation.js +61 -0
- package/dist/esm/onchain/validation/checkSimulation.js +59 -0
- package/dist/esm/onchain/validation/checks/checkBorrowLimit.js +24 -0
- package/dist/esm/onchain/validation/checks/checkCollateralised.js +25 -0
- package/dist/esm/onchain/validation/checks/checkCreditAccountFrozen.js +9 -0
- package/dist/esm/onchain/validation/checks/checkCreditManagerPaused.js +9 -0
- package/dist/esm/onchain/validation/checks/checkDebtLimits.js +17 -0
- package/dist/esm/onchain/validation/checks/checkEmergencyLiquidator.js +12 -0
- package/dist/esm/onchain/validation/checks/checkForbiddenToken.js +9 -0
- package/dist/esm/onchain/validation/checks/checkLeverage.js +12 -0
- package/dist/esm/onchain/validation/checks/checkLiquidatorEligible.js +9 -0
- package/dist/esm/onchain/validation/checks/checkMarketExpired.js +9 -0
- package/dist/esm/onchain/validation/checks/checkPoolLiquidity.js +24 -0
- package/dist/esm/onchain/validation/checks/checkPoolPaused.js +9 -0
- package/dist/esm/onchain/validation/checks/checkPoolSunset.js +9 -0
- package/dist/esm/onchain/validation/checks/checkQuotaCount.js +9 -0
- package/dist/esm/onchain/validation/checks/checkQuotaLimit.js +17 -0
- package/dist/esm/onchain/validation/checks/index.js +16 -0
- package/dist/esm/onchain/validation/helpers/amount.js +11 -0
- package/dist/esm/onchain/validation/helpers/health-factor-limits.js +21 -0
- package/dist/esm/onchain/validation/helpers/index.js +4 -0
- package/dist/esm/onchain/validation/{token.js → helpers/token.js} +3 -3
- package/dist/esm/onchain/validation/index.js +43 -4
- package/dist/esm/onchain/validation/raise.js +31 -0
- package/dist/esm/sdk/index.js +2 -3
- package/dist/esm/sdk/liquidations/LiquidationsNamespace.js +9 -0
- package/dist/esm/sdk/opportunities/OpportunitiesNamespace.js +19 -4
- package/dist/esm/sdk/prepare/PrepareApi.js +25 -35
- package/dist/esm/sdk/prepare/index.js +3 -3
- package/dist/esm/sdk/prepare/types.js +1 -2
- package/dist/esm/sdk/preview/PreviewNamespace.js +24 -13
- package/dist/types/abi/rwa/iMidasAccessControl.d.ts +22 -0
- package/dist/types/abi/rwa/iMidasDegenNFT.d.ts +82 -0
- package/dist/types/history/assembleOperations.d.ts +4 -5
- package/dist/types/history/classifyMulticallOperations.d.ts +3 -4
- package/dist/types/history/index.d.ts +8 -2
- package/dist/types/history/mapOperations.d.ts +1 -1
- package/dist/types/{preview → history}/trace/errors.d.ts +1 -1
- package/dist/types/{preview → history}/trace/extractAdapterCallTraces.d.ts +1 -1
- package/dist/types/{preview → history}/trace/extractTransfers.d.ts +2 -3
- package/dist/types/{preview → history}/trace/findFacadeCalls.d.ts +1 -1
- package/dist/types/{preview → history}/trace/types.d.ts +1 -1
- package/dist/types/history/types.d.ts +2 -3
- package/dist/types/model/errors/base.d.ts +28 -0
- package/dist/types/model/errors/index.d.ts +7 -0
- package/dist/types/model/errors/liquidation-errors.d.ts +45 -0
- package/dist/types/model/errors/operation-errors.d.ts +216 -0
- package/dist/types/{onchain/market/oracle/errors.d.ts → model/errors/oracle-errors.d.ts} +3 -5
- package/dist/types/model/errors/prepare-errors.d.ts +131 -0
- package/dist/types/model/errors/preview-errors.d.ts +72 -0
- package/dist/types/model/index.d.ts +12 -4
- package/dist/types/model/opportunities.d.ts +12 -2
- package/dist/types/model/opportunities.schema.d.ts +30 -0
- package/dist/types/model/positions.d.ts +2 -2
- package/dist/types/model/previews.d.ts +52 -113
- package/dist/types/model/result.d.ts +4 -8
- package/dist/types/model/rwa.d.ts +167 -0
- package/dist/types/model/rwa.schema.d.ts +29 -0
- package/dist/types/offchain/opportunities/OffchainOpportunities.d.ts +2 -1
- package/dist/types/offchain/opportunities/types.d.ts +4 -1
- package/dist/types/onchain/accounts/CreditAccountsServiceV310.d.ts +3 -1
- package/dist/types/onchain/accounts/index.d.ts +2 -4
- package/dist/types/onchain/accounts/intents/guards.d.ts +8 -18
- package/dist/types/onchain/accounts/intents/index.d.ts +20 -19
- package/dist/types/onchain/accounts/intents/leverage-band.d.ts +1 -1
- package/dist/types/onchain/accounts/intents/math.d.ts +6 -6
- package/dist/types/onchain/accounts/intents/operations.d.ts +2 -2
- package/dist/types/onchain/accounts/intents/plan.d.ts +9 -9
- package/dist/types/onchain/accounts/intents/tail.d.ts +2 -2
- package/dist/types/onchain/accounts/intents/testing/expect.d.ts +3 -3
- package/dist/types/onchain/accounts/intents/tests/finish-withdraw.fixtures.d.ts +6 -6
- package/dist/types/onchain/accounts/intents/tests/withdraw.fixtures.d.ts +12 -12
- package/dist/types/onchain/accounts/intents/types.d.ts +32 -30
- package/dist/types/onchain/accounts/types.d.ts +2 -1
- package/dist/types/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.d.ts +1 -1
- package/dist/types/onchain/accounts/withdrawal-compressor/index.d.ts +1 -2
- package/dist/types/onchain/accounts/withdrawal-compressor/types.d.ts +1 -1
- package/dist/types/onchain/index.d.ts +73 -16
- package/dist/types/onchain/market/MarketSuite.d.ts +5 -1
- package/dist/types/onchain/market/adapters/index.d.ts +2 -1
- package/dist/types/onchain/market/adapters/transfers.d.ts +0 -7
- package/dist/types/onchain/market/credit/CreditSuite.d.ts +30 -8
- package/dist/types/onchain/market/credit/index.d.ts +2 -2
- package/dist/types/onchain/market/credit/types.d.ts +11 -1
- package/dist/types/onchain/market/index.d.ts +11 -10
- package/dist/types/onchain/market/oracle/PriceOracleBaseContract.d.ts +1 -1
- package/dist/types/onchain/market/oracle/index.d.ts +1 -2
- package/dist/types/onchain/market/oracle/types.d.ts +1 -1
- package/dist/types/onchain/market/pool/PoolQuotaKeeperV310Contract.d.ts +5 -0
- package/dist/types/onchain/market/rwa/RWARegistry.d.ts +1 -1
- package/dist/types/onchain/market/rwa/createDegenNFT.d.ts +12 -0
- package/dist/types/onchain/market/rwa/index.d.ts +10 -8
- package/dist/types/onchain/market/rwa/midas/MidasDegenNFT.d.ts +98 -0
- package/dist/types/onchain/market/rwa/midas/constants.d.ts +2 -1
- package/dist/types/onchain/market/rwa/midas/index.d.ts +3 -2
- package/dist/types/onchain/market/rwa/securitize/SecuritizeDegenNFT.d.ts +8 -2
- package/dist/types/onchain/market/rwa/securitize/SecuritizeRWAFactory.d.ts +4 -3
- package/dist/types/onchain/market/rwa/securitize/constants.d.ts +2 -2
- package/dist/types/onchain/market/rwa/securitize/index.d.ts +5 -4
- package/dist/types/onchain/market/rwa/securitize/types.d.ts +4 -110
- package/dist/types/onchain/market/rwa/types.d.ts +24 -32
- package/dist/types/onchain/market/zapper/ZapperContract.d.ts +1 -1
- package/dist/types/onchain/market/zapper/index.d.ts +1 -2
- package/dist/types/onchain/market/zapper/types.d.ts +1 -1
- package/dist/types/onchain/opportunities/MultichainOpportunitiesService.d.ts +2 -1
- package/dist/types/onchain/opportunities/OpportunitiesService.d.ts +5 -1
- package/dist/types/onchain/opportunities/types.d.ts +3 -2
- package/dist/types/onchain/pools/types.d.ts +2 -2
- package/dist/types/onchain/preview/index.d.ts +24 -0
- package/dist/types/{preview → onchain/preview}/parse/classifyInnerOperations.d.ts +4 -4
- package/dist/types/{preview → onchain/preview}/parse/index.d.ts +2 -4
- package/dist/types/{preview → onchain/preview}/parse/parseFacadeOperationCalldata.d.ts +4 -4
- package/dist/types/onchain/preview/parse/parseOperationCalldata.d.ts +18 -0
- package/dist/types/{preview → onchain/preview}/parse/parsePoolOperationCalldata.d.ts +7 -7
- package/dist/types/{preview → onchain/preview}/parse/parseRWAFactoryOperationCalldata.d.ts +4 -4
- package/dist/types/{preview → onchain/preview}/parse/types-adapters.d.ts +5 -16
- package/dist/types/{preview → onchain/preview}/parse/types-facades.d.ts +3 -3
- package/dist/types/{preview → onchain/preview}/parse/types-pools.d.ts +1 -1
- package/dist/types/{preview → onchain/preview}/parse/types-rwa.d.ts +3 -3
- package/dist/types/{preview → onchain/preview}/parse/types.d.ts +3 -3
- package/dist/types/{preview → onchain/preview}/preview/CreditAccountState.d.ts +5 -5
- package/dist/types/{preview → onchain/preview}/preview/buildDelayedStrategyPositionOperationPreview.d.ts +5 -5
- package/dist/types/{preview → onchain/preview}/preview/detectCloseOrRepay.d.ts +1 -1
- package/dist/types/{preview → onchain/preview}/preview/detectDelayedClaim.d.ts +8 -8
- package/dist/types/{preview → onchain/preview}/preview/detectDelayedOperation.d.ts +9 -9
- package/dist/types/{preview → onchain/preview}/preview/estimateClaimableAt.d.ts +6 -6
- package/dist/types/{preview → onchain/preview}/preview/index.d.ts +3 -4
- package/dist/types/onchain/preview/preview/previewAdjustStrategyPosition.d.ts +20 -0
- package/dist/types/onchain/preview/preview/previewExitOrRepayStrategyPosition.d.ts +21 -0
- package/dist/types/onchain/preview/preview/previewOpenStrategyPosition.d.ts +14 -0
- package/dist/types/onchain/preview/preview/previewOperation.d.ts +32 -0
- package/dist/types/onchain/preview/preview/previewPoolPositionOperation.d.ts +13 -0
- package/dist/types/{preview → onchain/preview}/preview/replayInnerOperations.d.ts +11 -11
- package/dist/types/{preview → onchain/preview}/preview/replayMulticall.d.ts +10 -10
- package/dist/types/{preview → onchain/preview}/preview/unwrapNativeCollateral.d.ts +10 -20
- package/dist/types/onchain/validation/bundles/checkAccountQuotas.d.ts +16 -0
- package/dist/types/onchain/validation/bundles/checkCollateralFunding.d.ts +22 -0
- package/dist/types/onchain/validation/bundles/checkCreditOperation.d.ts +31 -0
- package/dist/types/onchain/validation/bundles/checkDraw.d.ts +20 -0
- package/dist/types/onchain/validation/bundles/checkHealthFactors.d.ts +39 -0
- package/dist/types/onchain/validation/bundles/checkLiquidationEligibility.d.ts +20 -0
- package/dist/types/onchain/validation/bundles/checkLiquidationFunding.d.ts +18 -0
- package/dist/types/onchain/validation/bundles/checkMarket.d.ts +15 -0
- package/dist/types/onchain/validation/bundles/checkObtained.d.ts +9 -0
- package/dist/types/onchain/validation/bundles/checkPoolFunding.d.ts +19 -0
- package/dist/types/onchain/validation/bundles/checkPoolOperation.d.ts +31 -0
- package/dist/types/onchain/validation/bundles/checkQuotasAsked.d.ts +10 -0
- package/dist/types/onchain/validation/bundles/checkRWAOpenRequirements.d.ts +21 -0
- package/dist/types/onchain/validation/bundles/checkRWAOpening.d.ts +19 -0
- package/dist/types/onchain/validation/bundles/checkWallet.d.ts +23 -0
- package/dist/types/onchain/validation/bundles/checkWalletAllowance.d.ts +18 -0
- package/dist/types/onchain/validation/bundles/checkWalletBalance.d.ts +17 -0
- package/dist/types/onchain/validation/bundles/index.d.ts +18 -0
- package/dist/types/onchain/validation/checkLiquidation.d.ts +23 -0
- package/dist/types/onchain/validation/checkOperation.d.ts +32 -0
- package/dist/types/onchain/validation/checkSimulation.d.ts +56 -0
- package/dist/types/onchain/validation/checks/checkBorrowLimit.d.ts +21 -0
- package/dist/types/onchain/validation/checks/checkCollateralised.d.ts +25 -0
- package/dist/types/onchain/validation/checks/checkCreditAccountFrozen.d.ts +12 -0
- package/dist/types/onchain/validation/checks/checkCreditManagerPaused.d.ts +12 -0
- package/dist/types/onchain/validation/checks/checkDebtLimits.d.ts +21 -0
- package/dist/types/onchain/validation/checks/checkEmergencyLiquidator.d.ts +17 -0
- package/dist/types/onchain/validation/checks/checkForbiddenToken.d.ts +12 -0
- package/dist/types/onchain/validation/checks/checkLeverage.d.ts +12 -0
- package/dist/types/onchain/validation/checks/checkLiquidatorEligible.d.ts +13 -0
- package/dist/types/onchain/validation/checks/checkMarketExpired.d.ts +14 -0
- package/dist/types/onchain/validation/checks/checkPoolLiquidity.d.ts +20 -0
- package/dist/types/onchain/validation/checks/checkPoolPaused.d.ts +12 -0
- package/dist/types/onchain/validation/checks/checkPoolSunset.d.ts +13 -0
- package/dist/types/onchain/validation/checks/checkQuotaCount.d.ts +11 -0
- package/dist/types/onchain/validation/checks/checkQuotaLimit.d.ts +18 -0
- package/dist/types/onchain/validation/checks/index.d.ts +16 -0
- package/dist/types/onchain/validation/helpers/amount.d.ts +7 -0
- package/dist/types/onchain/validation/helpers/health-factor-limits.d.ts +21 -0
- package/dist/types/onchain/validation/helpers/index.d.ts +4 -0
- package/dist/types/onchain/validation/{token.d.ts → helpers/token.d.ts} +4 -4
- package/dist/types/onchain/validation/index.d.ts +43 -4
- package/dist/types/onchain/validation/raise.d.ts +33 -0
- package/dist/types/sdk/execute/types.d.ts +2 -2
- package/dist/types/sdk/index.d.ts +5 -6
- package/dist/types/sdk/liquidations/LiquidationsNamespace.d.ts +5 -0
- package/dist/types/sdk/liquidations/types.d.ts +8 -0
- package/dist/types/sdk/opportunities/OpportunitiesNamespace.d.ts +2 -1
- package/dist/types/sdk/opportunities/types.d.ts +8 -2
- package/dist/types/sdk/prepare/PrepareApi.d.ts +5 -4
- package/dist/types/sdk/prepare/index.d.ts +5 -5
- package/dist/types/sdk/prepare/types.d.ts +41 -22
- package/dist/types/sdk/preview/PreviewNamespace.d.ts +13 -3
- package/dist/types/sdk/preview/index.d.ts +2 -2
- package/dist/types/sdk/preview/types.d.ts +30 -7
- package/package.json +1 -6
- package/dist/cjs/onchain/accounts/withdrawal-compressor/errors.js +0 -1
- package/dist/cjs/onchain/market/zapper/errors.js +0 -1
- package/dist/cjs/onchain/validation/checks.js +0 -258
- package/dist/cjs/onchain/validation/refusal.js +0 -39
- package/dist/cjs/preview/index.js +0 -86
- package/dist/cjs/preview/package.json +0 -1
- package/dist/cjs/preview/parse/errors.js +0 -1
- package/dist/cjs/preview/parse/index.js +0 -15
- package/dist/cjs/preview/prerequisites/AllowancePrerequisite.js +0 -38
- package/dist/cjs/preview/prerequisites/BalancePrerequisite.js +0 -52
- package/dist/cjs/preview/prerequisites/Prerequisite.js +0 -52
- package/dist/cjs/preview/prerequisites/RWAOpenRequirementsPrerequisite.js +0 -53
- package/dist/cjs/preview/prerequisites/buildCollateralPrerequisites.js +0 -63
- package/dist/cjs/preview/prerequisites/buildPartialLiquidationPrerequisites.js +0 -19
- package/dist/cjs/preview/prerequisites/buildPoolPrerequisites.js +0 -76
- package/dist/cjs/preview/prerequisites/buildRWAPrerequisites.js +0 -39
- package/dist/cjs/preview/prerequisites/checkPrerequisites.js +0 -74
- package/dist/cjs/preview/prerequisites/helpers.js +0 -23
- package/dist/cjs/preview/prerequisites/index.js +0 -12
- package/dist/cjs/preview/preview/errors.js +0 -85
- package/dist/cjs/preview/preview/index.js +0 -33
- package/dist/cjs/preview/preview/previewOpenStrategyPosition.js +0 -50
- package/dist/cjs/preview/preview/previewOperation.js +0 -100
- package/dist/cjs/preview/preview/previewPoolPositionOperation.js +0 -49
- package/dist/cjs/preview/preview/replayInnerOperations.js +0 -109
- package/dist/cjs/preview/preview/replayMulticall.js +0 -19
- package/dist/cjs/preview/simulate/errors.js +0 -73
- package/dist/cjs/preview/simulate/index.js +0 -11
- package/dist/cjs/preview/simulate/simulateFacadeOperation.js +0 -15
- package/dist/cjs/preview/simulate/simulateOperation.js +0 -29
- package/dist/cjs/preview/simulate/simulateRWAOperation.js +0 -15
- package/dist/cjs/preview/simulate/types.js +0 -1
- package/dist/cjs/preview/trace/index.js +0 -14
- package/dist/cjs/preview/trace/types.js +0 -1
- package/dist/cjs/preview/types.js +0 -1
- package/dist/cjs/preview/validate/checkOperation.js +0 -187
- package/dist/cjs/preview/validate/checkSimulation.js +0 -39
- package/dist/cjs/preview/validate/index.js +0 -8
- package/dist/cjs/sdk/prepare/errors.js +0 -114
- package/dist/esm/onchain/accounts/withdrawal-compressor/errors.js +0 -1
- package/dist/esm/onchain/market/zapper/errors.js +0 -1
- package/dist/esm/onchain/validation/checks.js +0 -238
- package/dist/esm/onchain/validation/refusal.js +0 -36
- package/dist/esm/preview/index.js +0 -38
- package/dist/esm/preview/package.json +0 -1
- package/dist/esm/preview/parse/errors.js +0 -1
- package/dist/esm/preview/prerequisites/AllowancePrerequisite.js +0 -37
- package/dist/esm/preview/prerequisites/BalancePrerequisite.js +0 -51
- package/dist/esm/preview/prerequisites/Prerequisite.js +0 -51
- package/dist/esm/preview/prerequisites/RWAOpenRequirementsPrerequisite.js +0 -52
- package/dist/esm/preview/prerequisites/buildCollateralPrerequisites.js +0 -62
- package/dist/esm/preview/prerequisites/buildPartialLiquidationPrerequisites.js +0 -18
- package/dist/esm/preview/prerequisites/buildPoolPrerequisites.js +0 -75
- package/dist/esm/preview/prerequisites/buildRWAPrerequisites.js +0 -38
- package/dist/esm/preview/prerequisites/checkPrerequisites.js +0 -73
- package/dist/esm/preview/prerequisites/helpers.js +0 -22
- package/dist/esm/preview/prerequisites/index.js +0 -7
- package/dist/esm/preview/preview/errors.js +0 -79
- package/dist/esm/preview/preview/previewPoolPositionOperation.js +0 -48
- package/dist/esm/preview/preview/replayInnerOperations.js +0 -107
- package/dist/esm/preview/preview/replayMulticall.js +0 -18
- package/dist/esm/preview/simulate/errors.js +0 -71
- package/dist/esm/preview/simulate/index.js +0 -6
- package/dist/esm/preview/simulate/simulateFacadeOperation.js +0 -14
- package/dist/esm/preview/simulate/simulateOperation.js +0 -28
- package/dist/esm/preview/simulate/simulateRWAOperation.js +0 -14
- package/dist/esm/preview/simulate/types.js +0 -1
- package/dist/esm/preview/trace/types.js +0 -1
- package/dist/esm/preview/types.js +0 -1
- package/dist/esm/preview/validate/checkOperation.js +0 -183
- package/dist/esm/preview/validate/checkSimulation.js +0 -38
- package/dist/esm/preview/validate/index.js +0 -3
- package/dist/esm/sdk/prepare/errors.js +0 -108
- package/dist/types/model/errors.d.ts +0 -46
- package/dist/types/onchain/accounts/withdrawal-compressor/errors.d.ts +0 -20
- package/dist/types/onchain/market/zapper/errors.d.ts +0 -18
- package/dist/types/onchain/validation/checks.d.ts +0 -164
- package/dist/types/onchain/validation/refusal.d.ts +0 -242
- package/dist/types/preview/index.d.ts +0 -47
- package/dist/types/preview/parse/errors.d.ts +0 -29
- package/dist/types/preview/parse/parseOperationCalldata.d.ts +0 -18
- package/dist/types/preview/prerequisites/AllowancePrerequisite.d.ts +0 -26
- package/dist/types/preview/prerequisites/BalancePrerequisite.d.ts +0 -29
- package/dist/types/preview/prerequisites/Prerequisite.d.ts +0 -26
- package/dist/types/preview/prerequisites/RWAOpenRequirementsPrerequisite.d.ts +0 -55
- package/dist/types/preview/prerequisites/buildCollateralPrerequisites.d.ts +0 -20
- package/dist/types/preview/prerequisites/buildPartialLiquidationPrerequisites.d.ts +0 -12
- package/dist/types/preview/prerequisites/buildPoolPrerequisites.d.ts +0 -12
- package/dist/types/preview/prerequisites/buildRWAPrerequisites.d.ts +0 -26
- package/dist/types/preview/prerequisites/checkPrerequisites.d.ts +0 -28
- package/dist/types/preview/prerequisites/helpers.d.ts +0 -10
- package/dist/types/preview/prerequisites/index.d.ts +0 -7
- package/dist/types/preview/prerequisites/types.d.ts +0 -53
- package/dist/types/preview/preview/errors.d.ts +0 -44
- package/dist/types/preview/preview/previewAdjustStrategyPosition.d.ts +0 -19
- package/dist/types/preview/preview/previewExitOrRepayStrategyPosition.d.ts +0 -18
- package/dist/types/preview/preview/previewOpenStrategyPosition.d.ts +0 -12
- package/dist/types/preview/preview/previewOperation.d.ts +0 -32
- package/dist/types/preview/preview/previewPoolPositionOperation.d.ts +0 -13
- package/dist/types/preview/simulate/errors.d.ts +0 -52
- package/dist/types/preview/simulate/index.d.ts +0 -7
- package/dist/types/preview/simulate/simulateFacadeOperation.d.ts +0 -16
- package/dist/types/preview/simulate/simulateOperation.d.ts +0 -12
- package/dist/types/preview/simulate/simulatePoolOperation.d.ts +0 -42
- package/dist/types/preview/simulate/simulateRWAOperation.d.ts +0 -16
- package/dist/types/preview/simulate/types.d.ts +0 -48
- package/dist/types/preview/types.d.ts +0 -65
- package/dist/types/preview/validate/checkOperation.d.ts +0 -71
- package/dist/types/preview/validate/checkSimulation.d.ts +0 -32
- package/dist/types/preview/validate/index.d.ts +0 -3
- package/dist/types/sdk/prepare/errors.d.ts +0 -343
- /package/dist/cjs/{preview/prerequisites → history/trace}/types.js +0 -0
- /package/dist/cjs/model/{errors.js → errors/base.js} +0 -0
- /package/dist/cjs/{preview → onchain/preview}/parse/types-adapters.js +0 -0
- /package/dist/cjs/{preview → onchain/preview}/parse/types-facades.js +0 -0
- /package/dist/cjs/{preview → onchain/preview}/parse/types-pools.js +0 -0
- /package/dist/cjs/{preview → onchain/preview}/parse/types-rwa.js +0 -0
- /package/dist/esm/{preview → history}/trace/index.js +0 -0
- /package/dist/esm/{preview/prerequisites → history/trace}/types.js +0 -0
- /package/dist/esm/model/{errors.js → errors/base.js} +0 -0
- /package/dist/esm/{preview → onchain/preview}/parse/types-adapters.js +0 -0
- /package/dist/esm/{preview → onchain/preview}/parse/types-facades.js +0 -0
- /package/dist/esm/{preview → onchain/preview}/parse/types-pools.js +0 -0
- /package/dist/esm/{preview → onchain/preview}/parse/types-rwa.js +0 -0
- /package/dist/types/{preview → history}/trace/index.d.ts +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "
|
|
1
|
+
import { creditAccountNotFound } from "../../../model/errors/prepare-errors.js";
|
|
2
|
+
import { sdkErr, sdkOk } from "../../../model/result.js";
|
|
3
|
+
import "../../../model/index.js";
|
|
3
4
|
import { parseOperationCalldata } from "../parse/parseOperationCalldata.js";
|
|
4
5
|
import { isPoolOperation } from "../parse/types.js";
|
|
5
6
|
import "../parse/index.js";
|
|
@@ -8,12 +9,12 @@ import { isCloseOrRepay } from "./detectCloseOrRepay.js";
|
|
|
8
9
|
import { resolveDelayedClaimIntent } from "./detectDelayedClaim.js";
|
|
9
10
|
import { detectDelayedOperation } from "./detectDelayedOperation.js";
|
|
10
11
|
import { estimateClaimableAt } from "./estimateClaimableAt.js";
|
|
11
|
-
import { replayMulticall } from "./replayMulticall.js";
|
|
12
12
|
import { previewAdjustStrategyPosition } from "./previewAdjustStrategyPosition.js";
|
|
13
13
|
import { previewExitOrRepayStrategyPosition } from "./previewExitOrRepayStrategyPosition.js";
|
|
14
14
|
import { previewOpenStrategyPosition } from "./previewOpenStrategyPosition.js";
|
|
15
15
|
import { previewPoolPositionOperation } from "./previewPoolPositionOperation.js";
|
|
16
|
-
|
|
16
|
+
import { replayMulticall } from "./replayMulticall.js";
|
|
17
|
+
//#region src/onchain/preview/preview/previewOperation.ts
|
|
17
18
|
/**
|
|
18
19
|
* Previews a raw operation calldata: decodes it into a typed operation and
|
|
19
20
|
* assembles an operation-specific, human-displayable preview.
|
|
@@ -21,24 +22,37 @@ import { previewPoolPositionOperation } from "./previewPoolPositionOperation.js"
|
|
|
21
22
|
* Answers an {@link SDKReturn} envelope: the preview behind `ok: true`, or —
|
|
22
23
|
* when the transaction is one the previewer refuses to read — a
|
|
23
24
|
* {@link PreviewOperationError} behind `ok: false`. A thrown exception
|
|
24
|
-
* still means the SDK could not do its job (a read failed,
|
|
25
|
-
*
|
|
25
|
+
* still means the SDK could not do its job (a read failed), not a refusal
|
|
26
|
+
* of the transaction.
|
|
27
|
+
*
|
|
28
|
+
* `input.chainId` and `sdk` both name the chain; the engine does not read
|
|
29
|
+
* `input.chainId`.
|
|
26
30
|
*/
|
|
27
|
-
async function previewOperation(input, options) {
|
|
28
|
-
const parsed = parseOperationCalldata(input);
|
|
29
|
-
if (
|
|
31
|
+
async function previewOperation(sdk, input, options, creditAccount) {
|
|
32
|
+
const parsed = parseOperationCalldata(sdk, input);
|
|
33
|
+
if (!parsed.ok) return parsed;
|
|
30
34
|
const operation = parsed.data;
|
|
31
|
-
if (isPoolOperation(operation)) return previewPoolPositionOperation(
|
|
32
|
-
if (operation.operation === "OpenCreditAccount" || operation.operation === "RWAOpenCreditAccount") return
|
|
35
|
+
if (isPoolOperation(operation)) return previewPoolPositionOperation(sdk, operation, options);
|
|
36
|
+
if (operation.operation === "OpenCreditAccount" || operation.operation === "RWAOpenCreditAccount") return previewOpenStrategyPosition(sdk, input, operation);
|
|
33
37
|
if (operation.operation === "CloseCreditAccount") {
|
|
34
|
-
const resolved = await resolveCreditAccount(
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
if (
|
|
38
|
-
preview
|
|
39
|
-
|
|
38
|
+
const resolved = await resolveCreditAccount(sdk, operation, options, creditAccount);
|
|
39
|
+
if (!resolved.ok) return resolved;
|
|
40
|
+
const replayed = replayMulticall(sdk, operation, resolved.data);
|
|
41
|
+
if (!replayed.ok) return replayed;
|
|
42
|
+
const preview = previewExitOrRepayStrategyPosition(sdk, input, operation, true, replayed.data);
|
|
43
|
+
if (!preview.ok) return preview;
|
|
44
|
+
const intent = await resolveDelayedClaimIntent(sdk, operation.multicall, options?.blockNumber);
|
|
45
|
+
if (!intent.ok) return intent;
|
|
46
|
+
preview.data.intent = intent.data;
|
|
47
|
+
return preview;
|
|
48
|
+
}
|
|
49
|
+
if (operation.operation === "MultiCall" || operation.operation === "BotMulticall" || operation.operation === "RWAMulticall") {
|
|
50
|
+
const resolved = await resolveCreditAccount(sdk, operation, options, creditAccount);
|
|
51
|
+
if (!resolved.ok) return resolved;
|
|
52
|
+
const replayed = replayMulticall(sdk, operation, resolved.data);
|
|
53
|
+
if (!replayed.ok) return replayed;
|
|
54
|
+
return previewMulticallOperation(sdk, input, operation, replayed.data, options?.blockNumber);
|
|
40
55
|
}
|
|
41
|
-
if (operation.operation === "MultiCall" || operation.operation === "BotMulticall" || operation.operation === "RWAMulticall") return previewMulticallOperation(input, operation, await resolveCreditAccount(input, operation, options));
|
|
42
56
|
return sdkErr({
|
|
43
57
|
code: "unsupportedOperation",
|
|
44
58
|
message: `operation "${operation.operation}" is not supported by previewOperation`,
|
|
@@ -47,17 +61,14 @@ async function previewOperation(input, options) {
|
|
|
47
61
|
}
|
|
48
62
|
/**
|
|
49
63
|
* Resolves the pre-state of the credit account an operation targets: uses the
|
|
50
|
-
* state
|
|
51
|
-
*
|
|
64
|
+
* injected state when present, otherwise fetches it from the credit account
|
|
65
|
+
* compressor.
|
|
52
66
|
*/
|
|
53
|
-
async function resolveCreditAccount(
|
|
54
|
-
let
|
|
55
|
-
if (!
|
|
56
|
-
if (!
|
|
57
|
-
return
|
|
58
|
-
...options,
|
|
59
|
-
creditAccount
|
|
60
|
-
};
|
|
67
|
+
async function resolveCreditAccount(sdk, operation, options, creditAccount) {
|
|
68
|
+
let resolved = creditAccount;
|
|
69
|
+
if (!resolved) resolved = await sdk.accounts.getCreditAccountData(operation.creditAccount, options?.blockNumber);
|
|
70
|
+
if (!resolved) return sdkErr(creditAccountNotFound(operation.creditAccount));
|
|
71
|
+
return sdkOk(resolved);
|
|
61
72
|
}
|
|
62
73
|
/**
|
|
63
74
|
* Previews a plain/bot/RWA multicall: classifies the instant preview
|
|
@@ -66,19 +77,27 @@ async function resolveCreditAccount(input, operation, options) {
|
|
|
66
77
|
* `DelayedCreditAccountOperation` together with the best-effort preview of
|
|
67
78
|
* the state after the withdrawal is claimed.
|
|
68
79
|
*/
|
|
69
|
-
async function previewMulticallOperation(input, operation,
|
|
70
|
-
|
|
71
|
-
|
|
80
|
+
async function previewMulticallOperation(sdk, input, operation, replay, blockNumber) {
|
|
81
|
+
let instantPreview;
|
|
82
|
+
if (isCloseOrRepay(operation.multicall)) {
|
|
83
|
+
const instant = previewExitOrRepayStrategyPosition(sdk, input, operation, false, replay);
|
|
84
|
+
if (!instant.ok) return instant;
|
|
85
|
+
instantPreview = instant.data;
|
|
86
|
+
} else {
|
|
87
|
+
const instant = previewAdjustStrategyPosition(sdk, input, operation, replay);
|
|
88
|
+
if (!instant.ok) return instant;
|
|
89
|
+
instantPreview = instant.data;
|
|
90
|
+
}
|
|
72
91
|
const detected = detectDelayedOperation(sdk, operation.multicall);
|
|
73
|
-
if (
|
|
92
|
+
if (!detected.ok) return detected;
|
|
74
93
|
const delayed = detected.data;
|
|
75
94
|
if (!delayed) {
|
|
76
|
-
const intent = await resolveDelayedClaimIntent(sdk, operation.multicall,
|
|
77
|
-
if (
|
|
95
|
+
const intent = await resolveDelayedClaimIntent(sdk, operation.multicall, blockNumber);
|
|
96
|
+
if (!intent.ok) return intent;
|
|
78
97
|
instantPreview.intent = intent.data;
|
|
79
98
|
return sdkOk(instantPreview);
|
|
80
99
|
}
|
|
81
|
-
const { before, after } =
|
|
100
|
+
const { before, after } = replay;
|
|
82
101
|
const market = sdk.marketRegister.findByCreditManager(operation.creditManager);
|
|
83
102
|
const meta = sdk.tokensMeta.get(market.underlying);
|
|
84
103
|
const receivedToken = meta && sdk.tokensMeta.isRWAUnderlying(meta) ? meta.asset : market.underlying;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import "
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
//#region src/preview/
|
|
1
|
+
import { ierc20Abi } from "../../../abi/iERC20.js";
|
|
2
|
+
import { iZapperAbi } from "../../../abi/iZapper.js";
|
|
3
|
+
import { iPoolV310Abi } from "../../../abi/310/generated.js";
|
|
4
|
+
import { sdkErr, sdkOk } from "../../../model/result.js";
|
|
5
|
+
import "../../../model/index.js";
|
|
6
|
+
//#region src/onchain/preview/preview/previewPoolPositionOperation.ts
|
|
7
7
|
function previewRead(operation) {
|
|
8
8
|
switch (operation.operation) {
|
|
9
9
|
case "Deposit": return {
|
|
@@ -73,34 +73,50 @@ function amountsInOut(operation, previewAmount) {
|
|
|
73
73
|
};
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
* `previewDeposit`/`previewMint`/`previewWithdraw`/`previewRedeem`, or the
|
|
84
|
-
* zapper's `previewDeposit`/`previewRedeem`) to convert the calldata-known
|
|
85
|
-
* amount into its counterpart. It works on every network the SDK supports.
|
|
86
|
-
*
|
|
87
|
-
* It does not execute the calldata, so it ignores balance/allowance
|
|
88
|
-
* prerequisites (preview reads succeed regardless).
|
|
89
|
-
*/
|
|
90
|
-
async function simulatePoolOperation(input, options = {}) {
|
|
91
|
-
const { sdk, operation } = input;
|
|
92
|
-
const { blockNumber, logger } = options;
|
|
76
|
+
async function previewPoolPositionOperation(sdk, operation, options) {
|
|
77
|
+
const { tokenIn, tokenOut } = operation;
|
|
78
|
+
const market = sdk.marketRegister.findByPool(operation.pool);
|
|
79
|
+
const pool = market.pool.pool;
|
|
80
|
+
const holder = "owner" in operation ? operation.owner : operation.receiver;
|
|
81
|
+
let previewAmount;
|
|
82
|
+
let shares;
|
|
93
83
|
try {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
84
|
+
[previewAmount, shares] = await sdk.client.multicall({
|
|
85
|
+
contracts: [previewContract(operation), {
|
|
86
|
+
address: operation.pool,
|
|
87
|
+
abi: ierc20Abi,
|
|
88
|
+
functionName: "balanceOf",
|
|
89
|
+
args: [holder]
|
|
90
|
+
}],
|
|
91
|
+
allowFailure: false,
|
|
92
|
+
batchSize: 0,
|
|
93
|
+
blockNumber: options?.blockNumber
|
|
97
94
|
});
|
|
98
|
-
return sdkOk(amountsInOut(operation, previewAmount));
|
|
99
95
|
} catch (cause) {
|
|
100
|
-
const error =
|
|
101
|
-
|
|
96
|
+
const error = {
|
|
97
|
+
code: "poolOperationPreviewError",
|
|
98
|
+
message: cause instanceof Error ? cause.message : String(cause),
|
|
99
|
+
pool: operation.pool,
|
|
100
|
+
cause: cause instanceof Error ? cause : new Error(String(cause))
|
|
101
|
+
};
|
|
102
102
|
return sdkErr(error);
|
|
103
103
|
}
|
|
104
|
+
const sim = amountsInOut(operation, previewAmount);
|
|
105
|
+
const inflow = operation.operation === "Deposit" || operation.operation === "Mint";
|
|
106
|
+
const after = shares + (inflow ? sim.amountOut : -sim.amountIn);
|
|
107
|
+
return sdkOk({
|
|
108
|
+
operation: operation.operation,
|
|
109
|
+
pool: operation.pool,
|
|
110
|
+
zapper: operation.zapper,
|
|
111
|
+
holder,
|
|
112
|
+
name: sdk.tokensMeta.mustGetToken(operation.pool).name,
|
|
113
|
+
underlyingToken: market.underlyingToken,
|
|
114
|
+
shareRate: pool.dieselRate,
|
|
115
|
+
tokenIn: market.priceOracle.toTokenAmount(tokenIn, sim.amountIn),
|
|
116
|
+
tokenOut: market.priceOracle.toTokenAmount(tokenOut, sim.amountOut),
|
|
117
|
+
curator: market.curator,
|
|
118
|
+
netValue: market.toUnderlyingAmount(pool.sharesToUnderlying(after > 0n ? after : 0n))
|
|
119
|
+
});
|
|
104
120
|
}
|
|
105
121
|
//#endregion
|
|
106
|
-
export {
|
|
122
|
+
export { previewPoolPositionOperation };
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { AssetsMap } from "../../utils/AssetsMap.js";
|
|
2
|
+
import "../../constants/math.js";
|
|
3
|
+
import { AbstractAdapterContract } from "../../market/adapters/contracts/AbstractAdapter.js";
|
|
4
|
+
import { malformedTransaction } from "../../../model/errors/preview-errors.js";
|
|
5
|
+
import "../../../model/index.js";
|
|
6
|
+
//#region src/onchain/preview/preview/replayInnerOperations.ts
|
|
7
|
+
/**
|
|
8
|
+
* Creates a {@link ReplayState} around the given account seed, with empty
|
|
9
|
+
* bookkeeping.
|
|
10
|
+
*/
|
|
11
|
+
function makeReplayState(account) {
|
|
12
|
+
return {
|
|
13
|
+
account,
|
|
14
|
+
collateralAdded: new AssetsMap(),
|
|
15
|
+
collateralWithdrawn: new AssetsMap()
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Replays a credit-facade multicall over `state`, mutating it in place in
|
|
20
|
+
* facade execution order. The result is the *minimal guaranteed* post-state.
|
|
21
|
+
*
|
|
22
|
+
* The function assumes that the call was generated by our frontend using
|
|
23
|
+
* router/withdrawal compressor, otherwise it answers the error on a malformed
|
|
24
|
+
* multicall; state is left as replayed up to that op.
|
|
25
|
+
*
|
|
26
|
+
* @returns `undefined` on success, the error on a malformed multicall.
|
|
27
|
+
*/
|
|
28
|
+
function replayInnerOperations(sdk, multicall, state) {
|
|
29
|
+
let inBracket = false;
|
|
30
|
+
for (const op of multicall) switch (op.operation) {
|
|
31
|
+
case "AddCollateral":
|
|
32
|
+
applyAddCollateral(state, op);
|
|
33
|
+
break;
|
|
34
|
+
case "WithdrawCollateral":
|
|
35
|
+
applyWithdrawCollateral(state, op);
|
|
36
|
+
break;
|
|
37
|
+
case "IncreaseBorrowedAmount":
|
|
38
|
+
state.account.increaseDebt(op.amount);
|
|
39
|
+
break;
|
|
40
|
+
case "DecreaseBorrowedAmount":
|
|
41
|
+
state.account.repay(op.amount);
|
|
42
|
+
break;
|
|
43
|
+
case "UpdateQuota":
|
|
44
|
+
state.account.updateQuota(op.token, op.change);
|
|
45
|
+
break;
|
|
46
|
+
case "StoreExpectedBalances":
|
|
47
|
+
if (inBracket) return malformedTransaction("nested storeExpectedBalances/compareBalances bracket");
|
|
48
|
+
inBracket = true;
|
|
49
|
+
for (const { token, balance } of op.deltas) state.account.balances.inc(token, balance);
|
|
50
|
+
break;
|
|
51
|
+
case "CompareBalances":
|
|
52
|
+
if (!inBracket) return malformedTransaction("compareBalances without a preceding storeExpectedBalances");
|
|
53
|
+
inBracket = false;
|
|
54
|
+
break;
|
|
55
|
+
case "Execute": {
|
|
56
|
+
const error = applyExecute(sdk, op, inBracket, state.account.balances);
|
|
57
|
+
if (error) return error;
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (inBracket) return malformedTransaction("storeExpectedBalances without a matching compareBalances");
|
|
62
|
+
}
|
|
63
|
+
function applyAddCollateral(state, op) {
|
|
64
|
+
state.collateralAdded.inc(op.token, op.amount);
|
|
65
|
+
state.account.balances.inc(op.token, op.amount);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* `MAX_UINT256` is the facade sentinel for "withdraw the entire balance", so
|
|
69
|
+
* it is resolved against the running balance at the point of the call.
|
|
70
|
+
*/
|
|
71
|
+
function applyWithdrawCollateral(state, op) {
|
|
72
|
+
const running = state.account.balances.getOrZero(op.token);
|
|
73
|
+
const amount = op.amount === 115792089237316195423570985008687907853269984665640564039457584007913129639935n ? running > 0n ? running : 0n : op.amount;
|
|
74
|
+
state.account.balances.dec(op.token, amount);
|
|
75
|
+
state.collateralWithdrawn.inc(op.token, amount);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Replays an adapter `Execute` call against the running balances.
|
|
79
|
+
*
|
|
80
|
+
* Inside a bracket, the adapter's balance changes are previewed via
|
|
81
|
+
* {@link AbstractAdapterContract.previewBalanceChanges}. Outside a bracket,
|
|
82
|
+
* only calls that {@link AbstractAdapterContract.replayOutOfBracketCall}
|
|
83
|
+
* accepts are allowed; nothing enforces the outcome of any other out-of-bracket
|
|
84
|
+
* adapter call on-chain, so its effect on balances cannot be previewed.
|
|
85
|
+
*/
|
|
86
|
+
function applyExecute(sdk, op, inBracket, balances) {
|
|
87
|
+
const adapter = sdk.getContract(op.adapter);
|
|
88
|
+
if (!inBracket) {
|
|
89
|
+
if (adapter instanceof AbstractAdapterContract) try {
|
|
90
|
+
if (adapter.replayOutOfBracketCall(balances, op.calldata)) return;
|
|
91
|
+
} catch (e) {
|
|
92
|
+
const cause = e instanceof Error ? e : new Error(String(e));
|
|
93
|
+
return malformedTransaction(`cannot replay out-of-bracket call to ${op.adapter}: ${cause.message}`, cause);
|
|
94
|
+
}
|
|
95
|
+
return malformedTransaction(`call to ${op.adapter} outside of a storeExpectedBalances/compareBalances bracket`);
|
|
96
|
+
}
|
|
97
|
+
if (!(adapter instanceof AbstractAdapterContract)) return malformedTransaction(`call to ${op.adapter} between storeExpectedBalances and compareBalances is not an adapter call`);
|
|
98
|
+
try {
|
|
99
|
+
adapter.previewBalanceChanges(balances, op.calldata);
|
|
100
|
+
return;
|
|
101
|
+
} catch (e) {
|
|
102
|
+
const cause = e instanceof Error ? e : new Error(String(e));
|
|
103
|
+
return malformedTransaction(`cannot replay adapter call to ${op.adapter}: ${cause.message}`, cause);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
//#endregion
|
|
107
|
+
export { makeReplayState, replayInnerOperations };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { sdkErr, sdkOk } from "../../../model/result.js";
|
|
2
|
+
import "../../../model/index.js";
|
|
3
|
+
import { CreditAccountState } from "./CreditAccountState.js";
|
|
4
|
+
import { makeReplayState, replayInnerOperations } from "./replayInnerOperations.js";
|
|
5
|
+
//#region src/onchain/preview/preview/replayMulticall.ts
|
|
6
|
+
/**
|
|
7
|
+
* Replays the operation's multicall over the account's pre-resolved
|
|
8
|
+
* pre-state via {@link replayInnerOperations}.
|
|
9
|
+
*/
|
|
10
|
+
function replayMulticall(sdk, operation, creditAccount) {
|
|
11
|
+
const before = CreditAccountState.fromCreditAccountData(creditAccount);
|
|
12
|
+
const after = makeReplayState(before.clone());
|
|
13
|
+
const error = replayInnerOperations(sdk, operation.multicall, after);
|
|
14
|
+
if (error) return sdkErr(error);
|
|
15
|
+
return sdkOk({
|
|
16
|
+
before,
|
|
17
|
+
after
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { replayMulticall };
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { AssetsMap } from "../../
|
|
2
|
-
import { NATIVE_ADDRESS } from "../../
|
|
3
|
-
import "
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
import { AssetsMap } from "../../utils/AssetsMap.js";
|
|
2
|
+
import { NATIVE_ADDRESS } from "../../constants/addresses.js";
|
|
3
|
+
import { malformedTransaction } from "../../../model/errors/preview-errors.js";
|
|
4
|
+
import { sdkErr, sdkOk } from "../../../model/result.js";
|
|
5
|
+
import "../../../model/index.js";
|
|
6
|
+
//#region src/onchain/preview/preview/unwrapNativeCollateral.ts
|
|
6
7
|
/**
|
|
7
8
|
* Represents the transaction's attached native value as a `NATIVE_ADDRESS`
|
|
8
9
|
* entry in the collateral list.
|
|
@@ -14,26 +15,22 @@ import { invalidTransactionValueError } from "./errors.js";
|
|
|
14
15
|
* reaches zero). Other entries are preserved.
|
|
15
16
|
*
|
|
16
17
|
* When `nativeAmount` is positive but the WETH collateral is missing or
|
|
17
|
-
* smaller than it, the transaction is malformed
|
|
18
|
-
* as-is (no unwrapping) together with an `invalidTransactionValue` warning.
|
|
18
|
+
* smaller than it, the transaction is malformed.
|
|
19
19
|
*
|
|
20
20
|
* @param collateral - Collateral assets as declared by the multicall.
|
|
21
21
|
* @param nativeAmount - Transaction `msg.value`.
|
|
22
22
|
* @param wethToken - Wrapped native token address.
|
|
23
23
|
* @returns Collateral with the native amount unwrapped from the WETH entry,
|
|
24
|
-
*
|
|
24
|
+
* or `malformedTransaction` when `msg.value` does not fit the declared WETH.
|
|
25
25
|
*/
|
|
26
26
|
function unwrapNativeCollateral(collateral, nativeAmount, wethToken) {
|
|
27
|
-
if (nativeAmount === 0n) return
|
|
27
|
+
if (nativeAmount === 0n) return sdkOk(collateral);
|
|
28
28
|
const balances = new AssetsMap(collateral);
|
|
29
29
|
const wethBalance = balances.get(wethToken) ?? 0n;
|
|
30
|
-
if (wethBalance < nativeAmount) return {
|
|
31
|
-
assets: collateral,
|
|
32
|
-
warning: invalidTransactionValueError(nativeAmount, wethBalance)
|
|
33
|
-
};
|
|
30
|
+
if (wethBalance < nativeAmount) return sdkErr(malformedTransaction(`transaction value ${nativeAmount} exceeds WETH collateral ${wethBalance}`));
|
|
34
31
|
balances.upsert(wethToken, wethBalance === nativeAmount ? void 0 : wethBalance - nativeAmount);
|
|
35
32
|
balances.inc(NATIVE_ADDRESS, nativeAmount);
|
|
36
|
-
return
|
|
33
|
+
return sdkOk(balances.toAssets());
|
|
37
34
|
}
|
|
38
35
|
//#endregion
|
|
39
36
|
export { unwrapNativeCollateral };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { errorAbis } from "../../../abi/errors.js";
|
|
2
|
-
import { generateCastTraceCall } from "./cast.js";
|
|
3
2
|
import { iUpdatablePriceFeedAbi } from "../../../abi/iUpdatablePriceFeed.js";
|
|
3
|
+
import { generateCastTraceCall } from "./cast.js";
|
|
4
4
|
import { simulateMulticall } from "./simulateMulticall.js";
|
|
5
5
|
import { BaseError, CallExecutionError, ContractFunctionRevertedError, decodeFunctionData, decodeFunctionResult, encodeFunctionData, parseAbi } from "viem";
|
|
6
6
|
import { getAction, parseAccount } from "viem/utils";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { checkQuotaCount } from "../checks/checkQuotaCount.js";
|
|
2
|
+
import "../checks/index.js";
|
|
3
|
+
//#region src/onchain/validation/bundles/checkAccountQuotas.ts
|
|
4
|
+
/**
|
|
5
|
+
* How many quoted tokens the account would end up holding, against the number
|
|
6
|
+
* the facade enables at once.
|
|
7
|
+
*
|
|
8
|
+
* Reads nothing but the projected account, so a parsed transaction and a
|
|
9
|
+
* simulated one are held to it by the same code — including the reading that a
|
|
10
|
+
* quota the operation zeroed out is no longer held.
|
|
11
|
+
*/
|
|
12
|
+
function checkAccountQuotas(suite, account) {
|
|
13
|
+
return checkQuotaCount({
|
|
14
|
+
count: account.quotas.filter((q) => q.value > 0n).length,
|
|
15
|
+
max: suite.creditManager.maxEnabledTokens
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { checkAccountQuotas };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { AssetsMap } from "../../utils/AssetsMap.js";
|
|
2
|
+
import { AP_WETH_TOKEN } from "../../constants/address-provider.js";
|
|
3
|
+
import { NATIVE_ADDRESS } from "../../constants/addresses.js";
|
|
4
|
+
import "../../constants/index.js";
|
|
5
|
+
import { unexpectedFailure } from "../../../model/errors/prepare-errors.js";
|
|
6
|
+
import "../../../model/index.js";
|
|
7
|
+
import { checkWalletAllowance } from "./checkWalletAllowance.js";
|
|
8
|
+
import { checkWalletBalance } from "./checkWalletBalance.js";
|
|
9
|
+
//#region src/onchain/validation/bundles/checkCollateralFunding.ts
|
|
10
|
+
/**
|
|
11
|
+
* What the wallet must hold and have approved for the collateral the
|
|
12
|
+
* operation adds. Native value is already split out of `collateralAdded` as a
|
|
13
|
+
* `NATIVE_ADDRESS` entry; the facade wraps it into WETH, so the WETH allowance
|
|
14
|
+
* covers both halves.
|
|
15
|
+
*/
|
|
16
|
+
async function checkCollateralFunding(input) {
|
|
17
|
+
const { sdk, preview, sender, blockNumber } = input;
|
|
18
|
+
const held = new AssetsMap(preview.collateralAdded.map((a) => ({
|
|
19
|
+
token: a.token.address,
|
|
20
|
+
balance: a.value
|
|
21
|
+
})));
|
|
22
|
+
if (held.size === 0) return [];
|
|
23
|
+
let spender;
|
|
24
|
+
try {
|
|
25
|
+
if (preview.operation === "OpenCreditAccount" || preview.operation === "RWAOpenCreditAccount") spender = await sdk.accounts.getApprovalAddress({
|
|
26
|
+
creditManager: preview.creditManager,
|
|
27
|
+
borrower: sender
|
|
28
|
+
});
|
|
29
|
+
else spender = await sdk.accounts.getApprovalAddress({
|
|
30
|
+
creditManager: preview.creditManager,
|
|
31
|
+
creditAccount: preview.creditAccount
|
|
32
|
+
});
|
|
33
|
+
} catch (cause) {
|
|
34
|
+
return [unexpectedFailure(cause, "resolve the approval address")];
|
|
35
|
+
}
|
|
36
|
+
const approved = held.clone();
|
|
37
|
+
const native = approved.get("0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE") ?? 0n;
|
|
38
|
+
if (native > 0n) {
|
|
39
|
+
approved.delete(NATIVE_ADDRESS);
|
|
40
|
+
approved.inc(sdk.addressProvider.getAddress(AP_WETH_TOKEN, 0), native);
|
|
41
|
+
}
|
|
42
|
+
return (await Promise.all([...held.entries().map(([token, required]) => checkWalletBalance({
|
|
43
|
+
sdk,
|
|
44
|
+
token,
|
|
45
|
+
holder: sender,
|
|
46
|
+
required,
|
|
47
|
+
blockNumber
|
|
48
|
+
})), ...approved.entries().map(([token, required]) => checkWalletAllowance({
|
|
49
|
+
sdk,
|
|
50
|
+
token,
|
|
51
|
+
owner: sender,
|
|
52
|
+
spender,
|
|
53
|
+
required,
|
|
54
|
+
blockNumber
|
|
55
|
+
}))])).flat();
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
export { checkCollateralFunding };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { toToken } from "../helpers/token.js";
|
|
2
|
+
import "../helpers/index.js";
|
|
3
|
+
import { checkDebtLimits } from "../checks/checkDebtLimits.js";
|
|
4
|
+
import "../checks/index.js";
|
|
5
|
+
import { checkAccountQuotas } from "./checkAccountQuotas.js";
|
|
6
|
+
import { checkCollateralFunding } from "./checkCollateralFunding.js";
|
|
7
|
+
import { checkDraw } from "./checkDraw.js";
|
|
8
|
+
import { checkHealthFactors } from "./checkHealthFactors.js";
|
|
9
|
+
import { checkMarket } from "./checkMarket.js";
|
|
10
|
+
import { checkObtained } from "./checkObtained.js";
|
|
11
|
+
import { checkQuotasAsked } from "./checkQuotasAsked.js";
|
|
12
|
+
import { checkRWAOpening } from "./checkRWAOpening.js";
|
|
13
|
+
//#region src/onchain/validation/bundles/checkCreditOperation.ts
|
|
14
|
+
/**
|
|
15
|
+
* What the protocol stops a credit operation for, then what the wallet still
|
|
16
|
+
* has to hold, approve or sign.
|
|
17
|
+
*
|
|
18
|
+
* The array is in check order, most fundamental first: the market's own state,
|
|
19
|
+
* then what the facade would revert on, then what the operation asks the
|
|
20
|
+
* market for, then the account it leaves behind, and last the wallet's side.
|
|
21
|
+
*/
|
|
22
|
+
async function checkCreditOperation(args) {
|
|
23
|
+
const { sdk, preview, sender, blockNumber, ...thresholds } = args;
|
|
24
|
+
const suite = sdk.marketRegister.findCreditManager(preview.creditManager);
|
|
25
|
+
const market = suite.market;
|
|
26
|
+
const underlying = toToken(sdk, market.pool.underlying);
|
|
27
|
+
const isOpening = preview.operation === "OpenCreditAccount" || preview.operation === "RWAOpenCreditAccount";
|
|
28
|
+
const protocol = [
|
|
29
|
+
...checkMarket(suite),
|
|
30
|
+
...checkDebtLimits({
|
|
31
|
+
debt: preview.totalDebt.value,
|
|
32
|
+
minDebt: suite.creditFacade.minDebt,
|
|
33
|
+
maxDebt: suite.creditFacade.maxDebt,
|
|
34
|
+
underlying,
|
|
35
|
+
allowZero: !isOpening
|
|
36
|
+
}),
|
|
37
|
+
...checkDraw(suite, preview, underlying),
|
|
38
|
+
...checkObtained(suite, preview),
|
|
39
|
+
...checkAccountQuotas(suite, preview),
|
|
40
|
+
...checkQuotasAsked(market, preview, underlying),
|
|
41
|
+
...checkHealthFactors({
|
|
42
|
+
totalDebt: preview.totalDebt,
|
|
43
|
+
healthFactor: preview.estHealthFactor,
|
|
44
|
+
safeHealthFactor: preview.estSafeHealthFactor
|
|
45
|
+
}, thresholds)
|
|
46
|
+
];
|
|
47
|
+
const [funding, rwa] = await Promise.all([checkCollateralFunding({
|
|
48
|
+
sdk,
|
|
49
|
+
preview,
|
|
50
|
+
sender,
|
|
51
|
+
blockNumber
|
|
52
|
+
}), preview.operation === "RWAOpenCreditAccount" ? checkRWAOpening({
|
|
53
|
+
sdk,
|
|
54
|
+
preview,
|
|
55
|
+
sender
|
|
56
|
+
}) : []]);
|
|
57
|
+
return [
|
|
58
|
+
...protocol,
|
|
59
|
+
...funding,
|
|
60
|
+
...rwa
|
|
61
|
+
];
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
export { checkCreditOperation };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { checkBorrowLimit } from "../checks/checkBorrowLimit.js";
|
|
2
|
+
import "../checks/index.js";
|
|
3
|
+
//#region src/onchain/validation/bundles/checkDraw.ts
|
|
4
|
+
/**
|
|
5
|
+
* What the transaction draws, against what the market can lend right now.
|
|
6
|
+
*
|
|
7
|
+
* Only a draw is weighed: repaying, or leaving the debt alone, can never exceed
|
|
8
|
+
* a ceiling. Opening borrows the whole debt; adjusting borrows
|
|
9
|
+
* `totalDebtChange`.
|
|
10
|
+
*
|
|
11
|
+
* The engine holds every simulation to this already (`assertCanBorrow`), so
|
|
12
|
+
* this is here for the transactions it never saw — a pasted calldata reaches
|
|
13
|
+
* the confirm screen with nothing else standing between it and a revert.
|
|
14
|
+
*/
|
|
15
|
+
function checkDraw(suite, preview, underlying) {
|
|
16
|
+
const drawn = preview.operation === "AdjustCreditAccount" ? preview.totalDebtChange.value : preview.totalDebt.value;
|
|
17
|
+
if (drawn <= 0n) return [];
|
|
18
|
+
const { value, limit } = suite.maxBorrowAmount();
|
|
19
|
+
return checkBorrowLimit({
|
|
20
|
+
requested: drawn,
|
|
21
|
+
available: value,
|
|
22
|
+
limit,
|
|
23
|
+
underlying
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
export { checkDraw };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { checkCollateralised } from "../checks/checkCollateralised.js";
|
|
2
|
+
import "../checks/index.js";
|
|
3
|
+
//#region src/onchain/validation/bundles/checkHealthFactors.ts
|
|
4
|
+
/**
|
|
5
|
+
* The account against whichever thresholds the caller holds it to, so a parsed
|
|
6
|
+
* transaction and a simulated one are weighed by the same code.
|
|
7
|
+
*
|
|
8
|
+
* A loan-free account is nothing to weigh: the health factor reports its
|
|
9
|
+
* zero-debt sentinel and no threshold applies.
|
|
10
|
+
*/
|
|
11
|
+
function checkHealthFactors(account, thresholds) {
|
|
12
|
+
const { minHealthFactor, minSafeHealthFactor, currentHealthFactor } = thresholds;
|
|
13
|
+
if (account.totalDebt.value === 0n) return [];
|
|
14
|
+
return [...minHealthFactor === void 0 ? [] : checkCollateralised({
|
|
15
|
+
healthFactor: account.healthFactor,
|
|
16
|
+
healthFactorThreshold: minHealthFactor,
|
|
17
|
+
safePrices: false,
|
|
18
|
+
improvesFrom: currentHealthFactor
|
|
19
|
+
}), ...minSafeHealthFactor === void 0 ? [] : checkCollateralised({
|
|
20
|
+
healthFactor: account.safeHealthFactor,
|
|
21
|
+
healthFactorThreshold: minSafeHealthFactor,
|
|
22
|
+
safePrices: true
|
|
23
|
+
})];
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { checkHealthFactors };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { checkCreditAccountFrozen } from "../checks/checkCreditAccountFrozen.js";
|
|
2
|
+
import { checkEmergencyLiquidator } from "../checks/checkEmergencyLiquidator.js";
|
|
3
|
+
import { checkLiquidatorEligible } from "../checks/checkLiquidatorEligible.js";
|
|
4
|
+
import "../checks/index.js";
|
|
5
|
+
//#region src/onchain/validation/bundles/checkLiquidationEligibility.ts
|
|
6
|
+
/**
|
|
7
|
+
* Whether this wallet may liquidate this account, from the facts the
|
|
8
|
+
* compressor already reported and the market's emergency-liquidator list.
|
|
9
|
+
*/
|
|
10
|
+
function checkLiquidationEligibility(input) {
|
|
11
|
+
const { sdk, details, liquidator } = input;
|
|
12
|
+
const market = sdk.marketRegister.findByCreditManager(details.creditManager);
|
|
13
|
+
return [
|
|
14
|
+
...checkCreditAccountFrozen({
|
|
15
|
+
frozen: details.isCreditAccountFrozen,
|
|
16
|
+
creditAccount: details.creditAccount
|
|
17
|
+
}),
|
|
18
|
+
...checkEmergencyLiquidator({
|
|
19
|
+
paused: details.paused,
|
|
20
|
+
isEmergencyLiquidator: market.isEmergencyLiquidator(liquidator),
|
|
21
|
+
creditManager: details.creditManager,
|
|
22
|
+
liquidator
|
|
23
|
+
}),
|
|
24
|
+
...checkLiquidatorEligible({
|
|
25
|
+
eligible: details.isLiquidatorEligible,
|
|
26
|
+
kycProtocol: details.kycProtocol,
|
|
27
|
+
kycToken: details.kycToken
|
|
28
|
+
})
|
|
29
|
+
];
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { checkLiquidationEligibility };
|