@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
|
@@ -1,22 +1,137 @@
|
|
|
1
|
-
import { DelayedIntent } from "../withdrawal-compressor/types.js";
|
|
2
|
-
import { OnchainSDK } from "../../OnchainSDK.js";
|
|
3
1
|
import { SDKConstruct } from "../../base/SDKConstruct.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import "./operations
|
|
2
|
+
import { OpenStrategyPreview, OpenStrategyProps } from "./open-strategy.js";
|
|
3
|
+
import { AddCollateralIntent, AdjustLeverageIntent, CreditAccountSlice, DelayableIntent, DelayedRoute, DelayedStart, DelayedStartResult, DepositStrategyIntent, FinishIntentProps, InstantRoute, IntentPreviewError, IntentPreviewResult, IntentRoutesResult, OperationState, PreviewErrorReason, RepayStrategyIntent, ResumableIntent, RouteRefusals, StartIntent, StartIntentProps, WithdrawAssetIntent, WithdrawStrategyIntent } from "./types.js";
|
|
4
|
+
import { AccountCalculatorOperation } from "./operations.js";
|
|
5
|
+
import { fetchCreditAccountSlice, toCreditAccountSlice } from "./utils/credit-account-slice.js";
|
|
7
6
|
//#region src/sdk/accounts/intents/index.d.ts
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Open-strategy preview outcome.
|
|
9
|
+
*
|
|
10
|
+
* Shaped like {@link IntentPreviewResult} in its error half so all previews fail
|
|
11
|
+
* the same way, but the payload is its own: opening has no existing account, so
|
|
12
|
+
* there is no operation chain to report.
|
|
13
|
+
*/
|
|
14
|
+
type OpenStrategyPreviewResult = {
|
|
15
|
+
ok: true;
|
|
16
|
+
preview: OpenStrategyPreview;
|
|
17
|
+
} | {
|
|
18
|
+
ok: false;
|
|
19
|
+
reason: PreviewErrorReason;
|
|
15
20
|
};
|
|
16
|
-
|
|
21
|
+
/** An intent plus everything previewing it needs. */
|
|
22
|
+
type StartProps = StartIntentProps & {
|
|
23
|
+
intent: StartIntent;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Previews of everything a wallet can do to an existing credit account.
|
|
27
|
+
*
|
|
28
|
+
* Two halves, deliberately kept apart: `plan.ts` turns an intent into a few
|
|
29
|
+
* steps with pure arithmetic, `realize.ts` turns the steps into router-backed
|
|
30
|
+
* operations. This class only picks the planner and wraps the outcome.
|
|
31
|
+
*/
|
|
17
32
|
declare class CreditAccountOperationsService extends SDKConstruct {
|
|
18
33
|
#private;
|
|
19
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Previews an operation on an existing account.
|
|
36
|
+
*
|
|
37
|
+
* @param props - Intent plus account slice, quota reserve and slippage
|
|
38
|
+
* @returns Operations, projected state and calldata, or `{ ok: false, reason }`
|
|
39
|
+
* when the intent cannot be satisfied (e.g. the account lacks the source
|
|
40
|
+
* balance)
|
|
41
|
+
*/
|
|
42
|
+
startIntent(props: StartProps): Promise<IntentPreviewResult>;
|
|
43
|
+
/**
|
|
44
|
+
* Largest `WITHDRAW` amount (in underlying) the account can take out while
|
|
45
|
+
* keeping leverage and staying inside the facade's debt band — the ceiling a
|
|
46
|
+
* withdraw form should offer. Taking everything out is the same intent with
|
|
47
|
+
* `MAX_UINT256` for an amount, and needs none of this arithmetic.
|
|
48
|
+
*
|
|
49
|
+
* @param props - Account slice and the SDK holding its market
|
|
50
|
+
* @returns Amount in underlying units; `0n` when nothing can leave
|
|
51
|
+
*/
|
|
52
|
+
maxWithdraw(props: Pick<StartIntentProps, "creditAccount" | "sdk">): bigint;
|
|
53
|
+
/**
|
|
54
|
+
* Debt a `REPAY` would have to cover to settle the account, in underlying
|
|
55
|
+
* units: principal plus the interest and fees accrued as of the read.
|
|
56
|
+
*
|
|
57
|
+
* A repayment of exactly this leaves nothing behind at the block it was read
|
|
58
|
+
* at, and a little behind at any later one, since interest does not stop —
|
|
59
|
+
* so a wallet meaning to clear the account sends this with a buffer on top,
|
|
60
|
+
* which the intent caps at the debt rather than spending. `REPAY` with
|
|
61
|
+
* `MAX_UINT256` sizes that buffer itself.
|
|
62
|
+
*
|
|
63
|
+
* @param props - Account slice and the SDK holding its market
|
|
64
|
+
* @returns Amount in underlying units; `0n` on an account that owes nothing
|
|
65
|
+
*/
|
|
66
|
+
maxRepay(props: Pick<StartIntentProps, "creditAccount" | "sdk">): bigint;
|
|
67
|
+
/**
|
|
68
|
+
* Previews the same operation when its source only redeems through its
|
|
69
|
+
* issuer: a Securitize dsToken, a Mellow share.
|
|
70
|
+
*
|
|
71
|
+
* Sits apart from {@link startIntent} because it is a different trade route,
|
|
72
|
+
* not a different intent: the request goes to the issuer instead of the
|
|
73
|
+
* router, and the proceeds — hence the repayment and the payout — arrive days
|
|
74
|
+
* later. Both routes of one intent are quoted together by
|
|
75
|
+
* {@link intentRoutes}; this is the one to call when the delayed route is the
|
|
76
|
+
* only one of interest.
|
|
77
|
+
*
|
|
78
|
+
* @param props - Intent plus account slice, quota reserve and slippage
|
|
79
|
+
* @returns The request transaction and what it recorded for the tail, or
|
|
80
|
+
* `{ ok: false, reason }` — `noDelayedRoute` when this route does not exist
|
|
81
|
+
* for the account at all
|
|
82
|
+
*/
|
|
83
|
+
startDelayedIntent(props: StartIntentProps & {
|
|
84
|
+
intent: DelayableIntent;
|
|
85
|
+
}): Promise<DelayedStartResult>;
|
|
86
|
+
/**
|
|
87
|
+
* Previews a delayable intent both ways at once: settled by the router now,
|
|
88
|
+
* and started as a redemption that finishes days later.
|
|
89
|
+
*
|
|
90
|
+
* Which routes an account has depends on the intent and the token it sells,
|
|
91
|
+
* and a form has to know before it can offer a choice — so both are quoted
|
|
92
|
+
* from the same request and each is reported on its own. A route the account
|
|
93
|
+
* cannot take comes back `undefined` with its refusal in `refused`; only when
|
|
94
|
+
* neither answers is the whole result `{ ok: false }`.
|
|
95
|
+
*
|
|
96
|
+
* A route that could not be quoted at all — a pathfinder with no path out of
|
|
97
|
+
* the source, a read that failed — counts as missing rather than fatal, since
|
|
98
|
+
* the other route may be the one the caller wanted. With nothing left to
|
|
99
|
+
* report the failure is rethrown, as {@link startIntent} would have.
|
|
100
|
+
*
|
|
101
|
+
* @param props - A withdraw or adjust-leverage intent plus account slice,
|
|
102
|
+
* quota reserve and slippage
|
|
103
|
+
* @returns Whichever routes are viable, or `{ ok: false, reason }` when none is
|
|
104
|
+
*/
|
|
105
|
+
intentRoutes(props: StartIntentProps & {
|
|
106
|
+
intent: DelayableIntent;
|
|
107
|
+
}): Promise<IntentRoutesResult>;
|
|
108
|
+
/**
|
|
109
|
+
* Previews the tail of a delayed intent, once the withdrawal it started has
|
|
110
|
+
* matured: the claim, then whatever the intent still owes.
|
|
111
|
+
*
|
|
112
|
+
* Serves the two operations that can genuinely be interrupted by a delay — a
|
|
113
|
+
* withdrawal and a deleveraging. For the rest, the claim is the whole tail:
|
|
114
|
+
* the tokens land on the account and only their quota has to catch up.
|
|
115
|
+
*
|
|
116
|
+
* @param props - The recorded intent, the account slice as it stands now, and
|
|
117
|
+
* the matured claimable
|
|
118
|
+
* @returns Shaped exactly like {@link startIntent}'s result, so both halves of
|
|
119
|
+
* an operation are consumed the same way
|
|
120
|
+
*/
|
|
121
|
+
finishIntent(props: FinishIntentProps): Promise<IntentPreviewResult>;
|
|
122
|
+
/**
|
|
123
|
+
* Previews opening a brand-new leveraged position.
|
|
124
|
+
*
|
|
125
|
+
* Sits apart from {@link startIntent} because there is no account yet: nothing
|
|
126
|
+
* can be projected from existing balances, and the output feeds
|
|
127
|
+
* `sdk.accounts.openCA` rather than a facade multicall assembled here.
|
|
128
|
+
*
|
|
129
|
+
* @param props - Credit manager, wallet collateral, target token and leverage
|
|
130
|
+
* @returns Debt, position size, projected balances and quotas for both the
|
|
131
|
+
* expected and the floor branch, or `{ ok: false, reason }` when the requested
|
|
132
|
+
* leverage or the resulting debt is not viable
|
|
133
|
+
*/
|
|
134
|
+
openStrategyIntent(props: OpenStrategyProps): Promise<OpenStrategyPreviewResult>;
|
|
20
135
|
}
|
|
21
136
|
//#endregion
|
|
22
|
-
export { CreditAccountOperationsService, type CreditAccountSlice, type IntentPreviewResult,
|
|
137
|
+
export { type AccountCalculatorOperation, type AddCollateralIntent, type AdjustLeverageIntent, CreditAccountOperationsService, type CreditAccountSlice, type DelayableIntent, type DelayedRoute, type DelayedStart, type DelayedStartResult, type DepositStrategyIntent, type FinishIntentProps, type InstantRoute, IntentPreviewError, type IntentPreviewResult, type IntentRoutesResult, type OpenStrategyPreview, OpenStrategyPreviewResult, type OpenStrategyProps, type OperationState, type PreviewErrorReason, type RepayStrategyIntent, type ResumableIntent, type RouteRefusals, type StartIntent, type WithdrawAssetIntent, type WithdrawStrategyIntent, fetchCreditAccountSlice, toCreditAccountSlice };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
//#region src/sdk/accounts/intents/math.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The whole arithmetic behind every intent, in underlying units.
|
|
4
|
+
*
|
|
5
|
+
* Notation: `C` collateral (own funds = TVL − debt), `D` debt, `L` total
|
|
6
|
+
* leverage scaled by {@link LEVERAGE_DECIMALS} (300n = 3x), so `TVL = C · L`
|
|
7
|
+
* and `D = C · (L − 1)`.
|
|
8
|
+
*/
|
|
9
|
+
/** Debt and collateral of an account, both priced in the underlying. */
|
|
10
|
+
interface Position {
|
|
11
|
+
debt: bigint;
|
|
12
|
+
collateral: bigint;
|
|
13
|
+
}
|
|
14
|
+
/** Facade limits a non-zero debt must respect. */
|
|
15
|
+
interface DebtBand {
|
|
16
|
+
minDebt: bigint;
|
|
17
|
+
maxDebt: bigint;
|
|
18
|
+
}
|
|
19
|
+
/** Debt that realises `leverage` on `collateral`: `D = C · (L − 1)`. */
|
|
20
|
+
declare function debtForLeverage(collateral: bigint, leverage: bigint): bigint;
|
|
21
|
+
/**
|
|
22
|
+
* Debt change that keeps leverage fixed while collateral moves by
|
|
23
|
+
* `collateralDelta`: `dD = D0 · dC / C0`.
|
|
24
|
+
*
|
|
25
|
+
* Computed on the ratio directly rather than by recovering `L` and reapplying
|
|
26
|
+
* it, so no rounding is introduced on the way.
|
|
27
|
+
*/
|
|
28
|
+
declare function proportionalDebt(position: Position, collateralDelta: bigint): bigint;
|
|
29
|
+
/**
|
|
30
|
+
* Largest withdrawal (in underlying) that {@link proportionalDebt} can still
|
|
31
|
+
* pay for: the repayment it implies leaves debt at or above `minDebt`, and
|
|
32
|
+
* strictly less than the collateral goes — the last unit closes the account
|
|
33
|
+
* rather than shrinks it. `0n` when the debt already sits below the band.
|
|
34
|
+
*
|
|
35
|
+
* Solves `floor(D0 · W / C0) ≤ D0 − minDebt` for `W`.
|
|
36
|
+
*/
|
|
37
|
+
declare function maxProportionalWithdrawal(position: Position, band: DebtBand): bigint;
|
|
38
|
+
/** Total leverage cannot drop below 1x — that would be negative debt. */
|
|
39
|
+
declare function assertLeverageAtLeastOne(leverage: bigint): void;
|
|
40
|
+
/**
|
|
41
|
+
* Rejects a debt the facade would revert on: zero is always fine (no loan at
|
|
42
|
+
* all), anything else has to sit inside `[minDebt, maxDebt]`.
|
|
43
|
+
*/
|
|
44
|
+
declare function assertDebtInBand(debt: bigint, band: DebtBand): void;
|
|
45
|
+
//#endregion
|
|
46
|
+
export { DebtBand, Position, assertDebtInBand, assertLeverageAtLeastOne, debtForLeverage, maxProportionalWithdrawal, proportionalDebt };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Asset } from "../../base/types.js";
|
|
2
|
+
import { PositionMetrics } from "../../../model/positions.js";
|
|
3
|
+
import "../../../model/index.js";
|
|
4
|
+
import { MultiCall } from "../../types/transactions.js";
|
|
5
|
+
import { OnchainSDK } from "../../OnchainSDK.js";
|
|
6
|
+
import "../../index.js";
|
|
7
|
+
import { Address } from "viem";
|
|
8
|
+
//#region src/sdk/accounts/intents/open-strategy.d.ts
|
|
9
|
+
interface OpenStrategyProps {
|
|
10
|
+
sdk: OnchainSDK;
|
|
11
|
+
/** Credit manager to open the account in. */
|
|
12
|
+
creditManager: Address;
|
|
13
|
+
/** Collateral coming from the wallet, in their own tokens. */
|
|
14
|
+
collateral: Asset[];
|
|
15
|
+
/** Token the position ends up in. */
|
|
16
|
+
targetToken: Address;
|
|
17
|
+
/** Target total leverage scaled by `LEVERAGE_DECIMALS` (300n = 3x). */
|
|
18
|
+
leverage: bigint;
|
|
19
|
+
/** Router slippage in PERCENTAGE_FORMAT (100% = 10_000). */
|
|
20
|
+
slippage: number | undefined;
|
|
21
|
+
/** Extra quota headroom in PERCENTAGE_FORMAT. */
|
|
22
|
+
quotaReserve: number | undefined;
|
|
23
|
+
/** Balances to leave unswapped; everything else is routed into the target. */
|
|
24
|
+
leftoverBalances?: Asset[];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Projected result of opening a brand-new leveraged position.
|
|
28
|
+
*
|
|
29
|
+
* Unlike every other flow this one reports **both** branches: the pathfinder
|
|
30
|
+
* hands back expected and floor balances from a single call, and `openCA` wants
|
|
31
|
+
* both `minQuota` and `averageQuota`, so there is nothing to gain by dropping one.
|
|
32
|
+
*/
|
|
33
|
+
interface OpenStrategyPreview extends PositionMetrics {
|
|
34
|
+
/** Debt drawn, in underlying. */
|
|
35
|
+
debt: bigint;
|
|
36
|
+
/** Collateral supplied, valued in underlying. */
|
|
37
|
+
collateral: bigint;
|
|
38
|
+
/** Position size — collateral plus debt, in underlying. */
|
|
39
|
+
totalValue: bigint;
|
|
40
|
+
/** Expected post-open balances. */
|
|
41
|
+
averageAssets: Asset[];
|
|
42
|
+
/** Floor post-open balances after slippage. */
|
|
43
|
+
minAssets: Asset[];
|
|
44
|
+
/** Quotas to buy against `averageAssets`; feeds `openCA.averageQuota`. */
|
|
45
|
+
averageQuota: Asset[];
|
|
46
|
+
/** Quotas to buy against `minAssets`; feeds `openCA.minQuota`. */
|
|
47
|
+
minQuota: Asset[];
|
|
48
|
+
/** Router path; feeds `openCA.calls`. */
|
|
49
|
+
calls: MultiCall[];
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Previews opening a leveraged position out of wallet collateral.
|
|
53
|
+
*
|
|
54
|
+
* Debt follows from the target leverage against the supplied margin
|
|
55
|
+
* (`debt = margin * (L - 1)`, `totalValue = margin * L`); the collateral and the
|
|
56
|
+
* borrowed underlying are then routed into the target token in one pathfinder call.
|
|
57
|
+
*
|
|
58
|
+
* There is no account yet, so this does not go through `startIntent` and produces
|
|
59
|
+
* no operation list — the caller passes the numbers and calls straight to
|
|
60
|
+
* `sdk.accounts.openCA`.
|
|
61
|
+
*/
|
|
62
|
+
declare function previewOpenStrategy(props: OpenStrategyProps): Promise<OpenStrategyPreview>;
|
|
63
|
+
//#endregion
|
|
64
|
+
export { OpenStrategyPreview, OpenStrategyProps, previewOpenStrategy };
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { ClaimableWithdrawal, RequestableWithdrawal, WithdrawalOutput } from "../withdrawal-compressor/types.js";
|
|
2
|
+
import { Asset } from "../../base/types.js";
|
|
3
|
+
import { MultiCall } from "../../types/transactions.js";
|
|
4
|
+
import { OnchainSDK } from "../../OnchainSDK.js";
|
|
5
|
+
import { EncodableCreditAccountOperation } from "../types.js";
|
|
6
|
+
import { calcQuotaUpdate } from "../../../common-utils/utils/creditAccount/quota-utils.js";
|
|
7
|
+
import { CreditAccountSlice } from "./types.js";
|
|
8
|
+
import "../../index.js";
|
|
9
|
+
import { Address } from "viem";
|
|
10
|
+
//#region src/sdk/accounts/intents/operations.d.ts
|
|
11
|
+
/**
|
|
12
|
+
* The operation vocabulary: one logical step of an intent, carrying both the
|
|
13
|
+
* calldata that realises it and the amounts it was computed from.
|
|
14
|
+
*
|
|
15
|
+
* A superset of {@link EncodableCreditAccountOperation}: same discriminants,
|
|
16
|
+
* plus the quoted amounts the preview and the tests read, plus the RWA legs
|
|
17
|
+
* that come from their own assemblers rather than from `assembleCaOperations`.
|
|
18
|
+
*/
|
|
19
|
+
type AccountCalculatorOperation = AddCollateralOperation | IncreaseDebtOperation | DecreaseDebtOperation | SwapOperation | WithdrawCollateralOperation | QuotaUpdateOperation | WrapRwaCollateralOperation | UnwrapRwaCollateralOperation | StartDelayedWithdrawalOperation | ClaimDelayedWithdrawalOperation;
|
|
20
|
+
/**
|
|
21
|
+
* Compile-time proof that the engine's operations really are the SDK's own
|
|
22
|
+
* encodable ones with the quoted amounts attached, so the two cannot drift into
|
|
23
|
+
* parallel vocabularies for the same facade calls.
|
|
24
|
+
*/
|
|
25
|
+
type Extends<A extends B, B> = A;
|
|
26
|
+
type _EngineOpsAreEncodable = Extends<Extract<AccountCalculatorOperation, {
|
|
27
|
+
type: EncodableCreditAccountOperation["type"];
|
|
28
|
+
}>, EncodableCreditAccountOperation>;
|
|
29
|
+
interface AddCollateralOperation {
|
|
30
|
+
type: "addCollateral";
|
|
31
|
+
token: Address;
|
|
32
|
+
amount: bigint;
|
|
33
|
+
value?: bigint;
|
|
34
|
+
calls: MultiCall[];
|
|
35
|
+
}
|
|
36
|
+
declare function buildAddCollateralOperation(input: {
|
|
37
|
+
token: Address;
|
|
38
|
+
amount: bigint;
|
|
39
|
+
value?: bigint;
|
|
40
|
+
creditAccount: CreditAccountSlice;
|
|
41
|
+
sdk: OnchainSDK;
|
|
42
|
+
}): AddCollateralOperation;
|
|
43
|
+
interface IncreaseDebtOperation {
|
|
44
|
+
type: "increaseDebt";
|
|
45
|
+
amount: bigint;
|
|
46
|
+
calls: MultiCall[];
|
|
47
|
+
}
|
|
48
|
+
declare function buildIncreaseDebtOperation(input: {
|
|
49
|
+
amount: bigint;
|
|
50
|
+
creditAccount: CreditAccountSlice;
|
|
51
|
+
sdk: OnchainSDK;
|
|
52
|
+
}): IncreaseDebtOperation;
|
|
53
|
+
interface DecreaseDebtOperation {
|
|
54
|
+
type: "decreaseDebt";
|
|
55
|
+
amount: bigint;
|
|
56
|
+
/**
|
|
57
|
+
* The repayment settles the loan rather than shrinking it, so the call names
|
|
58
|
+
* no amount and the facade takes everything outstanding. `amount` is still
|
|
59
|
+
* the debt as it was read, which is what the projection is built on; the
|
|
60
|
+
* difference is the interest that accrues before the transaction lands.
|
|
61
|
+
*/
|
|
62
|
+
full?: boolean;
|
|
63
|
+
calls: MultiCall[];
|
|
64
|
+
}
|
|
65
|
+
declare function buildDecreaseDebtOperation(input: {
|
|
66
|
+
amount: bigint;
|
|
67
|
+
full?: boolean;
|
|
68
|
+
creditAccount: CreditAccountSlice;
|
|
69
|
+
sdk: OnchainSDK;
|
|
70
|
+
}): DecreaseDebtOperation;
|
|
71
|
+
interface WithdrawCollateralOperation {
|
|
72
|
+
type: "withdrawCollateral";
|
|
73
|
+
token: Address;
|
|
74
|
+
amount: bigint;
|
|
75
|
+
/** Wallet recipient for withdrawn tokens — never a token address. */
|
|
76
|
+
to: Address;
|
|
77
|
+
/**
|
|
78
|
+
* The call names no amount and the facade hands over the whole balance, so a
|
|
79
|
+
* swap that beat its floor does not strand the surplus on the account.
|
|
80
|
+
* `amount` remains the figure the projection was built on.
|
|
81
|
+
*/
|
|
82
|
+
all?: boolean;
|
|
83
|
+
calls: MultiCall[];
|
|
84
|
+
}
|
|
85
|
+
declare function buildWithdrawCollateralOperation(input: {
|
|
86
|
+
token: Address;
|
|
87
|
+
amount: bigint;
|
|
88
|
+
to: Address;
|
|
89
|
+
all?: boolean;
|
|
90
|
+
creditAccount: CreditAccountSlice;
|
|
91
|
+
sdk: OnchainSDK;
|
|
92
|
+
}): WithdrawCollateralOperation;
|
|
93
|
+
/** Routed conversion: one or more tokens in, one token out. */
|
|
94
|
+
interface SwapOperation {
|
|
95
|
+
type: "swap";
|
|
96
|
+
from: Asset[];
|
|
97
|
+
tokenOut: Address;
|
|
98
|
+
amountOut: bigint;
|
|
99
|
+
calls: MultiCall[];
|
|
100
|
+
}
|
|
101
|
+
/** One routed leg, with the amounts it was quoted at. */
|
|
102
|
+
declare function buildSwapOperation(input: {
|
|
103
|
+
tokenIn: Address;
|
|
104
|
+
amountIn: bigint;
|
|
105
|
+
tokenOut: Address;
|
|
106
|
+
amountOut: bigint;
|
|
107
|
+
calls: MultiCall[];
|
|
108
|
+
}): SwapOperation;
|
|
109
|
+
/**
|
|
110
|
+
* The many-to-one leg an exit routes: every balance listed goes in, and the
|
|
111
|
+
* underlying comes out.
|
|
112
|
+
*/
|
|
113
|
+
declare function buildCloseSwapOperation(input: {
|
|
114
|
+
from: Asset[];
|
|
115
|
+
tokenOut: Address;
|
|
116
|
+
amountOut: bigint;
|
|
117
|
+
calls: MultiCall[];
|
|
118
|
+
}): SwapOperation;
|
|
119
|
+
interface QuotaUpdateOperation {
|
|
120
|
+
type: "changeQuota";
|
|
121
|
+
desiredQuota: Record<Address, Asset>;
|
|
122
|
+
quotaIncrease: Asset[];
|
|
123
|
+
quotaDecrease: Asset[];
|
|
124
|
+
calls: MultiCall[];
|
|
125
|
+
}
|
|
126
|
+
type QuotaUpdateState = ReturnType<typeof calcQuotaUpdate>;
|
|
127
|
+
declare function buildQuotaUpdateOperation(input: {
|
|
128
|
+
update: QuotaUpdateState;
|
|
129
|
+
creditAccount: CreditAccountSlice;
|
|
130
|
+
sdk: OnchainSDK;
|
|
131
|
+
}): QuotaUpdateOperation;
|
|
132
|
+
interface WrapRwaCollateralOperation {
|
|
133
|
+
type: "wrapRwaCollateral";
|
|
134
|
+
/** Amount of RWA asset wrapped. */
|
|
135
|
+
amount: bigint;
|
|
136
|
+
/** RWA asset token (wrap source). */
|
|
137
|
+
tokenIn: Address;
|
|
138
|
+
/** Underlying received after wrap. */
|
|
139
|
+
tokenOut: Address;
|
|
140
|
+
amountOut: bigint;
|
|
141
|
+
calls: MultiCall[];
|
|
142
|
+
}
|
|
143
|
+
interface UnwrapRwaCollateralOperation {
|
|
144
|
+
type: "unwrapRwaCollateral";
|
|
145
|
+
/** Amount of wrapped underlying unwrapped. */
|
|
146
|
+
amount: bigint;
|
|
147
|
+
/** Wrapped underlying token (unwrap source). */
|
|
148
|
+
tokenIn: Address;
|
|
149
|
+
/** RWA asset received after unwrap. */
|
|
150
|
+
tokenOut: Address;
|
|
151
|
+
amountOut: bigint;
|
|
152
|
+
calls: MultiCall[];
|
|
153
|
+
}
|
|
154
|
+
interface RwaLegInput {
|
|
155
|
+
tokenIn: Address;
|
|
156
|
+
amountIn: bigint;
|
|
157
|
+
tokenOut: Address;
|
|
158
|
+
amountOut: bigint;
|
|
159
|
+
creditAccount: CreditAccountSlice;
|
|
160
|
+
sdk: OnchainSDK;
|
|
161
|
+
}
|
|
162
|
+
/** Wraps an RWA asset into the market underlying. */
|
|
163
|
+
declare function buildWrapRwaCollateralOperation(input: RwaLegInput): Promise<WrapRwaCollateralOperation>;
|
|
164
|
+
/** Unwraps the market underlying back into its RWA asset. */
|
|
165
|
+
declare function buildUnwrapRwaCollateralOperation(input: RwaLegInput): Promise<UnwrapRwaCollateralOperation>;
|
|
166
|
+
/**
|
|
167
|
+
* The request that starts a redemption: spends the source token and receives
|
|
168
|
+
* the phantom token standing in for the payout until it matures.
|
|
169
|
+
*/
|
|
170
|
+
interface StartDelayedWithdrawalOperation {
|
|
171
|
+
type: "startDelayedWithdrawal";
|
|
172
|
+
/** Source token the redemption is requested from. */
|
|
173
|
+
token: Address;
|
|
174
|
+
/** Amount of `token` the issuer burns; capped at the account balance. */
|
|
175
|
+
amountIn: bigint;
|
|
176
|
+
/** Request outputs; a delayed one is the phantom token, not the payout. */
|
|
177
|
+
outputs: WithdrawalOutput[];
|
|
178
|
+
/** Whether anything at all has to be waited for. */
|
|
179
|
+
settlement: "instant" | "delayed";
|
|
180
|
+
calls: MultiCall[];
|
|
181
|
+
}
|
|
182
|
+
declare function buildStartDelayedWithdrawalOperation(input: {
|
|
183
|
+
preview: RequestableWithdrawal;
|
|
184
|
+
creditAccount: CreditAccountSlice;
|
|
185
|
+
sdk: OnchainSDK;
|
|
186
|
+
}): StartDelayedWithdrawalOperation;
|
|
187
|
+
/**
|
|
188
|
+
* The claim of a matured delayed withdrawal: burns the phantom and credits the
|
|
189
|
+
* outputs the compressor reports.
|
|
190
|
+
*/
|
|
191
|
+
interface ClaimDelayedWithdrawalOperation {
|
|
192
|
+
type: "claimDelayedWithdrawal";
|
|
193
|
+
/** Source token the delayed withdrawal was requested from. */
|
|
194
|
+
token: Address;
|
|
195
|
+
withdrawalPhantomToken: Address;
|
|
196
|
+
withdrawalTokenSpent: bigint;
|
|
197
|
+
/** Claim outputs as returned by the compressor (incl. `isDelayed`). */
|
|
198
|
+
outputs: WithdrawalOutput[];
|
|
199
|
+
calls: MultiCall[];
|
|
200
|
+
}
|
|
201
|
+
declare function buildClaimDelayedWithdrawalOperation(input: {
|
|
202
|
+
claimable: ClaimableWithdrawal;
|
|
203
|
+
creditAccount: CreditAccountSlice;
|
|
204
|
+
sdk: OnchainSDK;
|
|
205
|
+
}): ClaimDelayedWithdrawalOperation;
|
|
206
|
+
/**
|
|
207
|
+
* What a request or a claim puts on the account right away, as opposed to what
|
|
208
|
+
* only the phantom token represents.
|
|
209
|
+
*/
|
|
210
|
+
declare function instantOutput(outputs: WithdrawalOutput[], token?: Address): {
|
|
211
|
+
token: Address;
|
|
212
|
+
amount: bigint;
|
|
213
|
+
} | undefined;
|
|
214
|
+
//#endregion
|
|
215
|
+
export { AccountCalculatorOperation, AddCollateralOperation, ClaimDelayedWithdrawalOperation, DecreaseDebtOperation, IncreaseDebtOperation, QuotaUpdateOperation, QuotaUpdateState, RwaLegInput, StartDelayedWithdrawalOperation, SwapOperation, UnwrapRwaCollateralOperation, WithdrawCollateralOperation, WrapRwaCollateralOperation, _EngineOpsAreEncodable, buildAddCollateralOperation, buildClaimDelayedWithdrawalOperation, buildCloseSwapOperation, buildDecreaseDebtOperation, buildIncreaseDebtOperation, buildQuotaUpdateOperation, buildStartDelayedWithdrawalOperation, buildSwapOperation, buildUnwrapRwaCollateralOperation, buildWithdrawCollateralOperation, buildWrapRwaCollateralOperation, instantOutput };
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { ClaimableWithdrawal, DelayedIntent } from "../withdrawal-compressor/types.js";
|
|
2
|
+
import { AddCollateralIntent, AdjustLeverageIntent, DepositStrategyIntent, RepayStrategyIntent, WithdrawAssetIntent, WithdrawStrategyIntent } from "./types.js";
|
|
3
|
+
import { DebtBand } from "./math.js";
|
|
4
|
+
import { Address } from "viem";
|
|
5
|
+
//#region src/sdk/accounts/intents/plan.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Planning: an intent becomes a short list of {@link Step}s.
|
|
8
|
+
*
|
|
9
|
+
* Every intent is a walk along the same chain —
|
|
10
|
+
*
|
|
11
|
+
* ```
|
|
12
|
+
* wallet ─add─▶ account ─convert(in→U)─▶ borrow | repay ─convert(U→out)─▶ ─withdraw─▶ wallet
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* — so a plan is just which slots are filled and by how much. Planners are
|
|
16
|
+
* pure: they read an {@link AccountView} and return steps; nothing here touches
|
|
17
|
+
* the router or the chain. Identity converts (`from === to`) are legitimate
|
|
18
|
+
* plan entries — the realiser drops them after checking the balance — which is
|
|
19
|
+
* what lets one planner cover every "S is / is not the underlying" shape.
|
|
20
|
+
*/
|
|
21
|
+
/** Amount of a step: fixed, or whatever the previous step produced. */
|
|
22
|
+
type Amount = bigint | {
|
|
23
|
+
raised: true;
|
|
24
|
+
max?: bigint;
|
|
25
|
+
};
|
|
26
|
+
/** Whatever the previous convert produced. */
|
|
27
|
+
declare const RAISED: Amount;
|
|
28
|
+
type Step = {
|
|
29
|
+
kind: "add";
|
|
30
|
+
token: Address;
|
|
31
|
+
amount: bigint;
|
|
32
|
+
value: bigint | undefined;
|
|
33
|
+
} | {
|
|
34
|
+
kind: "borrow";
|
|
35
|
+
amount: bigint;
|
|
36
|
+
} |
|
|
37
|
+
/**
|
|
38
|
+
* Repays up to `amount`, never more than the underlying on the account minus
|
|
39
|
+
* `keep` — a routing shortfall shows up as slightly less debt repaid.
|
|
40
|
+
*/
|
|
41
|
+
{
|
|
42
|
+
kind: "repay";
|
|
43
|
+
amount: Amount;
|
|
44
|
+
keep?: bigint;
|
|
45
|
+
} | {
|
|
46
|
+
kind: "convert";
|
|
47
|
+
from: Address;
|
|
48
|
+
to: Address;
|
|
49
|
+
amount: Amount;
|
|
50
|
+
} | {
|
|
51
|
+
kind: "withdraw";
|
|
52
|
+
token: Address;
|
|
53
|
+
amount: Amount;
|
|
54
|
+
to: Address;
|
|
55
|
+
} |
|
|
56
|
+
/**
|
|
57
|
+
* Sells every balance the account holds into the underlying in one
|
|
58
|
+
* many-to-one route. Only an exit asks for this: the whole position is
|
|
59
|
+
* leaving, so the router is given all of it at once rather than one leg per
|
|
60
|
+
* token, and there is nothing left to price a fixed input against.
|
|
61
|
+
*/
|
|
62
|
+
{
|
|
63
|
+
kind: "closeAll";
|
|
64
|
+
} |
|
|
65
|
+
/**
|
|
66
|
+
* Redeems `amount` of `token` through its issuer instead of a DEX, keeping
|
|
67
|
+
* `reserve` of it on the account. `record` is written into the request and
|
|
68
|
+
* read back at claim time, which is what lets the tail be planned then.
|
|
69
|
+
*/
|
|
70
|
+
{
|
|
71
|
+
kind: "request";
|
|
72
|
+
token: Address;
|
|
73
|
+
amount: bigint;
|
|
74
|
+
reserve: bigint;
|
|
75
|
+
record: DelayedIntent;
|
|
76
|
+
} | {
|
|
77
|
+
kind: "claim";
|
|
78
|
+
claimable: ClaimableWithdrawal;
|
|
79
|
+
} |
|
|
80
|
+
/**
|
|
81
|
+
* Hands whatever is left on the account to `to`, each balance in the token it
|
|
82
|
+
* stands in. Only an exit asks for this: the amounts are whatever the legs
|
|
83
|
+
* before it happen to leave, which no planner can name in advance.
|
|
84
|
+
*/
|
|
85
|
+
{
|
|
86
|
+
kind: "sweep";
|
|
87
|
+
to: Address;
|
|
88
|
+
} |
|
|
89
|
+
/**
|
|
90
|
+
* Drops every quota the account holds, in the same transaction and before
|
|
91
|
+
* whatever follows. Only a plan that leaves no debt behind asks for this:
|
|
92
|
+
* quota fees accrue on the quota, not on the loan, so a quota outliving the
|
|
93
|
+
* debt it backed would keep charging an account that owes nothing.
|
|
94
|
+
*/
|
|
95
|
+
{
|
|
96
|
+
kind: "clearQuotas";
|
|
97
|
+
};
|
|
98
|
+
/** What a planner is allowed to know about the account. */
|
|
99
|
+
interface AccountView {
|
|
100
|
+
underlying: Address;
|
|
101
|
+
/** Raw asset of an RWA market (e.g. USDC behind dcUSDC); undefined otherwise. */
|
|
102
|
+
rwaAsset: Address | undefined;
|
|
103
|
+
debt: bigint;
|
|
104
|
+
/** TVL − debt, in underlying. */
|
|
105
|
+
collateral: bigint;
|
|
106
|
+
band: DebtBand;
|
|
107
|
+
balanceOf(token: Address): bigint;
|
|
108
|
+
/** Oracle conversion, RWA-aware. */
|
|
109
|
+
price(from: Address, to: Address, amount: bigint): bigint;
|
|
110
|
+
/** Most valuable non-phantom balance, or undefined when there is none. */
|
|
111
|
+
fattest(exclude?: Address[]): Address | undefined;
|
|
112
|
+
}
|
|
113
|
+
/** Intent 5: the token lands as is; debt is untouched. */
|
|
114
|
+
declare function planAddCollateral(intent: Omit<AddCollateralIntent, "type">): Step[];
|
|
115
|
+
/** Intent 4: one asset out at fixed debt. */
|
|
116
|
+
declare function planWithdrawAsset(intent: Omit<WithdrawAssetIntent, "type">, view: AccountView): Step[];
|
|
117
|
+
/** Intent 6: collateral fixed, debt retargeted to `C0 · (L1 − 1)`. */
|
|
118
|
+
declare function planAdjustLeverage(intent: Omit<AdjustLeverageIntent, "type">, view: AccountView): Step[];
|
|
119
|
+
/** Intents 1.1 / 1.2: collateral grows by `a`, debt grows to match. */
|
|
120
|
+
declare function planDeposit(intent: Omit<DepositStrategyIntent, "type">, view: AccountView): Step[];
|
|
121
|
+
/**
|
|
122
|
+
* Intent 3: funding comes in from the wallet and goes straight into the debt.
|
|
123
|
+
* Collateral never moves, so the whole plan is the funding's way to `U`.
|
|
124
|
+
*
|
|
125
|
+
* Funding in `U` needs no way there: it lands and is repaid, which is the whole
|
|
126
|
+
* plan. An RWA market also takes the raw asset behind its underlying, and that
|
|
127
|
+
* one is wrapped on the way in.
|
|
128
|
+
*
|
|
129
|
+
* `MAX_UINT256` settles the loan: the wallet is asked for the debt as it stands
|
|
130
|
+
* plus the headroom {@link SETTLE_MARGIN} allows for the interest of the blocks
|
|
131
|
+
* still to come, since the facade is told to repay everything outstanding
|
|
132
|
+
* rather than the amount quoted here.
|
|
133
|
+
*/
|
|
134
|
+
declare function planRepay(intent: Omit<RepayStrategyIntent, "type">, view: AccountView): Step[];
|
|
135
|
+
/**
|
|
136
|
+
* Intent 2.1: `W` of value leaves, debt shrinks by `D0 · W / C0` so leverage
|
|
137
|
+
* holds. Both are funded by the source `S`.
|
|
138
|
+
*/
|
|
139
|
+
declare function planWithdraw(intent: Omit<WithdrawStrategyIntent, "type">, view: AccountView): Step[];
|
|
140
|
+
/**
|
|
141
|
+
* Intent 2.1 against a source that cannot be sold on a DEX.
|
|
142
|
+
*
|
|
143
|
+
* Some collateral only converts through its issuer — a Securitize dsToken, a
|
|
144
|
+
* Mellow share — which answers a redemption request now and pays out days
|
|
145
|
+
* later. The trade is unchanged; what changes is that the proceeds do not exist
|
|
146
|
+
* yet, so this half only requests the redemption:
|
|
147
|
+
*
|
|
148
|
+
* ```
|
|
149
|
+
* request(S, W + dD) → [days] → claim → convert → repay → withdraw
|
|
150
|
+
* ```
|
|
151
|
+
*
|
|
152
|
+
* The tail is planned at claim time by {@link planFinishWithdraw}, from the
|
|
153
|
+
* intent this request records — only then is the claimed amount, and the token
|
|
154
|
+
* it arrived in, known.
|
|
155
|
+
*/
|
|
156
|
+
declare function planWithdrawDelayed(intent: Omit<WithdrawStrategyIntent, "type">, view: AccountView): Step[];
|
|
157
|
+
/**
|
|
158
|
+
* Intent 6.2 against a position token that only redeems through its issuer.
|
|
159
|
+
*
|
|
160
|
+
* Only deleveraging can be delayed: raising leverage borrows and buys, both of
|
|
161
|
+
* which settle at once. The request covers whatever idle underlying does not
|
|
162
|
+
* already, and the tail repays from the claim.
|
|
163
|
+
*/
|
|
164
|
+
declare function planAdjustLeverageDelayed(intent: Omit<AdjustLeverageIntent, "type">, view: AccountView): Step[];
|
|
165
|
+
/** Everything claimed goes into the debt. */
|
|
166
|
+
declare function planFinishDecreaseLeverage(claimable: ClaimableWithdrawal, claimed: {
|
|
167
|
+
token: Address;
|
|
168
|
+
amount: bigint;
|
|
169
|
+
}, view: AccountView): Step[];
|
|
170
|
+
/**
|
|
171
|
+
* The claim is split between the promised payout `W` and the debt the leading
|
|
172
|
+
* half deferred: the payout is served first, the debt gets what is left, so a
|
|
173
|
+
* routing shortfall shows as leverage a touch above target rather than as a
|
|
174
|
+
* payout the wallet was promised and did not get.
|
|
175
|
+
*/
|
|
176
|
+
declare function planFinishWithdraw(intent: {
|
|
177
|
+
withdrawToken: Address;
|
|
178
|
+
withdrawAmount: bigint;
|
|
179
|
+
debtRepaid: bigint;
|
|
180
|
+
sourceToken: Address;
|
|
181
|
+
to: Address;
|
|
182
|
+
}, claimable: ClaimableWithdrawal, claimed: {
|
|
183
|
+
token: Address;
|
|
184
|
+
amount: bigint;
|
|
185
|
+
}, view: AccountView): Step[];
|
|
186
|
+
/** Nothing is owed beyond the claim: the tokens land and quotas catch up. */
|
|
187
|
+
declare function planFinishClaimOnly(claimable: ClaimableWithdrawal): Step[];
|
|
188
|
+
//#endregion
|
|
189
|
+
export { AccountView, Amount, RAISED, Step, planAddCollateral, planAdjustLeverage, planAdjustLeverageDelayed, planDeposit, planFinishClaimOnly, planFinishDecreaseLeverage, planFinishWithdraw, planRepay, planWithdraw, planWithdrawAsset, planWithdrawDelayed };
|