@gearbox-protocol/sdk 15.1.0-next.1 → 15.1.0-next.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/abi/iExpirable.js +15 -0
- package/dist/cjs/common-utils/utils/apy/get-single-quota-borrow-rate.js +2 -0
- package/dist/cjs/common-utils/utils/creditAccount/calc-health-factor.js +24 -22
- package/dist/cjs/common-utils/utils/creditAccount/calc-quota-borrow-rate.js +2 -0
- package/dist/cjs/common-utils/utils/creditAccount/get-time-to-liquidation.js +8 -5
- package/dist/cjs/common-utils/utils/creditAccount/liquidation-price.js +21 -11
- package/dist/cjs/dev/AccountOpener.js +0 -1
- package/dist/cjs/dev/compareOpportunities.js +218 -0
- package/dist/cjs/model/charts.js +147 -0
- package/dist/cjs/model/charts.schema.js +240 -0
- package/dist/cjs/model/index.js +35 -22
- package/dist/cjs/model/liquidations.schema.js +1 -1
- package/dist/cjs/model/notices.schema.js +25 -0
- package/dist/cjs/model/opportunities.schema.js +1 -1
- package/dist/cjs/model/positions.schema.js +48 -2
- package/dist/cjs/new-sdk/AbstractNamespace.js +34 -4
- package/dist/cjs/new-sdk/GearboxSDK.js +72 -3
- package/dist/cjs/new-sdk/execute/ExecuteApi.js +95 -0
- package/dist/cjs/new-sdk/execute/index.js +3 -0
- package/dist/cjs/new-sdk/index.js +7 -0
- package/dist/cjs/new-sdk/opportunities/OpportunitiesNamespace.js +29 -6
- package/dist/cjs/new-sdk/positions/PositionsNamespace.js +3 -6
- package/dist/cjs/new-sdk/simulate/SimulateApi.js +361 -0
- package/dist/cjs/new-sdk/simulate/index.js +4 -0
- package/dist/cjs/new-sdk/utils/index.js +0 -1
- package/dist/cjs/offchain/AbstractOffchainNamespace.js +10 -7
- package/dist/cjs/offchain/GearboxAPI.js +7 -0
- package/dist/cjs/offchain/index.js +3 -0
- package/dist/cjs/offchain/notices/OffchainNotices.js +27 -0
- package/dist/cjs/offchain/notices/index.js +3 -0
- package/dist/cjs/offchain/opportunities/OffchainOpportunities.js +4 -8
- package/dist/cjs/offchain/positions/OffchainPositions.js +12 -12
- package/dist/cjs/preview/preview/CreditAccountState.js +14 -1
- package/dist/cjs/preview/preview/buildDelayedPreview.js +16 -6
- package/dist/cjs/preview/preview/previewAdjustCreditAccount.js +9 -2
- package/dist/cjs/preview/preview/previewOpenCreditAccount.js +11 -3
- package/dist/cjs/preview/preview/previewOperation.js +1 -1
- package/dist/cjs/sdk/MultichainSDK.js +3 -4
- package/dist/cjs/sdk/OnchainSDK.js +42 -13
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +2 -8
- package/dist/cjs/sdk/accounts/credit-account-compressor/CreditAccountCompressor.js +2 -90
- package/dist/cjs/sdk/accounts/index.js +5 -2
- package/dist/cjs/sdk/accounts/intents/guards.js +114 -0
- package/dist/cjs/sdk/accounts/intents/index.js +216 -358
- package/dist/cjs/sdk/accounts/intents/math.js +56 -0
- package/dist/cjs/sdk/accounts/intents/open-strategy.js +133 -0
- package/dist/cjs/sdk/accounts/intents/operations.js +165 -0
- package/dist/cjs/sdk/accounts/intents/plan.js +373 -0
- package/dist/cjs/sdk/accounts/intents/realize.js +301 -0
- package/dist/cjs/sdk/accounts/intents/testing/delayed.js +50 -0
- package/dist/cjs/sdk/accounts/intents/testing/market.js +166 -0
- package/dist/cjs/sdk/accounts/intents/testing/sdk-mock.js +194 -35
- package/dist/cjs/sdk/accounts/intents/tests/add-collateral.fixtures.js +123 -0
- package/dist/cjs/sdk/accounts/intents/tests/adjust-leverage.fixtures.js +254 -0
- package/dist/cjs/sdk/accounts/intents/tests/deposit.fixtures.js +324 -0
- package/dist/cjs/sdk/accounts/intents/tests/finish-decrease-leverage.fixtures.js +242 -0
- package/dist/cjs/sdk/accounts/intents/tests/finish-withdraw.fixtures.js +383 -0
- package/dist/cjs/sdk/accounts/intents/tests/open-strategy.fixtures.js +133 -0
- package/dist/cjs/sdk/accounts/intents/tests/withdraw-asset.fixtures.js +131 -0
- package/dist/cjs/sdk/accounts/intents/tests/withdraw.fixtures.js +426 -0
- package/dist/cjs/sdk/accounts/intents/types.js +16 -0
- package/dist/cjs/sdk/accounts/intents/utils/adjust-state-to-snapshot.js +18 -0
- package/dist/cjs/sdk/accounts/intents/utils/credit-account-slice.js +45 -0
- package/dist/cjs/sdk/accounts/intents/utils/index.js +17 -8
- package/dist/cjs/sdk/accounts/intents/utils/ledger.js +94 -0
- package/dist/cjs/sdk/accounts/intents/utils/pick-token.js +72 -0
- package/dist/cjs/sdk/accounts/intents/utils/quotas-for-update.js +27 -0
- package/dist/cjs/sdk/accounts/intents/utils/router-path.js +86 -0
- package/dist/cjs/sdk/accounts/intents/view.js +38 -0
- package/dist/cjs/sdk/accounts/liquidations/LiquidationsService.js +0 -3
- package/dist/cjs/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.js +29 -18
- package/dist/cjs/sdk/base/BaseContract.js +1 -1
- package/dist/cjs/sdk/base/TokensMeta.js +78 -27
- package/dist/cjs/sdk/index.js +30 -7
- package/dist/cjs/sdk/market/MarketRegister.js +16 -7
- package/dist/cjs/sdk/market/ZapperRegister.js +56 -25
- package/dist/cjs/sdk/market/credit/CreditManagerV310Contract.js +1 -12
- package/dist/cjs/sdk/market/credit/CreditSuite.js +28 -9
- package/dist/cjs/sdk/market/credit/index.js +3 -0
- package/dist/cjs/sdk/market/credit/isStrategyCollateral.js +50 -0
- package/dist/cjs/sdk/market/index.js +17 -0
- package/dist/cjs/sdk/market/math.js +57 -44
- package/dist/cjs/sdk/market/oracle/PriceOracleBaseContract.js +10 -3
- package/dist/cjs/sdk/market/pool/PoolV310Contract.js +15 -1
- package/dist/cjs/sdk/market/rwa/RWARegistry.js +22 -0
- package/dist/cjs/sdk/opportunities/index.js +0 -13
- package/dist/cjs/sdk/options.js +1 -5
- package/dist/cjs/sdk/pools/PoolService.js +132 -3
- package/dist/cjs/sdk/pools/index.js +2 -0
- package/dist/cjs/sdk/positions/PositionsService.js +213 -1
- package/dist/cjs/sdk/positions/calcBorrowRate.js +43 -0
- package/dist/cjs/sdk/positions/calcHealthFactor.js +52 -0
- package/dist/cjs/sdk/positions/calcLiquidationPrice.js +23 -0
- package/dist/cjs/sdk/positions/calcLiquidationPriceForTarget.js +30 -0
- package/dist/cjs/sdk/positions/calcTimeToLiquidationMs.js +19 -0
- package/dist/cjs/sdk/positions/index.js +12 -1
- package/dist/cjs/sdk/positions/types.js +31 -0
- package/dist/cjs/sdk/utils/abi-decode.js +2 -2
- package/dist/cjs/sdk/utils/viem/executeMulticallBatches.js +32 -0
- package/dist/cjs/sdk/utils/viem/index.js +2 -0
- package/dist/esm/abi/iExpirable.js +14 -0
- package/dist/esm/common-utils/utils/apy/get-single-quota-borrow-rate.js +2 -0
- package/dist/esm/common-utils/utils/creditAccount/calc-health-factor.js +24 -22
- package/dist/esm/common-utils/utils/creditAccount/calc-quota-borrow-rate.js +2 -0
- package/dist/esm/common-utils/utils/creditAccount/get-time-to-liquidation.js +8 -5
- package/dist/esm/common-utils/utils/creditAccount/liquidation-price.js +21 -11
- package/dist/esm/dev/AccountOpener.js +1 -2
- package/dist/esm/dev/compareOpportunities.js +216 -0
- package/dist/esm/dev/withdrawalUtils.js +1 -1
- package/dist/esm/model/charts.js +140 -0
- package/dist/esm/model/charts.schema.js +226 -0
- package/dist/esm/model/index.js +9 -7
- package/dist/esm/model/liquidations.schema.js +1 -1
- package/dist/esm/model/notices.schema.js +23 -0
- package/dist/esm/model/opportunities.schema.js +1 -1
- package/dist/esm/model/positions.schema.js +46 -4
- package/dist/esm/new-sdk/AbstractNamespace.js +34 -4
- package/dist/esm/new-sdk/GearboxSDK.js +72 -4
- package/dist/esm/new-sdk/execute/ExecuteApi.js +94 -0
- package/dist/esm/new-sdk/execute/index.js +2 -0
- package/dist/esm/new-sdk/index.js +6 -2
- package/dist/esm/new-sdk/opportunities/OpportunitiesNamespace.js +29 -6
- package/dist/esm/new-sdk/positions/PositionsNamespace.js +3 -6
- package/dist/esm/new-sdk/simulate/SimulateApi.js +360 -0
- package/dist/esm/new-sdk/simulate/index.js +3 -0
- package/dist/esm/new-sdk/utils/index.js +0 -1
- package/dist/esm/offchain/AbstractOffchainNamespace.js +10 -7
- package/dist/esm/offchain/GearboxAPI.js +7 -0
- package/dist/esm/offchain/index.js +3 -1
- package/dist/esm/offchain/notices/OffchainNotices.js +26 -0
- package/dist/esm/offchain/notices/index.js +2 -0
- package/dist/esm/offchain/opportunities/OffchainOpportunities.js +4 -8
- package/dist/esm/offchain/positions/OffchainPositions.js +12 -12
- package/dist/esm/plugins/adapters/contracts/ERC4626AdapterContract.js +1 -1
- package/dist/esm/preview/preview/CreditAccountState.js +14 -1
- package/dist/esm/preview/preview/buildDelayedPreview.js +16 -6
- package/dist/esm/preview/preview/previewAdjustCreditAccount.js +9 -2
- package/dist/esm/preview/preview/previewOpenCreditAccount.js +11 -3
- package/dist/esm/preview/preview/previewOperation.js +1 -1
- package/dist/esm/preview/simulate/simulatePoolOperation.js +1 -1
- package/dist/esm/preview/trace/extractTransfers.js +1 -1
- package/dist/esm/sdk/MultichainSDK.js +3 -4
- package/dist/esm/sdk/OnchainSDK.js +42 -13
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +4 -10
- package/dist/esm/sdk/accounts/credit-account-compressor/CreditAccountCompressor.js +2 -90
- package/dist/esm/sdk/accounts/index.js +3 -2
- package/dist/esm/sdk/accounts/intents/guards.js +108 -0
- package/dist/esm/sdk/accounts/intents/index.js +214 -358
- package/dist/esm/sdk/accounts/intents/math.js +51 -0
- package/dist/esm/sdk/accounts/intents/open-strategy.js +132 -0
- package/dist/esm/sdk/accounts/intents/operations.js +153 -0
- package/dist/esm/sdk/accounts/intents/plan.js +361 -0
- package/dist/esm/sdk/accounts/intents/realize.js +300 -0
- package/dist/esm/sdk/accounts/intents/testing/delayed.js +38 -0
- package/dist/esm/sdk/accounts/intents/testing/market.js +148 -0
- package/dist/esm/sdk/accounts/intents/testing/sdk-mock.js +194 -35
- package/dist/esm/sdk/accounts/intents/tests/add-collateral.fixtures.js +110 -0
- package/dist/esm/sdk/accounts/intents/tests/adjust-leverage.fixtures.js +234 -0
- package/dist/esm/sdk/accounts/intents/tests/deposit.fixtures.js +302 -0
- package/dist/esm/sdk/accounts/intents/tests/finish-decrease-leverage.fixtures.js +220 -0
- package/dist/esm/sdk/accounts/intents/tests/finish-withdraw.fixtures.js +355 -0
- package/dist/esm/sdk/accounts/intents/tests/open-strategy.fixtures.js +119 -0
- package/dist/esm/sdk/accounts/intents/tests/withdraw-asset.fixtures.js +117 -0
- package/dist/esm/sdk/accounts/intents/tests/withdraw.fixtures.js +402 -0
- package/dist/esm/sdk/accounts/intents/types.js +16 -1
- package/dist/esm/sdk/accounts/intents/utils/adjust-state-to-snapshot.js +17 -0
- package/dist/esm/sdk/accounts/intents/utils/credit-account-slice.js +43 -0
- package/dist/esm/sdk/accounts/intents/utils/index.js +9 -7
- package/dist/esm/sdk/accounts/intents/utils/ledger.js +93 -0
- package/dist/esm/sdk/accounts/intents/utils/pick-token.js +68 -0
- package/dist/esm/sdk/accounts/intents/utils/quotas-for-update.js +27 -1
- package/dist/esm/sdk/accounts/intents/utils/router-path.js +85 -0
- package/dist/esm/sdk/accounts/intents/view.js +37 -0
- package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +1 -4
- package/dist/esm/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.js +29 -18
- package/dist/esm/sdk/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
- package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
- package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
- package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
- package/dist/esm/sdk/base/BaseContract.js +1 -1
- package/dist/esm/sdk/base/TokensMeta.js +80 -29
- package/dist/esm/sdk/chain/detectNetwork.js +1 -1
- package/dist/esm/sdk/core/createAddressProvider.js +1 -1
- package/dist/esm/sdk/index.js +13 -4
- package/dist/esm/sdk/market/MarketRegister.js +16 -7
- package/dist/esm/sdk/market/ZapperRegister.js +56 -25
- package/dist/esm/sdk/market/credit/CreditFacadeV310BaseContract.js +1 -1
- package/dist/esm/sdk/market/credit/CreditManagerV310Contract.js +2 -13
- package/dist/esm/sdk/market/credit/CreditSuite.js +29 -10
- package/dist/esm/sdk/market/credit/index.js +2 -1
- package/dist/esm/sdk/market/credit/isStrategyCollateral.js +48 -0
- package/dist/esm/sdk/market/index.js +3 -1
- package/dist/esm/sdk/market/math.js +52 -40
- package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +10 -3
- package/dist/esm/sdk/market/pool/PoolV310Contract.js +17 -3
- package/dist/esm/sdk/market/rwa/RWARegistry.js +22 -0
- package/dist/esm/sdk/market/zapper/IETHZapperContract.js +1 -1
- package/dist/esm/sdk/market/zapper/ZapperContract.js +1 -1
- package/dist/esm/sdk/opportunities/index.js +1 -2
- package/dist/esm/sdk/options.js +1 -5
- package/dist/esm/sdk/pools/PoolService.js +133 -6
- package/dist/esm/sdk/pools/index.js +2 -2
- package/dist/esm/sdk/positions/PositionsService.js +213 -1
- package/dist/esm/sdk/positions/calcBorrowRate.js +42 -0
- package/dist/esm/sdk/positions/calcHealthFactor.js +51 -0
- package/dist/esm/sdk/positions/calcLiquidationPrice.js +22 -0
- package/dist/esm/sdk/positions/calcLiquidationPriceForTarget.js +29 -0
- package/dist/esm/sdk/positions/calcTimeToLiquidationMs.js +18 -0
- package/dist/esm/sdk/positions/index.js +7 -2
- package/dist/esm/sdk/positions/types.js +31 -1
- package/dist/esm/sdk/utils/abi-decode.js +2 -2
- package/dist/esm/sdk/utils/viem/executeMulticallBatches.js +31 -0
- package/dist/esm/sdk/utils/viem/index.js +2 -1
- package/dist/esm/sdk/utils/viem/simulateWithPriceUpdates.js +1 -1
- package/dist/types/abi/iExpirable.d.ts +14 -0
- package/dist/types/common-utils/utils/apy/get-single-quota-borrow-rate.d.ts +2 -0
- package/dist/types/common-utils/utils/creditAccount/calc-health-factor.d.ts +3 -0
- package/dist/types/common-utils/utils/creditAccount/calc-quota-borrow-rate.d.ts +2 -0
- package/dist/types/common-utils/utils/creditAccount/get-time-to-liquidation.d.ts +6 -1
- package/dist/types/common-utils/utils/creditAccount/liquidation-price.d.ts +3 -0
- package/dist/types/dev/compareOpportunities.d.ts +153 -0
- package/dist/types/model/charts.d.ts +349 -0
- package/dist/types/model/charts.schema.d.ts +364 -0
- package/dist/types/model/index.d.ts +8 -6
- package/dist/types/model/notices.d.ts +29 -0
- package/dist/types/model/notices.schema.d.ts +23 -0
- package/dist/types/model/opportunities.d.ts +9 -9
- package/dist/types/model/positions.d.ts +133 -7
- package/dist/types/model/positions.schema.d.ts +128 -1
- package/dist/types/new-sdk/AbstractNamespace.d.ts +15 -2
- package/dist/types/new-sdk/GearboxSDK.d.ts +14 -2
- package/dist/types/new-sdk/execute/ExecuteApi.d.ts +108 -0
- package/dist/types/new-sdk/execute/index.d.ts +2 -0
- package/dist/types/new-sdk/index.d.ts +8 -4
- package/dist/types/new-sdk/opportunities/OpportunitiesNamespace.d.ts +19 -7
- package/dist/types/new-sdk/opportunities/types.d.ts +30 -9
- package/dist/types/new-sdk/positions/PositionsNamespace.d.ts +4 -5
- package/dist/types/new-sdk/positions/types.d.ts +9 -9
- package/dist/types/new-sdk/simulate/SimulateApi.d.ts +90 -0
- package/dist/types/new-sdk/simulate/index.d.ts +3 -0
- package/dist/types/new-sdk/simulate/types.d.ts +508 -0
- package/dist/types/new-sdk/types.d.ts +35 -1
- package/dist/types/new-sdk/utils/index.d.ts +1 -2
- package/dist/types/offchain/AbstractOffchainNamespace.d.ts +5 -21
- package/dist/types/offchain/GearboxAPI.d.ts +6 -0
- package/dist/types/offchain/index.d.ts +4 -2
- package/dist/types/offchain/notices/OffchainNotices.d.ts +19 -0
- package/dist/types/offchain/notices/index.d.ts +2 -0
- package/dist/types/offchain/opportunities/OffchainOpportunities.d.ts +8 -4
- package/dist/types/offchain/positions/OffchainPositions.d.ts +8 -6
- package/dist/types/preview/preview/CreditAccountState.d.ts +6 -0
- package/dist/types/preview/preview/buildDelayedPreview.d.ts +5 -1
- package/dist/types/preview/preview/types.d.ts +4 -2
- package/dist/types/sdk/MultichainSDK.d.ts +0 -5
- package/dist/types/sdk/OnchainSDK.d.ts +1 -5
- package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +1 -7
- package/dist/types/sdk/accounts/credit-account-compressor/CreditAccountCompressor.d.ts +3 -12
- package/dist/types/sdk/accounts/credit-account-compressor/index.d.ts +2 -2
- package/dist/types/sdk/accounts/credit-account-compressor/types.d.ts +1 -19
- package/dist/types/sdk/accounts/index.d.ts +7 -5
- package/dist/types/sdk/accounts/intents/guards.d.ts +72 -0
- package/dist/types/sdk/accounts/intents/index.d.ts +130 -15
- package/dist/types/sdk/accounts/intents/math.d.ts +46 -0
- package/dist/types/sdk/accounts/intents/open-strategy.d.ts +64 -0
- package/dist/types/sdk/accounts/intents/operations.d.ts +215 -0
- package/dist/types/sdk/accounts/intents/plan.d.ts +189 -0
- package/dist/types/sdk/accounts/intents/realize.d.ts +35 -0
- package/dist/types/sdk/accounts/intents/testing/delayed.d.ts +50 -0
- package/dist/types/sdk/accounts/intents/testing/expect.d.ts +17 -21
- package/dist/types/sdk/accounts/intents/testing/market.d.ts +91 -0
- package/dist/types/sdk/accounts/intents/testing/sdk-mock.d.ts +64 -16
- package/dist/types/sdk/accounts/intents/tests/add-collateral.fixtures.d.ts +45 -0
- package/dist/types/sdk/accounts/intents/tests/adjust-leverage.fixtures.d.ts +56 -0
- package/dist/types/sdk/accounts/intents/tests/deposit.fixtures.d.ts +64 -0
- package/dist/types/sdk/accounts/intents/tests/finish-decrease-leverage.fixtures.d.ts +107 -0
- package/dist/types/sdk/accounts/intents/tests/finish-withdraw.fixtures.d.ts +136 -0
- package/dist/types/sdk/accounts/intents/tests/open-strategy.fixtures.d.ts +56 -0
- package/dist/types/sdk/accounts/intents/tests/withdraw-asset.fixtures.d.ts +60 -0
- package/dist/types/sdk/accounts/intents/tests/withdraw.fixtures.d.ts +79 -0
- package/dist/types/sdk/accounts/intents/types.d.ts +369 -43
- package/dist/types/sdk/accounts/intents/utils/adjust-state-to-snapshot.d.ts +13 -0
- package/dist/types/sdk/accounts/intents/utils/assemble-operation-calls.d.ts +1 -1
- package/dist/types/sdk/accounts/intents/utils/credit-account-slice.d.ts +29 -0
- package/dist/types/sdk/accounts/intents/utils/index.d.ts +7 -5
- package/dist/types/sdk/accounts/intents/utils/ledger.d.ts +41 -0
- package/dist/types/sdk/accounts/intents/utils/pick-token.d.ts +55 -0
- package/dist/types/sdk/accounts/intents/utils/quotas-for-update.d.ts +15 -4
- package/dist/types/sdk/accounts/intents/utils/router-path.d.ts +70 -0
- package/dist/types/sdk/accounts/intents/view.d.ts +15 -0
- package/dist/types/sdk/accounts/types.d.ts +17 -14
- package/dist/types/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.d.ts +6 -0
- package/dist/types/sdk/accounts/withdrawal-compressor/types.d.ts +18 -0
- package/dist/types/sdk/base/TokensMeta.d.ts +44 -1
- package/dist/types/sdk/base/index.d.ts +2 -2
- package/dist/types/sdk/base/token-types.d.ts +12 -1
- package/dist/types/sdk/index.d.ts +28 -19
- package/dist/types/sdk/market/MarketRegister.d.ts +7 -3
- package/dist/types/sdk/market/ZapperRegister.d.ts +20 -2
- package/dist/types/sdk/market/credit/CreditManagerV310Contract.d.ts +0 -4
- package/dist/types/sdk/market/credit/CreditSuite.d.ts +6 -3
- package/dist/types/sdk/market/credit/index.d.ts +2 -1
- package/dist/types/sdk/market/credit/isStrategyCollateral.d.ts +74 -0
- package/dist/types/sdk/market/credit/types.d.ts +2 -9
- package/dist/types/sdk/market/index.d.ts +4 -2
- package/dist/types/sdk/market/math.d.ts +44 -34
- package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +6 -2
- package/dist/types/sdk/market/oracle/types.d.ts +10 -2
- package/dist/types/sdk/market/pool/PoolV310Contract.d.ts +5 -0
- package/dist/types/sdk/market/pool/types.d.ts +5 -0
- package/dist/types/sdk/market/rwa/RWARegistry.d.ts +13 -0
- package/dist/types/sdk/market/types.d.ts +5 -1
- package/dist/types/sdk/opportunities/index.d.ts +1 -2
- package/dist/types/sdk/options.d.ts +0 -1
- package/dist/types/sdk/pools/PoolService.d.ts +32 -2
- package/dist/types/sdk/pools/index.d.ts +3 -3
- package/dist/types/sdk/pools/types.d.ts +109 -4
- package/dist/types/sdk/positions/PositionsService.d.ts +33 -2
- package/dist/types/sdk/positions/calcBorrowRate.d.ts +40 -0
- package/dist/types/sdk/positions/calcHealthFactor.d.ts +55 -0
- package/dist/types/sdk/positions/calcLiquidationPrice.d.ts +12 -0
- package/dist/types/sdk/positions/calcLiquidationPriceForTarget.d.ts +43 -0
- package/dist/types/sdk/positions/calcTimeToLiquidationMs.d.ts +16 -0
- package/dist/types/sdk/positions/index.d.ts +7 -2
- package/dist/types/sdk/positions/types.d.ts +58 -1
- package/dist/types/sdk/types/state.d.ts +6 -0
- package/dist/types/sdk/utils/viem/executeMulticallBatches.d.ts +39 -0
- package/dist/types/sdk/utils/viem/index.d.ts +3 -2
- package/package.json +2 -1
- package/dist/cjs/model/history.js +0 -53
- package/dist/cjs/model/history.schema.js +0 -128
- package/dist/cjs/sdk/accounts/intents/intents/index.js +0 -14
- package/dist/cjs/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.fixtures.js +0 -121
- package/dist/cjs/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.js +0 -15
- package/dist/cjs/sdk/accounts/intents/intents/resume/close/close.fixtures.js +0 -108
- package/dist/cjs/sdk/accounts/intents/intents/resume/close/close.js +0 -51
- package/dist/cjs/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.fixtures.js +0 -130
- package/dist/cjs/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.js +0 -83
- package/dist/cjs/sdk/accounts/intents/intents/resume/deposit/deposit.fixtures.js +0 -117
- package/dist/cjs/sdk/accounts/intents/intents/resume/deposit/deposit.js +0 -15
- package/dist/cjs/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.fixtures.js +0 -95
- package/dist/cjs/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.js +0 -15
- package/dist/cjs/sdk/accounts/intents/intents/resume/index.js +0 -13
- package/dist/cjs/sdk/accounts/intents/intents/resume/withdraw/withdraw.fixtures.js +0 -138
- package/dist/cjs/sdk/accounts/intents/intents/resume/withdraw/withdraw.js +0 -161
- package/dist/cjs/sdk/accounts/intents/operations/add-collateral/index.js +0 -17
- package/dist/cjs/sdk/accounts/intents/operations/claim-delayed/index.js +0 -54
- package/dist/cjs/sdk/accounts/intents/operations/close-credit-account/index.js +0 -26
- package/dist/cjs/sdk/accounts/intents/operations/decrease-debt/index.js +0 -12
- package/dist/cjs/sdk/accounts/intents/operations/increase-debt/index.js +0 -12
- package/dist/cjs/sdk/accounts/intents/operations/index.js +0 -27
- package/dist/cjs/sdk/accounts/intents/operations/quota-update/index.js +0 -22
- package/dist/cjs/sdk/accounts/intents/operations/repay-credit-account/index.js +0 -22
- package/dist/cjs/sdk/accounts/intents/operations/start-delayed-withdrawal/index.js +0 -18
- package/dist/cjs/sdk/accounts/intents/operations/swap/index.js +0 -18
- package/dist/cjs/sdk/accounts/intents/operations/unwrap-rwa-collateral/index.js +0 -27
- package/dist/cjs/sdk/accounts/intents/operations/withdraw-collateral/index.js +0 -43
- package/dist/cjs/sdk/accounts/intents/operations/wrap-rwa-collateral/index.js +0 -27
- package/dist/cjs/sdk/accounts/intents/quoters/close.js +0 -58
- package/dist/cjs/sdk/accounts/intents/quoters/index.js +0 -7
- package/dist/cjs/sdk/accounts/intents/quoters/swap.js +0 -79
- package/dist/cjs/sdk/accounts/intents/testing/expect.js +0 -167
- package/dist/cjs/sdk/accounts/intents/testing/resume.js +0 -172
- package/dist/cjs/sdk/accounts/intents/utils/simulate-adjust-state.js +0 -39
- package/dist/cjs/sdk/accounts/intents/utils/simulate-assets.js +0 -69
- package/dist/cjs/sdk/accounts/intents/utils/with-quota-update.js +0 -13
- package/dist/esm/model/history.js +0 -49
- package/dist/esm/model/history.schema.js +0 -116
- package/dist/esm/sdk/accounts/intents/intents/index.js +0 -8
- package/dist/esm/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.fixtures.js +0 -107
- package/dist/esm/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.js +0 -14
- package/dist/esm/sdk/accounts/intents/intents/resume/close/close.fixtures.js +0 -94
- package/dist/esm/sdk/accounts/intents/intents/resume/close/close.js +0 -50
- package/dist/esm/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.fixtures.js +0 -114
- package/dist/esm/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.js +0 -82
- package/dist/esm/sdk/accounts/intents/intents/resume/deposit/deposit.fixtures.js +0 -110
- package/dist/esm/sdk/accounts/intents/intents/resume/deposit/deposit.js +0 -14
- package/dist/esm/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.fixtures.js +0 -88
- package/dist/esm/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.js +0 -14
- package/dist/esm/sdk/accounts/intents/intents/resume/index.js +0 -7
- package/dist/esm/sdk/accounts/intents/intents/resume/withdraw/withdraw.fixtures.js +0 -121
- package/dist/esm/sdk/accounts/intents/intents/resume/withdraw/withdraw.js +0 -160
- package/dist/esm/sdk/accounts/intents/operations/add-collateral/index.js +0 -16
- package/dist/esm/sdk/accounts/intents/operations/claim-delayed/index.js +0 -52
- package/dist/esm/sdk/accounts/intents/operations/close-credit-account/index.js +0 -25
- package/dist/esm/sdk/accounts/intents/operations/decrease-debt/index.js +0 -11
- package/dist/esm/sdk/accounts/intents/operations/increase-debt/index.js +0 -11
- package/dist/esm/sdk/accounts/intents/operations/index.js +0 -14
- package/dist/esm/sdk/accounts/intents/operations/quota-update/index.js +0 -21
- package/dist/esm/sdk/accounts/intents/operations/repay-credit-account/index.js +0 -21
- package/dist/esm/sdk/accounts/intents/operations/start-delayed-withdrawal/index.js +0 -17
- package/dist/esm/sdk/accounts/intents/operations/swap/index.js +0 -17
- package/dist/esm/sdk/accounts/intents/operations/unwrap-rwa-collateral/index.js +0 -26
- package/dist/esm/sdk/accounts/intents/operations/withdraw-collateral/index.js +0 -42
- package/dist/esm/sdk/accounts/intents/operations/wrap-rwa-collateral/index.js +0 -26
- package/dist/esm/sdk/accounts/intents/quoters/close.js +0 -56
- package/dist/esm/sdk/accounts/intents/quoters/index.js +0 -3
- package/dist/esm/sdk/accounts/intents/quoters/swap.js +0 -77
- package/dist/esm/sdk/accounts/intents/testing/expect.js +0 -162
- package/dist/esm/sdk/accounts/intents/testing/resume.js +0 -157
- package/dist/esm/sdk/accounts/intents/utils/simulate-adjust-state.js +0 -38
- package/dist/esm/sdk/accounts/intents/utils/simulate-assets.js +0 -68
- package/dist/esm/sdk/accounts/intents/utils/with-quota-update.js +0 -12
- package/dist/types/model/history.d.ts +0 -153
- package/dist/types/model/history.schema.d.ts +0 -95
- package/dist/types/new-sdk/utils/history.d.ts +0 -18
- package/dist/types/sdk/accounts/intents/intents/index.d.ts +0 -8
- package/dist/types/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.d.ts +0 -13
- package/dist/types/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.fixtures.d.ts +0 -38
- package/dist/types/sdk/accounts/intents/intents/resume/close/close.d.ts +0 -26
- package/dist/types/sdk/accounts/intents/intents/resume/close/close.fixtures.d.ts +0 -63
- package/dist/types/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.d.ts +0 -26
- package/dist/types/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.fixtures.d.ts +0 -86
- package/dist/types/sdk/accounts/intents/intents/resume/deposit/deposit.d.ts +0 -13
- package/dist/types/sdk/accounts/intents/intents/resume/deposit/deposit.fixtures.d.ts +0 -48
- package/dist/types/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.d.ts +0 -13
- package/dist/types/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.fixtures.d.ts +0 -46
- package/dist/types/sdk/accounts/intents/intents/resume/index.d.ts +0 -7
- package/dist/types/sdk/accounts/intents/intents/resume/withdraw/withdraw.d.ts +0 -33
- package/dist/types/sdk/accounts/intents/intents/resume/withdraw/withdraw.fixtures.d.ts +0 -68
- package/dist/types/sdk/accounts/intents/operations/add-collateral/index.d.ts +0 -23
- package/dist/types/sdk/accounts/intents/operations/claim-delayed/index.d.ts +0 -55
- package/dist/types/sdk/accounts/intents/operations/close-credit-account/index.d.ts +0 -22
- package/dist/types/sdk/accounts/intents/operations/decrease-debt/index.d.ts +0 -18
- package/dist/types/sdk/accounts/intents/operations/increase-debt/index.d.ts +0 -18
- package/dist/types/sdk/accounts/intents/operations/index.d.ts +0 -14
- package/dist/types/sdk/accounts/intents/operations/quota-update/index.d.ts +0 -24
- package/dist/types/sdk/accounts/intents/operations/repay-credit-account/index.d.ts +0 -31
- package/dist/types/sdk/accounts/intents/operations/start-delayed-withdrawal/index.d.ts +0 -23
- package/dist/types/sdk/accounts/intents/operations/swap/index.d.ts +0 -28
- package/dist/types/sdk/accounts/intents/operations/types.d.ts +0 -21
- package/dist/types/sdk/accounts/intents/operations/unwrap-rwa-collateral/index.d.ts +0 -30
- package/dist/types/sdk/accounts/intents/operations/withdraw-collateral/index.d.ts +0 -36
- package/dist/types/sdk/accounts/intents/operations/wrap-rwa-collateral/index.d.ts +0 -30
- package/dist/types/sdk/accounts/intents/quoters/close.d.ts +0 -43
- package/dist/types/sdk/accounts/intents/quoters/index.d.ts +0 -3
- package/dist/types/sdk/accounts/intents/quoters/swap.d.ts +0 -43
- package/dist/types/sdk/accounts/intents/testing/resume.d.ts +0 -84
- package/dist/types/sdk/accounts/intents/utils/simulate-adjust-state.d.ts +0 -19
- package/dist/types/sdk/accounts/intents/utils/simulate-assets.d.ts +0 -21
- package/dist/types/sdk/accounts/intents/utils/with-quota-update.d.ts +0 -16
- /package/dist/cjs/{new-sdk/utils/history.js → model/notices.js} +0 -0
- /package/dist/cjs/{sdk/accounts/intents/operations → new-sdk/simulate}/types.js +0 -0
- /package/dist/esm/{new-sdk/utils/history.js → model/notices.js} +0 -0
- /package/dist/esm/{sdk/accounts/intents/operations → new-sdk/simulate}/types.js +0 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/abi/iExpirable.ts
|
|
3
|
+
const iExpirableAbi = [{
|
|
4
|
+
type: "function",
|
|
5
|
+
inputs: [],
|
|
6
|
+
name: "isExpired",
|
|
7
|
+
outputs: [{
|
|
8
|
+
name: "",
|
|
9
|
+
internalType: "bool",
|
|
10
|
+
type: "bool"
|
|
11
|
+
}],
|
|
12
|
+
stateMutability: "view"
|
|
13
|
+
}];
|
|
14
|
+
//#endregion
|
|
15
|
+
exports.iExpirableAbi = iExpirableAbi;
|
|
@@ -5,6 +5,8 @@ const require_common_utils_utils_creditAccount_calc_quota_borrow_rate = require(
|
|
|
5
5
|
/**
|
|
6
6
|
* Under the hood sums up rates for all given quotas and then multiplies them by 1+feeInterest,
|
|
7
7
|
* but it is expected that the ONLY quota will be passed
|
|
8
|
+
*
|
|
9
|
+
* @deprecated Use `calcBorrowRate` from `sdk/positions` instead.
|
|
8
10
|
*/
|
|
9
11
|
function getSingleQuotaBorrowRate(props) {
|
|
10
12
|
const qr = require_common_utils_utils_creditAccount_calc_quota_borrow_rate.calcQuotaBorrowRate(props);
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
3
|
-
const require_sdk_constants_math = require("../../../sdk/constants/math.js");
|
|
4
|
-
require("../../../sdk/index.js");
|
|
5
|
-
const require_common_utils_utils_price_math = require("../price-math.js");
|
|
2
|
+
const require_sdk_positions_calcHealthFactor = require("../../../sdk/positions/calcHealthFactor.js");
|
|
6
3
|
//#region src/common-utils/utils/creditAccount/calc-health-factor.ts
|
|
7
|
-
const MAX_UINT16 = 65535;
|
|
8
4
|
/**
|
|
9
5
|
* Computes account health factor in percentage-factor units.
|
|
10
6
|
*
|
|
@@ -15,25 +11,31 @@ const MAX_UINT16 = 65535;
|
|
|
15
11
|
* @param props Credit account balances, quotas, prices, thresholds, and debt context.
|
|
16
12
|
* @returns Health factor as a number in `PERCENTAGE_FACTOR` scale,
|
|
17
13
|
* or `65535` when debt is zero.
|
|
14
|
+
*
|
|
15
|
+
* @deprecated Use `calcHealthFactor` from `sdk/positions` instead; this
|
|
16
|
+
* wrapper only maps the legacy props onto an `AccountSnapshot`.
|
|
18
17
|
*/
|
|
19
18
|
function calcHealthFactor({ assets, quotas, quotasInfo, liquidationThresholds, underlyingToken, debt, prices, tokensList }) {
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
19
|
+
const decimals = {};
|
|
20
|
+
for (const [token, meta] of Object.entries(tokensList)) decimals[token] = meta.decimals;
|
|
21
|
+
const lts = {};
|
|
22
|
+
for (const [token, lt] of Object.entries(liquidationThresholds)) lts[token] = Number(lt);
|
|
23
|
+
const activeQuotas = {};
|
|
24
|
+
for (const [token, info] of Object.entries(quotasInfo)) if (info?.isActive) activeQuotas[token] = true;
|
|
25
|
+
return require_sdk_positions_calcHealthFactor.calcHealthFactor({
|
|
26
|
+
snapshot: {
|
|
27
|
+
creditManager: underlyingToken,
|
|
28
|
+
assets,
|
|
29
|
+
quotas: Object.values(quotas),
|
|
30
|
+
totalDebt: debt,
|
|
31
|
+
totalValue: 0n
|
|
32
|
+
},
|
|
33
|
+
underlying: underlyingToken,
|
|
34
|
+
decimals,
|
|
35
|
+
prices,
|
|
36
|
+
liquidationThresholds: lts,
|
|
37
|
+
activeQuotas
|
|
38
|
+
});
|
|
37
39
|
}
|
|
38
40
|
//#endregion
|
|
39
41
|
exports.calcHealthFactor = calcHealthFactor;
|
|
@@ -9,6 +9,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
9
9
|
*
|
|
10
10
|
* @param props Quota balances and per-token quota rates.
|
|
11
11
|
* @returns Sum of `balance * rate` terms in percentage-factor scale.
|
|
12
|
+
*
|
|
13
|
+
* @deprecated Use `calcBorrowRate` from `sdk/positions` instead.
|
|
12
14
|
*/
|
|
13
15
|
function calcQuotaBorrowRate({ quotas, quotaRates }) {
|
|
14
16
|
return Object.values(quotas).reduce((acc, { token, balance }) => {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
3
|
-
require("../../../sdk/index.js");
|
|
2
|
+
const require_sdk_positions_calcTimeToLiquidationMs = require("../../../sdk/positions/calcTimeToLiquidationMs.js");
|
|
4
3
|
//#region src/common-utils/utils/creditAccount/get-time-to-liquidation.ts
|
|
5
4
|
/**
|
|
6
5
|
* Estimates time remaining until health factor reaches liquidation level.
|
|
@@ -9,13 +8,17 @@ require("../../../sdk/index.js");
|
|
|
9
8
|
* and returns a millisecond duration until `healthFactor` decays to `1.0`
|
|
10
9
|
* (`PERCENTAGE_FACTOR` in internal scale).
|
|
11
10
|
*
|
|
12
|
-
* @param props Current health factor and `
|
|
11
|
+
* @param props Current health factor and `totalBorrowRate_debt`, both `Bps`
|
|
12
|
+
* (`10000` = 100%) — not the legacy `PERCENTAGE_FACTOR_1KK` (`1_000_000` =
|
|
13
|
+
* 100%) scale the pre-rewrite frontend fed this under the same name.
|
|
13
14
|
* @returns Milliseconds to liquidation as `bigint`, or `null` when already at/under
|
|
14
15
|
* liquidation threshold or when borrow-rate exposure is zero.
|
|
16
|
+
*
|
|
17
|
+
* @deprecated Use `calcTimeToLiquidationMs` from `sdk/positions` instead;
|
|
18
|
+
* this wrapper only forwards to the new implementation.
|
|
15
19
|
*/
|
|
16
20
|
function getTimeToLiquidation({ healthFactor, totalBorrowRate_debt }) {
|
|
17
|
-
|
|
18
|
-
return (BigInt(healthFactor) - require_sdk_constants_math.PERCENTAGE_FACTOR) * (BigInt(require_sdk_constants_math.SECONDS_PER_YEAR) * require_sdk_constants_math.PERCENTAGE_FACTOR * require_sdk_constants_math.PERCENTAGE_DECIMALS / totalBorrowRate_debt) * 1000n / require_sdk_constants_math.PERCENTAGE_FACTOR;
|
|
21
|
+
return require_sdk_positions_calcTimeToLiquidationMs.calcTimeToLiquidationMs(healthFactor, totalBorrowRate_debt);
|
|
19
22
|
}
|
|
20
23
|
//#endregion
|
|
21
24
|
exports.getTimeToLiquidation = getTimeToLiquidation;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
3
|
-
require("../../../sdk/index.js");
|
|
2
|
+
const require_sdk_positions_calcLiquidationPriceForTarget = require("../../../sdk/positions/calcLiquidationPriceForTarget.js");
|
|
4
3
|
//#region src/common-utils/utils/creditAccount/liquidation-price.ts
|
|
5
4
|
/**
|
|
6
5
|
* Calculates target token liquidation price for a credit account.
|
|
@@ -13,17 +12,28 @@ require("../../../sdk/index.js");
|
|
|
13
12
|
* @param props Debt context, assets, thresholds, and token metadata.
|
|
14
13
|
* @returns Target token price in `PRICE_DECIMALS` precision that corresponds
|
|
15
14
|
* to liquidation boundary; returns `0n` when target balance or LT is non-positive.
|
|
15
|
+
*
|
|
16
|
+
* @deprecated Use `calcLiquidationPriceForTarget` from `sdk/positions`
|
|
17
|
+
* instead; this wrapper only maps the legacy props onto an `AccountSnapshot`.
|
|
16
18
|
*/
|
|
17
19
|
function liquidationPrice({ liquidationThresholds, debt, underlyingToken, targetToken, assets, tokensList }) {
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
const decimals = {};
|
|
21
|
+
for (const [token, meta] of Object.entries(tokensList)) decimals[token] = meta.decimals;
|
|
22
|
+
const lts = {};
|
|
23
|
+
for (const [token, lt] of Object.entries(liquidationThresholds)) lts[token] = Number(lt);
|
|
24
|
+
return require_sdk_positions_calcLiquidationPriceForTarget.calcLiquidationPriceForTarget({
|
|
25
|
+
snapshot: {
|
|
26
|
+
creditManager: underlyingToken,
|
|
27
|
+
assets: Object.values(assets),
|
|
28
|
+
quotas: [],
|
|
29
|
+
totalDebt: debt,
|
|
30
|
+
totalValue: 0n
|
|
31
|
+
},
|
|
32
|
+
targetToken,
|
|
33
|
+
underlying: underlyingToken,
|
|
34
|
+
decimals,
|
|
35
|
+
liquidationThresholds: lts
|
|
36
|
+
});
|
|
27
37
|
}
|
|
28
38
|
//#endregion
|
|
29
39
|
exports.liquidationPrice = liquidationPrice;
|
|
@@ -87,7 +87,6 @@ var AccountOpener = class extends require_sdk_base_SDKConstruct.SDKConstruct {
|
|
|
87
87
|
depositIntoPools,
|
|
88
88
|
claimFromFaucet
|
|
89
89
|
}, "opening credit accounts");
|
|
90
|
-
await Promise.all([this.sdk.tokensMeta.loadTokenData(), this.sdk.marketRegister.loadZappers()]);
|
|
91
90
|
let deposits = [];
|
|
92
91
|
if (depositIntoPools) try {
|
|
93
92
|
deposits = await this.#depositIntoPools(targets);
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_model_opportunities = require("../model/opportunities.js");
|
|
3
|
+
require("../model/index.js");
|
|
4
|
+
//#region src/dev/compareOpportunities.ts
|
|
5
|
+
/**
|
|
6
|
+
* Matches two opportunity listings by {@link opportunityId} and reports every
|
|
7
|
+
* field the two sources disagree on.
|
|
8
|
+
*
|
|
9
|
+
* Nothing is filtered out: a diff that is expected — a field only the backend
|
|
10
|
+
* can fill, a formula the two sides define differently, a USD value smoothed on
|
|
11
|
+
* one side — is reported like any other, tagged by {@link DiffKind} so that a
|
|
12
|
+
* reader can bucket it afterwards.
|
|
13
|
+
**/
|
|
14
|
+
function compareOpportunities(input) {
|
|
15
|
+
const onchainRows = indexById(input.onchain.data);
|
|
16
|
+
const offchainRows = indexById(input.offchain.data);
|
|
17
|
+
const onlyOnchain = [];
|
|
18
|
+
const onlyOffchain = [];
|
|
19
|
+
const matched = [];
|
|
20
|
+
for (const [id, row] of onchainRows) {
|
|
21
|
+
const counterpart = offchainRows.get(id);
|
|
22
|
+
if (!counterpart) {
|
|
23
|
+
onlyOnchain.push(toRef(row));
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
const diffs = diffOpportunity(row, counterpart);
|
|
27
|
+
matched.push({
|
|
28
|
+
id,
|
|
29
|
+
kind: row.kind,
|
|
30
|
+
chainId: row.chainId,
|
|
31
|
+
onchainName: row.name,
|
|
32
|
+
offchainName: counterpart.name,
|
|
33
|
+
identical: diffs.length === 0,
|
|
34
|
+
diffs
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
for (const [id, row] of offchainRows) if (!onchainRows.has(id)) onlyOffchain.push(toRef(row));
|
|
38
|
+
byId(onlyOnchain);
|
|
39
|
+
byId(onlyOffchain);
|
|
40
|
+
matched.sort((a, b) => a.id.localeCompare(b.id));
|
|
41
|
+
return {
|
|
42
|
+
generatedAt: input.generatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
43
|
+
backendUrl: input.backendUrl,
|
|
44
|
+
networks: [...input.networks],
|
|
45
|
+
onchainChains: input.onchain.meta.chains,
|
|
46
|
+
offchainChains: input.offchain.meta.chains,
|
|
47
|
+
summary: summarize(input.onchain.data, input.offchain.data, onlyOnchain, onlyOffchain, matched),
|
|
48
|
+
onlyOnchain,
|
|
49
|
+
onlyOffchain,
|
|
50
|
+
matched
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function indexById(rows) {
|
|
54
|
+
return new Map(rows.map((row) => [require_model_opportunities.opportunityId(row), row]));
|
|
55
|
+
}
|
|
56
|
+
function byId(refs) {
|
|
57
|
+
refs.sort((a, b) => a.id.localeCompare(b.id));
|
|
58
|
+
}
|
|
59
|
+
function toRef(row) {
|
|
60
|
+
const base = {
|
|
61
|
+
id: require_model_opportunities.opportunityId(row),
|
|
62
|
+
kind: row.kind,
|
|
63
|
+
chainId: row.chainId,
|
|
64
|
+
name: row.name
|
|
65
|
+
};
|
|
66
|
+
return row.kind === "pool" ? {
|
|
67
|
+
...base,
|
|
68
|
+
pool: row.pool
|
|
69
|
+
} : {
|
|
70
|
+
...base,
|
|
71
|
+
creditManager: row.creditManager,
|
|
72
|
+
targetCollateral: row.targetCollateral.address
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Every field two versions of one opportunity disagree on.
|
|
77
|
+
**/
|
|
78
|
+
function diffOpportunity(onchain, offchain) {
|
|
79
|
+
const diffs = [];
|
|
80
|
+
diffValue("", onchain, offchain, diffs);
|
|
81
|
+
return diffs;
|
|
82
|
+
}
|
|
83
|
+
function diffValue(path, onchain, offchain, out) {
|
|
84
|
+
if (isAbsent(onchain) && isAbsent(offchain)) return;
|
|
85
|
+
if (isAbsent(onchain) || isAbsent(offchain)) {
|
|
86
|
+
out.push({
|
|
87
|
+
path,
|
|
88
|
+
onchain,
|
|
89
|
+
offchain,
|
|
90
|
+
kind: "presence"
|
|
91
|
+
});
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (Array.isArray(onchain) && Array.isArray(offchain)) {
|
|
95
|
+
diffArray(path, onchain, offchain, out);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (isRecord(onchain) && isRecord(offchain)) {
|
|
99
|
+
for (const key of union(Object.keys(onchain), Object.keys(offchain))) diffValue(join(path, key), onchain[key], offchain[key], out);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (!sameScalar(onchain, offchain)) out.push({
|
|
103
|
+
path,
|
|
104
|
+
onchain,
|
|
105
|
+
offchain,
|
|
106
|
+
kind: scalarKind(path, onchain)
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Arrays whose elements identify themselves — collateral tokens, points
|
|
111
|
+
* programs — are matched by that identity, so a token present on one side only
|
|
112
|
+
* is reported as such rather than shifting every later element into a diff.
|
|
113
|
+
**/
|
|
114
|
+
function diffArray(path, onchain, offchain, out) {
|
|
115
|
+
const onchainKeyed = keyElements(onchain);
|
|
116
|
+
const offchainKeyed = keyElements(offchain);
|
|
117
|
+
if (!onchainKeyed || !offchainKeyed) {
|
|
118
|
+
if (onchain.length !== offchain.length) {
|
|
119
|
+
out.push({
|
|
120
|
+
path,
|
|
121
|
+
onchain,
|
|
122
|
+
offchain,
|
|
123
|
+
kind: "other"
|
|
124
|
+
});
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
onchain.forEach((element, index) => {
|
|
128
|
+
diffValue(`${path}[${index}]`, element, offchain[index], out);
|
|
129
|
+
});
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
for (const key of union([...onchainKeyed.keys()], [...offchainKeyed.keys()])) diffValue(`${path}[${key}]`, onchainKeyed.get(key), offchainKeyed.get(key), out);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* The array indexed by each element's own identity, or `undefined` when its
|
|
136
|
+
* elements have none and order is all there is to go by.
|
|
137
|
+
**/
|
|
138
|
+
function keyElements(values) {
|
|
139
|
+
const keyed = /* @__PURE__ */ new Map();
|
|
140
|
+
for (const value of values) {
|
|
141
|
+
if (!isRecord(value)) return;
|
|
142
|
+
const identity = value.address ?? value.id ?? value.token;
|
|
143
|
+
if (typeof identity !== "string") return;
|
|
144
|
+
keyed.set(identity.toLowerCase(), value);
|
|
145
|
+
}
|
|
146
|
+
return keyed.size === values.length ? keyed : void 0;
|
|
147
|
+
}
|
|
148
|
+
const ADDRESS = /^0x[0-9a-f]{40}$/i;
|
|
149
|
+
/**
|
|
150
|
+
* Only addresses are compared case-insensitively: the backend lowercases them
|
|
151
|
+
* while the chain hands out checksummed ones, which is not a disagreement. A
|
|
152
|
+
* symbol or a name spelled differently is.
|
|
153
|
+
**/
|
|
154
|
+
function sameScalar(onchain, offchain) {
|
|
155
|
+
if (typeof onchain === "string" && typeof offchain === "string" && ADDRESS.test(onchain) && ADDRESS.test(offchain)) return onchain.toLowerCase() === offchain.toLowerCase();
|
|
156
|
+
return onchain === offchain;
|
|
157
|
+
}
|
|
158
|
+
function scalarKind(path, onchain) {
|
|
159
|
+
if (path.endsWith("valueUsd")) return "usd";
|
|
160
|
+
return typeof onchain === "number" || typeof onchain === "bigint" ? "numeric" : "other";
|
|
161
|
+
}
|
|
162
|
+
function summarize(onchain, offchain, onlyOnchain, onlyOffchain, matched) {
|
|
163
|
+
const byChain = union(onchain.map((row) => String(row.chainId)), offchain.map((row) => String(row.chainId))).map((chainId) => ({
|
|
164
|
+
chainId: Number(chainId),
|
|
165
|
+
...count(onchain.filter((row) => String(row.chainId) === chainId), offchain.filter((row) => String(row.chainId) === chainId), onlyOnchain.filter((ref) => String(ref.chainId) === chainId), onlyOffchain.filter((ref) => String(ref.chainId) === chainId), matched.filter((match) => String(match.chainId) === chainId))
|
|
166
|
+
})).sort((a, b) => a.chainId - b.chainId);
|
|
167
|
+
return {
|
|
168
|
+
...count(onchain, offchain, onlyOnchain, onlyOffchain, matched),
|
|
169
|
+
byChain,
|
|
170
|
+
diffsByPath: countPaths(matched)
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
function count(onchain, offchain, onlyOnchain, onlyOffchain, matched) {
|
|
174
|
+
const identical = matched.filter((match) => match.identical).length;
|
|
175
|
+
return {
|
|
176
|
+
onchainRows: onchain.length,
|
|
177
|
+
offchainRows: offchain.length,
|
|
178
|
+
matched: matched.length,
|
|
179
|
+
identical,
|
|
180
|
+
differing: matched.length - identical,
|
|
181
|
+
onlyOnchain: onlyOnchain.length,
|
|
182
|
+
onlyOffchain: onlyOffchain.length
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* How often each field differed, with array keys collapsed so that the same
|
|
187
|
+
* field of a hundred collateral tokens counts as one path.
|
|
188
|
+
**/
|
|
189
|
+
function countPaths(matched) {
|
|
190
|
+
const counts = /* @__PURE__ */ new Map();
|
|
191
|
+
for (const match of matched) for (const diff of match.diffs) {
|
|
192
|
+
const path = diff.path.replace(/\[[^\]]*\]/g, "[]");
|
|
193
|
+
const entry = counts.get(path) ?? {
|
|
194
|
+
path,
|
|
195
|
+
kinds: [],
|
|
196
|
+
count: 0
|
|
197
|
+
};
|
|
198
|
+
entry.count += 1;
|
|
199
|
+
if (!entry.kinds.includes(diff.kind)) entry.kinds.push(diff.kind);
|
|
200
|
+
counts.set(path, entry);
|
|
201
|
+
}
|
|
202
|
+
return [...counts.values()].sort((a, b) => b.count - a.count || a.path.localeCompare(b.path));
|
|
203
|
+
}
|
|
204
|
+
function isAbsent(value) {
|
|
205
|
+
return value === void 0 || value === null;
|
|
206
|
+
}
|
|
207
|
+
function isRecord(value) {
|
|
208
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
209
|
+
}
|
|
210
|
+
function union(left, right) {
|
|
211
|
+
return [.../* @__PURE__ */ new Set([...left, ...right])];
|
|
212
|
+
}
|
|
213
|
+
function join(path, key) {
|
|
214
|
+
return path ? `${path}.${key}` : key;
|
|
215
|
+
}
|
|
216
|
+
//#endregion
|
|
217
|
+
exports.compareOpportunities = compareOpportunities;
|
|
218
|
+
exports.diffOpportunity = diffOpportunity;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/model/charts.ts
|
|
3
|
+
/**
|
|
4
|
+
* Historical charts of an opportunity or a position.
|
|
5
|
+
*
|
|
6
|
+
* Charts are backend-only by construction: the chain serves the present, and
|
|
7
|
+
* reconstructing a series from it would mean archive-node reads per point.
|
|
8
|
+
*
|
|
9
|
+
* A chart is read as a {@link ChartBundle}: one shared x-axis plus one
|
|
10
|
+
* {@link ChartSeries} per metric, each holding values only. Alignment is
|
|
11
|
+
* therefore structural — series `i` and series `j` describe the same instant at
|
|
12
|
+
* the same index — rather than a property the backend promises and every
|
|
13
|
+
* consumer re-checks.
|
|
14
|
+
**/
|
|
15
|
+
/**
|
|
16
|
+
* Time window a chart covers, ending at the present.
|
|
17
|
+
*
|
|
18
|
+
* `"max"` is the full history the backend retains for the subject.
|
|
19
|
+
**/
|
|
20
|
+
const CHART_RANGES = [
|
|
21
|
+
"1d",
|
|
22
|
+
"1w",
|
|
23
|
+
"1m",
|
|
24
|
+
"1y",
|
|
25
|
+
"max"
|
|
26
|
+
];
|
|
27
|
+
/**
|
|
28
|
+
* Every metric a pool opportunity can chart.
|
|
29
|
+
**/
|
|
30
|
+
const POOL_OPPORTUNITY_CHART_METRICS = [
|
|
31
|
+
"depositApy",
|
|
32
|
+
"borrowApy",
|
|
33
|
+
"dieselRate",
|
|
34
|
+
"supplied",
|
|
35
|
+
"borrowed",
|
|
36
|
+
"availableLiquidity"
|
|
37
|
+
];
|
|
38
|
+
/**
|
|
39
|
+
* Every metric a strategy opportunity can chart.
|
|
40
|
+
*
|
|
41
|
+
* `collateralPrice` is the collateral/underlying series a liquidation-price
|
|
42
|
+
* chart draws; the two USD series are the same prices quoted in dollars.
|
|
43
|
+
**/
|
|
44
|
+
const STRATEGY_OPPORTUNITY_CHART_METRICS = [
|
|
45
|
+
"netApy",
|
|
46
|
+
"borrowApy",
|
|
47
|
+
"collateralApy",
|
|
48
|
+
"tvl",
|
|
49
|
+
"collateralPrice",
|
|
50
|
+
"collateralUsdPrice",
|
|
51
|
+
"underlyingUsdPrice"
|
|
52
|
+
];
|
|
53
|
+
/**
|
|
54
|
+
* Every metric a pool position can chart.
|
|
55
|
+
*
|
|
56
|
+
* Nothing to do with {@link POOL_OPPORTUNITY_CHART_METRICS}: an opportunity charts what the
|
|
57
|
+
* pool did, a position charts what one wallet's deposit did in it. `mwr` and
|
|
58
|
+
* `twr` are cumulative returns since the position opened — money-weighted, so
|
|
59
|
+
* sensitive to when deposits and withdrawals landed, and time-weighted, which
|
|
60
|
+
* strips that timing out. Both are anchored at inception, so a narrow `range`
|
|
61
|
+
* only zooms the visible slice and its first point is rarely zero.
|
|
62
|
+
**/
|
|
63
|
+
const POOL_POSITION_CHART_METRICS = [
|
|
64
|
+
"value",
|
|
65
|
+
"apy",
|
|
66
|
+
"pnl",
|
|
67
|
+
"mwr",
|
|
68
|
+
"twr",
|
|
69
|
+
"underlyingPrice"
|
|
70
|
+
];
|
|
71
|
+
/**
|
|
72
|
+
* Every metric a strategy position can chart.
|
|
73
|
+
*
|
|
74
|
+
* `twrApy` annualizes `twr` over the position's whole life; the two trailing
|
|
75
|
+
* APYs annualize it over a fixed window instead, so they track the current pace
|
|
76
|
+
* rather than the lifetime rate and are comparable across positions of
|
|
77
|
+
* different ages.
|
|
78
|
+
**/
|
|
79
|
+
const STRATEGY_POSITION_CHART_METRICS = [
|
|
80
|
+
"totalValueUsd",
|
|
81
|
+
"totalValueUnderlying",
|
|
82
|
+
"debt",
|
|
83
|
+
"healthFactor",
|
|
84
|
+
"leverage",
|
|
85
|
+
"borrowApy",
|
|
86
|
+
"underlyingPrice",
|
|
87
|
+
"pnl",
|
|
88
|
+
"mwr",
|
|
89
|
+
"twr",
|
|
90
|
+
"twrApy",
|
|
91
|
+
"trailingApy7d",
|
|
92
|
+
"trailingApy30d"
|
|
93
|
+
];
|
|
94
|
+
/**
|
|
95
|
+
* Unit of every metric, the one place either side decides it.
|
|
96
|
+
*
|
|
97
|
+
* A metric added to a union above fails to compile here until its unit is
|
|
98
|
+
* named, and the wire schema rejects a series whose `unit` disagrees with this
|
|
99
|
+
* table, so the backend cannot drift from it silently.
|
|
100
|
+
**/
|
|
101
|
+
const CHART_METRIC_UNITS = {
|
|
102
|
+
depositApy: "bps",
|
|
103
|
+
borrowApy: "bps",
|
|
104
|
+
netApy: "bps",
|
|
105
|
+
collateralApy: "bps",
|
|
106
|
+
supplied: "token",
|
|
107
|
+
borrowed: "token",
|
|
108
|
+
availableLiquidity: "token",
|
|
109
|
+
tvl: "token",
|
|
110
|
+
dieselRate: "ratio",
|
|
111
|
+
collateralPrice: "ratio",
|
|
112
|
+
collateralUsdPrice: "usd",
|
|
113
|
+
underlyingUsdPrice: "usd",
|
|
114
|
+
value: "token",
|
|
115
|
+
apy: "bps",
|
|
116
|
+
pnl: "token",
|
|
117
|
+
mwr: "bps",
|
|
118
|
+
twr: "bps",
|
|
119
|
+
underlyingPrice: "usd",
|
|
120
|
+
totalValueUsd: "usd",
|
|
121
|
+
totalValueUnderlying: "token",
|
|
122
|
+
debt: "token",
|
|
123
|
+
healthFactor: "bps",
|
|
124
|
+
leverage: "scalar",
|
|
125
|
+
twrApy: "bps",
|
|
126
|
+
trailingApy7d: "bps",
|
|
127
|
+
trailingApy30d: "bps"
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Reason a series could not be produced at all, which is not the same as a
|
|
131
|
+
* series that has no points in the window.
|
|
132
|
+
**/
|
|
133
|
+
const CHART_UNAVAILABLE_CODES = [
|
|
134
|
+
"unknown_subject",
|
|
135
|
+
"unsupported_metric",
|
|
136
|
+
"no_price_feed",
|
|
137
|
+
"not_indexed",
|
|
138
|
+
"internal"
|
|
139
|
+
];
|
|
140
|
+
//#endregion
|
|
141
|
+
exports.CHART_METRIC_UNITS = CHART_METRIC_UNITS;
|
|
142
|
+
exports.CHART_RANGES = CHART_RANGES;
|
|
143
|
+
exports.CHART_UNAVAILABLE_CODES = CHART_UNAVAILABLE_CODES;
|
|
144
|
+
exports.POOL_OPPORTUNITY_CHART_METRICS = POOL_OPPORTUNITY_CHART_METRICS;
|
|
145
|
+
exports.POOL_POSITION_CHART_METRICS = POOL_POSITION_CHART_METRICS;
|
|
146
|
+
exports.STRATEGY_OPPORTUNITY_CHART_METRICS = STRATEGY_OPPORTUNITY_CHART_METRICS;
|
|
147
|
+
exports.STRATEGY_POSITION_CHART_METRICS = STRATEGY_POSITION_CHART_METRICS;
|