@gearbox-protocol/sdk 14.12.0-next.66 → 14.12.0-next.68

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 (244) 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/model/history.js +28 -0
  14. package/dist/cjs/model/history.schema.js +84 -0
  15. package/dist/cjs/model/index.js +77 -0
  16. package/dist/cjs/model/liquidations.js +23 -0
  17. package/dist/cjs/model/liquidations.schema.js +93 -0
  18. package/dist/cjs/model/opportunities.js +55 -0
  19. package/dist/cjs/model/opportunities.schema.js +223 -0
  20. package/dist/cjs/model/package.json +1 -0
  21. package/dist/cjs/model/positions.js +1 -0
  22. package/dist/cjs/model/positions.schema.js +120 -0
  23. package/dist/cjs/model/primitives.js +1 -0
  24. package/dist/cjs/model/primitives.schema.js +85 -0
  25. package/dist/cjs/new-sdk/AbstractNamespace.js +158 -0
  26. package/dist/cjs/new-sdk/GearboxSDK.js +122 -0
  27. package/dist/cjs/new-sdk/index.js +11 -0
  28. package/dist/cjs/new-sdk/opportunities/OpportunitiesNamespace.js +122 -0
  29. package/dist/cjs/new-sdk/opportunities/index.js +4 -0
  30. package/dist/cjs/new-sdk/opportunities/types.js +1 -0
  31. package/dist/cjs/new-sdk/package.json +1 -0
  32. package/dist/cjs/new-sdk/types.js +22 -0
  33. package/dist/cjs/new-sdk/utils/history.js +1 -0
  34. package/dist/cjs/new-sdk/utils/index.js +2 -0
  35. package/dist/cjs/offchain/GearboxAPI.js +33 -0
  36. package/dist/cjs/offchain/index.js +8 -0
  37. package/dist/cjs/offchain/opportunities/OffchainOpportunities.js +97 -0
  38. package/dist/cjs/offchain/opportunities/index.js +4 -0
  39. package/dist/cjs/offchain/package.json +1 -0
  40. package/dist/cjs/offchain/types.js +1 -0
  41. package/dist/cjs/preview/preview/buildDelayedPreview.js +5 -5
  42. package/dist/cjs/rewards/rewards/api.js +2 -2
  43. package/dist/cjs/rewards/rewards/extra-apy.js +2 -2
  44. package/dist/cjs/sdk/MultichainSDK.js +18 -2
  45. package/dist/cjs/sdk/OnchainSDK.js +8 -1
  46. package/dist/cjs/sdk/accounts/index.js +2 -0
  47. package/dist/cjs/sdk/accounts/liquidations/LiquidationsService.js +161 -106
  48. package/dist/cjs/sdk/accounts/liquidations/MultichainLiquidationsService.js +32 -38
  49. package/dist/cjs/sdk/accounts/liquidations/constants.js +13 -0
  50. package/dist/cjs/sdk/accounts/liquidations/index.js +2 -0
  51. package/dist/cjs/sdk/base/MultichainConstruct.js +80 -0
  52. package/dist/cjs/sdk/base/TokensMeta.js +51 -0
  53. package/dist/cjs/sdk/base/index.js +2 -0
  54. package/dist/cjs/sdk/chain/chains.js +76 -0
  55. package/dist/cjs/sdk/chain/index.js +4 -0
  56. package/dist/cjs/sdk/core/errors.js +13 -0
  57. package/dist/cjs/sdk/core/index.js +2 -1
  58. package/dist/cjs/sdk/index.js +25 -1
  59. package/dist/cjs/sdk/market/MarketConfiguratorContract.js +14 -0
  60. package/dist/cjs/sdk/market/MarketSuite.js +159 -0
  61. package/dist/cjs/sdk/market/credit/CreditManagerV310Contract.js +26 -0
  62. package/dist/cjs/sdk/market/credit/CreditSuite.js +92 -0
  63. package/dist/cjs/sdk/market/math.js +104 -0
  64. package/dist/cjs/sdk/market/oracle/PriceOracleBaseContract.js +52 -0
  65. package/dist/cjs/sdk/market/pool/LinearInterestRateModelContract.js +30 -0
  66. package/dist/cjs/sdk/market/pool/PoolQuotaKeeperV310Contract.js +26 -0
  67. package/dist/cjs/sdk/market/pool/PoolSuite.js +28 -0
  68. package/dist/cjs/sdk/market/pool/PoolV310Contract.js +27 -0
  69. package/dist/cjs/sdk/market/pool/math.js +44 -0
  70. package/dist/cjs/sdk/market/pricefeeds/AbstractPriceFeed.js +17 -0
  71. package/dist/cjs/sdk/opportunities/MultichainOpportunitiesService.js +60 -0
  72. package/dist/cjs/sdk/opportunities/OpportunitiesService.js +48 -0
  73. package/dist/cjs/sdk/opportunities/index.js +12 -0
  74. package/dist/cjs/sdk/types/multichain.js +1 -0
  75. package/dist/cjs/{common-utils → sdk}/utils/bigint-math.js +11 -11
  76. package/dist/cjs/sdk/utils/index.js +3 -0
  77. package/dist/cjs/sdk/utils/zod.js +12 -0
  78. package/dist/esm/common-utils/index.js +1 -1
  79. package/dist/esm/common-utils/utils/apy/calculate-safe-borrow-rate.js +1 -1
  80. package/dist/esm/common-utils/utils/assets-math.js +1 -1
  81. package/dist/esm/common-utils/utils/creditAccount/calc-health-factor.js +1 -1
  82. package/dist/esm/common-utils/utils/creditAccount/debt.js +1 -1
  83. package/dist/esm/common-utils/utils/creditAccount/quota-utils.js +1 -1
  84. package/dist/esm/common-utils/utils/index.js +1 -1
  85. package/dist/esm/common-utils/utils/strategies/leverage/calculate-max-leverage-factor.js +1 -1
  86. package/dist/esm/common-utils/utils/strategies/leverage/calculate-max-strategy-debt.js +1 -1
  87. package/dist/esm/common-utils/utils/strategies/strategy-info/calculate-total-points.js +1 -1
  88. package/dist/esm/common-utils/utils/strategies/strategy-info/get-cm-you-can-earn.js +1 -1
  89. package/dist/esm/common-utils/utils/validation/validate-open-account-pool-status.js +1 -1
  90. package/dist/esm/dev/AccountOpener.js +1 -1
  91. package/dist/esm/dev/withdrawalUtils.js +1 -1
  92. package/dist/esm/model/history.js +26 -0
  93. package/dist/esm/model/history.schema.js +76 -0
  94. package/dist/esm/model/index.js +11 -0
  95. package/dist/esm/model/liquidations.js +22 -0
  96. package/dist/esm/model/liquidations.schema.js +85 -0
  97. package/dist/esm/model/opportunities.js +51 -0
  98. package/dist/esm/model/opportunities.schema.js +201 -0
  99. package/dist/esm/model/package.json +1 -0
  100. package/dist/esm/model/positions.js +1 -0
  101. package/dist/esm/model/positions.schema.js +109 -0
  102. package/dist/esm/model/primitives.js +1 -0
  103. package/dist/esm/model/primitives.schema.js +75 -0
  104. package/dist/esm/new-sdk/AbstractNamespace.js +157 -0
  105. package/dist/esm/new-sdk/GearboxSDK.js +121 -0
  106. package/dist/esm/new-sdk/index.js +7 -0
  107. package/dist/esm/new-sdk/opportunities/OpportunitiesNamespace.js +121 -0
  108. package/dist/esm/new-sdk/opportunities/index.js +3 -0
  109. package/dist/esm/new-sdk/opportunities/types.js +1 -0
  110. package/dist/esm/new-sdk/package.json +1 -0
  111. package/dist/esm/new-sdk/types.js +21 -0
  112. package/dist/esm/new-sdk/utils/history.js +1 -0
  113. package/dist/esm/new-sdk/utils/index.js +2 -0
  114. package/dist/esm/offchain/GearboxAPI.js +32 -0
  115. package/dist/esm/offchain/index.js +5 -0
  116. package/dist/esm/offchain/opportunities/OffchainOpportunities.js +95 -0
  117. package/dist/esm/offchain/opportunities/index.js +2 -0
  118. package/dist/esm/offchain/package.json +1 -0
  119. package/dist/esm/offchain/types.js +1 -0
  120. package/dist/esm/preview/preview/buildDelayedPreview.js +1 -1
  121. package/dist/esm/preview/simulate/simulatePoolOperation.js +1 -1
  122. package/dist/esm/preview/trace/extractTransfers.js +1 -1
  123. package/dist/esm/rewards/rewards/api.js +1 -1
  124. package/dist/esm/rewards/rewards/extra-apy.js +1 -1
  125. package/dist/esm/sdk/MultichainSDK.js +18 -2
  126. package/dist/esm/sdk/OnchainSDK.js +8 -1
  127. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +2 -2
  128. package/dist/esm/sdk/accounts/index.js +2 -2
  129. package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +164 -109
  130. package/dist/esm/sdk/accounts/liquidations/MultichainLiquidationsService.js +32 -38
  131. package/dist/esm/sdk/accounts/liquidations/constants.js +12 -1
  132. package/dist/esm/sdk/accounts/liquidations/index.js +2 -2
  133. package/dist/esm/sdk/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
  134. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
  135. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
  136. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
  137. package/dist/esm/sdk/base/MultichainConstruct.js +79 -0
  138. package/dist/esm/sdk/base/TokensMeta.js +53 -2
  139. package/dist/esm/sdk/base/index.js +2 -1
  140. package/dist/esm/sdk/chain/chains.js +74 -2
  141. package/dist/esm/sdk/chain/detectNetwork.js +1 -1
  142. package/dist/esm/sdk/chain/index.js +2 -2
  143. package/dist/esm/sdk/core/createAddressProvider.js +1 -1
  144. package/dist/esm/sdk/core/errors.js +13 -1
  145. package/dist/esm/sdk/core/index.js +2 -2
  146. package/dist/esm/sdk/index.js +11 -5
  147. package/dist/esm/sdk/market/MarketConfiguratorContract.js +14 -0
  148. package/dist/esm/sdk/market/MarketSuite.js +159 -0
  149. package/dist/esm/sdk/market/credit/CreditFacadeV310BaseContract.js +1 -1
  150. package/dist/esm/sdk/market/credit/CreditManagerV310Contract.js +26 -0
  151. package/dist/esm/sdk/market/credit/CreditSuite.js +92 -0
  152. package/dist/esm/sdk/market/math.js +98 -0
  153. package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +52 -0
  154. package/dist/esm/sdk/market/pool/LinearInterestRateModelContract.js +30 -0
  155. package/dist/esm/sdk/market/pool/PoolQuotaKeeperV310Contract.js +26 -0
  156. package/dist/esm/sdk/market/pool/PoolSuite.js +28 -0
  157. package/dist/esm/sdk/market/pool/PoolV310Contract.js +28 -1
  158. package/dist/esm/sdk/market/pool/math.js +41 -0
  159. package/dist/esm/sdk/market/pricefeeds/AbstractPriceFeed.js +17 -0
  160. package/dist/esm/sdk/market/zapper/IETHZapperContract.js +1 -1
  161. package/dist/esm/sdk/market/zapper/ZapperContract.js +1 -1
  162. package/dist/esm/sdk/opportunities/MultichainOpportunitiesService.js +59 -0
  163. package/dist/esm/sdk/opportunities/OpportunitiesService.js +47 -0
  164. package/dist/esm/sdk/opportunities/index.js +4 -0
  165. package/dist/esm/sdk/pools/PoolService.js +1 -1
  166. package/dist/esm/sdk/types/multichain.js +1 -0
  167. package/dist/esm/{common-utils → sdk}/utils/bigint-math.js +11 -11
  168. package/dist/esm/sdk/utils/index.js +3 -2
  169. package/dist/esm/sdk/utils/viem/simulateWithPriceUpdates.js +1 -1
  170. package/dist/esm/sdk/utils/zod.js +13 -2
  171. package/dist/types/common-utils/index.d.ts +1 -1
  172. package/dist/types/common-utils/utils/index.d.ts +1 -1
  173. package/dist/types/model/history.d.ts +105 -0
  174. package/dist/types/model/history.schema.d.ts +66 -0
  175. package/dist/types/model/index.d.ts +11 -0
  176. package/dist/types/model/liquidations.d.ts +238 -0
  177. package/dist/types/model/liquidations.schema.d.ts +294 -0
  178. package/dist/types/model/opportunities.d.ts +584 -0
  179. package/dist/types/model/opportunities.schema.d.ts +1037 -0
  180. package/dist/types/model/positions.d.ts +247 -0
  181. package/dist/types/model/positions.schema.d.ts +701 -0
  182. package/dist/types/model/primitives.d.ts +194 -0
  183. package/dist/types/model/primitives.schema.d.ts +81 -0
  184. package/dist/types/new-sdk/AbstractNamespace.d.ts +119 -0
  185. package/dist/types/new-sdk/GearboxSDK.d.ts +78 -0
  186. package/dist/types/new-sdk/index.d.ts +9 -0
  187. package/dist/types/new-sdk/opportunities/OpportunitiesNamespace.d.ts +69 -0
  188. package/dist/types/new-sdk/opportunities/index.d.ts +3 -0
  189. package/dist/types/new-sdk/opportunities/types.d.ts +66 -0
  190. package/dist/types/new-sdk/types.d.ts +149 -0
  191. package/dist/types/new-sdk/utils/history.d.ts +44 -0
  192. package/dist/types/new-sdk/utils/index.d.ts +2 -0
  193. package/dist/types/offchain/GearboxAPI.d.ts +31 -0
  194. package/dist/types/offchain/index.d.ts +5 -0
  195. package/dist/types/offchain/opportunities/OffchainOpportunities.d.ts +69 -0
  196. package/dist/types/offchain/opportunities/index.d.ts +2 -0
  197. package/dist/types/offchain/types.d.ts +50 -0
  198. package/dist/types/sdk/MultichainSDK.d.ts +15 -2
  199. package/dist/types/sdk/OnchainSDK.d.ts +9 -3
  200. package/dist/types/sdk/accounts/index.d.ts +3 -3
  201. package/dist/types/sdk/accounts/liquidations/LiquidationsService.d.ts +24 -16
  202. package/dist/types/sdk/accounts/liquidations/MultichainLiquidationsService.d.ts +26 -20
  203. package/dist/types/sdk/accounts/liquidations/constants.d.ts +12 -1
  204. package/dist/types/sdk/accounts/liquidations/index.d.ts +3 -3
  205. package/dist/types/sdk/accounts/liquidations/types.d.ts +34 -309
  206. package/dist/types/sdk/base/MultichainConstruct.d.ts +57 -0
  207. package/dist/types/sdk/base/TokensMeta.d.ts +26 -0
  208. package/dist/types/sdk/base/index.d.ts +2 -1
  209. package/dist/types/sdk/chain/chains.d.ts +68 -1
  210. package/dist/types/sdk/chain/index.d.ts +2 -2
  211. package/dist/types/sdk/core/errors.d.ts +10 -1
  212. package/dist/types/sdk/core/index.d.ts +2 -2
  213. package/dist/types/sdk/index.d.ts +15 -8
  214. package/dist/types/sdk/market/MarketConfiguratorContract.d.ts +9 -0
  215. package/dist/types/sdk/market/MarketSuite.d.ts +98 -1
  216. package/dist/types/sdk/market/credit/CreditManagerV310Contract.d.ts +14 -0
  217. package/dist/types/sdk/market/credit/CreditSuite.d.ts +43 -0
  218. package/dist/types/sdk/market/credit/types.d.ts +22 -0
  219. package/dist/types/sdk/market/index.d.ts +2 -2
  220. package/dist/types/sdk/market/math.d.ts +74 -0
  221. package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +23 -0
  222. package/dist/types/sdk/market/oracle/types.d.ts +46 -0
  223. package/dist/types/sdk/market/pool/LinearInterestRateModelContract.d.ts +12 -0
  224. package/dist/types/sdk/market/pool/PoolQuotaKeeperV310Contract.d.ts +22 -1
  225. package/dist/types/sdk/market/pool/PoolSuite.d.ts +23 -0
  226. package/dist/types/sdk/market/pool/PoolV310Contract.d.ts +18 -0
  227. package/dist/types/sdk/market/pool/math.d.ts +57 -0
  228. package/dist/types/sdk/market/pool/types.d.ts +23 -0
  229. package/dist/types/sdk/market/pricefeeds/AbstractPriceFeed.d.ts +6 -0
  230. package/dist/types/sdk/market/pricefeeds/types.d.ts +10 -0
  231. package/dist/types/sdk/opportunities/MultichainOpportunitiesService.d.ts +40 -0
  232. package/dist/types/sdk/opportunities/OpportunitiesService.d.ts +42 -0
  233. package/dist/types/sdk/opportunities/index.d.ts +4 -0
  234. package/dist/types/sdk/types/index.d.ts +2 -1
  235. package/dist/types/sdk/types/multichain.d.ts +65 -0
  236. package/dist/types/sdk/types/state.d.ts +1 -1
  237. package/dist/types/sdk/types/transactions.d.ts +3 -0
  238. package/dist/types/{common-utils → sdk}/utils/bigint-math.d.ts +7 -11
  239. package/dist/types/sdk/utils/index.d.ts +3 -2
  240. package/dist/types/sdk/utils/zod.d.ts +6 -2
  241. package/package.json +16 -1
  242. package/dist/cjs/sdk/accounts/liquidations/helpers.js +0 -201
  243. package/dist/esm/sdk/accounts/liquidations/helpers.js +0 -192
  244. package/dist/types/sdk/accounts/liquidations/helpers.d.ts +0 -140
@@ -0,0 +1,584 @@
1
+ import { Amount, AssetType, Bps, ChainId, Curator, Leverage, Timestamp, Token } from "./primitives.js";
2
+ import { Address } from "viem";
3
+ //#region src/model/opportunities.d.ts
4
+ /**
5
+ * Discriminator of the two opportunity kinds.
6
+ *
7
+ * - `"pool"` — passive lending: deposit the underlying, earn the supply rate.
8
+ * - `"strategy"` — leveraged position: deposit collateral, borrow the
9
+ * underlying against it inside a credit account.
10
+ **/
11
+ type OpportunityKind = "pool" | "strategy";
12
+ /**
13
+ * An off-chain points program a position accrues towards, e.g. a partner
14
+ * protocol's season points. Points have no APY, so they are listed separately
15
+ * from token rewards.
16
+ **/
17
+ interface PointsProgram {
18
+ /**
19
+ * Stable slug of the program.
20
+ *
21
+ * @example `"ethena-sats-s3"`
22
+ **/
23
+ id: string;
24
+ /**
25
+ * Display name of the program.
26
+ *
27
+ * @example `"Ethena Sats Season 3"`
28
+ **/
29
+ name: string;
30
+ /**
31
+ * Points earned per unit of position relative to the program's base rate, or
32
+ * `null` when the program does not publish one.
33
+ *
34
+ * @example `2` for a 2x boost
35
+ **/
36
+ multiplier: number | null;
37
+ }
38
+ /**
39
+ * Rewards paid out in a token, e.g. a liquidity mining program.
40
+ **/
41
+ interface TokenRewards {
42
+ kind: "token";
43
+ /**
44
+ * Token the rewards are paid in.
45
+ **/
46
+ token: Token;
47
+ /**
48
+ * Extra APR earned by supplying, in basis points.
49
+ *
50
+ * @example `120` for +1.2% APR
51
+ **/
52
+ supplyApr?: Bps;
53
+ /**
54
+ * Extra APR earned on the borrowed side, in basis points. Present when a
55
+ * program rebates part of the borrow cost.
56
+ *
57
+ * @example `45` for +0.45% APR
58
+ **/
59
+ borrowApr?: Bps;
60
+ }
61
+ /**
62
+ * Rewards accrued as points rather than tokens.
63
+ **/
64
+ interface PointRewards {
65
+ kind: "point";
66
+ /**
67
+ * Programs the position accrues points in.
68
+ **/
69
+ points: PointsProgram[];
70
+ }
71
+ /**
72
+ * Any reward stream attached to an opportunity.
73
+ **/
74
+ type Rewards = TokenRewards | PointRewards;
75
+ /**
76
+ * A yield figure split into the part the protocol itself generates and the
77
+ * incentives layered on top.
78
+ **/
79
+ interface ApyBreakdown {
80
+ /**
81
+ * Everything combined, in basis points: the number a UI shows as "APY".
82
+ *
83
+ * Absent in `onchain` mode: it folds in the incentives of {@link rewards},
84
+ * which only the backend knows.
85
+ *
86
+ * @example `842` for 8.42% APY
87
+ *
88
+ * @mode offchain
89
+ **/
90
+ totalApy?: Bps;
91
+ /**
92
+ * The part generated by the underlying protocol alone, without incentives,
93
+ * in basis points. Always readable from the chain.
94
+ *
95
+ * @example `610` for 6.10% APY
96
+ **/
97
+ organicApy: Bps;
98
+ /**
99
+ * Incentives that make up the difference between {@link organicApy} and
100
+ * {@link totalApy}, plus any points programs that carry no APY at all.
101
+ *
102
+ * @mode offchain
103
+ **/
104
+ rewards?: Rewards[];
105
+ }
106
+ /**
107
+ * Fields both opportunity kinds share.
108
+ **/
109
+ interface OpportunityBase {
110
+ /**
111
+ * Chain the opportunity lives on.
112
+ **/
113
+ chainId: ChainId;
114
+ /**
115
+ * Human-readable name for the row.
116
+ *
117
+ * @example `"USDC Pool"`, `"wstETH / WETH"`
118
+ **/
119
+ name: string;
120
+ /**
121
+ * Curator of the market this opportunity belongs to.
122
+ **/
123
+ curator: Curator;
124
+ /**
125
+ * Token that is supplied to the pool and borrowed by credit accounts. All
126
+ * amounts of the opportunity are denominated in it.
127
+ *
128
+ * For RWA markets it's an unwrapped, e.g. — `USDC`, not `dcUSDC` (pool underlying according to contract).
129
+ * The wrapper converts one-for-one, so every amount stays exact.
130
+ **/
131
+ underlyingToken: Token;
132
+ /**
133
+ * Debt principal drawn against the opportunity: everything the pool has lent
134
+ * out for a {@link PoolOpportunity} (`pool.totalBorrowed()`), only what the
135
+ * strategy's credit manager has drawn for a {@link StrategyOpportunity}
136
+ * (`pool.creditManagerBorrowed(creditManager)`).
137
+ **/
138
+ totalBorrow: Amount;
139
+ /**
140
+ * Tokens accepted as collateral, i.e. the tokens that have both a non-zero
141
+ * liquidation threshold and a non-zero quota limit.
142
+ **/
143
+ collateralTokens: Token[];
144
+ /**
145
+ * The contract's own pause flag: the pool for a {@link PoolOpportunity}, the
146
+ * credit facade or the pool it borrows from for a
147
+ * {@link StrategyOpportunity}.
148
+ **/
149
+ paused: boolean;
150
+ /**
151
+ * Whether at least one of {@link collateralTokens} is a real-world-asset
152
+ * token. Read from a hardcoded per-chain list rather than from the chain.
153
+ **/
154
+ rwa: boolean;
155
+ /**
156
+ * Whether the opportunity is being wound down and should no longer be
157
+ * entered. Read from a hardcoded per-chain list, kept separately for pools
158
+ * and for strategies, and unrelated to
159
+ * {@link StrategyOpportunity.expirationDate}.
160
+ **/
161
+ sunset: boolean;
162
+ }
163
+ /**
164
+ * Passive lending into a Gearbox pool.
165
+ *
166
+ * Identified by `(chainId, pool)`, see {@link poolOpportunityId}.
167
+ **/
168
+ interface PoolOpportunity extends OpportunityBase {
169
+ kind: "pool";
170
+ /**
171
+ * Address of the ERC-4626 pool contract.
172
+ **/
173
+ pool: Address;
174
+ /**
175
+ * Size of the pool: the underlying its shares are worth, converted at the
176
+ * current share rate, i.e. `pool.totalAssets()`. Denominated in the
177
+ * underlying rather than in shares, so it is comparable with
178
+ * {@link OpportunityBase.totalBorrow}.
179
+ **/
180
+ totalSupply: Amount;
181
+ /**
182
+ * How much of the pool's capital is currently borrowed, in basis points.
183
+ *
184
+ * @example `7500` for 75% utilization
185
+ **/
186
+ utilization: Bps;
187
+ /**
188
+ * Yield earned by supplying to the pool.
189
+ *
190
+ * Its {@link ApyBreakdown.organicApy} is the pool's own supply rate (
191
+ * which consists of base interest and quota revenue)
192
+ * so this group is present in `onchain` mode too, with only that part filled.
193
+ **/
194
+ supplyApy: ApyBreakdown;
195
+ }
196
+ /**
197
+ * A leveraged position: one credit manager plus one target collateral token.
198
+ * A credit manager that accepts five collateral tokens therefore produces five
199
+ * strategies.
200
+ *
201
+ * Identified by `(chainId, creditManager, targetCollateral.address)`,
202
+ * see {@link strategyOpportunityId}.
203
+ **/
204
+ interface StrategyOpportunity extends OpportunityBase {
205
+ kind: "strategy";
206
+ /**
207
+ * Address of the credit manager the position is opened in.
208
+ **/
209
+ creditManager: Address;
210
+ /**
211
+ * Collateral token the position is built around.
212
+ **/
213
+ targetCollateral: Token;
214
+ /**
215
+ * Liquidation threshold of {@link targetCollateral} in this credit manager,
216
+ * in basis points: the share of the collateral value that counts towards
217
+ * covering debt.
218
+ *
219
+ * @example `9000` for an 86% threshold
220
+ **/
221
+ liquidationThreshold: Bps;
222
+ /**
223
+ * Share of a liquidated account's value paid to the liquidator, in basis
224
+ * points.
225
+ *
226
+ * @example `400` for a 4% premium
227
+ **/
228
+ liquidationPremium: Bps;
229
+ /**
230
+ * Share of a liquidated account's value taken by the protocol, in basis
231
+ * points.
232
+ *
233
+ * @example `150` for a 1.5% fee
234
+ **/
235
+ liquidationFee: Bps;
236
+ /**
237
+ * Moment the credit facade expires, after which positions can no longer be
238
+ * opened and open ones become liquidatable, or `null` when the facade is not
239
+ * expirable. A timestamp in the past means it has already expired.
240
+ **/
241
+ expirationDate: Timestamp | null;
242
+ /**
243
+ * Yield the collateral itself earns while it sits in the credit account,
244
+ * before leverage. Comes from external sources rather than from the chain.
245
+ *
246
+ * @mode offchain
247
+ **/
248
+ collateralApy?: ApyBreakdown;
249
+ /**
250
+ * Net yield at {@link maxLeverage}:
251
+ * `collateralApy * maxLeverage - borrowApy * (maxLeverage - 1)`, applied to
252
+ * {@link ApyBreakdown.totalApy}, {@link ApyBreakdown.organicApy} and
253
+ * {@link ApyBreakdown.rewards} alike.
254
+ *
255
+ * Absent in `onchain` mode: its {@link collateralApy} term is.
256
+ *
257
+ * @mode offchain
258
+ **/
259
+ maxLeverageApy?: ApyBreakdown;
260
+ /**
261
+ * Annual cost of the borrowed underlying, in basis points, including the
262
+ * protocol's interest fee.
263
+ *
264
+ * @example `520` for 5.2% APY
265
+ **/
266
+ borrowApy?: Bps;
267
+ /**
268
+ * Annual cost of the quota on {@link targetCollateral}, scaled to the debt a
269
+ * maximally leveraged position carries, in basis points. Comes on top of
270
+ * {@link borrowApy}.
271
+ *
272
+ * @example `90` for +0.9% APY
273
+ **/
274
+ additionalBorrowApy?: Bps;
275
+ /**
276
+ * Size of the strategy: the summed total value of the credit accounts
277
+ * holding {@link targetCollateral}. An account that holds several strategy
278
+ * collaterals counts in full towards each of them.
279
+ *
280
+ * Absent in `onchain` mode.
281
+ *
282
+ * @mode offchain
283
+ **/
284
+ totalValue?: Amount;
285
+ /**
286
+ * Share of {@link totalValue} that is borrowed, in basis points:
287
+ * `totalBorrow / totalValue`.
288
+ *
289
+ * Absent in `onchain` mode, because its denominator is, see
290
+ * {@link totalValue}.
291
+ *
292
+ * @example `7500` for 75% utilization
293
+ *
294
+ * @mode offchain
295
+ **/
296
+ utilization?: Bps;
297
+ /**
298
+ * Largest debt a single new position can take on right now: the tightest of
299
+ * the credit manager's remaining debt limit, the pool's free liquidity and
300
+ * the facade's per-account maximum.
301
+ **/
302
+ maxBorrowAmount: Amount;
303
+ /**
304
+ * Highest leverage the liquidation threshold allows,
305
+ * `1 / (1 - liquidationThreshold)`.
306
+ *
307
+ * @example `10` at a 90% threshold
308
+ **/
309
+ maxLeverage: Leverage;
310
+ }
311
+ /**
312
+ * A row of the opportunities list.
313
+ **/
314
+ type Opportunity = PoolOpportunity | StrategyOpportunity;
315
+ /**
316
+ * Canonical id of an opportunity: the string used to match a row read from the
317
+ * chain with the same row served by the backend.
318
+ **/
319
+ type OpportunityId = string;
320
+ /**
321
+ * Builds the canonical id of a pool opportunity.
322
+ *
323
+ * @example
324
+ * ```ts
325
+ * poolOpportunityId(1, "0xda00...") // "1:0xda00..."
326
+ * ```
327
+ **/
328
+ declare function poolOpportunityId(chainId: ChainId, pool: Address): OpportunityId;
329
+ /**
330
+ * Builds the canonical id of a strategy opportunity.
331
+ *
332
+ * @example
333
+ * ```ts
334
+ * strategyOpportunityId(1, "0x3eb9...", "0x7f39...") // "1:0x3eb9...:0x7f39..."
335
+ * ```
336
+ **/
337
+ declare function strategyOpportunityId(chainId: ChainId, creditManager: Address, targetCollateral: Address): OpportunityId;
338
+ /**
339
+ * Canonical id of any opportunity, dispatching on {@link Opportunity.kind}.
340
+ **/
341
+ declare function opportunityId(opportunity: Opportunity): OpportunityId;
342
+ /**
343
+ * Optional narrowing of an opportunities list.
344
+ *
345
+ * The list is filtered in memory over final values, so there is no paging and
346
+ * no sorting: a screen sorts what it got.
347
+ *
348
+ * Every criterion is optional and an omitted one matches any value, so an empty
349
+ * filter is the same as no filter at all. Criteria combine with AND.
350
+ **/
351
+ interface OpportunityFilter {
352
+ /**
353
+ * Keep only pools or only strategies.
354
+ **/
355
+ kind?: OpportunityKind;
356
+ /**
357
+ * Keep only opportunities on these chains.
358
+ **/
359
+ chainIds?: ChainId[];
360
+ /**
361
+ * Keep only opportunities whose {@link OpportunityBase.underlyingToken} is of
362
+ * this class, which for an RWA market means the class of the token its
363
+ * wrapper holds. An underlying that is not in the hardcoded table never
364
+ * matches, so a set filter also drops unclassified rows.
365
+ **/
366
+ underlyingType?: AssetType;
367
+ /**
368
+ * Keep only paused opportunities, or only unpaused ones.
369
+ **/
370
+ paused?: boolean;
371
+ /**
372
+ * Keep only opportunities being wound down, or only the ones that are not.
373
+ **/
374
+ sunset?: boolean;
375
+ /**
376
+ * Keep only opportunities that accept RWA collateral, or only the ones that
377
+ * do not.
378
+ **/
379
+ rwa?: boolean;
380
+ }
381
+ /**
382
+ * Whether an opportunity satisfies every criterion of a filter.
383
+ *
384
+ * This is the single definition of what each criterion means: every source
385
+ * builds its rows first and runs them through here, so the chain and the
386
+ * backend cannot disagree on what a filter selects.
387
+ *
388
+ * @param opportunity - Row to test.
389
+ * @param filter - Criteria to test against. An absent filter matches anything.
390
+ **/
391
+ declare function matchesOpportunityFilter(opportunity: Opportunity, filter?: OpportunityFilter): boolean;
392
+ /**
393
+ * One point of an interest rate curve.
394
+ **/
395
+ interface RateCurvePoint {
396
+ /**
397
+ * Utilization this point is sampled at, in basis points.
398
+ *
399
+ * @example `9000` for 90% utilization
400
+ **/
401
+ utilization: Bps;
402
+ /**
403
+ * Rate depositors earn at this utilization, in basis points.
404
+ *
405
+ * @example `430` for 4.3%
406
+ **/
407
+ supplyApy: Bps;
408
+ /**
409
+ * Base rate borrowers pay at this utilization, in basis points. Excludes the
410
+ * per-credit-manager interest fee, because the curve belongs to the pool and
411
+ * every credit manager of a market can charge a different one.
412
+ *
413
+ * @example `620` for 6.2%
414
+ **/
415
+ borrowApy: Bps;
416
+ }
417
+ /**
418
+ * The pool's interest rate model, evaluated into chart-ready points so that no
419
+ * consumer has to reimplement the model.
420
+ **/
421
+ interface RateCurve {
422
+ /**
423
+ * Points ordered by ascending utilization, always including the kinks of the
424
+ * model so the polyline is exact rather than approximated.
425
+ **/
426
+ points: RateCurvePoint[];
427
+ /**
428
+ * Utilization above which borrowing is forbidden, in basis points, or `null`
429
+ * when the model has no such cutoff.
430
+ *
431
+ * @example `9000` for a cutoff at 90% utilization
432
+ **/
433
+ borrowingLimitUtilization: Bps | null;
434
+ }
435
+ /**
436
+ * Quota configuration of one collateral token: how much of it the market
437
+ * accepts in total, and what holding it costs.
438
+ **/
439
+ interface QuotaAsset {
440
+ /**
441
+ * Token the quota applies to.
442
+ **/
443
+ token: Token;
444
+ /**
445
+ * Annual quota rate paid on the quoted amount, in basis points.
446
+ *
447
+ * @example `250` for 2.5% per year
448
+ **/
449
+ quotaRate: Bps;
450
+ /**
451
+ * Maximum amount that can be quoted across all credit accounts, denominated
452
+ * in the market's underlying.
453
+ **/
454
+ limit: Amount;
455
+ /**
456
+ * Amount currently quoted, denominated in the market's underlying.
457
+ **/
458
+ used: Amount;
459
+ }
460
+ /**
461
+ * A price feed and the feeds it is composed of.
462
+ **/
463
+ interface PriceFeedData {
464
+ /**
465
+ * Display name of the feed.
466
+ *
467
+ * @example `"CompositePriceFeed wstETH / USD"`
468
+ **/
469
+ name: string;
470
+ /**
471
+ * Gearbox price feed contract type.
472
+ *
473
+ * @example `"PRICE_FEED::COMPOSITE"`, `"PRICE_FEED::REDSTONE"`
474
+ **/
475
+ type: string;
476
+ /**
477
+ * Address of the feed contract.
478
+ **/
479
+ feedAddress: Address;
480
+ /**
481
+ * Feeds this feed reads from. Empty for a leaf feed.
482
+ **/
483
+ dependencies: PriceFeedData[];
484
+ }
485
+ /**
486
+ * Prices and feeds behind a strategy, i.e. everything a liquidation-price chart
487
+ * needs.
488
+ **/
489
+ interface PriceFeedSummary {
490
+ /**
491
+ * Price of one whole underlying token in USD.
492
+ *
493
+ * @example `1.0001` for USDC
494
+ **/
495
+ underlyingPriceInUsd: number;
496
+ /**
497
+ * Price of one whole collateral token in USD.
498
+ *
499
+ * @example `4210.55` for wstETH
500
+ **/
501
+ collateralPriceInUsd: number;
502
+ /**
503
+ * Price of one whole collateral token expressed in the underlying.
504
+ *
505
+ * @example `4210.13` for wstETH priced in USDC
506
+ **/
507
+ collateralPriceInUnderlying: number;
508
+ /**
509
+ * Main feed of the underlying token.
510
+ **/
511
+ underlyingFeed: PriceFeedData;
512
+ /**
513
+ * Main feed of the collateral token. Reserve feeds are not included.
514
+ **/
515
+ collateralFeed: PriceFeedData;
516
+ }
517
+ /**
518
+ * A pool opportunity plus the data only its detail screen needs.
519
+ **/
520
+ interface PoolOpportunityDetail extends PoolOpportunity {
521
+ /**
522
+ * Interest rate curve of the pool.
523
+ **/
524
+ rateCurve: RateCurve;
525
+ /**
526
+ * Quota configuration of every collateral token of the market.
527
+ **/
528
+ quotaAssets: QuotaAsset[];
529
+ }
530
+ /**
531
+ * A strategy opportunity plus the data only its detail screen needs.
532
+ **/
533
+ interface StrategyOpportunityDetail extends StrategyOpportunity {
534
+ /**
535
+ * Interest rate curve of the pool the strategy borrows from.
536
+ **/
537
+ rateCurve: RateCurve;
538
+ /**
539
+ * Prices and feeds of the underlying and the target collateral.
540
+ **/
541
+ priceFeeds: PriceFeedSummary;
542
+ }
543
+ /**
544
+ * Detailed view of any opportunity.
545
+ **/
546
+ type OpportunityDetail = PoolOpportunityDetail | StrategyOpportunityDetail;
547
+ /**
548
+ * Identifies a pool opportunity in a detail request.
549
+ **/
550
+ interface PoolOpportunityKey {
551
+ chainId: ChainId;
552
+ pool: Address;
553
+ }
554
+ /**
555
+ * Identifies a strategy opportunity in a detail request.
556
+ **/
557
+ interface StrategyOpportunityKey {
558
+ chainId: ChainId;
559
+ creditManager: Address;
560
+ /**
561
+ * Address of the target collateral token.
562
+ **/
563
+ targetCollateral: Address;
564
+ }
565
+ /**
566
+ * {@link PoolOpportunityKey} tagged with its kind, for requests that accept
567
+ * both kinds.
568
+ **/
569
+ interface PoolOpportunityRef extends PoolOpportunityKey {
570
+ kind: "pool";
571
+ }
572
+ /**
573
+ * {@link StrategyOpportunityKey} tagged with its kind, for requests that accept
574
+ * both kinds.
575
+ **/
576
+ interface StrategyOpportunityRef extends StrategyOpportunityKey {
577
+ kind: "strategy";
578
+ }
579
+ /**
580
+ * Identifies any opportunity, for requests that accept both kinds.
581
+ **/
582
+ type OpportunityKey = PoolOpportunityRef | StrategyOpportunityRef;
583
+ //#endregion
584
+ export { 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 };