@gearbox-protocol/sdk 15.1.0-next.1 → 15.1.0-next.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/abi/iExpirable.js +15 -0
- package/dist/cjs/common-utils/utils/apy/get-single-quota-borrow-rate.js +2 -0
- package/dist/cjs/common-utils/utils/creditAccount/calc-health-factor.js +24 -22
- package/dist/cjs/common-utils/utils/creditAccount/calc-quota-borrow-rate.js +2 -0
- package/dist/cjs/common-utils/utils/creditAccount/get-time-to-liquidation.js +8 -5
- package/dist/cjs/common-utils/utils/creditAccount/liquidation-price.js +21 -11
- package/dist/cjs/dev/AccountOpener.js +0 -1
- package/dist/cjs/dev/compareOpportunities.js +137 -0
- package/dist/cjs/dev/comparePositions.js +183 -0
- package/dist/cjs/dev/fieldDiff.js +241 -0
- package/dist/cjs/model/charts.js +147 -0
- package/dist/cjs/model/charts.schema.js +240 -0
- package/dist/cjs/model/index.js +35 -22
- package/dist/cjs/model/liquidations.schema.js +1 -1
- package/dist/cjs/model/notices.schema.js +25 -0
- package/dist/cjs/model/opportunities.schema.js +1 -1
- package/dist/cjs/model/positions.schema.js +48 -2
- package/dist/cjs/new-sdk/AbstractNamespace.js +34 -4
- package/dist/cjs/new-sdk/GearboxSDK.js +72 -3
- package/dist/cjs/new-sdk/execute/ExecuteApi.js +95 -0
- package/dist/cjs/new-sdk/execute/index.js +3 -0
- package/dist/cjs/new-sdk/index.js +7 -0
- package/dist/cjs/new-sdk/opportunities/OpportunitiesNamespace.js +29 -6
- package/dist/cjs/new-sdk/positions/PositionsNamespace.js +3 -6
- package/dist/cjs/new-sdk/simulate/SimulateApi.js +361 -0
- package/dist/cjs/new-sdk/simulate/index.js +4 -0
- package/dist/cjs/new-sdk/utils/index.js +0 -1
- package/dist/cjs/offchain/AbstractOffchainNamespace.js +10 -7
- package/dist/cjs/offchain/GearboxAPI.js +7 -0
- package/dist/cjs/offchain/index.js +3 -0
- package/dist/cjs/offchain/notices/OffchainNotices.js +27 -0
- package/dist/cjs/offchain/notices/index.js +3 -0
- package/dist/cjs/offchain/opportunities/OffchainOpportunities.js +4 -8
- package/dist/cjs/offchain/positions/OffchainPositions.js +12 -12
- package/dist/cjs/preview/preview/CreditAccountState.js +14 -1
- package/dist/cjs/preview/preview/buildDelayedPreview.js +16 -6
- package/dist/cjs/preview/preview/previewAdjustCreditAccount.js +9 -2
- package/dist/cjs/preview/preview/previewOpenCreditAccount.js +11 -3
- package/dist/cjs/preview/preview/previewOperation.js +1 -1
- package/dist/cjs/sdk/MultichainSDK.js +3 -4
- package/dist/cjs/sdk/OnchainSDK.js +42 -13
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +2 -8
- package/dist/cjs/sdk/accounts/credit-account-compressor/CreditAccountCompressor.js +2 -90
- package/dist/cjs/sdk/accounts/index.js +5 -2
- package/dist/cjs/sdk/accounts/intents/guards.js +114 -0
- package/dist/cjs/sdk/accounts/intents/index.js +216 -358
- package/dist/cjs/sdk/accounts/intents/math.js +56 -0
- package/dist/cjs/sdk/accounts/intents/open-strategy.js +133 -0
- package/dist/cjs/sdk/accounts/intents/operations.js +165 -0
- package/dist/cjs/sdk/accounts/intents/plan.js +373 -0
- package/dist/cjs/sdk/accounts/intents/realize.js +301 -0
- package/dist/cjs/sdk/accounts/intents/testing/delayed.js +50 -0
- package/dist/cjs/sdk/accounts/intents/testing/market.js +166 -0
- package/dist/cjs/sdk/accounts/intents/testing/sdk-mock.js +194 -35
- package/dist/cjs/sdk/accounts/intents/tests/add-collateral.fixtures.js +123 -0
- package/dist/cjs/sdk/accounts/intents/tests/adjust-leverage.fixtures.js +254 -0
- package/dist/cjs/sdk/accounts/intents/tests/deposit.fixtures.js +324 -0
- package/dist/cjs/sdk/accounts/intents/tests/finish-decrease-leverage.fixtures.js +242 -0
- package/dist/cjs/sdk/accounts/intents/tests/finish-withdraw.fixtures.js +383 -0
- package/dist/cjs/sdk/accounts/intents/tests/open-strategy.fixtures.js +133 -0
- package/dist/cjs/sdk/accounts/intents/tests/withdraw-asset.fixtures.js +131 -0
- package/dist/cjs/sdk/accounts/intents/tests/withdraw.fixtures.js +426 -0
- package/dist/cjs/sdk/accounts/intents/types.js +16 -0
- package/dist/cjs/sdk/accounts/intents/utils/adjust-state-to-snapshot.js +18 -0
- package/dist/cjs/sdk/accounts/intents/utils/credit-account-slice.js +45 -0
- package/dist/cjs/sdk/accounts/intents/utils/index.js +17 -8
- package/dist/cjs/sdk/accounts/intents/utils/ledger.js +94 -0
- package/dist/cjs/sdk/accounts/intents/utils/pick-token.js +72 -0
- package/dist/cjs/sdk/accounts/intents/utils/quotas-for-update.js +27 -0
- package/dist/cjs/sdk/accounts/intents/utils/router-path.js +86 -0
- package/dist/cjs/sdk/accounts/intents/view.js +38 -0
- package/dist/cjs/sdk/accounts/liquidations/LiquidationsService.js +0 -3
- package/dist/cjs/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.js +29 -18
- package/dist/cjs/sdk/base/BaseContract.js +1 -1
- package/dist/cjs/sdk/base/TokensMeta.js +78 -27
- package/dist/cjs/sdk/index.js +30 -7
- package/dist/cjs/sdk/market/MarketRegister.js +16 -7
- package/dist/cjs/sdk/market/ZapperRegister.js +56 -25
- package/dist/cjs/sdk/market/credit/CreditManagerV310Contract.js +1 -12
- package/dist/cjs/sdk/market/credit/CreditSuite.js +28 -9
- package/dist/cjs/sdk/market/credit/index.js +3 -0
- package/dist/cjs/sdk/market/credit/isStrategyCollateral.js +50 -0
- package/dist/cjs/sdk/market/index.js +17 -0
- package/dist/cjs/sdk/market/math.js +65 -45
- package/dist/cjs/sdk/market/oracle/PriceOracleBaseContract.js +10 -3
- package/dist/cjs/sdk/market/pool/PoolV310Contract.js +15 -1
- package/dist/cjs/sdk/market/rwa/RWARegistry.js +22 -0
- package/dist/cjs/sdk/opportunities/index.js +0 -13
- package/dist/cjs/sdk/options.js +1 -5
- package/dist/cjs/sdk/pools/PoolService.js +133 -4
- package/dist/cjs/sdk/pools/index.js +2 -0
- package/dist/cjs/sdk/positions/PositionsService.js +218 -1
- package/dist/cjs/sdk/positions/calcBorrowRate.js +43 -0
- package/dist/cjs/sdk/positions/calcHealthFactor.js +52 -0
- package/dist/cjs/sdk/positions/calcLiquidationPrice.js +23 -0
- package/dist/cjs/sdk/positions/calcLiquidationPriceForTarget.js +30 -0
- package/dist/cjs/sdk/positions/calcTimeToLiquidationMs.js +19 -0
- package/dist/cjs/sdk/positions/index.js +12 -1
- package/dist/cjs/sdk/positions/types.js +31 -0
- package/dist/cjs/sdk/utils/abi-decode.js +2 -2
- package/dist/cjs/sdk/utils/viem/executeMulticallBatches.js +32 -0
- package/dist/cjs/sdk/utils/viem/index.js +2 -0
- package/dist/esm/abi/iExpirable.js +14 -0
- package/dist/esm/common-utils/utils/apy/get-single-quota-borrow-rate.js +2 -0
- package/dist/esm/common-utils/utils/creditAccount/calc-health-factor.js +24 -22
- package/dist/esm/common-utils/utils/creditAccount/calc-quota-borrow-rate.js +2 -0
- package/dist/esm/common-utils/utils/creditAccount/get-time-to-liquidation.js +8 -5
- package/dist/esm/common-utils/utils/creditAccount/liquidation-price.js +21 -11
- package/dist/esm/dev/AccountOpener.js +0 -1
- package/dist/esm/dev/compareOpportunities.js +135 -0
- package/dist/esm/dev/comparePositions.js +181 -0
- package/dist/esm/dev/fieldDiff.js +224 -0
- package/dist/esm/model/charts.js +140 -0
- package/dist/esm/model/charts.schema.js +226 -0
- package/dist/esm/model/index.js +9 -7
- package/dist/esm/model/liquidations.schema.js +1 -1
- package/dist/esm/model/notices.schema.js +23 -0
- package/dist/esm/model/opportunities.schema.js +1 -1
- package/dist/esm/model/positions.schema.js +46 -4
- package/dist/esm/new-sdk/AbstractNamespace.js +34 -4
- package/dist/esm/new-sdk/GearboxSDK.js +72 -4
- package/dist/esm/new-sdk/execute/ExecuteApi.js +94 -0
- package/dist/esm/new-sdk/execute/index.js +2 -0
- package/dist/esm/new-sdk/index.js +6 -2
- package/dist/esm/new-sdk/opportunities/OpportunitiesNamespace.js +29 -6
- package/dist/esm/new-sdk/positions/PositionsNamespace.js +3 -6
- package/dist/esm/new-sdk/simulate/SimulateApi.js +360 -0
- package/dist/esm/new-sdk/simulate/index.js +3 -0
- package/dist/esm/new-sdk/utils/index.js +0 -1
- package/dist/esm/offchain/AbstractOffchainNamespace.js +10 -7
- package/dist/esm/offchain/GearboxAPI.js +7 -0
- package/dist/esm/offchain/index.js +3 -1
- package/dist/esm/offchain/notices/OffchainNotices.js +26 -0
- package/dist/esm/offchain/notices/index.js +2 -0
- package/dist/esm/offchain/opportunities/OffchainOpportunities.js +4 -8
- package/dist/esm/offchain/positions/OffchainPositions.js +12 -12
- package/dist/esm/preview/preview/CreditAccountState.js +14 -1
- package/dist/esm/preview/preview/buildDelayedPreview.js +16 -6
- package/dist/esm/preview/preview/previewAdjustCreditAccount.js +9 -2
- package/dist/esm/preview/preview/previewOpenCreditAccount.js +11 -3
- package/dist/esm/preview/preview/previewOperation.js +1 -1
- package/dist/esm/sdk/MultichainSDK.js +3 -4
- package/dist/esm/sdk/OnchainSDK.js +42 -13
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +2 -8
- package/dist/esm/sdk/accounts/credit-account-compressor/CreditAccountCompressor.js +2 -90
- package/dist/esm/sdk/accounts/index.js +3 -2
- package/dist/esm/sdk/accounts/intents/guards.js +108 -0
- package/dist/esm/sdk/accounts/intents/index.js +214 -358
- package/dist/esm/sdk/accounts/intents/math.js +51 -0
- package/dist/esm/sdk/accounts/intents/open-strategy.js +132 -0
- package/dist/esm/sdk/accounts/intents/operations.js +153 -0
- package/dist/esm/sdk/accounts/intents/plan.js +361 -0
- package/dist/esm/sdk/accounts/intents/realize.js +300 -0
- package/dist/esm/sdk/accounts/intents/testing/delayed.js +38 -0
- package/dist/esm/sdk/accounts/intents/testing/market.js +148 -0
- package/dist/esm/sdk/accounts/intents/testing/sdk-mock.js +194 -35
- package/dist/esm/sdk/accounts/intents/tests/add-collateral.fixtures.js +110 -0
- package/dist/esm/sdk/accounts/intents/tests/adjust-leverage.fixtures.js +234 -0
- package/dist/esm/sdk/accounts/intents/tests/deposit.fixtures.js +302 -0
- package/dist/esm/sdk/accounts/intents/tests/finish-decrease-leverage.fixtures.js +220 -0
- package/dist/esm/sdk/accounts/intents/tests/finish-withdraw.fixtures.js +355 -0
- package/dist/esm/sdk/accounts/intents/tests/open-strategy.fixtures.js +119 -0
- package/dist/esm/sdk/accounts/intents/tests/withdraw-asset.fixtures.js +117 -0
- package/dist/esm/sdk/accounts/intents/tests/withdraw.fixtures.js +402 -0
- package/dist/esm/sdk/accounts/intents/types.js +16 -1
- package/dist/esm/sdk/accounts/intents/utils/adjust-state-to-snapshot.js +17 -0
- package/dist/esm/sdk/accounts/intents/utils/credit-account-slice.js +43 -0
- package/dist/esm/sdk/accounts/intents/utils/index.js +9 -7
- package/dist/esm/sdk/accounts/intents/utils/ledger.js +93 -0
- package/dist/esm/sdk/accounts/intents/utils/pick-token.js +68 -0
- package/dist/esm/sdk/accounts/intents/utils/quotas-for-update.js +27 -1
- package/dist/esm/sdk/accounts/intents/utils/router-path.js +85 -0
- package/dist/esm/sdk/accounts/intents/view.js +37 -0
- package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +0 -3
- package/dist/esm/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.js +29 -18
- package/dist/esm/sdk/base/BaseContract.js +1 -1
- package/dist/esm/sdk/base/TokensMeta.js +78 -27
- package/dist/esm/sdk/index.js +13 -4
- package/dist/esm/sdk/market/MarketRegister.js +16 -7
- package/dist/esm/sdk/market/ZapperRegister.js +56 -25
- package/dist/esm/sdk/market/credit/CreditManagerV310Contract.js +2 -13
- package/dist/esm/sdk/market/credit/CreditSuite.js +29 -10
- package/dist/esm/sdk/market/credit/index.js +2 -1
- package/dist/esm/sdk/market/credit/isStrategyCollateral.js +48 -0
- package/dist/esm/sdk/market/index.js +3 -1
- package/dist/esm/sdk/market/math.js +60 -41
- package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +10 -3
- package/dist/esm/sdk/market/pool/PoolV310Contract.js +16 -2
- package/dist/esm/sdk/market/rwa/RWARegistry.js +22 -0
- package/dist/esm/sdk/opportunities/index.js +1 -2
- package/dist/esm/sdk/options.js +1 -5
- package/dist/esm/sdk/pools/PoolService.js +133 -6
- package/dist/esm/sdk/pools/index.js +2 -2
- package/dist/esm/sdk/positions/PositionsService.js +218 -1
- package/dist/esm/sdk/positions/calcBorrowRate.js +42 -0
- package/dist/esm/sdk/positions/calcHealthFactor.js +51 -0
- package/dist/esm/sdk/positions/calcLiquidationPrice.js +22 -0
- package/dist/esm/sdk/positions/calcLiquidationPriceForTarget.js +29 -0
- package/dist/esm/sdk/positions/calcTimeToLiquidationMs.js +18 -0
- package/dist/esm/sdk/positions/index.js +7 -2
- package/dist/esm/sdk/positions/types.js +31 -1
- package/dist/esm/sdk/utils/abi-decode.js +2 -2
- package/dist/esm/sdk/utils/viem/executeMulticallBatches.js +31 -0
- package/dist/esm/sdk/utils/viem/index.js +2 -1
- package/dist/types/abi/iExpirable.d.ts +14 -0
- package/dist/types/common-utils/utils/apy/get-single-quota-borrow-rate.d.ts +2 -0
- package/dist/types/common-utils/utils/creditAccount/calc-health-factor.d.ts +3 -0
- package/dist/types/common-utils/utils/creditAccount/calc-quota-borrow-rate.d.ts +2 -0
- package/dist/types/common-utils/utils/creditAccount/get-time-to-liquidation.d.ts +6 -1
- package/dist/types/common-utils/utils/creditAccount/liquidation-price.d.ts +3 -0
- package/dist/types/dev/compareOpportunities.d.ts +105 -0
- package/dist/types/dev/comparePositions.d.ts +149 -0
- package/dist/types/dev/fieldDiff.d.ts +167 -0
- package/dist/types/model/charts.d.ts +349 -0
- package/dist/types/model/charts.schema.d.ts +364 -0
- package/dist/types/model/index.d.ts +8 -6
- package/dist/types/model/notices.d.ts +29 -0
- package/dist/types/model/notices.schema.d.ts +23 -0
- package/dist/types/model/opportunities.d.ts +9 -9
- package/dist/types/model/positions.d.ts +133 -7
- package/dist/types/model/positions.schema.d.ts +128 -1
- package/dist/types/new-sdk/AbstractNamespace.d.ts +15 -2
- package/dist/types/new-sdk/GearboxSDK.d.ts +14 -2
- package/dist/types/new-sdk/execute/ExecuteApi.d.ts +108 -0
- package/dist/types/new-sdk/execute/index.d.ts +2 -0
- package/dist/types/new-sdk/index.d.ts +8 -4
- package/dist/types/new-sdk/opportunities/OpportunitiesNamespace.d.ts +19 -7
- package/dist/types/new-sdk/opportunities/types.d.ts +30 -9
- package/dist/types/new-sdk/positions/PositionsNamespace.d.ts +4 -5
- package/dist/types/new-sdk/positions/types.d.ts +9 -9
- package/dist/types/new-sdk/simulate/SimulateApi.d.ts +90 -0
- package/dist/types/new-sdk/simulate/index.d.ts +3 -0
- package/dist/types/new-sdk/simulate/types.d.ts +508 -0
- package/dist/types/new-sdk/types.d.ts +35 -1
- package/dist/types/new-sdk/utils/index.d.ts +1 -2
- package/dist/types/offchain/AbstractOffchainNamespace.d.ts +5 -21
- package/dist/types/offchain/GearboxAPI.d.ts +6 -0
- package/dist/types/offchain/index.d.ts +4 -2
- package/dist/types/offchain/notices/OffchainNotices.d.ts +19 -0
- package/dist/types/offchain/notices/index.d.ts +2 -0
- package/dist/types/offchain/opportunities/OffchainOpportunities.d.ts +8 -4
- package/dist/types/offchain/positions/OffchainPositions.d.ts +8 -6
- package/dist/types/preview/preview/CreditAccountState.d.ts +6 -0
- package/dist/types/preview/preview/buildDelayedPreview.d.ts +5 -1
- package/dist/types/preview/preview/types.d.ts +4 -2
- package/dist/types/sdk/MultichainSDK.d.ts +0 -5
- package/dist/types/sdk/OnchainSDK.d.ts +1 -5
- package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +1 -7
- package/dist/types/sdk/accounts/credit-account-compressor/CreditAccountCompressor.d.ts +3 -12
- package/dist/types/sdk/accounts/credit-account-compressor/index.d.ts +2 -2
- package/dist/types/sdk/accounts/credit-account-compressor/types.d.ts +1 -19
- package/dist/types/sdk/accounts/index.d.ts +7 -5
- package/dist/types/sdk/accounts/intents/guards.d.ts +72 -0
- package/dist/types/sdk/accounts/intents/index.d.ts +130 -15
- package/dist/types/sdk/accounts/intents/math.d.ts +46 -0
- package/dist/types/sdk/accounts/intents/open-strategy.d.ts +64 -0
- package/dist/types/sdk/accounts/intents/operations.d.ts +215 -0
- package/dist/types/sdk/accounts/intents/plan.d.ts +189 -0
- package/dist/types/sdk/accounts/intents/realize.d.ts +35 -0
- package/dist/types/sdk/accounts/intents/testing/delayed.d.ts +50 -0
- package/dist/types/sdk/accounts/intents/testing/expect.d.ts +17 -21
- package/dist/types/sdk/accounts/intents/testing/market.d.ts +91 -0
- package/dist/types/sdk/accounts/intents/testing/sdk-mock.d.ts +64 -16
- package/dist/types/sdk/accounts/intents/tests/add-collateral.fixtures.d.ts +45 -0
- package/dist/types/sdk/accounts/intents/tests/adjust-leverage.fixtures.d.ts +56 -0
- package/dist/types/sdk/accounts/intents/tests/deposit.fixtures.d.ts +64 -0
- package/dist/types/sdk/accounts/intents/tests/finish-decrease-leverage.fixtures.d.ts +107 -0
- package/dist/types/sdk/accounts/intents/tests/finish-withdraw.fixtures.d.ts +136 -0
- package/dist/types/sdk/accounts/intents/tests/open-strategy.fixtures.d.ts +56 -0
- package/dist/types/sdk/accounts/intents/tests/withdraw-asset.fixtures.d.ts +60 -0
- package/dist/types/sdk/accounts/intents/tests/withdraw.fixtures.d.ts +79 -0
- package/dist/types/sdk/accounts/intents/types.d.ts +369 -43
- package/dist/types/sdk/accounts/intents/utils/adjust-state-to-snapshot.d.ts +13 -0
- package/dist/types/sdk/accounts/intents/utils/assemble-operation-calls.d.ts +1 -1
- package/dist/types/sdk/accounts/intents/utils/credit-account-slice.d.ts +29 -0
- package/dist/types/sdk/accounts/intents/utils/index.d.ts +7 -5
- package/dist/types/sdk/accounts/intents/utils/ledger.d.ts +41 -0
- package/dist/types/sdk/accounts/intents/utils/pick-token.d.ts +55 -0
- package/dist/types/sdk/accounts/intents/utils/quotas-for-update.d.ts +15 -4
- package/dist/types/sdk/accounts/intents/utils/router-path.d.ts +70 -0
- package/dist/types/sdk/accounts/intents/view.d.ts +15 -0
- package/dist/types/sdk/accounts/types.d.ts +17 -14
- package/dist/types/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.d.ts +6 -0
- package/dist/types/sdk/accounts/withdrawal-compressor/types.d.ts +18 -0
- package/dist/types/sdk/base/TokensMeta.d.ts +44 -1
- package/dist/types/sdk/base/index.d.ts +2 -2
- package/dist/types/sdk/base/token-types.d.ts +12 -1
- package/dist/types/sdk/index.d.ts +28 -19
- package/dist/types/sdk/market/MarketRegister.d.ts +7 -3
- package/dist/types/sdk/market/ZapperRegister.d.ts +20 -2
- package/dist/types/sdk/market/credit/CreditManagerV310Contract.d.ts +0 -4
- package/dist/types/sdk/market/credit/CreditSuite.d.ts +6 -3
- package/dist/types/sdk/market/credit/index.d.ts +2 -1
- package/dist/types/sdk/market/credit/isStrategyCollateral.d.ts +74 -0
- package/dist/types/sdk/market/credit/types.d.ts +2 -9
- package/dist/types/sdk/market/index.d.ts +4 -2
- package/dist/types/sdk/market/math.d.ts +46 -34
- package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +6 -2
- package/dist/types/sdk/market/oracle/types.d.ts +10 -2
- package/dist/types/sdk/market/pool/PoolV310Contract.d.ts +5 -0
- package/dist/types/sdk/market/pool/types.d.ts +5 -0
- package/dist/types/sdk/market/rwa/RWARegistry.d.ts +13 -0
- package/dist/types/sdk/market/types.d.ts +5 -1
- package/dist/types/sdk/opportunities/index.d.ts +1 -2
- package/dist/types/sdk/options.d.ts +0 -1
- package/dist/types/sdk/pools/PoolService.d.ts +32 -2
- package/dist/types/sdk/pools/index.d.ts +3 -3
- package/dist/types/sdk/pools/types.d.ts +109 -4
- package/dist/types/sdk/positions/PositionsService.d.ts +33 -2
- package/dist/types/sdk/positions/calcBorrowRate.d.ts +40 -0
- package/dist/types/sdk/positions/calcHealthFactor.d.ts +55 -0
- package/dist/types/sdk/positions/calcLiquidationPrice.d.ts +12 -0
- package/dist/types/sdk/positions/calcLiquidationPriceForTarget.d.ts +43 -0
- package/dist/types/sdk/positions/calcTimeToLiquidationMs.d.ts +16 -0
- package/dist/types/sdk/positions/index.d.ts +7 -2
- package/dist/types/sdk/positions/types.d.ts +58 -1
- package/dist/types/sdk/types/state.d.ts +6 -0
- package/dist/types/sdk/utils/viem/executeMulticallBatches.d.ts +39 -0
- package/dist/types/sdk/utils/viem/index.d.ts +3 -2
- package/package.json +2 -1
- package/dist/cjs/model/history.js +0 -53
- package/dist/cjs/model/history.schema.js +0 -128
- package/dist/cjs/sdk/accounts/intents/intents/index.js +0 -14
- package/dist/cjs/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.fixtures.js +0 -121
- package/dist/cjs/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.js +0 -15
- package/dist/cjs/sdk/accounts/intents/intents/resume/close/close.fixtures.js +0 -108
- package/dist/cjs/sdk/accounts/intents/intents/resume/close/close.js +0 -51
- package/dist/cjs/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.fixtures.js +0 -130
- package/dist/cjs/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.js +0 -83
- package/dist/cjs/sdk/accounts/intents/intents/resume/deposit/deposit.fixtures.js +0 -117
- package/dist/cjs/sdk/accounts/intents/intents/resume/deposit/deposit.js +0 -15
- package/dist/cjs/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.fixtures.js +0 -95
- package/dist/cjs/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.js +0 -15
- package/dist/cjs/sdk/accounts/intents/intents/resume/index.js +0 -13
- package/dist/cjs/sdk/accounts/intents/intents/resume/withdraw/withdraw.fixtures.js +0 -138
- package/dist/cjs/sdk/accounts/intents/intents/resume/withdraw/withdraw.js +0 -161
- package/dist/cjs/sdk/accounts/intents/operations/add-collateral/index.js +0 -17
- package/dist/cjs/sdk/accounts/intents/operations/claim-delayed/index.js +0 -54
- package/dist/cjs/sdk/accounts/intents/operations/close-credit-account/index.js +0 -26
- package/dist/cjs/sdk/accounts/intents/operations/decrease-debt/index.js +0 -12
- package/dist/cjs/sdk/accounts/intents/operations/increase-debt/index.js +0 -12
- package/dist/cjs/sdk/accounts/intents/operations/index.js +0 -27
- package/dist/cjs/sdk/accounts/intents/operations/quota-update/index.js +0 -22
- package/dist/cjs/sdk/accounts/intents/operations/repay-credit-account/index.js +0 -22
- package/dist/cjs/sdk/accounts/intents/operations/start-delayed-withdrawal/index.js +0 -18
- package/dist/cjs/sdk/accounts/intents/operations/swap/index.js +0 -18
- package/dist/cjs/sdk/accounts/intents/operations/unwrap-rwa-collateral/index.js +0 -27
- package/dist/cjs/sdk/accounts/intents/operations/withdraw-collateral/index.js +0 -43
- package/dist/cjs/sdk/accounts/intents/operations/wrap-rwa-collateral/index.js +0 -27
- package/dist/cjs/sdk/accounts/intents/quoters/close.js +0 -58
- package/dist/cjs/sdk/accounts/intents/quoters/index.js +0 -7
- package/dist/cjs/sdk/accounts/intents/quoters/swap.js +0 -79
- package/dist/cjs/sdk/accounts/intents/testing/expect.js +0 -167
- package/dist/cjs/sdk/accounts/intents/testing/resume.js +0 -172
- package/dist/cjs/sdk/accounts/intents/utils/simulate-adjust-state.js +0 -39
- package/dist/cjs/sdk/accounts/intents/utils/simulate-assets.js +0 -69
- package/dist/cjs/sdk/accounts/intents/utils/with-quota-update.js +0 -13
- package/dist/esm/model/history.js +0 -49
- package/dist/esm/model/history.schema.js +0 -116
- package/dist/esm/sdk/accounts/intents/intents/index.js +0 -8
- package/dist/esm/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.fixtures.js +0 -107
- package/dist/esm/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.js +0 -14
- package/dist/esm/sdk/accounts/intents/intents/resume/close/close.fixtures.js +0 -94
- package/dist/esm/sdk/accounts/intents/intents/resume/close/close.js +0 -50
- package/dist/esm/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.fixtures.js +0 -114
- package/dist/esm/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.js +0 -82
- package/dist/esm/sdk/accounts/intents/intents/resume/deposit/deposit.fixtures.js +0 -110
- package/dist/esm/sdk/accounts/intents/intents/resume/deposit/deposit.js +0 -14
- package/dist/esm/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.fixtures.js +0 -88
- package/dist/esm/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.js +0 -14
- package/dist/esm/sdk/accounts/intents/intents/resume/index.js +0 -7
- package/dist/esm/sdk/accounts/intents/intents/resume/withdraw/withdraw.fixtures.js +0 -121
- package/dist/esm/sdk/accounts/intents/intents/resume/withdraw/withdraw.js +0 -160
- package/dist/esm/sdk/accounts/intents/operations/add-collateral/index.js +0 -16
- package/dist/esm/sdk/accounts/intents/operations/claim-delayed/index.js +0 -52
- package/dist/esm/sdk/accounts/intents/operations/close-credit-account/index.js +0 -25
- package/dist/esm/sdk/accounts/intents/operations/decrease-debt/index.js +0 -11
- package/dist/esm/sdk/accounts/intents/operations/increase-debt/index.js +0 -11
- package/dist/esm/sdk/accounts/intents/operations/index.js +0 -14
- package/dist/esm/sdk/accounts/intents/operations/quota-update/index.js +0 -21
- package/dist/esm/sdk/accounts/intents/operations/repay-credit-account/index.js +0 -21
- package/dist/esm/sdk/accounts/intents/operations/start-delayed-withdrawal/index.js +0 -17
- package/dist/esm/sdk/accounts/intents/operations/swap/index.js +0 -17
- package/dist/esm/sdk/accounts/intents/operations/unwrap-rwa-collateral/index.js +0 -26
- package/dist/esm/sdk/accounts/intents/operations/withdraw-collateral/index.js +0 -42
- package/dist/esm/sdk/accounts/intents/operations/wrap-rwa-collateral/index.js +0 -26
- package/dist/esm/sdk/accounts/intents/quoters/close.js +0 -56
- package/dist/esm/sdk/accounts/intents/quoters/index.js +0 -3
- package/dist/esm/sdk/accounts/intents/quoters/swap.js +0 -77
- package/dist/esm/sdk/accounts/intents/testing/expect.js +0 -162
- package/dist/esm/sdk/accounts/intents/testing/resume.js +0 -157
- package/dist/esm/sdk/accounts/intents/utils/simulate-adjust-state.js +0 -38
- package/dist/esm/sdk/accounts/intents/utils/simulate-assets.js +0 -68
- package/dist/esm/sdk/accounts/intents/utils/with-quota-update.js +0 -12
- package/dist/types/model/history.d.ts +0 -153
- package/dist/types/model/history.schema.d.ts +0 -95
- package/dist/types/new-sdk/utils/history.d.ts +0 -18
- package/dist/types/sdk/accounts/intents/intents/index.d.ts +0 -8
- package/dist/types/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.d.ts +0 -13
- package/dist/types/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.fixtures.d.ts +0 -38
- package/dist/types/sdk/accounts/intents/intents/resume/close/close.d.ts +0 -26
- package/dist/types/sdk/accounts/intents/intents/resume/close/close.fixtures.d.ts +0 -63
- package/dist/types/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.d.ts +0 -26
- package/dist/types/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.fixtures.d.ts +0 -86
- package/dist/types/sdk/accounts/intents/intents/resume/deposit/deposit.d.ts +0 -13
- package/dist/types/sdk/accounts/intents/intents/resume/deposit/deposit.fixtures.d.ts +0 -48
- package/dist/types/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.d.ts +0 -13
- package/dist/types/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.fixtures.d.ts +0 -46
- package/dist/types/sdk/accounts/intents/intents/resume/index.d.ts +0 -7
- package/dist/types/sdk/accounts/intents/intents/resume/withdraw/withdraw.d.ts +0 -33
- package/dist/types/sdk/accounts/intents/intents/resume/withdraw/withdraw.fixtures.d.ts +0 -68
- package/dist/types/sdk/accounts/intents/operations/add-collateral/index.d.ts +0 -23
- package/dist/types/sdk/accounts/intents/operations/claim-delayed/index.d.ts +0 -55
- package/dist/types/sdk/accounts/intents/operations/close-credit-account/index.d.ts +0 -22
- package/dist/types/sdk/accounts/intents/operations/decrease-debt/index.d.ts +0 -18
- package/dist/types/sdk/accounts/intents/operations/increase-debt/index.d.ts +0 -18
- package/dist/types/sdk/accounts/intents/operations/index.d.ts +0 -14
- package/dist/types/sdk/accounts/intents/operations/quota-update/index.d.ts +0 -24
- package/dist/types/sdk/accounts/intents/operations/repay-credit-account/index.d.ts +0 -31
- package/dist/types/sdk/accounts/intents/operations/start-delayed-withdrawal/index.d.ts +0 -23
- package/dist/types/sdk/accounts/intents/operations/swap/index.d.ts +0 -28
- package/dist/types/sdk/accounts/intents/operations/types.d.ts +0 -21
- package/dist/types/sdk/accounts/intents/operations/unwrap-rwa-collateral/index.d.ts +0 -30
- package/dist/types/sdk/accounts/intents/operations/withdraw-collateral/index.d.ts +0 -36
- package/dist/types/sdk/accounts/intents/operations/wrap-rwa-collateral/index.d.ts +0 -30
- package/dist/types/sdk/accounts/intents/quoters/close.d.ts +0 -43
- package/dist/types/sdk/accounts/intents/quoters/index.d.ts +0 -3
- package/dist/types/sdk/accounts/intents/quoters/swap.d.ts +0 -43
- package/dist/types/sdk/accounts/intents/testing/resume.d.ts +0 -84
- package/dist/types/sdk/accounts/intents/utils/simulate-adjust-state.d.ts +0 -19
- package/dist/types/sdk/accounts/intents/utils/simulate-assets.d.ts +0 -21
- package/dist/types/sdk/accounts/intents/utils/with-quota-update.d.ts +0 -16
- /package/dist/cjs/{new-sdk/utils/history.js → model/notices.js} +0 -0
- /package/dist/cjs/{sdk/accounts/intents/operations → new-sdk/simulate}/types.js +0 -0
- /package/dist/esm/{new-sdk/utils/history.js → model/notices.js} +0 -0
- /package/dist/esm/{sdk/accounts/intents/operations → new-sdk/simulate}/types.js +0 -0
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { eq, toTargetDecimals } from "../../../utils/common.js";
|
|
2
|
-
import { simulateState } from "../../../utils/simulate-adjust-state.js";
|
|
3
|
-
import "../../../utils/index.js";
|
|
4
|
-
import { buildClaimDelayedWithdrawalOperation, primaryInstantOutput } from "../../../operations/claim-delayed/index.js";
|
|
5
|
-
import { buildDecreaseDebtOperation } from "../../../operations/decrease-debt/index.js";
|
|
6
|
-
import { buildSwapOperation } from "../../../operations/swap/index.js";
|
|
7
|
-
import { buildWrapRwaCollateralOperation } from "../../../operations/wrap-rwa-collateral/index.js";
|
|
8
|
-
import "../../../operations/index.js";
|
|
9
|
-
//#region src/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.ts
|
|
10
|
-
/**
|
|
11
|
-
* Resume decrease-leverage — linear op chain:
|
|
12
|
-
* claim → (wrapRwa | swap)? → decreaseDebt.
|
|
13
|
-
* All claimed proceeds fund debt repay (legacy
|
|
14
|
-
* `buildDecreaseLeverageResumeLogicalOps` + `buildResumeRepayFromClaimOps`).
|
|
15
|
-
* Conversion legs go through the given quoter; wrap is 1:1 decimals rescale.
|
|
16
|
-
*/
|
|
17
|
-
async function buildResumeDecreaseLeverageOperations(props, quoter) {
|
|
18
|
-
const { options, creditAccount, sdk } = props;
|
|
19
|
-
const underlying = creditAccount.underlying;
|
|
20
|
-
const rwaMeta = sdk.tokensMeta.rwaUnderlyings.get(underlying);
|
|
21
|
-
const claimOp = buildClaimDelayedWithdrawalOperation({
|
|
22
|
-
creditAccount,
|
|
23
|
-
sdk
|
|
24
|
-
}, options);
|
|
25
|
-
const primary = primaryInstantOutput(claimOp.outputs);
|
|
26
|
-
if (!primary || primary.amount <= 0n) throw new Error("No claimable assets");
|
|
27
|
-
const operations = [claimOp];
|
|
28
|
-
const decreaseDebt = (amount) => {
|
|
29
|
-
if (amount > 0n) operations.push(buildDecreaseDebtOperation({
|
|
30
|
-
amount,
|
|
31
|
-
creditAccount,
|
|
32
|
-
sdk
|
|
33
|
-
}, options));
|
|
34
|
-
};
|
|
35
|
-
if (eq(primary.token, underlying)) {
|
|
36
|
-
decreaseDebt(primary.amount);
|
|
37
|
-
return operations;
|
|
38
|
-
}
|
|
39
|
-
const rwaAsset = rwaMeta?.asset;
|
|
40
|
-
if (rwaAsset != null && eq(primary.token, rwaAsset)) {
|
|
41
|
-
const amountOut = toTargetDecimals(primary.amount, primary.token, underlying, sdk);
|
|
42
|
-
operations.push(await buildWrapRwaCollateralOperation({
|
|
43
|
-
tokenIn: primary.token,
|
|
44
|
-
amountIn: primary.amount,
|
|
45
|
-
tokenOut: underlying,
|
|
46
|
-
amountOut,
|
|
47
|
-
creditAccount,
|
|
48
|
-
sdk
|
|
49
|
-
}, options));
|
|
50
|
-
decreaseDebt(amountOut);
|
|
51
|
-
return operations;
|
|
52
|
-
} else {
|
|
53
|
-
const { state } = simulateState({
|
|
54
|
-
operations,
|
|
55
|
-
creditAccount,
|
|
56
|
-
sdk,
|
|
57
|
-
quotaReserve: props.quotaReserve
|
|
58
|
-
});
|
|
59
|
-
const tokenInBalance = state.assets.find((asset) => eq(asset.token, primary.token))?.balance ?? 0n;
|
|
60
|
-
const quote = await quoter({
|
|
61
|
-
from: [{
|
|
62
|
-
token: primary.token,
|
|
63
|
-
balance: primary.amount
|
|
64
|
-
}],
|
|
65
|
-
tokenOut: underlying,
|
|
66
|
-
tokenInBalance
|
|
67
|
-
});
|
|
68
|
-
operations.push(buildSwapOperation({
|
|
69
|
-
tokenIn: primary.token,
|
|
70
|
-
amountIn: primary.amount,
|
|
71
|
-
tokenOut: underlying,
|
|
72
|
-
amountOut: quote.minAmount,
|
|
73
|
-
calls: quote.calls,
|
|
74
|
-
creditAccount,
|
|
75
|
-
sdk
|
|
76
|
-
}, options));
|
|
77
|
-
decreaseDebt(quote.minAmount);
|
|
78
|
-
return operations;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
//#endregion
|
|
82
|
-
export { buildResumeDecreaseLeverageOperations };
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { ANY, RESUME_FIXTURE_PHANTOM, RWA_ASSET, UND, buildClaimResumeProps } from "../../../testing/resume.js";
|
|
2
|
-
//#region src/sdk/accounts/intents/intents/resume/deposit/deposit.fixtures.ts
|
|
3
|
-
/** Shared op amounts from deposit.flow (fixed-L collateral-up). */
|
|
4
|
-
const DEPOSIT_ADD_UND = 100000000000n;
|
|
5
|
-
const ANY_SWAP_OUT = 10000000000000000000000n;
|
|
6
|
-
const RWA_CLAIMED = 500000000000n;
|
|
7
|
-
const QUOTA_INCREASE = 460000000000n;
|
|
8
|
-
/** Post-claim metrics after fixed-L deposit (literals, not derived). */
|
|
9
|
-
const DEPOSIT_T1 = 5500000000000n;
|
|
10
|
-
const DEPOSIT_D1 = 4400000000000n;
|
|
11
|
-
/**
|
|
12
|
-
* Flow B non-RWA: C=und, T=any.
|
|
13
|
-
* Full: add + increaseDebt + swap(und→any) + changeQuota
|
|
14
|
-
* Resume: changeQuota only
|
|
15
|
-
*/
|
|
16
|
-
const case_b_und_any = {
|
|
17
|
-
claimedToken: ANY,
|
|
18
|
-
claimedAmount: ANY_SWAP_OUT,
|
|
19
|
-
postClaimTotalValue: DEPOSIT_T1,
|
|
20
|
-
postClaimDebt: DEPOSIT_D1,
|
|
21
|
-
resumeOps: [{
|
|
22
|
-
type: "claimDelayedWithdrawal",
|
|
23
|
-
token: ANY,
|
|
24
|
-
withdrawalPhantomToken: RESUME_FIXTURE_PHANTOM,
|
|
25
|
-
withdrawalTokenSpent: ANY_SWAP_OUT,
|
|
26
|
-
outputs: [{
|
|
27
|
-
token: ANY,
|
|
28
|
-
amount: ANY_SWAP_OUT,
|
|
29
|
-
isDelayed: false
|
|
30
|
-
}],
|
|
31
|
-
calls: []
|
|
32
|
-
}, {
|
|
33
|
-
type: "changeQuota",
|
|
34
|
-
quotaIncrease: [{
|
|
35
|
-
token: ANY,
|
|
36
|
-
balance: QUOTA_INCREASE
|
|
37
|
-
}],
|
|
38
|
-
quotaDecrease: [],
|
|
39
|
-
desiredQuota: {}
|
|
40
|
-
}],
|
|
41
|
-
expectedQuotaBalance: QUOTA_INCREASE
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* Flow B RWA: C=und, T=asset.
|
|
45
|
-
* Full: add + increaseDebt + swap + unwrap + changeQuota
|
|
46
|
-
* Resume: changeQuota only
|
|
47
|
-
*/
|
|
48
|
-
const case_b_und_rwa = {
|
|
49
|
-
claimedToken: RWA_ASSET,
|
|
50
|
-
claimedAmount: RWA_CLAIMED,
|
|
51
|
-
postClaimTotalValue: DEPOSIT_T1,
|
|
52
|
-
postClaimDebt: DEPOSIT_D1,
|
|
53
|
-
resumeOps: [{
|
|
54
|
-
type: "claimDelayedWithdrawal",
|
|
55
|
-
token: RWA_ASSET,
|
|
56
|
-
withdrawalPhantomToken: RESUME_FIXTURE_PHANTOM,
|
|
57
|
-
withdrawalTokenSpent: RWA_CLAIMED,
|
|
58
|
-
outputs: [{
|
|
59
|
-
token: RWA_ASSET,
|
|
60
|
-
amount: RWA_CLAIMED,
|
|
61
|
-
isDelayed: false
|
|
62
|
-
}],
|
|
63
|
-
calls: []
|
|
64
|
-
}, {
|
|
65
|
-
type: "changeQuota",
|
|
66
|
-
quotaIncrease: [{
|
|
67
|
-
token: RWA_ASSET,
|
|
68
|
-
balance: QUOTA_INCREASE
|
|
69
|
-
}],
|
|
70
|
-
quotaDecrease: [],
|
|
71
|
-
desiredQuota: {}
|
|
72
|
-
}],
|
|
73
|
-
expectedQuotaBalance: QUOTA_INCREASE
|
|
74
|
-
};
|
|
75
|
-
/** Claimed und — no active quota-buy path. */
|
|
76
|
-
const case_claimed_und = {
|
|
77
|
-
claimedToken: UND,
|
|
78
|
-
claimedAmount: DEPOSIT_ADD_UND,
|
|
79
|
-
postClaimTotalValue: 5000000000000n,
|
|
80
|
-
postClaimDebt: 4000000000000n,
|
|
81
|
-
baseAssets: [{
|
|
82
|
-
token: ANY,
|
|
83
|
-
balance: 98000000000000000000000n,
|
|
84
|
-
quota: 0n,
|
|
85
|
-
mask: 0n,
|
|
86
|
-
success: true
|
|
87
|
-
}],
|
|
88
|
-
resumeOps: [{
|
|
89
|
-
type: "claimDelayedWithdrawal",
|
|
90
|
-
token: UND,
|
|
91
|
-
withdrawalPhantomToken: RESUME_FIXTURE_PHANTOM,
|
|
92
|
-
withdrawalTokenSpent: DEPOSIT_ADD_UND,
|
|
93
|
-
outputs: [{
|
|
94
|
-
token: UND,
|
|
95
|
-
amount: DEPOSIT_ADD_UND,
|
|
96
|
-
isDelayed: false
|
|
97
|
-
}],
|
|
98
|
-
calls: []
|
|
99
|
-
}]
|
|
100
|
-
};
|
|
101
|
-
function buildResumeDepositProps(args) {
|
|
102
|
-
return buildClaimResumeProps({
|
|
103
|
-
intent: args.delayedIntent,
|
|
104
|
-
case: args.case,
|
|
105
|
-
sdk: args.sdk,
|
|
106
|
-
options: args.options
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
//#endregion
|
|
110
|
-
export { ANY_SWAP_OUT, DEPOSIT_ADD_UND, QUOTA_INCREASE, buildResumeDepositProps, case_b_und_any, case_b_und_rwa, case_claimed_und };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { buildClaimDelayedWithdrawalOperation } from "../../../operations/claim-delayed/index.js";
|
|
2
|
-
import "../../../operations/index.js";
|
|
3
|
-
//#region src/sdk/accounts/intents/intents/resume/deposit/deposit.ts
|
|
4
|
-
/**
|
|
5
|
-
* Shared by DEPOSIT and DEPOSIT_AND_INCREASE_LEVERAGE resume
|
|
6
|
-
*/
|
|
7
|
-
function buildResumeDepositOperations(creditAccount, options, sdk) {
|
|
8
|
-
return [buildClaimDelayedWithdrawalOperation({
|
|
9
|
-
creditAccount,
|
|
10
|
-
sdk
|
|
11
|
-
}, options)];
|
|
12
|
-
}
|
|
13
|
-
//#endregion
|
|
14
|
-
export { buildResumeDepositOperations };
|
package/dist/esm/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.fixtures.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { ANY, RESUME_FIXTURE_PHANTOM, RWA_ASSET, buildClaimResumeProps } from "../../../testing/resume.js";
|
|
2
|
-
//#region src/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.fixtures.ts
|
|
3
|
-
/**
|
|
4
|
-
* Resume increase-leverage fixtures, ported from intent-calculator
|
|
5
|
-
* `increaseLeverage.flowFixtures.ts` (resume cases only). Shared token / sdk /
|
|
6
|
-
* options helpers live in `testing/resume.ts`.
|
|
7
|
-
*/
|
|
8
|
-
/** Borrow delta for L0→L1_SIX with fixed collateral. */
|
|
9
|
-
const INCREASE_DEBT_AMOUNT = 1000000000000n;
|
|
10
|
-
/** Oracle swap out for `INCREASE_DEBT_AMOUNT` und → ANY. */
|
|
11
|
-
const ANY_SWAP_AMOUNT_OUT = 20000000000000000000000n;
|
|
12
|
-
/** Quota increase for obtained ANY / RWA asset (buyQuotaMode excess). */
|
|
13
|
-
const QUOTA_INCREASE = 920000000000n;
|
|
14
|
-
/** Post-borrow / post-claim CA metrics (fixed C). */
|
|
15
|
-
const INCREASE_POST_T = 6000000000000n;
|
|
16
|
-
const INCREASE_POST_D = 5000000000000n;
|
|
17
|
-
/**
|
|
18
|
-
* Case 2.1 — NON RWA, target=ANY (borrow stays on CA).
|
|
19
|
-
* Full: increaseDebt → swap(und→any) → changeQuota(any)
|
|
20
|
-
* Resume: claim → changeQuota(any)
|
|
21
|
-
*/
|
|
22
|
-
const case_2_1_any = {
|
|
23
|
-
claimedToken: ANY,
|
|
24
|
-
claimedAmount: ANY_SWAP_AMOUNT_OUT,
|
|
25
|
-
postClaimTotalValue: INCREASE_POST_T,
|
|
26
|
-
postClaimDebt: INCREASE_POST_D,
|
|
27
|
-
resumeOps: [{
|
|
28
|
-
type: "claimDelayedWithdrawal",
|
|
29
|
-
token: ANY,
|
|
30
|
-
withdrawalPhantomToken: RESUME_FIXTURE_PHANTOM,
|
|
31
|
-
withdrawalTokenSpent: ANY_SWAP_AMOUNT_OUT,
|
|
32
|
-
outputs: [{
|
|
33
|
-
token: ANY,
|
|
34
|
-
amount: ANY_SWAP_AMOUNT_OUT,
|
|
35
|
-
isDelayed: false
|
|
36
|
-
}],
|
|
37
|
-
calls: []
|
|
38
|
-
}, {
|
|
39
|
-
type: "changeQuota",
|
|
40
|
-
quotaIncrease: [{
|
|
41
|
-
token: ANY,
|
|
42
|
-
balance: QUOTA_INCREASE
|
|
43
|
-
}],
|
|
44
|
-
quotaDecrease: [],
|
|
45
|
-
desiredQuota: {}
|
|
46
|
-
}]
|
|
47
|
-
};
|
|
48
|
-
/**
|
|
49
|
-
* Case 1.2 — RWA, target=asset.
|
|
50
|
-
* Full: increaseDebt → unwrap(und→asset) → changeQuota(asset)
|
|
51
|
-
* Resume: claim(asset) → changeQuota(asset)
|
|
52
|
-
*/
|
|
53
|
-
const case_1_2_asset_rwa = {
|
|
54
|
-
claimedToken: RWA_ASSET,
|
|
55
|
-
claimedAmount: INCREASE_DEBT_AMOUNT,
|
|
56
|
-
postClaimTotalValue: INCREASE_POST_T,
|
|
57
|
-
postClaimDebt: INCREASE_POST_D,
|
|
58
|
-
resumeOps: [{
|
|
59
|
-
type: "claimDelayedWithdrawal",
|
|
60
|
-
token: RWA_ASSET,
|
|
61
|
-
withdrawalPhantomToken: RESUME_FIXTURE_PHANTOM,
|
|
62
|
-
withdrawalTokenSpent: INCREASE_DEBT_AMOUNT,
|
|
63
|
-
outputs: [{
|
|
64
|
-
token: RWA_ASSET,
|
|
65
|
-
amount: INCREASE_DEBT_AMOUNT,
|
|
66
|
-
isDelayed: false
|
|
67
|
-
}],
|
|
68
|
-
calls: []
|
|
69
|
-
}, {
|
|
70
|
-
type: "changeQuota",
|
|
71
|
-
quotaIncrease: [{
|
|
72
|
-
token: RWA_ASSET,
|
|
73
|
-
balance: QUOTA_INCREASE
|
|
74
|
-
}],
|
|
75
|
-
quotaDecrease: [],
|
|
76
|
-
desiredQuota: {}
|
|
77
|
-
}]
|
|
78
|
-
};
|
|
79
|
-
function buildResumeIncreaseLeverageProps(args) {
|
|
80
|
-
return buildClaimResumeProps({
|
|
81
|
-
intent: { type: "INCREASE_LEVERAGE" },
|
|
82
|
-
case: args.case,
|
|
83
|
-
sdk: args.sdk,
|
|
84
|
-
options: args.options
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
//#endregion
|
|
88
|
-
export { INCREASE_DEBT_AMOUNT, INCREASE_POST_D, INCREASE_POST_T, QUOTA_INCREASE, buildResumeIncreaseLeverageProps, case_1_2_asset_rwa, case_2_1_any };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { buildClaimDelayedWithdrawalOperation } from "../../../operations/claim-delayed/index.js";
|
|
2
|
-
import "../../../operations/index.js";
|
|
3
|
-
//#region src/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.ts
|
|
4
|
-
/**
|
|
5
|
-
* Resume increase-leverage: claim only
|
|
6
|
-
*/
|
|
7
|
-
function buildResumeIncreaseLeverageOperations(creditAccount, options, sdk) {
|
|
8
|
-
return [buildClaimDelayedWithdrawalOperation({
|
|
9
|
-
creditAccount,
|
|
10
|
-
sdk
|
|
11
|
-
}, options)];
|
|
12
|
-
}
|
|
13
|
-
//#endregion
|
|
14
|
-
export { buildResumeIncreaseLeverageOperations };
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { buildResumeAddCollateralOperations } from "./add-collateral/add-collateral.js";
|
|
2
|
-
import { buildResumeCloseOperations } from "./close/close.js";
|
|
3
|
-
import { buildResumeDecreaseLeverageOperations } from "./decrease-leverage/decrease-leverage.js";
|
|
4
|
-
import { buildResumeDepositOperations } from "./deposit/deposit.js";
|
|
5
|
-
import { buildResumeIncreaseLeverageOperations } from "./increase-leverage/increase-leverage.js";
|
|
6
|
-
import { buildResumeWithdrawOperations } from "./withdraw/withdraw.js";
|
|
7
|
-
export { buildResumeAddCollateralOperations, buildResumeCloseOperations, buildResumeDecreaseLeverageOperations, buildResumeDepositOperations, buildResumeIncreaseLeverageOperations, buildResumeWithdrawOperations };
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { toBN } from "../../../../../utils/formatter.js";
|
|
2
|
-
import "../../../../../index.js";
|
|
3
|
-
import { MOCK_CLAIM_CALL } from "../../../testing/sdk-mock.js";
|
|
4
|
-
import { CREDIT_ACCOUNT, CREDIT_FACADE, CREDIT_MANAGER, UND, buildResumeSdk } from "../../../testing/resume.js";
|
|
5
|
-
//#region src/sdk/accounts/intents/intents/resume/withdraw/withdraw.fixtures.ts
|
|
6
|
-
/**
|
|
7
|
-
* Resume withdraw fixtures, ported from intent-calculator
|
|
8
|
-
* `withdraw.flowFixtures.ts` (resume cases only).
|
|
9
|
-
*/
|
|
10
|
-
const WITHDRAW_UND = toBN("1000", 8);
|
|
11
|
-
const WITHDRAW_ANY = toBN("2000", 18);
|
|
12
|
-
const WITHDRAW_ANY2 = toBN("2000", 18);
|
|
13
|
-
/** Withdraw amount in rwa.asset units (8 decimals, priced 1:1 with UND). */
|
|
14
|
-
const WITHDRAW_RWA = toBN("2000", 8);
|
|
15
|
-
const DEBT_DELTA = toBN("4000", 8);
|
|
16
|
-
const PHANTOM = "0xb1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1";
|
|
17
|
-
/** Per-token CA balance (legacy `A0_TOK` / und balance). */
|
|
18
|
-
const A0 = toBN("100000", 18);
|
|
19
|
-
const A0_UND = toBN("100000", 8);
|
|
20
|
-
const QUOTA0 = toBN("50000", 8);
|
|
21
|
-
/** Starting account debt on the fixture CA. */
|
|
22
|
-
const WITHDRAW_PRE_D = toBN("40000", 8);
|
|
23
|
-
/**
|
|
24
|
-
* Starting TVL of the fixture CA tokens (ANY + ANY2 + UND). Claim may add
|
|
25
|
-
* value when the phantom is absent from `tokens` (current fixtures).
|
|
26
|
-
*/
|
|
27
|
-
const WITHDRAW_BASE_TV = 20000000000000n;
|
|
28
|
-
const WITHDRAW_TO = "0x1234567890123456789012345678901234567890";
|
|
29
|
-
function withdrawAmountFor(token) {
|
|
30
|
-
if (token === "0x3333333333333333333333333333333333333333") return WITHDRAW_UND;
|
|
31
|
-
if (token === "0x1111111111111111111111111111111111111111") return WITHDRAW_ANY;
|
|
32
|
-
return WITHDRAW_ANY2;
|
|
33
|
-
}
|
|
34
|
-
function buildWithdrawSdk(args) {
|
|
35
|
-
return buildResumeSdk({ claimedToken: args.claimedToken }, {
|
|
36
|
-
extraPrices: args.extraPrices,
|
|
37
|
-
extraDecimals: args.extraDecimals,
|
|
38
|
-
rwaAssets: args.rwaAssets,
|
|
39
|
-
phantom: PHANTOM
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
function buildWithdrawOffchainOptions(args) {
|
|
43
|
-
return {
|
|
44
|
-
kind: "offchain",
|
|
45
|
-
phantomSpent: args.claimedAmount,
|
|
46
|
-
withdrawalConfig: {
|
|
47
|
-
creditManager: CREDIT_MANAGER,
|
|
48
|
-
token: args.claimedToken,
|
|
49
|
-
withdrawalPhantomToken: PHANTOM,
|
|
50
|
-
underlying: args.claimedToken,
|
|
51
|
-
withdrawalLength: 0n
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
function buildWithdrawOnchainOptions(args) {
|
|
56
|
-
return {
|
|
57
|
-
kind: "onchain",
|
|
58
|
-
claimableWithdrawal: {
|
|
59
|
-
token: args.claimedToken,
|
|
60
|
-
withdrawalPhantomToken: PHANTOM,
|
|
61
|
-
withdrawalTokenSpent: args.claimedAmount,
|
|
62
|
-
outputs: [{
|
|
63
|
-
token: args.claimedToken,
|
|
64
|
-
amount: args.claimedAmount,
|
|
65
|
-
isDelayed: false
|
|
66
|
-
}],
|
|
67
|
-
claimCalls: [MOCK_CLAIM_CALL]
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
function buildWithdrawResumeProps(args) {
|
|
72
|
-
const creditAccount = {
|
|
73
|
-
creditAccount: CREDIT_ACCOUNT,
|
|
74
|
-
creditManager: CREDIT_MANAGER,
|
|
75
|
-
creditFacade: CREDIT_FACADE,
|
|
76
|
-
underlying: UND,
|
|
77
|
-
enabledTokensMask: 0n,
|
|
78
|
-
totalDebtUSD: 0n,
|
|
79
|
-
accountDebt: WITHDRAW_PRE_D,
|
|
80
|
-
tokens: args.tokens ?? [
|
|
81
|
-
{
|
|
82
|
-
token: "0x1111111111111111111111111111111111111111",
|
|
83
|
-
balance: A0,
|
|
84
|
-
quota: QUOTA0,
|
|
85
|
-
mask: 0n,
|
|
86
|
-
success: true
|
|
87
|
-
},
|
|
88
|
-
{
|
|
89
|
-
token: "0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
|
|
90
|
-
balance: A0,
|
|
91
|
-
quota: QUOTA0,
|
|
92
|
-
mask: 0n,
|
|
93
|
-
success: true
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
token: "0x3333333333333333333333333333333333333333",
|
|
97
|
-
balance: A0_UND,
|
|
98
|
-
quota: 0n,
|
|
99
|
-
mask: 0n,
|
|
100
|
-
success: true
|
|
101
|
-
}
|
|
102
|
-
]
|
|
103
|
-
};
|
|
104
|
-
return {
|
|
105
|
-
intent: {
|
|
106
|
-
type: "WITHDRAW_COLLATERAL",
|
|
107
|
-
to: WITHDRAW_TO,
|
|
108
|
-
sourceToken: args.sourceToken,
|
|
109
|
-
withdrawToken: args.withdrawToken,
|
|
110
|
-
withdrawAmount: args.withdrawAmount ?? withdrawAmountFor(args.withdrawToken),
|
|
111
|
-
debtRepaid: args.debtRepaid
|
|
112
|
-
},
|
|
113
|
-
creditAccount,
|
|
114
|
-
sdk: args.sdk,
|
|
115
|
-
quotaReserve: void 0,
|
|
116
|
-
options: args.options,
|
|
117
|
-
slippage: args.slippage ?? 50
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
//#endregion
|
|
121
|
-
export { A0, A0_UND, DEBT_DELTA, PHANTOM, QUOTA0, WITHDRAW_ANY, WITHDRAW_ANY2, WITHDRAW_BASE_TV, WITHDRAW_PRE_D, WITHDRAW_RWA, WITHDRAW_TO, WITHDRAW_UND, buildWithdrawOffchainOptions, buildWithdrawOnchainOptions, buildWithdrawResumeProps, buildWithdrawSdk, withdrawAmountFor };
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import { BigIntMath } from "../../../../../utils/bigint-math.js";
|
|
2
|
-
import { eq } from "../../../utils/common.js";
|
|
3
|
-
import { convertAmount } from "../../../utils/convert-amount.js";
|
|
4
|
-
import { simulateState } from "../../../utils/simulate-adjust-state.js";
|
|
5
|
-
import "../../../utils/index.js";
|
|
6
|
-
import { buildClaimDelayedWithdrawalOperation, primaryInstantOutput } from "../../../operations/claim-delayed/index.js";
|
|
7
|
-
import { buildDecreaseDebtOperation } from "../../../operations/decrease-debt/index.js";
|
|
8
|
-
import { buildSwapOperation } from "../../../operations/swap/index.js";
|
|
9
|
-
import { buildWithdrawCollateralOperation } from "../../../operations/withdraw-collateral/index.js";
|
|
10
|
-
import "../../../operations/index.js";
|
|
11
|
-
//#region src/sdk/accounts/intents/intents/resume/withdraw/withdraw.ts
|
|
12
|
-
const ZERO_QUOTE = {
|
|
13
|
-
amount: 0n,
|
|
14
|
-
minAmount: 0n,
|
|
15
|
-
calls: []
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* Resume withdraw — linear op chain following the W-first matrix:
|
|
19
|
-
* claim → (swap?) → decreaseDebt? → (unwrapRwa?) → withdrawCollateral.
|
|
20
|
-
* Only the underlying token (or the unwrapped rwa.asset on RWA markets) can
|
|
21
|
-
* be withdrawn (enforced below).
|
|
22
|
-
* The delayed lean intent records debt already paid at start; only its
|
|
23
|
-
* residual `debtRepaid` may consume claimed proceeds.
|
|
24
|
-
*
|
|
25
|
-
* Matrix arithmetic (split sizing) is oracle-priced; emitted swap legs go
|
|
26
|
-
* through the given quoter (`amountOut` on the op, `minAmountOut` caps the
|
|
27
|
-
* debt repay funded by the leg). Mirrors legacy
|
|
28
|
-
* `buildWithdrawResumeLogicalOps` + `resolveSwapBranches` (simplified: no
|
|
29
|
-
* min/avg op branches).
|
|
30
|
-
*/
|
|
31
|
-
async function buildResumeWithdrawOperations(props, quoter) {
|
|
32
|
-
const { intent, options, creditAccount, sdk } = props;
|
|
33
|
-
const underlying = creditAccount.underlying;
|
|
34
|
-
const rwaMeta = sdk.tokensMeta.rwaUnderlyings.get(underlying);
|
|
35
|
-
if (!eq(intent.withdrawToken, underlying) && !eq(intent.withdrawToken, rwaMeta?.asset ?? "")) throw new Error("Withdraw intent should withdraw underlying token only");
|
|
36
|
-
const claimOp = buildClaimDelayedWithdrawalOperation({
|
|
37
|
-
creditAccount,
|
|
38
|
-
sdk
|
|
39
|
-
}, options);
|
|
40
|
-
const primary = primaryInstantOutput(claimOp.outputs);
|
|
41
|
-
if (!primary || primary.amount <= 0n) throw new Error("No claimable assets");
|
|
42
|
-
const convert = convertAmount(sdk, creditAccount.creditManager);
|
|
43
|
-
const operations = [claimOp];
|
|
44
|
-
const swap = async (tokenIn, amountIn, tokenOut) => {
|
|
45
|
-
if (amountIn <= 0n) return ZERO_QUOTE;
|
|
46
|
-
const { state } = simulateState({
|
|
47
|
-
operations,
|
|
48
|
-
creditAccount,
|
|
49
|
-
sdk,
|
|
50
|
-
quotaReserve: props.quotaReserve
|
|
51
|
-
});
|
|
52
|
-
const tokenInBalance = state.assets.find((asset) => eq(asset.token, tokenIn))?.balance ?? 0n;
|
|
53
|
-
const quote = await quoter({
|
|
54
|
-
from: [{
|
|
55
|
-
token: tokenIn,
|
|
56
|
-
balance: amountIn
|
|
57
|
-
}],
|
|
58
|
-
tokenOut,
|
|
59
|
-
tokenInBalance
|
|
60
|
-
});
|
|
61
|
-
operations.push(buildSwapOperation({
|
|
62
|
-
tokenIn,
|
|
63
|
-
amountIn,
|
|
64
|
-
tokenOut,
|
|
65
|
-
amountOut: quote.minAmount,
|
|
66
|
-
calls: quote.calls,
|
|
67
|
-
creditAccount,
|
|
68
|
-
sdk
|
|
69
|
-
}, options));
|
|
70
|
-
return quote;
|
|
71
|
-
};
|
|
72
|
-
const decreaseDebt = (amount) => {
|
|
73
|
-
if (amount > 0n) operations.push(buildDecreaseDebtOperation({
|
|
74
|
-
amount,
|
|
75
|
-
creditAccount,
|
|
76
|
-
sdk
|
|
77
|
-
}, options));
|
|
78
|
-
};
|
|
79
|
-
const withdrawCollateral = async (amount) => {
|
|
80
|
-
const withdrawOperations = await buildWithdrawCollateralOperation({
|
|
81
|
-
token: intent.withdrawToken,
|
|
82
|
-
amount,
|
|
83
|
-
to: intent.to,
|
|
84
|
-
underlying,
|
|
85
|
-
creditAccount,
|
|
86
|
-
sdk
|
|
87
|
-
}, options);
|
|
88
|
-
operations.push(...withdrawOperations);
|
|
89
|
-
};
|
|
90
|
-
if (intent.debtRepaid === 0n) {
|
|
91
|
-
/**
|
|
92
|
-
* 2.2.x: debtRepaid === 0n means that debt was repayed on withdrawal start,
|
|
93
|
-
* So all claimed amount should be withdrawn
|
|
94
|
-
*/
|
|
95
|
-
const available = eq(primary.token, intent.withdrawToken) ? primary.amount : (await swap(primary.token, primary.amount, intent.withdrawToken)).minAmount;
|
|
96
|
-
await withdrawCollateral(BigIntMath.min(intent.withdrawAmount, available));
|
|
97
|
-
} else if (eq(intent.sourceToken, intent.withdrawToken)) {
|
|
98
|
-
/**
|
|
99
|
-
* 2.5.x: This can happen when source=target and source has delayedConfig.
|
|
100
|
-
* In this case claimed amount should be used only to repay debt
|
|
101
|
-
* and withdrawAmount can be withdrawn as is
|
|
102
|
-
*/
|
|
103
|
-
const undQuote = eq(primary.token, underlying) ? {
|
|
104
|
-
...ZERO_QUOTE,
|
|
105
|
-
amount: primary.amount,
|
|
106
|
-
minAmount: primary.amount
|
|
107
|
-
} : await swap(primary.token, primary.amount, underlying);
|
|
108
|
-
decreaseDebt(BigIntMath.min(undQuote.minAmount, intent.debtRepaid));
|
|
109
|
-
await withdrawCollateral(intent.withdrawAmount);
|
|
110
|
-
} else if (eq(intent.withdrawToken, underlying)) {
|
|
111
|
-
/**
|
|
112
|
-
* 2.3.x: Special case - withdrawToken = underlying,
|
|
113
|
-
* so the full claim amount can be swapped int underlying;
|
|
114
|
-
* reserve W from the U result, then repay from the remainder.
|
|
115
|
-
*/
|
|
116
|
-
const undQuote = eq(primary.token, underlying) ? {
|
|
117
|
-
...ZERO_QUOTE,
|
|
118
|
-
amount: primary.amount,
|
|
119
|
-
minAmount: primary.amount
|
|
120
|
-
} : await swap(primary.token, primary.amount, underlying);
|
|
121
|
-
const withdrawn = BigIntMath.min(intent.withdrawAmount, undQuote.minAmount);
|
|
122
|
-
decreaseDebt(BigIntMath.min(BigIntMath.max(undQuote.minAmount - withdrawn, 0n), intent.debtRepaid));
|
|
123
|
-
withdrawCollateral(withdrawn);
|
|
124
|
-
} else if (eq(primary.token, intent.withdrawToken)) {
|
|
125
|
-
/**
|
|
126
|
-
* 2.4.2: Special case - withdrawToken = claimedToken,
|
|
127
|
-
* so we can take part of claimed amount without conversion and swap the rest into underlying;
|
|
128
|
-
* reserve claimed T for W; only the remainder funds debt.
|
|
129
|
-
*/
|
|
130
|
-
const withdrawn = BigIntMath.min(intent.withdrawAmount, primary.amount);
|
|
131
|
-
const undQuote = await swap(primary.token, primary.amount - withdrawn, underlying);
|
|
132
|
-
decreaseDebt(BigIntMath.min(undQuote.minAmount, intent.debtRepaid));
|
|
133
|
-
withdrawCollateral(withdrawn);
|
|
134
|
-
} else if (eq(primary.token, underlying)) {
|
|
135
|
-
/**
|
|
136
|
-
* 2.4.1: Special case - underlying = claimedToken,
|
|
137
|
-
* so we can decrease debt using part of claimed amount and swap the rest into target;
|
|
138
|
-
* reserve U equivalent of W, repay with the rest, then swap W.
|
|
139
|
-
*/
|
|
140
|
-
const withdrawInUnderlying = BigIntMath.min(convert(intent.withdrawToken, primary.token, intent.withdrawAmount), primary.amount);
|
|
141
|
-
decreaseDebt(BigIntMath.min(primary.amount - withdrawInUnderlying, intent.debtRepaid));
|
|
142
|
-
const withdrawQuote = await swap(primary.token, withdrawInUnderlying, intent.withdrawToken);
|
|
143
|
-
withdrawCollateral(BigIntMath.min(intent.withdrawAmount, withdrawQuote.minAmount));
|
|
144
|
-
} else {
|
|
145
|
-
/**
|
|
146
|
-
* 2.4.3: Common case - both target and claimed token are independent tokens;
|
|
147
|
-
* Here we should reserve part of claimed amount for withdrawal and
|
|
148
|
-
* use the rest for debt repayment.
|
|
149
|
-
* split a third-token claim into independent debt and W legs.
|
|
150
|
-
*/
|
|
151
|
-
const withdrawInClaim = BigIntMath.min(convert(intent.withdrawToken, primary.token, intent.withdrawAmount), primary.amount);
|
|
152
|
-
const debtQuote = await swap(primary.token, BigIntMath.max(primary.amount - withdrawInClaim, 0n), underlying);
|
|
153
|
-
decreaseDebt(BigIntMath.min(debtQuote.minAmount, intent.debtRepaid));
|
|
154
|
-
const withdrawQuote = await swap(primary.token, withdrawInClaim, intent.withdrawToken);
|
|
155
|
-
withdrawCollateral(BigIntMath.min(intent.withdrawAmount, withdrawQuote.minAmount));
|
|
156
|
-
}
|
|
157
|
-
return operations;
|
|
158
|
-
}
|
|
159
|
-
//#endregion
|
|
160
|
-
export { buildResumeWithdrawOperations };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
//#region src/sdk/accounts/intents/operations/add-collateral/index.ts
|
|
2
|
-
function buildAddCollateralOperation(input, option) {
|
|
3
|
-
const calls = option.kind === "onchain" ? input.sdk.accounts.prepareAddCollateral(input.creditAccount.creditFacade, [{
|
|
4
|
-
token: input.token,
|
|
5
|
-
balance: input.amount
|
|
6
|
-
}], {}) : [];
|
|
7
|
-
return {
|
|
8
|
-
type: "addCollateral",
|
|
9
|
-
token: input.token,
|
|
10
|
-
amount: input.amount,
|
|
11
|
-
value: input.value,
|
|
12
|
-
calls
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
//#endregion
|
|
16
|
-
export { buildAddCollateralOperation };
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { eq, toTargetDecimals } from "../../utils/common.js";
|
|
2
|
-
import "../../utils/index.js";
|
|
3
|
-
//#region src/sdk/accounts/intents/operations/claim-delayed/index.ts
|
|
4
|
-
/**
|
|
5
|
-
* Build the claim op from a matured claimable, or a simulation-only op from
|
|
6
|
-
* resume claimedToken/amount when claimable is not attached.
|
|
7
|
-
* Stores balances for raw call
|
|
8
|
-
*/
|
|
9
|
-
function buildClaimDelayedWithdrawalOperation(input, option) {
|
|
10
|
-
if (option.kind === "onchain") {
|
|
11
|
-
const calls = input.sdk.accounts.assembleClaimDelayedCalls({
|
|
12
|
-
creditFacade: input.creditAccount.creditFacade,
|
|
13
|
-
claimableNow: option.claimableWithdrawal
|
|
14
|
-
});
|
|
15
|
-
return {
|
|
16
|
-
type: "claimDelayedWithdrawal",
|
|
17
|
-
token: option.claimableWithdrawal.token.toLowerCase(),
|
|
18
|
-
withdrawalPhantomToken: option.claimableWithdrawal.withdrawalPhantomToken.toLowerCase(),
|
|
19
|
-
withdrawalTokenSpent: option.claimableWithdrawal.withdrawalTokenSpent,
|
|
20
|
-
outputs: option.claimableWithdrawal.outputs.map((o) => ({
|
|
21
|
-
...o,
|
|
22
|
-
token: o.token.toLowerCase()
|
|
23
|
-
})),
|
|
24
|
-
calls
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
return {
|
|
28
|
-
type: "claimDelayedWithdrawal",
|
|
29
|
-
token: option.withdrawalConfig.token,
|
|
30
|
-
withdrawalPhantomToken: option.withdrawalConfig.withdrawalPhantomToken,
|
|
31
|
-
withdrawalTokenSpent: option.phantomSpent,
|
|
32
|
-
outputs: [{
|
|
33
|
-
token: option.withdrawalConfig.underlying,
|
|
34
|
-
amount: toTargetDecimals(option.phantomSpent, option.withdrawalConfig.withdrawalPhantomToken, option.withdrawalConfig.underlying, input.sdk),
|
|
35
|
-
isDelayed: false
|
|
36
|
-
}],
|
|
37
|
-
calls: []
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
/** First positive non-delayed output (optionally restricted to `token`). */
|
|
41
|
-
function primaryInstantOutput(outputs, token) {
|
|
42
|
-
for (const out of outputs) {
|
|
43
|
-
if (out.isDelayed || out.amount <= 0n) continue;
|
|
44
|
-
if (token != null && !eq(out.token, token)) continue;
|
|
45
|
-
return {
|
|
46
|
-
token: out.token,
|
|
47
|
-
amount: out.amount
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
//#endregion
|
|
52
|
-
export { buildClaimDelayedWithdrawalOperation, primaryInstantOutput };
|