@gearbox-protocol/sdk 14.12.0-next.65 → 14.12.0-next.67
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/common-utils/index.js +2 -2
- package/dist/cjs/common-utils/utils/apy/calculate-safe-borrow-rate.js +3 -3
- package/dist/cjs/common-utils/utils/assets-math.js +7 -7
- package/dist/cjs/common-utils/utils/creditAccount/calc-health-factor.js +2 -2
- package/dist/cjs/common-utils/utils/creditAccount/debt.js +2 -2
- package/dist/cjs/common-utils/utils/creditAccount/quota-utils.js +5 -5
- package/dist/cjs/common-utils/utils/index.js +2 -2
- package/dist/cjs/common-utils/utils/strategies/leverage/calculate-max-leverage-factor.js +2 -2
- package/dist/cjs/common-utils/utils/strategies/leverage/calculate-max-strategy-debt.js +5 -5
- package/dist/cjs/common-utils/utils/strategies/strategy-info/calculate-total-points.js +2 -2
- package/dist/cjs/common-utils/utils/strategies/strategy-info/get-cm-you-can-earn.js +2 -2
- package/dist/cjs/common-utils/utils/validation/validate-open-account-pool-status.js +4 -4
- package/dist/cjs/dev/index.js +2 -1
- package/dist/cjs/dev/kycUtils.js +1 -1
- package/dist/cjs/dev/midasUtils.js +104 -0
- package/dist/cjs/model/history.js +28 -0
- package/dist/cjs/model/history.schema.js +84 -0
- package/dist/cjs/model/index.js +64 -0
- package/dist/cjs/model/liquidations.js +23 -0
- package/dist/cjs/model/liquidations.schema.js +91 -0
- package/dist/cjs/model/opportunities.js +55 -0
- package/dist/cjs/model/opportunities.schema.js +220 -0
- package/dist/cjs/model/package.json +1 -0
- package/dist/cjs/model/positions.js +1 -0
- package/dist/cjs/model/primitives.js +1 -0
- package/dist/cjs/model/primitives.schema.js +85 -0
- package/dist/cjs/new-sdk/AbstractNamespace.js +158 -0
- package/dist/cjs/new-sdk/GearboxSDK.js +122 -0
- package/dist/cjs/new-sdk/index.js +11 -0
- package/dist/cjs/new-sdk/opportunities/OpportunitiesNamespace.js +122 -0
- package/dist/cjs/new-sdk/opportunities/index.js +4 -0
- package/dist/cjs/new-sdk/opportunities/types.js +1 -0
- package/dist/cjs/new-sdk/package.json +1 -0
- package/dist/cjs/new-sdk/types.js +22 -0
- package/dist/cjs/new-sdk/utils/history.js +1 -0
- package/dist/cjs/new-sdk/utils/index.js +2 -0
- package/dist/cjs/offchain/GearboxAPI.js +33 -0
- package/dist/cjs/offchain/index.js +8 -0
- package/dist/cjs/offchain/opportunities/OffchainOpportunities.js +97 -0
- package/dist/cjs/offchain/opportunities/index.js +4 -0
- package/dist/cjs/offchain/package.json +1 -0
- package/dist/cjs/offchain/types.js +1 -0
- package/dist/cjs/preview/preview/buildDelayedPreview.js +5 -5
- package/dist/cjs/rewards/rewards/api.js +2 -2
- package/dist/cjs/rewards/rewards/extra-apy.js +2 -2
- package/dist/cjs/sdk/MultichainSDK.js +18 -2
- package/dist/cjs/sdk/OnchainSDK.js +8 -1
- package/dist/cjs/sdk/accounts/index.js +2 -0
- package/dist/cjs/sdk/accounts/liquidations/LiquidationsService.js +150 -106
- package/dist/cjs/sdk/accounts/liquidations/MultichainLiquidationsService.js +32 -38
- package/dist/cjs/sdk/accounts/liquidations/constants.js +13 -0
- package/dist/cjs/sdk/accounts/liquidations/index.js +2 -0
- package/dist/cjs/sdk/base/MultichainConstruct.js +80 -0
- package/dist/cjs/sdk/base/TokensMeta.js +51 -0
- package/dist/cjs/sdk/base/index.js +2 -0
- package/dist/cjs/sdk/chain/chains.js +76 -0
- package/dist/cjs/sdk/chain/index.js +4 -0
- package/dist/cjs/sdk/core/errors.js +13 -0
- package/dist/cjs/sdk/core/index.js +2 -1
- package/dist/cjs/sdk/index.js +25 -1
- package/dist/cjs/sdk/market/MarketConfiguratorContract.js +14 -0
- package/dist/cjs/sdk/market/MarketSuite.js +163 -0
- package/dist/cjs/sdk/market/credit/CreditManagerV310Contract.js +26 -0
- package/dist/cjs/sdk/market/credit/CreditSuite.js +102 -0
- package/dist/cjs/sdk/market/math.js +104 -0
- package/dist/cjs/sdk/market/oracle/PriceOracleBaseContract.js +52 -0
- package/dist/cjs/sdk/market/pool/LinearInterestRateModelContract.js +30 -0
- package/dist/cjs/sdk/market/pool/PoolQuotaKeeperV310Contract.js +26 -0
- package/dist/cjs/sdk/market/pool/PoolSuite.js +28 -0
- package/dist/cjs/sdk/market/pool/PoolV310Contract.js +27 -0
- package/dist/cjs/sdk/market/pool/math.js +44 -0
- package/dist/cjs/sdk/market/pricefeeds/AbstractPriceFeed.js +17 -0
- package/dist/cjs/sdk/opportunities/MultichainOpportunitiesService.js +60 -0
- package/dist/cjs/sdk/opportunities/OpportunitiesService.js +103 -0
- package/dist/cjs/sdk/opportunities/index.js +12 -0
- package/dist/cjs/sdk/types/multichain.js +1 -0
- package/dist/cjs/{common-utils → sdk}/utils/bigint-math.js +11 -11
- package/dist/cjs/sdk/utils/index.js +3 -0
- package/dist/cjs/sdk/utils/zod.js +12 -0
- package/dist/esm/common-utils/index.js +1 -1
- package/dist/esm/common-utils/utils/apy/calculate-safe-borrow-rate.js +1 -1
- package/dist/esm/common-utils/utils/assets-math.js +1 -1
- package/dist/esm/common-utils/utils/creditAccount/calc-health-factor.js +1 -1
- package/dist/esm/common-utils/utils/creditAccount/debt.js +1 -1
- package/dist/esm/common-utils/utils/creditAccount/quota-utils.js +1 -1
- package/dist/esm/common-utils/utils/index.js +1 -1
- package/dist/esm/common-utils/utils/strategies/leverage/calculate-max-leverage-factor.js +1 -1
- package/dist/esm/common-utils/utils/strategies/leverage/calculate-max-strategy-debt.js +1 -1
- package/dist/esm/common-utils/utils/strategies/strategy-info/calculate-total-points.js +1 -1
- package/dist/esm/common-utils/utils/strategies/strategy-info/get-cm-you-can-earn.js +1 -1
- package/dist/esm/common-utils/utils/validation/validate-open-account-pool-status.js +1 -1
- package/dist/esm/dev/AccountOpener.js +1 -1
- package/dist/esm/dev/index.js +3 -3
- package/dist/esm/dev/kycUtils.js +1 -1
- package/dist/esm/dev/midasUtils.js +105 -2
- package/dist/esm/dev/withdrawalUtils.js +1 -1
- package/dist/esm/model/history.js +26 -0
- package/dist/esm/model/history.schema.js +76 -0
- package/dist/esm/model/index.js +9 -0
- package/dist/esm/model/liquidations.js +22 -0
- package/dist/esm/model/liquidations.schema.js +83 -0
- package/dist/esm/model/opportunities.js +51 -0
- package/dist/esm/model/opportunities.schema.js +198 -0
- package/dist/esm/model/package.json +1 -0
- package/dist/esm/model/positions.js +1 -0
- package/dist/esm/model/primitives.js +1 -0
- package/dist/esm/model/primitives.schema.js +75 -0
- package/dist/esm/new-sdk/AbstractNamespace.js +157 -0
- package/dist/esm/new-sdk/GearboxSDK.js +121 -0
- package/dist/esm/new-sdk/index.js +7 -0
- package/dist/esm/new-sdk/opportunities/OpportunitiesNamespace.js +121 -0
- package/dist/esm/new-sdk/opportunities/index.js +3 -0
- package/dist/esm/new-sdk/opportunities/types.js +1 -0
- package/dist/esm/new-sdk/package.json +1 -0
- package/dist/esm/new-sdk/types.js +21 -0
- package/dist/esm/new-sdk/utils/history.js +1 -0
- package/dist/esm/new-sdk/utils/index.js +2 -0
- package/dist/esm/offchain/GearboxAPI.js +32 -0
- package/dist/esm/offchain/index.js +5 -0
- package/dist/esm/offchain/opportunities/OffchainOpportunities.js +95 -0
- package/dist/esm/offchain/opportunities/index.js +2 -0
- package/dist/esm/offchain/package.json +1 -0
- package/dist/esm/offchain/types.js +1 -0
- package/dist/esm/preview/preview/buildDelayedPreview.js +1 -1
- package/dist/esm/preview/simulate/simulatePoolOperation.js +1 -1
- package/dist/esm/preview/trace/extractTransfers.js +1 -1
- package/dist/esm/rewards/rewards/api.js +1 -1
- package/dist/esm/rewards/rewards/extra-apy.js +1 -1
- package/dist/esm/sdk/MultichainSDK.js +18 -2
- package/dist/esm/sdk/OnchainSDK.js +8 -1
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +2 -2
- package/dist/esm/sdk/accounts/index.js +2 -2
- package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +153 -109
- package/dist/esm/sdk/accounts/liquidations/MultichainLiquidationsService.js +32 -38
- package/dist/esm/sdk/accounts/liquidations/constants.js +12 -1
- package/dist/esm/sdk/accounts/liquidations/index.js +2 -2
- 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/MultichainConstruct.js +79 -0
- package/dist/esm/sdk/base/TokensMeta.js +53 -2
- package/dist/esm/sdk/base/index.js +2 -1
- package/dist/esm/sdk/chain/chains.js +74 -2
- package/dist/esm/sdk/chain/detectNetwork.js +1 -1
- package/dist/esm/sdk/chain/index.js +2 -2
- package/dist/esm/sdk/core/createAddressProvider.js +1 -1
- package/dist/esm/sdk/core/errors.js +13 -1
- package/dist/esm/sdk/core/index.js +2 -2
- package/dist/esm/sdk/index.js +11 -5
- package/dist/esm/sdk/market/MarketConfiguratorContract.js +14 -0
- package/dist/esm/sdk/market/MarketSuite.js +163 -0
- package/dist/esm/sdk/market/credit/CreditFacadeV310BaseContract.js +1 -1
- package/dist/esm/sdk/market/credit/CreditManagerV310Contract.js +26 -0
- package/dist/esm/sdk/market/credit/CreditSuite.js +102 -0
- package/dist/esm/sdk/market/math.js +98 -0
- package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +52 -0
- package/dist/esm/sdk/market/pool/LinearInterestRateModelContract.js +30 -0
- package/dist/esm/sdk/market/pool/PoolQuotaKeeperV310Contract.js +26 -0
- package/dist/esm/sdk/market/pool/PoolSuite.js +28 -0
- package/dist/esm/sdk/market/pool/PoolV310Contract.js +28 -1
- package/dist/esm/sdk/market/pool/math.js +41 -0
- package/dist/esm/sdk/market/pricefeeds/AbstractPriceFeed.js +17 -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/MultichainOpportunitiesService.js +59 -0
- package/dist/esm/sdk/opportunities/OpportunitiesService.js +102 -0
- package/dist/esm/sdk/opportunities/index.js +4 -0
- package/dist/esm/sdk/pools/PoolService.js +1 -1
- package/dist/esm/sdk/types/multichain.js +1 -0
- package/dist/esm/{common-utils → sdk}/utils/bigint-math.js +11 -11
- package/dist/esm/sdk/utils/index.js +3 -2
- package/dist/esm/sdk/utils/viem/simulateWithPriceUpdates.js +1 -1
- package/dist/esm/sdk/utils/zod.js +13 -2
- package/dist/types/common-utils/index.d.ts +1 -1
- package/dist/types/common-utils/utils/index.d.ts +1 -1
- package/dist/types/dev/index.d.ts +2 -2
- package/dist/types/dev/midasUtils.d.ts +31 -2
- package/dist/types/model/history.d.ts +105 -0
- package/dist/types/model/history.schema.d.ts +66 -0
- package/dist/types/model/index.d.ts +9 -0
- package/dist/types/model/liquidations.d.ts +230 -0
- package/dist/types/model/liquidations.schema.d.ts +292 -0
- package/dist/types/model/opportunities.d.ts +543 -0
- package/dist/types/model/opportunities.schema.d.ts +1066 -0
- package/dist/types/model/positions.d.ts +11 -0
- package/dist/types/model/primitives.d.ts +193 -0
- package/dist/types/model/primitives.schema.d.ts +81 -0
- package/dist/types/new-sdk/AbstractNamespace.d.ts +119 -0
- package/dist/types/new-sdk/GearboxSDK.d.ts +78 -0
- package/dist/types/new-sdk/index.d.ts +9 -0
- package/dist/types/new-sdk/opportunities/OpportunitiesNamespace.d.ts +69 -0
- package/dist/types/new-sdk/opportunities/index.d.ts +3 -0
- package/dist/types/new-sdk/opportunities/types.d.ts +66 -0
- package/dist/types/new-sdk/types.d.ts +149 -0
- package/dist/types/new-sdk/utils/history.d.ts +44 -0
- package/dist/types/new-sdk/utils/index.d.ts +2 -0
- package/dist/types/offchain/GearboxAPI.d.ts +31 -0
- package/dist/types/offchain/index.d.ts +5 -0
- package/dist/types/offchain/opportunities/OffchainOpportunities.d.ts +69 -0
- package/dist/types/offchain/opportunities/index.d.ts +2 -0
- package/dist/types/offchain/types.d.ts +50 -0
- package/dist/types/sdk/MultichainSDK.d.ts +15 -2
- package/dist/types/sdk/OnchainSDK.d.ts +9 -3
- package/dist/types/sdk/accounts/index.d.ts +3 -3
- package/dist/types/sdk/accounts/liquidations/LiquidationsService.d.ts +24 -16
- package/dist/types/sdk/accounts/liquidations/MultichainLiquidationsService.d.ts +26 -20
- package/dist/types/sdk/accounts/liquidations/constants.d.ts +12 -1
- package/dist/types/sdk/accounts/liquidations/index.d.ts +3 -3
- package/dist/types/sdk/accounts/liquidations/types.d.ts +34 -309
- package/dist/types/sdk/base/MultichainConstruct.d.ts +57 -0
- package/dist/types/sdk/base/TokensMeta.d.ts +26 -0
- package/dist/types/sdk/base/index.d.ts +2 -1
- package/dist/types/sdk/chain/chains.d.ts +68 -1
- package/dist/types/sdk/chain/index.d.ts +2 -2
- package/dist/types/sdk/core/errors.d.ts +10 -1
- package/dist/types/sdk/core/index.d.ts +2 -2
- package/dist/types/sdk/index.d.ts +15 -8
- package/dist/types/sdk/market/MarketConfiguratorContract.d.ts +9 -0
- package/dist/types/sdk/market/MarketSuite.d.ts +109 -1
- package/dist/types/sdk/market/credit/CreditManagerV310Contract.d.ts +14 -0
- package/dist/types/sdk/market/credit/CreditSuite.d.ts +47 -0
- package/dist/types/sdk/market/credit/types.d.ts +22 -0
- package/dist/types/sdk/market/index.d.ts +2 -2
- package/dist/types/sdk/market/math.d.ts +74 -0
- package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +23 -0
- package/dist/types/sdk/market/oracle/types.d.ts +46 -0
- package/dist/types/sdk/market/pool/LinearInterestRateModelContract.d.ts +12 -0
- package/dist/types/sdk/market/pool/PoolQuotaKeeperV310Contract.d.ts +22 -1
- package/dist/types/sdk/market/pool/PoolSuite.d.ts +23 -0
- package/dist/types/sdk/market/pool/PoolV310Contract.d.ts +18 -0
- package/dist/types/sdk/market/pool/math.d.ts +57 -0
- package/dist/types/sdk/market/pool/types.d.ts +23 -0
- package/dist/types/sdk/market/pricefeeds/AbstractPriceFeed.d.ts +6 -0
- package/dist/types/sdk/market/pricefeeds/types.d.ts +10 -0
- package/dist/types/sdk/opportunities/MultichainOpportunitiesService.d.ts +40 -0
- package/dist/types/sdk/opportunities/OpportunitiesService.d.ts +47 -0
- package/dist/types/sdk/opportunities/index.d.ts +4 -0
- package/dist/types/sdk/types/index.d.ts +2 -1
- package/dist/types/sdk/types/multichain.d.ts +65 -0
- package/dist/types/sdk/types/state.d.ts +1 -1
- package/dist/types/sdk/types/transactions.d.ts +3 -0
- package/dist/types/{common-utils → sdk}/utils/bigint-math.d.ts +7 -11
- package/dist/types/sdk/utils/index.d.ts +3 -2
- package/dist/types/sdk/utils/zod.d.ts +6 -2
- package/package.json +16 -1
- package/dist/cjs/sdk/accounts/liquidations/helpers.js +0 -201
- package/dist/esm/sdk/accounts/liquidations/helpers.js +0 -192
- package/dist/types/sdk/accounts/liquidations/helpers.d.ts +0 -140
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ChainId } from "./primitives.js";
|
|
2
|
+
//#region src/model/positions.d.ts
|
|
3
|
+
interface PositionFilter {
|
|
4
|
+
isZeroDebt?: boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Keep only opportunities on these chains.
|
|
7
|
+
**/
|
|
8
|
+
chainIds?: ChainId[];
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { PositionFilter };
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { Address, Hex } from "viem";
|
|
2
|
+
//#region src/model/primitives.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* EVM chain id.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* const mainnet: ChainId = 1;
|
|
9
|
+
* const arbitrum: ChainId = 42161;
|
|
10
|
+
* ```
|
|
11
|
+
**/
|
|
12
|
+
type ChainId = number;
|
|
13
|
+
/**
|
|
14
|
+
* Unix timestamp in seconds (not milliseconds).
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const t: Timestamp = 1719792000; // 2024-07-01T00:00:00Z
|
|
19
|
+
* ```
|
|
20
|
+
**/
|
|
21
|
+
type Timestamp = number;
|
|
22
|
+
/**
|
|
23
|
+
* Basis points: an integer where `10000` means 100%.
|
|
24
|
+
*
|
|
25
|
+
* Every percentage-like value of the read model — utilization, liquidation
|
|
26
|
+
* threshold, fees, premiums, APY and APR — uses this scale, which is also the
|
|
27
|
+
* scale the protocol itself stores (`PERCENTAGE_FACTOR`). Values are not
|
|
28
|
+
* clamped to `0..10000`: an APY can exceed 100%, so `12500` (125%) is valid.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* const full: Bps = 10000; // 100%
|
|
33
|
+
* const lt: Bps = 8600; // 86% liquidation threshold
|
|
34
|
+
* const apy: Bps = 512; // 5.12% APY
|
|
35
|
+
* const smallest: Bps = 1; // 0.01%
|
|
36
|
+
* ```
|
|
37
|
+
**/
|
|
38
|
+
type Bps = number;
|
|
39
|
+
/**
|
|
40
|
+
* Coarse denomination class of a token, used to group and filter opportunities
|
|
41
|
+
* by what they are ultimately priced in.
|
|
42
|
+
*
|
|
43
|
+
* This is not read from the chain: it comes from a hardcoded per-chain table
|
|
44
|
+
* and is maintained only for market underlyings, of which there are few.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* const usdc: AssetType = "Stable";
|
|
49
|
+
* const wsteth: AssetType = "ETH";
|
|
50
|
+
* ```
|
|
51
|
+
**/
|
|
52
|
+
type AssetType = "Stable" | "ETH" | "BTC";
|
|
53
|
+
/**
|
|
54
|
+
* Leverage as a plain multiplier, not a percentage and not in basis points.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* const x10: Leverage = 10; // 10x, the maximum at a 90% liquidation threshold
|
|
59
|
+
* const x1: Leverage = 1; // unleveraged
|
|
60
|
+
* ```
|
|
61
|
+
**/
|
|
62
|
+
type Leverage = number;
|
|
63
|
+
/**
|
|
64
|
+
* A token amount together with its USD valuation.
|
|
65
|
+
*
|
|
66
|
+
* The group that owns the field names the token (e.g. `totalBorrow` of an
|
|
67
|
+
* opportunity is denominated in its `underlyingToken`), so neither the symbol
|
|
68
|
+
* nor the decimals are repeated here.
|
|
69
|
+
*
|
|
70
|
+
* Both fields always come from the same source: a merged opportunity never has
|
|
71
|
+
* `value` from the chain and `valueUsd` from the backend.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* // 1500.5 USDC (6 decimals) worth $1500.50
|
|
76
|
+
* const amount: Amount = { value: 1_500_500_000n, valueUsd: 1500.5 };
|
|
77
|
+
* ```
|
|
78
|
+
**/
|
|
79
|
+
interface Amount {
|
|
80
|
+
/**
|
|
81
|
+
* Amount in the base units of the owning group's token, i.e. scaled by
|
|
82
|
+
* `10 ** decimals`.
|
|
83
|
+
*
|
|
84
|
+
* @example `1_500_500_000n` for 1500.5 USDC
|
|
85
|
+
**/
|
|
86
|
+
value: bigint;
|
|
87
|
+
/**
|
|
88
|
+
* Value of {@link value} in US dollars as a plain float, or `null` when no
|
|
89
|
+
* price is available for the token.
|
|
90
|
+
*
|
|
91
|
+
* @example `1500.5`
|
|
92
|
+
**/
|
|
93
|
+
valueUsd: number | null;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* An ERC-20 token as the read model describes it.
|
|
97
|
+
*
|
|
98
|
+
* Tokens are always fully inlined rather than referenced by address, so a row
|
|
99
|
+
* is renderable without a separate token dictionary.
|
|
100
|
+
**/
|
|
101
|
+
interface Token {
|
|
102
|
+
/**
|
|
103
|
+
* Chain the token is deployed on.
|
|
104
|
+
*
|
|
105
|
+
* @example `1`
|
|
106
|
+
**/
|
|
107
|
+
chainId: ChainId;
|
|
108
|
+
/**
|
|
109
|
+
* Checksummed token address.
|
|
110
|
+
**/
|
|
111
|
+
address: Address;
|
|
112
|
+
/**
|
|
113
|
+
* Ticker symbol.
|
|
114
|
+
*
|
|
115
|
+
* @example `"USDC"`
|
|
116
|
+
**/
|
|
117
|
+
symbol: string;
|
|
118
|
+
/**
|
|
119
|
+
* Full token name.
|
|
120
|
+
*
|
|
121
|
+
* @example `"USD Coin"`
|
|
122
|
+
**/
|
|
123
|
+
name: string;
|
|
124
|
+
/**
|
|
125
|
+
* Number of decimals the token uses.
|
|
126
|
+
*
|
|
127
|
+
* @example `6` for USDC, `18` for WETH
|
|
128
|
+
**/
|
|
129
|
+
decimals: number;
|
|
130
|
+
/**
|
|
131
|
+
* Denomination class of the token, or `undefined` when the token is not
|
|
132
|
+
* classified.
|
|
133
|
+
*
|
|
134
|
+
* Only market underlyings are classified, so a collateral token normally
|
|
135
|
+
* leaves this unset. Absence means "unknown", never "neither of the three".
|
|
136
|
+
**/
|
|
137
|
+
assetType?: AssetType;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* An {@link Amount} that names its own token.
|
|
141
|
+
**/
|
|
142
|
+
interface TokenAmount extends Amount {
|
|
143
|
+
/**
|
|
144
|
+
* Token {@link Amount.value} is denominated in.
|
|
145
|
+
**/
|
|
146
|
+
token: Token;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* The minimal transaction the read model hands out: enough to sign and send,
|
|
150
|
+
* with no ABI metadata attached.
|
|
151
|
+
**/
|
|
152
|
+
interface TxCall {
|
|
153
|
+
/**
|
|
154
|
+
* Contract the transaction is sent to.
|
|
155
|
+
**/
|
|
156
|
+
to: Address;
|
|
157
|
+
/**
|
|
158
|
+
* Encoded calldata.
|
|
159
|
+
**/
|
|
160
|
+
callData: Hex;
|
|
161
|
+
/**
|
|
162
|
+
* Wei to send along. Omitted for a plain contract call.
|
|
163
|
+
*
|
|
164
|
+
* @example `1_000_000_000_000_000_000n` for 1 ETH
|
|
165
|
+
**/
|
|
166
|
+
value?: bigint;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* The entity that curates a market: sets risk parameters, picks collateral and
|
|
170
|
+
* operates the market configurator.
|
|
171
|
+
**/
|
|
172
|
+
interface Curator {
|
|
173
|
+
/**
|
|
174
|
+
* Address of the market configurator the curator operates. This is the
|
|
175
|
+
* on-chain identity of a curator, not a personal wallet.
|
|
176
|
+
**/
|
|
177
|
+
address: Address;
|
|
178
|
+
/**
|
|
179
|
+
* Display name.
|
|
180
|
+
*
|
|
181
|
+
* @example `"Chaos Labs"`
|
|
182
|
+
**/
|
|
183
|
+
name: string;
|
|
184
|
+
/**
|
|
185
|
+
* Link to the curator's page, or `null` when unknown. The chain knows no
|
|
186
|
+
* URLs, so this is `null` for anything served from the on-chain source.
|
|
187
|
+
*
|
|
188
|
+
* @mode offchain
|
|
189
|
+
**/
|
|
190
|
+
url: string | null;
|
|
191
|
+
}
|
|
192
|
+
//#endregion
|
|
193
|
+
export { Amount, AssetType, Bps, ChainId, Curator, Leverage, Timestamp, Token, TokenAmount, TxCall };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
//#region src/model/primitives.schema.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Runtime schemas for {@link ./primitives.js}.
|
|
5
|
+
*
|
|
6
|
+
* The hand-written types are the contract; these schemas exist so the offchain
|
|
7
|
+
* client can reject a backend response that no longer matches it. The two are
|
|
8
|
+
* kept in sync by the type-level tests in `model.test-d.ts`, not by inferring
|
|
9
|
+
* one from the other.
|
|
10
|
+
**/
|
|
11
|
+
/**
|
|
12
|
+
* {@link ChainId}
|
|
13
|
+
**/
|
|
14
|
+
declare const chainIdSchema: z.ZodNumber;
|
|
15
|
+
/**
|
|
16
|
+
* {@link Timestamp}
|
|
17
|
+
**/
|
|
18
|
+
declare const timestampSchema: z.ZodNumber;
|
|
19
|
+
/**
|
|
20
|
+
* {@link Bps}. Integer, not bounded to `0..10000`: rates may exceed 100%.
|
|
21
|
+
**/
|
|
22
|
+
declare const bpsSchema: z.ZodNumber;
|
|
23
|
+
/**
|
|
24
|
+
* {@link AssetType}
|
|
25
|
+
**/
|
|
26
|
+
declare const assetTypeSchema: z.ZodUnion<readonly [z.ZodLiteral<"Stable">, z.ZodLiteral<"ETH">, z.ZodLiteral<"BTC">]>;
|
|
27
|
+
/**
|
|
28
|
+
* {@link Leverage}
|
|
29
|
+
**/
|
|
30
|
+
declare const leverageSchema: z.ZodNumber;
|
|
31
|
+
/**
|
|
32
|
+
* {@link Amount}
|
|
33
|
+
**/
|
|
34
|
+
declare const amountSchema: z.ZodObject<{
|
|
35
|
+
value: z.ZodBigInt;
|
|
36
|
+
valueUsd: z.ZodNullable<z.ZodNumber>;
|
|
37
|
+
}, z.core.$strip>;
|
|
38
|
+
/**
|
|
39
|
+
* {@link Token}
|
|
40
|
+
**/
|
|
41
|
+
declare const tokenSchema: z.ZodObject<{
|
|
42
|
+
chainId: z.ZodNumber;
|
|
43
|
+
address: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
|
|
44
|
+
symbol: z.ZodString;
|
|
45
|
+
name: z.ZodString;
|
|
46
|
+
decimals: z.ZodNumber;
|
|
47
|
+
assetType: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"Stable">, z.ZodLiteral<"ETH">, z.ZodLiteral<"BTC">]>>;
|
|
48
|
+
}, z.core.$strip>;
|
|
49
|
+
/**
|
|
50
|
+
* {@link TokenAmount}
|
|
51
|
+
**/
|
|
52
|
+
declare const tokenAmountSchema: z.ZodObject<{
|
|
53
|
+
value: z.ZodBigInt;
|
|
54
|
+
valueUsd: z.ZodNullable<z.ZodNumber>;
|
|
55
|
+
token: z.ZodObject<{
|
|
56
|
+
chainId: z.ZodNumber;
|
|
57
|
+
address: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
|
|
58
|
+
symbol: z.ZodString;
|
|
59
|
+
name: z.ZodString;
|
|
60
|
+
decimals: z.ZodNumber;
|
|
61
|
+
assetType: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"Stable">, z.ZodLiteral<"ETH">, z.ZodLiteral<"BTC">]>>;
|
|
62
|
+
}, z.core.$strip>;
|
|
63
|
+
}, z.core.$strip>;
|
|
64
|
+
/**
|
|
65
|
+
* {@link TxCall}
|
|
66
|
+
**/
|
|
67
|
+
declare const txCallSchema: z.ZodObject<{
|
|
68
|
+
to: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
|
|
69
|
+
callData: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
|
|
70
|
+
value: z.ZodOptional<z.ZodBigInt>;
|
|
71
|
+
}, z.core.$strip>;
|
|
72
|
+
/**
|
|
73
|
+
* {@link Curator}
|
|
74
|
+
**/
|
|
75
|
+
declare const curatorSchema: z.ZodObject<{
|
|
76
|
+
address: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
|
|
77
|
+
name: z.ZodString;
|
|
78
|
+
url: z.ZodNullable<z.ZodString>;
|
|
79
|
+
}, z.core.$strip>;
|
|
80
|
+
//#endregion
|
|
81
|
+
export { amountSchema, assetTypeSchema, bpsSchema, chainIdSchema, curatorSchema, leverageSchema, timestampSchema, tokenAmountSchema, tokenSchema, txCallSchema };
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { ILogger } from "../sdk/types/logger.js";
|
|
2
|
+
import { ChainId } from "../model/primitives.js";
|
|
3
|
+
import { NetworkType } from "../sdk/chain/chains.js";
|
|
4
|
+
import { MultichainNetworkMeta } from "../sdk/types/multichain.js";
|
|
5
|
+
import "../model/index.js";
|
|
6
|
+
import { MultichainSDK } from "../sdk/MultichainSDK.js";
|
|
7
|
+
import "../sdk/index.js";
|
|
8
|
+
import { OffchainResult } from "../offchain/types.js";
|
|
9
|
+
import { GearboxAPI } from "../offchain/GearboxAPI.js";
|
|
10
|
+
import "../offchain/index.js";
|
|
11
|
+
import { OffchainSourceStatus, ReadResult, SourceMeta } from "./types.js";
|
|
12
|
+
//#region src/new-sdk/AbstractNamespace.d.ts
|
|
13
|
+
/**
|
|
14
|
+
* What the on-chain source contributed, after per-chain failures have been
|
|
15
|
+
* turned into metadata.
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
**/
|
|
19
|
+
interface OnchainContribution<T> {
|
|
20
|
+
value?: T;
|
|
21
|
+
chains: MultichainNetworkMeta[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* What the off-chain source contributed, after a rejection has been turned into
|
|
25
|
+
* metadata.
|
|
26
|
+
*
|
|
27
|
+
* @internal
|
|
28
|
+
**/
|
|
29
|
+
interface OffchainContribution<T> {
|
|
30
|
+
value?: T;
|
|
31
|
+
status?: OffchainSourceStatus;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* How a read turns the two contributions into one payload. Either side is
|
|
35
|
+
* absent when its source was not asked, or was asked and failed.
|
|
36
|
+
*
|
|
37
|
+
* @internal
|
|
38
|
+
**/
|
|
39
|
+
type CombineSources<T> = (onchain: T | undefined, offchain: T | undefined) => T;
|
|
40
|
+
/**
|
|
41
|
+
* Shared machinery of every {@link GearboxSDK} namespace.
|
|
42
|
+
*
|
|
43
|
+
* A namespace is a stateless router: it asks the sources its mode allows, in
|
|
44
|
+
* parallel, merges what came back and reports what did not. This class owns
|
|
45
|
+
* that routing — per-chain failure capture, backend degradation, the response
|
|
46
|
+
* envelope and the all-sources-failed rule — so a namespace holds nothing but
|
|
47
|
+
* its reads and its merge policy.
|
|
48
|
+
*
|
|
49
|
+
* The sources are whatever it was handed, and their readiness is their owner's
|
|
50
|
+
* business: a source that is not ready to answer fails the read it was given,
|
|
51
|
+
* and that failure is reported like any other.
|
|
52
|
+
*
|
|
53
|
+
* All protocol knowledge lives in the sources: `MultichainSDK` for the chain,
|
|
54
|
+
* `GearboxAPI` for the backend. None of it is repeated here or in a subclass.
|
|
55
|
+
*
|
|
56
|
+
* @typeParam ListRow - Row type of the namespace's list read.
|
|
57
|
+
**/
|
|
58
|
+
declare abstract class AbstractNamespace<ListRow extends object> {
|
|
59
|
+
#private;
|
|
60
|
+
protected readonly logger?: ILogger;
|
|
61
|
+
protected constructor(name: string, onchain: MultichainSDK | undefined, offchain: GearboxAPI | undefined, logger?: ILogger);
|
|
62
|
+
/**
|
|
63
|
+
* Per-field source policy for one row of this namespace.
|
|
64
|
+
**/
|
|
65
|
+
protected abstract mergeOne<T extends object>(onchain: T, offchain: T): T;
|
|
66
|
+
/**
|
|
67
|
+
* Union policy for this namespace's list read.
|
|
68
|
+
**/
|
|
69
|
+
protected abstract mergeList(onchain: ListRow[], offchain: ListRow[]): ListRow[];
|
|
70
|
+
/**
|
|
71
|
+
* Asks both sources in parallel and combines whatever answered.
|
|
72
|
+
*
|
|
73
|
+
* The action name is only used in diagnostics and in the error raised when
|
|
74
|
+
* every source the read had failed.
|
|
75
|
+
**/
|
|
76
|
+
protected read<T>(action: string, fromChain: (sdk: MultichainSDK) => Promise<OnchainContribution<T>>, fromBackend: (api: GearboxAPI) => Promise<OffchainResult<T>>, combine: CombineSources<T>): Promise<ReadResult<T>>;
|
|
77
|
+
/**
|
|
78
|
+
* Reads the namespace's list from both sources, unioned by
|
|
79
|
+
* {@link AbstractNamespace.mergeList}.
|
|
80
|
+
**/
|
|
81
|
+
protected readList(action: string, fromChain: (sdk: MultichainSDK) => Promise<OnchainContribution<ListRow[]>>, fromBackend: (api: GearboxAPI) => Promise<OffchainResult<ListRow[]>>): Promise<ReadResult<ListRow[]>>;
|
|
82
|
+
/**
|
|
83
|
+
* Reads one row from both sources and merges them under
|
|
84
|
+
* {@link AbstractNamespace.mergeOne}. The key names the chain, so the
|
|
85
|
+
* on-chain leg queries exactly one.
|
|
86
|
+
**/
|
|
87
|
+
protected readOne<T extends object>(action: string, chainId: ChainId, fromChain: (sdk: MultichainSDK) => Promise<T>, fromBackend: (api: GearboxAPI) => Promise<OffchainResult<T>>): Promise<ReadResult<T>>;
|
|
88
|
+
/**
|
|
89
|
+
* Reads something only the backend can answer.
|
|
90
|
+
*
|
|
91
|
+
* The fallback stands in for a backend that answered with nothing, which is
|
|
92
|
+
* a different thing from a backend that failed and was dropped.
|
|
93
|
+
**/
|
|
94
|
+
protected readOffchain<T>(action: string, fromBackend: (api: GearboxAPI) => Promise<OffchainResult<T>>, fallback: T): Promise<ReadResult<T>>;
|
|
95
|
+
/**
|
|
96
|
+
* Runs a read against the chain, or reports the chain as absent when the
|
|
97
|
+
* namespace has no on-chain source at all.
|
|
98
|
+
**/
|
|
99
|
+
protected fromChain<T>(run: (sdk: MultichainSDK) => Promise<OnchainContribution<T>>): Promise<OnchainContribution<T>>;
|
|
100
|
+
/**
|
|
101
|
+
* Runs a read against the backend, turning any rejection into metadata so
|
|
102
|
+
* that a dead backend degrades a `both`-mode read instead of failing it.
|
|
103
|
+
**/
|
|
104
|
+
protected fromBackend<T>(run: (api: GearboxAPI) => Promise<OffchainResult<T>>): Promise<OffchainContribution<T>>;
|
|
105
|
+
/**
|
|
106
|
+
* Runs a read against one chain, turning a rejection into that chain's
|
|
107
|
+
* metadata entry.
|
|
108
|
+
**/
|
|
109
|
+
protected onOneChain<T>(action: string, network: NetworkType, run: () => Promise<T>): Promise<OnchainContribution<T>>;
|
|
110
|
+
/**
|
|
111
|
+
* A read that reached at least one source returns what it has; a read where
|
|
112
|
+
* every source it had failed throws, because an empty result would otherwise
|
|
113
|
+
* be indistinguishable from "there is nothing here".
|
|
114
|
+
**/
|
|
115
|
+
protected assertAnySourceSucceeded(action: string, meta: SourceMeta): void;
|
|
116
|
+
protected networkOf(chainId: ChainId): NetworkType | undefined;
|
|
117
|
+
}
|
|
118
|
+
//#endregion
|
|
119
|
+
export { AbstractNamespace, CombineSources, OffchainContribution, OnchainContribution };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { NetworkType } from "../sdk/chain/chains.js";
|
|
2
|
+
import "../sdk/index.js";
|
|
3
|
+
import { GearboxSDKOptions, Mode, OffchainByMode, OnchainByMode } from "./types.js";
|
|
4
|
+
import { Opportunities } from "./opportunities/types.js";
|
|
5
|
+
import "./opportunities/index.js";
|
|
6
|
+
//#region src/new-sdk/GearboxSDK.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Combined entry point over both sources of Gearbox data: the chain and the
|
|
9
|
+
* Gearbox backend.
|
|
10
|
+
*
|
|
11
|
+
* The {@link Mode} is fixed at construction and decides which methods exist,
|
|
12
|
+
* not what they return, so a screen written against `both` cannot silently
|
|
13
|
+
* degrade to a subset when someone reconfigures the SDK:
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* const sdk = new GearboxSDK({
|
|
17
|
+
* mode: "both",
|
|
18
|
+
* networks: ["Mainnet"],
|
|
19
|
+
* onchain: { chains: { Mainnet: { rpcURLs } } },
|
|
20
|
+
* offchain: { baseUrl: "https://api.gearbox.fi" },
|
|
21
|
+
* });
|
|
22
|
+
* await sdk.attach();
|
|
23
|
+
*
|
|
24
|
+
* const { result, meta } = await sdk.opportunities.list({ kind: "strategy" });
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* Every read answers with `{ result, meta }`: `meta` says which chains and
|
|
28
|
+
* which backend answered, because a partial answer is the normal case for a
|
|
29
|
+
* multi-chain read.
|
|
30
|
+
*
|
|
31
|
+
* @typeParam M - Mode the instance was built in.
|
|
32
|
+
**/
|
|
33
|
+
declare class GearboxSDK<const M extends Mode = Mode> {
|
|
34
|
+
#private;
|
|
35
|
+
/**
|
|
36
|
+
* Sources this instance reads from.
|
|
37
|
+
**/
|
|
38
|
+
readonly mode: M;
|
|
39
|
+
/**
|
|
40
|
+
* Chains this instance covers. Authoritative even when an injected on-chain
|
|
41
|
+
* SDK covers a different set.
|
|
42
|
+
**/
|
|
43
|
+
readonly networks: readonly NetworkType[];
|
|
44
|
+
/**
|
|
45
|
+
* Namespace for pool and strategy opportunities.
|
|
46
|
+
**/
|
|
47
|
+
readonly opportunities: Opportunities<M>;
|
|
48
|
+
constructor(options: GearboxSDKOptions<M>);
|
|
49
|
+
/**
|
|
50
|
+
* Attaches the on-chain SDK when this instance owns one.
|
|
51
|
+
*
|
|
52
|
+
* Reads issued before this resolves still reach the chain and fail there, so
|
|
53
|
+
* in `both` mode they are served from the backend alone and report the chain
|
|
54
|
+
* as failed in their meta, rather than blocking.
|
|
55
|
+
*
|
|
56
|
+
* A no-op in `offchain` mode and when an already-attached SDK was injected.
|
|
57
|
+
**/
|
|
58
|
+
attach(): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Whether the on-chain source is ready to be read from. Always `true` in
|
|
61
|
+
* `offchain` mode, where there is nothing to wait for.
|
|
62
|
+
**/
|
|
63
|
+
get attached(): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* The underlying on-chain SDK, for everything this facade does not expose
|
|
66
|
+
* yet: markets, credit accounts, transaction building.
|
|
67
|
+
*
|
|
68
|
+
* `undefined` in `offchain` mode. Otherwise it exists from construction on,
|
|
69
|
+
* but only answers reads once {@link attach} has resolved.
|
|
70
|
+
**/
|
|
71
|
+
get onchain(): OnchainByMode[M];
|
|
72
|
+
/**
|
|
73
|
+
* The underlying backend client. `undefined` in `onchain` mode.
|
|
74
|
+
**/
|
|
75
|
+
get offchain(): OffchainByMode[M];
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
export { GearboxSDK };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AllSourcesFailedError, GearboxSDKOptions, Mode, OffchainByMode, OffchainSource, OffchainSourceStatus, OnchainByMode, OnchainSource, PlainMultichainSDKOptions, ReadResult, SourceMeta } from "./types.js";
|
|
2
|
+
import { AbstractNamespace, CombineSources, OffchainContribution, OnchainContribution } from "./AbstractNamespace.js";
|
|
3
|
+
import { Chart, ChartMetadata, HistoryReader } from "./utils/history.js";
|
|
4
|
+
import "./utils/index.js";
|
|
5
|
+
import { Opportunities, OpportunitiesBase, OpportunitiesByMode, OpportunitiesOffchainOnly, OpportunitiesOnchainOnly } from "./opportunities/types.js";
|
|
6
|
+
import { OpportunitiesNamespace } from "./opportunities/OpportunitiesNamespace.js";
|
|
7
|
+
import "./opportunities/index.js";
|
|
8
|
+
import { GearboxSDK } from "./GearboxSDK.js";
|
|
9
|
+
export { AbstractNamespace, AllSourcesFailedError, Chart, ChartMetadata, CombineSources, GearboxSDK, GearboxSDKOptions, HistoryReader, Mode, OffchainByMode, OffchainContribution, OffchainSource, OffchainSourceStatus, OnchainByMode, OnchainContribution, OnchainSource, Opportunities, OpportunitiesBase, OpportunitiesByMode, OpportunitiesNamespace, OpportunitiesOffchainOnly, OpportunitiesOnchainOnly, PlainMultichainSDKOptions, ReadResult, SourceMeta };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { ILogger } from "../../sdk/types/logger.js";
|
|
2
|
+
import { Opportunity, OpportunityFilter, PoolOpportunityDetail, PoolOpportunityKey, PoolOpportunityRef, StrategyOpportunityDetail, StrategyOpportunityKey, StrategyOpportunityRef } from "../../model/opportunities.js";
|
|
3
|
+
import { PoolHistoryMetric, StrategyHistoryMetric } from "../../model/history.js";
|
|
4
|
+
import "../../model/index.js";
|
|
5
|
+
import { MultichainSDK } from "../../sdk/MultichainSDK.js";
|
|
6
|
+
import "../../sdk/index.js";
|
|
7
|
+
import { GearboxAPI } from "../../offchain/GearboxAPI.js";
|
|
8
|
+
import "../../offchain/index.js";
|
|
9
|
+
import { ReadResult } from "../types.js";
|
|
10
|
+
import { AbstractNamespace } from "../AbstractNamespace.js";
|
|
11
|
+
import { HistoryReader } from "../utils/history.js";
|
|
12
|
+
import "../utils/index.js";
|
|
13
|
+
import { OpportunitiesBase, OpportunitiesOffchainOnly } from "./types.js";
|
|
14
|
+
//#region src/new-sdk/opportunities/OpportunitiesNamespace.d.ts
|
|
15
|
+
/**
|
|
16
|
+
* The `opportunities` namespace of the combined SDK.
|
|
17
|
+
*
|
|
18
|
+
* A stateless router over the two sources, see {@link AbstractNamespace} for
|
|
19
|
+
* the routing itself. What is specific to opportunities is the reads below and
|
|
20
|
+
* the merge policy at the bottom of the class.
|
|
21
|
+
*
|
|
22
|
+
* The class implements the methods of every mode; {@link GearboxSDK} exposes it
|
|
23
|
+
* as its mode's slice of {@link OpportunitiesByMode}, so calling a method the
|
|
24
|
+
* mode does not have is a compile error rather than a runtime one.
|
|
25
|
+
**/
|
|
26
|
+
declare class OpportunitiesNamespace extends AbstractNamespace<Opportunity> implements OpportunitiesBase, OpportunitiesOffchainOnly {
|
|
27
|
+
#private;
|
|
28
|
+
constructor(onchain: MultichainSDK | undefined, offchain: GearboxAPI | undefined, logger?: ILogger);
|
|
29
|
+
/**
|
|
30
|
+
* {@inheritDoc OpportunitiesBase.list}
|
|
31
|
+
**/
|
|
32
|
+
list(filter?: OpportunityFilter): Promise<ReadResult<Opportunity[]>>;
|
|
33
|
+
/**
|
|
34
|
+
* {@inheritDoc OpportunitiesBase.getPool}
|
|
35
|
+
**/
|
|
36
|
+
getPool(key: PoolOpportunityKey): Promise<ReadResult<PoolOpportunityDetail>>;
|
|
37
|
+
/**
|
|
38
|
+
* {@inheritDoc OpportunitiesBase.getStrategy}
|
|
39
|
+
**/
|
|
40
|
+
getStrategy(key: StrategyOpportunityKey): Promise<ReadResult<StrategyOpportunityDetail>>;
|
|
41
|
+
/**
|
|
42
|
+
* {@inheritDoc OpportunitiesOffchainOnly.history}
|
|
43
|
+
**/
|
|
44
|
+
history(key: PoolOpportunityRef): HistoryReader<PoolHistoryMetric>;
|
|
45
|
+
history(key: StrategyOpportunityRef): HistoryReader<StrategyHistoryMetric>;
|
|
46
|
+
/**
|
|
47
|
+
* Merges the two versions of one opportunity.
|
|
48
|
+
*
|
|
49
|
+
* The chain wins every field it fills; the backend fills the rest and owns
|
|
50
|
+
* {@link OFFCHAIN_OWNED_FIELDS}.
|
|
51
|
+
*
|
|
52
|
+
* The rule is onchain-first, field-wise, and never deeper than one level: a
|
|
53
|
+
* group like `totalSupply` or `supplyApy` is taken whole from one source, so
|
|
54
|
+
* a row never mixes an on-chain token amount with a backend dollar value
|
|
55
|
+
* derived from a different block.
|
|
56
|
+
**/
|
|
57
|
+
protected mergeOne<T extends object>(onchain: T, offchain: T): T;
|
|
58
|
+
/**
|
|
59
|
+
* Unions the two lists by canonical opportunity id.
|
|
60
|
+
*
|
|
61
|
+
* Rows present in both are merged by {@link OpportunitiesNamespace.mergeOne}.
|
|
62
|
+
* Rows only the backend knows are appended: a chain the SDK does not cover,
|
|
63
|
+
* or a market it has not loaded, is a reason to show more rather than fewer
|
|
64
|
+
* opportunities.
|
|
65
|
+
**/
|
|
66
|
+
protected mergeList(onchain: Opportunity[], offchain: Opportunity[]): Opportunity[];
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
export { OpportunitiesNamespace };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Opportunities, OpportunitiesBase, OpportunitiesByMode, OpportunitiesOffchainOnly, OpportunitiesOnchainOnly } from "./types.js";
|
|
2
|
+
import { OpportunitiesNamespace } from "./OpportunitiesNamespace.js";
|
|
3
|
+
export { Opportunities, OpportunitiesBase, OpportunitiesByMode, OpportunitiesNamespace, OpportunitiesOffchainOnly, OpportunitiesOnchainOnly };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Opportunity, OpportunityFilter, PoolOpportunityDetail, PoolOpportunityKey, PoolOpportunityRef, StrategyOpportunityDetail, StrategyOpportunityKey, StrategyOpportunityRef } from "../../model/opportunities.js";
|
|
2
|
+
import { PoolHistoryMetric, StrategyHistoryMetric } from "../../model/history.js";
|
|
3
|
+
import "../../model/index.js";
|
|
4
|
+
import { Mode, ReadResult } from "../types.js";
|
|
5
|
+
import { HistoryReader } from "../utils/history.js";
|
|
6
|
+
//#region src/new-sdk/opportunities/types.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Reads every mode supports, because either source alone can answer them.
|
|
9
|
+
**/
|
|
10
|
+
interface OpportunitiesBase {
|
|
11
|
+
/**
|
|
12
|
+
* All pool and strategy opportunities, optionally narrowed.
|
|
13
|
+
*
|
|
14
|
+
* In `both` mode the two lists are unioned by canonical opportunity id and
|
|
15
|
+
* merged field-wise, with the chain winning any field both sources fill.
|
|
16
|
+
**/
|
|
17
|
+
list(filter?: OpportunityFilter): Promise<ReadResult<Opportunity[]>>;
|
|
18
|
+
/**
|
|
19
|
+
* Detailed view of one pool opportunity.
|
|
20
|
+
**/
|
|
21
|
+
getPool(key: PoolOpportunityKey): Promise<ReadResult<PoolOpportunityDetail>>;
|
|
22
|
+
/**
|
|
23
|
+
* Detailed view of one strategy opportunity.
|
|
24
|
+
**/
|
|
25
|
+
getStrategy(key: StrategyOpportunityKey): Promise<ReadResult<StrategyOpportunityDetail>>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Reads only a backend can answer.
|
|
29
|
+
**/
|
|
30
|
+
interface OpportunitiesOffchainOnly {
|
|
31
|
+
/**
|
|
32
|
+
* Historical charts of one opportunity, one metric and one range at a time:
|
|
33
|
+
* `history(key).chart("depositApy", "1m")`.
|
|
34
|
+
*
|
|
35
|
+
* The key's kind decides which metrics exist, so asking a pool for a
|
|
36
|
+
* strategy series does not compile.
|
|
37
|
+
*
|
|
38
|
+
* Absent in `onchain` mode: the chain serves the present, and rebuilding a
|
|
39
|
+
* series from it would mean an archive read per point.
|
|
40
|
+
**/
|
|
41
|
+
history(key: PoolOpportunityRef): HistoryReader<PoolHistoryMetric>;
|
|
42
|
+
history(key: StrategyOpportunityRef): HistoryReader<StrategyHistoryMetric>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Reads only the chain can answer. Empty for now — every on-chain read the
|
|
46
|
+
* namespace exposes has a backend counterpart.
|
|
47
|
+
**/
|
|
48
|
+
interface OpportunitiesOnchainOnly {}
|
|
49
|
+
/**
|
|
50
|
+
* Which methods the `opportunities` namespace has in each mode.
|
|
51
|
+
*
|
|
52
|
+
* A lookup map rather than a conditional type: `both` is spelled out instead of
|
|
53
|
+
* being inferred, and a widened mode degrades to the intersection of what all
|
|
54
|
+
* modes offer rather than silently distributing into a union of everything.
|
|
55
|
+
**/
|
|
56
|
+
interface OpportunitiesByMode {
|
|
57
|
+
onchain: OpportunitiesBase & OpportunitiesOnchainOnly;
|
|
58
|
+
offchain: OpportunitiesBase & OpportunitiesOffchainOnly;
|
|
59
|
+
both: OpportunitiesBase & OpportunitiesOffchainOnly & OpportunitiesOnchainOnly;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The `opportunities` namespace of a {@link GearboxSDK} in mode `M`.
|
|
63
|
+
**/
|
|
64
|
+
type Opportunities<M extends Mode = Mode> = OpportunitiesByMode[M];
|
|
65
|
+
//#endregion
|
|
66
|
+
export { Opportunities, OpportunitiesBase, OpportunitiesByMode, OpportunitiesOffchainOnly, OpportunitiesOnchainOnly };
|