@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
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { toRouterCaSlice } from "./common.js";
|
|
2
|
+
//#region src/sdk/accounts/intents/utils/router-path.ts
|
|
3
|
+
/**
|
|
4
|
+
* The engine's only door to the pathfinder.
|
|
5
|
+
*
|
|
6
|
+
* Deliberately not a quoter abstraction with an oracle-priced twin: paths are
|
|
7
|
+
* always resolved on-chain, because a preview whose swap amounts came from
|
|
8
|
+
* oracle prices could not produce the calldata that realises them.
|
|
9
|
+
*/
|
|
10
|
+
function createRouterPaths(args) {
|
|
11
|
+
const { sdk, creditAccount, slippage } = args;
|
|
12
|
+
const suite = sdk.marketRegister.findCreditManager(creditAccount.creditManager);
|
|
13
|
+
const cmSlice = {
|
|
14
|
+
address: suite.creditManager.address.toLowerCase(),
|
|
15
|
+
creditFacade: suite.creditFacade.address.toLowerCase(),
|
|
16
|
+
collateralTokens: suite.creditManager.collateralTokens.map((t) => t.toLowerCase())
|
|
17
|
+
};
|
|
18
|
+
const router = sdk.routerFor({ creditFacade: suite.creditFacade.address });
|
|
19
|
+
return {
|
|
20
|
+
async swap({ tokenIn, tokenOut, amount, keep = 0n }) {
|
|
21
|
+
if (amount <= 0n) return {
|
|
22
|
+
amount: 0n,
|
|
23
|
+
minAmount: 0n,
|
|
24
|
+
calls: []
|
|
25
|
+
};
|
|
26
|
+
if (keep < 0n) throw new Error(`swap: spending ${amount} of ${tokenIn} exceeds its balance`);
|
|
27
|
+
if (keep > 0n) {
|
|
28
|
+
const expectedBalances = [{
|
|
29
|
+
token: tokenIn,
|
|
30
|
+
balance: amount + keep
|
|
31
|
+
}];
|
|
32
|
+
return router.findManyToOnePath({
|
|
33
|
+
creditAccount: toRouterCaSlice(creditAccount, expectedBalances),
|
|
34
|
+
creditManager: cmSlice,
|
|
35
|
+
expectedBalances,
|
|
36
|
+
leftoverBalances: [{
|
|
37
|
+
token: tokenIn,
|
|
38
|
+
balance: keep
|
|
39
|
+
}],
|
|
40
|
+
target: tokenOut,
|
|
41
|
+
slippage
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return router.findOneTokenPath({
|
|
45
|
+
creditAccount: toRouterCaSlice(creditAccount, [{
|
|
46
|
+
token: tokenIn,
|
|
47
|
+
balance: amount
|
|
48
|
+
}]),
|
|
49
|
+
creditManager: cmSlice,
|
|
50
|
+
tokenIn,
|
|
51
|
+
tokenOut,
|
|
52
|
+
amount,
|
|
53
|
+
slippage
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
async closeAll({ balances }) {
|
|
57
|
+
const { amount, minAmount, calls } = await router.findBestClosePath({
|
|
58
|
+
creditAccount: toRouterCaSlice(creditAccount, balances),
|
|
59
|
+
creditManager: cmSlice,
|
|
60
|
+
balances: {
|
|
61
|
+
expectedBalances: balances,
|
|
62
|
+
leftoverBalances: [],
|
|
63
|
+
tokensToClaim: []
|
|
64
|
+
},
|
|
65
|
+
slippage
|
|
66
|
+
});
|
|
67
|
+
return {
|
|
68
|
+
amount,
|
|
69
|
+
minAmount,
|
|
70
|
+
calls: [...calls]
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
async openStrategy({ expectedBalances, leftoverBalances, target }) {
|
|
74
|
+
return router.findOpenStrategyPath({
|
|
75
|
+
creditManager: cmSlice,
|
|
76
|
+
expectedBalances,
|
|
77
|
+
leftoverBalances,
|
|
78
|
+
target,
|
|
79
|
+
slippage
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
85
|
+
export { createRouterPaths };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { eq } from "./utils/common.js";
|
|
2
|
+
import { convertAmount } from "./utils/convert-amount.js";
|
|
3
|
+
import { pickFattestNonPhantomToken } from "./utils/pick-token.js";
|
|
4
|
+
//#region src/sdk/accounts/intents/view.ts
|
|
5
|
+
/**
|
|
6
|
+
* The account as the planners see it: a handful of numbers in underlying units
|
|
7
|
+
* plus balance / price lookups. Read once per preview.
|
|
8
|
+
*
|
|
9
|
+
* TVL uses the RWA-aware conversion so an `rwa.asset` balance without a direct
|
|
10
|
+
* pool price still counts at its wrapped value instead of throwing.
|
|
11
|
+
*/
|
|
12
|
+
function accountView(creditAccount, sdk) {
|
|
13
|
+
const { underlying, creditManager } = creditAccount;
|
|
14
|
+
const price = convertAmount(sdk, creditManager);
|
|
15
|
+
const { creditFacade } = sdk.marketRegister.findCreditManager(creditManager);
|
|
16
|
+
let totalValue = 0n;
|
|
17
|
+
for (const t of creditAccount.tokens) totalValue += price(t.token, underlying, t.balance);
|
|
18
|
+
return {
|
|
19
|
+
underlying,
|
|
20
|
+
rwaAsset: sdk.tokensMeta.rwaUnderlyings.get(underlying)?.asset,
|
|
21
|
+
debt: creditAccount.accountDebt,
|
|
22
|
+
collateral: totalValue - creditAccount.accountDebt,
|
|
23
|
+
band: {
|
|
24
|
+
minDebt: creditFacade.minDebt,
|
|
25
|
+
maxDebt: creditFacade.maxDebt
|
|
26
|
+
},
|
|
27
|
+
balanceOf: (token) => creditAccount.tokens.find((t) => eq(t.token, token))?.balance ?? 0n,
|
|
28
|
+
price,
|
|
29
|
+
fattest: (exclude) => pickFattestNonPhantomToken({
|
|
30
|
+
creditAccount,
|
|
31
|
+
sdk,
|
|
32
|
+
exclude
|
|
33
|
+
})?.token
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
export { accountView };
|
|
@@ -32,7 +32,6 @@ var LiquidationsService = class extends SDKConstruct {
|
|
|
32
32
|
* Accounts whose collateral computation failed are excluded.
|
|
33
33
|
**/
|
|
34
34
|
async getLiquidatableAccounts(props) {
|
|
35
|
-
await this.sdk.withdrawalCompressor?.loadWithdrawableAssets(void 0, props?.blockNumber);
|
|
36
35
|
const unhealthy = await this.sdk.accounts.getCreditAccounts({
|
|
37
36
|
maxHealthFactor: WAD - 1n,
|
|
38
37
|
includeZeroDebt: false
|
|
@@ -59,7 +58,6 @@ var LiquidationsService = class extends SDKConstruct {
|
|
|
59
58
|
const ca = await this.#getCreditAccountData(creditAccount, blockNumber);
|
|
60
59
|
const suite = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
61
60
|
const { priceOracle } = suite.market;
|
|
62
|
-
await this.sdk.withdrawalCompressor?.loadWithdrawableAssets(void 0, blockNumber);
|
|
63
61
|
const account = this.#buildAccount(ca, suite);
|
|
64
62
|
const data = await this.#getLiquidationData(ca, liquidator, ignoreReservePrices, blockNumber);
|
|
65
63
|
return {
|
|
@@ -96,7 +94,6 @@ var LiquidationsService = class extends SDKConstruct {
|
|
|
96
94
|
async getLiquidationPositions(props) {
|
|
97
95
|
const compressor = this.sdk.withdrawalCompressor;
|
|
98
96
|
if (!compressor) return [];
|
|
99
|
-
await compressor.loadWithdrawableAssets(void 0, props.blockNumber);
|
|
100
97
|
const phantomTokens = new AddressSet(compressor.getWithdrawableAssets().map((a) => a.withdrawalPhantomToken));
|
|
101
98
|
const { claimable, pending } = await compressor.getExternalAccountCurrentWithdrawals({
|
|
102
99
|
account: props.liquidator,
|
|
@@ -3,8 +3,10 @@ import "../../constants/addresses.js";
|
|
|
3
3
|
import "../../constants/index.js";
|
|
4
4
|
import { hexEq } from "../../utils/hex.js";
|
|
5
5
|
import "../../utils/index.js";
|
|
6
|
+
import { executeMulticallBatches } from "../../utils/viem/executeMulticallBatches.js";
|
|
6
7
|
import { BaseContract } from "../../base/BaseContract.js";
|
|
7
8
|
import "../../base/index.js";
|
|
9
|
+
import "../../utils/viem/index.js";
|
|
8
10
|
import { decodeDelayedIntent } from "./intent-codec.js";
|
|
9
11
|
import { isAddressEqual } from "viem";
|
|
10
12
|
//#region src/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.ts
|
|
@@ -57,37 +59,46 @@ var AbstractWithdrawalCompressorContract = class extends BaseContract {
|
|
|
57
59
|
**/
|
|
58
60
|
getWithdrawableAssets(...creditManagers) {
|
|
59
61
|
const cache = this.#withdrawableAssets;
|
|
60
|
-
if (!cache) throw new Error("withdrawable assets are not loaded,
|
|
62
|
+
if (!cache) throw new Error("withdrawable assets are not loaded, check if the sdk was properly attached or hydrated");
|
|
61
63
|
if (creditManagers.length === 0) return cache.values().flat();
|
|
62
64
|
return creditManagers.flatMap((cm) => cache.get(cm) ?? []);
|
|
63
65
|
}
|
|
64
66
|
/**
|
|
65
|
-
* {@inheritDoc IWithdrawalCompressorContract.
|
|
67
|
+
* {@inheritDoc IWithdrawalCompressorContract.getLoadWithdrawableAssetsMulticall}
|
|
66
68
|
**/
|
|
67
|
-
|
|
68
|
-
if (this.#withdrawableAssets && !force) return
|
|
69
|
+
getLoadWithdrawableAssetsMulticall(force) {
|
|
70
|
+
if (this.#withdrawableAssets && !force) return {
|
|
71
|
+
contracts: [],
|
|
72
|
+
onResults: () => {}
|
|
73
|
+
};
|
|
69
74
|
const cms = this.#sdk.marketRegister.creditManagers.map((cm) => cm.creditManager.address);
|
|
70
|
-
|
|
75
|
+
return {
|
|
71
76
|
contracts: cms.map((cm) => ({
|
|
72
77
|
address: this.address,
|
|
73
78
|
abi: this.abi,
|
|
74
79
|
functionName: "getWithdrawableAssets",
|
|
75
80
|
args: [cm]
|
|
76
81
|
})),
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
82
|
+
onResults: (resps) => {
|
|
83
|
+
const cache = new AddressMap(void 0, MAP_LABEL);
|
|
84
|
+
for (let i = 0; i < resps.length; i++) {
|
|
85
|
+
const r = resps[i];
|
|
86
|
+
if (r.status !== "success") {
|
|
87
|
+
this.logger?.warn(`failed to get withdrawable assets of credit manager ${cms[i]}: ${r.error}`);
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
const assets = r.result;
|
|
91
|
+
if (assets.length > 0) cache.upsert(cms[i], assets.map((a) => toWithdrawableAsset(a, cms[i])));
|
|
92
|
+
}
|
|
93
|
+
this.#withdrawableAssets = cache;
|
|
87
94
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* {@inheritDoc IWithdrawalCompressorContract.loadWithdrawableAssets}
|
|
99
|
+
**/
|
|
100
|
+
async loadWithdrawableAssets(force, blockNumber) {
|
|
101
|
+
await executeMulticallBatches(this.client, [this.getLoadWithdrawableAssetsMulticall(force)], { blockNumber });
|
|
91
102
|
return this.getWithdrawableAssets();
|
|
92
103
|
}
|
|
93
104
|
/**
|
|
@@ -170,7 +170,7 @@ var BaseContract = class extends Construct {
|
|
|
170
170
|
name: decoded.functionName,
|
|
171
171
|
args: decoded.args
|
|
172
172
|
});
|
|
173
|
-
if (
|
|
173
|
+
if (abiItem?.type !== "function") return `Unknown function: ${decoded.functionName}`;
|
|
174
174
|
const params = this.stringifyFunctionParams(decoded).map((v, i) => `${abiItem.inputs[i].name}: ${v}`);
|
|
175
175
|
return `${this.name}.${decoded.functionName}({${params.join(", ")}})`;
|
|
176
176
|
}
|
|
@@ -4,8 +4,10 @@ import { bytes32ToString } from "../utils/bytes32ToString.js";
|
|
|
4
4
|
import { getAssetType } from "../chain/chains.js";
|
|
5
5
|
import { formatBN } from "../utils/formatter.js";
|
|
6
6
|
import "../utils/index.js";
|
|
7
|
+
import { iExpirableAbi } from "../../abi/iExpirable.js";
|
|
7
8
|
import { iStateSerializerAbi } from "../../abi/iStateSerializer.js";
|
|
8
9
|
import { iVersionAbi } from "../../abi/iVersion.js";
|
|
10
|
+
import { executeMulticallBatches } from "../utils/viem/executeMulticallBatches.js";
|
|
9
11
|
//#region src/sdk/base/TokensMeta.ts
|
|
10
12
|
/**
|
|
11
13
|
* Registry of token metadata (symbol, decimals, phantom type) keyed by address.
|
|
@@ -62,7 +64,7 @@ var TokensMeta = class extends AddressMap {
|
|
|
62
64
|
* @returns
|
|
63
65
|
*/
|
|
64
66
|
isPhantomToken(t) {
|
|
65
|
-
if (!this.#tokenDataLoaded.has(t.addr)) throw new Error(`extended token data not loaded for ${t.symbol} (${t.addr})`);
|
|
67
|
+
if (!this.#tokenDataLoaded.has(t.addr)) throw new Error(`extended token data not loaded for ${t.symbol} (${t.addr}), check if the sdk was properly attached or hydrated`);
|
|
66
68
|
return !!t.contractType?.startsWith("PHANTOM_TOKEN::");
|
|
67
69
|
}
|
|
68
70
|
/**
|
|
@@ -167,44 +169,93 @@ var TokensMeta = class extends AddressMap {
|
|
|
167
169
|
return meta;
|
|
168
170
|
}
|
|
169
171
|
/**
|
|
172
|
+
* @internal
|
|
173
|
+
*
|
|
174
|
+
* Returns the multicall batch that loads extended token data (`contractType`
|
|
175
|
+
* and `serialize()`) for the tokens that do not have it yet. Used by the SDK
|
|
176
|
+
* to warm this cache together with other loaders in a single multicall.
|
|
177
|
+
*
|
|
178
|
+
* @param tokens - tokens to load data for, defaults to all tokens
|
|
179
|
+
**/
|
|
180
|
+
getLoadTokenDataMulticall(...tokens) {
|
|
181
|
+
const tokenz = new AddressSet(tokens.length > 0 ? tokens : this.keys());
|
|
182
|
+
const tokensToLoad = Array.from(tokenz.difference(this.#tokenDataLoaded));
|
|
183
|
+
return {
|
|
184
|
+
contracts: tokensToLoad.flatMap((t) => [
|
|
185
|
+
{
|
|
186
|
+
address: t,
|
|
187
|
+
abi: iVersionAbi,
|
|
188
|
+
functionName: "contractType"
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
address: t,
|
|
192
|
+
abi: iStateSerializerAbi,
|
|
193
|
+
functionName: "serialize"
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
address: t,
|
|
197
|
+
abi: iExpirableAbi,
|
|
198
|
+
functionName: "isExpired"
|
|
199
|
+
}
|
|
200
|
+
]),
|
|
201
|
+
onResults: (resps) => {
|
|
202
|
+
this.#logger?.debug(`loaded data of ${tokensToLoad.length} tokens`);
|
|
203
|
+
for (let i = 0; i < tokensToLoad.length; i++) {
|
|
204
|
+
this.#overrideTokenMeta(tokensToLoad[i], resps[3 * i], resps[3 * i + 1], resps[3 * i + 2]);
|
|
205
|
+
this.#tokenDataLoaded.add(tokensToLoad[i]);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
170
211
|
* Loads token information about phantom tokens
|
|
171
212
|
* In future other custom tokens types that do not have compressors might be handled here
|
|
172
213
|
*
|
|
214
|
+
* Tokens loaded during SDK attach or restored by {@link hydrate} are skipped,
|
|
215
|
+
* so calling this after either is a no-op.
|
|
216
|
+
*
|
|
173
217
|
* @param tokens - tokens to load data for, defaults to all tokens
|
|
174
218
|
*/
|
|
175
219
|
async loadTokenData(...tokens) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
abi: iStateSerializerAbi,
|
|
187
|
-
functionName: "serialize"
|
|
188
|
-
}]),
|
|
189
|
-
allowFailure: true,
|
|
190
|
-
batchSize: 0
|
|
191
|
-
});
|
|
192
|
-
this.#logger?.debug(`loaded ${resp.length} contract types`);
|
|
193
|
-
for (let i = 0; i < tokensToLoad.length; i++) {
|
|
194
|
-
this.#overrideTokenMeta(tokensToLoad[i], resp[2 * i], resp[2 * i + 1]);
|
|
195
|
-
this.#tokenDataLoaded.add(tokensToLoad[i]);
|
|
196
|
-
}
|
|
220
|
+
await executeMulticallBatches(this.#client, [this.getLoadTokenDataMulticall(...tokens)]);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Serializable snapshot of all token metadata, suitable for hydration.
|
|
224
|
+
**/
|
|
225
|
+
get state() {
|
|
226
|
+
return {
|
|
227
|
+
tokens: this.values(),
|
|
228
|
+
extendedLoaded: this.#tokenDataLoaded.asArray()
|
|
229
|
+
};
|
|
197
230
|
}
|
|
198
|
-
|
|
231
|
+
/**
|
|
232
|
+
* Restores token metadata from a previously serialized snapshot,
|
|
233
|
+
* bypassing on-chain reads.
|
|
234
|
+
*
|
|
235
|
+
* Entries are merged into the ones already registered by markets, zappers and
|
|
236
|
+
* the RWA registry (see {@link upsert}), so the snapshot must be applied last
|
|
237
|
+
* for its augmented fields to win.
|
|
238
|
+
*
|
|
239
|
+
* @param state - Token metadata snapshot.
|
|
240
|
+
**/
|
|
241
|
+
hydrate(state) {
|
|
242
|
+
for (const token of state.tokens) this.upsert(token.addr, token);
|
|
243
|
+
for (const token of state.extendedLoaded) this.#tokenDataLoaded.add(token);
|
|
244
|
+
}
|
|
245
|
+
#overrideTokenMeta(token, contractTypeResp, serializeResp, isExpiredResp) {
|
|
199
246
|
const meta = this.mustGet(token);
|
|
247
|
+
const update = { ...meta };
|
|
200
248
|
if (contractTypeResp.status === "success") {
|
|
201
249
|
const contractType = bytes32ToString(contractTypeResp.result);
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
contractType
|
|
205
|
-
});
|
|
250
|
+
update.contractType = contractType;
|
|
251
|
+
update.serializedParams = serializeResp.status === "success" ? serializeResp.result : void 0;
|
|
206
252
|
this.#logger?.debug(`token ${meta.symbol} is ${contractType}`);
|
|
207
253
|
}
|
|
254
|
+
if (isExpiredResp.status === "success") {
|
|
255
|
+
update.isExpired = isExpiredResp.result;
|
|
256
|
+
this.#logger?.debug(`token ${meta.symbol} is expirable, expired: ${isExpiredResp.result}`);
|
|
257
|
+
}
|
|
258
|
+
if (contractTypeResp.status === "success" || isExpiredResp.status === "success") this.upsert(token, update);
|
|
208
259
|
return this.mustGet(token);
|
|
209
260
|
}
|
|
210
261
|
};
|
package/dist/esm/sdk/index.js
CHANGED
|
@@ -30,6 +30,7 @@ import { ZodAddress, ZodBigInt, ZodHex } from "./utils/zod.js";
|
|
|
30
30
|
import "./utils/index.js";
|
|
31
31
|
import { generateCastTraceCall, getCastTraceArgs } from "./utils/viem/cast.js";
|
|
32
32
|
import { SimulationError, simulateCall } from "./utils/viem/simulateCall.js";
|
|
33
|
+
import { executeMulticallBatches } from "./utils/viem/executeMulticallBatches.js";
|
|
33
34
|
import { TokensMeta } from "./base/TokensMeta.js";
|
|
34
35
|
import { ChainContractsRegister } from "./base/ChainContractsRegister.js";
|
|
35
36
|
import { Construct } from "./base/Construct.js";
|
|
@@ -48,9 +49,10 @@ import { createAdapter } from "./market/adapters/createAdapter.js";
|
|
|
48
49
|
import { CreditConfiguratorV310Contract } from "./market/credit/CreditConfiguratorV310Contract.js";
|
|
49
50
|
import { CreditFacadeV310BaseContract, creditFacadeV310Abi as abi } from "./market/credit/CreditFacadeV310BaseContract.js";
|
|
50
51
|
import { CreditFacadeV310Contract } from "./market/credit/CreditFacadeV310Contract.js";
|
|
51
|
-
import { PARTIAL_LIQUIDATION_BUFFER_BPS,
|
|
52
|
+
import { MAX_LEVERAGE_BUFFER_BPS, PARTIAL_LIQUIDATION_BUFFER_BPS, calcAdditionalBorrowApy, calcBorrowApy, calcMaxLeverage, calcPositionLeverage, calcUtilization, healthFactorBps, minSeizedAmount, optimalHFForPartialLiquidation, optimalRepaidAmount, rayToBps, usdToNumber } from "./market/math.js";
|
|
52
53
|
import { CreditManagerV310Contract } from "./market/credit/CreditManagerV310Contract.js";
|
|
53
54
|
import { dominantCollateral, mustGetDominantCollateral } from "./market/credit/dominantCollateral.js";
|
|
55
|
+
import { NON_STRATEGY_PHANTOM_TOKEN_TYPES, isStrategyCollateral } from "./market/credit/isStrategyCollateral.js";
|
|
54
56
|
import { CreditSuite } from "./market/credit/CreditSuite.js";
|
|
55
57
|
import { expectedBalanceDeltas } from "./market/credit/expectedBalanceDeltas.js";
|
|
56
58
|
import { simulateMulticall } from "./utils/viem/simulateMulticall.js";
|
|
@@ -107,7 +109,8 @@ import "./market/index.js";
|
|
|
107
109
|
import { CreditAccountCompressorV310Contract } from "./accounts/credit-account-compressor/CreditAccountCompressorV310Contract.js";
|
|
108
110
|
import { CreditAccountCompressor } from "./accounts/credit-account-compressor/CreditAccountCompressor.js";
|
|
109
111
|
import { CreditAccountsServiceV310 } from "./accounts/CreditAccountsServiceV310.js";
|
|
110
|
-
import {
|
|
112
|
+
import { IntentPreviewError } from "./accounts/intents/types.js";
|
|
113
|
+
import { fetchCreditAccountSlice, toCreditAccountSlice } from "./accounts/intents/utils/credit-account-slice.js";
|
|
111
114
|
import { CreditAccountOperationsService } from "./accounts/intents/index.js";
|
|
112
115
|
import { LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS } from "./accounts/liquidations/constants.js";
|
|
113
116
|
import { LiquidationsService } from "./accounts/liquidations/LiquidationsService.js";
|
|
@@ -134,9 +137,15 @@ import "./opportunities/index.js";
|
|
|
134
137
|
import { BasePlugin } from "./plugins/BasePlugin.js";
|
|
135
138
|
import { PluginStateVersionError } from "./plugins/errors.js";
|
|
136
139
|
import "./plugins/index.js";
|
|
137
|
-
import { PoolService } from "./pools/PoolService.js";
|
|
140
|
+
import { PoolService, toShares, toSharesUp } from "./pools/PoolService.js";
|
|
138
141
|
import "./pools/index.js";
|
|
142
|
+
import { calcBorrowRate } from "./positions/calcBorrowRate.js";
|
|
143
|
+
import { calcHealthFactor } from "./positions/calcHealthFactor.js";
|
|
144
|
+
import { calcLiquidationPriceForTarget } from "./positions/calcLiquidationPriceForTarget.js";
|
|
145
|
+
import { calcLiquidationPrice } from "./positions/calcLiquidationPrice.js";
|
|
146
|
+
import { calcTimeToLiquidationMs } from "./positions/calcTimeToLiquidationMs.js";
|
|
139
147
|
import { MultichainPositionsService } from "./positions/MultichainPositionsService.js";
|
|
148
|
+
import { accountSnapshotFromCreditAccountData } from "./positions/types.js";
|
|
140
149
|
import { PositionsService } from "./positions/PositionsService.js";
|
|
141
150
|
import "./positions/index.js";
|
|
142
151
|
import { assetsMap } from "./router/helpers.js";
|
|
@@ -147,4 +156,4 @@ import { OnchainSDK, STATE_VERSION } from "./OnchainSDK.js";
|
|
|
147
156
|
import { MultichainSDK } from "./MultichainSDK.js";
|
|
148
157
|
import { attachOptionsSchema, onchainSDKOptionsSchema } from "./options.js";
|
|
149
158
|
import "./types/index.js";
|
|
150
|
-
export { ADDRESS_0X0, ADDRESS_PROVIDER_V310, AP_ACCOUNT_FACTORY, AP_ACL, AP_BOT_LIST, AP_BYTECODE_REPOSITORY, AP_CONTRACTS_REGISTER, AP_CONTROLLER_TIMELOCK, AP_CREDIT_ACCOUNT_COMPRESSOR, AP_CREDIT_SUITE_COMPRESSOR, AP_DATA_COMPRESSOR, AP_DELEVERAGE_BOT_HV, AP_DELEVERAGE_BOT_LV, AP_DELEVERAGE_BOT_PEGGED, AP_GAUGE_COMPRESSOR, AP_GEAR_STAKING, AP_GEAR_TOKEN, AP_INFLATION_ATTACK_BLOCKER, AP_INSOLVENCY_CHECKER, AP_MARKET_COMPRESSOR, AP_MARKET_CONFIGURATOR, AP_PARTIAL_LIQUIDATION_BOT, AP_PERIPHERY_COMPRESSOR, AP_PRICE_FEED_COMPRESSOR, AP_PRICE_FEED_STORE, AP_PRICE_ORACLE, AP_REDEMPTION_LOGGER, AP_REWARDS_COMPRESSOR, AP_ROUTER, AP_RWA_COMPRESSOR, AP_TOKEN_COMPRESSOR, AP_TREASURY, AP_WETH_GATEWAY, AP_WETH_TOKEN, AP_ZAPPER_REGISTER, AP_ZERO_PRICE_FEED, AbstractLPPriceFeedContract, AbstractPriceFeedContract, AbstractWithdrawalCompressorContract, AccountBotsService, AddressMap, AddressProviderV310Contract, AddressSet, AssetsMap, BLOCKS_PER_WEEK_BY_NETWORK, BalancerStablePriceFeedContract, BalancerWeightedPriceFeedContract, BaseContract, BasePlugin, BigIntMath, BotPermissions, BoundedPriceFeedContract, ChainContractsRegister, ChainNotConfiguredError, CompositePriceFeedContract, Construct, ContractParseError, CreditAccountCompressor, CreditAccountCompressorV310Contract, CreditAccountOperationsService, CreditAccountsServiceV310, CreditConfiguratorV310Contract, CreditFacadeV310BaseContract, CreditFacadeV310Contract, CreditManagerV310Contract, CreditSuite, CurveCryptoPriceFeedContract, CurveStablePriceFeedContract, CurveUSDPriceFeedContract, DELAYED_INTENT_TYPES, DELAYED_INTENT_VERSION, DUST_THRESHOLD, Erc4626PriceFeedContract, ExternalPriceFeedContract, GaugeContract, IERC20ZapperContract, IETHZapperContract, InvalidDelayedIntentError, LEVERAGE_DECIMALS, LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS, LinearInterestRateModelContract, LiquidationsService, MAX_INT, MAX_UINT16, MAX_UINT256, MIN_INT96, MULTICALL_ADDRESS, MarketRegister, MarketSuite, MellowLRTPriceFeedContract, MidasLiquidatorContract, MissingSerializedParamsError, MultichainConstruct, MultichainLiquidationsService, MultichainOpportunitiesService, MultichainPositionsService, MultichainSDK, NATIVE_ADDRESS, NOT_DEPLOYED, NO_VERSION, NetworkType, OnchainSDK, OpportunitiesService, PARTIAL_LIQUIDATION_BUFFER_BPS, PERCENTAGE_DECIMALS, PERCENTAGE_FACTOR, PERCENTAGE_FACTOR_1KK, PERIPHERY_CONTRACTS, PHANTOM_TOKEN_CONTRACT_TYPES, PHANTOM_TOKEN_MIDAS_REDEMPTION, PHANTOM_TOKEN_SECURITIZE_REDEMPTION, PRICE_DECIMALS, PRICE_DECIMALS_POW, PartialPriceFeedInitError, PendleTWAPPTPriceFeed, PeripheryCompressorV310Contract, PlaceholderAdapterContract, PlaceholderContract, PluginStateVersionError, PoolService, PoolSuite, PoolV310Contract, PositionsService, PriceFeedRef, PriceFeedRegister, PriceOracleV310Contract, PythPriceFeed, RAMP_DURATION_BY_NETWORK, RAY, RAY_DECIMALS_POW, RWARegistry, RWA_FACTORY_SECURITIZE, RWA_FACTORY_TYPES, RWA_LIQUIDATOR_MIDAS, RWA_LIQUIDATOR_SECURITIZE, RWA_ON_DEMAND_LP_MONOPOLIZED, RWA_UNDERLYING_DEFAULT, RWA_UNDERLYING_ON_DEMAND, RedemptionLoggerV310Contract, RedstonePriceFeedContract, RouterV310Contract, SDKConstruct, SECONDS_PER_YEAR, SECURITIZE_REGISTER_VAULT_TYPES, SLIPPAGE_DECIMALS, STATE_VERSION, SUPPORTED_NETWORKS, SdkAlreadyAttachedError, SdkChainMismatchError, SdkMissingChainStateError, SdkNotAttachedError, SdkStateVersionMismatchError, SdkSyncFailedError, SecuritizeLiquidatorContract, SecuritizeRWAFactory, SimulateWithPriceUpdatesError, SimulationError, TokensMeta, TypedObjectUtils, UnsupportedZapperFunctionError, VERSION_RANGE_310, VotingContractStatus, WAD, WAD_DECIMALS_POW, WithdrawalCompressorV310Contract, WithdrawalCompressorV311Contract, WithdrawalCompressorV313Contract, WstETHPriceFeedContract, YearnPriceFeedContract, ZapperContract, ZeroPriceFeedContract, ZodAddress, ZodBigInt, ZodHex,
|
|
159
|
+
export { ADDRESS_0X0, ADDRESS_PROVIDER_V310, AP_ACCOUNT_FACTORY, AP_ACL, AP_BOT_LIST, AP_BYTECODE_REPOSITORY, AP_CONTRACTS_REGISTER, AP_CONTROLLER_TIMELOCK, AP_CREDIT_ACCOUNT_COMPRESSOR, AP_CREDIT_SUITE_COMPRESSOR, AP_DATA_COMPRESSOR, AP_DELEVERAGE_BOT_HV, AP_DELEVERAGE_BOT_LV, AP_DELEVERAGE_BOT_PEGGED, AP_GAUGE_COMPRESSOR, AP_GEAR_STAKING, AP_GEAR_TOKEN, AP_INFLATION_ATTACK_BLOCKER, AP_INSOLVENCY_CHECKER, AP_MARKET_COMPRESSOR, AP_MARKET_CONFIGURATOR, AP_PARTIAL_LIQUIDATION_BOT, AP_PERIPHERY_COMPRESSOR, AP_PRICE_FEED_COMPRESSOR, AP_PRICE_FEED_STORE, AP_PRICE_ORACLE, AP_REDEMPTION_LOGGER, AP_REWARDS_COMPRESSOR, AP_ROUTER, AP_RWA_COMPRESSOR, AP_TOKEN_COMPRESSOR, AP_TREASURY, AP_WETH_GATEWAY, AP_WETH_TOKEN, AP_ZAPPER_REGISTER, AP_ZERO_PRICE_FEED, AbstractLPPriceFeedContract, AbstractPriceFeedContract, AbstractWithdrawalCompressorContract, AccountBotsService, AddressMap, AddressProviderV310Contract, AddressSet, AssetsMap, BLOCKS_PER_WEEK_BY_NETWORK, BalancerStablePriceFeedContract, BalancerWeightedPriceFeedContract, BaseContract, BasePlugin, BigIntMath, BotPermissions, BoundedPriceFeedContract, ChainContractsRegister, ChainNotConfiguredError, CompositePriceFeedContract, Construct, ContractParseError, CreditAccountCompressor, CreditAccountCompressorV310Contract, CreditAccountOperationsService, CreditAccountsServiceV310, CreditConfiguratorV310Contract, CreditFacadeV310BaseContract, CreditFacadeV310Contract, CreditManagerV310Contract, CreditSuite, CurveCryptoPriceFeedContract, CurveStablePriceFeedContract, CurveUSDPriceFeedContract, DELAYED_INTENT_TYPES, DELAYED_INTENT_VERSION, DUST_THRESHOLD, Erc4626PriceFeedContract, ExternalPriceFeedContract, GaugeContract, IERC20ZapperContract, IETHZapperContract, IntentPreviewError, InvalidDelayedIntentError, LEVERAGE_DECIMALS, LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS, LinearInterestRateModelContract, LiquidationsService, MAX_INT, MAX_LEVERAGE_BUFFER_BPS, MAX_UINT16, MAX_UINT256, MIN_INT96, MULTICALL_ADDRESS, MarketRegister, MarketSuite, MellowLRTPriceFeedContract, MidasLiquidatorContract, MissingSerializedParamsError, MultichainConstruct, MultichainLiquidationsService, MultichainOpportunitiesService, MultichainPositionsService, MultichainSDK, NATIVE_ADDRESS, NON_STRATEGY_PHANTOM_TOKEN_TYPES, NOT_DEPLOYED, NO_VERSION, NetworkType, OnchainSDK, OpportunitiesService, PARTIAL_LIQUIDATION_BUFFER_BPS, PERCENTAGE_DECIMALS, PERCENTAGE_FACTOR, PERCENTAGE_FACTOR_1KK, PERIPHERY_CONTRACTS, PHANTOM_TOKEN_CONTRACT_TYPES, PHANTOM_TOKEN_MIDAS_REDEMPTION, PHANTOM_TOKEN_SECURITIZE_REDEMPTION, PRICE_DECIMALS, PRICE_DECIMALS_POW, PartialPriceFeedInitError, PendleTWAPPTPriceFeed, PeripheryCompressorV310Contract, PlaceholderAdapterContract, PlaceholderContract, PluginStateVersionError, PoolService, PoolSuite, PoolV310Contract, PositionsService, PriceFeedRef, PriceFeedRegister, PriceOracleV310Contract, PythPriceFeed, RAMP_DURATION_BY_NETWORK, RAY, RAY_DECIMALS_POW, RWARegistry, RWA_FACTORY_SECURITIZE, RWA_FACTORY_TYPES, RWA_LIQUIDATOR_MIDAS, RWA_LIQUIDATOR_SECURITIZE, RWA_ON_DEMAND_LP_MONOPOLIZED, RWA_UNDERLYING_DEFAULT, RWA_UNDERLYING_ON_DEMAND, RedemptionLoggerV310Contract, RedstonePriceFeedContract, RouterV310Contract, SDKConstruct, SECONDS_PER_YEAR, SECURITIZE_REGISTER_VAULT_TYPES, SLIPPAGE_DECIMALS, STATE_VERSION, SUPPORTED_NETWORKS, SdkAlreadyAttachedError, SdkChainMismatchError, SdkMissingChainStateError, SdkNotAttachedError, SdkStateVersionMismatchError, SdkSyncFailedError, SecuritizeLiquidatorContract, SecuritizeRWAFactory, SimulateWithPriceUpdatesError, SimulationError, TokensMeta, TypedObjectUtils, UnsupportedZapperFunctionError, VERSION_RANGE_310, VotingContractStatus, WAD, WAD_DECIMALS_POW, WithdrawalCompressorV310Contract, WithdrawalCompressorV311Contract, WithdrawalCompressorV313Contract, WstETHPriceFeedContract, YearnPriceFeedContract, ZapperContract, ZeroPriceFeedContract, ZodAddress, ZodBigInt, ZodHex, accountSnapshotFromCreditAccountData, assetsMap, attachOptionsSchema, botPermissionsToString, bytes32ToString, calcAdditionalBorrowApy, calcBorrowApy, calcBorrowRate, calcHealthFactor, calcLiquidationPrice, calcLiquidationPriceForTarget, calcMaxLeverage, calcPositionLeverage, calcTimeToLiquidationMs, calcUtilization, chains, childLogger, createAdapter, createAddressProvider, createPriceOracle, createRawTx, createRedemptionLogger, createRouter, createWithdrawalCompressor, createZapper, abi as creditFacadeV310Abi, decodeDelayedIntent, detectNetwork, dominantCollateral, encodeDelayedIntent, estimateRawTxGas, etherscanApiUrl, etherscanUrl, executeDelegatedMulticalls, executeMulticallBatches, expectedBalanceDeltas, fetchCreditAccountSlice, fetchRedstonePayloads, filterDust, filterDustUSD, findCuratorMarketConfigurator, fmtBinaryMask, formatBN, formatBNvalue, formatDuration, formatLeverage, formatNumberToString_, formatPercentage, formatTimestamp, functionArgsToMap, functionArgsToRecord, generateCastTraceCall, getAssetType, getCastTraceArgs, getChain, getCuratorName, getFunctionSignature, getNetworkType, getRawPriceUpdates, getSimulateWithPriceUpdatesError, getWithdrawalCompressorAddress, halfRAY, healthFactorBps, hexEq, hydrateAddressProvider, iCreditAccountAbi, isDust, isLPPriceFeed, isPublicNetwork, isRWAFactory, isRWAToken, isStrategyCollateral, isSunsetPool, isSunsetStrategy, isSupportedNetwork, isUpdatablePriceFeed, isV310, isVersionRange, json_parse, json_stringify, minSeizedAmount, mustGetDominantCollateral, numberWithCommas, onchainSDKOptionsSchema, optimalHFForPartialLiquidation, optimalRepaidAmount, percentFmt, rayToBps, rayToNumber, retry, sendRawTx, shortAddress, shortHash, simulateCall, simulateMulticall, simulateWithPriceUpdates, toAddress, toBN, toBigInt, toChainIds, toClaimableWithdrawal, toCreditAccountSlice, toPendingWithdrawal, toRequestableWithdrawal, toShares, toSharesUp, toSignificant, toWithdrawalStatus, usdToNumber, watchBlocksAsync };
|
|
@@ -94,29 +94,38 @@ var MarketRegister = class extends ZapperRegister {
|
|
|
94
94
|
* Otherwise only prices are refreshed.
|
|
95
95
|
*
|
|
96
96
|
* @param ignoreUpdateablePrices - When `true`, skips off-chain price updates.
|
|
97
|
+
* @param extra - Additional multicalls to execute in the same batch, so that
|
|
98
|
+
* other registries can be synced without an extra request.
|
|
99
|
+
* @returns `true` when markets were fully reloaded, so that callers can
|
|
100
|
+
* refresh the caches derived from the market set.
|
|
97
101
|
**/
|
|
98
|
-
async syncState(ignoreUpdateablePrices) {
|
|
102
|
+
async syncState(ignoreUpdateablePrices, extra = []) {
|
|
99
103
|
const dirty = this.markets.some((m) => m.dirty) || this.marketConfigurators.some((c) => c.dirty);
|
|
100
104
|
let multicalls;
|
|
101
105
|
let txs = [];
|
|
102
106
|
if (dirty) {
|
|
103
107
|
this.logger?.debug("some markets or market configurators are dirty, reloading everything");
|
|
104
|
-
multicalls = this.getLoadMulticalls([...this.marketFilter.configurators]);
|
|
108
|
+
multicalls = [...this.getLoadMulticalls([...this.marketFilter.configurators]), ...extra];
|
|
105
109
|
if (!ignoreUpdateablePrices) {
|
|
106
110
|
const updatables = await this.sdk.priceFeeds.getPartialUpdatablePriceFeeds([...this.marketFilter.configurators]);
|
|
107
111
|
txs = (await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(updatables)).txs;
|
|
108
112
|
}
|
|
109
113
|
} else if (!ignoreUpdateablePrices) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
114
|
+
const oracles = this.#getOracleSyncMulticalls();
|
|
115
|
+
multicalls = [...oracles, ...extra];
|
|
116
|
+
if (!multicalls.length) return false;
|
|
117
|
+
if (oracles.length) {
|
|
118
|
+
this.logger?.debug(`syncing prices on ${oracles.length} oracles`);
|
|
119
|
+
txs = (await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs()).txs;
|
|
120
|
+
}
|
|
121
|
+
} else if (extra.length) multicalls = extra;
|
|
122
|
+
else return false;
|
|
115
123
|
await executeDelegatedMulticalls(this.client, multicalls, {
|
|
116
124
|
priceUpdates: txs,
|
|
117
125
|
blockNumber: this.sdk.currentBlock,
|
|
118
126
|
gas: this.sdk.gasLimit
|
|
119
127
|
});
|
|
128
|
+
return dirty;
|
|
120
129
|
}
|
|
121
130
|
#getOracleSyncMulticalls(oracles) {
|
|
122
131
|
const uniqOracles = new AddressMap();
|
|
@@ -4,53 +4,84 @@ import { VERSION_RANGE_310 } from "../constants/versions.js";
|
|
|
4
4
|
import "../constants/index.js";
|
|
5
5
|
import { hexEq } from "../utils/hex.js";
|
|
6
6
|
import "../utils/index.js";
|
|
7
|
+
import { executeMulticallBatches } from "../utils/viem/executeMulticallBatches.js";
|
|
7
8
|
import { SDKConstruct } from "../base/SDKConstruct.js";
|
|
8
9
|
import "../base/index.js";
|
|
9
10
|
import { peripheryCompressorAbi } from "../../abi/compressors/peripheryCompressor.js";
|
|
11
|
+
import "../utils/viem/index.js";
|
|
10
12
|
import { createZapper } from "./zapper/createZapper.js";
|
|
11
13
|
import "./zapper/index.js";
|
|
12
14
|
//#region src/sdk/market/ZapperRegister.ts
|
|
13
15
|
var ZapperRegister = class extends SDKConstruct {
|
|
14
16
|
/**
|
|
15
17
|
* Mapping pool.address -> Zapper[]
|
|
16
|
-
*
|
|
18
|
+
* Loaded during SDK attach, or restored by hydration
|
|
17
19
|
*/
|
|
18
20
|
#zappers;
|
|
19
21
|
/**
|
|
20
|
-
*
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
* @internal
|
|
23
|
+
*
|
|
24
|
+
* Returns the multicall batch that loads zappers of all pools from the
|
|
25
|
+
* periphery compressor. Used by the SDK to warm this cache together with
|
|
26
|
+
* other loaders in a single multicall.
|
|
27
|
+
*
|
|
28
|
+
* Returns an empty batch when zappers are already loaded and `force` is not set.
|
|
29
|
+
*
|
|
30
|
+
* @param force - reload zappers even when they are already loaded
|
|
31
|
+
**/
|
|
32
|
+
getLoadZappersMulticall(force) {
|
|
33
|
+
if (!force && this.#zappers) return {
|
|
34
|
+
contracts: [],
|
|
35
|
+
onResults: () => {}
|
|
36
|
+
};
|
|
37
|
+
this.#zappers = new AddressMap(void 0, "zappers");
|
|
38
|
+
const compressor = this.sdk.addressProvider.getLatest(AP_PERIPHERY_COMPRESSOR, VERSION_RANGE_310);
|
|
39
|
+
if (!compressor) {
|
|
40
|
+
this.logger?.warn("no periphery compressor on this chain, skipping zappers");
|
|
41
|
+
return {
|
|
42
|
+
contracts: [],
|
|
43
|
+
onResults: () => {}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const [pcAddr] = compressor;
|
|
25
47
|
this.logger?.debug(`loading zappers with periphery compressor ${pcAddr}`);
|
|
26
48
|
const markets = this.sdk.marketRegister.markets;
|
|
27
|
-
|
|
49
|
+
return {
|
|
28
50
|
contracts: markets.map((m) => ({
|
|
29
51
|
abi: peripheryCompressorAbi,
|
|
30
52
|
address: pcAddr,
|
|
31
53
|
functionName: "getZappers",
|
|
32
54
|
args: [m.configurator.address, m.pool.pool.address]
|
|
33
55
|
})),
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
56
|
+
onResults: (resps) => {
|
|
57
|
+
for (let i = 0; i < resps.length; i++) {
|
|
58
|
+
const { status, result, error } = resps[i];
|
|
59
|
+
const marketConfigurator = markets[i].configurator.address;
|
|
60
|
+
const pool = markets[i].pool.pool.address;
|
|
61
|
+
if (status === "success") for (const z of result) this.#addZapper({
|
|
62
|
+
...z,
|
|
63
|
+
pool,
|
|
64
|
+
type: "base"
|
|
65
|
+
});
|
|
66
|
+
else this.logger?.error(`failed to load zapper for market configurator ${this.labelAddress(marketConfigurator)} and pool ${this.labelAddress(pool)}: ${error}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Load zappers for all pools using periphery compressor, adds hardcoded zappers
|
|
73
|
+
*
|
|
74
|
+
* Zappers loaded during SDK attach or restored by hydration are kept unless
|
|
75
|
+
* `force` is set, so calling this after either is a no-op.
|
|
76
|
+
*/
|
|
77
|
+
async loadZappers(force) {
|
|
78
|
+
await executeMulticallBatches(this.client, [this.getLoadZappersMulticall(force)]);
|
|
49
79
|
}
|
|
50
80
|
/**
|
|
51
81
|
* Serializable snapshot of all loaded zappers, suitable for hydration.
|
|
52
|
-
* Returns `undefined` when zappers were never loaded (i.e.
|
|
53
|
-
*
|
|
82
|
+
* Returns `undefined` when zappers were never loaded (i.e. the SDK was
|
|
83
|
+
* attached without market configurators), so the not-loaded state round-trips
|
|
84
|
+
* cleanly.
|
|
54
85
|
**/
|
|
55
86
|
get zappersState() {
|
|
56
87
|
if (!this.#zappers) return;
|
|
@@ -102,7 +133,7 @@ var ZapperRegister = class extends SDKConstruct {
|
|
|
102
133
|
}
|
|
103
134
|
}
|
|
104
135
|
get zappers() {
|
|
105
|
-
if (!this.#zappers) throw new Error("zappers not loaded,
|
|
136
|
+
if (!this.#zappers) throw new Error("zappers are not loaded, check if the sdk was properly attached or hydrated");
|
|
106
137
|
return this.#zappers;
|
|
107
138
|
}
|
|
108
139
|
poolZappers(pool) {
|
|
@@ -8,8 +8,7 @@ import { BaseContract } from "../../base/BaseContract.js";
|
|
|
8
8
|
import "../../base/index.js";
|
|
9
9
|
import { createAdapter } from "../adapters/createAdapter.js";
|
|
10
10
|
import "../adapters/index.js";
|
|
11
|
-
import {
|
|
12
|
-
import { isAddressEqual } from "viem";
|
|
11
|
+
import { calcMaxLeverage } from "../math.js";
|
|
13
12
|
//#region src/sdk/market/credit/CreditManagerV310Contract.ts
|
|
14
13
|
const abi = iCreditManagerV310Abi;
|
|
15
14
|
var CreditManagerV310Contract = class extends BaseContract {
|
|
@@ -64,20 +63,10 @@ var CreditManagerV310Contract = class extends BaseContract {
|
|
|
64
63
|
return this.liquidationThresholds.keys();
|
|
65
64
|
}
|
|
66
65
|
/**
|
|
67
|
-
* {@inheritDoc ICreditManagerContract.leverageableCollaterals}
|
|
68
|
-
*/
|
|
69
|
-
get leverageableCollaterals() {
|
|
70
|
-
return this.collateralTokens.filter((token) => {
|
|
71
|
-
if (isAddressEqual(token, this.underlying)) return false;
|
|
72
|
-
const lt = this.liquidationThresholds.get(token);
|
|
73
|
-
return !!lt && lt > 0 && lt < Number(10000n);
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
66
|
* {@inheritDoc ICreditManagerContract.maxLeverage}
|
|
78
67
|
*/
|
|
79
68
|
maxLeverage(collateral) {
|
|
80
|
-
return
|
|
69
|
+
return calcMaxLeverage(this.liquidationThresholds.mustGet(collateral));
|
|
81
70
|
}
|
|
82
71
|
/**
|
|
83
72
|
* {@inheritDoc ICreditManagerContract.liquidationPremium}
|