@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,102 @@
|
|
|
1
|
+
import { SDKConstruct } from "../base/SDKConstruct.js";
|
|
2
|
+
import "../base/index.js";
|
|
3
|
+
import { usdToNumber } from "../market/math.js";
|
|
4
|
+
//#region src/sdk/opportunities/OpportunitiesService.ts
|
|
5
|
+
/**
|
|
6
|
+
* A lookup that knows of no strategy, used when a filter rules strategies out
|
|
7
|
+
* and the credit-account query is skipped altogether.
|
|
8
|
+
**/
|
|
9
|
+
const NO_TOTALS = () => void 0;
|
|
10
|
+
/**
|
|
11
|
+
* Builds the `opportunities` read model from the chain.
|
|
12
|
+
*
|
|
13
|
+
* Everything except the credit-account totals comes from the market state the
|
|
14
|
+
* SDK already holds, so a list costs one RPC round-trip at most. Yield figures
|
|
15
|
+
* that fold in incentives, points or history are deliberately absent: they are
|
|
16
|
+
* the backend's job, and this service never guesses them.
|
|
17
|
+
*
|
|
18
|
+
* The rows themselves are assembled by the market wrappers — see
|
|
19
|
+
* {@link MarketSuite.opportunities} — because every value in them is market
|
|
20
|
+
* state. What is left here is the one thing no single market can answer: how
|
|
21
|
+
* much the credit accounts of a strategy are worth.
|
|
22
|
+
**/
|
|
23
|
+
var OpportunitiesService = class extends SDKConstruct {
|
|
24
|
+
/**
|
|
25
|
+
* Every pool and strategy of every loaded market on this chain.
|
|
26
|
+
*
|
|
27
|
+
* Strategies are measured by the value locked in their credit accounts, so
|
|
28
|
+
* the list issues one credit-account query unless the filter rules strategies
|
|
29
|
+
* out entirely.
|
|
30
|
+
*
|
|
31
|
+
* @param filter - Optional narrowing, applied to the built rows.
|
|
32
|
+
**/
|
|
33
|
+
async list(filter) {
|
|
34
|
+
if (filter?.chainIds && !filter.chainIds.includes(this.chainId)) return [];
|
|
35
|
+
const { markets } = this.sdk.marketRegister;
|
|
36
|
+
const totals = filter?.kind === "pool" ? NO_TOTALS : await this.#strategyTotals(markets);
|
|
37
|
+
return markets.flatMap((market) => market.opportunities(totals, filter));
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A single pool opportunity plus its interest rate curve and quotas.
|
|
41
|
+
*
|
|
42
|
+
* @throws If no loaded market has this pool.
|
|
43
|
+
**/
|
|
44
|
+
async getPool(key) {
|
|
45
|
+
return this.sdk.marketRegister.findByPool(key.pool).poolOpportunityDetail();
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A single strategy opportunity plus the rate curve of the pool it borrows
|
|
49
|
+
* from and the price feeds its liquidation price depends on.
|
|
50
|
+
*
|
|
51
|
+
* @throws If the credit manager is unknown, or does not accept the requested
|
|
52
|
+
* collateral as a strategy.
|
|
53
|
+
**/
|
|
54
|
+
async getStrategy(key) {
|
|
55
|
+
const market = this.sdk.marketRegister.findByCreditManager(key.creditManager);
|
|
56
|
+
const { suite } = market.mustFindStrategy(key.creditManager, key.targetCollateral);
|
|
57
|
+
const totals = await this.#strategyTotals([market]);
|
|
58
|
+
return suite.strategyOpportunityDetail(key.targetCollateral, totals(key.creditManager, key.targetCollateral));
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Total value held by the credit accounts backing every strategy of the given
|
|
62
|
+
* markets.
|
|
63
|
+
*
|
|
64
|
+
* An account that holds several strategy collaterals counts in full towards
|
|
65
|
+
* each of them: the read model reports what a strategy's accounts are worth,
|
|
66
|
+
* not how that worth splits across the collaterals inside them.
|
|
67
|
+
**/
|
|
68
|
+
async #strategyTotals(markets) {
|
|
69
|
+
const wanted = /* @__PURE__ */ new Map();
|
|
70
|
+
for (const market of markets) for (const { suite, collateral } of market.strategies) {
|
|
71
|
+
const cm = suite.creditManager.address.toLowerCase();
|
|
72
|
+
const tokens = wanted.get(cm) ?? /* @__PURE__ */ new Set();
|
|
73
|
+
tokens.add(collateral.toLowerCase());
|
|
74
|
+
wanted.set(cm, tokens);
|
|
75
|
+
}
|
|
76
|
+
if (wanted.size === 0) return NO_TOTALS;
|
|
77
|
+
const accounts = await this.sdk.accounts.getCreditAccounts({ includeZeroDebt: true });
|
|
78
|
+
const totals = /* @__PURE__ */ new Map();
|
|
79
|
+
for (const account of accounts) {
|
|
80
|
+
const tokens = wanted.get(account.creditManager.toLowerCase());
|
|
81
|
+
if (!tokens) continue;
|
|
82
|
+
for (const token of account.tokens) {
|
|
83
|
+
if (token.balance <= 0n || !tokens.has(token.token.toLowerCase())) continue;
|
|
84
|
+
const key = strategyKey(account.creditManager, token.token);
|
|
85
|
+
const current = totals.get(key);
|
|
86
|
+
totals.set(key, {
|
|
87
|
+
value: (current?.value ?? 0n) + account.totalValue,
|
|
88
|
+
valueUsd: (current?.valueUsd ?? 0) + usdToNumber(account.totalValueUSD)
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return (creditManager, collateral) => totals.get(strategyKey(creditManager, collateral));
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Both halves of a strategy key folded into one map key.
|
|
97
|
+
**/
|
|
98
|
+
function strategyKey(creditManager, collateral) {
|
|
99
|
+
return `${creditManager.toLowerCase()}:${collateral.toLowerCase()}`;
|
|
100
|
+
}
|
|
101
|
+
//#endregion
|
|
102
|
+
export { OpportunitiesService };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { additionalBorrowApyBps, borrowApyBps, maxLeverage, rayToBps, usdToNumber, utilizationBps } from "../market/math.js";
|
|
2
|
+
import { MultichainOpportunitiesService } from "./MultichainOpportunitiesService.js";
|
|
3
|
+
import { OpportunitiesService } from "./OpportunitiesService.js";
|
|
4
|
+
export { MultichainOpportunitiesService, OpportunitiesService, additionalBorrowApyBps, borrowApyBps, maxLeverage, rayToBps, usdToNumber, utilizationBps };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AddressSet } from "../utils/AddressSet.js";
|
|
2
1
|
import { ierc20Abi } from "../../abi/iERC20.js";
|
|
2
|
+
import { AddressSet } from "../utils/AddressSet.js";
|
|
3
3
|
import "../constants/addresses.js";
|
|
4
4
|
import "../constants/index.js";
|
|
5
5
|
import { hexEq } from "../utils/hex.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region src/
|
|
1
|
+
//#region src/sdk/utils/bigint-math.ts
|
|
2
2
|
/**
|
|
3
3
|
* Utility namespace for common `bigint` operations.
|
|
4
4
|
*
|
|
@@ -16,20 +16,20 @@ var BigIntMath = class {
|
|
|
16
16
|
static abs = (x) => x < 0n ? -x : x;
|
|
17
17
|
/**
|
|
18
18
|
* Returns the greater of two bigint values.
|
|
19
|
-
*
|
|
20
|
-
* @
|
|
21
|
-
* @param b Second candidate value.
|
|
22
|
-
* @returns The larger value between `a` and `b`.
|
|
19
|
+
* @param values - The values to find the maximum of.
|
|
20
|
+
* @returns The maximum value.
|
|
23
21
|
*/
|
|
24
|
-
static max = (
|
|
22
|
+
static max = (...values) => {
|
|
23
|
+
return values.reduce((max, v) => v > max ? v : max);
|
|
24
|
+
};
|
|
25
25
|
/**
|
|
26
26
|
* Returns the smaller of two bigint values.
|
|
27
|
-
*
|
|
28
|
-
* @
|
|
29
|
-
* @param b Second candidate value.
|
|
30
|
-
* @returns The smaller value between `a` and `b`.
|
|
27
|
+
* @param values - The values to find the minimum of.
|
|
28
|
+
* @returns The minimum value.
|
|
31
29
|
*/
|
|
32
|
-
static min = (
|
|
30
|
+
static min = (...values) => {
|
|
31
|
+
return values.reduce((min, v) => v < min ? v : min);
|
|
32
|
+
};
|
|
33
33
|
/**
|
|
34
34
|
* Returns the negative form of a bigint if it is currently positive.
|
|
35
35
|
*
|
|
@@ -3,6 +3,7 @@ import { AddressSet } from "./AddressSet.js";
|
|
|
3
3
|
import { AssetsMap } from "./AssetsMap.js";
|
|
4
4
|
import { json_parse, json_stringify } from "./json.js";
|
|
5
5
|
import { functionArgsToMap, functionArgsToRecord, getFunctionSignature } from "./abi-decode.js";
|
|
6
|
+
import { BigIntMath } from "./bigint-math.js";
|
|
6
7
|
import { bytes32ToString } from "./bytes32ToString.js";
|
|
7
8
|
import { childLogger } from "./childLogger.js";
|
|
8
9
|
import { createRawTx } from "./createRawTx.js";
|
|
@@ -15,5 +16,5 @@ import { hexEq } from "./hex.js";
|
|
|
15
16
|
import { retry } from "./retry.js";
|
|
16
17
|
import { toAddress } from "./toAddress.js";
|
|
17
18
|
import "./type-utils.js";
|
|
18
|
-
import { ZodAddress } from "./zod.js";
|
|
19
|
-
export { AddressMap, AddressSet, AssetsMap, TypedObjectUtils, ZodAddress, bytes32ToString, childLogger, createRawTx, etherscanApiUrl, etherscanUrl, filterDust, filterDustUSD, fmtBinaryMask, formatBN, formatBNvalue, formatDuration, formatLeverage, formatNumberToString_, formatPercentage, formatTimestamp, functionArgsToMap, functionArgsToRecord, getFunctionSignature, hexEq, isDust, json_parse, json_stringify, numberWithCommas, percentFmt, rayToNumber, retry, shortAddress, shortHash, toAddress, toBN, toBigInt, toSignificant };
|
|
19
|
+
import { ZodAddress, ZodHex } from "./zod.js";
|
|
20
|
+
export { AddressMap, AddressSet, AssetsMap, BigIntMath, TypedObjectUtils, ZodAddress, ZodHex, bytes32ToString, childLogger, createRawTx, etherscanApiUrl, etherscanUrl, filterDust, filterDustUSD, fmtBinaryMask, formatBN, formatBNvalue, formatDuration, formatLeverage, formatNumberToString_, formatPercentage, formatTimestamp, functionArgsToMap, functionArgsToRecord, getFunctionSignature, hexEq, isDust, json_parse, json_stringify, numberWithCommas, percentFmt, rayToNumber, retry, shortAddress, shortHash, toAddress, toBN, toBigInt, toSignificant };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { errorAbis } from "../../../abi/errors.js";
|
|
2
|
-
import { generateCastTraceCall } from "./cast.js";
|
|
3
2
|
import { iUpdatablePriceFeedAbi } from "../../../abi/iUpdatablePriceFeed.js";
|
|
3
|
+
import { generateCastTraceCall } from "./cast.js";
|
|
4
4
|
import { simulateMulticall } from "./simulateMulticall.js";
|
|
5
5
|
import { BaseError, CallExecutionError, ContractFunctionRevertedError, decodeFunctionData, decodeFunctionResult, encodeFunctionData, parseAbi } from "viem";
|
|
6
6
|
import { getAction, parseAccount } from "viem/utils";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getAddress, isAddress } from "viem";
|
|
1
|
+
import { getAddress, isAddress, isHex } from "viem";
|
|
2
2
|
import { z } from "zod/v4";
|
|
3
3
|
//#region src/sdk/utils/zod.ts
|
|
4
4
|
/**
|
|
@@ -12,5 +12,16 @@ const ZodAddress = () => z.string().transform((val, ctx) => {
|
|
|
12
12
|
});
|
|
13
13
|
return getAddress(val);
|
|
14
14
|
});
|
|
15
|
+
/**
|
|
16
|
+
* A `0x`-prefixed hex string, as viem's Hex.
|
|
17
|
+
*/
|
|
18
|
+
const ZodHex = () => z.string().transform((val, ctx) => {
|
|
19
|
+
if (!isHex(val)) ctx.issues.push({
|
|
20
|
+
code: "custom",
|
|
21
|
+
message: `invalid hex string ${val}`,
|
|
22
|
+
input: ctx.value
|
|
23
|
+
});
|
|
24
|
+
return val;
|
|
25
|
+
});
|
|
15
26
|
//#endregion
|
|
16
|
-
export { ZodAddress };
|
|
27
|
+
export { ZodAddress, ZodHex };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BigIntMath } from "../sdk/utils/bigint-math.js";
|
|
1
2
|
import { AxiosCache } from "./axios-cache/AxiosCache.js";
|
|
2
3
|
import "./axios-cache/index.js";
|
|
3
4
|
import { BigNumberish, ChartsCreditManagerPayload } from "./charts/credit-manager-payload.js";
|
|
@@ -43,7 +44,6 @@ import { getSafeBaseBorrowRate } from "./utils/apy/get-safe-base-borrow-rate.js"
|
|
|
43
44
|
import { CalcQuotaBorrowRateProps, calcQuotaBorrowRate } from "./utils/creditAccount/calc-quota-borrow-rate.js";
|
|
44
45
|
import { GetSingleQuotaBorrowRateRate, getSingleQuotaBorrowRate } from "./utils/apy/get-single-quota-borrow-rate.js";
|
|
45
46
|
import { maxAPYFormula } from "./utils/apy/max-apy-formula.js";
|
|
46
|
-
import { BigIntMath } from "./utils/bigint-math.js";
|
|
47
47
|
import { EMPTY_ADDRESS, EMPTY_ARRAY, EMPTY_OBJECT } from "./utils/constants.js";
|
|
48
48
|
import { CalcHealthFactorProps, calcHealthFactor } from "./utils/creditAccount/calc-health-factor.js";
|
|
49
49
|
import { CalcOverallAPYProps, calcOverallAPY } from "./utils/creditAccount/calc-overall-apy.js";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BigIntMath } from "../../sdk/utils/bigint-math.js";
|
|
1
2
|
import { AssetUtils, AssetWithAmountInTarget, AssetWithView, WrapResult } from "./assets-math.js";
|
|
2
3
|
import { BONUS_APY_FROM_POINTS } from "./apy/bonus-apy-from-points.js";
|
|
3
4
|
import { AppChains } from "./strategies/types/chains.js";
|
|
@@ -28,7 +29,6 @@ import { CalcQuotaBorrowRateProps, calcQuotaBorrowRate } from "./creditAccount/c
|
|
|
28
29
|
import { GetSingleQuotaBorrowRateRate, getSingleQuotaBorrowRate } from "./apy/get-single-quota-borrow-rate.js";
|
|
29
30
|
import { maxAPYFormula } from "./apy/max-apy-formula.js";
|
|
30
31
|
import "./apy/index.js";
|
|
31
|
-
import { BigIntMath } from "./bigint-math.js";
|
|
32
32
|
import { EMPTY_ADDRESS, EMPTY_ARRAY, EMPTY_OBJECT } from "./constants.js";
|
|
33
33
|
import { CalcHealthFactorProps, calcHealthFactor } from "./creditAccount/calc-health-factor.js";
|
|
34
34
|
import { CalcOverallAPYProps, calcOverallAPY } from "./creditAccount/calc-overall-apy.js";
|
|
@@ -14,7 +14,7 @@ import { isTransientError } from "./isTransientError.js";
|
|
|
14
14
|
import { GreenlistMidasGatewayProps, RWAKycFailure, RegisterMidasInvestorProps, RegisterRWAInvestorProps, RegisterRWAInvestorResult, RegisterSecuritizeInvestorProps, greenlistMidasGateway, registerMidasInvestor, registerRWAInvestor, registerSecuritizeInvestor, writeAndWait } from "./kycUtils.js";
|
|
15
15
|
import { LogSplitterTransportOptions, isRangeError, logSplitterTransport } from "./logSplitterTransport.js";
|
|
16
16
|
import { setLTZero, setLTs } from "./ltUtils.js";
|
|
17
|
-
import { PrependMidasReceiveGreenlistProps, prependMidasReceiveGreenlist } from "./midasUtils.js";
|
|
17
|
+
import { PrependMidasReceiveGreenlistProps, RestoreMidasIssuanceVaultPause, UnpauseMidasIssuanceVaultProps, prependMidasReceiveGreenlist, unpauseMidasIssuanceVault } from "./midasUtils.js";
|
|
18
18
|
import { migrateFaucet } from "./migrateFaucet.js";
|
|
19
19
|
import { IMinter } from "./mint/types.js";
|
|
20
20
|
import { createMinter } from "./mint/factory.js";
|
|
@@ -26,4 +26,4 @@ import { EnableDSTokenBackDatingProps, RestoreDSTokenBackDating, claimDSToken, c
|
|
|
26
26
|
import { httpTransportOptionsSchema } from "./transports.js";
|
|
27
27
|
import { ONCHAIN_EXECUTION_ID_ADDRESS, VerifyTestnetParams, verifyTestnet } from "./verifyTestnet.js";
|
|
28
28
|
import { MakePendingWithdrawalsClaimableOptions, makePendingWithdrawalsClaimable } from "./withdrawalUtils.js";
|
|
29
|
-
export { AccountOpener, AccountOpenerOptions, AnvilActions, AnvilClient, AnvilClientConfig, AnvilDealParameters, AnvilNodeInfo, AnvilRPCSchema, CheckMulticallFn, Create2Deployer, Create2Parameters, DEFAULT_CREATE2_SALT, DetectedCall, EnableDSTokenBackDatingProps, EnsureExistsUsingPublicCreate2ReturnType, EthCallMethod, EthCallRequest, EthCallSpy, GetCreate2AddressParameters, GreenlistMidasGatewayProps, IMinter, type LogSplitterTransportOptions, MakePendingWithdrawalsClaimableOptions, NoAvailableTransportsError, ONCHAIN_EXECUTION_ID_ADDRESS, OpenAccountHumanizedPreview, OpenAccountResult, OpenAccountsResult, OpenTxRevertedError, PUBLIC_CREATE2_FACTORY, PoolDepositResult, PrependMidasReceiveGreenlistProps, ProviderConfig, ProviderStatus, RWAKycFailure, RegisterMidasInvestorProps, RegisterRWAInvestorProps, RegisterRWAInvestorResult, RegisterSecuritizeInvestorProps, ReplaceStorageParams, ResilientTransportOptions, RestoreDSTokenBackDating, RevolverTransport, RevolverTransportConfig, RevolverTransportValue, RpcErrorResult, RpcProvider, RpcResponse, RpcSuccessResult, SUPPORTED_RPC_PROVIDERS, SelectionStrategy, TargetAccount, VerifyTestnetParams, anvilNodeInfo, calcLiquidatableLTs, claimDSToken, claimDSTokens, claimFromFaucet, createAnvilClient, createMinter, deployUsingPublicCreate2, detectChain, enableDSTokenBackDating, evmMineDetailed, extendAnvilClient, faucetAbi, getAlchemyUrl, getAnkrUrl, getDrpcUrl, getErpcKey, getPublicCreate2Address, getRpcProviderUrl, getThirdWebUrl, greenlistMidasGateway, httpTransportOptionsSchema, iDegenNftv2Abi, iOnchainExecutionIdAbi, iOwnableAbi, iaclTraitAbi, isAnvil, isDeployedUsingPublicCreate2, isOutOfSyncError, isRangeError, isRateLimitError, isTransientError, logSplitterTransport, makePendingWithdrawalsClaimable, migrateFaucet, prependMidasReceiveGreenlist, providerConfigSchema, registerMidasInvestor, registerRWAInvestor, registerSecuritizeInvestor, replaceStorage, resilientTransport, resilientTransportOptionsSchema, revolverTransportConfigBaseSchema, revolverTransportConfigSchema, rpcProvidersSchema, setLTZero, setLTs, verifyTestnet, writeAndWait };
|
|
29
|
+
export { AccountOpener, AccountOpenerOptions, AnvilActions, AnvilClient, AnvilClientConfig, AnvilDealParameters, AnvilNodeInfo, AnvilRPCSchema, CheckMulticallFn, Create2Deployer, Create2Parameters, DEFAULT_CREATE2_SALT, DetectedCall, EnableDSTokenBackDatingProps, EnsureExistsUsingPublicCreate2ReturnType, EthCallMethod, EthCallRequest, EthCallSpy, GetCreate2AddressParameters, GreenlistMidasGatewayProps, IMinter, type LogSplitterTransportOptions, MakePendingWithdrawalsClaimableOptions, NoAvailableTransportsError, ONCHAIN_EXECUTION_ID_ADDRESS, OpenAccountHumanizedPreview, OpenAccountResult, OpenAccountsResult, OpenTxRevertedError, PUBLIC_CREATE2_FACTORY, PoolDepositResult, PrependMidasReceiveGreenlistProps, ProviderConfig, ProviderStatus, RWAKycFailure, RegisterMidasInvestorProps, RegisterRWAInvestorProps, RegisterRWAInvestorResult, RegisterSecuritizeInvestorProps, ReplaceStorageParams, ResilientTransportOptions, RestoreDSTokenBackDating, RestoreMidasIssuanceVaultPause, RevolverTransport, RevolverTransportConfig, RevolverTransportValue, RpcErrorResult, RpcProvider, RpcResponse, RpcSuccessResult, SUPPORTED_RPC_PROVIDERS, SelectionStrategy, TargetAccount, UnpauseMidasIssuanceVaultProps, VerifyTestnetParams, anvilNodeInfo, calcLiquidatableLTs, claimDSToken, claimDSTokens, claimFromFaucet, createAnvilClient, createMinter, deployUsingPublicCreate2, detectChain, enableDSTokenBackDating, evmMineDetailed, extendAnvilClient, faucetAbi, getAlchemyUrl, getAnkrUrl, getDrpcUrl, getErpcKey, getPublicCreate2Address, getRpcProviderUrl, getThirdWebUrl, greenlistMidasGateway, httpTransportOptionsSchema, iDegenNftv2Abi, iOnchainExecutionIdAbi, iOwnableAbi, iaclTraitAbi, isAnvil, isDeployedUsingPublicCreate2, isOutOfSyncError, isRangeError, isRateLimitError, isTransientError, logSplitterTransport, makePendingWithdrawalsClaimable, migrateFaucet, prependMidasReceiveGreenlist, providerConfigSchema, registerMidasInvestor, registerRWAInvestor, registerSecuritizeInvestor, replaceStorage, resilientTransport, resilientTransportOptionsSchema, revolverTransportConfigBaseSchema, revolverTransportConfigSchema, rpcProvidersSchema, setLTZero, setLTs, unpauseMidasIssuanceVault, verifyTestnet, writeAndWait };
|
|
@@ -2,7 +2,8 @@ import { ILogger } from "../sdk/types/logger.js";
|
|
|
2
2
|
import { CreditSuite } from "../sdk/market/credit/CreditSuite.js";
|
|
3
3
|
import { MultiCall } from "../sdk/types/transactions.js";
|
|
4
4
|
import "../sdk/index.js";
|
|
5
|
-
import {
|
|
5
|
+
import { AnvilClient } from "./createAnvilClient.js";
|
|
6
|
+
import { Address, PublicClient } from "viem";
|
|
6
7
|
//#region src/dev/midasUtils.d.ts
|
|
7
8
|
interface PrependMidasReceiveGreenlistProps {
|
|
8
9
|
/**
|
|
@@ -35,5 +36,33 @@ interface PrependMidasReceiveGreenlistProps {
|
|
|
35
36
|
* the gateway is permissionless, or the call is already there.
|
|
36
37
|
*/
|
|
37
38
|
declare function prependMidasReceiveGreenlist(props: PrependMidasReceiveGreenlistProps): Promise<MultiCall[]>;
|
|
39
|
+
interface UnpauseMidasIssuanceVaultProps {
|
|
40
|
+
anvil: AnvilClient;
|
|
41
|
+
/**
|
|
42
|
+
* Midas issuance vault (deposit vault) to unpause
|
|
43
|
+
*/
|
|
44
|
+
vault: Address;
|
|
45
|
+
/**
|
|
46
|
+
* Midas access control admin, impersonated on the fork
|
|
47
|
+
* (MIDAS_ACL_ADMIN in periphery-v3/router-v3 foundry tests)
|
|
48
|
+
*/
|
|
49
|
+
admin: Address;
|
|
50
|
+
logger?: ILogger;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Pauses the vault back when it was unpaused by `unpauseMidasIssuanceVault`,
|
|
54
|
+
* and does nothing otherwise. Safe to call more than once.
|
|
55
|
+
*/
|
|
56
|
+
type RestoreMidasIssuanceVaultPause = () => Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Unpauses a globally paused Midas issuance vault on an anvil fork, so that
|
|
59
|
+
* `depositInstant` stops reverting with `Pausable: paused`, and returns a
|
|
60
|
+
* callback that restores the original pause state.
|
|
61
|
+
*
|
|
62
|
+
* Impersonates `admin` and grants it `pauseAdminRole()` when missing, same as
|
|
63
|
+
* `greenlistMidasGateway` does with the greenlist roles. The grant is not
|
|
64
|
+
* reverted by the callback, only the pause state is.
|
|
65
|
+
*/
|
|
66
|
+
declare function unpauseMidasIssuanceVault(props: UnpauseMidasIssuanceVaultProps): Promise<RestoreMidasIssuanceVaultPause>;
|
|
38
67
|
//#endregion
|
|
39
|
-
export { PrependMidasReceiveGreenlistProps, prependMidasReceiveGreenlist };
|
|
68
|
+
export { PrependMidasReceiveGreenlistProps, RestoreMidasIssuanceVaultPause, UnpauseMidasIssuanceVaultProps, prependMidasReceiveGreenlist, unpauseMidasIssuanceVault };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { Timestamp } from "./primitives.js";
|
|
2
|
+
import { OpportunityKey } from "./opportunities.js";
|
|
3
|
+
//#region src/model/history.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Historical time series of an opportunity.
|
|
6
|
+
*
|
|
7
|
+
* History is backend-only by construction: the chain serves the present, and
|
|
8
|
+
* reconstructing a series from it would mean archive-node reads per point.
|
|
9
|
+
**/
|
|
10
|
+
/**
|
|
11
|
+
* Time window a series covers, ending at the present.
|
|
12
|
+
*
|
|
13
|
+
* `"max"` is the full history the backend retains for the opportunity.
|
|
14
|
+
**/
|
|
15
|
+
type HistoryRange = "1d" | "1w" | "1m" | "1y" | "max";
|
|
16
|
+
/**
|
|
17
|
+
* Series available for a pool opportunity.
|
|
18
|
+
**/
|
|
19
|
+
type PoolHistoryMetric = "depositApy" | "borrowApy" | "dieselRate" | "supplied" | "borrowed" | "availableLiquidity";
|
|
20
|
+
/**
|
|
21
|
+
* Every {@link PoolHistoryMetric}, for callers that enumerate them.
|
|
22
|
+
**/
|
|
23
|
+
declare const POOL_HISTORY_METRICS: readonly ["depositApy", "borrowApy", "dieselRate", "supplied", "borrowed", "availableLiquidity"];
|
|
24
|
+
/**
|
|
25
|
+
* Series available for a strategy opportunity.
|
|
26
|
+
*
|
|
27
|
+
* `collateralPrice` is the collateral/underlying series a liquidation-price
|
|
28
|
+
* chart draws; the two USD series are the same prices quoted in dollars.
|
|
29
|
+
**/
|
|
30
|
+
type StrategyHistoryMetric = "netApy" | "borrowApy" | "collateralApy" | "tvl" | "collateralPrice" | "collateralUsdPrice" | "underlyingUsdPrice";
|
|
31
|
+
/**
|
|
32
|
+
* Every {@link StrategyHistoryMetric}, for callers that enumerate them.
|
|
33
|
+
**/
|
|
34
|
+
declare const STRATEGY_HISTORY_METRICS: readonly ["netApy", "borrowApy", "collateralApy", "tvl", "collateralPrice", "collateralUsdPrice", "underlyingUsdPrice"];
|
|
35
|
+
/**
|
|
36
|
+
* Any series the read model can return.
|
|
37
|
+
**/
|
|
38
|
+
type HistoryMetric = PoolHistoryMetric | StrategyHistoryMetric;
|
|
39
|
+
/**
|
|
40
|
+
* One sample of a series.
|
|
41
|
+
**/
|
|
42
|
+
interface HistoryPoint {
|
|
43
|
+
/**
|
|
44
|
+
* When the sample was taken.
|
|
45
|
+
**/
|
|
46
|
+
timestamp: Timestamp;
|
|
47
|
+
/**
|
|
48
|
+
* Sampled value. The unit follows from the metric: APY metrics are in basis
|
|
49
|
+
* points, amount metrics are in the underlying's base units expressed as a
|
|
50
|
+
* float, price metrics are plain prices.
|
|
51
|
+
*
|
|
52
|
+
* @example `842` for an 8.42% APY sample
|
|
53
|
+
**/
|
|
54
|
+
value: number;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Annotations the backend ships alongside a series, e.g. what a chart drawn
|
|
58
|
+
* from it should say beyond the points themselves.
|
|
59
|
+
*
|
|
60
|
+
* TODO: the backend has not specified this payload yet. It stays empty until
|
|
61
|
+
* it does, so that filling it in later is additive rather than a rename.
|
|
62
|
+
**/
|
|
63
|
+
interface HistoryChartMetadata {}
|
|
64
|
+
/**
|
|
65
|
+
* A named series of samples ordered by ascending timestamp.
|
|
66
|
+
*
|
|
67
|
+
* @typeParam M - Metric the series carries.
|
|
68
|
+
**/
|
|
69
|
+
interface HistorySeries<M extends string = HistoryMetric> {
|
|
70
|
+
/**
|
|
71
|
+
* Metric the samples belong to; it also defines their unit, so no separate
|
|
72
|
+
* unit field ships.
|
|
73
|
+
**/
|
|
74
|
+
metric: M;
|
|
75
|
+
/**
|
|
76
|
+
* Samples, oldest first.
|
|
77
|
+
**/
|
|
78
|
+
points: HistoryPoint[];
|
|
79
|
+
/**
|
|
80
|
+
* What the backend says about the series, see {@link HistoryChartMetadata}.
|
|
81
|
+
**/
|
|
82
|
+
metadata: HistoryChartMetadata;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* A request for one series of a single opportunity.
|
|
86
|
+
*
|
|
87
|
+
* @typeParam M - Metric requested.
|
|
88
|
+
**/
|
|
89
|
+
interface OpportunityHistoryQuery<M extends HistoryMetric = HistoryMetric> {
|
|
90
|
+
/**
|
|
91
|
+
* Opportunity the series belongs to.
|
|
92
|
+
**/
|
|
93
|
+
opportunity: OpportunityKey;
|
|
94
|
+
/**
|
|
95
|
+
* Window to cover.
|
|
96
|
+
**/
|
|
97
|
+
range: HistoryRange;
|
|
98
|
+
/**
|
|
99
|
+
* Metric to return. A metric that does not apply to the opportunity's kind
|
|
100
|
+
* has no series.
|
|
101
|
+
**/
|
|
102
|
+
metric: M;
|
|
103
|
+
}
|
|
104
|
+
//#endregion
|
|
105
|
+
export { HistoryChartMetadata, HistoryMetric, HistoryPoint, HistoryRange, HistorySeries, OpportunityHistoryQuery, POOL_HISTORY_METRICS, PoolHistoryMetric, STRATEGY_HISTORY_METRICS, StrategyHistoryMetric };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { HistoryChartMetadata } from "./history.js";
|
|
2
|
+
import { z } from "zod/v4";
|
|
3
|
+
//#region src/model/history.schema.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Runtime schemas for {@link ./history.js}, see the note in
|
|
6
|
+
* `primitives.schema.ts` on why they are written by hand.
|
|
7
|
+
**/
|
|
8
|
+
/**
|
|
9
|
+
* {@link HistoryRange}
|
|
10
|
+
**/
|
|
11
|
+
declare const historyRangeSchema: z.ZodUnion<readonly [z.ZodLiteral<"1d">, z.ZodLiteral<"1w">, z.ZodLiteral<"1m">, z.ZodLiteral<"1y">, z.ZodLiteral<"max">]>;
|
|
12
|
+
/**
|
|
13
|
+
* {@link PoolHistoryMetric}
|
|
14
|
+
**/
|
|
15
|
+
declare const poolHistoryMetricSchema: z.ZodUnion<readonly [z.ZodLiteral<"depositApy">, z.ZodLiteral<"borrowApy">, z.ZodLiteral<"dieselRate">, z.ZodLiteral<"supplied">, z.ZodLiteral<"borrowed">, z.ZodLiteral<"availableLiquidity">]>;
|
|
16
|
+
/**
|
|
17
|
+
* {@link StrategyHistoryMetric}
|
|
18
|
+
**/
|
|
19
|
+
declare const strategyHistoryMetricSchema: z.ZodUnion<readonly [z.ZodLiteral<"netApy">, z.ZodLiteral<"borrowApy">, z.ZodLiteral<"collateralApy">, z.ZodLiteral<"tvl">, z.ZodLiteral<"collateralPrice">, z.ZodLiteral<"collateralUsdPrice">, z.ZodLiteral<"underlyingUsdPrice">]>;
|
|
20
|
+
/**
|
|
21
|
+
* {@link HistoryMetric}
|
|
22
|
+
**/
|
|
23
|
+
declare const historyMetricSchema: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodLiteral<"depositApy">, z.ZodLiteral<"borrowApy">, z.ZodLiteral<"dieselRate">, z.ZodLiteral<"supplied">, z.ZodLiteral<"borrowed">, z.ZodLiteral<"availableLiquidity">]>, z.ZodUnion<readonly [z.ZodLiteral<"netApy">, z.ZodLiteral<"borrowApy">, z.ZodLiteral<"collateralApy">, z.ZodLiteral<"tvl">, z.ZodLiteral<"collateralPrice">, z.ZodLiteral<"collateralUsdPrice">, z.ZodLiteral<"underlyingUsdPrice">]>]>;
|
|
24
|
+
/**
|
|
25
|
+
* {@link HistoryPoint}
|
|
26
|
+
**/
|
|
27
|
+
declare const historyPointSchema: z.ZodObject<{
|
|
28
|
+
timestamp: z.ZodNumber;
|
|
29
|
+
value: z.ZodNumber;
|
|
30
|
+
}, z.core.$strip>;
|
|
31
|
+
/**
|
|
32
|
+
* {@link HistoryChartMetadata}
|
|
33
|
+
*
|
|
34
|
+
* TODO: empty until the backend specifies the payload.
|
|
35
|
+
**/
|
|
36
|
+
declare const historyChartMetadataSchema: z.ZodType<HistoryChartMetadata>;
|
|
37
|
+
/**
|
|
38
|
+
* {@link HistorySeries}
|
|
39
|
+
**/
|
|
40
|
+
declare const historySeriesSchema: z.ZodObject<{
|
|
41
|
+
metric: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodLiteral<"depositApy">, z.ZodLiteral<"borrowApy">, z.ZodLiteral<"dieselRate">, z.ZodLiteral<"supplied">, z.ZodLiteral<"borrowed">, z.ZodLiteral<"availableLiquidity">]>, z.ZodUnion<readonly [z.ZodLiteral<"netApy">, z.ZodLiteral<"borrowApy">, z.ZodLiteral<"collateralApy">, z.ZodLiteral<"tvl">, z.ZodLiteral<"collateralPrice">, z.ZodLiteral<"collateralUsdPrice">, z.ZodLiteral<"underlyingUsdPrice">]>]>;
|
|
42
|
+
points: z.ZodArray<z.ZodObject<{
|
|
43
|
+
timestamp: z.ZodNumber;
|
|
44
|
+
value: z.ZodNumber;
|
|
45
|
+
}, z.core.$strip>>;
|
|
46
|
+
metadata: z.ZodType<HistoryChartMetadata, unknown, z.core.$ZodTypeInternals<HistoryChartMetadata, unknown>>;
|
|
47
|
+
}, z.core.$strip>;
|
|
48
|
+
/**
|
|
49
|
+
* {@link OpportunityHistoryQuery}
|
|
50
|
+
**/
|
|
51
|
+
declare const opportunityHistoryQuerySchema: z.ZodObject<{
|
|
52
|
+
opportunity: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
53
|
+
chainId: z.ZodNumber;
|
|
54
|
+
pool: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
|
|
55
|
+
kind: z.ZodLiteral<"pool">;
|
|
56
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
57
|
+
chainId: z.ZodNumber;
|
|
58
|
+
creditManager: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
|
|
59
|
+
targetCollateral: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
|
|
60
|
+
kind: z.ZodLiteral<"strategy">;
|
|
61
|
+
}, z.core.$strip>], "kind">;
|
|
62
|
+
range: z.ZodUnion<readonly [z.ZodLiteral<"1d">, z.ZodLiteral<"1w">, z.ZodLiteral<"1m">, z.ZodLiteral<"1y">, z.ZodLiteral<"max">]>;
|
|
63
|
+
metric: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodLiteral<"depositApy">, z.ZodLiteral<"borrowApy">, z.ZodLiteral<"dieselRate">, z.ZodLiteral<"supplied">, z.ZodLiteral<"borrowed">, z.ZodLiteral<"availableLiquidity">]>, z.ZodUnion<readonly [z.ZodLiteral<"netApy">, z.ZodLiteral<"borrowApy">, z.ZodLiteral<"collateralApy">, z.ZodLiteral<"tvl">, z.ZodLiteral<"collateralPrice">, z.ZodLiteral<"collateralUsdPrice">, z.ZodLiteral<"underlyingUsdPrice">]>]>;
|
|
64
|
+
}, z.core.$strip>;
|
|
65
|
+
//#endregion
|
|
66
|
+
export { historyChartMetadataSchema, historyMetricSchema, historyPointSchema, historyRangeSchema, historySeriesSchema, opportunityHistoryQuerySchema, poolHistoryMetricSchema, strategyHistoryMetricSchema };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Amount, AssetType, Bps, ChainId, Curator, Leverage, Timestamp, Token, TokenAmount, TxCall } from "./primitives.js";
|
|
2
|
+
import { ApyBreakdown, Opportunity, OpportunityBase, OpportunityDetail, OpportunityFilter, OpportunityId, OpportunityKey, OpportunityKind, PointRewards, PointsProgram, PoolOpportunity, PoolOpportunityDetail, PoolOpportunityKey, PoolOpportunityRef, PriceFeedData, PriceFeedSummary, QuotaAsset, RateCurve, RateCurvePoint, Rewards, StrategyOpportunity, StrategyOpportunityDetail, StrategyOpportunityKey, StrategyOpportunityRef, TokenRewards, matchesOpportunityFilter, opportunityId, poolOpportunityId, strategyOpportunityId } from "./opportunities.js";
|
|
3
|
+
import { HistoryChartMetadata, HistoryMetric, HistoryPoint, HistoryRange, HistorySeries, OpportunityHistoryQuery, POOL_HISTORY_METRICS, PoolHistoryMetric, STRATEGY_HISTORY_METRICS, StrategyHistoryMetric } from "./history.js";
|
|
4
|
+
import { historyChartMetadataSchema, historyMetricSchema, historyPointSchema, historyRangeSchema, historySeriesSchema, opportunityHistoryQuerySchema, poolHistoryMetricSchema, strategyHistoryMetricSchema } from "./history.schema.js";
|
|
5
|
+
import { DelayedReceivedAsset, InstantReceivedAsset, LiquidatableAccount, LiquidatableAccountFilter, LiquidationApproval, LiquidationDetails, LiquidationPosition, ReceivedAsset, matchesLiquidatableAccountFilter } from "./liquidations.js";
|
|
6
|
+
import { delayedReceivedAssetSchema, instantReceivedAssetSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionSchema, receivedAssetSchema } from "./liquidations.schema.js";
|
|
7
|
+
import { apyBreakdownSchema, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterSchema, opportunityKeySchema, opportunityKindSchema, opportunitySchema, pointRewardsSchema, pointsProgramSchema, poolOpportunityDetailSchema, poolOpportunityKeySchema, poolOpportunitySchema, priceFeedDataSchema, priceFeedSummarySchema, quotaAssetSchema, rateCurvePointSchema, rateCurveSchema, rewardsSchema, strategyOpportunityDetailSchema, strategyOpportunityKeySchema, strategyOpportunitySchema, tokenRewardsSchema } from "./opportunities.schema.js";
|
|
8
|
+
import { amountSchema, assetTypeSchema, bpsSchema, chainIdSchema, curatorSchema, leverageSchema, timestampSchema, tokenAmountSchema, tokenSchema, txCallSchema } from "./primitives.schema.js";
|
|
9
|
+
export { Amount, ApyBreakdown, AssetType, Bps, ChainId, Curator, DelayedReceivedAsset, HistoryChartMetadata, HistoryMetric, HistoryPoint, HistoryRange, HistorySeries, InstantReceivedAsset, Leverage, LiquidatableAccount, LiquidatableAccountFilter, LiquidationApproval, LiquidationDetails, LiquidationPosition, Opportunity, OpportunityBase, OpportunityDetail, OpportunityFilter, OpportunityHistoryQuery, OpportunityId, OpportunityKey, OpportunityKind, POOL_HISTORY_METRICS, PointRewards, PointsProgram, PoolHistoryMetric, PoolOpportunity, PoolOpportunityDetail, PoolOpportunityKey, PoolOpportunityRef, PriceFeedData, PriceFeedSummary, QuotaAsset, RateCurve, RateCurvePoint, ReceivedAsset, Rewards, STRATEGY_HISTORY_METRICS, StrategyHistoryMetric, StrategyOpportunity, StrategyOpportunityDetail, StrategyOpportunityKey, StrategyOpportunityRef, Timestamp, Token, TokenAmount, TokenRewards, TxCall, amountSchema, apyBreakdownSchema, assetTypeSchema, bpsSchema, chainIdSchema, curatorSchema, delayedReceivedAssetSchema, historyChartMetadataSchema, historyMetricSchema, historyPointSchema, historyRangeSchema, historySeriesSchema, instantReceivedAssetSchema, leverageSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionSchema, matchesLiquidatableAccountFilter, matchesOpportunityFilter, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterSchema, opportunityHistoryQuerySchema, opportunityId, opportunityKeySchema, opportunityKindSchema, opportunitySchema, pointRewardsSchema, pointsProgramSchema, poolHistoryMetricSchema, poolOpportunityDetailSchema, poolOpportunityId, poolOpportunityKeySchema, poolOpportunitySchema, priceFeedDataSchema, priceFeedSummarySchema, quotaAssetSchema, rateCurvePointSchema, rateCurveSchema, receivedAssetSchema, rewardsSchema, strategyHistoryMetricSchema, strategyOpportunityDetailSchema, strategyOpportunityId, strategyOpportunityKeySchema, strategyOpportunitySchema, timestampSchema, tokenAmountSchema, tokenRewardsSchema, tokenSchema, txCallSchema };
|