@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,26 @@
|
|
|
1
|
+
//#region src/model/history.ts
|
|
2
|
+
/**
|
|
3
|
+
* Every {@link PoolHistoryMetric}, for callers that enumerate them.
|
|
4
|
+
**/
|
|
5
|
+
const POOL_HISTORY_METRICS = [
|
|
6
|
+
"depositApy",
|
|
7
|
+
"borrowApy",
|
|
8
|
+
"dieselRate",
|
|
9
|
+
"supplied",
|
|
10
|
+
"borrowed",
|
|
11
|
+
"availableLiquidity"
|
|
12
|
+
];
|
|
13
|
+
/**
|
|
14
|
+
* Every {@link StrategyHistoryMetric}, for callers that enumerate them.
|
|
15
|
+
**/
|
|
16
|
+
const STRATEGY_HISTORY_METRICS = [
|
|
17
|
+
"netApy",
|
|
18
|
+
"borrowApy",
|
|
19
|
+
"collateralApy",
|
|
20
|
+
"tvl",
|
|
21
|
+
"collateralPrice",
|
|
22
|
+
"collateralUsdPrice",
|
|
23
|
+
"underlyingUsdPrice"
|
|
24
|
+
];
|
|
25
|
+
//#endregion
|
|
26
|
+
export { POOL_HISTORY_METRICS, STRATEGY_HISTORY_METRICS };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { timestampSchema } from "./primitives.schema.js";
|
|
2
|
+
import { opportunityKeySchema } from "./opportunities.schema.js";
|
|
3
|
+
import { z } from "zod/v4";
|
|
4
|
+
//#region src/model/history.schema.ts
|
|
5
|
+
/**
|
|
6
|
+
* Runtime schemas for {@link ./history.js}, see the note in
|
|
7
|
+
* `primitives.schema.ts` on why they are written by hand.
|
|
8
|
+
**/
|
|
9
|
+
/**
|
|
10
|
+
* {@link HistoryRange}
|
|
11
|
+
**/
|
|
12
|
+
const historyRangeSchema = z.union([
|
|
13
|
+
z.literal("1d"),
|
|
14
|
+
z.literal("1w"),
|
|
15
|
+
z.literal("1m"),
|
|
16
|
+
z.literal("1y"),
|
|
17
|
+
z.literal("max")
|
|
18
|
+
]);
|
|
19
|
+
/**
|
|
20
|
+
* {@link PoolHistoryMetric}
|
|
21
|
+
**/
|
|
22
|
+
const poolHistoryMetricSchema = z.union([
|
|
23
|
+
z.literal("depositApy"),
|
|
24
|
+
z.literal("borrowApy"),
|
|
25
|
+
z.literal("dieselRate"),
|
|
26
|
+
z.literal("supplied"),
|
|
27
|
+
z.literal("borrowed"),
|
|
28
|
+
z.literal("availableLiquidity")
|
|
29
|
+
]);
|
|
30
|
+
/**
|
|
31
|
+
* {@link StrategyHistoryMetric}
|
|
32
|
+
**/
|
|
33
|
+
const strategyHistoryMetricSchema = z.union([
|
|
34
|
+
z.literal("netApy"),
|
|
35
|
+
z.literal("borrowApy"),
|
|
36
|
+
z.literal("collateralApy"),
|
|
37
|
+
z.literal("tvl"),
|
|
38
|
+
z.literal("collateralPrice"),
|
|
39
|
+
z.literal("collateralUsdPrice"),
|
|
40
|
+
z.literal("underlyingUsdPrice")
|
|
41
|
+
]);
|
|
42
|
+
/**
|
|
43
|
+
* {@link HistoryMetric}
|
|
44
|
+
**/
|
|
45
|
+
const historyMetricSchema = z.union([poolHistoryMetricSchema, strategyHistoryMetricSchema]);
|
|
46
|
+
/**
|
|
47
|
+
* {@link HistoryPoint}
|
|
48
|
+
**/
|
|
49
|
+
const historyPointSchema = z.object({
|
|
50
|
+
timestamp: timestampSchema,
|
|
51
|
+
value: z.number()
|
|
52
|
+
});
|
|
53
|
+
/**
|
|
54
|
+
* {@link HistoryChartMetadata}
|
|
55
|
+
*
|
|
56
|
+
* TODO: empty until the backend specifies the payload.
|
|
57
|
+
**/
|
|
58
|
+
const historyChartMetadataSchema = z.object({});
|
|
59
|
+
/**
|
|
60
|
+
* {@link HistorySeries}
|
|
61
|
+
**/
|
|
62
|
+
const historySeriesSchema = z.object({
|
|
63
|
+
metric: historyMetricSchema,
|
|
64
|
+
points: z.array(historyPointSchema),
|
|
65
|
+
metadata: historyChartMetadataSchema
|
|
66
|
+
});
|
|
67
|
+
/**
|
|
68
|
+
* {@link OpportunityHistoryQuery}
|
|
69
|
+
**/
|
|
70
|
+
const opportunityHistoryQuerySchema = z.object({
|
|
71
|
+
opportunity: opportunityKeySchema,
|
|
72
|
+
range: historyRangeSchema,
|
|
73
|
+
metric: historyMetricSchema
|
|
74
|
+
});
|
|
75
|
+
//#endregion
|
|
76
|
+
export { historyChartMetadataSchema, historyMetricSchema, historyPointSchema, historyRangeSchema, historySeriesSchema, opportunityHistoryQuerySchema, poolHistoryMetricSchema, strategyHistoryMetricSchema };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { POOL_HISTORY_METRICS, STRATEGY_HISTORY_METRICS } from "./history.js";
|
|
2
|
+
import { amountSchema, assetTypeSchema, bpsSchema, chainIdSchema, curatorSchema, leverageSchema, timestampSchema, tokenAmountSchema, tokenSchema, txCallSchema } from "./primitives.schema.js";
|
|
3
|
+
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";
|
|
4
|
+
import { historyChartMetadataSchema, historyMetricSchema, historyPointSchema, historyRangeSchema, historySeriesSchema, opportunityHistoryQuerySchema, poolHistoryMetricSchema, strategyHistoryMetricSchema } from "./history.schema.js";
|
|
5
|
+
import { matchesLiquidatableAccountFilter } from "./liquidations.js";
|
|
6
|
+
import { delayedReceivedAssetSchema, instantReceivedAssetSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionSchema, receivedAssetSchema } from "./liquidations.schema.js";
|
|
7
|
+
import { matchesOpportunityFilter, opportunityId, poolOpportunityId, strategyOpportunityId } from "./opportunities.js";
|
|
8
|
+
import "./primitives.js";
|
|
9
|
+
export { POOL_HISTORY_METRICS, STRATEGY_HISTORY_METRICS, 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 };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#region src/model/liquidations.ts
|
|
2
|
+
/**
|
|
3
|
+
* Whether a liquidatable account satisfies every criterion of a filter.
|
|
4
|
+
*
|
|
5
|
+
* This is the single definition of what each criterion means: every source
|
|
6
|
+
* builds its rows first and runs them through here, so the chain and the
|
|
7
|
+
* backend cannot disagree on what a filter selects.
|
|
8
|
+
*
|
|
9
|
+
* @param account - Row to test.
|
|
10
|
+
* @param filter - Criteria to test against. An absent filter matches anything.
|
|
11
|
+
**/
|
|
12
|
+
function matchesLiquidatableAccountFilter(account, filter) {
|
|
13
|
+
if (!filter) return true;
|
|
14
|
+
if (filter.chainIds && !filter.chainIds.includes(account.chainId)) return false;
|
|
15
|
+
if (filter.underlyingType && account.totalValue.token.assetType !== filter.underlyingType) return false;
|
|
16
|
+
if (filter.paused !== void 0 && account.paused !== filter.paused) return false;
|
|
17
|
+
if (filter.rwa !== void 0 && account.rwa !== filter.rwa) return false;
|
|
18
|
+
if (filter.delayed !== void 0 && account.isDelayed !== filter.delayed) return false;
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { matchesLiquidatableAccountFilter };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { ZodAddress } from "../sdk/utils/zod.js";
|
|
2
|
+
import { assetTypeSchema, chainIdSchema, timestampSchema, tokenAmountSchema, tokenSchema, txCallSchema } from "./primitives.schema.js";
|
|
3
|
+
import { z } from "zod/v4";
|
|
4
|
+
//#region src/model/liquidations.schema.ts
|
|
5
|
+
/**
|
|
6
|
+
* Runtime schemas for {@link ./liquidations.js}, see the note in
|
|
7
|
+
* `primitives.schema.ts` on why they are written by hand.
|
|
8
|
+
**/
|
|
9
|
+
/**
|
|
10
|
+
* {@link LiquidatableAccountFilter}
|
|
11
|
+
**/
|
|
12
|
+
const liquidatableAccountFilterSchema = z.object({
|
|
13
|
+
chainIds: z.array(chainIdSchema).optional(),
|
|
14
|
+
underlyingType: assetTypeSchema.optional(),
|
|
15
|
+
paused: z.boolean().optional(),
|
|
16
|
+
rwa: z.boolean().optional(),
|
|
17
|
+
delayed: z.boolean().optional()
|
|
18
|
+
});
|
|
19
|
+
/**
|
|
20
|
+
* {@link LiquidatableAccount}
|
|
21
|
+
**/
|
|
22
|
+
const liquidatableAccountSchema = z.object({
|
|
23
|
+
chainId: chainIdSchema,
|
|
24
|
+
creditAccount: ZodAddress(),
|
|
25
|
+
creditManager: ZodAddress(),
|
|
26
|
+
asset: tokenSchema,
|
|
27
|
+
totalValue: tokenAmountSchema,
|
|
28
|
+
repaymentAmount: tokenAmountSchema,
|
|
29
|
+
estimatedProfit: tokenAmountSchema,
|
|
30
|
+
isDelayed: z.boolean(),
|
|
31
|
+
paused: z.boolean(),
|
|
32
|
+
rwa: z.boolean()
|
|
33
|
+
});
|
|
34
|
+
/**
|
|
35
|
+
* {@link InstantReceivedAsset}
|
|
36
|
+
**/
|
|
37
|
+
const instantReceivedAssetSchema = z.object({
|
|
38
|
+
...tokenAmountSchema.shape,
|
|
39
|
+
isDelayed: z.literal(false)
|
|
40
|
+
});
|
|
41
|
+
/**
|
|
42
|
+
* {@link DelayedReceivedAsset}
|
|
43
|
+
**/
|
|
44
|
+
const delayedReceivedAssetSchema = z.object({
|
|
45
|
+
...tokenAmountSchema.shape,
|
|
46
|
+
isDelayed: z.literal(true),
|
|
47
|
+
redeemerAddress: ZodAddress().optional(),
|
|
48
|
+
claimableAt: timestampSchema.optional()
|
|
49
|
+
});
|
|
50
|
+
/**
|
|
51
|
+
* {@link ReceivedAsset}
|
|
52
|
+
**/
|
|
53
|
+
const receivedAssetSchema = z.discriminatedUnion("isDelayed", [instantReceivedAssetSchema, delayedReceivedAssetSchema]);
|
|
54
|
+
/**
|
|
55
|
+
* {@link LiquidationApproval}
|
|
56
|
+
**/
|
|
57
|
+
const liquidationApprovalSchema = tokenAmountSchema.extend({ spender: ZodAddress() });
|
|
58
|
+
/**
|
|
59
|
+
* {@link LiquidationPosition}
|
|
60
|
+
**/
|
|
61
|
+
const liquidationPositionSchema = z.object({
|
|
62
|
+
chainId: chainIdSchema,
|
|
63
|
+
sourceToken: tokenSchema,
|
|
64
|
+
output: tokenAmountSchema,
|
|
65
|
+
claimableAt: timestampSchema.optional(),
|
|
66
|
+
claimTx: txCallSchema.optional(),
|
|
67
|
+
redeemer: ZodAddress().optional()
|
|
68
|
+
});
|
|
69
|
+
/**
|
|
70
|
+
* {@link LiquidationDetails}
|
|
71
|
+
**/
|
|
72
|
+
const liquidationDetailsSchema = z.object({
|
|
73
|
+
...liquidatableAccountSchema.shape,
|
|
74
|
+
repaymentAmount: tokenAmountSchema,
|
|
75
|
+
receivedAssets: z.array(receivedAssetSchema),
|
|
76
|
+
isLiquidatorEligible: z.boolean(),
|
|
77
|
+
isCreditAccountFrozen: z.boolean(),
|
|
78
|
+
kycProtocol: z.string().optional(),
|
|
79
|
+
kycToken: tokenSchema.optional(),
|
|
80
|
+
approve: liquidationApprovalSchema.optional()
|
|
81
|
+
});
|
|
82
|
+
//#endregion
|
|
83
|
+
export { delayedReceivedAssetSchema, instantReceivedAssetSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionSchema, receivedAssetSchema };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
//#region src/model/opportunities.ts
|
|
2
|
+
/**
|
|
3
|
+
* Builds the canonical id of a pool opportunity.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* poolOpportunityId(1, "0xda00...") // "1:0xda00..."
|
|
8
|
+
* ```
|
|
9
|
+
**/
|
|
10
|
+
function poolOpportunityId(chainId, pool) {
|
|
11
|
+
return `${chainId}:${pool.toLowerCase()}`;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Builds the canonical id of a strategy opportunity.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* strategyOpportunityId(1, "0x3eb9...", "0x7f39...") // "1:0x3eb9...:0x7f39..."
|
|
19
|
+
* ```
|
|
20
|
+
**/
|
|
21
|
+
function strategyOpportunityId(chainId, creditManager, targetCollateral) {
|
|
22
|
+
return `${chainId}:${creditManager.toLowerCase()}:${targetCollateral.toLowerCase()}`;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Canonical id of any opportunity, dispatching on {@link Opportunity.kind}.
|
|
26
|
+
**/
|
|
27
|
+
function opportunityId(opportunity) {
|
|
28
|
+
return opportunity.kind === "pool" ? poolOpportunityId(opportunity.chainId, opportunity.pool) : strategyOpportunityId(opportunity.chainId, opportunity.creditManager, opportunity.targetCollateral.address);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Whether an opportunity satisfies every criterion of a filter.
|
|
32
|
+
*
|
|
33
|
+
* This is the single definition of what each criterion means: every source
|
|
34
|
+
* builds its rows first and runs them through here, so the chain and the
|
|
35
|
+
* backend cannot disagree on what a filter selects.
|
|
36
|
+
*
|
|
37
|
+
* @param opportunity - Row to test.
|
|
38
|
+
* @param filter - Criteria to test against. An absent filter matches anything.
|
|
39
|
+
**/
|
|
40
|
+
function matchesOpportunityFilter(opportunity, filter) {
|
|
41
|
+
if (!filter) return true;
|
|
42
|
+
if (filter.kind && opportunity.kind !== filter.kind) return false;
|
|
43
|
+
if (filter.chainIds && !filter.chainIds.includes(opportunity.chainId)) return false;
|
|
44
|
+
if (filter.underlyingType && opportunity.underlyingToken.assetType !== filter.underlyingType) return false;
|
|
45
|
+
if (filter.paused !== void 0 && opportunity.paused !== filter.paused) return false;
|
|
46
|
+
if (filter.sunset !== void 0 && opportunity.sunset !== filter.sunset) return false;
|
|
47
|
+
if (filter.rwa !== void 0 && opportunity.rwa !== filter.rwa) return false;
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { matchesOpportunityFilter, opportunityId, poolOpportunityId, strategyOpportunityId };
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { ZodAddress } from "../sdk/utils/zod.js";
|
|
2
|
+
import { amountSchema, assetTypeSchema, bpsSchema, chainIdSchema, curatorSchema, leverageSchema, timestampSchema, tokenSchema } from "./primitives.schema.js";
|
|
3
|
+
import { z } from "zod/v4";
|
|
4
|
+
//#region src/model/opportunities.schema.ts
|
|
5
|
+
/**
|
|
6
|
+
* Runtime schemas for {@link ./opportunities.js}, see the note in
|
|
7
|
+
* `primitives.schema.ts` on why they are written by hand.
|
|
8
|
+
**/
|
|
9
|
+
/**
|
|
10
|
+
* {@link OpportunityKind}
|
|
11
|
+
**/
|
|
12
|
+
const opportunityKindSchema = z.union([z.literal("pool"), z.literal("strategy")]);
|
|
13
|
+
/**
|
|
14
|
+
* {@link PointsProgram}
|
|
15
|
+
**/
|
|
16
|
+
const pointsProgramSchema = z.object({
|
|
17
|
+
id: z.string(),
|
|
18
|
+
name: z.string(),
|
|
19
|
+
multiplier: z.number().nullable()
|
|
20
|
+
});
|
|
21
|
+
/**
|
|
22
|
+
* {@link TokenRewards}
|
|
23
|
+
**/
|
|
24
|
+
const tokenRewardsSchema = z.object({
|
|
25
|
+
kind: z.literal("token"),
|
|
26
|
+
token: tokenSchema,
|
|
27
|
+
supplyApr: bpsSchema.optional(),
|
|
28
|
+
borrowApr: bpsSchema.optional()
|
|
29
|
+
});
|
|
30
|
+
/**
|
|
31
|
+
* {@link PointRewards}
|
|
32
|
+
**/
|
|
33
|
+
const pointRewardsSchema = z.object({
|
|
34
|
+
kind: z.literal("point"),
|
|
35
|
+
points: z.array(pointsProgramSchema)
|
|
36
|
+
});
|
|
37
|
+
/**
|
|
38
|
+
* {@link Rewards}
|
|
39
|
+
**/
|
|
40
|
+
const rewardsSchema = z.discriminatedUnion("kind", [tokenRewardsSchema, pointRewardsSchema]);
|
|
41
|
+
/**
|
|
42
|
+
* {@link ApyBreakdown}
|
|
43
|
+
**/
|
|
44
|
+
const apyBreakdownSchema = z.object({
|
|
45
|
+
totalApy: bpsSchema,
|
|
46
|
+
organicApy: bpsSchema,
|
|
47
|
+
rewards: z.array(rewardsSchema)
|
|
48
|
+
});
|
|
49
|
+
/**
|
|
50
|
+
* {@link OpportunityBase}
|
|
51
|
+
**/
|
|
52
|
+
const opportunityBaseSchema = z.object({
|
|
53
|
+
chainId: chainIdSchema,
|
|
54
|
+
title: z.string(),
|
|
55
|
+
curator: curatorSchema,
|
|
56
|
+
underlyingToken: tokenSchema,
|
|
57
|
+
totalSupply: amountSchema,
|
|
58
|
+
totalBorrow: amountSchema,
|
|
59
|
+
utilization: bpsSchema,
|
|
60
|
+
supplyApy: apyBreakdownSchema.optional(),
|
|
61
|
+
collateralTokens: z.array(tokenSchema),
|
|
62
|
+
paused: z.boolean(),
|
|
63
|
+
rwa: z.boolean(),
|
|
64
|
+
sunset: z.boolean()
|
|
65
|
+
});
|
|
66
|
+
/**
|
|
67
|
+
* {@link PoolOpportunity}
|
|
68
|
+
**/
|
|
69
|
+
const poolOpportunitySchema = z.object({
|
|
70
|
+
...opportunityBaseSchema.shape,
|
|
71
|
+
kind: z.literal("pool"),
|
|
72
|
+
pool: ZodAddress()
|
|
73
|
+
});
|
|
74
|
+
/**
|
|
75
|
+
* {@link StrategyOpportunity}
|
|
76
|
+
**/
|
|
77
|
+
const strategyOpportunitySchema = z.object({
|
|
78
|
+
...opportunityBaseSchema.shape,
|
|
79
|
+
kind: z.literal("strategy"),
|
|
80
|
+
creditManager: ZodAddress(),
|
|
81
|
+
targetCollateral: tokenSchema,
|
|
82
|
+
liquidationThreshold: bpsSchema,
|
|
83
|
+
liquidationPremium: bpsSchema,
|
|
84
|
+
liquidationFee: bpsSchema,
|
|
85
|
+
expirationDate: timestampSchema.nullable(),
|
|
86
|
+
collateralApy: apyBreakdownSchema.optional(),
|
|
87
|
+
borrowApy: bpsSchema.optional(),
|
|
88
|
+
additionalBorrowApy: bpsSchema.optional(),
|
|
89
|
+
maxBorrowAmount: amountSchema,
|
|
90
|
+
maxLeverage: leverageSchema
|
|
91
|
+
});
|
|
92
|
+
/**
|
|
93
|
+
* {@link Opportunity}
|
|
94
|
+
**/
|
|
95
|
+
const opportunitySchema = z.discriminatedUnion("kind", [poolOpportunitySchema, strategyOpportunitySchema]);
|
|
96
|
+
/**
|
|
97
|
+
* {@link OpportunityFilter}
|
|
98
|
+
**/
|
|
99
|
+
const opportunityFilterSchema = z.object({
|
|
100
|
+
kind: opportunityKindSchema.optional(),
|
|
101
|
+
chainIds: z.array(chainIdSchema).optional(),
|
|
102
|
+
underlyingType: assetTypeSchema.optional(),
|
|
103
|
+
paused: z.boolean().optional(),
|
|
104
|
+
sunset: z.boolean().optional(),
|
|
105
|
+
rwa: z.boolean().optional()
|
|
106
|
+
});
|
|
107
|
+
/**
|
|
108
|
+
* {@link RateCurvePoint}
|
|
109
|
+
**/
|
|
110
|
+
const rateCurvePointSchema = z.object({
|
|
111
|
+
utilization: bpsSchema,
|
|
112
|
+
supplyApy: bpsSchema,
|
|
113
|
+
borrowApy: bpsSchema
|
|
114
|
+
});
|
|
115
|
+
/**
|
|
116
|
+
* {@link RateCurve}
|
|
117
|
+
**/
|
|
118
|
+
const rateCurveSchema = z.object({
|
|
119
|
+
points: z.array(rateCurvePointSchema),
|
|
120
|
+
borrowingLimitUtilization: bpsSchema.nullable()
|
|
121
|
+
});
|
|
122
|
+
/**
|
|
123
|
+
* {@link QuotaAsset}
|
|
124
|
+
**/
|
|
125
|
+
const quotaAssetSchema = z.object({
|
|
126
|
+
token: tokenSchema,
|
|
127
|
+
quotaRate: bpsSchema,
|
|
128
|
+
limit: amountSchema,
|
|
129
|
+
used: amountSchema
|
|
130
|
+
});
|
|
131
|
+
/**
|
|
132
|
+
* {@link PriceFeedData}. Recursive: a composite feed lists the feeds it reads.
|
|
133
|
+
**/
|
|
134
|
+
const priceFeedDataSchema = z.object({
|
|
135
|
+
name: z.string(),
|
|
136
|
+
type: z.string(),
|
|
137
|
+
feedAddress: ZodAddress(),
|
|
138
|
+
get dependencies() {
|
|
139
|
+
return z.array(priceFeedDataSchema);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
/**
|
|
143
|
+
* {@link PriceFeedSummary}
|
|
144
|
+
**/
|
|
145
|
+
const priceFeedSummarySchema = z.object({
|
|
146
|
+
underlyingPriceInUsd: z.number(),
|
|
147
|
+
collateralPriceInUsd: z.number(),
|
|
148
|
+
collateralPriceInUnderlying: z.number(),
|
|
149
|
+
underlyingFeed: priceFeedDataSchema,
|
|
150
|
+
collateralFeed: priceFeedDataSchema
|
|
151
|
+
});
|
|
152
|
+
/**
|
|
153
|
+
* {@link PoolOpportunityDetail}
|
|
154
|
+
**/
|
|
155
|
+
const poolOpportunityDetailSchema = z.object({
|
|
156
|
+
...poolOpportunitySchema.shape,
|
|
157
|
+
rateCurve: rateCurveSchema,
|
|
158
|
+
quotaAssets: z.array(quotaAssetSchema)
|
|
159
|
+
});
|
|
160
|
+
/**
|
|
161
|
+
* {@link StrategyOpportunityDetail}
|
|
162
|
+
**/
|
|
163
|
+
const strategyOpportunityDetailSchema = z.object({
|
|
164
|
+
...strategyOpportunitySchema.shape,
|
|
165
|
+
rateCurve: rateCurveSchema,
|
|
166
|
+
priceFeeds: priceFeedSummarySchema
|
|
167
|
+
});
|
|
168
|
+
/**
|
|
169
|
+
* {@link OpportunityDetail}
|
|
170
|
+
**/
|
|
171
|
+
const opportunityDetailSchema = z.discriminatedUnion("kind", [poolOpportunityDetailSchema, strategyOpportunityDetailSchema]);
|
|
172
|
+
/**
|
|
173
|
+
* {@link PoolOpportunityKey}
|
|
174
|
+
**/
|
|
175
|
+
const poolOpportunityKeySchema = z.object({
|
|
176
|
+
chainId: chainIdSchema,
|
|
177
|
+
pool: ZodAddress()
|
|
178
|
+
});
|
|
179
|
+
/**
|
|
180
|
+
* {@link StrategyOpportunityKey}
|
|
181
|
+
**/
|
|
182
|
+
const strategyOpportunityKeySchema = z.object({
|
|
183
|
+
chainId: chainIdSchema,
|
|
184
|
+
creditManager: ZodAddress(),
|
|
185
|
+
targetCollateral: ZodAddress()
|
|
186
|
+
});
|
|
187
|
+
/**
|
|
188
|
+
* {@link OpportunityKey}
|
|
189
|
+
**/
|
|
190
|
+
const opportunityKeySchema = z.discriminatedUnion("kind", [z.object({
|
|
191
|
+
kind: z.literal("pool"),
|
|
192
|
+
...poolOpportunityKeySchema.shape
|
|
193
|
+
}), z.object({
|
|
194
|
+
kind: z.literal("strategy"),
|
|
195
|
+
...strategyOpportunityKeySchema.shape
|
|
196
|
+
})]);
|
|
197
|
+
//#endregion
|
|
198
|
+
export { apyBreakdownSchema, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterSchema, opportunityKeySchema, opportunityKindSchema, opportunitySchema, pointRewardsSchema, pointsProgramSchema, poolOpportunityDetailSchema, poolOpportunityKeySchema, poolOpportunitySchema, priceFeedDataSchema, priceFeedSummarySchema, quotaAssetSchema, rateCurvePointSchema, rateCurveSchema, rewardsSchema, strategyOpportunityDetailSchema, strategyOpportunityKeySchema, strategyOpportunitySchema, tokenRewardsSchema };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type": "module","sideEffects":false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { ZodAddress, ZodHex } from "../sdk/utils/zod.js";
|
|
2
|
+
import { z } from "zod/v4";
|
|
3
|
+
//#region src/model/primitives.schema.ts
|
|
4
|
+
/**
|
|
5
|
+
* Runtime schemas for {@link ./primitives.js}.
|
|
6
|
+
*
|
|
7
|
+
* The hand-written types are the contract; these schemas exist so the offchain
|
|
8
|
+
* client can reject a backend response that no longer matches it. The two are
|
|
9
|
+
* kept in sync by the type-level tests in `model.test-d.ts`, not by inferring
|
|
10
|
+
* one from the other.
|
|
11
|
+
**/
|
|
12
|
+
/**
|
|
13
|
+
* {@link ChainId}
|
|
14
|
+
**/
|
|
15
|
+
const chainIdSchema = z.number().int().positive();
|
|
16
|
+
/**
|
|
17
|
+
* {@link Timestamp}
|
|
18
|
+
**/
|
|
19
|
+
const timestampSchema = z.number().int().nonnegative();
|
|
20
|
+
/**
|
|
21
|
+
* {@link Bps}. Integer, not bounded to `0..10000`: rates may exceed 100%.
|
|
22
|
+
**/
|
|
23
|
+
const bpsSchema = z.number().int();
|
|
24
|
+
/**
|
|
25
|
+
* {@link AssetType}
|
|
26
|
+
**/
|
|
27
|
+
const assetTypeSchema = z.union([
|
|
28
|
+
z.literal("Stable"),
|
|
29
|
+
z.literal("ETH"),
|
|
30
|
+
z.literal("BTC")
|
|
31
|
+
]);
|
|
32
|
+
/**
|
|
33
|
+
* {@link Leverage}
|
|
34
|
+
**/
|
|
35
|
+
const leverageSchema = z.number().positive();
|
|
36
|
+
/**
|
|
37
|
+
* {@link Amount}
|
|
38
|
+
**/
|
|
39
|
+
const amountSchema = z.object({
|
|
40
|
+
value: z.bigint(),
|
|
41
|
+
valueUsd: z.number().nullable()
|
|
42
|
+
});
|
|
43
|
+
/**
|
|
44
|
+
* {@link Token}
|
|
45
|
+
**/
|
|
46
|
+
const tokenSchema = z.object({
|
|
47
|
+
chainId: chainIdSchema,
|
|
48
|
+
address: ZodAddress(),
|
|
49
|
+
symbol: z.string(),
|
|
50
|
+
name: z.string(),
|
|
51
|
+
decimals: z.number().int().nonnegative(),
|
|
52
|
+
assetType: assetTypeSchema.optional()
|
|
53
|
+
});
|
|
54
|
+
/**
|
|
55
|
+
* {@link TokenAmount}
|
|
56
|
+
**/
|
|
57
|
+
const tokenAmountSchema = amountSchema.extend({ token: tokenSchema });
|
|
58
|
+
/**
|
|
59
|
+
* {@link TxCall}
|
|
60
|
+
**/
|
|
61
|
+
const txCallSchema = z.object({
|
|
62
|
+
to: ZodAddress(),
|
|
63
|
+
callData: ZodHex(),
|
|
64
|
+
value: z.bigint().optional()
|
|
65
|
+
});
|
|
66
|
+
/**
|
|
67
|
+
* {@link Curator}
|
|
68
|
+
**/
|
|
69
|
+
const curatorSchema = z.object({
|
|
70
|
+
address: ZodAddress(),
|
|
71
|
+
name: z.string(),
|
|
72
|
+
url: z.string().nullable()
|
|
73
|
+
});
|
|
74
|
+
//#endregion
|
|
75
|
+
export { amountSchema, assetTypeSchema, bpsSchema, chainIdSchema, curatorSchema, leverageSchema, timestampSchema, tokenAmountSchema, tokenSchema, txCallSchema };
|