@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
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { checkWalletAllowance } from "./checkWalletAllowance.js";
|
|
2
|
+
import { checkWalletBalance } from "./checkWalletBalance.js";
|
|
3
|
+
//#region src/onchain/validation/bundles/checkLiquidationFunding.ts
|
|
4
|
+
/**
|
|
5
|
+
* What the liquidator wallet must hold and have approved.
|
|
6
|
+
*/
|
|
7
|
+
async function checkLiquidationFunding(input) {
|
|
8
|
+
const { sdk, details, liquidator, blockNumber } = input;
|
|
9
|
+
const reads = [];
|
|
10
|
+
if (details.repaymentAmount.value > 0n) reads.push(checkWalletBalance({
|
|
11
|
+
sdk,
|
|
12
|
+
token: details.repaymentAmount.token.address,
|
|
13
|
+
holder: liquidator,
|
|
14
|
+
required: details.repaymentAmount.value,
|
|
15
|
+
blockNumber
|
|
16
|
+
}));
|
|
17
|
+
if (details.approve) reads.push(checkWalletAllowance({
|
|
18
|
+
sdk,
|
|
19
|
+
token: details.approve.token.address,
|
|
20
|
+
owner: liquidator,
|
|
21
|
+
spender: details.approve.spender,
|
|
22
|
+
required: details.approve.value,
|
|
23
|
+
blockNumber
|
|
24
|
+
}));
|
|
25
|
+
return (await Promise.all(reads)).flat();
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { checkLiquidationFunding };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { checkCreditManagerPaused } from "../checks/checkCreditManagerPaused.js";
|
|
2
|
+
import { checkMarketExpired } from "../checks/checkMarketExpired.js";
|
|
3
|
+
import "../checks/index.js";
|
|
4
|
+
//#region src/onchain/validation/bundles/checkMarket.ts
|
|
5
|
+
/**
|
|
6
|
+
* What the market itself stops, whatever the operation does.
|
|
7
|
+
*
|
|
8
|
+
* Neither state is anything the sender can fix, which is why it comes first
|
|
9
|
+
* wherever it is composed in.
|
|
10
|
+
*/
|
|
11
|
+
function checkMarket(suite) {
|
|
12
|
+
const creditManager = suite.creditManager.address;
|
|
13
|
+
return [...checkCreditManagerPaused({
|
|
14
|
+
isPaused: suite.isPaused,
|
|
15
|
+
creditManager
|
|
16
|
+
}), ...checkMarketExpired({
|
|
17
|
+
isExpired: suite.isExpired,
|
|
18
|
+
creditManager,
|
|
19
|
+
expirationDate: suite.creditFacade.expirationDate
|
|
20
|
+
})];
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { checkMarket };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { checkForbiddenToken } from "../checks/checkForbiddenToken.js";
|
|
2
|
+
import "../checks/index.js";
|
|
3
|
+
//#region src/onchain/validation/bundles/checkObtained.ts
|
|
4
|
+
/** Every token the operation buys more of, against what the market forbids. */
|
|
5
|
+
function checkObtained(suite, preview) {
|
|
6
|
+
return (preview.operation === "AdjustCreditAccount" ? preview.assetsChange : preview.estAssets).filter((asset) => asset.value > 0n).flatMap((asset) => checkForbiddenToken({
|
|
7
|
+
token: asset.token,
|
|
8
|
+
isForbidden: suite.isForbidden(asset.token.address)
|
|
9
|
+
}));
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { checkObtained };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { checkWallet } from "./checkWallet.js";
|
|
2
|
+
//#region src/onchain/validation/bundles/checkPoolFunding.ts
|
|
3
|
+
/**
|
|
4
|
+
* What the wallet must hold (and approve) for a pool deposit, mint, withdraw
|
|
5
|
+
* or redeem, read off the preview's `tokenIn`, `zapper` and `holder`.
|
|
6
|
+
*/
|
|
7
|
+
async function checkPoolFunding(input) {
|
|
8
|
+
const { sdk, preview, sender, blockNumber } = input;
|
|
9
|
+
const { tokenIn: { token: { address: token }, value: required }, pool, zapper, holder } = preview;
|
|
10
|
+
const isDeposit = preview.operation === "Deposit" || preview.operation === "Mint";
|
|
11
|
+
return checkWallet({
|
|
12
|
+
sdk,
|
|
13
|
+
token,
|
|
14
|
+
required,
|
|
15
|
+
blockNumber,
|
|
16
|
+
holder: isDeposit || zapper ? sender : holder,
|
|
17
|
+
spender: zapper ?? (isDeposit ? pool : sender)
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { checkPoolFunding };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { checkPoolLiquidity } from "../checks/checkPoolLiquidity.js";
|
|
2
|
+
import { checkPoolPaused } from "../checks/checkPoolPaused.js";
|
|
3
|
+
import { checkPoolSunset } from "../checks/checkPoolSunset.js";
|
|
4
|
+
import "../checks/index.js";
|
|
5
|
+
//#region src/onchain/validation/bundles/checkPoolOperation.ts
|
|
6
|
+
/**
|
|
7
|
+
* What the pool's own state stops, whichever side of it the wallet is on.
|
|
8
|
+
*
|
|
9
|
+
* The liquidity read is the market's rather than the trimmed figure a
|
|
10
|
+
* simulation carries: a withdrawal sized against that figure has to pass the
|
|
11
|
+
* check that follows it.
|
|
12
|
+
*/
|
|
13
|
+
function checkPoolOperation(args) {
|
|
14
|
+
const { sdk, pool, isDeposit, tokenOut } = args;
|
|
15
|
+
const market = sdk.marketRegister.findByPool(pool);
|
|
16
|
+
return [
|
|
17
|
+
...checkPoolPaused({
|
|
18
|
+
isPaused: market.pool.pool.isPaused,
|
|
19
|
+
pool
|
|
20
|
+
}),
|
|
21
|
+
...checkPoolSunset({
|
|
22
|
+
isSunset: market.sunset,
|
|
23
|
+
isDeposit,
|
|
24
|
+
pool
|
|
25
|
+
}),
|
|
26
|
+
...isDeposit ? [] : checkPoolLiquidity({
|
|
27
|
+
requested: tokenOut.value,
|
|
28
|
+
available: market.pool.pool.availableLiquidity,
|
|
29
|
+
underlying: tokenOut.token
|
|
30
|
+
})
|
|
31
|
+
];
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
export { checkPoolOperation };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { checkQuotaLimit } from "../checks/checkQuotaLimit.js";
|
|
2
|
+
import "../checks/index.js";
|
|
3
|
+
//#region src/onchain/validation/bundles/checkQuotasAsked.ts
|
|
4
|
+
/** Every quota the operation raises, against the room the keeper has left. */
|
|
5
|
+
function checkQuotasAsked(market, preview, underlying) {
|
|
6
|
+
const increases = preview.operation === "AdjustCreditAccount" ? preview.quotasChange : preview.quotas;
|
|
7
|
+
const { pqk } = market.pool;
|
|
8
|
+
return increases.filter((q) => q.value > 0n).flatMap((q) => {
|
|
9
|
+
const quoted = pqk.hasActiveQuota(q.token.address);
|
|
10
|
+
return checkQuotaLimit({
|
|
11
|
+
token: q.token,
|
|
12
|
+
requested: quoted ? q.value : void 0,
|
|
13
|
+
available: quoted ? pqk.quotaAvailable(q.token.address) : 0n,
|
|
14
|
+
underlying
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { checkQuotasAsked };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { rwaOpenRequirementsNotMet } from "../../../model/errors/operation-errors.js";
|
|
2
|
+
import { unexpectedFailure } from "../../../model/errors/prepare-errors.js";
|
|
3
|
+
import "../../../model/index.js";
|
|
4
|
+
import { toToken } from "../helpers/token.js";
|
|
5
|
+
import "../helpers/index.js";
|
|
6
|
+
//#region src/onchain/validation/bundles/checkRWAOpenRequirements.ts
|
|
7
|
+
/**
|
|
8
|
+
* The RWA factory is satisfied that `wallet` may open on `token` with the
|
|
9
|
+
* registration args already on the transaction.
|
|
10
|
+
*/
|
|
11
|
+
async function checkRWAOpenRequirements(input) {
|
|
12
|
+
const { sdk, wallet, creditManager, token, providedArgs } = input;
|
|
13
|
+
try {
|
|
14
|
+
const requirements = await sdk.accounts.getOpenAccountRequirements(wallet, creditManager, { tokenOutAddress: token });
|
|
15
|
+
if (!requirements) return [];
|
|
16
|
+
const { rwaFactory } = sdk.marketRegister.findByCreditManager(creditManager);
|
|
17
|
+
if (!rwaFactory) throw new Error(`no RWA factory for credit manager ${creditManager}`);
|
|
18
|
+
const missing = rwaFactory.getMissingRequirements(requirements, providedArgs);
|
|
19
|
+
if (!missing && requirements.securitizeTokensToRegister.length === 0) return [];
|
|
20
|
+
return [rwaOpenRequirementsNotMet({
|
|
21
|
+
token: toToken(sdk, token),
|
|
22
|
+
creditManager,
|
|
23
|
+
factory: rwaFactory.address,
|
|
24
|
+
requirements,
|
|
25
|
+
...missing === void 0 ? {} : { missing }
|
|
26
|
+
})];
|
|
27
|
+
} catch (cause) {
|
|
28
|
+
return [unexpectedFailure(cause, "read the RWA opening requirements")];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { checkRWAOpenRequirements };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AddressSet } from "../../utils/AddressSet.js";
|
|
2
|
+
import { checkRWAOpenRequirements } from "./checkRWAOpenRequirements.js";
|
|
3
|
+
//#region src/onchain/validation/bundles/checkRWAOpening.ts
|
|
4
|
+
/**
|
|
5
|
+
* Per factory-gated token among `collateralAdded ∪ quotas`, whether the
|
|
6
|
+
* borrower still has to register or sign before this opening can land.
|
|
7
|
+
*/
|
|
8
|
+
async function checkRWAOpening(input) {
|
|
9
|
+
const { sdk, preview, sender } = input;
|
|
10
|
+
const { rwaFactory } = sdk.marketRegister.findByCreditManager(preview.creditManager);
|
|
11
|
+
if (!rwaFactory) return [];
|
|
12
|
+
const gated = new AddressSet(rwaFactory.getTokens());
|
|
13
|
+
const candidates = new AddressSet([...preview.collateralAdded.map((a) => a.token.address), ...preview.quotas.map((q) => q.token.address)]);
|
|
14
|
+
return (await Promise.all([...candidates].filter((token) => gated.has(token)).map((token) => checkRWAOpenRequirements({
|
|
15
|
+
sdk,
|
|
16
|
+
wallet: sender,
|
|
17
|
+
creditManager: preview.creditManager,
|
|
18
|
+
token,
|
|
19
|
+
providedArgs: preview.rwaArgs
|
|
20
|
+
})))).flat();
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { checkRWAOpening };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import "../../constants/addresses.js";
|
|
2
|
+
import "../../constants/index.js";
|
|
3
|
+
import { checkWalletAllowance } from "./checkWalletAllowance.js";
|
|
4
|
+
import { checkWalletBalance } from "./checkWalletBalance.js";
|
|
5
|
+
import { isAddressEqual } from "viem";
|
|
6
|
+
//#region src/onchain/validation/bundles/checkWallet.ts
|
|
7
|
+
/**
|
|
8
|
+
* The wallet's whole side for one token: always the balance; the allowance
|
|
9
|
+
* only when it can matter (an ERC-20, with a spender who is not the holder).
|
|
10
|
+
*/
|
|
11
|
+
async function checkWallet(input) {
|
|
12
|
+
const { spender, ...rest } = input;
|
|
13
|
+
const needsAllowance = spender !== void 0 && !isAddressEqual(rest.token, "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE") && !isAddressEqual(spender, rest.holder);
|
|
14
|
+
return (await Promise.all([checkWalletBalance(rest), needsAllowance ? checkWalletAllowance({
|
|
15
|
+
...rest,
|
|
16
|
+
owner: rest.holder,
|
|
17
|
+
spender
|
|
18
|
+
}) : []])).flat();
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { checkWallet };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ierc20Abi } from "../../../abi/iERC20.js";
|
|
2
|
+
import { insufficientAllowance } from "../../../model/errors/operation-errors.js";
|
|
3
|
+
import { unexpectedFailure } from "../../../model/errors/prepare-errors.js";
|
|
4
|
+
import "../../../model/index.js";
|
|
5
|
+
import { toToken, toTokenAmount } from "../helpers/token.js";
|
|
6
|
+
import "../helpers/index.js";
|
|
7
|
+
//#region src/onchain/validation/bundles/checkWalletAllowance.ts
|
|
8
|
+
/** `owner` has approved `spender` for at least `required` of `token`. */
|
|
9
|
+
async function checkWalletAllowance(input) {
|
|
10
|
+
const { sdk, token, owner, spender, required, blockNumber } = input;
|
|
11
|
+
try {
|
|
12
|
+
const allowed = await sdk.client.readContract({
|
|
13
|
+
address: token,
|
|
14
|
+
abi: ierc20Abi,
|
|
15
|
+
functionName: "allowance",
|
|
16
|
+
args: [owner, spender],
|
|
17
|
+
blockNumber
|
|
18
|
+
});
|
|
19
|
+
return allowed >= required ? [] : [insufficientAllowance({
|
|
20
|
+
owner,
|
|
21
|
+
spender,
|
|
22
|
+
required: toTokenAmount(sdk, token, required),
|
|
23
|
+
allowed: toTokenAmount(sdk, token, allowed)
|
|
24
|
+
})];
|
|
25
|
+
} catch (cause) {
|
|
26
|
+
const { symbol } = toToken(sdk, token);
|
|
27
|
+
return [unexpectedFailure(cause, `read the ${symbol} allowance`)];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { checkWalletAllowance };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ierc20Abi } from "../../../abi/iERC20.js";
|
|
2
|
+
import "../../constants/addresses.js";
|
|
3
|
+
import "../../constants/index.js";
|
|
4
|
+
import { insufficientBalance } from "../../../model/errors/operation-errors.js";
|
|
5
|
+
import { unexpectedFailure } from "../../../model/errors/prepare-errors.js";
|
|
6
|
+
import "../../../model/index.js";
|
|
7
|
+
import { amountOf } from "../helpers/amount.js";
|
|
8
|
+
import { toToken } from "../helpers/token.js";
|
|
9
|
+
import "../helpers/index.js";
|
|
10
|
+
import { isAddressEqual } from "viem";
|
|
11
|
+
//#region src/onchain/validation/bundles/checkWalletBalance.ts
|
|
12
|
+
/** `holder` holds at least `required` of `token` (ERC-20 or native). */
|
|
13
|
+
async function checkWalletBalance(input) {
|
|
14
|
+
const { sdk, token, holder, required, blockNumber } = input;
|
|
15
|
+
try {
|
|
16
|
+
const held = isAddressEqual(token, "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE") ? await sdk.client.getBalance({
|
|
17
|
+
address: holder,
|
|
18
|
+
blockNumber
|
|
19
|
+
}) : await sdk.client.readContract({
|
|
20
|
+
address: token,
|
|
21
|
+
abi: ierc20Abi,
|
|
22
|
+
functionName: "balanceOf",
|
|
23
|
+
args: [holder],
|
|
24
|
+
blockNumber
|
|
25
|
+
});
|
|
26
|
+
if (required <= held) return [];
|
|
27
|
+
const meta = toToken(sdk, token);
|
|
28
|
+
return [insufficientBalance({
|
|
29
|
+
required: amountOf(meta, required),
|
|
30
|
+
held: amountOf(meta, held),
|
|
31
|
+
holderKind: "wallet",
|
|
32
|
+
holder
|
|
33
|
+
})];
|
|
34
|
+
} catch (cause) {
|
|
35
|
+
const { symbol } = toToken(sdk, token);
|
|
36
|
+
return [unexpectedFailure(cause, `read the ${symbol} balance`)];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
export { checkWalletBalance };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { checkAccountQuotas } from "./checkAccountQuotas.js";
|
|
2
|
+
import { checkWalletAllowance } from "./checkWalletAllowance.js";
|
|
3
|
+
import { checkWalletBalance } from "./checkWalletBalance.js";
|
|
4
|
+
import { checkCollateralFunding } from "./checkCollateralFunding.js";
|
|
5
|
+
import { checkDraw } from "./checkDraw.js";
|
|
6
|
+
import { checkHealthFactors } from "./checkHealthFactors.js";
|
|
7
|
+
import { checkMarket } from "./checkMarket.js";
|
|
8
|
+
import { checkObtained } from "./checkObtained.js";
|
|
9
|
+
import { checkQuotasAsked } from "./checkQuotasAsked.js";
|
|
10
|
+
import { checkRWAOpenRequirements } from "./checkRWAOpenRequirements.js";
|
|
11
|
+
import { checkRWAOpening } from "./checkRWAOpening.js";
|
|
12
|
+
import { checkCreditOperation } from "./checkCreditOperation.js";
|
|
13
|
+
import { checkLiquidationEligibility } from "./checkLiquidationEligibility.js";
|
|
14
|
+
import { checkLiquidationFunding } from "./checkLiquidationFunding.js";
|
|
15
|
+
import { checkWallet } from "./checkWallet.js";
|
|
16
|
+
import { checkPoolFunding } from "./checkPoolFunding.js";
|
|
17
|
+
import { checkPoolOperation } from "./checkPoolOperation.js";
|
|
18
|
+
export { checkAccountQuotas, checkCollateralFunding, checkCreditOperation, checkDraw, checkHealthFactors, checkLiquidationEligibility, checkLiquidationFunding, checkMarket, checkObtained, checkPoolFunding, checkPoolOperation, checkQuotasAsked, checkRWAOpenRequirements, checkRWAOpening, checkWallet, checkWalletAllowance, checkWalletBalance };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { checkLiquidationEligibility } from "./bundles/checkLiquidationEligibility.js";
|
|
2
|
+
import { checkLiquidationFunding } from "./bundles/checkLiquidationFunding.js";
|
|
3
|
+
//#region src/onchain/validation/checkLiquidation.ts
|
|
4
|
+
/**
|
|
5
|
+
* Whether `liquidator` may send a full liquidation of this account
|
|
6
|
+
*/
|
|
7
|
+
async function checkLiquidation(sdk, input, options = {}) {
|
|
8
|
+
const { details, liquidator } = input;
|
|
9
|
+
return [...checkLiquidationEligibility({
|
|
10
|
+
sdk,
|
|
11
|
+
details,
|
|
12
|
+
liquidator
|
|
13
|
+
}), ...await checkLiquidationFunding({
|
|
14
|
+
sdk,
|
|
15
|
+
details,
|
|
16
|
+
liquidator,
|
|
17
|
+
blockNumber: options.blockNumber
|
|
18
|
+
})];
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { checkLiquidation };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { checkCollateralFunding } from "./bundles/checkCollateralFunding.js";
|
|
2
|
+
import { checkMarket } from "./bundles/checkMarket.js";
|
|
3
|
+
import { checkCreditOperation } from "./bundles/checkCreditOperation.js";
|
|
4
|
+
import { checkPoolFunding } from "./bundles/checkPoolFunding.js";
|
|
5
|
+
import { checkPoolOperation } from "./bundles/checkPoolOperation.js";
|
|
6
|
+
//#region src/onchain/validation/checkOperation.ts
|
|
7
|
+
/**
|
|
8
|
+
* Whether a parsed operation may be signed by `sender`: protocol state first,
|
|
9
|
+
* then what the wallet has to approve, hold or sign.
|
|
10
|
+
*
|
|
11
|
+
* The array is in check order, most fundamental first, so a caller with room
|
|
12
|
+
* for one verdict reports the first entry. Approve and sign errors are picked
|
|
13
|
+
* out by `code`, not by position.
|
|
14
|
+
*/
|
|
15
|
+
async function checkOperation(input, options = {}) {
|
|
16
|
+
const { sdk, preview, sender } = input;
|
|
17
|
+
const { blockNumber, ...thresholds } = options;
|
|
18
|
+
const wallet = {
|
|
19
|
+
sdk,
|
|
20
|
+
sender,
|
|
21
|
+
blockNumber
|
|
22
|
+
};
|
|
23
|
+
switch (preview.operation) {
|
|
24
|
+
case "Deposit":
|
|
25
|
+
case "Mint":
|
|
26
|
+
case "Withdraw":
|
|
27
|
+
case "Redeem": {
|
|
28
|
+
const isDeposit = preview.operation === "Deposit" || preview.operation === "Mint";
|
|
29
|
+
return [...checkPoolOperation({
|
|
30
|
+
sdk,
|
|
31
|
+
pool: preview.pool,
|
|
32
|
+
isDeposit,
|
|
33
|
+
tokenOut: preview.tokenOut
|
|
34
|
+
}), ...await checkPoolFunding({
|
|
35
|
+
...wallet,
|
|
36
|
+
preview
|
|
37
|
+
})];
|
|
38
|
+
}
|
|
39
|
+
case "DelayedCreditAccountOperation": return checkOperation({
|
|
40
|
+
sdk,
|
|
41
|
+
preview: preview.instantPreview,
|
|
42
|
+
sender
|
|
43
|
+
}, options);
|
|
44
|
+
case "OpenCreditAccount":
|
|
45
|
+
case "RWAOpenCreditAccount":
|
|
46
|
+
case "AdjustCreditAccount": return checkCreditOperation({
|
|
47
|
+
sdk,
|
|
48
|
+
preview,
|
|
49
|
+
sender,
|
|
50
|
+
blockNumber,
|
|
51
|
+
...thresholds
|
|
52
|
+
});
|
|
53
|
+
case "RepayCreditAccount": return [...checkMarket(sdk.marketRegister.findCreditManager(preview.creditManager)), ...await checkCollateralFunding({
|
|
54
|
+
...wallet,
|
|
55
|
+
preview
|
|
56
|
+
})];
|
|
57
|
+
case "CloseCreditAccount": return checkMarket(sdk.marketRegister.findCreditManager(preview.creditManager));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
export { checkOperation };
|
|
@@ -0,0 +1,59 @@
|
|
|
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 "./bundles/checkAccountQuotas.js";
|
|
6
|
+
import { checkHealthFactors } from "./bundles/checkHealthFactors.js";
|
|
7
|
+
import { checkMarket } from "./bundles/checkMarket.js";
|
|
8
|
+
import { checkPoolOperation } from "./bundles/checkPoolOperation.js";
|
|
9
|
+
//#region src/onchain/validation/checkSimulation.ts
|
|
10
|
+
/**
|
|
11
|
+
* Whether a simulated operation clears the caller's own thresholds.
|
|
12
|
+
*
|
|
13
|
+
* The engine holds an account to the facade's `1.0`, because its guards answer
|
|
14
|
+
* "would this revert". A form is wiser to ask for more, and the engine's own
|
|
15
|
+
* note says so — a caller wanting the stricter threshold applies it itself.
|
|
16
|
+
* This is that second opinion, over the numbers the engine already reported.
|
|
17
|
+
*
|
|
18
|
+
* Three of the checks on a credit account the engine does not make at all:
|
|
19
|
+
* both health-factor thresholds are its own `1.0`, and the quota count it never
|
|
20
|
+
* weighs. The other two run against the same numbers the engine used, and are
|
|
21
|
+
* here so that a change in the engine cannot pass silently.
|
|
22
|
+
*
|
|
23
|
+
* What is deliberately absent: the forbidden-token, quota-limit and funding
|
|
24
|
+
* checks all need the *delta* an operation applies, and `OperationState` reports
|
|
25
|
+
* only the state after it. Weighing them against absolutes would stop a
|
|
26
|
+
* forbidden token the account merely holds, or a quota the operation never
|
|
27
|
+
* touched. The engine performed all three during the walk, so a simulation that
|
|
28
|
+
* came back `ok` has already passed them.
|
|
29
|
+
*
|
|
30
|
+
* A pool operation has no account to weigh, so what is left is the pool's own
|
|
31
|
+
* state — which the engine does not read either.
|
|
32
|
+
*/
|
|
33
|
+
function checkSimulation(sdk, input, options = {}) {
|
|
34
|
+
if ("pool" in input) {
|
|
35
|
+
const { pool, state, isDeposit } = input;
|
|
36
|
+
return checkPoolOperation({
|
|
37
|
+
sdk,
|
|
38
|
+
pool,
|
|
39
|
+
isDeposit,
|
|
40
|
+
tokenOut: state.tokenOut
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
const { state } = input;
|
|
44
|
+
const suite = sdk.marketRegister.findCreditManager(state.creditManager);
|
|
45
|
+
return [
|
|
46
|
+
...checkMarket(suite),
|
|
47
|
+
...checkDebtLimits({
|
|
48
|
+
debt: state.totalDebt.value,
|
|
49
|
+
minDebt: suite.creditFacade.minDebt,
|
|
50
|
+
maxDebt: suite.creditFacade.maxDebt,
|
|
51
|
+
underlying: toToken(sdk, suite.market.pool.underlying),
|
|
52
|
+
allowZero: true
|
|
53
|
+
}),
|
|
54
|
+
...checkAccountQuotas(suite, state),
|
|
55
|
+
...checkHealthFactors(state, options)
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
export { checkSimulation };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { insufficientPoolLiquidity } from "../../../model/errors/operation-errors.js";
|
|
2
|
+
import "../../../model/index.js";
|
|
3
|
+
import { amountOf } from "../helpers/amount.js";
|
|
4
|
+
import "../helpers/index.js";
|
|
5
|
+
//#region src/onchain/validation/checks/checkBorrowLimit.ts
|
|
6
|
+
/**
|
|
7
|
+
* What the pool will hand over, against what is asked for.
|
|
8
|
+
*
|
|
9
|
+
* `available` and `limit` are the caller's reading of which limit is in the
|
|
10
|
+
* way; this check only compares. `maxBorrowAmount` is the largest debt still
|
|
11
|
+
* takeable, left out when none is.
|
|
12
|
+
*/
|
|
13
|
+
function checkBorrowLimit(args) {
|
|
14
|
+
const { requested, available, limit, underlying, maxBorrowAmount } = args;
|
|
15
|
+
if (requested <= available) return [];
|
|
16
|
+
return [insufficientPoolLiquidity({
|
|
17
|
+
requested: amountOf(underlying, requested),
|
|
18
|
+
available: amountOf(underlying, available),
|
|
19
|
+
limit,
|
|
20
|
+
...maxBorrowAmount === void 0 ? {} : { maxBorrowAmount: amountOf(underlying, maxBorrowAmount) }
|
|
21
|
+
})];
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { checkBorrowLimit };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { insufficientCollateral } from "../../../model/errors/operation-errors.js";
|
|
2
|
+
import "../../../model/index.js";
|
|
3
|
+
//#region src/onchain/validation/checks/checkCollateralised.ts
|
|
4
|
+
/**
|
|
5
|
+
* The account against its debt, at whichever threshold the caller holds it to.
|
|
6
|
+
*
|
|
7
|
+
* An unread factor counts as failing: a check that cannot see the number is
|
|
8
|
+
* not evidence that the number is fine.
|
|
9
|
+
*/
|
|
10
|
+
function checkCollateralised(args) {
|
|
11
|
+
const { healthFactor, healthFactorThreshold, safePrices, improvesFrom } = args;
|
|
12
|
+
if (healthFactor === void 0) return [insufficientCollateral({
|
|
13
|
+
healthFactor: 0,
|
|
14
|
+
healthFactorThreshold,
|
|
15
|
+
safePrices
|
|
16
|
+
})];
|
|
17
|
+
if (healthFactor >= healthFactorThreshold || improvesFrom !== void 0 && healthFactor > improvesFrom) return [];
|
|
18
|
+
return [insufficientCollateral({
|
|
19
|
+
healthFactor,
|
|
20
|
+
healthFactorThreshold,
|
|
21
|
+
safePrices
|
|
22
|
+
})];
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { checkCollateralised };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { creditAccountFrozen } from "../../../model/errors/liquidation-errors.js";
|
|
2
|
+
import "../../../model/index.js";
|
|
3
|
+
//#region src/onchain/validation/checks/checkCreditAccountFrozen.ts
|
|
4
|
+
/** An RWA factory freeze stops the account's collateral from moving. */
|
|
5
|
+
function checkCreditAccountFrozen(args) {
|
|
6
|
+
return args.frozen ? [creditAccountFrozen(args.creditAccount)] : [];
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { checkCreditAccountFrozen };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { creditManagerPaused } from "../../../model/errors/operation-errors.js";
|
|
2
|
+
import "../../../model/index.js";
|
|
3
|
+
//#region src/onchain/validation/checks/checkCreditManagerPaused.ts
|
|
4
|
+
/** The credit manager takes no multicall while it is paused. */
|
|
5
|
+
function checkCreditManagerPaused(args) {
|
|
6
|
+
return args.isPaused ? [creditManagerPaused(args.creditManager)] : [];
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { checkCreditManagerPaused };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { debtOutOfRange } from "../../../model/errors/operation-errors.js";
|
|
2
|
+
import "../../../model/index.js";
|
|
3
|
+
import { amountOf } from "../helpers/amount.js";
|
|
4
|
+
import "../helpers/index.js";
|
|
5
|
+
//#region src/onchain/validation/checks/checkDebtLimits.ts
|
|
6
|
+
/** A debt the facade would revert on. */
|
|
7
|
+
function checkDebtLimits(args) {
|
|
8
|
+
const { debt, minDebt, maxDebt, underlying, allowZero } = args;
|
|
9
|
+
if (!(debt > maxDebt || debt < minDebt && !(allowZero && debt === 0n))) return [];
|
|
10
|
+
return [debtOutOfRange({
|
|
11
|
+
requested: amountOf(underlying, debt),
|
|
12
|
+
minDebt: amountOf(underlying, minDebt),
|
|
13
|
+
maxDebt: amountOf(underlying, maxDebt)
|
|
14
|
+
})];
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { checkDebtLimits };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { notEmergencyLiquidator } from "../../../model/errors/liquidation-errors.js";
|
|
2
|
+
import "../../../model/index.js";
|
|
3
|
+
//#region src/onchain/validation/checks/checkEmergencyLiquidator.ts
|
|
4
|
+
/**
|
|
5
|
+
* A paused market only accepts liquidations from its emergency liquidators.
|
|
6
|
+
* An unpaused market does not consult the list.
|
|
7
|
+
*/
|
|
8
|
+
function checkEmergencyLiquidator(args) {
|
|
9
|
+
return args.paused && !args.isEmergencyLiquidator ? [notEmergencyLiquidator(args.creditManager, args.liquidator)] : [];
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { checkEmergencyLiquidator };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { forbiddenToken } from "../../../model/errors/operation-errors.js";
|
|
2
|
+
import "../../../model/index.js";
|
|
3
|
+
//#region src/onchain/validation/checks/checkForbiddenToken.ts
|
|
4
|
+
/** A token the market will not let the account hold more of. */
|
|
5
|
+
function checkForbiddenToken(args) {
|
|
6
|
+
return args.isForbidden ? [forbiddenToken(args.token)] : [];
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { checkForbiddenToken };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { leverageOutOfRange } from "../../../model/errors/operation-errors.js";
|
|
2
|
+
import "../../../model/index.js";
|
|
3
|
+
//#region src/onchain/validation/checks/checkLeverage.ts
|
|
4
|
+
/** Leverage below 1x is not a position, it is a withdrawal. */
|
|
5
|
+
function checkLeverage(args) {
|
|
6
|
+
return args.leverage < args.min ? [leverageOutOfRange({
|
|
7
|
+
requested: args.leverage,
|
|
8
|
+
min: args.min
|
|
9
|
+
})] : [];
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { checkLeverage };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { liquidatorNotEligible } from "../../../model/errors/liquidation-errors.js";
|
|
2
|
+
import "../../../model/index.js";
|
|
3
|
+
//#region src/onchain/validation/checks/checkLiquidatorEligible.ts
|
|
4
|
+
/** The compressor's KYC check of this wallet against the liquidated assets. */
|
|
5
|
+
function checkLiquidatorEligible(args) {
|
|
6
|
+
return args.eligible ? [] : [liquidatorNotEligible(args.kycProtocol, args.kycToken)];
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { checkLiquidatorEligible };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { marketExpired } from "../../../model/errors/operation-errors.js";
|
|
2
|
+
import "../../../model/index.js";
|
|
3
|
+
//#region src/onchain/validation/checks/checkMarketExpired.ts
|
|
4
|
+
/** Past its expiration date the facade takes no more multicalls. */
|
|
5
|
+
function checkMarketExpired(args) {
|
|
6
|
+
return args.isExpired ? [marketExpired(args.creditManager, args.expirationDate)] : [];
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { checkMarketExpired };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { insufficientPoolLiquidity } from "../../../model/errors/operation-errors.js";
|
|
2
|
+
import "../../../model/index.js";
|
|
3
|
+
import { amountOf } from "../helpers/amount.js";
|
|
4
|
+
import "../helpers/index.js";
|
|
5
|
+
//#region src/onchain/validation/checks/checkPoolLiquidity.ts
|
|
6
|
+
/**
|
|
7
|
+
* What the pool holds, against what is being taken out of it.
|
|
8
|
+
*
|
|
9
|
+
* The operator is not `checkBorrowLimit`'s: a pool holding exactly the amount
|
|
10
|
+
* asked for still cannot serve it, so equality is already a refusal. That is
|
|
11
|
+
* the rule the legacy withdrawal validator enforced and it is preserved to the
|
|
12
|
+
* unit.
|
|
13
|
+
*/
|
|
14
|
+
function checkPoolLiquidity(args) {
|
|
15
|
+
const { requested, available, underlying } = args;
|
|
16
|
+
if (requested < available) return [];
|
|
17
|
+
return [insufficientPoolLiquidity({
|
|
18
|
+
requested: amountOf(underlying, requested),
|
|
19
|
+
available: amountOf(underlying, available),
|
|
20
|
+
limit: "poolAvailableLiquidity"
|
|
21
|
+
})];
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { checkPoolLiquidity };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { poolPaused } from "../../../model/errors/operation-errors.js";
|
|
2
|
+
import "../../../model/index.js";
|
|
3
|
+
//#region src/onchain/validation/checks/checkPoolPaused.ts
|
|
4
|
+
/** A paused pool neither takes deposits nor serves withdrawals. */
|
|
5
|
+
function checkPoolPaused(args) {
|
|
6
|
+
return args.isPaused ? [poolPaused(args.pool)] : [];
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { checkPoolPaused };
|