@gearbox-protocol/sdk 15.1.0-next.1 → 15.1.0-next.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/abi/iExpirable.js +15 -0
- package/dist/cjs/common-utils/utils/apy/get-single-quota-borrow-rate.js +2 -0
- package/dist/cjs/common-utils/utils/creditAccount/calc-health-factor.js +24 -22
- package/dist/cjs/common-utils/utils/creditAccount/calc-quota-borrow-rate.js +2 -0
- package/dist/cjs/common-utils/utils/creditAccount/get-time-to-liquidation.js +8 -5
- package/dist/cjs/common-utils/utils/creditAccount/liquidation-price.js +21 -11
- package/dist/cjs/dev/AccountOpener.js +0 -1
- package/dist/cjs/dev/compareOpportunities.js +137 -0
- package/dist/cjs/dev/comparePositions.js +183 -0
- package/dist/cjs/dev/fieldDiff.js +241 -0
- package/dist/cjs/model/charts.js +147 -0
- package/dist/cjs/model/charts.schema.js +240 -0
- package/dist/cjs/model/index.js +35 -22
- package/dist/cjs/model/liquidations.schema.js +1 -1
- package/dist/cjs/model/notices.schema.js +25 -0
- package/dist/cjs/model/opportunities.schema.js +1 -1
- package/dist/cjs/model/positions.schema.js +48 -2
- package/dist/cjs/new-sdk/AbstractNamespace.js +34 -4
- package/dist/cjs/new-sdk/GearboxSDK.js +72 -3
- package/dist/cjs/new-sdk/execute/ExecuteApi.js +95 -0
- package/dist/cjs/new-sdk/execute/index.js +3 -0
- package/dist/cjs/new-sdk/index.js +7 -0
- package/dist/cjs/new-sdk/opportunities/OpportunitiesNamespace.js +29 -6
- package/dist/cjs/new-sdk/positions/PositionsNamespace.js +3 -6
- package/dist/cjs/new-sdk/simulate/SimulateApi.js +361 -0
- package/dist/cjs/new-sdk/simulate/index.js +4 -0
- package/dist/cjs/new-sdk/utils/index.js +0 -1
- package/dist/cjs/offchain/AbstractOffchainNamespace.js +10 -7
- package/dist/cjs/offchain/GearboxAPI.js +7 -0
- package/dist/cjs/offchain/index.js +3 -0
- package/dist/cjs/offchain/notices/OffchainNotices.js +27 -0
- package/dist/cjs/offchain/notices/index.js +3 -0
- package/dist/cjs/offchain/opportunities/OffchainOpportunities.js +4 -8
- package/dist/cjs/offchain/positions/OffchainPositions.js +12 -12
- package/dist/cjs/preview/preview/CreditAccountState.js +14 -1
- package/dist/cjs/preview/preview/buildDelayedPreview.js +16 -6
- package/dist/cjs/preview/preview/previewAdjustCreditAccount.js +9 -2
- package/dist/cjs/preview/preview/previewOpenCreditAccount.js +11 -3
- package/dist/cjs/preview/preview/previewOperation.js +1 -1
- package/dist/cjs/sdk/MultichainSDK.js +3 -4
- package/dist/cjs/sdk/OnchainSDK.js +42 -13
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +2 -8
- package/dist/cjs/sdk/accounts/credit-account-compressor/CreditAccountCompressor.js +2 -90
- package/dist/cjs/sdk/accounts/index.js +5 -2
- package/dist/cjs/sdk/accounts/intents/guards.js +114 -0
- package/dist/cjs/sdk/accounts/intents/index.js +216 -358
- package/dist/cjs/sdk/accounts/intents/math.js +56 -0
- package/dist/cjs/sdk/accounts/intents/open-strategy.js +133 -0
- package/dist/cjs/sdk/accounts/intents/operations.js +165 -0
- package/dist/cjs/sdk/accounts/intents/plan.js +373 -0
- package/dist/cjs/sdk/accounts/intents/realize.js +301 -0
- package/dist/cjs/sdk/accounts/intents/testing/delayed.js +50 -0
- package/dist/cjs/sdk/accounts/intents/testing/market.js +166 -0
- package/dist/cjs/sdk/accounts/intents/testing/sdk-mock.js +194 -35
- package/dist/cjs/sdk/accounts/intents/tests/add-collateral.fixtures.js +123 -0
- package/dist/cjs/sdk/accounts/intents/tests/adjust-leverage.fixtures.js +254 -0
- package/dist/cjs/sdk/accounts/intents/tests/deposit.fixtures.js +324 -0
- package/dist/cjs/sdk/accounts/intents/tests/finish-decrease-leverage.fixtures.js +242 -0
- package/dist/cjs/sdk/accounts/intents/tests/finish-withdraw.fixtures.js +383 -0
- package/dist/cjs/sdk/accounts/intents/tests/open-strategy.fixtures.js +133 -0
- package/dist/cjs/sdk/accounts/intents/tests/withdraw-asset.fixtures.js +131 -0
- package/dist/cjs/sdk/accounts/intents/tests/withdraw.fixtures.js +426 -0
- package/dist/cjs/sdk/accounts/intents/types.js +16 -0
- package/dist/cjs/sdk/accounts/intents/utils/adjust-state-to-snapshot.js +18 -0
- package/dist/cjs/sdk/accounts/intents/utils/credit-account-slice.js +45 -0
- package/dist/cjs/sdk/accounts/intents/utils/index.js +17 -8
- package/dist/cjs/sdk/accounts/intents/utils/ledger.js +94 -0
- package/dist/cjs/sdk/accounts/intents/utils/pick-token.js +72 -0
- package/dist/cjs/sdk/accounts/intents/utils/quotas-for-update.js +27 -0
- package/dist/cjs/sdk/accounts/intents/utils/router-path.js +86 -0
- package/dist/cjs/sdk/accounts/intents/view.js +38 -0
- package/dist/cjs/sdk/accounts/liquidations/LiquidationsService.js +0 -3
- package/dist/cjs/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.js +29 -18
- package/dist/cjs/sdk/base/BaseContract.js +1 -1
- package/dist/cjs/sdk/base/TokensMeta.js +78 -27
- package/dist/cjs/sdk/index.js +30 -7
- package/dist/cjs/sdk/market/MarketRegister.js +16 -7
- package/dist/cjs/sdk/market/ZapperRegister.js +56 -25
- package/dist/cjs/sdk/market/credit/CreditManagerV310Contract.js +1 -12
- package/dist/cjs/sdk/market/credit/CreditSuite.js +28 -9
- package/dist/cjs/sdk/market/credit/index.js +3 -0
- package/dist/cjs/sdk/market/credit/isStrategyCollateral.js +50 -0
- package/dist/cjs/sdk/market/index.js +17 -0
- package/dist/cjs/sdk/market/math.js +65 -45
- package/dist/cjs/sdk/market/oracle/PriceOracleBaseContract.js +10 -3
- package/dist/cjs/sdk/market/pool/PoolV310Contract.js +15 -1
- package/dist/cjs/sdk/market/rwa/RWARegistry.js +22 -0
- package/dist/cjs/sdk/opportunities/index.js +0 -13
- package/dist/cjs/sdk/options.js +1 -5
- package/dist/cjs/sdk/pools/PoolService.js +133 -4
- package/dist/cjs/sdk/pools/index.js +2 -0
- package/dist/cjs/sdk/positions/PositionsService.js +218 -1
- package/dist/cjs/sdk/positions/calcBorrowRate.js +43 -0
- package/dist/cjs/sdk/positions/calcHealthFactor.js +52 -0
- package/dist/cjs/sdk/positions/calcLiquidationPrice.js +23 -0
- package/dist/cjs/sdk/positions/calcLiquidationPriceForTarget.js +30 -0
- package/dist/cjs/sdk/positions/calcTimeToLiquidationMs.js +19 -0
- package/dist/cjs/sdk/positions/index.js +12 -1
- package/dist/cjs/sdk/positions/types.js +31 -0
- package/dist/cjs/sdk/utils/abi-decode.js +2 -2
- package/dist/cjs/sdk/utils/viem/executeMulticallBatches.js +32 -0
- package/dist/cjs/sdk/utils/viem/index.js +2 -0
- package/dist/esm/abi/iExpirable.js +14 -0
- package/dist/esm/common-utils/utils/apy/get-single-quota-borrow-rate.js +2 -0
- package/dist/esm/common-utils/utils/creditAccount/calc-health-factor.js +24 -22
- package/dist/esm/common-utils/utils/creditAccount/calc-quota-borrow-rate.js +2 -0
- package/dist/esm/common-utils/utils/creditAccount/get-time-to-liquidation.js +8 -5
- package/dist/esm/common-utils/utils/creditAccount/liquidation-price.js +21 -11
- package/dist/esm/dev/AccountOpener.js +0 -1
- package/dist/esm/dev/compareOpportunities.js +135 -0
- package/dist/esm/dev/comparePositions.js +181 -0
- package/dist/esm/dev/fieldDiff.js +224 -0
- package/dist/esm/model/charts.js +140 -0
- package/dist/esm/model/charts.schema.js +226 -0
- package/dist/esm/model/index.js +9 -7
- package/dist/esm/model/liquidations.schema.js +1 -1
- package/dist/esm/model/notices.schema.js +23 -0
- package/dist/esm/model/opportunities.schema.js +1 -1
- package/dist/esm/model/positions.schema.js +46 -4
- package/dist/esm/new-sdk/AbstractNamespace.js +34 -4
- package/dist/esm/new-sdk/GearboxSDK.js +72 -4
- package/dist/esm/new-sdk/execute/ExecuteApi.js +94 -0
- package/dist/esm/new-sdk/execute/index.js +2 -0
- package/dist/esm/new-sdk/index.js +6 -2
- package/dist/esm/new-sdk/opportunities/OpportunitiesNamespace.js +29 -6
- package/dist/esm/new-sdk/positions/PositionsNamespace.js +3 -6
- package/dist/esm/new-sdk/simulate/SimulateApi.js +360 -0
- package/dist/esm/new-sdk/simulate/index.js +3 -0
- package/dist/esm/new-sdk/utils/index.js +0 -1
- package/dist/esm/offchain/AbstractOffchainNamespace.js +10 -7
- package/dist/esm/offchain/GearboxAPI.js +7 -0
- package/dist/esm/offchain/index.js +3 -1
- package/dist/esm/offchain/notices/OffchainNotices.js +26 -0
- package/dist/esm/offchain/notices/index.js +2 -0
- package/dist/esm/offchain/opportunities/OffchainOpportunities.js +4 -8
- package/dist/esm/offchain/positions/OffchainPositions.js +12 -12
- package/dist/esm/preview/preview/CreditAccountState.js +14 -1
- package/dist/esm/preview/preview/buildDelayedPreview.js +16 -6
- package/dist/esm/preview/preview/previewAdjustCreditAccount.js +9 -2
- package/dist/esm/preview/preview/previewOpenCreditAccount.js +11 -3
- package/dist/esm/preview/preview/previewOperation.js +1 -1
- package/dist/esm/sdk/MultichainSDK.js +3 -4
- package/dist/esm/sdk/OnchainSDK.js +42 -13
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +2 -8
- package/dist/esm/sdk/accounts/credit-account-compressor/CreditAccountCompressor.js +2 -90
- package/dist/esm/sdk/accounts/index.js +3 -2
- package/dist/esm/sdk/accounts/intents/guards.js +108 -0
- package/dist/esm/sdk/accounts/intents/index.js +214 -358
- package/dist/esm/sdk/accounts/intents/math.js +51 -0
- package/dist/esm/sdk/accounts/intents/open-strategy.js +132 -0
- package/dist/esm/sdk/accounts/intents/operations.js +153 -0
- package/dist/esm/sdk/accounts/intents/plan.js +361 -0
- package/dist/esm/sdk/accounts/intents/realize.js +300 -0
- package/dist/esm/sdk/accounts/intents/testing/delayed.js +38 -0
- package/dist/esm/sdk/accounts/intents/testing/market.js +148 -0
- package/dist/esm/sdk/accounts/intents/testing/sdk-mock.js +194 -35
- package/dist/esm/sdk/accounts/intents/tests/add-collateral.fixtures.js +110 -0
- package/dist/esm/sdk/accounts/intents/tests/adjust-leverage.fixtures.js +234 -0
- package/dist/esm/sdk/accounts/intents/tests/deposit.fixtures.js +302 -0
- package/dist/esm/sdk/accounts/intents/tests/finish-decrease-leverage.fixtures.js +220 -0
- package/dist/esm/sdk/accounts/intents/tests/finish-withdraw.fixtures.js +355 -0
- package/dist/esm/sdk/accounts/intents/tests/open-strategy.fixtures.js +119 -0
- package/dist/esm/sdk/accounts/intents/tests/withdraw-asset.fixtures.js +117 -0
- package/dist/esm/sdk/accounts/intents/tests/withdraw.fixtures.js +402 -0
- package/dist/esm/sdk/accounts/intents/types.js +16 -1
- package/dist/esm/sdk/accounts/intents/utils/adjust-state-to-snapshot.js +17 -0
- package/dist/esm/sdk/accounts/intents/utils/credit-account-slice.js +43 -0
- package/dist/esm/sdk/accounts/intents/utils/index.js +9 -7
- package/dist/esm/sdk/accounts/intents/utils/ledger.js +93 -0
- package/dist/esm/sdk/accounts/intents/utils/pick-token.js +68 -0
- package/dist/esm/sdk/accounts/intents/utils/quotas-for-update.js +27 -1
- package/dist/esm/sdk/accounts/intents/utils/router-path.js +85 -0
- package/dist/esm/sdk/accounts/intents/view.js +37 -0
- package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +0 -3
- package/dist/esm/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.js +29 -18
- package/dist/esm/sdk/base/BaseContract.js +1 -1
- package/dist/esm/sdk/base/TokensMeta.js +78 -27
- package/dist/esm/sdk/index.js +13 -4
- package/dist/esm/sdk/market/MarketRegister.js +16 -7
- package/dist/esm/sdk/market/ZapperRegister.js +56 -25
- package/dist/esm/sdk/market/credit/CreditManagerV310Contract.js +2 -13
- package/dist/esm/sdk/market/credit/CreditSuite.js +29 -10
- package/dist/esm/sdk/market/credit/index.js +2 -1
- package/dist/esm/sdk/market/credit/isStrategyCollateral.js +48 -0
- package/dist/esm/sdk/market/index.js +3 -1
- package/dist/esm/sdk/market/math.js +60 -41
- package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +10 -3
- package/dist/esm/sdk/market/pool/PoolV310Contract.js +16 -2
- package/dist/esm/sdk/market/rwa/RWARegistry.js +22 -0
- package/dist/esm/sdk/opportunities/index.js +1 -2
- package/dist/esm/sdk/options.js +1 -5
- package/dist/esm/sdk/pools/PoolService.js +133 -6
- package/dist/esm/sdk/pools/index.js +2 -2
- package/dist/esm/sdk/positions/PositionsService.js +218 -1
- package/dist/esm/sdk/positions/calcBorrowRate.js +42 -0
- package/dist/esm/sdk/positions/calcHealthFactor.js +51 -0
- package/dist/esm/sdk/positions/calcLiquidationPrice.js +22 -0
- package/dist/esm/sdk/positions/calcLiquidationPriceForTarget.js +29 -0
- package/dist/esm/sdk/positions/calcTimeToLiquidationMs.js +18 -0
- package/dist/esm/sdk/positions/index.js +7 -2
- package/dist/esm/sdk/positions/types.js +31 -1
- package/dist/esm/sdk/utils/abi-decode.js +2 -2
- package/dist/esm/sdk/utils/viem/executeMulticallBatches.js +31 -0
- package/dist/esm/sdk/utils/viem/index.js +2 -1
- package/dist/types/abi/iExpirable.d.ts +14 -0
- package/dist/types/common-utils/utils/apy/get-single-quota-borrow-rate.d.ts +2 -0
- package/dist/types/common-utils/utils/creditAccount/calc-health-factor.d.ts +3 -0
- package/dist/types/common-utils/utils/creditAccount/calc-quota-borrow-rate.d.ts +2 -0
- package/dist/types/common-utils/utils/creditAccount/get-time-to-liquidation.d.ts +6 -1
- package/dist/types/common-utils/utils/creditAccount/liquidation-price.d.ts +3 -0
- package/dist/types/dev/compareOpportunities.d.ts +105 -0
- package/dist/types/dev/comparePositions.d.ts +149 -0
- package/dist/types/dev/fieldDiff.d.ts +167 -0
- package/dist/types/model/charts.d.ts +349 -0
- package/dist/types/model/charts.schema.d.ts +364 -0
- package/dist/types/model/index.d.ts +8 -6
- package/dist/types/model/notices.d.ts +29 -0
- package/dist/types/model/notices.schema.d.ts +23 -0
- package/dist/types/model/opportunities.d.ts +9 -9
- package/dist/types/model/positions.d.ts +133 -7
- package/dist/types/model/positions.schema.d.ts +128 -1
- package/dist/types/new-sdk/AbstractNamespace.d.ts +15 -2
- package/dist/types/new-sdk/GearboxSDK.d.ts +14 -2
- package/dist/types/new-sdk/execute/ExecuteApi.d.ts +108 -0
- package/dist/types/new-sdk/execute/index.d.ts +2 -0
- package/dist/types/new-sdk/index.d.ts +8 -4
- package/dist/types/new-sdk/opportunities/OpportunitiesNamespace.d.ts +19 -7
- package/dist/types/new-sdk/opportunities/types.d.ts +30 -9
- package/dist/types/new-sdk/positions/PositionsNamespace.d.ts +4 -5
- package/dist/types/new-sdk/positions/types.d.ts +9 -9
- package/dist/types/new-sdk/simulate/SimulateApi.d.ts +90 -0
- package/dist/types/new-sdk/simulate/index.d.ts +3 -0
- package/dist/types/new-sdk/simulate/types.d.ts +508 -0
- package/dist/types/new-sdk/types.d.ts +35 -1
- package/dist/types/new-sdk/utils/index.d.ts +1 -2
- package/dist/types/offchain/AbstractOffchainNamespace.d.ts +5 -21
- package/dist/types/offchain/GearboxAPI.d.ts +6 -0
- package/dist/types/offchain/index.d.ts +4 -2
- package/dist/types/offchain/notices/OffchainNotices.d.ts +19 -0
- package/dist/types/offchain/notices/index.d.ts +2 -0
- package/dist/types/offchain/opportunities/OffchainOpportunities.d.ts +8 -4
- package/dist/types/offchain/positions/OffchainPositions.d.ts +8 -6
- package/dist/types/preview/preview/CreditAccountState.d.ts +6 -0
- package/dist/types/preview/preview/buildDelayedPreview.d.ts +5 -1
- package/dist/types/preview/preview/types.d.ts +4 -2
- package/dist/types/sdk/MultichainSDK.d.ts +0 -5
- package/dist/types/sdk/OnchainSDK.d.ts +1 -5
- package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +1 -7
- package/dist/types/sdk/accounts/credit-account-compressor/CreditAccountCompressor.d.ts +3 -12
- package/dist/types/sdk/accounts/credit-account-compressor/index.d.ts +2 -2
- package/dist/types/sdk/accounts/credit-account-compressor/types.d.ts +1 -19
- package/dist/types/sdk/accounts/index.d.ts +7 -5
- package/dist/types/sdk/accounts/intents/guards.d.ts +72 -0
- package/dist/types/sdk/accounts/intents/index.d.ts +130 -15
- package/dist/types/sdk/accounts/intents/math.d.ts +46 -0
- package/dist/types/sdk/accounts/intents/open-strategy.d.ts +64 -0
- package/dist/types/sdk/accounts/intents/operations.d.ts +215 -0
- package/dist/types/sdk/accounts/intents/plan.d.ts +189 -0
- package/dist/types/sdk/accounts/intents/realize.d.ts +35 -0
- package/dist/types/sdk/accounts/intents/testing/delayed.d.ts +50 -0
- package/dist/types/sdk/accounts/intents/testing/expect.d.ts +17 -21
- package/dist/types/sdk/accounts/intents/testing/market.d.ts +91 -0
- package/dist/types/sdk/accounts/intents/testing/sdk-mock.d.ts +64 -16
- package/dist/types/sdk/accounts/intents/tests/add-collateral.fixtures.d.ts +45 -0
- package/dist/types/sdk/accounts/intents/tests/adjust-leverage.fixtures.d.ts +56 -0
- package/dist/types/sdk/accounts/intents/tests/deposit.fixtures.d.ts +64 -0
- package/dist/types/sdk/accounts/intents/tests/finish-decrease-leverage.fixtures.d.ts +107 -0
- package/dist/types/sdk/accounts/intents/tests/finish-withdraw.fixtures.d.ts +136 -0
- package/dist/types/sdk/accounts/intents/tests/open-strategy.fixtures.d.ts +56 -0
- package/dist/types/sdk/accounts/intents/tests/withdraw-asset.fixtures.d.ts +60 -0
- package/dist/types/sdk/accounts/intents/tests/withdraw.fixtures.d.ts +79 -0
- package/dist/types/sdk/accounts/intents/types.d.ts +369 -43
- package/dist/types/sdk/accounts/intents/utils/adjust-state-to-snapshot.d.ts +13 -0
- package/dist/types/sdk/accounts/intents/utils/assemble-operation-calls.d.ts +1 -1
- package/dist/types/sdk/accounts/intents/utils/credit-account-slice.d.ts +29 -0
- package/dist/types/sdk/accounts/intents/utils/index.d.ts +7 -5
- package/dist/types/sdk/accounts/intents/utils/ledger.d.ts +41 -0
- package/dist/types/sdk/accounts/intents/utils/pick-token.d.ts +55 -0
- package/dist/types/sdk/accounts/intents/utils/quotas-for-update.d.ts +15 -4
- package/dist/types/sdk/accounts/intents/utils/router-path.d.ts +70 -0
- package/dist/types/sdk/accounts/intents/view.d.ts +15 -0
- package/dist/types/sdk/accounts/types.d.ts +17 -14
- package/dist/types/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.d.ts +6 -0
- package/dist/types/sdk/accounts/withdrawal-compressor/types.d.ts +18 -0
- package/dist/types/sdk/base/TokensMeta.d.ts +44 -1
- package/dist/types/sdk/base/index.d.ts +2 -2
- package/dist/types/sdk/base/token-types.d.ts +12 -1
- package/dist/types/sdk/index.d.ts +28 -19
- package/dist/types/sdk/market/MarketRegister.d.ts +7 -3
- package/dist/types/sdk/market/ZapperRegister.d.ts +20 -2
- package/dist/types/sdk/market/credit/CreditManagerV310Contract.d.ts +0 -4
- package/dist/types/sdk/market/credit/CreditSuite.d.ts +6 -3
- package/dist/types/sdk/market/credit/index.d.ts +2 -1
- package/dist/types/sdk/market/credit/isStrategyCollateral.d.ts +74 -0
- package/dist/types/sdk/market/credit/types.d.ts +2 -9
- package/dist/types/sdk/market/index.d.ts +4 -2
- package/dist/types/sdk/market/math.d.ts +46 -34
- package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +6 -2
- package/dist/types/sdk/market/oracle/types.d.ts +10 -2
- package/dist/types/sdk/market/pool/PoolV310Contract.d.ts +5 -0
- package/dist/types/sdk/market/pool/types.d.ts +5 -0
- package/dist/types/sdk/market/rwa/RWARegistry.d.ts +13 -0
- package/dist/types/sdk/market/types.d.ts +5 -1
- package/dist/types/sdk/opportunities/index.d.ts +1 -2
- package/dist/types/sdk/options.d.ts +0 -1
- package/dist/types/sdk/pools/PoolService.d.ts +32 -2
- package/dist/types/sdk/pools/index.d.ts +3 -3
- package/dist/types/sdk/pools/types.d.ts +109 -4
- package/dist/types/sdk/positions/PositionsService.d.ts +33 -2
- package/dist/types/sdk/positions/calcBorrowRate.d.ts +40 -0
- package/dist/types/sdk/positions/calcHealthFactor.d.ts +55 -0
- package/dist/types/sdk/positions/calcLiquidationPrice.d.ts +12 -0
- package/dist/types/sdk/positions/calcLiquidationPriceForTarget.d.ts +43 -0
- package/dist/types/sdk/positions/calcTimeToLiquidationMs.d.ts +16 -0
- package/dist/types/sdk/positions/index.d.ts +7 -2
- package/dist/types/sdk/positions/types.d.ts +58 -1
- package/dist/types/sdk/types/state.d.ts +6 -0
- package/dist/types/sdk/utils/viem/executeMulticallBatches.d.ts +39 -0
- package/dist/types/sdk/utils/viem/index.d.ts +3 -2
- package/package.json +2 -1
- package/dist/cjs/model/history.js +0 -53
- package/dist/cjs/model/history.schema.js +0 -128
- package/dist/cjs/sdk/accounts/intents/intents/index.js +0 -14
- package/dist/cjs/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.fixtures.js +0 -121
- package/dist/cjs/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.js +0 -15
- package/dist/cjs/sdk/accounts/intents/intents/resume/close/close.fixtures.js +0 -108
- package/dist/cjs/sdk/accounts/intents/intents/resume/close/close.js +0 -51
- package/dist/cjs/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.fixtures.js +0 -130
- package/dist/cjs/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.js +0 -83
- package/dist/cjs/sdk/accounts/intents/intents/resume/deposit/deposit.fixtures.js +0 -117
- package/dist/cjs/sdk/accounts/intents/intents/resume/deposit/deposit.js +0 -15
- package/dist/cjs/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.fixtures.js +0 -95
- package/dist/cjs/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.js +0 -15
- package/dist/cjs/sdk/accounts/intents/intents/resume/index.js +0 -13
- package/dist/cjs/sdk/accounts/intents/intents/resume/withdraw/withdraw.fixtures.js +0 -138
- package/dist/cjs/sdk/accounts/intents/intents/resume/withdraw/withdraw.js +0 -161
- package/dist/cjs/sdk/accounts/intents/operations/add-collateral/index.js +0 -17
- package/dist/cjs/sdk/accounts/intents/operations/claim-delayed/index.js +0 -54
- package/dist/cjs/sdk/accounts/intents/operations/close-credit-account/index.js +0 -26
- package/dist/cjs/sdk/accounts/intents/operations/decrease-debt/index.js +0 -12
- package/dist/cjs/sdk/accounts/intents/operations/increase-debt/index.js +0 -12
- package/dist/cjs/sdk/accounts/intents/operations/index.js +0 -27
- package/dist/cjs/sdk/accounts/intents/operations/quota-update/index.js +0 -22
- package/dist/cjs/sdk/accounts/intents/operations/repay-credit-account/index.js +0 -22
- package/dist/cjs/sdk/accounts/intents/operations/start-delayed-withdrawal/index.js +0 -18
- package/dist/cjs/sdk/accounts/intents/operations/swap/index.js +0 -18
- package/dist/cjs/sdk/accounts/intents/operations/unwrap-rwa-collateral/index.js +0 -27
- package/dist/cjs/sdk/accounts/intents/operations/withdraw-collateral/index.js +0 -43
- package/dist/cjs/sdk/accounts/intents/operations/wrap-rwa-collateral/index.js +0 -27
- package/dist/cjs/sdk/accounts/intents/quoters/close.js +0 -58
- package/dist/cjs/sdk/accounts/intents/quoters/index.js +0 -7
- package/dist/cjs/sdk/accounts/intents/quoters/swap.js +0 -79
- package/dist/cjs/sdk/accounts/intents/testing/expect.js +0 -167
- package/dist/cjs/sdk/accounts/intents/testing/resume.js +0 -172
- package/dist/cjs/sdk/accounts/intents/utils/simulate-adjust-state.js +0 -39
- package/dist/cjs/sdk/accounts/intents/utils/simulate-assets.js +0 -69
- package/dist/cjs/sdk/accounts/intents/utils/with-quota-update.js +0 -13
- package/dist/esm/model/history.js +0 -49
- package/dist/esm/model/history.schema.js +0 -116
- package/dist/esm/sdk/accounts/intents/intents/index.js +0 -8
- package/dist/esm/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.fixtures.js +0 -107
- package/dist/esm/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.js +0 -14
- package/dist/esm/sdk/accounts/intents/intents/resume/close/close.fixtures.js +0 -94
- package/dist/esm/sdk/accounts/intents/intents/resume/close/close.js +0 -50
- package/dist/esm/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.fixtures.js +0 -114
- package/dist/esm/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.js +0 -82
- package/dist/esm/sdk/accounts/intents/intents/resume/deposit/deposit.fixtures.js +0 -110
- package/dist/esm/sdk/accounts/intents/intents/resume/deposit/deposit.js +0 -14
- package/dist/esm/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.fixtures.js +0 -88
- package/dist/esm/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.js +0 -14
- package/dist/esm/sdk/accounts/intents/intents/resume/index.js +0 -7
- package/dist/esm/sdk/accounts/intents/intents/resume/withdraw/withdraw.fixtures.js +0 -121
- package/dist/esm/sdk/accounts/intents/intents/resume/withdraw/withdraw.js +0 -160
- package/dist/esm/sdk/accounts/intents/operations/add-collateral/index.js +0 -16
- package/dist/esm/sdk/accounts/intents/operations/claim-delayed/index.js +0 -52
- package/dist/esm/sdk/accounts/intents/operations/close-credit-account/index.js +0 -25
- package/dist/esm/sdk/accounts/intents/operations/decrease-debt/index.js +0 -11
- package/dist/esm/sdk/accounts/intents/operations/increase-debt/index.js +0 -11
- package/dist/esm/sdk/accounts/intents/operations/index.js +0 -14
- package/dist/esm/sdk/accounts/intents/operations/quota-update/index.js +0 -21
- package/dist/esm/sdk/accounts/intents/operations/repay-credit-account/index.js +0 -21
- package/dist/esm/sdk/accounts/intents/operations/start-delayed-withdrawal/index.js +0 -17
- package/dist/esm/sdk/accounts/intents/operations/swap/index.js +0 -17
- package/dist/esm/sdk/accounts/intents/operations/unwrap-rwa-collateral/index.js +0 -26
- package/dist/esm/sdk/accounts/intents/operations/withdraw-collateral/index.js +0 -42
- package/dist/esm/sdk/accounts/intents/operations/wrap-rwa-collateral/index.js +0 -26
- package/dist/esm/sdk/accounts/intents/quoters/close.js +0 -56
- package/dist/esm/sdk/accounts/intents/quoters/index.js +0 -3
- package/dist/esm/sdk/accounts/intents/quoters/swap.js +0 -77
- package/dist/esm/sdk/accounts/intents/testing/expect.js +0 -162
- package/dist/esm/sdk/accounts/intents/testing/resume.js +0 -157
- package/dist/esm/sdk/accounts/intents/utils/simulate-adjust-state.js +0 -38
- package/dist/esm/sdk/accounts/intents/utils/simulate-assets.js +0 -68
- package/dist/esm/sdk/accounts/intents/utils/with-quota-update.js +0 -12
- package/dist/types/model/history.d.ts +0 -153
- package/dist/types/model/history.schema.d.ts +0 -95
- package/dist/types/new-sdk/utils/history.d.ts +0 -18
- package/dist/types/sdk/accounts/intents/intents/index.d.ts +0 -8
- package/dist/types/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.d.ts +0 -13
- package/dist/types/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.fixtures.d.ts +0 -38
- package/dist/types/sdk/accounts/intents/intents/resume/close/close.d.ts +0 -26
- package/dist/types/sdk/accounts/intents/intents/resume/close/close.fixtures.d.ts +0 -63
- package/dist/types/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.d.ts +0 -26
- package/dist/types/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.fixtures.d.ts +0 -86
- package/dist/types/sdk/accounts/intents/intents/resume/deposit/deposit.d.ts +0 -13
- package/dist/types/sdk/accounts/intents/intents/resume/deposit/deposit.fixtures.d.ts +0 -48
- package/dist/types/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.d.ts +0 -13
- package/dist/types/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.fixtures.d.ts +0 -46
- package/dist/types/sdk/accounts/intents/intents/resume/index.d.ts +0 -7
- package/dist/types/sdk/accounts/intents/intents/resume/withdraw/withdraw.d.ts +0 -33
- package/dist/types/sdk/accounts/intents/intents/resume/withdraw/withdraw.fixtures.d.ts +0 -68
- package/dist/types/sdk/accounts/intents/operations/add-collateral/index.d.ts +0 -23
- package/dist/types/sdk/accounts/intents/operations/claim-delayed/index.d.ts +0 -55
- package/dist/types/sdk/accounts/intents/operations/close-credit-account/index.d.ts +0 -22
- package/dist/types/sdk/accounts/intents/operations/decrease-debt/index.d.ts +0 -18
- package/dist/types/sdk/accounts/intents/operations/increase-debt/index.d.ts +0 -18
- package/dist/types/sdk/accounts/intents/operations/index.d.ts +0 -14
- package/dist/types/sdk/accounts/intents/operations/quota-update/index.d.ts +0 -24
- package/dist/types/sdk/accounts/intents/operations/repay-credit-account/index.d.ts +0 -31
- package/dist/types/sdk/accounts/intents/operations/start-delayed-withdrawal/index.d.ts +0 -23
- package/dist/types/sdk/accounts/intents/operations/swap/index.d.ts +0 -28
- package/dist/types/sdk/accounts/intents/operations/types.d.ts +0 -21
- package/dist/types/sdk/accounts/intents/operations/unwrap-rwa-collateral/index.d.ts +0 -30
- package/dist/types/sdk/accounts/intents/operations/withdraw-collateral/index.d.ts +0 -36
- package/dist/types/sdk/accounts/intents/operations/wrap-rwa-collateral/index.d.ts +0 -30
- package/dist/types/sdk/accounts/intents/quoters/close.d.ts +0 -43
- package/dist/types/sdk/accounts/intents/quoters/index.d.ts +0 -3
- package/dist/types/sdk/accounts/intents/quoters/swap.d.ts +0 -43
- package/dist/types/sdk/accounts/intents/testing/resume.d.ts +0 -84
- package/dist/types/sdk/accounts/intents/utils/simulate-adjust-state.d.ts +0 -19
- package/dist/types/sdk/accounts/intents/utils/simulate-assets.d.ts +0 -21
- package/dist/types/sdk/accounts/intents/utils/with-quota-update.d.ts +0 -16
- /package/dist/cjs/{new-sdk/utils/history.js → model/notices.js} +0 -0
- /package/dist/cjs/{sdk/accounts/intents/operations → new-sdk/simulate}/types.js +0 -0
- /package/dist/esm/{new-sdk/utils/history.js → model/notices.js} +0 -0
- /package/dist/esm/{sdk/accounts/intents/operations → new-sdk/simulate}/types.js +0 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//#region src/sdk/utils/viem/executeMulticallBatches.ts
|
|
2
|
+
/**
|
|
3
|
+
* Executes the calls of several {@link MulticallBatch}es as a single multicall
|
|
4
|
+
* aggregate and dispatches each batch its own slice of the results.
|
|
5
|
+
*
|
|
6
|
+
* Failures are allowed per call: loaders in a batch decide themselves how to
|
|
7
|
+
* treat a reverted call (e.g. `contractType()` reverting on a plain ERC-20 is
|
|
8
|
+
* expected). Use {@link executeDelegatedMulticalls} instead when the calls need
|
|
9
|
+
* price updates applied first.
|
|
10
|
+
*
|
|
11
|
+
* @param client - Viem public client.
|
|
12
|
+
* @param batches - Batches to execute together, empty ones are allowed.
|
|
13
|
+
* @param opts - Block number forwarded to the multicall.
|
|
14
|
+
**/
|
|
15
|
+
async function executeMulticallBatches(client, batches, opts = {}) {
|
|
16
|
+
const contracts = batches.flatMap((b) => b.contracts);
|
|
17
|
+
if (!contracts.length) return;
|
|
18
|
+
const results = await client.multicall({
|
|
19
|
+
contracts,
|
|
20
|
+
allowFailure: true,
|
|
21
|
+
batchSize: 0,
|
|
22
|
+
blockNumber: opts.blockNumber
|
|
23
|
+
});
|
|
24
|
+
let offset = 0;
|
|
25
|
+
for (const batch of batches) {
|
|
26
|
+
batch.onResults(results.slice(offset, offset + batch.contracts.length));
|
|
27
|
+
offset += batch.contracts.length;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { executeMulticallBatches };
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { generateCastTraceCall, getCastTraceArgs } from "./cast.js";
|
|
2
2
|
import { SimulationError, simulateCall } from "./simulateCall.js";
|
|
3
|
+
import { executeMulticallBatches } from "./executeMulticallBatches.js";
|
|
3
4
|
import { simulateMulticall } from "./simulateMulticall.js";
|
|
4
5
|
import { SimulateWithPriceUpdatesError, getSimulateWithPriceUpdatesError, simulateWithPriceUpdates } from "./simulateWithPriceUpdates.js";
|
|
5
6
|
import { executeDelegatedMulticalls } from "./executeDelegatedMulticalls.js";
|
|
6
7
|
import { estimateRawTxGas, sendRawTx } from "./sendRawTx.js";
|
|
7
8
|
import { watchBlocksAsync } from "./watchBlocksAsync.js";
|
|
8
|
-
export { SimulateWithPriceUpdatesError, SimulationError, estimateRawTxGas, executeDelegatedMulticalls, generateCastTraceCall, getCastTraceArgs, getSimulateWithPriceUpdatesError, sendRawTx, simulateCall, simulateMulticall, simulateWithPriceUpdates, watchBlocksAsync };
|
|
9
|
+
export { SimulateWithPriceUpdatesError, SimulationError, estimateRawTxGas, executeDelegatedMulticalls, executeMulticallBatches, generateCastTraceCall, getCastTraceArgs, getSimulateWithPriceUpdatesError, sendRawTx, simulateCall, simulateMulticall, simulateWithPriceUpdates, watchBlocksAsync };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/abi/iExpirable.d.ts
|
|
2
|
+
declare const iExpirableAbi: readonly [{
|
|
3
|
+
readonly type: "function";
|
|
4
|
+
readonly inputs: readonly [];
|
|
5
|
+
readonly name: "isExpired";
|
|
6
|
+
readonly outputs: readonly [{
|
|
7
|
+
readonly name: "";
|
|
8
|
+
readonly internalType: "bool";
|
|
9
|
+
readonly type: "bool";
|
|
10
|
+
}];
|
|
11
|
+
readonly stateMutability: "view";
|
|
12
|
+
}];
|
|
13
|
+
//#endregion
|
|
14
|
+
export { iExpirableAbi };
|
|
@@ -6,6 +6,8 @@ interface GetSingleQuotaBorrowRateRate extends CalcQuotaBorrowRateProps {
|
|
|
6
6
|
/**
|
|
7
7
|
* Under the hood sums up rates for all given quotas and then multiplies them by 1+feeInterest,
|
|
8
8
|
* but it is expected that the ONLY quota will be passed
|
|
9
|
+
*
|
|
10
|
+
* @deprecated Use `calcBorrowRate` from `sdk/positions` instead.
|
|
9
11
|
*/
|
|
10
12
|
declare function getSingleQuotaBorrowRate(props: GetSingleQuotaBorrowRateRate): bigint;
|
|
11
13
|
//#endregion
|
|
@@ -23,6 +23,9 @@ interface CalcHealthFactorProps {
|
|
|
23
23
|
* @param props Credit account balances, quotas, prices, thresholds, and debt context.
|
|
24
24
|
* @returns Health factor as a number in `PERCENTAGE_FACTOR` scale,
|
|
25
25
|
* or `65535` when debt is zero.
|
|
26
|
+
*
|
|
27
|
+
* @deprecated Use `calcHealthFactor` from `sdk/positions` instead; this
|
|
28
|
+
* wrapper only maps the legacy props onto an `AccountSnapshot`.
|
|
26
29
|
*/
|
|
27
30
|
declare function calcHealthFactor({ assets, quotas, quotasInfo, liquidationThresholds, underlyingToken, debt, prices, tokensList }: CalcHealthFactorProps): number;
|
|
28
31
|
//#endregion
|
|
@@ -16,6 +16,8 @@ interface CalcQuotaBorrowRateProps {
|
|
|
16
16
|
*
|
|
17
17
|
* @param props Quota balances and per-token quota rates.
|
|
18
18
|
* @returns Sum of `balance * rate` terms in percentage-factor scale.
|
|
19
|
+
*
|
|
20
|
+
* @deprecated Use `calcBorrowRate` from `sdk/positions` instead.
|
|
19
21
|
*/
|
|
20
22
|
declare function calcQuotaBorrowRate({ quotas, quotaRates }: CalcQuotaBorrowRateProps): bigint;
|
|
21
23
|
//#endregion
|
|
@@ -10,9 +10,14 @@ interface TimeToLiquidationProps {
|
|
|
10
10
|
* and returns a millisecond duration until `healthFactor` decays to `1.0`
|
|
11
11
|
* (`PERCENTAGE_FACTOR` in internal scale).
|
|
12
12
|
*
|
|
13
|
-
* @param props Current health factor and `
|
|
13
|
+
* @param props Current health factor and `totalBorrowRate_debt`, both `Bps`
|
|
14
|
+
* (`10000` = 100%) — not the legacy `PERCENTAGE_FACTOR_1KK` (`1_000_000` =
|
|
15
|
+
* 100%) scale the pre-rewrite frontend fed this under the same name.
|
|
14
16
|
* @returns Milliseconds to liquidation as `bigint`, or `null` when already at/under
|
|
15
17
|
* liquidation threshold or when borrow-rate exposure is zero.
|
|
18
|
+
*
|
|
19
|
+
* @deprecated Use `calcTimeToLiquidationMs` from `sdk/positions` instead;
|
|
20
|
+
* this wrapper only forwards to the new implementation.
|
|
16
21
|
*/
|
|
17
22
|
declare function getTimeToLiquidation({ healthFactor, totalBorrowRate_debt }: TimeToLiquidationProps): bigint | null;
|
|
18
23
|
//#endregion
|
|
@@ -22,6 +22,9 @@ interface LiquidationPriceProps {
|
|
|
22
22
|
* @param props Debt context, assets, thresholds, and token metadata.
|
|
23
23
|
* @returns Target token price in `PRICE_DECIMALS` precision that corresponds
|
|
24
24
|
* to liquidation boundary; returns `0n` when target balance or LT is non-positive.
|
|
25
|
+
*
|
|
26
|
+
* @deprecated Use `calcLiquidationPriceForTarget` from `sdk/positions`
|
|
27
|
+
* instead; this wrapper only maps the legacy props onto an `AccountSnapshot`.
|
|
25
28
|
*/
|
|
26
29
|
declare function liquidationPrice({ liquidationThresholds, debt, underlyingToken, targetToken, assets, tokensList }: LiquidationPriceProps): bigint;
|
|
27
30
|
//#endregion
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { ChainId } from "../model/primitives.js";
|
|
2
|
+
import { Opportunity, OpportunityId, OpportunityKind } from "../model/opportunities.js";
|
|
3
|
+
import { ChainMetadata, DataResponse } from "../model/response.js";
|
|
4
|
+
import "../model/index.js";
|
|
5
|
+
import { ChainCompareCounts, CompareCounts, DiffKind, DiffPathCount, ExpectedDiffReason, FieldDiff } from "./fieldDiff.js";
|
|
6
|
+
import { Address } from "viem";
|
|
7
|
+
//#region src/dev/compareOpportunities.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* Enough of an opportunity to identify it in a report without carrying the
|
|
10
|
+
* whole row.
|
|
11
|
+
**/
|
|
12
|
+
interface OpportunityRef {
|
|
13
|
+
id: OpportunityId;
|
|
14
|
+
kind: OpportunityKind;
|
|
15
|
+
chainId: ChainId;
|
|
16
|
+
name: string;
|
|
17
|
+
/**
|
|
18
|
+
* Set on a pool opportunity.
|
|
19
|
+
**/
|
|
20
|
+
pool?: Address;
|
|
21
|
+
/**
|
|
22
|
+
* Set on a strategy opportunity, together with {@link targetCollateral}.
|
|
23
|
+
**/
|
|
24
|
+
creditManager?: Address;
|
|
25
|
+
targetCollateral?: Address;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* One opportunity both sources listed, and everything they disagree on.
|
|
29
|
+
**/
|
|
30
|
+
interface OpportunityMatch {
|
|
31
|
+
id: OpportunityId;
|
|
32
|
+
kind: OpportunityKind;
|
|
33
|
+
chainId: ChainId;
|
|
34
|
+
/**
|
|
35
|
+
* Name each source gave the row, which is itself a frequent diff.
|
|
36
|
+
**/
|
|
37
|
+
onchainName: string;
|
|
38
|
+
offchainName: string;
|
|
39
|
+
/**
|
|
40
|
+
* No diffs at all, including the documented offchain-only ones.
|
|
41
|
+
**/
|
|
42
|
+
identical: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* No unexpected diffs: every disagreement is mode-scoped or within tolerance.
|
|
45
|
+
**/
|
|
46
|
+
clean: boolean;
|
|
47
|
+
diffs: FieldDiff[];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Totals of the comparison plus the fields that differed most often.
|
|
51
|
+
**/
|
|
52
|
+
interface CompareSummary extends CompareCounts {
|
|
53
|
+
byChain: ChainCompareCounts[];
|
|
54
|
+
diffsByPath: DiffPathCount[];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Everything one comparison run produced, ready to be written out as JSON.
|
|
58
|
+
**/
|
|
59
|
+
interface OpportunityCompareReport {
|
|
60
|
+
generatedAt: string;
|
|
61
|
+
backendUrl: string;
|
|
62
|
+
networks: string[];
|
|
63
|
+
/**
|
|
64
|
+
* Per-chain metadata of the on-chain read, which says which block each chain
|
|
65
|
+
* answered from.
|
|
66
|
+
**/
|
|
67
|
+
onchainChains: ChainMetadata[];
|
|
68
|
+
/**
|
|
69
|
+
* Per-chain metadata of the backend read, see {@link onchainChains}.
|
|
70
|
+
**/
|
|
71
|
+
offchainChains: ChainMetadata[];
|
|
72
|
+
summary: CompareSummary;
|
|
73
|
+
onlyOnchain: OpportunityRef[];
|
|
74
|
+
onlyOffchain: OpportunityRef[];
|
|
75
|
+
matched: OpportunityMatch[];
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The two listings to compare, plus what the run was pointed at.
|
|
79
|
+
**/
|
|
80
|
+
interface CompareOpportunitiesInput {
|
|
81
|
+
onchain: DataResponse<Opportunity[]>;
|
|
82
|
+
offchain: DataResponse<Opportunity[]>;
|
|
83
|
+
backendUrl: string;
|
|
84
|
+
networks: string[];
|
|
85
|
+
/**
|
|
86
|
+
* ISO timestamp stamped onto the report, defaulting to now. Pinned by tests.
|
|
87
|
+
**/
|
|
88
|
+
generatedAt?: string;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Matches two opportunity listings by {@link opportunityId} and reports every
|
|
92
|
+
* field the two sources disagree on.
|
|
93
|
+
*
|
|
94
|
+
* Nothing is filtered out. A field only the backend can fill, or a USD value
|
|
95
|
+
* that drifted within snapshot-lag noise, is still reported — tagged
|
|
96
|
+
* {@link FieldDiff.expected} so that {@link CompareCounts.clean} can ignore it
|
|
97
|
+
* while {@link CompareCounts.identical} stays strict.
|
|
98
|
+
**/
|
|
99
|
+
declare function compareOpportunities(input: CompareOpportunitiesInput): OpportunityCompareReport;
|
|
100
|
+
/**
|
|
101
|
+
* Every field two versions of one opportunity disagree on.
|
|
102
|
+
**/
|
|
103
|
+
declare function diffOpportunity(onchain: Opportunity, offchain: Opportunity): FieldDiff[];
|
|
104
|
+
//#endregion
|
|
105
|
+
export { type ChainCompareCounts, type CompareCounts, CompareOpportunitiesInput, CompareSummary, type DiffKind, type DiffPathCount, type ExpectedDiffReason, type FieldDiff, OpportunityCompareReport, OpportunityMatch, OpportunityRef, compareOpportunities, diffOpportunity };
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { ChainId } from "../model/primitives.js";
|
|
2
|
+
import { Position, PositionId, PositionKind } from "../model/positions.js";
|
|
3
|
+
import { ChainMetadata, DataResponse } from "../model/response.js";
|
|
4
|
+
import "../model/index.js";
|
|
5
|
+
import { ChainCompareCounts, CompareCounts, DiffPathCount, FieldDiff } from "./fieldDiff.js";
|
|
6
|
+
import { Address } from "viem";
|
|
7
|
+
//#region src/dev/comparePositions.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* Enough of a position to identify it in a report without carrying the whole
|
|
10
|
+
* row.
|
|
11
|
+
**/
|
|
12
|
+
interface PositionRef {
|
|
13
|
+
id: PositionId;
|
|
14
|
+
kind: PositionKind;
|
|
15
|
+
chainId: ChainId;
|
|
16
|
+
name: string;
|
|
17
|
+
/**
|
|
18
|
+
* Set on a pool position.
|
|
19
|
+
**/
|
|
20
|
+
pool?: Address;
|
|
21
|
+
/**
|
|
22
|
+
* Set on a strategy position.
|
|
23
|
+
**/
|
|
24
|
+
creditAccount?: Address;
|
|
25
|
+
creditManager?: Address;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* One position both sources listed for a wallet, and everything they disagree
|
|
29
|
+
* on.
|
|
30
|
+
**/
|
|
31
|
+
interface PositionMatch {
|
|
32
|
+
id: PositionId;
|
|
33
|
+
kind: PositionKind;
|
|
34
|
+
chainId: ChainId;
|
|
35
|
+
onchainName: string;
|
|
36
|
+
offchainName: string;
|
|
37
|
+
/**
|
|
38
|
+
* No diffs at all, including the documented mode-scoped ones.
|
|
39
|
+
**/
|
|
40
|
+
identical: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* No unexpected diffs: every disagreement is mode-scoped or within tolerance.
|
|
43
|
+
**/
|
|
44
|
+
clean: boolean;
|
|
45
|
+
diffs: FieldDiff[];
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* One wallet's comparison, or the error that stopped it.
|
|
49
|
+
**/
|
|
50
|
+
interface WalletComparison {
|
|
51
|
+
wallet: Address;
|
|
52
|
+
/**
|
|
53
|
+
* Why both listings of this wallet could not be read. When set, the rest of
|
|
54
|
+
* the fields are empty.
|
|
55
|
+
**/
|
|
56
|
+
error?: string;
|
|
57
|
+
onlyOnchain: PositionRef[];
|
|
58
|
+
onlyOffchain: PositionRef[];
|
|
59
|
+
matched: PositionMatch[];
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Counts of one wallet.
|
|
63
|
+
**/
|
|
64
|
+
interface WalletCompareCounts extends CompareCounts {
|
|
65
|
+
wallet: Address;
|
|
66
|
+
/**
|
|
67
|
+
* Present when the wallet's listings could not be read.
|
|
68
|
+
**/
|
|
69
|
+
error?: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Totals of the comparison plus the fields that differed most often.
|
|
73
|
+
**/
|
|
74
|
+
interface PositionsCompareSummary extends CompareCounts {
|
|
75
|
+
wallets: number;
|
|
76
|
+
/**
|
|
77
|
+
* Wallets whose listings were read and that have no membership gaps and no
|
|
78
|
+
* unexpected field diffs.
|
|
79
|
+
**/
|
|
80
|
+
walletsClean: number;
|
|
81
|
+
walletsFailed: number;
|
|
82
|
+
byChain: ChainCompareCounts[];
|
|
83
|
+
byWallet: WalletCompareCounts[];
|
|
84
|
+
diffsByPath: DiffPathCount[];
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Everything one comparison run produced, ready to be written out as JSON.
|
|
88
|
+
**/
|
|
89
|
+
interface PositionsCompareReport {
|
|
90
|
+
generatedAt: string;
|
|
91
|
+
backendUrl: string;
|
|
92
|
+
networks: string[];
|
|
93
|
+
/**
|
|
94
|
+
* Per-chain metadata collected from the on-chain reads, which says which
|
|
95
|
+
* block each chain answered from. Taken from the first successful wallet
|
|
96
|
+
* listing of each chain.
|
|
97
|
+
**/
|
|
98
|
+
onchainChains: ChainMetadata[];
|
|
99
|
+
/**
|
|
100
|
+
* Per-chain metadata of the backend reads, see {@link onchainChains}.
|
|
101
|
+
**/
|
|
102
|
+
offchainChains: ChainMetadata[];
|
|
103
|
+
summary: PositionsCompareSummary;
|
|
104
|
+
wallets: WalletComparison[];
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Both listings of one wallet.
|
|
108
|
+
**/
|
|
109
|
+
interface WalletPositions {
|
|
110
|
+
wallet: Address;
|
|
111
|
+
onchain: DataResponse<Position[]>;
|
|
112
|
+
offchain: DataResponse<Position[]>;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* A wallet whose listings could not be read from one or both sources.
|
|
116
|
+
**/
|
|
117
|
+
interface WalletPositionsFailure {
|
|
118
|
+
wallet: Address;
|
|
119
|
+
error: string;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The per-wallet listings to compare, plus what the run was pointed at.
|
|
123
|
+
**/
|
|
124
|
+
interface ComparePositionsInput {
|
|
125
|
+
wallets: WalletPositions[];
|
|
126
|
+
failures?: WalletPositionsFailure[];
|
|
127
|
+
backendUrl: string;
|
|
128
|
+
networks: string[];
|
|
129
|
+
/**
|
|
130
|
+
* ISO timestamp stamped onto the report, defaulting to now. Pinned by tests.
|
|
131
|
+
**/
|
|
132
|
+
generatedAt?: string;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Matches two position listings per wallet by {@link positionId} and reports
|
|
136
|
+
* every field the two sources disagree on.
|
|
137
|
+
*
|
|
138
|
+
* Nothing is filtered out. A field only one mode can fill, or a USD value that
|
|
139
|
+
* drifted within snapshot-lag noise, is still reported — tagged
|
|
140
|
+
* {@link FieldDiff.expected} so that {@link CompareCounts.clean} can ignore it
|
|
141
|
+
* while {@link CompareCounts.identical} stays strict.
|
|
142
|
+
**/
|
|
143
|
+
declare function comparePositions(input: ComparePositionsInput): PositionsCompareReport;
|
|
144
|
+
/**
|
|
145
|
+
* Every field two versions of one position disagree on.
|
|
146
|
+
**/
|
|
147
|
+
declare function diffPosition(onchain: Position, offchain: Position): FieldDiff[];
|
|
148
|
+
//#endregion
|
|
149
|
+
export { ComparePositionsInput, PositionMatch, PositionRef, PositionsCompareReport, PositionsCompareSummary, WalletCompareCounts, WalletComparison, WalletPositions, WalletPositionsFailure, comparePositions, diffPosition };
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { ChainId } from "../model/primitives.js";
|
|
2
|
+
import "../model/index.js";
|
|
3
|
+
//#region src/dev/fieldDiff.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* What kind of disagreement a {@link FieldDiff} describes, so that a reader can
|
|
6
|
+
* bucket the report without re-deriving it from the values.
|
|
7
|
+
*
|
|
8
|
+
* - `"presence"` — one side has no value at all (`undefined` or `null`).
|
|
9
|
+
* - `"usd"` — an {@link Amount.valueUsd}, i.e. a price-derived float.
|
|
10
|
+
* - `"numeric"` — any other number or bigint.
|
|
11
|
+
* - `"other"` — everything else: strings, booleans, array shapes.
|
|
12
|
+
**/
|
|
13
|
+
type DiffKind = "presence" | "usd" | "numeric" | "other";
|
|
14
|
+
/**
|
|
15
|
+
* Why a {@link FieldDiff} is expected rather than a real disagreement.
|
|
16
|
+
*
|
|
17
|
+
* - `"mode-scoped"` — a field documented `@mode offchain` or `@mode onchain`,
|
|
18
|
+
* so the other source has nothing to put there.
|
|
19
|
+
* - `"tolerance"` — snapshot lag or float-path noise within the thresholds
|
|
20
|
+
* below, not a formula or membership mismatch.
|
|
21
|
+
**/
|
|
22
|
+
type ExpectedDiffReason = "mode-scoped" | "tolerance";
|
|
23
|
+
/**
|
|
24
|
+
* One field of one row where the two sources disagree.
|
|
25
|
+
**/
|
|
26
|
+
interface FieldDiff {
|
|
27
|
+
/**
|
|
28
|
+
* Dotted path into the row, with array elements keyed by their own identity
|
|
29
|
+
* rather than by index, e.g. `collateralTokens[0xa0b8...].symbol`.
|
|
30
|
+
**/
|
|
31
|
+
path: string;
|
|
32
|
+
/**
|
|
33
|
+
* Value the chain reported, `undefined` when it has no such field.
|
|
34
|
+
**/
|
|
35
|
+
onchain: unknown;
|
|
36
|
+
/**
|
|
37
|
+
* Value the backend reported, see {@link onchain}.
|
|
38
|
+
**/
|
|
39
|
+
offchain: unknown;
|
|
40
|
+
kind: DiffKind;
|
|
41
|
+
/**
|
|
42
|
+
* Present when this disagreement is documented or within snapshot-lag noise,
|
|
43
|
+
* so it does not keep the row from being counted as clean.
|
|
44
|
+
**/
|
|
45
|
+
expected?: true;
|
|
46
|
+
reason?: ExpectedDiffReason;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* How often one field disagreed across all matched rows, with array keys
|
|
50
|
+
* collapsed, e.g. `collateralTokens[].symbol`.
|
|
51
|
+
**/
|
|
52
|
+
interface DiffPathCount {
|
|
53
|
+
path: string;
|
|
54
|
+
kinds: DiffKind[];
|
|
55
|
+
count: number;
|
|
56
|
+
expected: number;
|
|
57
|
+
unexpected: number;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Counts of one chain, one wallet, or of the whole report when those ids are
|
|
61
|
+
* absent.
|
|
62
|
+
**/
|
|
63
|
+
interface CompareCounts {
|
|
64
|
+
onchainRows: number;
|
|
65
|
+
offchainRows: number;
|
|
66
|
+
matched: number;
|
|
67
|
+
identical: number;
|
|
68
|
+
/**
|
|
69
|
+
* Matched rows with no unexpected diffs, including the identical ones.
|
|
70
|
+
**/
|
|
71
|
+
clean: number;
|
|
72
|
+
differing: number;
|
|
73
|
+
onlyOnchain: number;
|
|
74
|
+
onlyOffchain: number;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Counts of one chain.
|
|
78
|
+
**/
|
|
79
|
+
interface ChainCompareCounts extends CompareCounts {
|
|
80
|
+
chainId: ChainId;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Identity of an array element, used so a token present on one side only is
|
|
84
|
+
* reported as such rather than shifting every later element into a diff.
|
|
85
|
+
*
|
|
86
|
+
* Return a string to key the element; `undefined` falls back to the default
|
|
87
|
+
* (`address`, `id`, `token`, or nested `token.address`).
|
|
88
|
+
**/
|
|
89
|
+
type ArrayElementKey = (path: string, value: unknown) => string | undefined;
|
|
90
|
+
/**
|
|
91
|
+
* How to walk two values. Callers that need identity-bearing arrays whose
|
|
92
|
+
* key is not one of the defaults pass {@link DiffOptions.keyOf}.
|
|
93
|
+
**/
|
|
94
|
+
interface DiffOptions {
|
|
95
|
+
keyOf?: ArrayElementKey;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Relative drift allowed on {@link Amount.valueUsd} before a USD float is a
|
|
99
|
+
* real disagreement: 0.1%.
|
|
100
|
+
**/
|
|
101
|
+
declare const USD_RELATIVE_EPSILON = 0.001;
|
|
102
|
+
/**
|
|
103
|
+
* Relative drift allowed on lag-bounded bigint amounts: 0.05%.
|
|
104
|
+
**/
|
|
105
|
+
declare const AMOUNT_RELATIVE_EPSILON = 0.0005;
|
|
106
|
+
/**
|
|
107
|
+
* Absolute drift allowed on bps rates before rounding and a one-block lag are
|
|
108
|
+
* no longer enough to explain it.
|
|
109
|
+
**/
|
|
110
|
+
declare const BPS_ABSOLUTE_EPSILON = 1;
|
|
111
|
+
/**
|
|
112
|
+
* Every field two versions of one value disagree on. Nothing is filtered or
|
|
113
|
+
* tagged: the caller marks expected diffs afterwards.
|
|
114
|
+
**/
|
|
115
|
+
declare function diffValue(path: string, onchain: unknown, offchain: unknown, out: FieldDiff[], options?: DiffOptions): void;
|
|
116
|
+
/**
|
|
117
|
+
* Deep-diff two values and return the disagreements, in path order of
|
|
118
|
+
* discovery.
|
|
119
|
+
**/
|
|
120
|
+
declare function diffObjects(onchain: unknown, offchain: unknown, options?: DiffOptions): FieldDiff[];
|
|
121
|
+
/**
|
|
122
|
+
* Mark a diff expected, so a later `clean` count can ignore it.
|
|
123
|
+
**/
|
|
124
|
+
declare function withExpected(diff: FieldDiff, reason: ExpectedDiffReason): FieldDiff;
|
|
125
|
+
/**
|
|
126
|
+
* How often each field differed, with array keys collapsed so that the same
|
|
127
|
+
* field of a hundred collateral tokens counts as one path. Sorted so the
|
|
128
|
+
* unexpected disagreements come first.
|
|
129
|
+
**/
|
|
130
|
+
declare function countPaths(diffs: Iterable<FieldDiff>): DiffPathCount[];
|
|
131
|
+
/**
|
|
132
|
+
* Collapse `collateralTokens[0xa0b8...].symbol` to `collateralTokens[].symbol`.
|
|
133
|
+
**/
|
|
134
|
+
declare function collapseArrayKeys(path: string): string;
|
|
135
|
+
/**
|
|
136
|
+
* Membership and match totals of one comparison, from already-built lists.
|
|
137
|
+
**/
|
|
138
|
+
declare function toCompareCounts(onchainRows: number, offchainRows: number, onlyOnchain: number, onlyOffchain: number, matched: ReadonlyArray<{
|
|
139
|
+
identical: boolean;
|
|
140
|
+
clean: boolean;
|
|
141
|
+
}>): CompareCounts;
|
|
142
|
+
/**
|
|
143
|
+
* USD floats within {@link USD_RELATIVE_EPSILON}.
|
|
144
|
+
**/
|
|
145
|
+
declare function isUsdWithinTolerance(onchain: unknown, offchain: unknown): boolean;
|
|
146
|
+
/**
|
|
147
|
+
* Bps rates that differ by at most {@link BPS_ABSOLUTE_EPSILON}.
|
|
148
|
+
**/
|
|
149
|
+
declare function isBpsWithinTolerance(onchain: unknown, offchain: unknown): boolean;
|
|
150
|
+
/**
|
|
151
|
+
* Bigint amounts within {@link AMOUNT_RELATIVE_EPSILON}.
|
|
152
|
+
**/
|
|
153
|
+
declare function isAmountWithinTolerance(onchain: unknown, offchain: unknown): boolean;
|
|
154
|
+
/**
|
|
155
|
+
* Finite numbers within a relative epsilon of each other.
|
|
156
|
+
**/
|
|
157
|
+
declare function withinRelative(onchain: number | undefined, offchain: number | undefined, epsilon: number): boolean;
|
|
158
|
+
/**
|
|
159
|
+
* `diff / max(|a|, |b|) <= epsilon`, computed in integer arithmetic so a
|
|
160
|
+
* 1e18-scale amount does not round through `Number`.
|
|
161
|
+
**/
|
|
162
|
+
declare function withinRelativeBigint(onchain: bigint, offchain: bigint, epsilon: number): boolean;
|
|
163
|
+
declare function asFiniteNumber(value: unknown): number | undefined;
|
|
164
|
+
declare function union(left: string[], right: string[]): string[];
|
|
165
|
+
declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
166
|
+
//#endregion
|
|
167
|
+
export { AMOUNT_RELATIVE_EPSILON, ArrayElementKey, BPS_ABSOLUTE_EPSILON, ChainCompareCounts, CompareCounts, DiffKind, DiffOptions, DiffPathCount, ExpectedDiffReason, FieldDiff, USD_RELATIVE_EPSILON, asFiniteNumber, collapseArrayKeys, countPaths, diffObjects, diffValue, isAmountWithinTolerance, isBpsWithinTolerance, isRecord, isUsdWithinTolerance, toCompareCounts, union, withExpected, withinRelative, withinRelativeBigint };
|