@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
package/dist/esm/model/index.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
|
+
import { CHART_METRIC_UNITS, CHART_RANGES, CHART_UNAVAILABLE_CODES, POOL_OPPORTUNITY_CHART_METRICS, POOL_POSITION_CHART_METRICS, STRATEGY_OPPORTUNITY_CHART_METRICS, STRATEGY_POSITION_CHART_METRICS } from "./charts.js";
|
|
2
|
+
import { amountSchema, assetTypeSchema, bpsSchema, chainIdSchema, leverageSchema, timestampSchema, tokenAmountSchema, tokenSchema, txCallSchema } from "./primitives.schema.js";
|
|
3
|
+
import { chartBundleSchemaFor, chartDenominationSchema, chartMetricSchema, chartQueryCodec, chartQueryParamsSchema, chartQuerySchema, chartRangeSchema, chartSeriesSchema, chartValueSchema, chartWindowSchema, poolOpportunityChartMetricSchema, poolPositionChartMetricSchema, strategyOpportunityChartMetricSchema, strategyPositionChartMetricSchema } from "./charts.schema.js";
|
|
1
4
|
import "./curators.js";
|
|
2
5
|
import { curatorNameSchema, curatorSchema } from "./curators.schema.js";
|
|
3
6
|
import { FILTER_ALL, isFilterSet } from "./filters.js";
|
|
4
7
|
import { booleanParamSchema, encodeFlag, filterAllSchema, filterable } from "./filters.schema.js";
|
|
5
|
-
import { POOL_HISTORY_METRICS, POOL_POSITION_HISTORY_METRICS, STRATEGY_HISTORY_METRICS, STRATEGY_POSITION_HISTORY_METRICS } from "./history.js";
|
|
6
|
-
import { amountSchema, assetTypeSchema, bpsSchema, chainIdSchema, leverageSchema, timestampSchema, tokenAmountSchema, tokenSchema, txCallSchema } from "./primitives.schema.js";
|
|
7
|
-
import { apyBreakdownSchema, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterQueryParamsSchema, opportunityFilterQuerySchema, opportunityFilterSchema, opportunityKeySchema, opportunityKindSchema, opportunitySchema, pointRewardsSchema, pointsProgramSchema, poolOpportunityDetailSchema, poolOpportunityKeySchema, poolOpportunitySchema, priceFeedDataSchema, priceFeedSummarySchema, quotaAssetSchema, rateCurvePointSchema, rateCurveSchema, rewardsSchema, strategyOpportunityDetailSchema, strategyOpportunityKeySchema, strategyOpportunitySchema, tokenRewardsSchema } from "./opportunities.schema.js";
|
|
8
|
-
import { delayedReceivedAssetSchema, instantReceivedAssetSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionSchema, receivedAssetSchema } from "./liquidations.schema.js";
|
|
9
|
-
import { pnlBreakdownSchema, pointsProgramPnLSchema, pointsRewardsPnLSchema, poolPositionKeySchema, poolPositionSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionKeySchema, positionKindSchema, positionSchema, rewardsPnLSchema, strategyPositionKeySchema, strategyPositionSchema, tokenRewardsPnLSchema } from "./positions.schema.js";
|
|
10
|
-
import { historyChartMetadataSchema, historyMetricSchema, historyPointSchema, historyRangeSchema, historySeriesSchema, opportunityHistoryQuerySchema, poolHistoryMetricSchema, poolPositionHistoryMetricSchema, positionHistoryMetricSchema, positionHistoryQuerySchema, strategyHistoryMetricSchema, strategyPositionHistoryMetricSchema } from "./history.schema.js";
|
|
11
8
|
import { matchesLiquidatableAccountFilter } from "./liquidations.js";
|
|
9
|
+
import { delayedReceivedAssetSchema, instantReceivedAssetSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionSchema, receivedAssetSchema } from "./liquidations.schema.js";
|
|
10
|
+
import "./notices.js";
|
|
11
|
+
import { noticeKindSchema, noticeSchema } from "./notices.schema.js";
|
|
12
12
|
import { matchesOpportunityFilter, opportunityId, poolOpportunityId, strategyOpportunityId } from "./opportunities.js";
|
|
13
|
+
import { apyBreakdownSchema, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterQueryParamsSchema, opportunityFilterQuerySchema, opportunityFilterSchema, opportunityKeySchema, opportunityKindSchema, opportunitySchema, pointRewardsSchema, pointsProgramSchema, poolOpportunityDetailSchema, poolOpportunityKeySchema, poolOpportunitySchema, priceFeedDataSchema, priceFeedSummarySchema, quotaAssetSchema, rateCurvePointSchema, rateCurveSchema, rewardsSchema, strategyOpportunityDetailSchema, strategyOpportunityKeySchema, strategyOpportunitySchema, tokenRewardsSchema } from "./opportunities.schema.js";
|
|
13
14
|
import { liquidationPositionId, matchesPositionFilter, poolPositionId, positionId, strategyPositionId } from "./positions.js";
|
|
15
|
+
import { borrowRateBreakdownSchema, pnlBreakdownSchema, pointsProgramPnLSchema, pointsRewardsPnLSchema, poolPositionKeySchema, poolPositionSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionKeySchema, positionKindSchema, positionSchema, positionTransactionKindSchema, positionTransactionSchema, positionsTotalsSchema, rewardsPnLSchema, strategyPositionKeySchema, strategyPositionSchema, tokenRewardsPnLSchema } from "./positions.schema.js";
|
|
14
16
|
import "./primitives.js";
|
|
15
17
|
import "./response.js";
|
|
16
18
|
import { chainFailedSchema, chainMetadataSchema, chainSucceededSchema, dataSourceSchema, responseMetadataSchema, responseSchema } from "./response.schema.js";
|
|
17
|
-
export { FILTER_ALL,
|
|
19
|
+
export { CHART_METRIC_UNITS, CHART_RANGES, CHART_UNAVAILABLE_CODES, FILTER_ALL, POOL_OPPORTUNITY_CHART_METRICS, POOL_POSITION_CHART_METRICS, STRATEGY_OPPORTUNITY_CHART_METRICS, STRATEGY_POSITION_CHART_METRICS, amountSchema, apyBreakdownSchema, assetTypeSchema, booleanParamSchema, borrowRateBreakdownSchema, bpsSchema, chainFailedSchema, chainIdSchema, chainMetadataSchema, chainSucceededSchema, chartBundleSchemaFor, chartDenominationSchema, chartMetricSchema, chartQueryCodec, chartQueryParamsSchema, chartQuerySchema, chartRangeSchema, chartSeriesSchema, chartValueSchema, chartWindowSchema, curatorNameSchema, curatorSchema, dataSourceSchema, delayedReceivedAssetSchema, encodeFlag, filterAllSchema, filterable, instantReceivedAssetSchema, isFilterSet, leverageSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionId, liquidationPositionSchema, matchesLiquidatableAccountFilter, matchesOpportunityFilter, matchesPositionFilter, noticeKindSchema, noticeSchema, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterQueryParamsSchema, opportunityFilterQuerySchema, opportunityFilterSchema, opportunityId, opportunityKeySchema, opportunityKindSchema, opportunitySchema, pnlBreakdownSchema, pointRewardsSchema, pointsProgramPnLSchema, pointsProgramSchema, pointsRewardsPnLSchema, poolOpportunityChartMetricSchema, poolOpportunityDetailSchema, poolOpportunityId, poolOpportunityKeySchema, poolOpportunitySchema, poolPositionChartMetricSchema, poolPositionId, poolPositionKeySchema, poolPositionSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionId, positionKeySchema, positionKindSchema, positionSchema, positionTransactionKindSchema, positionTransactionSchema, positionsTotalsSchema, priceFeedDataSchema, priceFeedSummarySchema, quotaAssetSchema, rateCurvePointSchema, rateCurveSchema, receivedAssetSchema, responseMetadataSchema, responseSchema, rewardsPnLSchema, rewardsSchema, strategyOpportunityChartMetricSchema, strategyOpportunityDetailSchema, strategyOpportunityId, strategyOpportunityKeySchema, strategyOpportunitySchema, strategyPositionChartMetricSchema, strategyPositionId, strategyPositionKeySchema, strategyPositionSchema, timestampSchema, tokenAmountSchema, tokenRewardsPnLSchema, tokenRewardsSchema, tokenSchema, txCallSchema };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ZodAddress } from "../sdk/utils/zod.js";
|
|
2
|
-
import { filterable } from "./filters.schema.js";
|
|
3
2
|
import { assetTypeSchema, chainIdSchema, timestampSchema, tokenAmountSchema, tokenSchema, txCallSchema } from "./primitives.schema.js";
|
|
3
|
+
import { filterable } from "./filters.schema.js";
|
|
4
4
|
import { z } from "zod/v4";
|
|
5
5
|
//#region src/model/liquidations.schema.ts
|
|
6
6
|
/**
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { tokenSchema } from "./primitives.schema.js";
|
|
2
|
+
import { z } from "zod/v4";
|
|
3
|
+
//#region src/model/notices.schema.ts
|
|
4
|
+
/**
|
|
5
|
+
* {@link NoticeKind}
|
|
6
|
+
**/
|
|
7
|
+
const noticeKindSchema = z.union([
|
|
8
|
+
z.literal("expired"),
|
|
9
|
+
z.literal("externalRewards"),
|
|
10
|
+
z.literal("extraApy"),
|
|
11
|
+
z.literal("warning"),
|
|
12
|
+
z.literal("disclaimer")
|
|
13
|
+
]);
|
|
14
|
+
/**
|
|
15
|
+
* {@link Notice}
|
|
16
|
+
**/
|
|
17
|
+
const noticeSchema = z.object({
|
|
18
|
+
kind: noticeKindSchema,
|
|
19
|
+
message: z.string(),
|
|
20
|
+
token: tokenSchema.optional()
|
|
21
|
+
});
|
|
22
|
+
//#endregion
|
|
23
|
+
export { noticeKindSchema, noticeSchema };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ZodAddress } from "../sdk/utils/zod.js";
|
|
2
|
+
import { amountSchema, assetTypeSchema, bpsSchema, chainIdSchema, leverageSchema, timestampSchema, tokenSchema } from "./primitives.schema.js";
|
|
2
3
|
import { curatorSchema } from "./curators.schema.js";
|
|
3
4
|
import { isFilterSet } from "./filters.js";
|
|
4
5
|
import { booleanParamSchema, encodeFlag, filterable } from "./filters.schema.js";
|
|
5
|
-
import { amountSchema, assetTypeSchema, bpsSchema, chainIdSchema, leverageSchema, timestampSchema, tokenSchema } from "./primitives.schema.js";
|
|
6
6
|
import { z } from "zod/v4";
|
|
7
7
|
//#region src/model/opportunities.schema.ts
|
|
8
8
|
/**
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ZodAddress } from "../sdk/utils/zod.js";
|
|
1
|
+
import { ZodAddress, ZodBigInt, ZodHex } from "../sdk/utils/zod.js";
|
|
2
|
+
import { assetTypeSchema, bpsSchema, chainIdSchema, leverageSchema, timestampSchema, tokenAmountSchema, tokenSchema } from "./primitives.schema.js";
|
|
2
3
|
import { isFilterSet } from "./filters.js";
|
|
3
4
|
import { booleanParamSchema, encodeFlag, filterable } from "./filters.schema.js";
|
|
4
|
-
import { assetTypeSchema, bpsSchema, chainIdSchema, leverageSchema, tokenAmountSchema, tokenSchema } from "./primitives.schema.js";
|
|
5
|
-
import { apyBreakdownSchema, pointsProgramSchema } from "./opportunities.schema.js";
|
|
6
5
|
import { delayedReceivedAssetSchema, liquidationPositionSchema } from "./liquidations.schema.js";
|
|
6
|
+
import { apyBreakdownSchema, pointsProgramSchema } from "./opportunities.schema.js";
|
|
7
7
|
import { z } from "zod/v4";
|
|
8
8
|
//#region src/model/positions.schema.ts
|
|
9
9
|
/**
|
|
@@ -72,6 +72,15 @@ const poolPositionSchema = z.object({
|
|
|
72
72
|
pnl: pnlBreakdownSchema.optional()
|
|
73
73
|
});
|
|
74
74
|
/**
|
|
75
|
+
* {@link BorrowRateBreakdown}
|
|
76
|
+
**/
|
|
77
|
+
const borrowRateBreakdownSchema = z.object({
|
|
78
|
+
total: bpsSchema,
|
|
79
|
+
totalOnDebt: bpsSchema,
|
|
80
|
+
base: bpsSchema,
|
|
81
|
+
quotas: z.record(ZodAddress(), bpsSchema)
|
|
82
|
+
});
|
|
83
|
+
/**
|
|
75
84
|
* {@link StrategyPosition}
|
|
76
85
|
**/
|
|
77
86
|
const strategyPositionSchema = z.object({
|
|
@@ -87,6 +96,9 @@ const strategyPositionSchema = z.object({
|
|
|
87
96
|
totalDebt: tokenAmountSchema,
|
|
88
97
|
totalValue: tokenAmountSchema,
|
|
89
98
|
healthFactor: bpsSchema,
|
|
99
|
+
borrowRate: borrowRateBreakdownSchema.optional(),
|
|
100
|
+
timeToLiquidation: ZodBigInt().nullable().optional(),
|
|
101
|
+
liquidationPrice: ZodBigInt().nullable().optional(),
|
|
90
102
|
pnl: pnlBreakdownSchema.optional(),
|
|
91
103
|
collaterals: z.array(positionCollateralSchema)
|
|
92
104
|
});
|
|
@@ -161,5 +173,35 @@ const positionKeySchema = z.discriminatedUnion("kind", [z.object({
|
|
|
161
173
|
kind: z.literal("strategy"),
|
|
162
174
|
...strategyPositionKeySchema.shape
|
|
163
175
|
})]);
|
|
176
|
+
/**
|
|
177
|
+
* {@link PositionsTotals}
|
|
178
|
+
**/
|
|
179
|
+
const positionsTotalsSchema = z.object({
|
|
180
|
+
currentYield: apyBreakdownSchema.nullable(),
|
|
181
|
+
pnl: pnlBreakdownSchema.nullable(),
|
|
182
|
+
netValueUsd: z.number().nullable(),
|
|
183
|
+
claimableUsd: z.number().nullable()
|
|
184
|
+
});
|
|
185
|
+
/**
|
|
186
|
+
* {@link PositionTransactionKind}
|
|
187
|
+
**/
|
|
188
|
+
const positionTransactionKindSchema = z.union([
|
|
189
|
+
z.literal("open"),
|
|
190
|
+
z.literal("deposit"),
|
|
191
|
+
z.literal("withdraw"),
|
|
192
|
+
z.literal("adjustLeverage"),
|
|
193
|
+
z.literal("addCollateral"),
|
|
194
|
+
z.literal("withdrawCollateral"),
|
|
195
|
+
z.literal("liquidation")
|
|
196
|
+
]);
|
|
197
|
+
/**
|
|
198
|
+
* {@link PositionTransaction}
|
|
199
|
+
**/
|
|
200
|
+
const positionTransactionSchema = z.object({
|
|
201
|
+
txHash: ZodHex(),
|
|
202
|
+
timestamp: timestampSchema,
|
|
203
|
+
kind: positionTransactionKindSchema,
|
|
204
|
+
assets: z.array(tokenAmountSchema)
|
|
205
|
+
});
|
|
164
206
|
//#endregion
|
|
165
|
-
export { pnlBreakdownSchema, pointsProgramPnLSchema, pointsRewardsPnLSchema, poolPositionKeySchema, poolPositionSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionKeySchema, positionKindSchema, positionSchema, rewardsPnLSchema, strategyPositionKeySchema, strategyPositionSchema, tokenRewardsPnLSchema };
|
|
207
|
+
export { borrowRateBreakdownSchema, pnlBreakdownSchema, pointsProgramPnLSchema, pointsRewardsPnLSchema, poolPositionKeySchema, poolPositionSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionKeySchema, positionKindSchema, positionSchema, positionTransactionKindSchema, positionTransactionSchema, positionsTotalsSchema, rewardsPnLSchema, strategyPositionKeySchema, strategyPositionSchema, tokenRewardsPnLSchema };
|
|
@@ -17,23 +17,34 @@ var AbstractNamespace = class {
|
|
|
17
17
|
**/
|
|
18
18
|
maxOffchainLagSeconds;
|
|
19
19
|
logger;
|
|
20
|
+
/**
|
|
21
|
+
* The SDK's loading policy, awaited before every on-chain leg: attached, and
|
|
22
|
+
* the touched chains no older than the SDK allows.
|
|
23
|
+
**/
|
|
24
|
+
ensureFresh;
|
|
20
25
|
#name;
|
|
21
26
|
#onchain;
|
|
22
27
|
#offchain;
|
|
28
|
+
/** {@link onchain}, built once: the source's methods behind the loading policy. */
|
|
29
|
+
#onchainView;
|
|
23
30
|
constructor(name, onchain, offchain, options) {
|
|
24
31
|
this.#name = name;
|
|
25
32
|
this.#onchain = onchain;
|
|
26
33
|
this.#offchain = offchain;
|
|
27
34
|
this.maxOffchainLagSeconds = options.maxOffchainLagSeconds;
|
|
35
|
+
this.ensureFresh = options.ensureFresh;
|
|
28
36
|
this.logger = options.logger?.child?.({ name }) ?? options.logger;
|
|
37
|
+
this.#onchainView = onchain && options.ensureFresh ? behindLoadingPolicy(onchain, options.ensureFresh) : onchain;
|
|
29
38
|
}
|
|
30
39
|
/**
|
|
31
|
-
* The on-chain source namespace on its own
|
|
40
|
+
* The on-chain source namespace on its own — every read of it attaches and
|
|
41
|
+
* revalidates like a merged read does, so a consumer showing the two sources
|
|
42
|
+
* separately still gets the SDK's loading policy. Throws
|
|
32
43
|
* {@link SourceUnavailableError} in `offchain` mode.
|
|
33
44
|
**/
|
|
34
45
|
get onchain() {
|
|
35
|
-
if (!this.#
|
|
36
|
-
return this.#
|
|
46
|
+
if (!this.#onchainView) throw new SourceUnavailableError(this.#name, "onchain");
|
|
47
|
+
return this.#onchainView;
|
|
37
48
|
}
|
|
38
49
|
/**
|
|
39
50
|
* The backend source namespace on its own. Throws
|
|
@@ -50,7 +61,10 @@ var AbstractNamespace = class {
|
|
|
50
61
|
async merged(action, query) {
|
|
51
62
|
const onchain = this.#onchain;
|
|
52
63
|
const offchain = this.#offchain;
|
|
53
|
-
const [fromChain, fromBackend] = await Promise.all([this.#ask(action, "onchain", onchain,
|
|
64
|
+
const [fromChain, fromBackend] = await Promise.all([this.#ask(action, "onchain", onchain, async (source) => {
|
|
65
|
+
await this.ensureFresh?.(query.chainIds);
|
|
66
|
+
return query.fromChain(source);
|
|
67
|
+
}), this.#ask(action, "offchain", offchain, query.fromBackend)]);
|
|
54
68
|
const merged = query.merge(fromChain.response, fromBackend.response);
|
|
55
69
|
if (merged && !everyChainFailed(merged.meta)) return merged;
|
|
56
70
|
const sole = onchain && offchain ? void 0 : fromChain.error ?? fromBackend.error;
|
|
@@ -71,5 +85,21 @@ var AbstractNamespace = class {
|
|
|
71
85
|
}
|
|
72
86
|
}
|
|
73
87
|
};
|
|
88
|
+
/**
|
|
89
|
+
* The source's every method, awaiting the loading policy first. The policy is
|
|
90
|
+
* asked for every chain — an escape hatch does not tell which chains a call
|
|
91
|
+
* touches (the merged reads do, and scope it); the object identity differs
|
|
92
|
+
* from the source's, its type does not.
|
|
93
|
+
**/
|
|
94
|
+
function behindLoadingPolicy(source, ensureFresh) {
|
|
95
|
+
return new Proxy(source, { get(target, property, receiver) {
|
|
96
|
+
const value = Reflect.get(target, property, receiver);
|
|
97
|
+
if (typeof value !== "function") return value;
|
|
98
|
+
return async (...args) => {
|
|
99
|
+
await ensureFresh();
|
|
100
|
+
return Reflect.apply(value, target, args);
|
|
101
|
+
};
|
|
102
|
+
} });
|
|
103
|
+
}
|
|
74
104
|
//#endregion
|
|
75
105
|
export { AbstractNamespace };
|
|
@@ -14,6 +14,11 @@ import { PositionsNamespace } from "./positions/PositionsNamespace.js";
|
|
|
14
14
|
import "./positions/index.js";
|
|
15
15
|
//#region src/new-sdk/GearboxSDK.ts
|
|
16
16
|
/**
|
|
17
|
+
* Default {@link GearboxSDKOptions.maxStateAgeSeconds}: the fastest poll an
|
|
18
|
+
* app runs, so a 30 s tick sees state no older than itself.
|
|
19
|
+
**/
|
|
20
|
+
const DEFAULT_MAX_STATE_AGE = 30;
|
|
21
|
+
/**
|
|
17
22
|
* Entry point over both sources of Gearbox data: the chain and the Gearbox
|
|
18
23
|
* backend. The {@link Mode} is fixed at construction and decides which methods
|
|
19
24
|
* exist.
|
|
@@ -53,12 +58,27 @@ var GearboxSDK = class {
|
|
|
53
58
|
#onchain;
|
|
54
59
|
#offchain;
|
|
55
60
|
#ownsOnchain = false;
|
|
61
|
+
#maxStateAgeSeconds;
|
|
62
|
+
#logger;
|
|
63
|
+
/**
|
|
64
|
+
* The banners the backend attaches to a pool opportunity or a strategy
|
|
65
|
+
* position, see {@link Notice}. Top-level because the subject is either
|
|
66
|
+
* kind of entity, so neither namespace owns it. Backend-only, hence gated
|
|
67
|
+
* by mode like every other backend read: absent in `onchain` mode.
|
|
68
|
+
**/
|
|
69
|
+
notices;
|
|
56
70
|
#attached;
|
|
71
|
+
/** The one attach in flight, shared by {@link attach} and every first read. */
|
|
72
|
+
#attaching;
|
|
73
|
+
/** One sync in flight per chain: concurrent stale reads join it. */
|
|
74
|
+
#syncing = /* @__PURE__ */ new Map();
|
|
57
75
|
constructor(options) {
|
|
58
|
-
const { mode, networks, onchain, offchain, attach, logger, maxOffchainLagSeconds = 120 } = options;
|
|
76
|
+
const { mode, networks, onchain, offchain, attach, logger, maxOffchainLagSeconds = 120, maxStateAgeSeconds = 30 } = options;
|
|
59
77
|
this.mode = mode;
|
|
60
78
|
this.networks = [...networks];
|
|
61
79
|
this.#attachOptions = attach;
|
|
80
|
+
this.#maxStateAgeSeconds = maxStateAgeSeconds;
|
|
81
|
+
this.#logger = logger;
|
|
62
82
|
const needsOnchain = mode === "onchain" || mode === "both";
|
|
63
83
|
const needsOffchain = mode === "offchain" || mode === "both";
|
|
64
84
|
if (needsOnchain && !onchain) throw new MissingSourceError(mode, "onchain");
|
|
@@ -91,19 +111,67 @@ var GearboxSDK = class {
|
|
|
91
111
|
this.#attached = !this.#ownsOnchain;
|
|
92
112
|
const namespaceOptions = {
|
|
93
113
|
maxOffchainLagSeconds,
|
|
114
|
+
ensureFresh: this.#onchain ? (chainIds) => this.#ensureFresh(chainIds) : void 0,
|
|
94
115
|
logger
|
|
95
116
|
};
|
|
96
117
|
this.opportunities = new OpportunitiesNamespace(this.#onchain, this.#offchain, namespaceOptions);
|
|
97
118
|
this.positions = new PositionsNamespace(this.#onchain, this.#offchain, namespaceOptions);
|
|
119
|
+
const backend = this.#offchain;
|
|
120
|
+
this.notices = backend ? (subject) => backend.notices.list(subject) : void 0;
|
|
98
121
|
}
|
|
99
122
|
/**
|
|
100
123
|
* Attaches the on-chain SDK when this instance owns one; a no-op in `offchain`
|
|
101
124
|
* mode and when an already-attached SDK was injected.
|
|
102
125
|
**/
|
|
103
126
|
async attach() {
|
|
127
|
+
return this.#ensureAttached();
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* The attach every async read awaits: the first caller starts it, later
|
|
131
|
+
* ones join the same promise; a rejected attach is not cached, so the next
|
|
132
|
+
* read retries.
|
|
133
|
+
**/
|
|
134
|
+
async #ensureAttached() {
|
|
104
135
|
if (this.#attached || !this.#ownsOnchain || !this.#onchain) return;
|
|
105
|
-
|
|
106
|
-
|
|
136
|
+
if (!this.#attaching) {
|
|
137
|
+
const onchain = this.#onchain;
|
|
138
|
+
this.#attaching = onchain.attach(this.#attachOptions).then(() => {
|
|
139
|
+
this.#attached = true;
|
|
140
|
+
}).finally(() => {
|
|
141
|
+
this.#attaching = void 0;
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
return this.#attaching;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* What every on-chain leg of an async read awaits: the source attached, and
|
|
148
|
+
* the chains the read touches (all of them when unnamed) synced when their
|
|
149
|
+
* loaded state is older than `maxStateAgeSeconds`. A sync that fails leaves
|
|
150
|
+
* the previous state to be served — its age tells the consumer it is stale.
|
|
151
|
+
**/
|
|
152
|
+
async #ensureFresh(chainIds) {
|
|
153
|
+
await this.#ensureAttached();
|
|
154
|
+
const onchain = this.#onchain;
|
|
155
|
+
if (!onchain) return;
|
|
156
|
+
const wanted = chainIds && new Set(chainIds);
|
|
157
|
+
const stale = [];
|
|
158
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
159
|
+
for (const chain of onchain.chains.values()) {
|
|
160
|
+
if (wanted && !wanted.has(chain.chainId)) continue;
|
|
161
|
+
if (now - Number(chain.timestamp) > this.#maxStateAgeSeconds) stale.push(chain);
|
|
162
|
+
}
|
|
163
|
+
await Promise.all(stale.map((chain) => this.#sync(chain)));
|
|
164
|
+
}
|
|
165
|
+
#sync(chain) {
|
|
166
|
+
const inFlight = this.#syncing.get(chain.chainId);
|
|
167
|
+
if (inFlight) return inFlight;
|
|
168
|
+
const sync = chain.syncState().then(() => void 0).catch((error) => {
|
|
169
|
+
this.#logger?.warn(error, `failed to sync chain ${chain.chainId}; serving state of block ${chain.currentBlock}`);
|
|
170
|
+
}).finally(() => {
|
|
171
|
+
this.#syncing.delete(chain.chainId);
|
|
172
|
+
});
|
|
173
|
+
this.#syncing.set(chain.chainId, sync);
|
|
174
|
+
return sync;
|
|
107
175
|
}
|
|
108
176
|
/**
|
|
109
177
|
* Whether the on-chain source is ready to be read from. Always `true` in
|
|
@@ -140,4 +208,4 @@ function chainsOf(configured, networks) {
|
|
|
140
208
|
return chains;
|
|
141
209
|
}
|
|
142
210
|
//#endregion
|
|
143
|
-
export { GearboxSDK };
|
|
211
|
+
export { DEFAULT_MAX_STATE_AGE, GearboxSDK };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
//#region src/new-sdk/execute/ExecuteApi.ts
|
|
2
|
+
/**
|
|
3
|
+
* {@inheritDoc OpportunitiesExecute}
|
|
4
|
+
**/
|
|
5
|
+
var ExecuteApi = class {
|
|
6
|
+
#chainOf;
|
|
7
|
+
constructor(chainOf) {
|
|
8
|
+
this.#chainOf = chainOf;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* {@inheritDoc OpportunitiesExecute.buildTx}
|
|
12
|
+
**/
|
|
13
|
+
async buildTx(request) {
|
|
14
|
+
if (!request.sim.ok) throw new Error(`cannot build a transaction from a failed ${request.kind} simulation`);
|
|
15
|
+
const sdk = this.#chainOf(request.chainId);
|
|
16
|
+
switch (request.kind) {
|
|
17
|
+
case "pool": return poolTx(sdk, request);
|
|
18
|
+
case "open": return openTx(sdk, request);
|
|
19
|
+
case "account": return accountTx(sdk, request);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
function poolTx(sdk, request) {
|
|
24
|
+
const { pool, wallet, sim } = request;
|
|
25
|
+
const { tokenIn, tokenOut } = sim.preview;
|
|
26
|
+
if (request.op === "deposit") {
|
|
27
|
+
const meta = sdk.pools.getDepositMetadata(pool, tokenIn.token, tokenOut.token);
|
|
28
|
+
const result = sdk.pools.addLiquidity({
|
|
29
|
+
pool,
|
|
30
|
+
wallet,
|
|
31
|
+
collateral: tokenIn,
|
|
32
|
+
meta
|
|
33
|
+
});
|
|
34
|
+
if (!result) throw new Error(`pool ${pool} takes no deposit transaction for ${tokenIn.token} (${meta.type})`);
|
|
35
|
+
return result.tx;
|
|
36
|
+
}
|
|
37
|
+
const meta = sdk.pools.getWithdrawalMetadata(pool, tokenIn.token, tokenOut.token);
|
|
38
|
+
return sdk.pools.removeLiquidity({
|
|
39
|
+
pool,
|
|
40
|
+
wallet,
|
|
41
|
+
amount: request.op === "withdraw" ? tokenOut.balance : tokenIn.balance,
|
|
42
|
+
permit: void 0,
|
|
43
|
+
meta,
|
|
44
|
+
mode: request.op === "withdraw" ? "withdraw" : "redeem"
|
|
45
|
+
}).tx;
|
|
46
|
+
}
|
|
47
|
+
async function openTx(sdk, request) {
|
|
48
|
+
const { creditManager, wallet, collateral, ethAmount, sim } = request;
|
|
49
|
+
const { preview } = sim;
|
|
50
|
+
return sdk.accounts.openCA({
|
|
51
|
+
creditManager,
|
|
52
|
+
to: wallet,
|
|
53
|
+
collateral,
|
|
54
|
+
ethAmount,
|
|
55
|
+
debt: preview.debt,
|
|
56
|
+
calls: preview.calls,
|
|
57
|
+
averageQuota: preview.averageQuota,
|
|
58
|
+
minQuota: preview.minQuota,
|
|
59
|
+
permits: {},
|
|
60
|
+
referralCode: 0n,
|
|
61
|
+
rwaOptions: await openRwaOptions(sdk, request)
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The documented `openCA` contract: ask the market for its open requirements
|
|
66
|
+
* and hand them back as operation args, with the caller's cached signatures
|
|
67
|
+
* attached. `undefined` on non-RWA markets and when no target token is named.
|
|
68
|
+
**/
|
|
69
|
+
async function openRwaOptions(sdk, request) {
|
|
70
|
+
if (!request.targetToken) return;
|
|
71
|
+
const requirements = await sdk.accounts.getOpenAccountRequirements(request.wallet, request.creditManager, { tokenOutAddress: request.targetToken });
|
|
72
|
+
if (!requirements) return;
|
|
73
|
+
return {
|
|
74
|
+
type: requirements.type,
|
|
75
|
+
tokensToRegister: requirements.tokensToRegister,
|
|
76
|
+
signaturesToCache: request.signaturesToCache ?? []
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
async function accountTx(sdk, request) {
|
|
80
|
+
const account = await sdk.accounts.getCreditAccountData(request.creditAccount);
|
|
81
|
+
if (!account) throw new Error(`credit account not found: ${request.creditAccount}`);
|
|
82
|
+
return sdk.accounts.executeCaUpdate(account, request.sim.calls, { ethAmount: nativeValue(request.sim.operations) });
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The coin the simulation asked the wallet for, which the facade wraps out of
|
|
86
|
+
* `msg.value` before running the multicall. Taken off the collateral step that
|
|
87
|
+
* recorded it rather than from the caller, so it cannot disagree with what was
|
|
88
|
+
* simulated.
|
|
89
|
+
**/
|
|
90
|
+
function nativeValue(operations) {
|
|
91
|
+
return operations.reduce((total, op) => total + (op.type === "addCollateral" ? op.value ?? 0n : 0n), 0n);
|
|
92
|
+
}
|
|
93
|
+
//#endregion
|
|
94
|
+
export { ExecuteApi };
|
|
@@ -7,6 +7,10 @@ import { NoSourceServedError } from "./errors/NoSourceServedError.js";
|
|
|
7
7
|
import { SourceUnavailableError } from "./errors/SourceUnavailableError.js";
|
|
8
8
|
import "./errors/index.js";
|
|
9
9
|
import { AbstractNamespace } from "./AbstractNamespace.js";
|
|
10
|
+
import { ExecuteApi } from "./execute/ExecuteApi.js";
|
|
11
|
+
import "./execute/index.js";
|
|
12
|
+
import { SimulateApi } from "./simulate/SimulateApi.js";
|
|
13
|
+
import "./simulate/index.js";
|
|
10
14
|
import { filterResponse } from "./utils/filterResponse.js";
|
|
11
15
|
import { DEFAULT_MAX_OFFCHAIN_LAG, mergeChainList, mergeChainOne } from "./utils/mergeChains.js";
|
|
12
16
|
import "./utils/index.js";
|
|
@@ -14,6 +18,6 @@ import { OpportunitiesNamespace } from "./opportunities/OpportunitiesNamespace.j
|
|
|
14
18
|
import "./opportunities/index.js";
|
|
15
19
|
import { PositionsNamespace } from "./positions/PositionsNamespace.js";
|
|
16
20
|
import "./positions/index.js";
|
|
17
|
-
import { GearboxSDK } from "./GearboxSDK.js";
|
|
21
|
+
import { DEFAULT_MAX_STATE_AGE, GearboxSDK } from "./GearboxSDK.js";
|
|
18
22
|
import "./types.js";
|
|
19
|
-
export { AbstractNamespace, AllSourcesFailedError, DEFAULT_MAX_OFFCHAIN_LAG, GearboxSDK, MissingSourceError, NoSourceServedError, OpportunitiesNamespace, PositionsNamespace, SourceChainMismatchError, SourceUnavailableError, assertSameChains, everyChainFailed, filterResponse, mergeChainList, mergeChainOne };
|
|
23
|
+
export { AbstractNamespace, AllSourcesFailedError, DEFAULT_MAX_OFFCHAIN_LAG, DEFAULT_MAX_STATE_AGE, ExecuteApi, GearboxSDK, MissingSourceError, NoSourceServedError, OpportunitiesNamespace, PositionsNamespace, SimulateApi, SourceChainMismatchError, SourceUnavailableError, assertSameChains, everyChainFailed, filterResponse, mergeChainList, mergeChainOne };
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { matchesOpportunityFilter } from "../../model/opportunities.js";
|
|
2
2
|
import "../../model/index.js";
|
|
3
|
+
import { SourceUnavailableError } from "../errors/SourceUnavailableError.js";
|
|
4
|
+
import "../errors/index.js";
|
|
3
5
|
import { AbstractNamespace } from "../AbstractNamespace.js";
|
|
6
|
+
import { ExecuteApi } from "../execute/ExecuteApi.js";
|
|
7
|
+
import "../execute/index.js";
|
|
8
|
+
import { SimulateApi } from "../simulate/SimulateApi.js";
|
|
9
|
+
import "../simulate/index.js";
|
|
4
10
|
import { filterResponse } from "../utils/filterResponse.js";
|
|
5
11
|
import { mergeChainList, mergeChainOne } from "../utils/mergeChains.js";
|
|
6
12
|
import "../utils/index.js";
|
|
@@ -18,14 +24,33 @@ var OpportunitiesNamespace = class extends AbstractNamespace {
|
|
|
18
24
|
pool: (onchain, offchain) => mergeChainOne(onchain, offchain, this.maxOffchainLagSeconds),
|
|
19
25
|
strategy: (onchain, offchain) => mergeChainOne(onchain, offchain, this.maxOffchainLagSeconds)
|
|
20
26
|
};
|
|
27
|
+
#simulate;
|
|
28
|
+
#execute;
|
|
21
29
|
constructor(onchain, offchain, options) {
|
|
22
30
|
super("Opportunities", onchain?.opportunities, offchain?.opportunities, options);
|
|
31
|
+
this.#simulate = onchain && new SimulateApi(onchain, options.ensureFresh);
|
|
32
|
+
this.#execute = onchain && new ExecuteApi((chainId) => onchain.chain(chainId));
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* {@inheritDoc OpportunitiesOnchainOnly.simulate}
|
|
36
|
+
**/
|
|
37
|
+
get simulate() {
|
|
38
|
+
if (!this.#simulate) throw new SourceUnavailableError("Opportunities", "onchain");
|
|
39
|
+
return this.#simulate;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* {@inheritDoc OpportunitiesOnchainOnly.execute}
|
|
43
|
+
**/
|
|
44
|
+
get execute() {
|
|
45
|
+
if (!this.#execute) throw new SourceUnavailableError("Opportunities", "onchain");
|
|
46
|
+
return this.#execute;
|
|
23
47
|
}
|
|
24
48
|
/**
|
|
25
49
|
* {@inheritDoc OpportunitiesBase.list}
|
|
26
50
|
**/
|
|
27
51
|
async list(filter) {
|
|
28
52
|
return this.merged("list opportunities", {
|
|
53
|
+
chainIds: filter?.chainIds,
|
|
29
54
|
fromChain: (source) => source.list(filter),
|
|
30
55
|
fromBackend: (source) => source.list(filter),
|
|
31
56
|
merge: this.merge.list
|
|
@@ -36,6 +61,7 @@ var OpportunitiesNamespace = class extends AbstractNamespace {
|
|
|
36
61
|
**/
|
|
37
62
|
async getPool(key) {
|
|
38
63
|
return this.merged("get pool opportunity", {
|
|
64
|
+
chainIds: [key.chainId],
|
|
39
65
|
fromChain: (source) => source.getPool(key),
|
|
40
66
|
fromBackend: (source) => source.getPool(key),
|
|
41
67
|
merge: this.merge.pool
|
|
@@ -46,6 +72,7 @@ var OpportunitiesNamespace = class extends AbstractNamespace {
|
|
|
46
72
|
**/
|
|
47
73
|
async getStrategy(key) {
|
|
48
74
|
return this.merged("get strategy opportunity", {
|
|
75
|
+
chainIds: [key.chainId],
|
|
49
76
|
fromChain: (source) => source.getStrategy(key),
|
|
50
77
|
fromBackend: (source) => source.getStrategy(key),
|
|
51
78
|
merge: this.merge.strategy
|
|
@@ -57,12 +84,8 @@ var OpportunitiesNamespace = class extends AbstractNamespace {
|
|
|
57
84
|
filter(response, filter) {
|
|
58
85
|
return filterResponse(response, filter, matchesOpportunityFilter);
|
|
59
86
|
}
|
|
60
|
-
|
|
61
|
-
return
|
|
62
|
-
opportunity: key,
|
|
63
|
-
range,
|
|
64
|
-
metric
|
|
65
|
-
}) };
|
|
87
|
+
async charts(key, metrics, range) {
|
|
88
|
+
return this.offchain.getCharts(key, metrics, range);
|
|
66
89
|
}
|
|
67
90
|
};
|
|
68
91
|
//#endregion
|
|
@@ -22,6 +22,7 @@ var PositionsNamespace = class extends AbstractNamespace {
|
|
|
22
22
|
**/
|
|
23
23
|
async list(wallet, filter) {
|
|
24
24
|
return this.merged("list positions", {
|
|
25
|
+
chainIds: filter?.chainIds,
|
|
25
26
|
fromChain: (source) => source.list({
|
|
26
27
|
wallet,
|
|
27
28
|
filter
|
|
@@ -39,12 +40,8 @@ var PositionsNamespace = class extends AbstractNamespace {
|
|
|
39
40
|
filter(response, filter) {
|
|
40
41
|
return filterResponse(response, filter, matchesPositionFilter);
|
|
41
42
|
}
|
|
42
|
-
|
|
43
|
-
return
|
|
44
|
-
position: key,
|
|
45
|
-
range,
|
|
46
|
-
metric
|
|
47
|
-
}) };
|
|
43
|
+
async charts(key, metrics, range) {
|
|
44
|
+
return this.offchain.getCharts(key, metrics, range);
|
|
48
45
|
}
|
|
49
46
|
};
|
|
50
47
|
//#endregion
|