@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
|
@@ -5,8 +5,10 @@ require("./adapters/index.js");
|
|
|
5
5
|
const require_sdk_market_credit_CreditConfiguratorV310Contract = require("./credit/CreditConfiguratorV310Contract.js");
|
|
6
6
|
const require_sdk_market_credit_CreditFacadeV310BaseContract = require("./credit/CreditFacadeV310BaseContract.js");
|
|
7
7
|
const require_sdk_market_credit_CreditFacadeV310Contract = require("./credit/CreditFacadeV310Contract.js");
|
|
8
|
+
const require_sdk_market_math = require("./math.js");
|
|
8
9
|
const require_sdk_market_credit_CreditManagerV310Contract = require("./credit/CreditManagerV310Contract.js");
|
|
9
10
|
const require_sdk_market_credit_dominantCollateral = require("./credit/dominantCollateral.js");
|
|
11
|
+
const require_sdk_market_credit_isStrategyCollateral = require("./credit/isStrategyCollateral.js");
|
|
10
12
|
const require_sdk_market_credit_CreditSuite = require("./credit/CreditSuite.js");
|
|
11
13
|
const require_sdk_market_credit_expectedBalanceDeltas = require("./credit/expectedBalanceDeltas.js");
|
|
12
14
|
require("./credit/index.js");
|
|
@@ -80,10 +82,13 @@ exports.GaugeContract = require_sdk_market_pool_GaugeContract.GaugeContract;
|
|
|
80
82
|
exports.IERC20ZapperContract = require_sdk_market_zapper_IERC20ZapperContract.IERC20ZapperContract;
|
|
81
83
|
exports.IETHZapperContract = require_sdk_market_zapper_IETHZapperContract.IETHZapperContract;
|
|
82
84
|
exports.LinearInterestRateModelContract = require_sdk_market_pool_LinearInterestRateModelContract.LinearInterestRateModelContract;
|
|
85
|
+
exports.MAX_LEVERAGE_BUFFER_BPS = require_sdk_market_math.MAX_LEVERAGE_BUFFER_BPS;
|
|
83
86
|
exports.MarketRegister = require_sdk_market_MarketRegister.MarketRegister;
|
|
84
87
|
exports.MarketSuite = require_sdk_market_MarketSuite.MarketSuite;
|
|
85
88
|
exports.MellowLRTPriceFeedContract = require_sdk_market_pricefeeds_MellowLRTPriceFeed.MellowLRTPriceFeedContract;
|
|
86
89
|
exports.MidasLiquidatorContract = require_sdk_market_rwa_midas_MidasLiquidatorContract.MidasLiquidatorContract;
|
|
90
|
+
exports.NON_STRATEGY_PHANTOM_TOKEN_TYPES = require_sdk_market_credit_isStrategyCollateral.NON_STRATEGY_PHANTOM_TOKEN_TYPES;
|
|
91
|
+
exports.PARTIAL_LIQUIDATION_BUFFER_BPS = require_sdk_market_math.PARTIAL_LIQUIDATION_BUFFER_BPS;
|
|
87
92
|
exports.PHANTOM_TOKEN_MIDAS_REDEMPTION = require_sdk_market_rwa_midas_constants.PHANTOM_TOKEN_MIDAS_REDEMPTION;
|
|
88
93
|
exports.PHANTOM_TOKEN_SECURITIZE_REDEMPTION = require_sdk_market_rwa_securitize_constants.PHANTOM_TOKEN_SECURITIZE_REDEMPTION;
|
|
89
94
|
exports.PartialPriceFeedInitError = require_sdk_market_pricefeeds_AbstractPriceFeed.PartialPriceFeedInitError;
|
|
@@ -109,6 +114,11 @@ exports.WstETHPriceFeedContract = require_sdk_market_pricefeeds_WstETHPriceFeed.
|
|
|
109
114
|
exports.YearnPriceFeedContract = require_sdk_market_pricefeeds_YearnPriceFeed.YearnPriceFeedContract;
|
|
110
115
|
exports.ZapperContract = require_sdk_market_zapper_ZapperContract.ZapperContract;
|
|
111
116
|
exports.ZeroPriceFeedContract = require_sdk_market_pricefeeds_ZeroPriceFeed.ZeroPriceFeedContract;
|
|
117
|
+
exports.calcAdditionalBorrowApy = require_sdk_market_math.calcAdditionalBorrowApy;
|
|
118
|
+
exports.calcBorrowApy = require_sdk_market_math.calcBorrowApy;
|
|
119
|
+
exports.calcMaxLeverage = require_sdk_market_math.calcMaxLeverage;
|
|
120
|
+
exports.calcPositionLeverage = require_sdk_market_math.calcPositionLeverage;
|
|
121
|
+
exports.calcUtilization = require_sdk_market_math.calcUtilization;
|
|
112
122
|
exports.createAdapter = require_sdk_market_adapters_createAdapter.createAdapter;
|
|
113
123
|
exports.createPriceOracle = require_sdk_market_oracle_createPriceOracle.createPriceOracle;
|
|
114
124
|
exports.createZapper = require_sdk_market_zapper_createZapper.createZapper;
|
|
@@ -117,7 +127,14 @@ exports.dominantCollateral = require_sdk_market_credit_dominantCollateral.domina
|
|
|
117
127
|
exports.expectedBalanceDeltas = require_sdk_market_credit_expectedBalanceDeltas.expectedBalanceDeltas;
|
|
118
128
|
exports.fetchRedstonePayloads = require_sdk_market_pricefeeds_updates_fetchRedstonePayloads.fetchRedstonePayloads;
|
|
119
129
|
exports.getRawPriceUpdates = require_sdk_market_pricefeeds_getRawPriceUpdates.getRawPriceUpdates;
|
|
130
|
+
exports.healthFactorBps = require_sdk_market_math.healthFactorBps;
|
|
120
131
|
exports.isLPPriceFeed = require_sdk_market_pricefeeds_AbstractLPPriceFeed.isLPPriceFeed;
|
|
121
132
|
exports.isRWAFactory = require_sdk_market_rwa_types.isRWAFactory;
|
|
133
|
+
exports.isStrategyCollateral = require_sdk_market_credit_isStrategyCollateral.isStrategyCollateral;
|
|
122
134
|
exports.isUpdatablePriceFeed = require_sdk_market_pricefeeds_isUpdatablePriceFeed.isUpdatablePriceFeed;
|
|
135
|
+
exports.minSeizedAmount = require_sdk_market_math.minSeizedAmount;
|
|
123
136
|
exports.mustGetDominantCollateral = require_sdk_market_credit_dominantCollateral.mustGetDominantCollateral;
|
|
137
|
+
exports.optimalHFForPartialLiquidation = require_sdk_market_math.optimalHFForPartialLiquidation;
|
|
138
|
+
exports.optimalRepaidAmount = require_sdk_market_math.optimalRepaidAmount;
|
|
139
|
+
exports.rayToBps = require_sdk_market_math.rayToBps;
|
|
140
|
+
exports.usdToNumber = require_sdk_market_math.usdToNumber;
|
|
@@ -16,7 +16,8 @@ const FULL = Number(require_sdk_constants_math.PERCENTAGE_FACTOR);
|
|
|
16
16
|
*
|
|
17
17
|
* @example
|
|
18
18
|
* ```ts
|
|
19
|
-
*
|
|
19
|
+
* // ray: 5% (0.05 × 10²⁷)
|
|
20
|
+
* rayToBps(50_000_000_000_000_000_000_000_000n) // 500 bps = 5%
|
|
20
21
|
* ```
|
|
21
22
|
**/
|
|
22
23
|
function rayToBps(ray) {
|
|
@@ -27,6 +28,7 @@ function rayToBps(ray) {
|
|
|
27
28
|
*
|
|
28
29
|
* @example
|
|
29
30
|
* ```ts
|
|
31
|
+
* // usd: $1500.50 in 8-decimal fixed point
|
|
30
32
|
* usdToNumber(150_050_000_000n) // 1500.5
|
|
31
33
|
* ```
|
|
32
34
|
**/
|
|
@@ -39,56 +41,66 @@ function usdToNumber(usd) {
|
|
|
39
41
|
*
|
|
40
42
|
* @example
|
|
41
43
|
* ```ts
|
|
42
|
-
*
|
|
44
|
+
* // borrowed: 750, total: 1000
|
|
45
|
+
* calcUtilization(750n, 1000n) // 750 / 1000 = 7500 bps = 75%
|
|
43
46
|
* ```
|
|
44
47
|
**/
|
|
45
|
-
function
|
|
48
|
+
function calcUtilization(borrowed, total) {
|
|
46
49
|
if (total <= 0n || borrowed <= 0n) return 0;
|
|
47
50
|
const utilization = Number(borrowed * require_sdk_constants_math.PERCENTAGE_FACTOR / total);
|
|
48
51
|
return Math.min(utilization, FULL);
|
|
49
52
|
}
|
|
50
53
|
/**
|
|
51
|
-
* Annual cost of debt for a credit manager, in basis points:
|
|
52
|
-
*
|
|
54
|
+
* Annual cost of debt for a credit manager, in basis points:
|
|
55
|
+
* `baseInterestRate × (1 + feeInterest)` — the pool's base rate plus the
|
|
56
|
+
* protocol's cut of the accrued interest.
|
|
53
57
|
*
|
|
54
58
|
* @param baseInterestRate - Pool base rate in ray.
|
|
55
59
|
* @param feeInterest - Credit manager interest fee in basis points.
|
|
56
60
|
*
|
|
57
61
|
* @example
|
|
58
62
|
* ```ts
|
|
59
|
-
* // 5%
|
|
60
|
-
*
|
|
63
|
+
* // baseInterestRate: 5% in ray, feeInterest: 5000 bps = 50%
|
|
64
|
+
* calcBorrowApy(50_000_000_000_000_000_000_000_000n, 5000) // 5% × 1.5 = 750 bps = 7.5%
|
|
61
65
|
* ```
|
|
62
66
|
**/
|
|
63
|
-
function
|
|
67
|
+
function calcBorrowApy(baseInterestRate, feeInterest) {
|
|
64
68
|
return rayToBps(baseInterestRate * (require_sdk_constants_math.PERCENTAGE_FACTOR + BigInt(feeInterest)) / require_sdk_constants_math.PERCENTAGE_FACTOR);
|
|
65
69
|
}
|
|
66
70
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
* 5% safety margin subtracted from 100% in {@link calcMaxLeverage}, so a
|
|
72
|
+
* maxed position opens with HF slightly above 1.
|
|
73
|
+
**/
|
|
74
|
+
const MAX_LEVERAGE_BUFFER_BPS = 500;
|
|
75
|
+
/**
|
|
76
|
+
* Highest total-value leverage a liquidation threshold allows:
|
|
77
|
+
* `(100% − buffer) / (100% − liquidationThreshold)`. At HF = 1, debt is
|
|
78
|
+
* `liquidationThreshold × totalValue`, leaving `1 − liquidationThreshold` of
|
|
79
|
+
* equity per unit of exposure; the {@link MAX_LEVERAGE_BUFFER_BPS} buffer
|
|
80
|
+
* keeps the maxed position slightly away from that boundary.
|
|
72
81
|
*
|
|
73
82
|
* @example
|
|
74
83
|
* ```ts
|
|
75
|
-
*
|
|
76
|
-
*
|
|
84
|
+
* // liquidationThreshold: 9000 bps = 90%
|
|
85
|
+
* calcMaxLeverage(9000) // (1 − 0.05) / (1 − 0.9) = 9.5x total exposure
|
|
77
86
|
* ```
|
|
78
87
|
**/
|
|
79
|
-
function
|
|
80
|
-
|
|
81
|
-
|
|
88
|
+
function calcMaxLeverage(liquidationThreshold) {
|
|
89
|
+
if (liquidationThreshold >= FULL) return 0;
|
|
90
|
+
const leverage = (FULL - 500) / (FULL - liquidationThreshold);
|
|
91
|
+
return Math.max(leverage, 1);
|
|
82
92
|
}
|
|
83
93
|
/**
|
|
84
94
|
* Converts a credit account's health factor from the 18-decimal fixed point the
|
|
85
95
|
* contracts store to basis points.
|
|
86
96
|
*
|
|
87
|
-
*
|
|
97
|
+
* Accounts with no debt store `MAX_UINT256` on-chain; for those this
|
|
98
|
+
* returns `0`.
|
|
88
99
|
*
|
|
89
100
|
* @example
|
|
90
101
|
* ```ts
|
|
91
|
-
*
|
|
102
|
+
* // healthFactor: 1.25 in 18-decimal fixed point
|
|
103
|
+
* healthFactorBps(1_250_000_000_000_000_000n) // 12500 bps = 1.25
|
|
92
104
|
* ```
|
|
93
105
|
**/
|
|
94
106
|
function healthFactorBps(healthFactor) {
|
|
@@ -96,39 +108,39 @@ function healthFactorBps(healthFactor) {
|
|
|
96
108
|
return Number(healthFactor * require_sdk_constants_math.PERCENTAGE_FACTOR / require_sdk_constants_math.WAD);
|
|
97
109
|
}
|
|
98
110
|
/**
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
* Returns `0` for a position that carries no debt and for one that is
|
|
103
|
-
* underwater, where there is no equity to lever.
|
|
111
|
+
* Total-value leverage of an open position:
|
|
112
|
+
* `totalValue / (totalValue − totalDebt)`. `1` when unleveraged, `0` when
|
|
113
|
+
* underwater.
|
|
104
114
|
*
|
|
105
|
-
* @param
|
|
106
|
-
* @param
|
|
115
|
+
* @param totalValue - Total value of the position.
|
|
116
|
+
* @param totalDebt - Debt principal plus accrued interest and fees, same token.
|
|
107
117
|
*
|
|
108
118
|
* @example
|
|
109
119
|
* ```ts
|
|
110
|
-
*
|
|
120
|
+
* // totalValue: 100k, totalDebt: 80k → equity: 100k − 80k = 20k
|
|
121
|
+
* calcPositionLeverage(100_000n, 80_000n) // 100k / 20k = 5x
|
|
111
122
|
* ```
|
|
112
123
|
**/
|
|
113
|
-
function
|
|
124
|
+
function calcPositionLeverage(totalValue, totalDebt) {
|
|
114
125
|
const equity = totalValue - totalDebt;
|
|
115
|
-
if (
|
|
116
|
-
|
|
126
|
+
if (totalValue <= 0n || equity <= 0n) return 0;
|
|
127
|
+
if (totalDebt <= 0n) return 1;
|
|
128
|
+
return Number(totalValue) / Number(equity);
|
|
117
129
|
}
|
|
118
130
|
/**
|
|
119
|
-
* Annual quota cost
|
|
120
|
-
*
|
|
121
|
-
*
|
|
131
|
+
* Annual quota cost on equity, in basis points:
|
|
132
|
+
* `quotaRate × (1 + feeInterest) × leverage`. Quota accrues on the whole
|
|
133
|
+
* quoted position, and the DAO takes `feeInterest` of it as with base interest.
|
|
122
134
|
*
|
|
123
135
|
* @example
|
|
124
136
|
* ```ts
|
|
125
|
-
* // 2
|
|
126
|
-
*
|
|
137
|
+
* // quotaRate: 200 bps = 2%, feeInterest: 2500 bps = 25%, leverage: 9.5x
|
|
138
|
+
* calcAdditionalBorrowApy(200, 2500, 9.5) // 2% × 1.25 × 9.5 = 2375 bps = 23.75%
|
|
127
139
|
* ```
|
|
128
140
|
**/
|
|
129
|
-
function
|
|
130
|
-
if (!Number.isFinite(leverage)) return 0;
|
|
131
|
-
return Math.round(quotaRate *
|
|
141
|
+
function calcAdditionalBorrowApy(quotaRate, feeInterest, leverage) {
|
|
142
|
+
if (!Number.isFinite(leverage) || leverage <= 0) return 0;
|
|
143
|
+
return Math.round(quotaRate * (1 + feeInterest / FULL) * leverage);
|
|
132
144
|
}
|
|
133
145
|
/**
|
|
134
146
|
* {@link PERCENTAGE_FACTOR} less a 0.1% safety buffer.
|
|
@@ -186,15 +198,16 @@ function optimalHFForPartialLiquidation(borrowRate) {
|
|
|
186
198
|
return require_sdk_constants_math.PERCENTAGE_FACTOR + (borrowRate < 100n ? borrowRate : 100n);
|
|
187
199
|
}
|
|
188
200
|
//#endregion
|
|
201
|
+
exports.MAX_LEVERAGE_BUFFER_BPS = MAX_LEVERAGE_BUFFER_BPS;
|
|
189
202
|
exports.PARTIAL_LIQUIDATION_BUFFER_BPS = PARTIAL_LIQUIDATION_BUFFER_BPS;
|
|
190
|
-
exports.
|
|
191
|
-
exports.
|
|
203
|
+
exports.calcAdditionalBorrowApy = calcAdditionalBorrowApy;
|
|
204
|
+
exports.calcBorrowApy = calcBorrowApy;
|
|
205
|
+
exports.calcMaxLeverage = calcMaxLeverage;
|
|
206
|
+
exports.calcPositionLeverage = calcPositionLeverage;
|
|
207
|
+
exports.calcUtilization = calcUtilization;
|
|
192
208
|
exports.healthFactorBps = healthFactorBps;
|
|
193
|
-
exports.maxLeverage = maxLeverage;
|
|
194
209
|
exports.minSeizedAmount = minSeizedAmount;
|
|
195
210
|
exports.optimalHFForPartialLiquidation = optimalHFForPartialLiquidation;
|
|
196
211
|
exports.optimalRepaidAmount = optimalRepaidAmount;
|
|
197
|
-
exports.positionLeverage = positionLeverage;
|
|
198
212
|
exports.rayToBps = rayToBps;
|
|
199
213
|
exports.usdToNumber = usdToNumber;
|
|
200
|
-
exports.utilizationBps = utilizationBps;
|
|
@@ -133,17 +133,24 @@ var PriceOracleBaseContract = class extends require_sdk_base_BaseContract.BaseCo
|
|
|
133
133
|
return amount * 10n ** BigInt(this.tokensMeta.decimals(to)) / price;
|
|
134
134
|
}
|
|
135
135
|
/**
|
|
136
|
-
* {@inheritDoc IPriceOracleContract.
|
|
136
|
+
* {@inheritDoc IPriceOracleContract.safeConvertToUSD}
|
|
137
137
|
**/
|
|
138
|
-
|
|
138
|
+
safeConvertToUSD(token, amount) {
|
|
139
139
|
try {
|
|
140
|
-
return
|
|
140
|
+
return this.convertToUSD(token, amount);
|
|
141
141
|
} catch (e) {
|
|
142
142
|
this.logger?.debug(`cannot price ${this.labelAddress(token)}: ${e}`);
|
|
143
143
|
return null;
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
/**
|
|
147
|
+
* {@inheritDoc IPriceOracleContract.safeUsdValue}
|
|
148
|
+
**/
|
|
149
|
+
safeUsdValue(token, amount) {
|
|
150
|
+
const usd = this.safeConvertToUSD(token, amount);
|
|
151
|
+
return usd === null ? null : require_sdk_market_math.usdToNumber(usd);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
147
154
|
* {@inheritDoc IPriceOracleContract.toAmount}
|
|
148
155
|
**/
|
|
149
156
|
toAmount = (token, value) => {
|
|
@@ -51,7 +51,7 @@ var PoolV310Contract = class extends require_sdk_base_BaseContract.BaseContract
|
|
|
51
51
|
* {@inheritDoc IPoolContract.utilization}
|
|
52
52
|
*/
|
|
53
53
|
get utilization() {
|
|
54
|
-
return require_sdk_market_math.
|
|
54
|
+
return require_sdk_market_math.calcUtilization(this.borrowed, this.expectedLiquidity);
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
57
57
|
* {@inheritDoc IPoolContract.unwrappedUnderlying}
|
|
@@ -137,6 +137,20 @@ var PoolV310Contract = class extends require_sdk_base_BaseContract.BaseContract
|
|
|
137
137
|
]
|
|
138
138
|
});
|
|
139
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* Burns as many of the owner's shares as it takes to send `assets` of the
|
|
142
|
+
* underlying to the receiver.
|
|
143
|
+
*/
|
|
144
|
+
withdraw(assets, receiver, owner) {
|
|
145
|
+
return this.createRawTx({
|
|
146
|
+
functionName: "withdraw",
|
|
147
|
+
args: [
|
|
148
|
+
assets,
|
|
149
|
+
receiver,
|
|
150
|
+
owner
|
|
151
|
+
]
|
|
152
|
+
});
|
|
153
|
+
}
|
|
140
154
|
stringifyFunctionParams(params) {
|
|
141
155
|
switch (params.functionName) {
|
|
142
156
|
case "deposit": {
|
|
@@ -25,6 +25,11 @@ var RWARegistry = class extends require_sdk_base_SDKConstruct.SDKConstruct {
|
|
|
25
25
|
#state;
|
|
26
26
|
#factories = new require_sdk_utils_AddressMap.AddressMap();
|
|
27
27
|
/**
|
|
28
|
+
* Factories requested during attach; `undefined` when the registry was
|
|
29
|
+
* hydrated instead, in which case the request was never made on this instance.
|
|
30
|
+
**/
|
|
31
|
+
#requestedFactories;
|
|
32
|
+
/**
|
|
28
33
|
* @internal
|
|
29
34
|
*
|
|
30
35
|
* Returns delegated multicalls for loading all RWA underlying tokens from the on-chain RWA compressor.
|
|
@@ -34,6 +39,7 @@ var RWARegistry = class extends require_sdk_base_SDKConstruct.SDKConstruct {
|
|
|
34
39
|
* @param rwaFactories - RWA factory contracts to query.
|
|
35
40
|
*/
|
|
36
41
|
getLoadMulticalls(configurators, rwaFactories = []) {
|
|
42
|
+
this.#requestedFactories = rwaFactories;
|
|
37
43
|
if (!rwaFactories.length) return [];
|
|
38
44
|
const [rwaCompressorAddress] = this.sdk.addressProvider.mustGetLatest(require_sdk_constants_address_provider.AP_RWA_COMPRESSOR, require_sdk_constants_versions.VERSION_RANGE_310);
|
|
39
45
|
return [{
|
|
@@ -47,6 +53,22 @@ var RWARegistry = class extends require_sdk_base_SDKConstruct.SDKConstruct {
|
|
|
47
53
|
}];
|
|
48
54
|
}
|
|
49
55
|
/**
|
|
56
|
+
* @internal
|
|
57
|
+
*
|
|
58
|
+
* Returns delegated multicalls that refresh the RWA state. Unlike the other
|
|
59
|
+
* warmed caches, RWA data carries values that change between blocks (e.g. the
|
|
60
|
+
* deposit allowance and claimable amount of an on-demand liquidity provider),
|
|
61
|
+
* so it is refreshed on every SDK sync.
|
|
62
|
+
*
|
|
63
|
+
* Factories are the ones requested during attach; after hydration the chain
|
|
64
|
+
* defaults are used, since the snapshot does not carry the requested list.
|
|
65
|
+
* An attach that explicitly requested no factories stays disabled.
|
|
66
|
+
**/
|
|
67
|
+
getSyncMulticalls() {
|
|
68
|
+
const factories = this.#requestedFactories ?? this.sdk.chain.rwaFactories;
|
|
69
|
+
return this.getLoadMulticalls([...this.sdk.marketRegister.marketFilter.configurators], factories);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
50
72
|
* Fetches decoded investor data from the on-chain RWA compressor.
|
|
51
73
|
*
|
|
52
74
|
* Each factory produces its own investor data (e.g. registered tokens,
|
|
@@ -1,18 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_sdk_market_math = require("../market/math.js");
|
|
3
2
|
const require_sdk_opportunities_MultichainOpportunitiesService = require("./MultichainOpportunitiesService.js");
|
|
4
3
|
const require_sdk_opportunities_OpportunitiesService = require("./OpportunitiesService.js");
|
|
5
4
|
exports.MultichainOpportunitiesService = require_sdk_opportunities_MultichainOpportunitiesService.MultichainOpportunitiesService;
|
|
6
5
|
exports.OpportunitiesService = require_sdk_opportunities_OpportunitiesService.OpportunitiesService;
|
|
7
|
-
exports.PARTIAL_LIQUIDATION_BUFFER_BPS = require_sdk_market_math.PARTIAL_LIQUIDATION_BUFFER_BPS;
|
|
8
|
-
exports.additionalBorrowApyBps = require_sdk_market_math.additionalBorrowApyBps;
|
|
9
|
-
exports.borrowApyBps = require_sdk_market_math.borrowApyBps;
|
|
10
|
-
exports.healthFactorBps = require_sdk_market_math.healthFactorBps;
|
|
11
|
-
exports.maxLeverage = require_sdk_market_math.maxLeverage;
|
|
12
|
-
exports.minSeizedAmount = require_sdk_market_math.minSeizedAmount;
|
|
13
|
-
exports.optimalHFForPartialLiquidation = require_sdk_market_math.optimalHFForPartialLiquidation;
|
|
14
|
-
exports.optimalRepaidAmount = require_sdk_market_math.optimalRepaidAmount;
|
|
15
|
-
exports.positionLeverage = require_sdk_market_math.positionLeverage;
|
|
16
|
-
exports.rayToBps = require_sdk_market_math.rayToBps;
|
|
17
|
-
exports.usdToNumber = require_sdk_market_math.usdToNumber;
|
|
18
|
-
exports.utilizationBps = require_sdk_market_math.utilizationBps;
|
package/dist/cjs/sdk/options.js
CHANGED
|
@@ -61,11 +61,7 @@ const attachOptionsSchema = zod_v4.z.object({
|
|
|
61
61
|
/**
|
|
62
62
|
* Options for Redstone price-feed updates.
|
|
63
63
|
**/
|
|
64
|
-
redstone: require_sdk_market_pricefeeds_updates_RedstoneUpdater.RedstoneOptions.optional()
|
|
65
|
-
/**
|
|
66
|
-
* When `true`, automatically load zappers during attach.
|
|
67
|
-
**/
|
|
68
|
-
loadZappers: zod_v4.z.boolean().optional()
|
|
64
|
+
redstone: require_sdk_market_pricefeeds_updates_RedstoneUpdater.RedstoneOptions.optional()
|
|
69
65
|
});
|
|
70
66
|
//#endregion
|
|
71
67
|
exports.attachOptionsSchema = attachOptionsSchema;
|
|
@@ -15,6 +15,12 @@ const require_sdk_market_zapper_IERC20ZapperContract = require("../market/zapper
|
|
|
15
15
|
const require_sdk_market_zapper_IETHZapperContract = require("../market/zapper/IETHZapperContract.js");
|
|
16
16
|
require("../market/index.js");
|
|
17
17
|
//#region src/sdk/pools/PoolService.ts
|
|
18
|
+
/**
|
|
19
|
+
* Haircut on reported pool liquidity, so a withdrawal sized against the reported
|
|
20
|
+
* figure is not defeated by rounding in the share conversion.
|
|
21
|
+
*/
|
|
22
|
+
const LIQUIDITY_SAFETY_NUM = 99999n;
|
|
23
|
+
const LIQUIDITY_SAFETY_DENOM = 100000n;
|
|
18
24
|
var PoolService = class extends require_sdk_base_SDKConstruct.SDKConstruct {
|
|
19
25
|
/**
|
|
20
26
|
* {@inheritDoc IPoolsService.getDepositTokensIn}
|
|
@@ -116,10 +122,87 @@ var PoolService = class extends require_sdk_base_SDKConstruct.SDKConstruct {
|
|
|
116
122
|
return this.#withdrawalTokensOut(pool, tokenIn, true);
|
|
117
123
|
}
|
|
118
124
|
/**
|
|
125
|
+
* {@inheritDoc IPoolsService.simulateDeposit}
|
|
126
|
+
*/
|
|
127
|
+
simulateDeposit(props) {
|
|
128
|
+
const { pool: poolAddr, amount } = props;
|
|
129
|
+
const { pool } = this.sdk.marketRegister.findByPool(poolAddr);
|
|
130
|
+
const tokenIn = props.tokenIn ?? pool.underlying;
|
|
131
|
+
const tokenOut = this.#resolveTokenOut(props.tokenOut, () => this.getDepositTokensOut(poolAddr, tokenIn), {
|
|
132
|
+
poolAddr,
|
|
133
|
+
tokenIn,
|
|
134
|
+
operation: "deposit"
|
|
135
|
+
});
|
|
136
|
+
const { zapper } = this.getDepositMetadata(poolAddr, tokenIn, tokenOut);
|
|
137
|
+
return {
|
|
138
|
+
tokenIn: {
|
|
139
|
+
token: tokenIn,
|
|
140
|
+
balance: amount
|
|
141
|
+
},
|
|
142
|
+
tokenOut: {
|
|
143
|
+
token: tokenOut,
|
|
144
|
+
balance: toShares(pool.pool, amount)
|
|
145
|
+
},
|
|
146
|
+
zapper: zapper?.baseParams.addr
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* {@inheritDoc IPoolsService.simulateWithdraw}
|
|
151
|
+
*/
|
|
152
|
+
simulateWithdraw(props) {
|
|
153
|
+
const { pool: poolAddr, amount } = props;
|
|
154
|
+
const { pool } = this.sdk.marketRegister.findByPool(poolAddr);
|
|
155
|
+
const tokenIn = props.tokenIn ?? poolAddr;
|
|
156
|
+
const tokenOut = this.#resolveTokenOut(props.tokenOut, () => this.getWithdrawalTokensOut(poolAddr, tokenIn), {
|
|
157
|
+
poolAddr,
|
|
158
|
+
tokenIn,
|
|
159
|
+
operation: "withdrawal"
|
|
160
|
+
});
|
|
161
|
+
const { zapper } = this.getWithdrawalMetadata(poolAddr, tokenIn, tokenOut);
|
|
162
|
+
return {
|
|
163
|
+
tokenIn: {
|
|
164
|
+
token: tokenIn,
|
|
165
|
+
balance: toSharesUp(pool.pool, amount)
|
|
166
|
+
},
|
|
167
|
+
tokenOut: {
|
|
168
|
+
token: tokenOut,
|
|
169
|
+
balance: amount
|
|
170
|
+
},
|
|
171
|
+
zapper: zapper?.baseParams.addr,
|
|
172
|
+
availableLiquidity: pool.pool.availableLiquidity * LIQUIDITY_SAFETY_NUM / LIQUIDITY_SAFETY_DENOM
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* {@inheritDoc IPoolsService.simulateRedeem}
|
|
177
|
+
*/
|
|
178
|
+
simulateRedeem(props) {
|
|
179
|
+
const { pool: poolAddr, amount } = props;
|
|
180
|
+
const { pool } = this.sdk.marketRegister.findByPool(poolAddr);
|
|
181
|
+
const tokenIn = props.tokenIn ?? poolAddr;
|
|
182
|
+
const tokenOut = this.#resolveTokenOut(props.tokenOut, () => this.getWithdrawalTokensOut(poolAddr, tokenIn), {
|
|
183
|
+
poolAddr,
|
|
184
|
+
tokenIn,
|
|
185
|
+
operation: "withdrawal"
|
|
186
|
+
});
|
|
187
|
+
const { zapper } = this.getWithdrawalMetadata(poolAddr, tokenIn, tokenOut);
|
|
188
|
+
return {
|
|
189
|
+
tokenIn: {
|
|
190
|
+
token: tokenIn,
|
|
191
|
+
balance: amount
|
|
192
|
+
},
|
|
193
|
+
tokenOut: {
|
|
194
|
+
token: tokenOut,
|
|
195
|
+
balance: toAssets(pool.pool, amount)
|
|
196
|
+
},
|
|
197
|
+
zapper: zapper?.baseParams.addr,
|
|
198
|
+
availableLiquidity: pool.pool.availableLiquidity * LIQUIDITY_SAFETY_NUM / LIQUIDITY_SAFETY_DENOM
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
119
202
|
* {@inheritDoc IPoolsService.removeLiquidity}
|
|
120
203
|
*/
|
|
121
204
|
removeLiquidity(props) {
|
|
122
|
-
const { pool, amount, meta, wallet, permit } = props;
|
|
205
|
+
const { pool, amount, meta, wallet, permit, mode = "withdraw" } = props;
|
|
123
206
|
const underlying = this.#describeUnderlying(pool);
|
|
124
207
|
if (this.sdk.tokensMeta.isRWAUnderlying(underlying)) {
|
|
125
208
|
if (underlying.contractType === "RWA_UNDERLYING::ON_DEMAND") {
|
|
@@ -140,8 +223,10 @@ var PoolService = class extends require_sdk_base_SDKConstruct.SDKConstruct {
|
|
|
140
223
|
};
|
|
141
224
|
}
|
|
142
225
|
}
|
|
226
|
+
const poolContract = this.sdk.marketRegister.findByPool(pool).pool.pool;
|
|
143
227
|
if (meta.zapper instanceof require_sdk_market_zapper_IETHZapperContract.IETHZapperContract || meta.zapper instanceof require_sdk_market_zapper_IERC20ZapperContract.IERC20ZapperContract) {
|
|
144
|
-
const
|
|
228
|
+
const shares = mode === "withdraw" ? toSharesUp(poolContract, amount) : amount;
|
|
229
|
+
const tx = permit ? meta.zapper.redeemWithPermit(shares, wallet, permit.deadline, permit.v, permit.r, permit.s) : meta.zapper.redeem(shares, wallet);
|
|
145
230
|
return {
|
|
146
231
|
tx,
|
|
147
232
|
calls: [{
|
|
@@ -150,7 +235,7 @@ var PoolService = class extends require_sdk_base_SDKConstruct.SDKConstruct {
|
|
|
150
235
|
}]
|
|
151
236
|
};
|
|
152
237
|
}
|
|
153
|
-
const tx =
|
|
238
|
+
const tx = mode === "withdraw" ? poolContract.withdraw(amount, wallet, wallet) : poolContract.redeem(amount, wallet, wallet);
|
|
154
239
|
return {
|
|
155
240
|
tx,
|
|
156
241
|
calls: [{
|
|
@@ -310,6 +395,18 @@ var PoolService = class extends require_sdk_base_SDKConstruct.SDKConstruct {
|
|
|
310
395
|
type
|
|
311
396
|
};
|
|
312
397
|
}
|
|
398
|
+
/**
|
|
399
|
+
* Picks the route output when the caller left it open.
|
|
400
|
+
*
|
|
401
|
+
* Only an unambiguous single route can be defaulted: with several outputs the
|
|
402
|
+
* choice is the caller's, and with none there is no route to preview.
|
|
403
|
+
*/
|
|
404
|
+
#resolveTokenOut(requested, candidates, ctx) {
|
|
405
|
+
if (requested) return requested;
|
|
406
|
+
const options = candidates();
|
|
407
|
+
if (options.length !== 1) throw new Error(`tokenOut is required: ${options.length} ${ctx.operation} routes from ${this.labelAddress(ctx.tokenIn)} on pool ${this.labelAddress(ctx.poolAddr)}`);
|
|
408
|
+
return options[0];
|
|
409
|
+
}
|
|
313
410
|
#describeUnderlying(pool) {
|
|
314
411
|
const market = this.sdk.marketRegister.findByPool(pool);
|
|
315
412
|
return this.sdk.tokensMeta.mustGet(market.underlying);
|
|
@@ -329,5 +426,37 @@ var PoolService = class extends require_sdk_base_SDKConstruct.SDKConstruct {
|
|
|
329
426
|
};
|
|
330
427
|
}
|
|
331
428
|
};
|
|
429
|
+
/**
|
|
430
|
+
* Shares minted for `assets`, as `previewDeposit` would report them.
|
|
431
|
+
*
|
|
432
|
+
* Both directions convert through the diesel rate — underlying per RAY of
|
|
433
|
+
* shares — because that is the rate the pool itself divides by, and the only
|
|
434
|
+
* exact one the SDK holds: `totalAssets` is this rate multiplied out, so
|
|
435
|
+
* converting back through it costs a wei on large amounts. Rounds down, as
|
|
436
|
+
* minting does.
|
|
437
|
+
*/
|
|
438
|
+
function toShares(pool, assets) {
|
|
439
|
+
const { dieselRate } = pool;
|
|
440
|
+
return dieselRate === 0n ? assets : assets * require_sdk_constants_math.RAY / dieselRate;
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Shares a withdrawal of `assets` burns, as `previewWithdraw` would report
|
|
444
|
+
* them: {@link toShares} rounded the other way, since the burn has to cover
|
|
445
|
+
* the payout the caller asked for.
|
|
446
|
+
*/
|
|
447
|
+
function toSharesUp(pool, assets) {
|
|
448
|
+
const { dieselRate } = pool;
|
|
449
|
+
return dieselRate === 0n ? assets : (assets * require_sdk_constants_math.RAY + dieselRate - 1n) / dieselRate;
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Underlying paid out for `shares`, as `previewRedeem` would report it:
|
|
453
|
+
* {@link toShares} run backwards, less the pool's withdrawal fee.
|
|
454
|
+
*/
|
|
455
|
+
function toAssets(pool, shares) {
|
|
456
|
+
const { dieselRate, withdrawFee } = pool;
|
|
457
|
+
return (dieselRate === 0n ? shares : shares * dieselRate / require_sdk_constants_math.RAY) * (require_sdk_constants_math.PERCENTAGE_FACTOR - withdrawFee) / require_sdk_constants_math.PERCENTAGE_FACTOR;
|
|
458
|
+
}
|
|
332
459
|
//#endregion
|
|
333
460
|
exports.PoolService = PoolService;
|
|
461
|
+
exports.toShares = toShares;
|
|
462
|
+
exports.toSharesUp = toSharesUp;
|
|
@@ -2,3 +2,5 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_sdk_pools_PoolService = require("./PoolService.js");
|
|
3
3
|
require("./types.js");
|
|
4
4
|
exports.PoolService = require_sdk_pools_PoolService.PoolService;
|
|
5
|
+
exports.toShares = require_sdk_pools_PoolService.toShares;
|
|
6
|
+
exports.toSharesUp = require_sdk_pools_PoolService.toSharesUp;
|