@gearbox-protocol/sdk 15.1.0-next.1 → 15.1.0-next.11
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/iExpirable.js +15 -0
- package/dist/cjs/common-utils/utils/apy/get-single-quota-borrow-rate.js +2 -0
- package/dist/cjs/common-utils/utils/creditAccount/calc-health-factor.js +24 -22
- package/dist/cjs/common-utils/utils/creditAccount/calc-quota-borrow-rate.js +2 -0
- package/dist/cjs/common-utils/utils/creditAccount/get-time-to-liquidation.js +8 -5
- package/dist/cjs/common-utils/utils/creditAccount/liquidation-price.js +21 -11
- package/dist/cjs/dev/AccountOpener.js +0 -1
- package/dist/cjs/dev/compareOpportunities.js +137 -0
- package/dist/cjs/dev/comparePositions.js +183 -0
- package/dist/cjs/dev/fieldDiff.js +241 -0
- package/dist/cjs/model/charts.js +147 -0
- package/dist/cjs/model/charts.schema.js +240 -0
- package/dist/cjs/model/index.js +35 -22
- package/dist/cjs/model/liquidations.schema.js +1 -1
- package/dist/cjs/model/notices.schema.js +25 -0
- package/dist/cjs/model/opportunities.schema.js +1 -1
- package/dist/cjs/model/positions.schema.js +48 -2
- package/dist/cjs/new-sdk/AbstractNamespace.js +34 -4
- package/dist/cjs/new-sdk/GearboxSDK.js +72 -3
- package/dist/cjs/new-sdk/execute/ExecuteApi.js +95 -0
- package/dist/cjs/new-sdk/execute/index.js +3 -0
- package/dist/cjs/new-sdk/index.js +7 -0
- package/dist/cjs/new-sdk/opportunities/OpportunitiesNamespace.js +29 -6
- package/dist/cjs/new-sdk/positions/PositionsNamespace.js +3 -6
- package/dist/cjs/new-sdk/simulate/SimulateApi.js +361 -0
- package/dist/cjs/new-sdk/simulate/index.js +4 -0
- package/dist/cjs/new-sdk/utils/index.js +0 -1
- package/dist/cjs/offchain/AbstractOffchainNamespace.js +10 -7
- package/dist/cjs/offchain/GearboxAPI.js +7 -0
- package/dist/cjs/offchain/index.js +3 -0
- package/dist/cjs/offchain/notices/OffchainNotices.js +27 -0
- package/dist/cjs/offchain/notices/index.js +3 -0
- package/dist/cjs/offchain/opportunities/OffchainOpportunities.js +4 -8
- package/dist/cjs/offchain/positions/OffchainPositions.js +12 -12
- package/dist/cjs/preview/preview/CreditAccountState.js +14 -1
- package/dist/cjs/preview/preview/buildDelayedPreview.js +16 -6
- package/dist/cjs/preview/preview/previewAdjustCreditAccount.js +9 -2
- package/dist/cjs/preview/preview/previewOpenCreditAccount.js +11 -3
- package/dist/cjs/preview/preview/previewOperation.js +1 -1
- package/dist/cjs/sdk/MultichainSDK.js +3 -4
- package/dist/cjs/sdk/OnchainSDK.js +42 -13
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +2 -8
- package/dist/cjs/sdk/accounts/credit-account-compressor/CreditAccountCompressor.js +2 -90
- package/dist/cjs/sdk/accounts/index.js +5 -2
- package/dist/cjs/sdk/accounts/intents/guards.js +114 -0
- package/dist/cjs/sdk/accounts/intents/index.js +216 -358
- package/dist/cjs/sdk/accounts/intents/math.js +56 -0
- package/dist/cjs/sdk/accounts/intents/open-strategy.js +133 -0
- package/dist/cjs/sdk/accounts/intents/operations.js +165 -0
- package/dist/cjs/sdk/accounts/intents/plan.js +373 -0
- package/dist/cjs/sdk/accounts/intents/realize.js +301 -0
- package/dist/cjs/sdk/accounts/intents/testing/delayed.js +50 -0
- package/dist/cjs/sdk/accounts/intents/testing/market.js +166 -0
- package/dist/cjs/sdk/accounts/intents/testing/sdk-mock.js +194 -35
- package/dist/cjs/sdk/accounts/intents/tests/add-collateral.fixtures.js +123 -0
- package/dist/cjs/sdk/accounts/intents/tests/adjust-leverage.fixtures.js +254 -0
- package/dist/cjs/sdk/accounts/intents/tests/deposit.fixtures.js +324 -0
- package/dist/cjs/sdk/accounts/intents/tests/finish-decrease-leverage.fixtures.js +242 -0
- package/dist/cjs/sdk/accounts/intents/tests/finish-withdraw.fixtures.js +383 -0
- package/dist/cjs/sdk/accounts/intents/tests/open-strategy.fixtures.js +133 -0
- package/dist/cjs/sdk/accounts/intents/tests/withdraw-asset.fixtures.js +131 -0
- package/dist/cjs/sdk/accounts/intents/tests/withdraw.fixtures.js +426 -0
- package/dist/cjs/sdk/accounts/intents/types.js +16 -0
- package/dist/cjs/sdk/accounts/intents/utils/adjust-state-to-snapshot.js +18 -0
- package/dist/cjs/sdk/accounts/intents/utils/credit-account-slice.js +45 -0
- package/dist/cjs/sdk/accounts/intents/utils/index.js +17 -8
- package/dist/cjs/sdk/accounts/intents/utils/ledger.js +94 -0
- package/dist/cjs/sdk/accounts/intents/utils/pick-token.js +72 -0
- package/dist/cjs/sdk/accounts/intents/utils/quotas-for-update.js +27 -0
- package/dist/cjs/sdk/accounts/intents/utils/router-path.js +86 -0
- package/dist/cjs/sdk/accounts/intents/view.js +38 -0
- package/dist/cjs/sdk/accounts/liquidations/LiquidationsService.js +0 -3
- package/dist/cjs/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.js +29 -18
- package/dist/cjs/sdk/base/BaseContract.js +1 -1
- package/dist/cjs/sdk/base/TokensMeta.js +78 -27
- package/dist/cjs/sdk/index.js +30 -7
- package/dist/cjs/sdk/market/MarketRegister.js +16 -7
- package/dist/cjs/sdk/market/ZapperRegister.js +56 -25
- package/dist/cjs/sdk/market/credit/CreditManagerV310Contract.js +1 -12
- package/dist/cjs/sdk/market/credit/CreditSuite.js +28 -9
- package/dist/cjs/sdk/market/credit/index.js +3 -0
- package/dist/cjs/sdk/market/credit/isStrategyCollateral.js +50 -0
- package/dist/cjs/sdk/market/index.js +17 -0
- package/dist/cjs/sdk/market/math.js +65 -45
- package/dist/cjs/sdk/market/oracle/PriceOracleBaseContract.js +10 -3
- package/dist/cjs/sdk/market/pool/PoolV310Contract.js +15 -1
- package/dist/cjs/sdk/market/rwa/RWARegistry.js +22 -0
- package/dist/cjs/sdk/opportunities/index.js +0 -13
- package/dist/cjs/sdk/options.js +1 -5
- package/dist/cjs/sdk/pools/PoolService.js +133 -4
- package/dist/cjs/sdk/pools/index.js +2 -0
- package/dist/cjs/sdk/positions/PositionsService.js +218 -1
- package/dist/cjs/sdk/positions/calcBorrowRate.js +43 -0
- package/dist/cjs/sdk/positions/calcHealthFactor.js +52 -0
- package/dist/cjs/sdk/positions/calcLiquidationPrice.js +23 -0
- package/dist/cjs/sdk/positions/calcLiquidationPriceForTarget.js +30 -0
- package/dist/cjs/sdk/positions/calcTimeToLiquidationMs.js +19 -0
- package/dist/cjs/sdk/positions/index.js +12 -1
- package/dist/cjs/sdk/positions/types.js +31 -0
- package/dist/cjs/sdk/utils/abi-decode.js +2 -2
- package/dist/cjs/sdk/utils/viem/executeMulticallBatches.js +32 -0
- package/dist/cjs/sdk/utils/viem/index.js +2 -0
- package/dist/esm/abi/iExpirable.js +14 -0
- package/dist/esm/common-utils/utils/apy/get-single-quota-borrow-rate.js +2 -0
- package/dist/esm/common-utils/utils/creditAccount/calc-health-factor.js +24 -22
- package/dist/esm/common-utils/utils/creditAccount/calc-quota-borrow-rate.js +2 -0
- package/dist/esm/common-utils/utils/creditAccount/get-time-to-liquidation.js +8 -5
- package/dist/esm/common-utils/utils/creditAccount/liquidation-price.js +21 -11
- package/dist/esm/dev/AccountOpener.js +0 -1
- package/dist/esm/dev/compareOpportunities.js +135 -0
- package/dist/esm/dev/comparePositions.js +181 -0
- package/dist/esm/dev/fieldDiff.js +224 -0
- package/dist/esm/model/charts.js +140 -0
- package/dist/esm/model/charts.schema.js +226 -0
- package/dist/esm/model/index.js +9 -7
- package/dist/esm/model/liquidations.schema.js +1 -1
- package/dist/esm/model/notices.schema.js +23 -0
- package/dist/esm/model/opportunities.schema.js +1 -1
- package/dist/esm/model/positions.schema.js +46 -4
- package/dist/esm/new-sdk/AbstractNamespace.js +34 -4
- package/dist/esm/new-sdk/GearboxSDK.js +72 -4
- package/dist/esm/new-sdk/execute/ExecuteApi.js +94 -0
- package/dist/esm/new-sdk/execute/index.js +2 -0
- package/dist/esm/new-sdk/index.js +6 -2
- package/dist/esm/new-sdk/opportunities/OpportunitiesNamespace.js +29 -6
- package/dist/esm/new-sdk/positions/PositionsNamespace.js +3 -6
- package/dist/esm/new-sdk/simulate/SimulateApi.js +360 -0
- package/dist/esm/new-sdk/simulate/index.js +3 -0
- package/dist/esm/new-sdk/utils/index.js +0 -1
- package/dist/esm/offchain/AbstractOffchainNamespace.js +10 -7
- package/dist/esm/offchain/GearboxAPI.js +7 -0
- package/dist/esm/offchain/index.js +3 -1
- package/dist/esm/offchain/notices/OffchainNotices.js +26 -0
- package/dist/esm/offchain/notices/index.js +2 -0
- package/dist/esm/offchain/opportunities/OffchainOpportunities.js +4 -8
- package/dist/esm/offchain/positions/OffchainPositions.js +12 -12
- package/dist/esm/preview/preview/CreditAccountState.js +14 -1
- package/dist/esm/preview/preview/buildDelayedPreview.js +16 -6
- package/dist/esm/preview/preview/previewAdjustCreditAccount.js +9 -2
- package/dist/esm/preview/preview/previewOpenCreditAccount.js +11 -3
- package/dist/esm/preview/preview/previewOperation.js +1 -1
- package/dist/esm/sdk/MultichainSDK.js +3 -4
- package/dist/esm/sdk/OnchainSDK.js +42 -13
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +2 -8
- package/dist/esm/sdk/accounts/credit-account-compressor/CreditAccountCompressor.js +2 -90
- package/dist/esm/sdk/accounts/index.js +3 -2
- package/dist/esm/sdk/accounts/intents/guards.js +108 -0
- package/dist/esm/sdk/accounts/intents/index.js +214 -358
- package/dist/esm/sdk/accounts/intents/math.js +51 -0
- package/dist/esm/sdk/accounts/intents/open-strategy.js +132 -0
- package/dist/esm/sdk/accounts/intents/operations.js +153 -0
- package/dist/esm/sdk/accounts/intents/plan.js +361 -0
- package/dist/esm/sdk/accounts/intents/realize.js +300 -0
- package/dist/esm/sdk/accounts/intents/testing/delayed.js +38 -0
- package/dist/esm/sdk/accounts/intents/testing/market.js +148 -0
- package/dist/esm/sdk/accounts/intents/testing/sdk-mock.js +194 -35
- package/dist/esm/sdk/accounts/intents/tests/add-collateral.fixtures.js +110 -0
- package/dist/esm/sdk/accounts/intents/tests/adjust-leverage.fixtures.js +234 -0
- package/dist/esm/sdk/accounts/intents/tests/deposit.fixtures.js +302 -0
- package/dist/esm/sdk/accounts/intents/tests/finish-decrease-leverage.fixtures.js +220 -0
- package/dist/esm/sdk/accounts/intents/tests/finish-withdraw.fixtures.js +355 -0
- package/dist/esm/sdk/accounts/intents/tests/open-strategy.fixtures.js +119 -0
- package/dist/esm/sdk/accounts/intents/tests/withdraw-asset.fixtures.js +117 -0
- package/dist/esm/sdk/accounts/intents/tests/withdraw.fixtures.js +402 -0
- package/dist/esm/sdk/accounts/intents/types.js +16 -1
- package/dist/esm/sdk/accounts/intents/utils/adjust-state-to-snapshot.js +17 -0
- package/dist/esm/sdk/accounts/intents/utils/credit-account-slice.js +43 -0
- package/dist/esm/sdk/accounts/intents/utils/index.js +9 -7
- package/dist/esm/sdk/accounts/intents/utils/ledger.js +93 -0
- package/dist/esm/sdk/accounts/intents/utils/pick-token.js +68 -0
- package/dist/esm/sdk/accounts/intents/utils/quotas-for-update.js +27 -1
- package/dist/esm/sdk/accounts/intents/utils/router-path.js +85 -0
- package/dist/esm/sdk/accounts/intents/view.js +37 -0
- package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +0 -3
- package/dist/esm/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.js +29 -18
- package/dist/esm/sdk/base/BaseContract.js +1 -1
- package/dist/esm/sdk/base/TokensMeta.js +78 -27
- package/dist/esm/sdk/index.js +13 -4
- package/dist/esm/sdk/market/MarketRegister.js +16 -7
- package/dist/esm/sdk/market/ZapperRegister.js +56 -25
- package/dist/esm/sdk/market/credit/CreditManagerV310Contract.js +2 -13
- package/dist/esm/sdk/market/credit/CreditSuite.js +29 -10
- package/dist/esm/sdk/market/credit/index.js +2 -1
- package/dist/esm/sdk/market/credit/isStrategyCollateral.js +48 -0
- package/dist/esm/sdk/market/index.js +3 -1
- package/dist/esm/sdk/market/math.js +60 -41
- package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +10 -3
- package/dist/esm/sdk/market/pool/PoolV310Contract.js +16 -2
- package/dist/esm/sdk/market/rwa/RWARegistry.js +22 -0
- package/dist/esm/sdk/opportunities/index.js +1 -2
- package/dist/esm/sdk/options.js +1 -5
- package/dist/esm/sdk/pools/PoolService.js +133 -6
- package/dist/esm/sdk/pools/index.js +2 -2
- package/dist/esm/sdk/positions/PositionsService.js +218 -1
- package/dist/esm/sdk/positions/calcBorrowRate.js +42 -0
- package/dist/esm/sdk/positions/calcHealthFactor.js +51 -0
- package/dist/esm/sdk/positions/calcLiquidationPrice.js +22 -0
- package/dist/esm/sdk/positions/calcLiquidationPriceForTarget.js +29 -0
- package/dist/esm/sdk/positions/calcTimeToLiquidationMs.js +18 -0
- package/dist/esm/sdk/positions/index.js +7 -2
- package/dist/esm/sdk/positions/types.js +31 -1
- package/dist/esm/sdk/utils/abi-decode.js +2 -2
- package/dist/esm/sdk/utils/viem/executeMulticallBatches.js +31 -0
- package/dist/esm/sdk/utils/viem/index.js +2 -1
- package/dist/types/abi/iExpirable.d.ts +14 -0
- package/dist/types/common-utils/utils/apy/get-single-quota-borrow-rate.d.ts +2 -0
- package/dist/types/common-utils/utils/creditAccount/calc-health-factor.d.ts +3 -0
- package/dist/types/common-utils/utils/creditAccount/calc-quota-borrow-rate.d.ts +2 -0
- package/dist/types/common-utils/utils/creditAccount/get-time-to-liquidation.d.ts +6 -1
- package/dist/types/common-utils/utils/creditAccount/liquidation-price.d.ts +3 -0
- package/dist/types/dev/compareOpportunities.d.ts +105 -0
- package/dist/types/dev/comparePositions.d.ts +149 -0
- package/dist/types/dev/fieldDiff.d.ts +167 -0
- package/dist/types/model/charts.d.ts +349 -0
- package/dist/types/model/charts.schema.d.ts +364 -0
- package/dist/types/model/index.d.ts +8 -6
- package/dist/types/model/notices.d.ts +29 -0
- package/dist/types/model/notices.schema.d.ts +23 -0
- package/dist/types/model/opportunities.d.ts +9 -9
- package/dist/types/model/positions.d.ts +133 -7
- package/dist/types/model/positions.schema.d.ts +128 -1
- package/dist/types/new-sdk/AbstractNamespace.d.ts +15 -2
- package/dist/types/new-sdk/GearboxSDK.d.ts +14 -2
- package/dist/types/new-sdk/execute/ExecuteApi.d.ts +108 -0
- package/dist/types/new-sdk/execute/index.d.ts +2 -0
- package/dist/types/new-sdk/index.d.ts +8 -4
- package/dist/types/new-sdk/opportunities/OpportunitiesNamespace.d.ts +19 -7
- package/dist/types/new-sdk/opportunities/types.d.ts +30 -9
- package/dist/types/new-sdk/positions/PositionsNamespace.d.ts +4 -5
- package/dist/types/new-sdk/positions/types.d.ts +9 -9
- package/dist/types/new-sdk/simulate/SimulateApi.d.ts +90 -0
- package/dist/types/new-sdk/simulate/index.d.ts +3 -0
- package/dist/types/new-sdk/simulate/types.d.ts +508 -0
- package/dist/types/new-sdk/types.d.ts +35 -1
- package/dist/types/new-sdk/utils/index.d.ts +1 -2
- package/dist/types/offchain/AbstractOffchainNamespace.d.ts +5 -21
- package/dist/types/offchain/GearboxAPI.d.ts +6 -0
- package/dist/types/offchain/index.d.ts +4 -2
- package/dist/types/offchain/notices/OffchainNotices.d.ts +19 -0
- package/dist/types/offchain/notices/index.d.ts +2 -0
- package/dist/types/offchain/opportunities/OffchainOpportunities.d.ts +8 -4
- package/dist/types/offchain/positions/OffchainPositions.d.ts +8 -6
- package/dist/types/preview/preview/CreditAccountState.d.ts +6 -0
- package/dist/types/preview/preview/buildDelayedPreview.d.ts +5 -1
- package/dist/types/preview/preview/types.d.ts +4 -2
- package/dist/types/sdk/MultichainSDK.d.ts +0 -5
- package/dist/types/sdk/OnchainSDK.d.ts +1 -5
- package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +1 -7
- package/dist/types/sdk/accounts/credit-account-compressor/CreditAccountCompressor.d.ts +3 -12
- package/dist/types/sdk/accounts/credit-account-compressor/index.d.ts +2 -2
- package/dist/types/sdk/accounts/credit-account-compressor/types.d.ts +1 -19
- package/dist/types/sdk/accounts/index.d.ts +7 -5
- package/dist/types/sdk/accounts/intents/guards.d.ts +72 -0
- package/dist/types/sdk/accounts/intents/index.d.ts +130 -15
- package/dist/types/sdk/accounts/intents/math.d.ts +46 -0
- package/dist/types/sdk/accounts/intents/open-strategy.d.ts +64 -0
- package/dist/types/sdk/accounts/intents/operations.d.ts +215 -0
- package/dist/types/sdk/accounts/intents/plan.d.ts +189 -0
- package/dist/types/sdk/accounts/intents/realize.d.ts +35 -0
- package/dist/types/sdk/accounts/intents/testing/delayed.d.ts +50 -0
- package/dist/types/sdk/accounts/intents/testing/expect.d.ts +17 -21
- package/dist/types/sdk/accounts/intents/testing/market.d.ts +91 -0
- package/dist/types/sdk/accounts/intents/testing/sdk-mock.d.ts +64 -16
- package/dist/types/sdk/accounts/intents/tests/add-collateral.fixtures.d.ts +45 -0
- package/dist/types/sdk/accounts/intents/tests/adjust-leverage.fixtures.d.ts +56 -0
- package/dist/types/sdk/accounts/intents/tests/deposit.fixtures.d.ts +64 -0
- package/dist/types/sdk/accounts/intents/tests/finish-decrease-leverage.fixtures.d.ts +107 -0
- package/dist/types/sdk/accounts/intents/tests/finish-withdraw.fixtures.d.ts +136 -0
- package/dist/types/sdk/accounts/intents/tests/open-strategy.fixtures.d.ts +56 -0
- package/dist/types/sdk/accounts/intents/tests/withdraw-asset.fixtures.d.ts +60 -0
- package/dist/types/sdk/accounts/intents/tests/withdraw.fixtures.d.ts +79 -0
- package/dist/types/sdk/accounts/intents/types.d.ts +369 -43
- package/dist/types/sdk/accounts/intents/utils/adjust-state-to-snapshot.d.ts +13 -0
- package/dist/types/sdk/accounts/intents/utils/assemble-operation-calls.d.ts +1 -1
- package/dist/types/sdk/accounts/intents/utils/credit-account-slice.d.ts +29 -0
- package/dist/types/sdk/accounts/intents/utils/index.d.ts +7 -5
- package/dist/types/sdk/accounts/intents/utils/ledger.d.ts +41 -0
- package/dist/types/sdk/accounts/intents/utils/pick-token.d.ts +55 -0
- package/dist/types/sdk/accounts/intents/utils/quotas-for-update.d.ts +15 -4
- package/dist/types/sdk/accounts/intents/utils/router-path.d.ts +70 -0
- package/dist/types/sdk/accounts/intents/view.d.ts +15 -0
- package/dist/types/sdk/accounts/types.d.ts +17 -14
- package/dist/types/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.d.ts +6 -0
- package/dist/types/sdk/accounts/withdrawal-compressor/types.d.ts +18 -0
- package/dist/types/sdk/base/TokensMeta.d.ts +44 -1
- package/dist/types/sdk/base/index.d.ts +2 -2
- package/dist/types/sdk/base/token-types.d.ts +12 -1
- package/dist/types/sdk/index.d.ts +28 -19
- package/dist/types/sdk/market/MarketRegister.d.ts +7 -3
- package/dist/types/sdk/market/ZapperRegister.d.ts +20 -2
- package/dist/types/sdk/market/credit/CreditManagerV310Contract.d.ts +0 -4
- package/dist/types/sdk/market/credit/CreditSuite.d.ts +6 -3
- package/dist/types/sdk/market/credit/index.d.ts +2 -1
- package/dist/types/sdk/market/credit/isStrategyCollateral.d.ts +74 -0
- package/dist/types/sdk/market/credit/types.d.ts +2 -9
- package/dist/types/sdk/market/index.d.ts +4 -2
- package/dist/types/sdk/market/math.d.ts +46 -34
- package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +6 -2
- package/dist/types/sdk/market/oracle/types.d.ts +10 -2
- package/dist/types/sdk/market/pool/PoolV310Contract.d.ts +5 -0
- package/dist/types/sdk/market/pool/types.d.ts +5 -0
- package/dist/types/sdk/market/rwa/RWARegistry.d.ts +13 -0
- package/dist/types/sdk/market/types.d.ts +5 -1
- package/dist/types/sdk/opportunities/index.d.ts +1 -2
- package/dist/types/sdk/options.d.ts +0 -1
- package/dist/types/sdk/pools/PoolService.d.ts +32 -2
- package/dist/types/sdk/pools/index.d.ts +3 -3
- package/dist/types/sdk/pools/types.d.ts +109 -4
- package/dist/types/sdk/positions/PositionsService.d.ts +33 -2
- package/dist/types/sdk/positions/calcBorrowRate.d.ts +40 -0
- package/dist/types/sdk/positions/calcHealthFactor.d.ts +55 -0
- package/dist/types/sdk/positions/calcLiquidationPrice.d.ts +12 -0
- package/dist/types/sdk/positions/calcLiquidationPriceForTarget.d.ts +43 -0
- package/dist/types/sdk/positions/calcTimeToLiquidationMs.d.ts +16 -0
- package/dist/types/sdk/positions/index.d.ts +7 -2
- package/dist/types/sdk/positions/types.d.ts +58 -1
- package/dist/types/sdk/types/state.d.ts +6 -0
- package/dist/types/sdk/utils/viem/executeMulticallBatches.d.ts +39 -0
- package/dist/types/sdk/utils/viem/index.d.ts +3 -2
- package/package.json +2 -1
- package/dist/cjs/model/history.js +0 -53
- package/dist/cjs/model/history.schema.js +0 -128
- package/dist/cjs/sdk/accounts/intents/intents/index.js +0 -14
- package/dist/cjs/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.fixtures.js +0 -121
- package/dist/cjs/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.js +0 -15
- package/dist/cjs/sdk/accounts/intents/intents/resume/close/close.fixtures.js +0 -108
- package/dist/cjs/sdk/accounts/intents/intents/resume/close/close.js +0 -51
- package/dist/cjs/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.fixtures.js +0 -130
- package/dist/cjs/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.js +0 -83
- package/dist/cjs/sdk/accounts/intents/intents/resume/deposit/deposit.fixtures.js +0 -117
- package/dist/cjs/sdk/accounts/intents/intents/resume/deposit/deposit.js +0 -15
- package/dist/cjs/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.fixtures.js +0 -95
- package/dist/cjs/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.js +0 -15
- package/dist/cjs/sdk/accounts/intents/intents/resume/index.js +0 -13
- package/dist/cjs/sdk/accounts/intents/intents/resume/withdraw/withdraw.fixtures.js +0 -138
- package/dist/cjs/sdk/accounts/intents/intents/resume/withdraw/withdraw.js +0 -161
- package/dist/cjs/sdk/accounts/intents/operations/add-collateral/index.js +0 -17
- package/dist/cjs/sdk/accounts/intents/operations/claim-delayed/index.js +0 -54
- package/dist/cjs/sdk/accounts/intents/operations/close-credit-account/index.js +0 -26
- package/dist/cjs/sdk/accounts/intents/operations/decrease-debt/index.js +0 -12
- package/dist/cjs/sdk/accounts/intents/operations/increase-debt/index.js +0 -12
- package/dist/cjs/sdk/accounts/intents/operations/index.js +0 -27
- package/dist/cjs/sdk/accounts/intents/operations/quota-update/index.js +0 -22
- package/dist/cjs/sdk/accounts/intents/operations/repay-credit-account/index.js +0 -22
- package/dist/cjs/sdk/accounts/intents/operations/start-delayed-withdrawal/index.js +0 -18
- package/dist/cjs/sdk/accounts/intents/operations/swap/index.js +0 -18
- package/dist/cjs/sdk/accounts/intents/operations/unwrap-rwa-collateral/index.js +0 -27
- package/dist/cjs/sdk/accounts/intents/operations/withdraw-collateral/index.js +0 -43
- package/dist/cjs/sdk/accounts/intents/operations/wrap-rwa-collateral/index.js +0 -27
- package/dist/cjs/sdk/accounts/intents/quoters/close.js +0 -58
- package/dist/cjs/sdk/accounts/intents/quoters/index.js +0 -7
- package/dist/cjs/sdk/accounts/intents/quoters/swap.js +0 -79
- package/dist/cjs/sdk/accounts/intents/testing/expect.js +0 -167
- package/dist/cjs/sdk/accounts/intents/testing/resume.js +0 -172
- package/dist/cjs/sdk/accounts/intents/utils/simulate-adjust-state.js +0 -39
- package/dist/cjs/sdk/accounts/intents/utils/simulate-assets.js +0 -69
- package/dist/cjs/sdk/accounts/intents/utils/with-quota-update.js +0 -13
- package/dist/esm/model/history.js +0 -49
- package/dist/esm/model/history.schema.js +0 -116
- package/dist/esm/sdk/accounts/intents/intents/index.js +0 -8
- package/dist/esm/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.fixtures.js +0 -107
- package/dist/esm/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.js +0 -14
- package/dist/esm/sdk/accounts/intents/intents/resume/close/close.fixtures.js +0 -94
- package/dist/esm/sdk/accounts/intents/intents/resume/close/close.js +0 -50
- package/dist/esm/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.fixtures.js +0 -114
- package/dist/esm/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.js +0 -82
- package/dist/esm/sdk/accounts/intents/intents/resume/deposit/deposit.fixtures.js +0 -110
- package/dist/esm/sdk/accounts/intents/intents/resume/deposit/deposit.js +0 -14
- package/dist/esm/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.fixtures.js +0 -88
- package/dist/esm/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.js +0 -14
- package/dist/esm/sdk/accounts/intents/intents/resume/index.js +0 -7
- package/dist/esm/sdk/accounts/intents/intents/resume/withdraw/withdraw.fixtures.js +0 -121
- package/dist/esm/sdk/accounts/intents/intents/resume/withdraw/withdraw.js +0 -160
- package/dist/esm/sdk/accounts/intents/operations/add-collateral/index.js +0 -16
- package/dist/esm/sdk/accounts/intents/operations/claim-delayed/index.js +0 -52
- package/dist/esm/sdk/accounts/intents/operations/close-credit-account/index.js +0 -25
- package/dist/esm/sdk/accounts/intents/operations/decrease-debt/index.js +0 -11
- package/dist/esm/sdk/accounts/intents/operations/increase-debt/index.js +0 -11
- package/dist/esm/sdk/accounts/intents/operations/index.js +0 -14
- package/dist/esm/sdk/accounts/intents/operations/quota-update/index.js +0 -21
- package/dist/esm/sdk/accounts/intents/operations/repay-credit-account/index.js +0 -21
- package/dist/esm/sdk/accounts/intents/operations/start-delayed-withdrawal/index.js +0 -17
- package/dist/esm/sdk/accounts/intents/operations/swap/index.js +0 -17
- package/dist/esm/sdk/accounts/intents/operations/unwrap-rwa-collateral/index.js +0 -26
- package/dist/esm/sdk/accounts/intents/operations/withdraw-collateral/index.js +0 -42
- package/dist/esm/sdk/accounts/intents/operations/wrap-rwa-collateral/index.js +0 -26
- package/dist/esm/sdk/accounts/intents/quoters/close.js +0 -56
- package/dist/esm/sdk/accounts/intents/quoters/index.js +0 -3
- package/dist/esm/sdk/accounts/intents/quoters/swap.js +0 -77
- package/dist/esm/sdk/accounts/intents/testing/expect.js +0 -162
- package/dist/esm/sdk/accounts/intents/testing/resume.js +0 -157
- package/dist/esm/sdk/accounts/intents/utils/simulate-adjust-state.js +0 -38
- package/dist/esm/sdk/accounts/intents/utils/simulate-assets.js +0 -68
- package/dist/esm/sdk/accounts/intents/utils/with-quota-update.js +0 -12
- package/dist/types/model/history.d.ts +0 -153
- package/dist/types/model/history.schema.d.ts +0 -95
- package/dist/types/new-sdk/utils/history.d.ts +0 -18
- package/dist/types/sdk/accounts/intents/intents/index.d.ts +0 -8
- package/dist/types/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.d.ts +0 -13
- package/dist/types/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.fixtures.d.ts +0 -38
- package/dist/types/sdk/accounts/intents/intents/resume/close/close.d.ts +0 -26
- package/dist/types/sdk/accounts/intents/intents/resume/close/close.fixtures.d.ts +0 -63
- package/dist/types/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.d.ts +0 -26
- package/dist/types/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.fixtures.d.ts +0 -86
- package/dist/types/sdk/accounts/intents/intents/resume/deposit/deposit.d.ts +0 -13
- package/dist/types/sdk/accounts/intents/intents/resume/deposit/deposit.fixtures.d.ts +0 -48
- package/dist/types/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.d.ts +0 -13
- package/dist/types/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.fixtures.d.ts +0 -46
- package/dist/types/sdk/accounts/intents/intents/resume/index.d.ts +0 -7
- package/dist/types/sdk/accounts/intents/intents/resume/withdraw/withdraw.d.ts +0 -33
- package/dist/types/sdk/accounts/intents/intents/resume/withdraw/withdraw.fixtures.d.ts +0 -68
- package/dist/types/sdk/accounts/intents/operations/add-collateral/index.d.ts +0 -23
- package/dist/types/sdk/accounts/intents/operations/claim-delayed/index.d.ts +0 -55
- package/dist/types/sdk/accounts/intents/operations/close-credit-account/index.d.ts +0 -22
- package/dist/types/sdk/accounts/intents/operations/decrease-debt/index.d.ts +0 -18
- package/dist/types/sdk/accounts/intents/operations/increase-debt/index.d.ts +0 -18
- package/dist/types/sdk/accounts/intents/operations/index.d.ts +0 -14
- package/dist/types/sdk/accounts/intents/operations/quota-update/index.d.ts +0 -24
- package/dist/types/sdk/accounts/intents/operations/repay-credit-account/index.d.ts +0 -31
- package/dist/types/sdk/accounts/intents/operations/start-delayed-withdrawal/index.d.ts +0 -23
- package/dist/types/sdk/accounts/intents/operations/swap/index.d.ts +0 -28
- package/dist/types/sdk/accounts/intents/operations/types.d.ts +0 -21
- package/dist/types/sdk/accounts/intents/operations/unwrap-rwa-collateral/index.d.ts +0 -30
- package/dist/types/sdk/accounts/intents/operations/withdraw-collateral/index.d.ts +0 -36
- package/dist/types/sdk/accounts/intents/operations/wrap-rwa-collateral/index.d.ts +0 -30
- package/dist/types/sdk/accounts/intents/quoters/close.d.ts +0 -43
- package/dist/types/sdk/accounts/intents/quoters/index.d.ts +0 -3
- package/dist/types/sdk/accounts/intents/quoters/swap.d.ts +0 -43
- package/dist/types/sdk/accounts/intents/testing/resume.d.ts +0 -84
- package/dist/types/sdk/accounts/intents/utils/simulate-adjust-state.d.ts +0 -19
- package/dist/types/sdk/accounts/intents/utils/simulate-assets.d.ts +0 -21
- package/dist/types/sdk/accounts/intents/utils/with-quota-update.d.ts +0 -16
- /package/dist/cjs/{new-sdk/utils/history.js → model/notices.js} +0 -0
- /package/dist/cjs/{sdk/accounts/intents/operations → new-sdk/simulate}/types.js +0 -0
- /package/dist/esm/{new-sdk/utils/history.js → model/notices.js} +0 -0
- /package/dist/esm/{sdk/accounts/intents/operations → new-sdk/simulate}/types.js +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_sdk_constants_address_provider = require("../../sdk/constants/address-provider.js");
|
|
3
|
+
const require_sdk_constants_math = require("../../sdk/constants/math.js");
|
|
3
4
|
require("../../sdk/index.js");
|
|
4
5
|
const require_preview_preview_types = require("./types.js");
|
|
5
6
|
const require_preview_preview_CreditAccountState = require("./CreditAccountState.js");
|
|
@@ -26,7 +27,9 @@ async function previewOpenCreditAccount(input, operation) {
|
|
|
26
27
|
});
|
|
27
28
|
const { assets: collateral, error: unwrapError } = require_preview_preview_unwrapNativeCollateral.unwrapNativeCollateral(state.collateralAdded.toAssets(), value, sdk.addressProvider.getAddress(require_sdk_constants_address_provider.AP_WETH_TOKEN, 0));
|
|
28
29
|
error ??= unwrapError ?? priceError;
|
|
29
|
-
const assets = account.balances.toAssets(
|
|
30
|
+
const assets = account.balances.toAssets(require_sdk_constants_math.DUST_THRESHOLD);
|
|
31
|
+
const quotas = account.quotas.toAssets(0n);
|
|
32
|
+
const snap = account.toSnapshot(collateralValue + account.totalDebt);
|
|
30
33
|
return {
|
|
31
34
|
operation: operation.operation,
|
|
32
35
|
creditManager: operation.creditManager,
|
|
@@ -34,9 +37,14 @@ async function previewOpenCreditAccount(input, operation) {
|
|
|
34
37
|
collateral,
|
|
35
38
|
collateralValue,
|
|
36
39
|
debt: account.debt,
|
|
37
|
-
quotas
|
|
40
|
+
quotas,
|
|
38
41
|
assets,
|
|
39
|
-
error
|
|
42
|
+
error,
|
|
43
|
+
healthFactor: sdk.positions.healthFactor(snap),
|
|
44
|
+
overallApy: 0,
|
|
45
|
+
borrowRate: sdk.positions.borrowRate(snap),
|
|
46
|
+
timeToLiquidation: sdk.positions.timeToLiquidation(snap),
|
|
47
|
+
liquidationPrice: sdk.positions.liquidationPrice(snap)
|
|
40
48
|
};
|
|
41
49
|
}
|
|
42
50
|
/**
|
|
@@ -70,7 +70,7 @@ async function previewMulticallOperation(input, operation, options) {
|
|
|
70
70
|
creditManager: operation.creditManager,
|
|
71
71
|
intent: delayed.intent,
|
|
72
72
|
instantPreview,
|
|
73
|
-
delayedPreview: require_preview_preview_buildDelayedPreview.buildDelayedPreview(after.account, before, delayed, convert, receivedToken)
|
|
73
|
+
delayedPreview: require_preview_preview_buildDelayedPreview.buildDelayedPreview(after.account, before, delayed, convert, receivedToken, sdk)
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
76
|
//#endregion
|
|
@@ -69,7 +69,6 @@ var MultichainSDK = class {
|
|
|
69
69
|
const perChainOpts = options?.perChain?.[network] ?? {};
|
|
70
70
|
return sdk.attach({
|
|
71
71
|
...perChainOpts,
|
|
72
|
-
loadZappers: perChainOpts.loadZappers ?? options?.loadZappers,
|
|
73
72
|
redstone: {
|
|
74
73
|
...options?.redstone,
|
|
75
74
|
cache: this.#redstoneCache,
|
|
@@ -89,7 +88,7 @@ var MultichainSDK = class {
|
|
|
89
88
|
* state and `allowMissingChains` is not set.
|
|
90
89
|
*/
|
|
91
90
|
hydrate(state, options) {
|
|
92
|
-
if (state.version !==
|
|
91
|
+
if (state.version !== 2) throw new require_sdk_core_errors.SdkStateVersionMismatchError(2, state.version);
|
|
93
92
|
if (options?.redstone) this.#redstoneCache = new require_sdk_market_pricefeeds_updates_PriceUpdatesCache.PriceUpdatesCache({
|
|
94
93
|
ttl: options.redstone.cacheTTL ?? 225e3,
|
|
95
94
|
historical: !!options.redstone.historicTimestamp
|
|
@@ -169,7 +168,7 @@ var MultichainSDK = class {
|
|
|
169
168
|
**/
|
|
170
169
|
get state() {
|
|
171
170
|
return {
|
|
172
|
-
version:
|
|
171
|
+
version: 2,
|
|
173
172
|
chains: [...this.#chains.values()].map((sdk) => sdk.state)
|
|
174
173
|
};
|
|
175
174
|
}
|
|
@@ -179,7 +178,7 @@ var MultichainSDK = class {
|
|
|
179
178
|
*/
|
|
180
179
|
stateHuman(raw) {
|
|
181
180
|
return {
|
|
182
|
-
version:
|
|
181
|
+
version: 2,
|
|
183
182
|
chains: [...this.#chains.values()].map((sdk) => sdk.stateHuman(raw))
|
|
184
183
|
};
|
|
185
184
|
}
|
|
@@ -8,6 +8,7 @@ require("./constants/index.js");
|
|
|
8
8
|
const require_sdk_utils_formatter = require("./utils/formatter.js");
|
|
9
9
|
const require_sdk_utils_toAddress = require("./utils/toAddress.js");
|
|
10
10
|
require("./utils/index.js");
|
|
11
|
+
const require_sdk_utils_viem_executeMulticallBatches = require("./utils/viem/executeMulticallBatches.js");
|
|
11
12
|
const require_sdk_base_ChainContractsRegister = require("./base/ChainContractsRegister.js");
|
|
12
13
|
require("./base/index.js");
|
|
13
14
|
const require_sdk_utils_viem_executeDelegatedMulticalls = require("./utils/viem/executeDelegatedMulticalls.js");
|
|
@@ -41,7 +42,7 @@ let viem = require("viem");
|
|
|
41
42
|
* Serialised state format version, checked during hydration to detect
|
|
42
43
|
* incompatible snapshots.
|
|
43
44
|
**/
|
|
44
|
-
const STATE_VERSION =
|
|
45
|
+
const STATE_VERSION = 2;
|
|
45
46
|
/**
|
|
46
47
|
* @internal
|
|
47
48
|
* Creates a viem `PublicClient` from the given connection options.
|
|
@@ -151,7 +152,7 @@ var OnchainSDK = class extends require_sdk_base_ChainContractsRegister.ChainCont
|
|
|
151
152
|
*/
|
|
152
153
|
async attach(options) {
|
|
153
154
|
if (this.#attached) throw new require_sdk_core_errors.SdkAlreadyAttachedError();
|
|
154
|
-
const { addressProvider = require_sdk_constants_address_provider.ADDRESS_PROVIDER_V310, blockNumber, ignoreUpdateablePrices, ignoreMarkets, marketConfigurators: mcs, redstone
|
|
155
|
+
const { addressProvider = require_sdk_constants_address_provider.ADDRESS_PROVIDER_V310, blockNumber, ignoreUpdateablePrices, ignoreMarkets, marketConfigurators: mcs, redstone } = options ?? {};
|
|
155
156
|
const marketConfigurators = mcs ?? require_sdk_utils_mappers.TypedObjectUtils.keys(this.client.chain.defaultMarketConfigurators);
|
|
156
157
|
const rwaFactories = options?.rwaFactories ?? this.client.chain.rwaFactories;
|
|
157
158
|
this.logger?.info({
|
|
@@ -175,19 +176,15 @@ var OnchainSDK = class extends require_sdk_base_ChainContractsRegister.ChainCont
|
|
|
175
176
|
this.#marketRegister = new require_sdk_market_MarketRegister.MarketRegister(this, ignoreMarkets);
|
|
176
177
|
if (!marketConfigurators.length) this.logger?.warn("no market configurators provided, skipping market loading");
|
|
177
178
|
else {
|
|
179
|
+
const priceUpdates = await this.#getPriceUpdateTxs(marketConfigurators, ignoreUpdateablePrices);
|
|
180
|
+
this.logger?.debug({ configurators: marketConfigurators }, `calling getMarkets with ${priceUpdates.length} price updates in block ${this.currentBlock}`);
|
|
178
181
|
const delegated = [...this.#marketRegister.getLoadMulticalls(marketConfigurators), ...this.#rwa.getLoadMulticalls(marketConfigurators, rwaFactories)];
|
|
179
|
-
let txs = [];
|
|
180
|
-
if (!ignoreUpdateablePrices) {
|
|
181
|
-
const updatables = await this.#priceFeeds.getPartialUpdatablePriceFeeds(marketConfigurators);
|
|
182
|
-
txs = (await this.#priceFeeds.generatePriceFeedsUpdateTxs(updatables)).txs;
|
|
183
|
-
}
|
|
184
|
-
this.logger?.debug({ configurators: marketConfigurators }, `calling getMarkets with ${txs.length} price updates in block ${this.currentBlock}`);
|
|
185
182
|
await require_sdk_utils_viem_executeDelegatedMulticalls.executeDelegatedMulticalls(this.client, delegated, {
|
|
186
|
-
priceUpdates
|
|
183
|
+
priceUpdates,
|
|
187
184
|
blockNumber: this.currentBlock,
|
|
188
185
|
gas: this.gasLimit
|
|
189
186
|
});
|
|
190
|
-
|
|
187
|
+
await this.#warmup();
|
|
191
188
|
}
|
|
192
189
|
const pluginsList = require_sdk_utils_mappers.TypedObjectUtils.entries(this.plugins);
|
|
193
190
|
(await Promise.allSettled(pluginsList.map(([name, plugin]) => {
|
|
@@ -204,6 +201,36 @@ var OnchainSDK = class extends require_sdk_base_ChainContractsRegister.ChainCont
|
|
|
204
201
|
this.#attached = true;
|
|
205
202
|
}
|
|
206
203
|
/**
|
|
204
|
+
* @internal
|
|
205
|
+
* Pass 0 of attach: resolves the price updates that the market reads of
|
|
206
|
+
* pass 1 are simulated with.
|
|
207
|
+
*
|
|
208
|
+
* @param configurators - Market configurators whose feeds are considered.
|
|
209
|
+
* @param ignoreUpdateablePrices - When `true`, no updates are fetched.
|
|
210
|
+
**/
|
|
211
|
+
async #getPriceUpdateTxs(configurators, ignoreUpdateablePrices) {
|
|
212
|
+
if (ignoreUpdateablePrices) return [];
|
|
213
|
+
const updatables = await this.priceFeeds.getPartialUpdatablePriceFeeds(configurators);
|
|
214
|
+
const { txs } = await this.priceFeeds.generatePriceFeedsUpdateTxs(updatables);
|
|
215
|
+
return txs;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* @internal
|
|
219
|
+
* Pass 2 of attach: loads the data that is read synchronously afterwards
|
|
220
|
+
* (zappers, withdrawable assets, extended token data) in a single multicall.
|
|
221
|
+
*
|
|
222
|
+
* Also re-run after a sync that reloaded the markets these caches derive from.
|
|
223
|
+
*
|
|
224
|
+
* @param force - Reload caches that are already populated.
|
|
225
|
+
**/
|
|
226
|
+
async #warmup(force = false) {
|
|
227
|
+
await require_sdk_utils_viem_executeMulticallBatches.executeMulticallBatches(this.client, [
|
|
228
|
+
this.marketRegister.getLoadZappersMulticall(force),
|
|
229
|
+
...this.#withdrawalCompressor ? [this.#withdrawalCompressor.getLoadWithdrawableAssetsMulticall(force)] : [],
|
|
230
|
+
this.tokensMeta.getLoadTokenDataMulticall()
|
|
231
|
+
], { blockNumber: this.currentBlock });
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
207
234
|
* Restores SDK state from a previously serialised {@link GearboxState}
|
|
208
235
|
* snapshot, without making any on-chain calls.
|
|
209
236
|
*
|
|
@@ -215,7 +242,7 @@ var OnchainSDK = class extends require_sdk_base_ChainContractsRegister.ChainCont
|
|
|
215
242
|
*/
|
|
216
243
|
hydrate(state, options) {
|
|
217
244
|
if (this.#attached) throw new require_sdk_core_errors.SdkAlreadyAttachedError();
|
|
218
|
-
if (state.version !==
|
|
245
|
+
if (state.version !== 2) throw new require_sdk_core_errors.SdkStateVersionMismatchError(2, state.version);
|
|
219
246
|
if (state.network !== this.networkType) throw new require_sdk_core_errors.SdkChainMismatchError(this.networkType, state.network);
|
|
220
247
|
const { ignoreMarkets, redstone } = options ?? {};
|
|
221
248
|
this.logger?.info({ networkType: this.networkType }, "hydrating sdk state");
|
|
@@ -229,6 +256,7 @@ var OnchainSDK = class extends require_sdk_base_ChainContractsRegister.ChainCont
|
|
|
229
256
|
this.#rwa = new require_sdk_market_rwa_RWARegistry.RWARegistry(this);
|
|
230
257
|
this.#rwa.setState(state.rwa);
|
|
231
258
|
if (state.withdrawals) this.#withdrawalCompressor?.hydrate(state.withdrawals);
|
|
259
|
+
if (state.tokens) this.tokensMeta.hydrate(state.tokens);
|
|
232
260
|
for (const [name, plugin] of require_sdk_utils_mappers.TypedObjectUtils.entries(this.plugins)) {
|
|
233
261
|
const pluginState = state.plugins[name];
|
|
234
262
|
if (plugin.hydrate && pluginState) {
|
|
@@ -274,13 +302,14 @@ var OnchainSDK = class extends require_sdk_base_ChainContractsRegister.ChainCont
|
|
|
274
302
|
/** Serialisable snapshot of the current SDK state. */
|
|
275
303
|
get state() {
|
|
276
304
|
return {
|
|
277
|
-
version:
|
|
305
|
+
version: 2,
|
|
278
306
|
network: this.networkType,
|
|
279
307
|
chainId: this.chainId,
|
|
280
308
|
currentBlock: this.currentBlock,
|
|
281
309
|
timestamp: this.timestamp,
|
|
282
310
|
addressProvider: this.addressProvider.state,
|
|
283
311
|
...this.marketRegister.state,
|
|
312
|
+
tokens: this.tokensMeta.state,
|
|
284
313
|
rwa: this.#rwa.state,
|
|
285
314
|
withdrawals: this.#withdrawalCompressor?.state,
|
|
286
315
|
plugins: Object.fromEntries(require_sdk_utils_mappers.TypedObjectUtils.entries(this.plugins).map(([name, plugin]) => [name, plugin.loaded ? {
|
|
@@ -339,7 +368,7 @@ var OnchainSDK = class extends require_sdk_base_ChainContractsRegister.ChainCont
|
|
|
339
368
|
}
|
|
340
369
|
this.#currentBlock = blockNumber;
|
|
341
370
|
this.#timestamp = timestamp;
|
|
342
|
-
await this.marketRegister.syncState(ignoreUpdateablePrices);
|
|
371
|
+
if (await this.marketRegister.syncState(ignoreUpdateablePrices, this.#rwa.getSyncMulticalls())) await this.#warmup(true);
|
|
343
372
|
const pluginsList = require_sdk_utils_mappers.TypedObjectUtils.entries(this.plugins);
|
|
344
373
|
(await Promise.allSettled(pluginsList.map(([name, plugin]) => {
|
|
345
374
|
if (plugin.syncState) {
|
|
@@ -57,12 +57,6 @@ var CreditAccountsServiceV310 = class extends require_sdk_base_SDKConstruct.SDKC
|
|
|
57
57
|
return this.#compressor.getBorrowerCreditAccounts(borrower, options, blockNumber);
|
|
58
58
|
}
|
|
59
59
|
/**
|
|
60
|
-
* {@inheritDoc ICreditAccountsService.listPositions}
|
|
61
|
-
**/
|
|
62
|
-
async listPositions(props) {
|
|
63
|
-
return this.#compressor.listPositions(props);
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
60
|
* {@inheritDoc ICreditAccountsService.getRewards}
|
|
67
61
|
**/
|
|
68
62
|
async getRewards(creditAccount) {
|
|
@@ -383,7 +377,7 @@ var CreditAccountsServiceV310 = class extends require_sdk_base_SDKConstruct.SDKC
|
|
|
383
377
|
calls.push(facade.prepareIncreaseDebt(op.amount));
|
|
384
378
|
break;
|
|
385
379
|
case "decreaseDebt":
|
|
386
|
-
calls.push(facade.prepareChangeDebt(op.amount, true));
|
|
380
|
+
calls.push(op.full ? facade.prepareDecreaseDebtFull() : facade.prepareChangeDebt(op.amount, true));
|
|
387
381
|
break;
|
|
388
382
|
case "addCollateral":
|
|
389
383
|
calls.push(...facade.prepareAddCollateral([{
|
|
@@ -392,7 +386,7 @@ var CreditAccountsServiceV310 = class extends require_sdk_base_SDKConstruct.SDKC
|
|
|
392
386
|
}], {}));
|
|
393
387
|
break;
|
|
394
388
|
case "withdrawCollateral":
|
|
395
|
-
calls.push(facade.prepareWithdrawCollateral(op.token, op.amount, op.to));
|
|
389
|
+
calls.push(facade.prepareWithdrawCollateral(op.token, op.all ? require_sdk_constants_math.MAX_UINT256 : op.amount, op.to));
|
|
396
390
|
break;
|
|
397
391
|
case "swap":
|
|
398
392
|
case "wrapRwaCollateral":
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_sdk_utils_AddressMap = require("../../utils/AddressMap.js");
|
|
3
2
|
const require_sdk_utils_AddressSet = require("../../utils/AddressSet.js");
|
|
4
3
|
const require_sdk_constants_address_provider = require("../../constants/address-provider.js");
|
|
5
4
|
const require_sdk_constants_addresses = require("../../constants/addresses.js");
|
|
@@ -10,11 +9,8 @@ const require_sdk_utils_hex = require("../../utils/hex.js");
|
|
|
10
9
|
require("../../utils/index.js");
|
|
11
10
|
const require_sdk_base_SDKConstruct = require("../../base/SDKConstruct.js");
|
|
12
11
|
require("../../base/index.js");
|
|
13
|
-
const require_sdk_market_math = require("../../market/math.js");
|
|
14
|
-
const require_sdk_market_credit_dominantCollateral = require("../../market/credit/dominantCollateral.js");
|
|
15
12
|
const require_sdk_utils_viem_simulateWithPriceUpdates = require("../../utils/viem/simulateWithPriceUpdates.js");
|
|
16
13
|
require("../../utils/viem/index.js");
|
|
17
|
-
require("../../market/index.js");
|
|
18
14
|
const require_abi_rwa_iRWAFactory = require("../../../abi/rwa/iRWAFactory.js");
|
|
19
15
|
const require_sdk_accounts_credit_account_compressor_CreditAccountCompressorV310Contract = require("./CreditAccountCompressorV310Contract.js");
|
|
20
16
|
//#region src/sdk/accounts/credit-account-compressor/CreditAccountCompressor.ts
|
|
@@ -22,9 +18,8 @@ const require_sdk_accounts_credit_account_compressor_CreditAccountCompressorV310
|
|
|
22
18
|
* Reads credit accounts of the current chain.
|
|
23
19
|
*
|
|
24
20
|
* Stitches the credit account compressor together with the RWA factories (for
|
|
25
|
-
* accounts owned via an investor EOA) and
|
|
26
|
-
*
|
|
27
|
-
* either as raw account data or as {@link StrategyPosition}s.
|
|
21
|
+
* accounts owned via an investor EOA), and describes the result as raw
|
|
22
|
+
* account data.
|
|
28
23
|
*
|
|
29
24
|
* TODO: create and deploy new compressor contract onchain to avoid all this stitching
|
|
30
25
|
**/
|
|
@@ -174,89 +169,6 @@ var CreditAccountCompressor = class extends require_sdk_base_SDKConstruct.SDKCon
|
|
|
174
169
|
return filtered.sort((a, b) => Number(a.healthFactor - b.healthFactor));
|
|
175
170
|
}
|
|
176
171
|
/**
|
|
177
|
-
* Describes all credit accounts of a wallet as strategy positions.
|
|
178
|
-
*
|
|
179
|
-
* @param props - {@link ListStrategyPositionsProps}
|
|
180
|
-
**/
|
|
181
|
-
async listPositions(props) {
|
|
182
|
-
const { owner, includeZeroDebt, blockNumber } = props;
|
|
183
|
-
const [accounts] = await Promise.all([this.getBorrowerCreditAccounts(owner, { includeZeroDebt }, blockNumber), this.sdk.withdrawalCompressor?.loadWithdrawableAssets(void 0, blockNumber)]);
|
|
184
|
-
const describable = accounts.filter((ca) => {
|
|
185
|
-
if (!ca.success) this.logger?.warn(`cannot describe position of ${this.labelAddress(ca.creditAccount)}: collateral computation failed`);
|
|
186
|
-
return ca.success;
|
|
187
|
-
});
|
|
188
|
-
const withdrawals = await Promise.all(describable.map((ca) => this.#accountWithdrawals(ca, blockNumber)));
|
|
189
|
-
return describable.map((ca, i) => this.#toStrategyPosition(ca, withdrawals[i] ?? new require_sdk_utils_AddressMap.AddressMap()));
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Builds one strategy position from an account snapshot.
|
|
193
|
-
*
|
|
194
|
-
* @param withdrawals - Delayed withdrawals of the account, keyed by the
|
|
195
|
-
* phantom token that represents them on it.
|
|
196
|
-
**/
|
|
197
|
-
#toStrategyPosition(ca, withdrawals) {
|
|
198
|
-
const suite = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
199
|
-
const { market } = suite;
|
|
200
|
-
const { priceOracle } = market;
|
|
201
|
-
const { pool } = market.pool;
|
|
202
|
-
const token = this.sdk.tokensMeta.mustGetToken(market.unwrappedUnderlying);
|
|
203
|
-
const totalDebtValue = ca.debt + ca.accruedInterest + ca.accruedFees;
|
|
204
|
-
const collateral = require_sdk_market_credit_dominantCollateral.dominantCollateral(ca, market);
|
|
205
|
-
return {
|
|
206
|
-
kind: "strategy",
|
|
207
|
-
chainId: this.sdk.chainId,
|
|
208
|
-
creditManager: ca.creditManager,
|
|
209
|
-
creditAccount: ca.creditAccount,
|
|
210
|
-
name: collateral ? suite.strategyName(collateral) : token.symbol,
|
|
211
|
-
targetCollateral: collateral ? this.sdk.tokensMeta.mustGetToken(collateral) : null,
|
|
212
|
-
leverage: require_sdk_market_math.positionLeverage(totalDebtValue, ca.totalValue),
|
|
213
|
-
borrowApy: require_sdk_market_math.borrowApyBps(pool.baseInterestRate, suite.creditManager.feeInterest),
|
|
214
|
-
totalDebt: {
|
|
215
|
-
token,
|
|
216
|
-
value: totalDebtValue,
|
|
217
|
-
valueUsd: require_sdk_market_math.usdToNumber(ca.totalDebtUSD)
|
|
218
|
-
},
|
|
219
|
-
totalValue: {
|
|
220
|
-
token,
|
|
221
|
-
value: ca.totalValue,
|
|
222
|
-
valueUsd: require_sdk_market_math.usdToNumber(ca.totalValueUSD)
|
|
223
|
-
},
|
|
224
|
-
healthFactor: require_sdk_market_math.healthFactorBps(ca.healthFactor),
|
|
225
|
-
collaterals: ca.tokens.flatMap((t) => {
|
|
226
|
-
if ((t.mask & ca.enabledTokensMask) === 0n || t.balance <= 10n) return [];
|
|
227
|
-
return [{
|
|
228
|
-
collateral: priceOracle.toTokenAmount(t.token, t.balance),
|
|
229
|
-
quota: priceOracle.toTokenAmount(market.underlying, t.quota),
|
|
230
|
-
withdrawals: withdrawals.get(t.token) ?? []
|
|
231
|
-
}];
|
|
232
|
-
})
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* Delayed withdrawals of one account, keyed by the phantom token that
|
|
237
|
-
* represents them on it, so that each collateral row can pick up its own.
|
|
238
|
-
**/
|
|
239
|
-
async #accountWithdrawals(ca, blockNumber) {
|
|
240
|
-
const compressor = this.sdk.withdrawalCompressor;
|
|
241
|
-
const byPhantomToken = new require_sdk_utils_AddressMap.AddressMap(void 0, "accountWithdrawals");
|
|
242
|
-
const holdsPhantomToken = ca.tokens.some((t) => t.balance > 10n && compressor?.getWithdrawalSourceToken(t.token) !== void 0);
|
|
243
|
-
if (!compressor || !holdsPhantomToken) return byPhantomToken;
|
|
244
|
-
const { priceOracle } = this.sdk.marketRegister.findByCreditManager(ca.creditManager);
|
|
245
|
-
const { claimable, pending } = await compressor.getCurrentWithdrawals(ca.creditAccount, blockNumber);
|
|
246
|
-
const add = (w, outputs, claimableAt) => {
|
|
247
|
-
const assets = outputs.map((o) => ({
|
|
248
|
-
isDelayed: true,
|
|
249
|
-
...priceOracle.toTokenAmount(o.token, o.amount),
|
|
250
|
-
redeemer: w.redeemer,
|
|
251
|
-
claimableAt: claimableAt === void 0 ? void 0 : Number(claimableAt)
|
|
252
|
-
}));
|
|
253
|
-
byPhantomToken.upsert(w.withdrawalPhantomToken, [...byPhantomToken.get(w.withdrawalPhantomToken) ?? [], ...assets]);
|
|
254
|
-
};
|
|
255
|
-
for (const w of claimable) add(w, w.outputs);
|
|
256
|
-
for (const w of pending) add(w, w.expectedOutputs, w.claimableAt);
|
|
257
|
-
return byPhantomToken;
|
|
258
|
-
}
|
|
259
|
-
/**
|
|
260
172
|
* Credit account compressor contract of the current chain.
|
|
261
173
|
*
|
|
262
174
|
* Resolved on every access, because the address provider is only populated
|
|
@@ -6,7 +6,8 @@ const require_sdk_accounts_credit_account_compressor_CreditAccountCompressorV310
|
|
|
6
6
|
const require_sdk_accounts_credit_account_compressor_CreditAccountCompressor = require("./credit-account-compressor/CreditAccountCompressor.js");
|
|
7
7
|
require("./credit-account-compressor/index.js");
|
|
8
8
|
const require_sdk_accounts_CreditAccountsServiceV310 = require("./CreditAccountsServiceV310.js");
|
|
9
|
-
const
|
|
9
|
+
const require_sdk_accounts_intents_types = require("./intents/types.js");
|
|
10
|
+
const require_sdk_accounts_intents_utils_credit_account_slice = require("./intents/utils/credit-account-slice.js");
|
|
10
11
|
const require_sdk_accounts_intents_index = require("./intents/index.js");
|
|
11
12
|
const require_sdk_accounts_liquidations_constants = require("./liquidations/constants.js");
|
|
12
13
|
const require_sdk_accounts_liquidations_LiquidationsService = require("./liquidations/LiquidationsService.js");
|
|
@@ -33,6 +34,7 @@ exports.CreditAccountOperationsService = require_sdk_accounts_intents_index.Cred
|
|
|
33
34
|
exports.CreditAccountsServiceV310 = require_sdk_accounts_CreditAccountsServiceV310.CreditAccountsServiceV310;
|
|
34
35
|
exports.DELAYED_INTENT_TYPES = require_sdk_accounts_withdrawal_compressor_intent_codec.DELAYED_INTENT_TYPES;
|
|
35
36
|
exports.DELAYED_INTENT_VERSION = require_sdk_accounts_withdrawal_compressor_intent_codec.DELAYED_INTENT_VERSION;
|
|
37
|
+
exports.IntentPreviewError = require_sdk_accounts_intents_types.IntentPreviewError;
|
|
36
38
|
exports.InvalidDelayedIntentError = require_sdk_accounts_withdrawal_compressor_errors.InvalidDelayedIntentError;
|
|
37
39
|
exports.LIQUIDATION_APPROVAL_BUFFER = require_sdk_accounts_liquidations_constants.LIQUIDATION_APPROVAL_BUFFER;
|
|
38
40
|
exports.LIQUIDATION_COMPRESSOR_V313_ADDRESS = require_sdk_accounts_liquidations_constants.LIQUIDATION_COMPRESSOR_V313_ADDRESS;
|
|
@@ -47,10 +49,11 @@ exports.createRedemptionLogger = require_sdk_accounts_withdrawal_compressor_crea
|
|
|
47
49
|
exports.createWithdrawalCompressor = require_sdk_accounts_withdrawal_compressor_createWithdrawalCompressor.createWithdrawalCompressor;
|
|
48
50
|
exports.decodeDelayedIntent = require_sdk_accounts_withdrawal_compressor_intent_codec.decodeDelayedIntent;
|
|
49
51
|
exports.encodeDelayedIntent = require_sdk_accounts_withdrawal_compressor_intent_codec.encodeDelayedIntent;
|
|
52
|
+
exports.fetchCreditAccountSlice = require_sdk_accounts_intents_utils_credit_account_slice.fetchCreditAccountSlice;
|
|
50
53
|
exports.getWithdrawalCompressorAddress = require_sdk_accounts_withdrawal_compressor_addresses.getWithdrawalCompressorAddress;
|
|
51
54
|
exports.iCreditAccountAbi = require_sdk_accounts_withdrawal_compressor_AbstractWithdrawalCompressorContract.iCreditAccountAbi;
|
|
52
|
-
exports.primaryInstantOutput = require_sdk_accounts_intents_operations_claim_delayed_index.primaryInstantOutput;
|
|
53
55
|
exports.toClaimableWithdrawal = require_sdk_accounts_withdrawal_compressor_AbstractWithdrawalCompressorContract.toClaimableWithdrawal;
|
|
56
|
+
exports.toCreditAccountSlice = require_sdk_accounts_intents_utils_credit_account_slice.toCreditAccountSlice;
|
|
54
57
|
exports.toPendingWithdrawal = require_sdk_accounts_withdrawal_compressor_AbstractWithdrawalCompressorContract.toPendingWithdrawal;
|
|
55
58
|
exports.toRequestableWithdrawal = require_sdk_accounts_withdrawal_compressor_AbstractWithdrawalCompressorContract.toRequestableWithdrawal;
|
|
56
59
|
exports.toWithdrawalStatus = require_sdk_accounts_withdrawal_compressor_types.toWithdrawalStatus;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("../../constants/math.js");
|
|
3
|
+
require("../../constants/index.js");
|
|
4
|
+
const require_sdk_accounts_intents_types = require("./types.js");
|
|
5
|
+
const require_sdk_accounts_intents_utils_common = require("./utils/common.js");
|
|
6
|
+
const require_sdk_accounts_intents_utils_pick_token = require("./utils/pick-token.js");
|
|
7
|
+
//#region src/sdk/accounts/intents/guards.ts
|
|
8
|
+
/**
|
|
9
|
+
* What the market itself refuses, checked before anything is quoted.
|
|
10
|
+
*
|
|
11
|
+
* The planners answer for the arithmetic of an intent and the ledger for the
|
|
12
|
+
* balances it moves, but neither can see that the facade is paused or that the
|
|
13
|
+
* pool has run out of what it lends. On-chain those come back as a reverted
|
|
14
|
+
* multicall with a selector no form can explain, so they are read from the
|
|
15
|
+
* loaded market and reported as refusals instead.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* The facade takes no multicall while it is paused or past its expiration, so
|
|
19
|
+
* every intent the engine previews would revert on arrival.
|
|
20
|
+
*/
|
|
21
|
+
function assertMarketOperable(suite) {
|
|
22
|
+
if (suite.isPaused) throw new require_sdk_accounts_intents_types.IntentPreviewError("marketPaused", `${suite.creditManager.address} is paused`);
|
|
23
|
+
if (suite.isExpired) throw new require_sdk_accounts_intents_types.IntentPreviewError("marketExpired", `${suite.creditManager.address} expired at ${suite.creditFacade.expirationDate}`);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* What the pool will hand this manager in one transaction: the tightest of its
|
|
27
|
+
* free liquidity, the manager's remaining debt limit and the per-block cap the
|
|
28
|
+
* facade puts on a single borrow. A zero multiplier switches borrowing off
|
|
29
|
+
* outright, which reads here as nothing being available.
|
|
30
|
+
*/
|
|
31
|
+
function borrowable(suite) {
|
|
32
|
+
const { pool } = suite.market.pool;
|
|
33
|
+
const { maxDebtPerBlockMultiplier, maxDebt } = suite.creditFacade;
|
|
34
|
+
if (maxDebtPerBlockMultiplier === 0) return 0n;
|
|
35
|
+
const available = pool.creditManagerDebtParams.get(suite.creditManager.address)?.available;
|
|
36
|
+
return [
|
|
37
|
+
pool.availableLiquidity,
|
|
38
|
+
maxDebt * BigInt(maxDebtPerBlockMultiplier),
|
|
39
|
+
...available === void 0 ? [] : [available]
|
|
40
|
+
].reduce((a, b) => a < b ? a : b);
|
|
41
|
+
}
|
|
42
|
+
/** The pool has to be able to lend what the plan means to draw. */
|
|
43
|
+
function assertCanBorrow(suite, amount) {
|
|
44
|
+
const limit = borrowable(suite);
|
|
45
|
+
if (amount > limit) throw new require_sdk_accounts_intents_types.IntentPreviewError("insufficientPoolLiquidity", `borrow: ${amount} exceeds what the pool can lend now (${limit})`);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* What the account is allowed to end up holding more of than it started with.
|
|
49
|
+
*
|
|
50
|
+
* A forbidden token may be sold and may leave, but its balance must not grow —
|
|
51
|
+
* the facade checks exactly that at the end of the multicall. A token the
|
|
52
|
+
* market takes no quota for is not forbidden, only worthless as collateral:
|
|
53
|
+
* buying one builds a position the collateral check cannot count, so the plan
|
|
54
|
+
* is refused before it is signed rather than after it reverts.
|
|
55
|
+
*
|
|
56
|
+
* The underlying answers to neither rule, and a phantom token is a redemption
|
|
57
|
+
* in flight rather than a holding.
|
|
58
|
+
*/
|
|
59
|
+
function assertGrowthAllowed(args) {
|
|
60
|
+
const { sdk, suite, market, before, after } = args;
|
|
61
|
+
const forbidden = forbiddenTokens(suite);
|
|
62
|
+
const underlying = market.pool.underlying;
|
|
63
|
+
for (const { token, balance } of after) {
|
|
64
|
+
if (balance <= (before.find((a) => require_sdk_accounts_intents_utils_common.eq(a.token, token))?.balance ?? 0n)) continue;
|
|
65
|
+
if (forbidden.some((f) => require_sdk_accounts_intents_utils_common.eq(f, token))) throw new require_sdk_accounts_intents_types.IntentPreviewError("forbiddenToken", `${token} is forbidden in this market and the plan buys more of it`);
|
|
66
|
+
if (require_sdk_accounts_intents_utils_common.eq(token, underlying) || require_sdk_accounts_intents_utils_pick_token.isPhantomToken(sdk, token)) continue;
|
|
67
|
+
if (!market.pool.pqk.hasActiveQuota(token)) throw new require_sdk_accounts_intents_types.IntentPreviewError("quotaLimitReached", `${token} takes no quota in this market, so it counts as no collateral`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/** Tokens the facade's mask flags, which is indexed by collateral position. */
|
|
71
|
+
function forbiddenTokens(suite) {
|
|
72
|
+
const mask = suite.creditFacade.forbiddenTokensMask;
|
|
73
|
+
if (mask === 0n) return [];
|
|
74
|
+
return suite.creditManager.collateralTokens.filter((_, i) => (mask & 1n << BigInt(i)) !== 0n);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The facade weighs the account against its debt at the end of every multicall
|
|
78
|
+
* and reverts if the collateral does not cover it, so a plan that lands the
|
|
79
|
+
* account below water is refused here.
|
|
80
|
+
*
|
|
81
|
+
* The bar is the health factor of the state the plan projects: collateral under
|
|
82
|
+
* liquidation thresholds, capped by quota, against the debt. Note that a
|
|
83
|
+
* position already underwater cannot be nursed back one step at a time — the
|
|
84
|
+
* check is on where the transaction ends, not on whether it improved things.
|
|
85
|
+
*
|
|
86
|
+
* @remarks
|
|
87
|
+
* The caller decides the pricing the factor was computed at: main prices, or
|
|
88
|
+
* the safe ones the facade switches to when the call hands funds over. A token
|
|
89
|
+
* whose reserve feed the SDK cannot read keeps its main price, so a plan can
|
|
90
|
+
* still be refused on-chain after passing here.
|
|
91
|
+
*/
|
|
92
|
+
function assertCollateralised(healthFactorBps) {
|
|
93
|
+
if (healthFactorBps < Number(10000n)) throw new require_sdk_accounts_intents_types.IntentPreviewError("insufficientCollateral", `the account would end at a health factor of ${healthFactorBps}, below 1.0`);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* A quota can only be raised as far as the market still has room for: past the
|
|
97
|
+
* token's limit the keeper takes nothing more, whoever is asking.
|
|
98
|
+
*/
|
|
99
|
+
function assertQuotaHeadroom(market, increases) {
|
|
100
|
+
for (const { token, balance } of increases) {
|
|
101
|
+
if (balance <= 0n) continue;
|
|
102
|
+
const quota = market.pool.pqk.quotas.get(token);
|
|
103
|
+
if (!quota) continue;
|
|
104
|
+
const left = quota.limit - quota.totalQuoted;
|
|
105
|
+
if (balance > left) throw new require_sdk_accounts_intents_types.IntentPreviewError("quotaLimitReached", `${token} has ${left} of quota left, the plan needs ${balance}`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
//#endregion
|
|
109
|
+
exports.assertCanBorrow = assertCanBorrow;
|
|
110
|
+
exports.assertCollateralised = assertCollateralised;
|
|
111
|
+
exports.assertGrowthAllowed = assertGrowthAllowed;
|
|
112
|
+
exports.assertMarketOperable = assertMarketOperable;
|
|
113
|
+
exports.assertQuotaHeadroom = assertQuotaHeadroom;
|
|
114
|
+
exports.borrowable = borrowable;
|