@gearbox-protocol/sdk 15.1.0-next.1 → 15.1.0-next.10
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 +218 -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 +57 -44
- 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 +132 -3
- package/dist/cjs/sdk/pools/index.js +2 -0
- package/dist/cjs/sdk/positions/PositionsService.js +213 -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 +1 -2
- package/dist/esm/dev/compareOpportunities.js +216 -0
- package/dist/esm/dev/withdrawalUtils.js +1 -1
- 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/plugins/adapters/contracts/ERC4626AdapterContract.js +1 -1
- 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/preview/simulate/simulatePoolOperation.js +1 -1
- package/dist/esm/preview/trace/extractTransfers.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 +4 -10
- 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 +1 -4
- package/dist/esm/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.js +29 -18
- package/dist/esm/sdk/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
- package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
- package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
- package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
- package/dist/esm/sdk/base/BaseContract.js +1 -1
- package/dist/esm/sdk/base/TokensMeta.js +80 -29
- package/dist/esm/sdk/chain/detectNetwork.js +1 -1
- package/dist/esm/sdk/core/createAddressProvider.js +1 -1
- 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/CreditFacadeV310BaseContract.js +1 -1
- 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 +52 -40
- package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +10 -3
- package/dist/esm/sdk/market/pool/PoolV310Contract.js +17 -3
- package/dist/esm/sdk/market/rwa/RWARegistry.js +22 -0
- package/dist/esm/sdk/market/zapper/IETHZapperContract.js +1 -1
- package/dist/esm/sdk/market/zapper/ZapperContract.js +1 -1
- 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 +213 -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/esm/sdk/utils/viem/simulateWithPriceUpdates.js +1 -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 +153 -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 +44 -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,360 @@
|
|
|
1
|
+
import { hexEq } from "../../sdk/utils/hex.js";
|
|
2
|
+
import { MultichainConstruct } from "../../sdk/base/MultichainConstruct.js";
|
|
3
|
+
import { fetchCreditAccountSlice } from "../../sdk/accounts/intents/utils/credit-account-slice.js";
|
|
4
|
+
import { CreditAccountOperationsService } from "../../sdk/accounts/intents/index.js";
|
|
5
|
+
import "../../sdk/index.js";
|
|
6
|
+
//#region src/new-sdk/simulate/SimulateApi.ts
|
|
7
|
+
/**
|
|
8
|
+
* {@inheritDoc OpportunitiesSimulate}
|
|
9
|
+
*
|
|
10
|
+
* Holds no state of its own: it owns the mapping from the public,
|
|
11
|
+
* read-model-shaped request to the engine's intent, and nothing else. All
|
|
12
|
+
* protocol knowledge stays in `CreditAccountOperationsService` and
|
|
13
|
+
* `PoolService`.
|
|
14
|
+
*
|
|
15
|
+
* A simulation names one chain, so it reads through
|
|
16
|
+
* {@link MultichainConstruct.queryChain}: there is no second source to fall back
|
|
17
|
+
* to, hence a chain the SDK does not cover, or one that fails the read, throws
|
|
18
|
+
* rather than answering with empty metadata.
|
|
19
|
+
**/
|
|
20
|
+
var SimulateApi = class extends MultichainConstruct {
|
|
21
|
+
#ensureFresh;
|
|
22
|
+
constructor(sdk, ensureFresh) {
|
|
23
|
+
super(sdk);
|
|
24
|
+
this.#ensureFresh = ensureFresh;
|
|
25
|
+
}
|
|
26
|
+
async queryChain(props) {
|
|
27
|
+
await this.#ensureFresh?.([this.sdk.chain(props.network).chainId]);
|
|
28
|
+
return super.queryChain(props);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* {@inheritDoc OpportunitiesSimulate.delayed}
|
|
32
|
+
**/
|
|
33
|
+
delayed = {
|
|
34
|
+
withdrawStrategy: (position, params) => this.#startDelayedIntent(position, params, {
|
|
35
|
+
type: "WITHDRAW",
|
|
36
|
+
amount: params.amount,
|
|
37
|
+
to: params.to,
|
|
38
|
+
tokenOut: params.tokenOut,
|
|
39
|
+
sourceToken: params.sourceToken
|
|
40
|
+
}),
|
|
41
|
+
adjustLeverage: (position, params) => this.#startDelayedIntent(position, params, {
|
|
42
|
+
type: "ADJUST_LEVERAGE",
|
|
43
|
+
targetLeverage: params.targetLeverage,
|
|
44
|
+
token: params.token
|
|
45
|
+
}),
|
|
46
|
+
finish: (position, params) => this.queryChain({
|
|
47
|
+
network: position.chainId,
|
|
48
|
+
run: async (sdk) => {
|
|
49
|
+
const intent = resumable(params.intent ?? params.claimable.intent);
|
|
50
|
+
if (!intent) return {
|
|
51
|
+
ok: false,
|
|
52
|
+
reason: "noRecordedIntent"
|
|
53
|
+
};
|
|
54
|
+
return service(sdk).finishIntent({
|
|
55
|
+
intent,
|
|
56
|
+
claimable: params.claimable,
|
|
57
|
+
creditAccount: await slice(sdk, position.creditAccount),
|
|
58
|
+
sdk,
|
|
59
|
+
slippage: params.slippage,
|
|
60
|
+
quotaReserve: params.quotaReserve
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* {@inheritDoc OpportunitiesSimulate.deposit}
|
|
67
|
+
**/
|
|
68
|
+
deposit(pool, params) {
|
|
69
|
+
const { marketRegister, pools } = this.sdk.chain(pool.chainId);
|
|
70
|
+
const tokenIn = params.tokenIn ?? marketRegister.findByPool(pool.pool).pool.underlying;
|
|
71
|
+
const tokenOut = lpRoute(params.tokenOut, () => pools.getDepositTokensOut(pool.pool, tokenIn));
|
|
72
|
+
if (!tokenOut) return {
|
|
73
|
+
ok: false,
|
|
74
|
+
reason: "unsupportedTokenPair"
|
|
75
|
+
};
|
|
76
|
+
const preview = pools.simulateDeposit({
|
|
77
|
+
pool: pool.pool,
|
|
78
|
+
amount: params.amount,
|
|
79
|
+
tokenIn,
|
|
80
|
+
tokenOut
|
|
81
|
+
});
|
|
82
|
+
const call = pools.addLiquidity({
|
|
83
|
+
collateral: preview.tokenIn,
|
|
84
|
+
pool: pool.pool,
|
|
85
|
+
wallet: params.wallet,
|
|
86
|
+
meta: pools.getDepositMetadata(pool.pool, tokenIn, tokenOut)
|
|
87
|
+
});
|
|
88
|
+
if (!call) return {
|
|
89
|
+
ok: false,
|
|
90
|
+
reason: "unsupportedTokenPair"
|
|
91
|
+
};
|
|
92
|
+
return {
|
|
93
|
+
ok: true,
|
|
94
|
+
operations: [],
|
|
95
|
+
preview,
|
|
96
|
+
calls: call.calls
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* {@inheritDoc OpportunitiesSimulate.withdraw}
|
|
101
|
+
**/
|
|
102
|
+
withdraw(pool, params) {
|
|
103
|
+
const { pools } = this.sdk.chain(pool.chainId);
|
|
104
|
+
const tokenIn = params.tokenIn ?? pool.pool;
|
|
105
|
+
const tokenOut = lpRoute(params.tokenOut, () => pools.getWithdrawalTokensOut(pool.pool, tokenIn));
|
|
106
|
+
if (!tokenOut) return {
|
|
107
|
+
ok: false,
|
|
108
|
+
reason: "unsupportedTokenPair"
|
|
109
|
+
};
|
|
110
|
+
const preview = pools.simulateWithdraw({
|
|
111
|
+
pool: pool.pool,
|
|
112
|
+
amount: params.amount,
|
|
113
|
+
tokenIn,
|
|
114
|
+
tokenOut
|
|
115
|
+
});
|
|
116
|
+
const { calls } = pools.removeLiquidity({
|
|
117
|
+
pool: pool.pool,
|
|
118
|
+
amount: params.amount,
|
|
119
|
+
wallet: params.wallet,
|
|
120
|
+
permit: void 0,
|
|
121
|
+
meta: pools.getWithdrawalMetadata(pool.pool, tokenIn, tokenOut),
|
|
122
|
+
mode: "withdraw"
|
|
123
|
+
});
|
|
124
|
+
return {
|
|
125
|
+
ok: true,
|
|
126
|
+
operations: [],
|
|
127
|
+
preview,
|
|
128
|
+
calls
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* {@inheritDoc OpportunitiesSimulate.redeem}
|
|
133
|
+
**/
|
|
134
|
+
redeem(pool, params) {
|
|
135
|
+
const { pools } = this.sdk.chain(pool.chainId);
|
|
136
|
+
const tokenIn = params.tokenIn ?? pool.pool;
|
|
137
|
+
const tokenOut = lpRoute(params.tokenOut, () => pools.getWithdrawalTokensOut(pool.pool, tokenIn));
|
|
138
|
+
if (!tokenOut) return {
|
|
139
|
+
ok: false,
|
|
140
|
+
reason: "unsupportedTokenPair"
|
|
141
|
+
};
|
|
142
|
+
const preview = pools.simulateRedeem({
|
|
143
|
+
pool: pool.pool,
|
|
144
|
+
amount: params.amount,
|
|
145
|
+
tokenIn,
|
|
146
|
+
tokenOut
|
|
147
|
+
});
|
|
148
|
+
const { calls } = pools.removeLiquidity({
|
|
149
|
+
pool: pool.pool,
|
|
150
|
+
amount: params.amount,
|
|
151
|
+
wallet: params.wallet,
|
|
152
|
+
permit: void 0,
|
|
153
|
+
meta: pools.getWithdrawalMetadata(pool.pool, tokenIn, tokenOut),
|
|
154
|
+
mode: "redeem"
|
|
155
|
+
});
|
|
156
|
+
return {
|
|
157
|
+
ok: true,
|
|
158
|
+
operations: [],
|
|
159
|
+
preview,
|
|
160
|
+
calls
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* {@inheritDoc OpportunitiesSimulate.openNewStrategy}
|
|
165
|
+
**/
|
|
166
|
+
async openNewStrategy(strategy, params) {
|
|
167
|
+
return this.queryChain({
|
|
168
|
+
network: strategy.chainId,
|
|
169
|
+
run: (sdk) => service(sdk).openStrategyIntent({
|
|
170
|
+
sdk,
|
|
171
|
+
creditManager: strategy.creditManager,
|
|
172
|
+
collateral: params.collateral,
|
|
173
|
+
targetToken: params.targetToken ?? strategy.targetCollateral,
|
|
174
|
+
leverage: params.leverage,
|
|
175
|
+
leftoverBalances: params.leftoverBalances,
|
|
176
|
+
slippage: params.slippage,
|
|
177
|
+
quotaReserve: params.quotaReserve
|
|
178
|
+
})
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* {@inheritDoc OpportunitiesSimulate.depositStrategy}
|
|
183
|
+
**/
|
|
184
|
+
async depositStrategy(position, params) {
|
|
185
|
+
return this.#startIntent(position, params, {
|
|
186
|
+
type: "DEPOSIT",
|
|
187
|
+
token: params.token,
|
|
188
|
+
amount: params.amount,
|
|
189
|
+
value: params.value,
|
|
190
|
+
positionToken: params.positionToken,
|
|
191
|
+
targetLeverage: params.targetLeverage
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* {@inheritDoc OpportunitiesSimulate.withdrawStrategy}
|
|
196
|
+
**/
|
|
197
|
+
async withdrawStrategy(position, params) {
|
|
198
|
+
return this.#startRoutes(position, params, {
|
|
199
|
+
type: "WITHDRAW",
|
|
200
|
+
amount: params.amount,
|
|
201
|
+
to: params.to,
|
|
202
|
+
tokenOut: params.tokenOut,
|
|
203
|
+
sourceToken: params.sourceToken
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* {@inheritDoc OpportunitiesSimulate.maxWithdraw}
|
|
208
|
+
**/
|
|
209
|
+
async maxWithdraw(position) {
|
|
210
|
+
return this.queryChain({
|
|
211
|
+
network: position.chainId,
|
|
212
|
+
run: async (sdk) => service(sdk).maxWithdraw({
|
|
213
|
+
creditAccount: await slice(sdk, position.creditAccount),
|
|
214
|
+
sdk
|
|
215
|
+
})
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* {@inheritDoc OpportunitiesSimulate.repayStrategy}
|
|
220
|
+
**/
|
|
221
|
+
async repayStrategy(position, params) {
|
|
222
|
+
return this.#startIntent(position, params, {
|
|
223
|
+
type: "REPAY",
|
|
224
|
+
token: params.token,
|
|
225
|
+
amount: params.amount,
|
|
226
|
+
value: params.value
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* {@inheritDoc OpportunitiesSimulate.maxRepay}
|
|
231
|
+
**/
|
|
232
|
+
async maxRepay(position) {
|
|
233
|
+
return this.queryChain({
|
|
234
|
+
network: position.chainId,
|
|
235
|
+
run: async (sdk) => service(sdk).maxRepay({
|
|
236
|
+
creditAccount: await slice(sdk, position.creditAccount),
|
|
237
|
+
sdk
|
|
238
|
+
})
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* {@inheritDoc OpportunitiesSimulate.adjustLeverage}
|
|
243
|
+
**/
|
|
244
|
+
async adjustLeverage(position, params) {
|
|
245
|
+
return this.#startRoutes(position, params, {
|
|
246
|
+
type: "ADJUST_LEVERAGE",
|
|
247
|
+
targetLeverage: params.targetLeverage,
|
|
248
|
+
token: params.token
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* {@inheritDoc OpportunitiesSimulate.addCollateral}
|
|
253
|
+
**/
|
|
254
|
+
async addCollateral(position, params) {
|
|
255
|
+
return this.#startIntent(position, params, {
|
|
256
|
+
type: "ADD_COLLATERAL",
|
|
257
|
+
token: params.token,
|
|
258
|
+
amount: params.amount,
|
|
259
|
+
value: params.value
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* {@inheritDoc OpportunitiesSimulate.withdrawCollateral}
|
|
264
|
+
**/
|
|
265
|
+
async withdrawCollateral(position, params) {
|
|
266
|
+
return this.#startIntent(position, params, {
|
|
267
|
+
type: "WITHDRAW_ASSET",
|
|
268
|
+
token: params.token,
|
|
269
|
+
amount: params.amount,
|
|
270
|
+
to: params.to
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Shared path of the two flows that sell a position asset, and therefore have
|
|
275
|
+
* two routes to offer: one account read, one intent, both routes quoted.
|
|
276
|
+
**/
|
|
277
|
+
async #startRoutes(position, options, intent) {
|
|
278
|
+
return this.queryChain({
|
|
279
|
+
network: position.chainId,
|
|
280
|
+
run: async (sdk) => service(sdk).intentRoutes({
|
|
281
|
+
intent,
|
|
282
|
+
creditAccount: await slice(sdk, position.creditAccount),
|
|
283
|
+
sdk,
|
|
284
|
+
slippage: options.slippage,
|
|
285
|
+
quotaReserve: options.quotaReserve
|
|
286
|
+
})
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Shared path of the same two flows when only the delayed route is asked for:
|
|
291
|
+
* a planner that requests a redemption instead of swapping.
|
|
292
|
+
**/
|
|
293
|
+
async #startDelayedIntent(position, options, intent) {
|
|
294
|
+
return this.queryChain({
|
|
295
|
+
network: position.chainId,
|
|
296
|
+
run: async (sdk) => service(sdk).startDelayedIntent({
|
|
297
|
+
intent,
|
|
298
|
+
creditAccount: await slice(sdk, position.creditAccount),
|
|
299
|
+
sdk,
|
|
300
|
+
slippage: options.slippage,
|
|
301
|
+
quotaReserve: options.quotaReserve
|
|
302
|
+
})
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Shared path of the five flows that act on an existing account: read the
|
|
307
|
+
* account, then run the intent through the engine.
|
|
308
|
+
**/
|
|
309
|
+
async #startIntent(position, options, intent) {
|
|
310
|
+
return this.queryChain({
|
|
311
|
+
network: position.chainId,
|
|
312
|
+
run: async (sdk) => {
|
|
313
|
+
const creditAccount = await slice(sdk, position.creditAccount);
|
|
314
|
+
return service(sdk).startIntent({
|
|
315
|
+
intent,
|
|
316
|
+
creditAccount,
|
|
317
|
+
sdk,
|
|
318
|
+
slippage: options.slippage,
|
|
319
|
+
quotaReserve: options.quotaReserve
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
function service(sdk) {
|
|
326
|
+
return new CreditAccountOperationsService(sdk);
|
|
327
|
+
}
|
|
328
|
+
function slice(sdk, creditAccount) {
|
|
329
|
+
return fetchCreditAccountSlice(sdk, creditAccount);
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* The operation a claim resumes, or `undefined` when there is none to resume:
|
|
333
|
+
* a withdrawal requested without an intent, a compressor too old to report one,
|
|
334
|
+
* or a full close, which the engine no longer previews.
|
|
335
|
+
**/
|
|
336
|
+
function resumable(intent) {
|
|
337
|
+
if (!intent || intent.type === "CLOSE_ACCOUNT") return;
|
|
338
|
+
return intent;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Picks the route the operation takes out of `tokenIn`, as a value rather than
|
|
342
|
+
* an exception: an unroutable or ambiguous pair is a request the caller can
|
|
343
|
+
* fix, so it belongs in the `ok: false` half alongside the strategy refusals.
|
|
344
|
+
*
|
|
345
|
+
* A pool with no route out of the input reports it by throwing, hence the
|
|
346
|
+
* catch; a requested output is checked against the list rather than trusted,
|
|
347
|
+
* so that a wrong one fails here instead of deeper in call assembly.
|
|
348
|
+
**/
|
|
349
|
+
function lpRoute(requested, routes) {
|
|
350
|
+
let options;
|
|
351
|
+
try {
|
|
352
|
+
options = routes();
|
|
353
|
+
} catch {
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
if (requested) return options.some((o) => hexEq(o, requested)) ? requested : void 0;
|
|
357
|
+
return options.length === 1 ? options[0] : void 0;
|
|
358
|
+
}
|
|
359
|
+
//#endregion
|
|
360
|
+
export { SimulateApi };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { chartBundleSchemaFor, chartQueryCodec } from "../model/charts.schema.js";
|
|
2
2
|
import { responseSchema } from "../model/response.schema.js";
|
|
3
3
|
import { OffchainInvalidJsonError } from "./errors/OffchainInvalidJsonError.js";
|
|
4
4
|
import { OffchainNotConfiguredError } from "./errors/OffchainNotConfiguredError.js";
|
|
@@ -64,14 +64,17 @@ var AbstractOffchainNamespace = class {
|
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
|
-
* Reads
|
|
68
|
-
*
|
|
67
|
+
* Reads the charts of one subject: one series per metric named, onto the one
|
|
68
|
+
* grid that lets them be compared at an index.
|
|
69
69
|
**/
|
|
70
|
-
async
|
|
70
|
+
async readCharts(path, metrics, range) {
|
|
71
71
|
return this.get({
|
|
72
|
-
path
|
|
73
|
-
query:
|
|
74
|
-
|
|
72
|
+
path,
|
|
73
|
+
query: z.encode(chartQueryCodec, {
|
|
74
|
+
metrics,
|
|
75
|
+
range
|
|
76
|
+
}),
|
|
77
|
+
schema: chartBundleSchemaFor(metrics, range)
|
|
75
78
|
});
|
|
76
79
|
}
|
|
77
80
|
/**
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { OffchainNotices } from "./notices/OffchainNotices.js";
|
|
2
|
+
import "./notices/index.js";
|
|
1
3
|
import { OffchainOpportunities } from "./opportunities/OffchainOpportunities.js";
|
|
2
4
|
import "./opportunities/index.js";
|
|
3
5
|
import { OffchainPositions } from "./positions/OffchainPositions.js";
|
|
@@ -33,10 +35,15 @@ var GearboxAPI = class {
|
|
|
33
35
|
* Namespace for the positions a wallet holds.
|
|
34
36
|
**/
|
|
35
37
|
positions;
|
|
38
|
+
/**
|
|
39
|
+
* Namespace for the notices the backend attaches to entities.
|
|
40
|
+
**/
|
|
41
|
+
notices;
|
|
36
42
|
constructor(options) {
|
|
37
43
|
this.chainIds = [...options.chainIds];
|
|
38
44
|
this.opportunities = new OffchainOpportunities(options);
|
|
39
45
|
this.positions = new OffchainPositions(options);
|
|
46
|
+
this.notices = new OffchainNotices(options);
|
|
40
47
|
}
|
|
41
48
|
};
|
|
42
49
|
//#endregion
|
|
@@ -10,10 +10,12 @@ import { OffchainValidationError } from "./errors/OffchainValidationError.js";
|
|
|
10
10
|
import { readResponseBody } from "./errors/readResponseBody.js";
|
|
11
11
|
import "./errors/index.js";
|
|
12
12
|
import { AbstractOffchainNamespace } from "./AbstractOffchainNamespace.js";
|
|
13
|
+
import { OffchainNotices } from "./notices/OffchainNotices.js";
|
|
14
|
+
import "./notices/index.js";
|
|
13
15
|
import { OffchainOpportunities } from "./opportunities/OffchainOpportunities.js";
|
|
14
16
|
import "./opportunities/index.js";
|
|
15
17
|
import { OffchainPositions } from "./positions/OffchainPositions.js";
|
|
16
18
|
import "./positions/index.js";
|
|
17
19
|
import { GearboxAPI } from "./GearboxAPI.js";
|
|
18
20
|
import "./types.js";
|
|
19
|
-
export { AbstractOffchainNamespace, GearboxAPI, OffchainInvalidJsonError, OffchainNotConfiguredError, OffchainNotImplementedError, OffchainOpportunities, OffchainPositions, OffchainRequestFailedError, OffchainStatusError, OffchainTransportError, OffchainValidationError, backendMessage, errorCause, readResponseBody };
|
|
21
|
+
export { AbstractOffchainNamespace, GearboxAPI, OffchainInvalidJsonError, OffchainNotConfiguredError, OffchainNotImplementedError, OffchainNotices, OffchainOpportunities, OffchainPositions, OffchainRequestFailedError, OffchainStatusError, OffchainTransportError, OffchainValidationError, backendMessage, errorCause, readResponseBody };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { noticeSchema } from "../../model/notices.schema.js";
|
|
2
|
+
import { AbstractOffchainNamespace } from "../AbstractOffchainNamespace.js";
|
|
3
|
+
import { z } from "zod/v4";
|
|
4
|
+
//#region src/offchain/notices/OffchainNotices.ts
|
|
5
|
+
/**
|
|
6
|
+
* Backend counterpart of `sdk.notices`: banners the backend asks a consumer to
|
|
7
|
+
* show for one entity, see {@link Notice}.
|
|
8
|
+
**/
|
|
9
|
+
var OffchainNotices = class extends AbstractOffchainNamespace {
|
|
10
|
+
#root = "/v2/notices";
|
|
11
|
+
constructor(options) {
|
|
12
|
+
super("OffchainNotices", options);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The notices of one pool opportunity or one strategy position.
|
|
16
|
+
**/
|
|
17
|
+
async list(subject) {
|
|
18
|
+
const [kind, address] = subject.kind === "pool" ? ["pool", subject.pool] : ["strategy", subject.creditAccount];
|
|
19
|
+
return this.get({
|
|
20
|
+
path: `${this.#root}/${kind}/${subject.chainId}/${address}`,
|
|
21
|
+
schema: z.array(noticeSchema)
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
//#endregion
|
|
26
|
+
export { OffchainNotices };
|
|
@@ -43,14 +43,10 @@ var OffchainOpportunities = class extends AbstractOffchainNamespace {
|
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
/**
|
|
46
|
-
*
|
|
46
|
+
* Charts of one opportunity: one series per metric, on a shared grid.
|
|
47
47
|
**/
|
|
48
|
-
async
|
|
49
|
-
return this.
|
|
50
|
-
path: `${this.#historyRoot(query.opportunity)}/history/${query.metric}`,
|
|
51
|
-
metric: query.metric,
|
|
52
|
-
range: query.range
|
|
53
|
-
});
|
|
48
|
+
async getCharts(key, metrics, range) {
|
|
49
|
+
return this.readCharts(`${this.#chartRoot(key)}/charts`, metrics, range);
|
|
54
50
|
}
|
|
55
51
|
#poolPath(key) {
|
|
56
52
|
return `${this.#root}/pools/${key.chainId}/${key.pool}`;
|
|
@@ -58,7 +54,7 @@ var OffchainOpportunities = class extends AbstractOffchainNamespace {
|
|
|
58
54
|
#strategyPath(key) {
|
|
59
55
|
return `${this.#root}/strategies/${key.chainId}/${key.creditManager}/${key.targetCollateral}`;
|
|
60
56
|
}
|
|
61
|
-
#
|
|
57
|
+
#chartRoot(key) {
|
|
62
58
|
return key.kind === "pool" ? this.#poolPath(key) : this.#strategyPath(key);
|
|
63
59
|
}
|
|
64
60
|
};
|
|
@@ -24,19 +24,19 @@ var OffchainPositions = class extends AbstractOffchainNamespace {
|
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* @returns An empty series until the backend client is implemented.
|
|
27
|
+
* Charts of one position: one series per metric, on a shared grid.
|
|
30
28
|
**/
|
|
31
|
-
async
|
|
32
|
-
return {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
29
|
+
async getCharts(key, metrics, range) {
|
|
30
|
+
return this.readCharts(`${this.#chartRoot(key)}/charts`, metrics, range);
|
|
31
|
+
}
|
|
32
|
+
#poolPath(key) {
|
|
33
|
+
return `${this.#root}/pool/${key.chainId}/${key.pool}/${key.wallet}`;
|
|
34
|
+
}
|
|
35
|
+
#strategyPath(key) {
|
|
36
|
+
return `${this.#root}/strategy/${key.chainId}/${key.creditAccount}`;
|
|
37
|
+
}
|
|
38
|
+
#chartRoot(key) {
|
|
39
|
+
return key.kind === "pool" ? this.#poolPath(key) : this.#strategyPath(key);
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
42
|
//#endregion
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { MissingSerializedParamsError } from "../../../sdk/base/errors.js";
|
|
2
1
|
import { ierc4626AdapterAbi } from "../../../abi/ierc4626Adapter.js";
|
|
2
|
+
import { MissingSerializedParamsError } from "../../../sdk/base/errors.js";
|
|
3
3
|
import "../../../sdk/index.js";
|
|
4
4
|
import { fnSigToName, swapFromTransfers } from "../transferHelpers.js";
|
|
5
5
|
import { AbstractAdapterContract } from "./AbstractAdapter.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AssetsMap } from "../../sdk/utils/AssetsMap.js";
|
|
2
|
-
import "../../sdk/constants/math.js";
|
|
2
|
+
import { DUST_THRESHOLD } from "../../sdk/constants/math.js";
|
|
3
3
|
import "../../sdk/index.js";
|
|
4
4
|
import { zeroAddress } from "viem";
|
|
5
5
|
//#region src/preview/preview/CreditAccountState.ts
|
|
@@ -78,6 +78,19 @@ var CreditAccountState = class CreditAccountState {
|
|
|
78
78
|
totalDebt: ca.debt + ca.accruedInterest + ca.accruedFees
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Immutable snapshot of this projected state for `sdk.positions` metric
|
|
83
|
+
* methods: dust-filtered balances, all quotas, and {@link totalDebt}.
|
|
84
|
+
**/
|
|
85
|
+
toSnapshot(totalValue) {
|
|
86
|
+
return {
|
|
87
|
+
creditManager: this.creditManager,
|
|
88
|
+
assets: this.balances.toAssets(DUST_THRESHOLD),
|
|
89
|
+
quotas: this.quotas.toAssets(0n),
|
|
90
|
+
totalDebt: this.totalDebt,
|
|
91
|
+
totalValue
|
|
92
|
+
};
|
|
93
|
+
}
|
|
81
94
|
clone() {
|
|
82
95
|
return new CreditAccountState({
|
|
83
96
|
creditAccount: this.creditAccount,
|
|
@@ -25,8 +25,10 @@ import { isAddressEqual } from "viem";
|
|
|
25
25
|
* @param receivedToken - Token the `CLOSE_ACCOUNT` resume withdraws to the
|
|
26
26
|
* user: the unwrapped underlying (vault asset) for RWA markets, the
|
|
27
27
|
* underlying itself otherwise.
|
|
28
|
+
* @param sdk - Market data source for the position metrics of the resulting
|
|
29
|
+
* state; read synchronously, no network access.
|
|
28
30
|
*/
|
|
29
|
-
function buildDelayedPreview(afterInstant, before, detected, convert, receivedToken) {
|
|
31
|
+
function buildDelayedPreview(afterInstant, before, detected, convert, receivedToken, sdk) {
|
|
30
32
|
const { request, intent } = detected;
|
|
31
33
|
const post = afterInstant.clone();
|
|
32
34
|
const converter = makeSafeConverter(convert);
|
|
@@ -39,7 +41,7 @@ function buildDelayedPreview(afterInstant, before, detected, convert, receivedTo
|
|
|
39
41
|
break;
|
|
40
42
|
case "WITHDRAW_COLLATERAL": applyWithdrawCollateral(post, request, intent, converter, collateralWithdrawn);
|
|
41
43
|
}
|
|
42
|
-
return buildAdjustPreview(post, before, collateralWithdrawn, converter);
|
|
44
|
+
return buildAdjustPreview(post, before, collateralWithdrawn, converter, sdk);
|
|
43
45
|
}
|
|
44
46
|
function makeSafeConverter(convert) {
|
|
45
47
|
let error;
|
|
@@ -171,8 +173,11 @@ function buildClosePreview(post, converter, receivedToken) {
|
|
|
171
173
|
error: converter.error
|
|
172
174
|
};
|
|
173
175
|
}
|
|
174
|
-
function buildAdjustPreview(post, before, collateralWithdrawn, converter) {
|
|
176
|
+
function buildAdjustPreview(post, before, collateralWithdrawn, converter, sdk) {
|
|
175
177
|
const totalValue = totalValueInUnderlying(post, converter.convert, DUST_THRESHOLD);
|
|
178
|
+
const assets = post.balances.toAssets(DUST_THRESHOLD);
|
|
179
|
+
const quotas = post.quotas.toAssets(0n);
|
|
180
|
+
const snap = post.toSnapshot(totalValue);
|
|
176
181
|
return {
|
|
177
182
|
operation: "AdjustCreditAccount",
|
|
178
183
|
creditManager: post.creditManager,
|
|
@@ -182,11 +187,16 @@ function buildAdjustPreview(post, before, collateralWithdrawn, converter) {
|
|
|
182
187
|
totalValue,
|
|
183
188
|
debt: post.debt,
|
|
184
189
|
debtChange: post.debt - before.debt,
|
|
185
|
-
quotas
|
|
190
|
+
quotas,
|
|
186
191
|
quotasChange: post.quotas.difference(before.quotas).toAssets(),
|
|
187
|
-
assets
|
|
192
|
+
assets,
|
|
188
193
|
assetsChange: post.balances.difference(before.balances).toAssets(DUST_THRESHOLD),
|
|
189
|
-
error: converter.error
|
|
194
|
+
error: converter.error,
|
|
195
|
+
healthFactor: sdk.positions.healthFactor(snap),
|
|
196
|
+
overallApy: 0,
|
|
197
|
+
borrowRate: sdk.positions.borrowRate(snap),
|
|
198
|
+
timeToLiquidation: sdk.positions.timeToLiquidation(snap),
|
|
199
|
+
liquidationPrice: sdk.positions.liquidationPrice(snap)
|
|
190
200
|
};
|
|
191
201
|
}
|
|
192
202
|
//#endregion
|
|
@@ -21,6 +21,7 @@ async function previewAdjustCreditAccount(input, operation, options) {
|
|
|
21
21
|
const { assets: collateralAdded, error: unwrapError } = unwrapNativeCollateral(after.collateralAdded.toAssets(), value, sdk.addressProvider.getAddress(AP_WETH_TOKEN, 0));
|
|
22
22
|
error ??= unwrapError;
|
|
23
23
|
const assets = account.balances.toAssets(DUST_THRESHOLD);
|
|
24
|
+
const quotas = account.quotas.toAssets(0n);
|
|
24
25
|
const assetsChange = account.balances.difference(before.balances).toAssets(DUST_THRESHOLD);
|
|
25
26
|
const totalValue = assets.reduce((acc, { token, balance }) => {
|
|
26
27
|
try {
|
|
@@ -33,6 +34,7 @@ async function previewAdjustCreditAccount(input, operation, options) {
|
|
|
33
34
|
return acc;
|
|
34
35
|
}
|
|
35
36
|
}, 0n);
|
|
37
|
+
const snap = account.toSnapshot(totalValue);
|
|
36
38
|
return {
|
|
37
39
|
operation: "AdjustCreditAccount",
|
|
38
40
|
creditManager: operation.creditManager,
|
|
@@ -42,11 +44,16 @@ async function previewAdjustCreditAccount(input, operation, options) {
|
|
|
42
44
|
totalValue,
|
|
43
45
|
debt: account.debt,
|
|
44
46
|
debtChange: account.debt - before.debt,
|
|
45
|
-
quotas
|
|
47
|
+
quotas,
|
|
46
48
|
quotasChange: account.quotas.difference(before.quotas).toAssets(),
|
|
47
49
|
assets,
|
|
48
50
|
assetsChange,
|
|
49
|
-
error
|
|
51
|
+
error,
|
|
52
|
+
healthFactor: sdk.positions.healthFactor(snap),
|
|
53
|
+
overallApy: 0,
|
|
54
|
+
borrowRate: sdk.positions.borrowRate(snap),
|
|
55
|
+
timeToLiquidation: sdk.positions.timeToLiquidation(snap),
|
|
56
|
+
liquidationPrice: sdk.positions.liquidationPrice(snap)
|
|
50
57
|
};
|
|
51
58
|
}
|
|
52
59
|
//#endregion
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AP_WETH_TOKEN } from "../../sdk/constants/address-provider.js";
|
|
2
|
+
import { DUST_THRESHOLD } from "../../sdk/constants/math.js";
|
|
2
3
|
import "../../sdk/index.js";
|
|
3
4
|
import { ERROR_UNPRICEABLE_TOKEN } from "./types.js";
|
|
4
5
|
import { CreditAccountState } from "./CreditAccountState.js";
|
|
@@ -25,7 +26,9 @@ async function previewOpenCreditAccount(input, operation) {
|
|
|
25
26
|
});
|
|
26
27
|
const { assets: collateral, error: unwrapError } = unwrapNativeCollateral(state.collateralAdded.toAssets(), value, sdk.addressProvider.getAddress(AP_WETH_TOKEN, 0));
|
|
27
28
|
error ??= unwrapError ?? priceError;
|
|
28
|
-
const assets = account.balances.toAssets(
|
|
29
|
+
const assets = account.balances.toAssets(DUST_THRESHOLD);
|
|
30
|
+
const quotas = account.quotas.toAssets(0n);
|
|
31
|
+
const snap = account.toSnapshot(collateralValue + account.totalDebt);
|
|
29
32
|
return {
|
|
30
33
|
operation: operation.operation,
|
|
31
34
|
creditManager: operation.creditManager,
|
|
@@ -33,9 +36,14 @@ async function previewOpenCreditAccount(input, operation) {
|
|
|
33
36
|
collateral,
|
|
34
37
|
collateralValue,
|
|
35
38
|
debt: account.debt,
|
|
36
|
-
quotas
|
|
39
|
+
quotas,
|
|
37
40
|
assets,
|
|
38
|
-
error
|
|
41
|
+
error,
|
|
42
|
+
healthFactor: sdk.positions.healthFactor(snap),
|
|
43
|
+
overallApy: 0,
|
|
44
|
+
borrowRate: sdk.positions.borrowRate(snap),
|
|
45
|
+
timeToLiquidation: sdk.positions.timeToLiquidation(snap),
|
|
46
|
+
liquidationPrice: sdk.positions.liquidationPrice(snap)
|
|
39
47
|
};
|
|
40
48
|
}
|
|
41
49
|
/**
|