@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.
Files changed (249) hide show
  1. package/dist/cjs/common-utils/index.js +2 -2
  2. package/dist/cjs/common-utils/utils/apy/calculate-safe-borrow-rate.js +3 -3
  3. package/dist/cjs/common-utils/utils/assets-math.js +7 -7
  4. package/dist/cjs/common-utils/utils/creditAccount/calc-health-factor.js +2 -2
  5. package/dist/cjs/common-utils/utils/creditAccount/debt.js +2 -2
  6. package/dist/cjs/common-utils/utils/creditAccount/quota-utils.js +5 -5
  7. package/dist/cjs/common-utils/utils/index.js +2 -2
  8. package/dist/cjs/common-utils/utils/strategies/leverage/calculate-max-leverage-factor.js +2 -2
  9. package/dist/cjs/common-utils/utils/strategies/leverage/calculate-max-strategy-debt.js +5 -5
  10. package/dist/cjs/common-utils/utils/strategies/strategy-info/calculate-total-points.js +2 -2
  11. package/dist/cjs/common-utils/utils/strategies/strategy-info/get-cm-you-can-earn.js +2 -2
  12. package/dist/cjs/common-utils/utils/validation/validate-open-account-pool-status.js +4 -4
  13. package/dist/cjs/dev/index.js +2 -1
  14. package/dist/cjs/dev/kycUtils.js +1 -1
  15. package/dist/cjs/dev/midasUtils.js +104 -0
  16. package/dist/cjs/model/history.js +28 -0
  17. package/dist/cjs/model/history.schema.js +84 -0
  18. package/dist/cjs/model/index.js +64 -0
  19. package/dist/cjs/model/liquidations.js +23 -0
  20. package/dist/cjs/model/liquidations.schema.js +91 -0
  21. package/dist/cjs/model/opportunities.js +55 -0
  22. package/dist/cjs/model/opportunities.schema.js +220 -0
  23. package/dist/cjs/model/package.json +1 -0
  24. package/dist/cjs/model/positions.js +1 -0
  25. package/dist/cjs/model/primitives.js +1 -0
  26. package/dist/cjs/model/primitives.schema.js +85 -0
  27. package/dist/cjs/new-sdk/AbstractNamespace.js +158 -0
  28. package/dist/cjs/new-sdk/GearboxSDK.js +122 -0
  29. package/dist/cjs/new-sdk/index.js +11 -0
  30. package/dist/cjs/new-sdk/opportunities/OpportunitiesNamespace.js +122 -0
  31. package/dist/cjs/new-sdk/opportunities/index.js +4 -0
  32. package/dist/cjs/new-sdk/opportunities/types.js +1 -0
  33. package/dist/cjs/new-sdk/package.json +1 -0
  34. package/dist/cjs/new-sdk/types.js +22 -0
  35. package/dist/cjs/new-sdk/utils/history.js +1 -0
  36. package/dist/cjs/new-sdk/utils/index.js +2 -0
  37. package/dist/cjs/offchain/GearboxAPI.js +33 -0
  38. package/dist/cjs/offchain/index.js +8 -0
  39. package/dist/cjs/offchain/opportunities/OffchainOpportunities.js +97 -0
  40. package/dist/cjs/offchain/opportunities/index.js +4 -0
  41. package/dist/cjs/offchain/package.json +1 -0
  42. package/dist/cjs/offchain/types.js +1 -0
  43. package/dist/cjs/preview/preview/buildDelayedPreview.js +5 -5
  44. package/dist/cjs/rewards/rewards/api.js +2 -2
  45. package/dist/cjs/rewards/rewards/extra-apy.js +2 -2
  46. package/dist/cjs/sdk/MultichainSDK.js +18 -2
  47. package/dist/cjs/sdk/OnchainSDK.js +8 -1
  48. package/dist/cjs/sdk/accounts/index.js +2 -0
  49. package/dist/cjs/sdk/accounts/liquidations/LiquidationsService.js +150 -106
  50. package/dist/cjs/sdk/accounts/liquidations/MultichainLiquidationsService.js +32 -38
  51. package/dist/cjs/sdk/accounts/liquidations/constants.js +13 -0
  52. package/dist/cjs/sdk/accounts/liquidations/index.js +2 -0
  53. package/dist/cjs/sdk/base/MultichainConstruct.js +80 -0
  54. package/dist/cjs/sdk/base/TokensMeta.js +51 -0
  55. package/dist/cjs/sdk/base/index.js +2 -0
  56. package/dist/cjs/sdk/chain/chains.js +76 -0
  57. package/dist/cjs/sdk/chain/index.js +4 -0
  58. package/dist/cjs/sdk/core/errors.js +13 -0
  59. package/dist/cjs/sdk/core/index.js +2 -1
  60. package/dist/cjs/sdk/index.js +25 -1
  61. package/dist/cjs/sdk/market/MarketConfiguratorContract.js +14 -0
  62. package/dist/cjs/sdk/market/MarketSuite.js +163 -0
  63. package/dist/cjs/sdk/market/credit/CreditManagerV310Contract.js +26 -0
  64. package/dist/cjs/sdk/market/credit/CreditSuite.js +102 -0
  65. package/dist/cjs/sdk/market/math.js +104 -0
  66. package/dist/cjs/sdk/market/oracle/PriceOracleBaseContract.js +52 -0
  67. package/dist/cjs/sdk/market/pool/LinearInterestRateModelContract.js +30 -0
  68. package/dist/cjs/sdk/market/pool/PoolQuotaKeeperV310Contract.js +26 -0
  69. package/dist/cjs/sdk/market/pool/PoolSuite.js +28 -0
  70. package/dist/cjs/sdk/market/pool/PoolV310Contract.js +27 -0
  71. package/dist/cjs/sdk/market/pool/math.js +44 -0
  72. package/dist/cjs/sdk/market/pricefeeds/AbstractPriceFeed.js +17 -0
  73. package/dist/cjs/sdk/opportunities/MultichainOpportunitiesService.js +60 -0
  74. package/dist/cjs/sdk/opportunities/OpportunitiesService.js +103 -0
  75. package/dist/cjs/sdk/opportunities/index.js +12 -0
  76. package/dist/cjs/sdk/types/multichain.js +1 -0
  77. package/dist/cjs/{common-utils → sdk}/utils/bigint-math.js +11 -11
  78. package/dist/cjs/sdk/utils/index.js +3 -0
  79. package/dist/cjs/sdk/utils/zod.js +12 -0
  80. package/dist/esm/common-utils/index.js +1 -1
  81. package/dist/esm/common-utils/utils/apy/calculate-safe-borrow-rate.js +1 -1
  82. package/dist/esm/common-utils/utils/assets-math.js +1 -1
  83. package/dist/esm/common-utils/utils/creditAccount/calc-health-factor.js +1 -1
  84. package/dist/esm/common-utils/utils/creditAccount/debt.js +1 -1
  85. package/dist/esm/common-utils/utils/creditAccount/quota-utils.js +1 -1
  86. package/dist/esm/common-utils/utils/index.js +1 -1
  87. package/dist/esm/common-utils/utils/strategies/leverage/calculate-max-leverage-factor.js +1 -1
  88. package/dist/esm/common-utils/utils/strategies/leverage/calculate-max-strategy-debt.js +1 -1
  89. package/dist/esm/common-utils/utils/strategies/strategy-info/calculate-total-points.js +1 -1
  90. package/dist/esm/common-utils/utils/strategies/strategy-info/get-cm-you-can-earn.js +1 -1
  91. package/dist/esm/common-utils/utils/validation/validate-open-account-pool-status.js +1 -1
  92. package/dist/esm/dev/AccountOpener.js +1 -1
  93. package/dist/esm/dev/index.js +3 -3
  94. package/dist/esm/dev/kycUtils.js +1 -1
  95. package/dist/esm/dev/midasUtils.js +105 -2
  96. package/dist/esm/dev/withdrawalUtils.js +1 -1
  97. package/dist/esm/model/history.js +26 -0
  98. package/dist/esm/model/history.schema.js +76 -0
  99. package/dist/esm/model/index.js +9 -0
  100. package/dist/esm/model/liquidations.js +22 -0
  101. package/dist/esm/model/liquidations.schema.js +83 -0
  102. package/dist/esm/model/opportunities.js +51 -0
  103. package/dist/esm/model/opportunities.schema.js +198 -0
  104. package/dist/esm/model/package.json +1 -0
  105. package/dist/esm/model/positions.js +1 -0
  106. package/dist/esm/model/primitives.js +1 -0
  107. package/dist/esm/model/primitives.schema.js +75 -0
  108. package/dist/esm/new-sdk/AbstractNamespace.js +157 -0
  109. package/dist/esm/new-sdk/GearboxSDK.js +121 -0
  110. package/dist/esm/new-sdk/index.js +7 -0
  111. package/dist/esm/new-sdk/opportunities/OpportunitiesNamespace.js +121 -0
  112. package/dist/esm/new-sdk/opportunities/index.js +3 -0
  113. package/dist/esm/new-sdk/opportunities/types.js +1 -0
  114. package/dist/esm/new-sdk/package.json +1 -0
  115. package/dist/esm/new-sdk/types.js +21 -0
  116. package/dist/esm/new-sdk/utils/history.js +1 -0
  117. package/dist/esm/new-sdk/utils/index.js +2 -0
  118. package/dist/esm/offchain/GearboxAPI.js +32 -0
  119. package/dist/esm/offchain/index.js +5 -0
  120. package/dist/esm/offchain/opportunities/OffchainOpportunities.js +95 -0
  121. package/dist/esm/offchain/opportunities/index.js +2 -0
  122. package/dist/esm/offchain/package.json +1 -0
  123. package/dist/esm/offchain/types.js +1 -0
  124. package/dist/esm/preview/preview/buildDelayedPreview.js +1 -1
  125. package/dist/esm/preview/simulate/simulatePoolOperation.js +1 -1
  126. package/dist/esm/preview/trace/extractTransfers.js +1 -1
  127. package/dist/esm/rewards/rewards/api.js +1 -1
  128. package/dist/esm/rewards/rewards/extra-apy.js +1 -1
  129. package/dist/esm/sdk/MultichainSDK.js +18 -2
  130. package/dist/esm/sdk/OnchainSDK.js +8 -1
  131. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +2 -2
  132. package/dist/esm/sdk/accounts/index.js +2 -2
  133. package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +153 -109
  134. package/dist/esm/sdk/accounts/liquidations/MultichainLiquidationsService.js +32 -38
  135. package/dist/esm/sdk/accounts/liquidations/constants.js +12 -1
  136. package/dist/esm/sdk/accounts/liquidations/index.js +2 -2
  137. package/dist/esm/sdk/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
  138. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
  139. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
  140. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
  141. package/dist/esm/sdk/base/MultichainConstruct.js +79 -0
  142. package/dist/esm/sdk/base/TokensMeta.js +53 -2
  143. package/dist/esm/sdk/base/index.js +2 -1
  144. package/dist/esm/sdk/chain/chains.js +74 -2
  145. package/dist/esm/sdk/chain/detectNetwork.js +1 -1
  146. package/dist/esm/sdk/chain/index.js +2 -2
  147. package/dist/esm/sdk/core/createAddressProvider.js +1 -1
  148. package/dist/esm/sdk/core/errors.js +13 -1
  149. package/dist/esm/sdk/core/index.js +2 -2
  150. package/dist/esm/sdk/index.js +11 -5
  151. package/dist/esm/sdk/market/MarketConfiguratorContract.js +14 -0
  152. package/dist/esm/sdk/market/MarketSuite.js +163 -0
  153. package/dist/esm/sdk/market/credit/CreditFacadeV310BaseContract.js +1 -1
  154. package/dist/esm/sdk/market/credit/CreditManagerV310Contract.js +26 -0
  155. package/dist/esm/sdk/market/credit/CreditSuite.js +102 -0
  156. package/dist/esm/sdk/market/math.js +98 -0
  157. package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +52 -0
  158. package/dist/esm/sdk/market/pool/LinearInterestRateModelContract.js +30 -0
  159. package/dist/esm/sdk/market/pool/PoolQuotaKeeperV310Contract.js +26 -0
  160. package/dist/esm/sdk/market/pool/PoolSuite.js +28 -0
  161. package/dist/esm/sdk/market/pool/PoolV310Contract.js +28 -1
  162. package/dist/esm/sdk/market/pool/math.js +41 -0
  163. package/dist/esm/sdk/market/pricefeeds/AbstractPriceFeed.js +17 -0
  164. package/dist/esm/sdk/market/zapper/IETHZapperContract.js +1 -1
  165. package/dist/esm/sdk/market/zapper/ZapperContract.js +1 -1
  166. package/dist/esm/sdk/opportunities/MultichainOpportunitiesService.js +59 -0
  167. package/dist/esm/sdk/opportunities/OpportunitiesService.js +102 -0
  168. package/dist/esm/sdk/opportunities/index.js +4 -0
  169. package/dist/esm/sdk/pools/PoolService.js +1 -1
  170. package/dist/esm/sdk/types/multichain.js +1 -0
  171. package/dist/esm/{common-utils → sdk}/utils/bigint-math.js +11 -11
  172. package/dist/esm/sdk/utils/index.js +3 -2
  173. package/dist/esm/sdk/utils/viem/simulateWithPriceUpdates.js +1 -1
  174. package/dist/esm/sdk/utils/zod.js +13 -2
  175. package/dist/types/common-utils/index.d.ts +1 -1
  176. package/dist/types/common-utils/utils/index.d.ts +1 -1
  177. package/dist/types/dev/index.d.ts +2 -2
  178. package/dist/types/dev/midasUtils.d.ts +31 -2
  179. package/dist/types/model/history.d.ts +105 -0
  180. package/dist/types/model/history.schema.d.ts +66 -0
  181. package/dist/types/model/index.d.ts +9 -0
  182. package/dist/types/model/liquidations.d.ts +230 -0
  183. package/dist/types/model/liquidations.schema.d.ts +292 -0
  184. package/dist/types/model/opportunities.d.ts +543 -0
  185. package/dist/types/model/opportunities.schema.d.ts +1066 -0
  186. package/dist/types/model/positions.d.ts +11 -0
  187. package/dist/types/model/primitives.d.ts +193 -0
  188. package/dist/types/model/primitives.schema.d.ts +81 -0
  189. package/dist/types/new-sdk/AbstractNamespace.d.ts +119 -0
  190. package/dist/types/new-sdk/GearboxSDK.d.ts +78 -0
  191. package/dist/types/new-sdk/index.d.ts +9 -0
  192. package/dist/types/new-sdk/opportunities/OpportunitiesNamespace.d.ts +69 -0
  193. package/dist/types/new-sdk/opportunities/index.d.ts +3 -0
  194. package/dist/types/new-sdk/opportunities/types.d.ts +66 -0
  195. package/dist/types/new-sdk/types.d.ts +149 -0
  196. package/dist/types/new-sdk/utils/history.d.ts +44 -0
  197. package/dist/types/new-sdk/utils/index.d.ts +2 -0
  198. package/dist/types/offchain/GearboxAPI.d.ts +31 -0
  199. package/dist/types/offchain/index.d.ts +5 -0
  200. package/dist/types/offchain/opportunities/OffchainOpportunities.d.ts +69 -0
  201. package/dist/types/offchain/opportunities/index.d.ts +2 -0
  202. package/dist/types/offchain/types.d.ts +50 -0
  203. package/dist/types/sdk/MultichainSDK.d.ts +15 -2
  204. package/dist/types/sdk/OnchainSDK.d.ts +9 -3
  205. package/dist/types/sdk/accounts/index.d.ts +3 -3
  206. package/dist/types/sdk/accounts/liquidations/LiquidationsService.d.ts +24 -16
  207. package/dist/types/sdk/accounts/liquidations/MultichainLiquidationsService.d.ts +26 -20
  208. package/dist/types/sdk/accounts/liquidations/constants.d.ts +12 -1
  209. package/dist/types/sdk/accounts/liquidations/index.d.ts +3 -3
  210. package/dist/types/sdk/accounts/liquidations/types.d.ts +34 -309
  211. package/dist/types/sdk/base/MultichainConstruct.d.ts +57 -0
  212. package/dist/types/sdk/base/TokensMeta.d.ts +26 -0
  213. package/dist/types/sdk/base/index.d.ts +2 -1
  214. package/dist/types/sdk/chain/chains.d.ts +68 -1
  215. package/dist/types/sdk/chain/index.d.ts +2 -2
  216. package/dist/types/sdk/core/errors.d.ts +10 -1
  217. package/dist/types/sdk/core/index.d.ts +2 -2
  218. package/dist/types/sdk/index.d.ts +15 -8
  219. package/dist/types/sdk/market/MarketConfiguratorContract.d.ts +9 -0
  220. package/dist/types/sdk/market/MarketSuite.d.ts +109 -1
  221. package/dist/types/sdk/market/credit/CreditManagerV310Contract.d.ts +14 -0
  222. package/dist/types/sdk/market/credit/CreditSuite.d.ts +47 -0
  223. package/dist/types/sdk/market/credit/types.d.ts +22 -0
  224. package/dist/types/sdk/market/index.d.ts +2 -2
  225. package/dist/types/sdk/market/math.d.ts +74 -0
  226. package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +23 -0
  227. package/dist/types/sdk/market/oracle/types.d.ts +46 -0
  228. package/dist/types/sdk/market/pool/LinearInterestRateModelContract.d.ts +12 -0
  229. package/dist/types/sdk/market/pool/PoolQuotaKeeperV310Contract.d.ts +22 -1
  230. package/dist/types/sdk/market/pool/PoolSuite.d.ts +23 -0
  231. package/dist/types/sdk/market/pool/PoolV310Contract.d.ts +18 -0
  232. package/dist/types/sdk/market/pool/math.d.ts +57 -0
  233. package/dist/types/sdk/market/pool/types.d.ts +23 -0
  234. package/dist/types/sdk/market/pricefeeds/AbstractPriceFeed.d.ts +6 -0
  235. package/dist/types/sdk/market/pricefeeds/types.d.ts +10 -0
  236. package/dist/types/sdk/opportunities/MultichainOpportunitiesService.d.ts +40 -0
  237. package/dist/types/sdk/opportunities/OpportunitiesService.d.ts +47 -0
  238. package/dist/types/sdk/opportunities/index.d.ts +4 -0
  239. package/dist/types/sdk/types/index.d.ts +2 -1
  240. package/dist/types/sdk/types/multichain.d.ts +65 -0
  241. package/dist/types/sdk/types/state.d.ts +1 -1
  242. package/dist/types/sdk/types/transactions.d.ts +3 -0
  243. package/dist/types/{common-utils → sdk}/utils/bigint-math.d.ts +7 -11
  244. package/dist/types/sdk/utils/index.d.ts +3 -2
  245. package/dist/types/sdk/utils/zod.d.ts +6 -2
  246. package/package.json +16 -1
  247. package/dist/cjs/sdk/accounts/liquidations/helpers.js +0 -201
  248. package/dist/esm/sdk/accounts/liquidations/helpers.js +0 -192
  249. 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 };