@morpho-org/midnight-sdk 0.1.0

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 (157) hide show
  1. package/README.md +252 -0
  2. package/lib/cjs/abis.d.ts +3170 -0
  3. package/lib/cjs/abis.js +4073 -0
  4. package/lib/cjs/api/MidnightApi.d.ts +532 -0
  5. package/lib/cjs/api/MidnightApi.js +713 -0
  6. package/lib/cjs/api/helpers.d.ts +20 -0
  7. package/lib/cjs/api/helpers.js +189 -0
  8. package/lib/cjs/api/index.d.ts +2 -0
  9. package/lib/cjs/api/index.js +21 -0
  10. package/lib/cjs/api/types.d.ts +453 -0
  11. package/lib/cjs/api/types.js +2 -0
  12. package/lib/cjs/constants.d.ts +168 -0
  13. package/lib/cjs/constants.js +187 -0
  14. package/lib/cjs/errors.d.ts +253 -0
  15. package/lib/cjs/errors.js +309 -0
  16. package/lib/cjs/fetch/Market.d.ts +65 -0
  17. package/lib/cjs/fetch/Market.js +117 -0
  18. package/lib/cjs/fetch/Offer.d.ts +74 -0
  19. package/lib/cjs/fetch/Offer.js +119 -0
  20. package/lib/cjs/fetch/Position.d.ts +85 -0
  21. package/lib/cjs/fetch/Position.js +148 -0
  22. package/lib/cjs/fetch/Ratifier.d.ts +38 -0
  23. package/lib/cjs/fetch/Ratifier.js +57 -0
  24. package/lib/cjs/fetch/index.d.ts +5 -0
  25. package/lib/cjs/fetch/index.js +21 -0
  26. package/lib/cjs/fetch/types.d.ts +57 -0
  27. package/lib/cjs/fetch/types.js +2 -0
  28. package/lib/cjs/fetch/utils.d.ts +8 -0
  29. package/lib/cjs/fetch/utils.js +18 -0
  30. package/lib/cjs/index.d.ts +18 -0
  31. package/lib/cjs/index.js +57 -0
  32. package/lib/cjs/market/Market.d.ts +613 -0
  33. package/lib/cjs/market/Market.js +503 -0
  34. package/lib/cjs/market/MarketUtils.d.ts +189 -0
  35. package/lib/cjs/market/MarketUtils.js +303 -0
  36. package/lib/cjs/market/Position.d.ts +424 -0
  37. package/lib/cjs/market/Position.js +425 -0
  38. package/lib/cjs/market/PositionUtils.d.ts +115 -0
  39. package/lib/cjs/market/PositionUtils.js +194 -0
  40. package/lib/cjs/market/index.d.ts +4 -0
  41. package/lib/cjs/market/index.js +20 -0
  42. package/lib/cjs/math/ConsumableUnitsLib.d.ts +57 -0
  43. package/lib/cjs/math/ConsumableUnitsLib.js +77 -0
  44. package/lib/cjs/math/TakeAmountsLib.d.ts +175 -0
  45. package/lib/cjs/math/TakeAmountsLib.js +199 -0
  46. package/lib/cjs/math/TickLib.d.ts +200 -0
  47. package/lib/cjs/math/TickLib.js +272 -0
  48. package/lib/cjs/math/index.d.ts +3 -0
  49. package/lib/cjs/math/index.js +19 -0
  50. package/lib/cjs/offers/Offer.d.ts +534 -0
  51. package/lib/cjs/offers/Offer.js +343 -0
  52. package/lib/cjs/offers/OfferUtils.d.ts +565 -0
  53. package/lib/cjs/offers/OfferUtils.js +659 -0
  54. package/lib/cjs/offers/index.d.ts +2 -0
  55. package/lib/cjs/offers/index.js +18 -0
  56. package/lib/cjs/package.json +1 -0
  57. package/lib/cjs/queries/GetPosition.d.ts +55 -0
  58. package/lib/cjs/queries/GetPosition.js +74 -0
  59. package/lib/cjs/queries/index.d.ts +1 -0
  60. package/lib/cjs/queries/index.js +37 -0
  61. package/lib/cjs/signatures/EcrecoverRatifierUtils.d.ts +733 -0
  62. package/lib/cjs/signatures/EcrecoverRatifierUtils.js +618 -0
  63. package/lib/cjs/signatures/Group.d.ts +178 -0
  64. package/lib/cjs/signatures/Group.js +193 -0
  65. package/lib/cjs/signatures/GroupUtils.d.ts +191 -0
  66. package/lib/cjs/signatures/GroupUtils.js +127 -0
  67. package/lib/cjs/signatures/Payload.d.ts +283 -0
  68. package/lib/cjs/signatures/Payload.js +570 -0
  69. package/lib/cjs/signatures/RatifierUtils.d.ts +109 -0
  70. package/lib/cjs/signatures/RatifierUtils.js +76 -0
  71. package/lib/cjs/signatures/SetterRatifierUtils.d.ts +243 -0
  72. package/lib/cjs/signatures/SetterRatifierUtils.js +217 -0
  73. package/lib/cjs/signatures/Tree.d.ts +241 -0
  74. package/lib/cjs/signatures/Tree.js +263 -0
  75. package/lib/cjs/signatures/TreeUtils.d.ts +573 -0
  76. package/lib/cjs/signatures/TreeUtils.js +461 -0
  77. package/lib/cjs/signatures/index.d.ts +7 -0
  78. package/lib/cjs/signatures/index.js +23 -0
  79. package/lib/esm/abis.d.ts +3170 -0
  80. package/lib/esm/abis.js +4070 -0
  81. package/lib/esm/api/MidnightApi.d.ts +532 -0
  82. package/lib/esm/api/MidnightApi.js +709 -0
  83. package/lib/esm/api/helpers.d.ts +20 -0
  84. package/lib/esm/api/helpers.js +180 -0
  85. package/lib/esm/api/index.d.ts +2 -0
  86. package/lib/esm/api/index.js +2 -0
  87. package/lib/esm/api/types.d.ts +453 -0
  88. package/lib/esm/api/types.js +1 -0
  89. package/lib/esm/constants.d.ts +168 -0
  90. package/lib/esm/constants.js +184 -0
  91. package/lib/esm/errors.d.ts +253 -0
  92. package/lib/esm/errors.js +291 -0
  93. package/lib/esm/fetch/Market.d.ts +65 -0
  94. package/lib/esm/fetch/Market.js +113 -0
  95. package/lib/esm/fetch/Offer.d.ts +74 -0
  96. package/lib/esm/fetch/Offer.js +116 -0
  97. package/lib/esm/fetch/Position.d.ts +85 -0
  98. package/lib/esm/fetch/Position.js +144 -0
  99. package/lib/esm/fetch/Ratifier.d.ts +38 -0
  100. package/lib/esm/fetch/Ratifier.js +54 -0
  101. package/lib/esm/fetch/index.d.ts +5 -0
  102. package/lib/esm/fetch/index.js +5 -0
  103. package/lib/esm/fetch/types.d.ts +57 -0
  104. package/lib/esm/fetch/types.js +1 -0
  105. package/lib/esm/fetch/utils.d.ts +8 -0
  106. package/lib/esm/fetch/utils.js +12 -0
  107. package/lib/esm/index.d.ts +18 -0
  108. package/lib/esm/index.js +18 -0
  109. package/lib/esm/market/Market.d.ts +613 -0
  110. package/lib/esm/market/Market.js +498 -0
  111. package/lib/esm/market/MarketUtils.d.ts +189 -0
  112. package/lib/esm/market/MarketUtils.js +300 -0
  113. package/lib/esm/market/Position.d.ts +424 -0
  114. package/lib/esm/market/Position.js +420 -0
  115. package/lib/esm/market/PositionUtils.d.ts +115 -0
  116. package/lib/esm/market/PositionUtils.js +191 -0
  117. package/lib/esm/market/index.d.ts +4 -0
  118. package/lib/esm/market/index.js +4 -0
  119. package/lib/esm/math/ConsumableUnitsLib.d.ts +57 -0
  120. package/lib/esm/math/ConsumableUnitsLib.js +74 -0
  121. package/lib/esm/math/TakeAmountsLib.d.ts +175 -0
  122. package/lib/esm/math/TakeAmountsLib.js +196 -0
  123. package/lib/esm/math/TickLib.d.ts +200 -0
  124. package/lib/esm/math/TickLib.js +269 -0
  125. package/lib/esm/math/index.d.ts +3 -0
  126. package/lib/esm/math/index.js +3 -0
  127. package/lib/esm/offers/Offer.d.ts +534 -0
  128. package/lib/esm/offers/Offer.js +339 -0
  129. package/lib/esm/offers/OfferUtils.d.ts +565 -0
  130. package/lib/esm/offers/OfferUtils.js +656 -0
  131. package/lib/esm/offers/index.d.ts +2 -0
  132. package/lib/esm/offers/index.js +2 -0
  133. package/lib/esm/package.json +1 -0
  134. package/lib/esm/queries/GetPosition.d.ts +55 -0
  135. package/lib/esm/queries/GetPosition.js +71 -0
  136. package/lib/esm/queries/index.d.ts +1 -0
  137. package/lib/esm/queries/index.js +1 -0
  138. package/lib/esm/signatures/EcrecoverRatifierUtils.d.ts +733 -0
  139. package/lib/esm/signatures/EcrecoverRatifierUtils.js +615 -0
  140. package/lib/esm/signatures/Group.d.ts +178 -0
  141. package/lib/esm/signatures/Group.js +189 -0
  142. package/lib/esm/signatures/GroupUtils.d.ts +191 -0
  143. package/lib/esm/signatures/GroupUtils.js +124 -0
  144. package/lib/esm/signatures/Payload.d.ts +283 -0
  145. package/lib/esm/signatures/Payload.js +564 -0
  146. package/lib/esm/signatures/RatifierUtils.d.ts +109 -0
  147. package/lib/esm/signatures/RatifierUtils.js +73 -0
  148. package/lib/esm/signatures/SetterRatifierUtils.d.ts +243 -0
  149. package/lib/esm/signatures/SetterRatifierUtils.js +214 -0
  150. package/lib/esm/signatures/Tree.d.ts +241 -0
  151. package/lib/esm/signatures/Tree.js +259 -0
  152. package/lib/esm/signatures/TreeUtils.d.ts +573 -0
  153. package/lib/esm/signatures/TreeUtils.js +458 -0
  154. package/lib/esm/signatures/index.d.ts +7 -0
  155. package/lib/esm/signatures/index.js +7 -0
  156. package/package.json +69 -0
  157. package/src/index.ts +19 -0
@@ -0,0 +1,613 @@
1
+ import { type BigIntish } from "@morpho-org/morpho-ts";
2
+ import type { Address, Hash } from "viem";
3
+ /**
4
+ * Seven settlement-fee centibip buckets stored on a Midnight market.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import type { SettlementFeeCbps } from "@morpho-org/midnight-sdk";
9
+ *
10
+ * const cbps: SettlementFeeCbps = [0, 0, 0, 0, 0, 0, 0];
11
+ * console.log(cbps.length);
12
+ * ```
13
+ */
14
+ export type SettlementFeeCbps = readonly [
15
+ number,
16
+ number,
17
+ number,
18
+ number,
19
+ number,
20
+ number,
21
+ number
22
+ ];
23
+ /**
24
+ * Plain collateral params input accepted by {@link MarketParams}.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * import type { ICollateralParams } from "@morpho-org/midnight-sdk";
29
+ *
30
+ * const params: ICollateralParams = {
31
+ * token: "0x0000000000000000000000000000000000000001",
32
+ * lltv: 770000000000000000n,
33
+ * maxLif: 1061007957559681697n,
34
+ * oracle: "0x0000000000000000000000000000000000000002",
35
+ * };
36
+ * ```
37
+ */
38
+ export interface ICollateralParams {
39
+ /** Collateral token address. */
40
+ readonly token: Address;
41
+ /** WAD-scaled liquidation loan-to-value. */
42
+ readonly lltv: BigIntish;
43
+ /** WAD-scaled maximum liquidation incentive factor. */
44
+ readonly maxLif: BigIntish;
45
+ /** Oracle address for this collateral. */
46
+ readonly oracle: Address;
47
+ }
48
+ /**
49
+ * Normalized Midnight collateral params.
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * import type { CollateralParams } from "@morpho-org/midnight-sdk";
54
+ *
55
+ * const params: CollateralParams = {
56
+ * token: "0x0000000000000000000000000000000000000001",
57
+ * lltv: 770000000000000000n,
58
+ * maxLif: 1298701298701298701n,
59
+ * oracle: "0x0000000000000000000000000000000000000002",
60
+ * };
61
+ * console.log(params.lltv);
62
+ * ```
63
+ */
64
+ export interface CollateralParams {
65
+ /** Collateral token address. */
66
+ readonly token: Address;
67
+ /** WAD-scaled liquidation loan-to-value. */
68
+ readonly lltv: bigint;
69
+ /** WAD-scaled maximum liquidation incentive factor. */
70
+ readonly maxLif: bigint;
71
+ /** Oracle address for this collateral. */
72
+ readonly oracle: Address;
73
+ }
74
+ /**
75
+ * Plain input accepted by {@link MarketParams}.
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * import type { IMarketParams } from "@morpho-org/midnight-sdk";
80
+ *
81
+ * const params: IMarketParams = {
82
+ * loanToken: "0x0000000000000000000000000000000000000001",
83
+ * collateralParams: [
84
+ * {
85
+ * token: "0x0000000000000000000000000000000000000002",
86
+ * lltv: 770000000000000000n,
87
+ * maxLif: 1061007957559681697n,
88
+ * oracle: "0x0000000000000000000000000000000000000003",
89
+ * },
90
+ * ],
91
+ * maturity: 1n,
92
+ * rcfThreshold: 0n,
93
+ * enterGate: "0x0000000000000000000000000000000000000000",
94
+ * liquidatorGate: "0x0000000000000000000000000000000000000000",
95
+ * };
96
+ * ```
97
+ */
98
+ export interface IMarketParams {
99
+ /** Loan token address. */
100
+ readonly loanToken: Address;
101
+ /** Collateral definitions; `MarketParams` stores them sorted by token and rejects duplicate tokens. */
102
+ readonly collateralParams: readonly (ICollateralParams | CollateralParams)[];
103
+ /** Market maturity timestamp. */
104
+ readonly maturity: BigIntish;
105
+ /** Recovery close factor threshold. */
106
+ readonly rcfThreshold: BigIntish;
107
+ /** Optional entry gate. */
108
+ readonly enterGate: Address;
109
+ /** Optional liquidation gate. */
110
+ readonly liquidatorGate: Address;
111
+ }
112
+ /**
113
+ * Immutable Midnight market configuration.
114
+ *
115
+ * @example
116
+ * ```ts
117
+ * import { MarketParams } from "@morpho-org/midnight-sdk";
118
+ *
119
+ * const params = new MarketParams({
120
+ * loanToken: "0x0000000000000000000000000000000000000001",
121
+ * collateralParams: [
122
+ * {
123
+ * token: "0x0000000000000000000000000000000000000002",
124
+ * lltv: 770000000000000000n,
125
+ * maxLif: 1061007957559681697n,
126
+ * oracle: "0x0000000000000000000000000000000000000003",
127
+ * },
128
+ * ],
129
+ * maturity: 1n,
130
+ * rcfThreshold: 0n,
131
+ * enterGate: "0x0000000000000000000000000000000000000000",
132
+ * liquidatorGate: "0x0000000000000000000000000000000000000000",
133
+ * });
134
+ * console.log(params.loanToken);
135
+ * ```
136
+ */
137
+ export declare class MarketParams {
138
+ /** Loan token address. */
139
+ readonly loanToken: Address;
140
+ /** Collateral definitions sorted by token. */
141
+ readonly collateralParams: readonly CollateralParams[];
142
+ /** Market maturity timestamp. */
143
+ readonly maturity: bigint;
144
+ /** Recovery close factor threshold. */
145
+ readonly rcfThreshold: bigint;
146
+ /** Entry gate address. */
147
+ readonly enterGate: Address;
148
+ /** Liquidator gate address. */
149
+ readonly liquidatorGate: Address;
150
+ /**
151
+ * Creates normalized market params.
152
+ *
153
+ * @param params - Market params to normalize.
154
+ * @throws {InvalidMarketParameterError} when the collateral list is empty, contains duplicate tokens, or has LLTV outside `[0, WAD]`.
155
+ */
156
+ constructor(params: IMarketParams);
157
+ /**
158
+ * Returns market params from a params object or hydrated market.
159
+ *
160
+ * Use at boundaries that accept either a standalone market config or a full
161
+ * market object. Existing `MarketParams` instances are returned as-is.
162
+ *
163
+ * @param market - Market params or hydrated market.
164
+ * @returns Market params instance.
165
+ * @example
166
+ * ```ts
167
+ * import { MarketParams } from "@morpho-org/midnight-sdk";
168
+ *
169
+ * const params = MarketParams.from({
170
+ * loanToken: "0x0000000000000000000000000000000000006000",
171
+ * collateralParams: [
172
+ * {
173
+ * token: "0x0000000000000000000000000000000000007000",
174
+ * lltv: 770000000000000000n,
175
+ * maxLif: 1061007957559681697n,
176
+ * oracle: "0x0000000000000000000000000000000000008000",
177
+ * },
178
+ * ],
179
+ * maturity: 54_000n,
180
+ * rcfThreshold: 0n,
181
+ * enterGate: "0x0000000000000000000000000000000000000000",
182
+ * liquidatorGate: "0x0000000000000000000000000000000000000000",
183
+ * });
184
+ * console.log(params.loanToken);
185
+ * ```
186
+ */
187
+ static from(market: MarketInput): MarketParams;
188
+ }
189
+ /**
190
+ * Plain input accepted by {@link Market}.
191
+ *
192
+ * @example
193
+ * ```ts
194
+ * import type { IMarket } from "@morpho-org/midnight-sdk";
195
+ *
196
+ * const market: IMarket = {
197
+ * chainId: 31337,
198
+ * params: {
199
+ * loanToken: "0x0000000000000000000000000000000000000001",
200
+ * collateralParams: [
201
+ * {
202
+ * token: "0x0000000000000000000000000000000000000002",
203
+ * lltv: 770000000000000000n,
204
+ * maxLif: 1061007957559681697n,
205
+ * oracle: "0x0000000000000000000000000000000000000003",
206
+ * },
207
+ * ],
208
+ * maturity: 1n,
209
+ * rcfThreshold: 0n,
210
+ * enterGate: "0x0000000000000000000000000000000000000000",
211
+ * liquidatorGate: "0x0000000000000000000000000000000000000000",
212
+ * },
213
+ * totalUnits: 0n,
214
+ * lossFactor: 0n,
215
+ * withdrawable: 0n,
216
+ * continuousFeeCredit: 0n,
217
+ * settlementFeeCbps: [0, 0, 0, 0, 0, 0, 0],
218
+ * continuousFee: 0,
219
+ * tickSpacing: 4,
220
+ * };
221
+ * ```
222
+ */
223
+ export interface IMarket {
224
+ /** EIP-155 chain id used to derive the market id. */
225
+ readonly chainId: BigIntish;
226
+ /** Immutable market configuration. */
227
+ readonly params: IMarketParams;
228
+ /** Total market units. */
229
+ readonly totalUnits: BigIntish;
230
+ /** Current loss factor. */
231
+ readonly lossFactor: BigIntish;
232
+ /** Withdrawable assets. */
233
+ readonly withdrawable: BigIntish;
234
+ /** Continuous-fee credit. */
235
+ readonly continuousFeeCredit: BigIntish;
236
+ /** Seven settlement-fee cbp buckets. */
237
+ readonly settlementFeeCbps: SettlementFeeCbps;
238
+ /** Continuous fee per second. */
239
+ readonly continuousFee: number;
240
+ /** Market tick spacing. */
241
+ readonly tickSpacing: number;
242
+ }
243
+ /**
244
+ * Plain market params or hydrated market object accepted by market helpers.
245
+ *
246
+ * @example
247
+ * ```ts
248
+ * import type { MarketInput } from "@morpho-org/midnight-sdk";
249
+ *
250
+ * const market: MarketInput = {
251
+ * loanToken: "0x0000000000000000000000000000000000006000",
252
+ * collateralParams: [
253
+ * {
254
+ * token: "0x0000000000000000000000000000000000007000",
255
+ * lltv: 770000000000000000n,
256
+ * maxLif: 1061007957559681697n,
257
+ * oracle: "0x0000000000000000000000000000000000008000",
258
+ * },
259
+ * ],
260
+ * maturity: 54_000n,
261
+ * rcfThreshold: 0n,
262
+ * enterGate: "0x0000000000000000000000000000000000000000",
263
+ * liquidatorGate: "0x0000000000000000000000000000000000000000",
264
+ * };
265
+ * console.log(market.loanToken);
266
+ * ```
267
+ */
268
+ export type MarketInput = IMarketParams | IMarket;
269
+ /**
270
+ * Hydrated Midnight market configuration plus state.
271
+ *
272
+ * @example
273
+ * ```ts
274
+ * import { registerCustomAddresses } from "@morpho-org/morpho-ts";
275
+ * import { Market } from "@morpho-org/midnight-sdk";
276
+ *
277
+ * registerCustomAddresses({
278
+ * addresses: {
279
+ * 31337: {
280
+ * morpho: "0x0000000000000000000000000000000000000001",
281
+ * bundler3: {
282
+ * bundler3: "0x0000000000000000000000000000000000000002",
283
+ * generalAdapter1: "0x0000000000000000000000000000000000000003",
284
+ * },
285
+ * adaptiveCurveIrm: "0x0000000000000000000000000000000000000004",
286
+ * midnight: "0x0000000000000000000000000000000000001000",
287
+ * },
288
+ * },
289
+ * });
290
+ *
291
+ * const market = new Market({
292
+ * chainId: 31337,
293
+ * params: {
294
+ * loanToken: "0x0000000000000000000000000000000000006000",
295
+ * collateralParams: [
296
+ * {
297
+ * token: "0x0000000000000000000000000000000000007000",
298
+ * lltv: 770000000000000000n,
299
+ * maxLif: 1061007957559681697n,
300
+ * oracle: "0x0000000000000000000000000000000000008000",
301
+ * },
302
+ * ],
303
+ * maturity: 54_000n,
304
+ * rcfThreshold: 0n,
305
+ * enterGate: "0x0000000000000000000000000000000000000000",
306
+ * liquidatorGate: "0x0000000000000000000000000000000000000000",
307
+ * },
308
+ * totalUnits: 1_000n,
309
+ * lossFactor: 0n,
310
+ * withdrawable: 500n,
311
+ * continuousFeeCredit: 0n,
312
+ * settlementFeeCbps: [1, 2, 3, 4, 5, 6, 7],
313
+ * continuousFee: 10,
314
+ * tickSpacing: 4,
315
+ * });
316
+ * console.log(market.timeToMaturity(0n));
317
+ * ```
318
+ */
319
+ export declare class Market {
320
+ /** Market id. */
321
+ readonly id: Hash;
322
+ /** EIP-155 chain id used to derive the market id. */
323
+ readonly chainId: bigint;
324
+ /** Immutable market configuration. */
325
+ readonly params: MarketParams;
326
+ /** Total market units. */
327
+ readonly totalUnits: bigint;
328
+ /** Current loss factor. */
329
+ readonly lossFactor: bigint;
330
+ /** Withdrawable assets. */
331
+ readonly withdrawable: bigint;
332
+ /** Continuous-fee credit. */
333
+ readonly continuousFeeCredit: bigint;
334
+ /** Seven settlement-fee cbp buckets. */
335
+ readonly settlementFeeCbps: SettlementFeeCbps;
336
+ /** Continuous fee per second. */
337
+ readonly continuousFee: number;
338
+ /** Market tick spacing. */
339
+ readonly tickSpacing: number;
340
+ constructor(market: IMarket);
341
+ /**
342
+ * Returns the non-negative time remaining before maturity.
343
+ *
344
+ * @param timestamp - Timestamp to compare.
345
+ * @returns Seconds until maturity, floored to zero.
346
+ * @throws {NegativeValueError} when `timestamp` is negative.
347
+ * @example
348
+ * ```ts
349
+ * import { registerCustomAddresses } from "@morpho-org/morpho-ts";
350
+ * import { Market } from "@morpho-org/midnight-sdk";
351
+ *
352
+ * registerCustomAddresses({
353
+ * addresses: {
354
+ * 31337: {
355
+ * morpho: "0x0000000000000000000000000000000000000001",
356
+ * bundler3: {
357
+ * bundler3: "0x0000000000000000000000000000000000000002",
358
+ * generalAdapter1: "0x0000000000000000000000000000000000000003",
359
+ * },
360
+ * adaptiveCurveIrm: "0x0000000000000000000000000000000000000004",
361
+ * midnight: "0x0000000000000000000000000000000000001000",
362
+ * },
363
+ * },
364
+ * });
365
+ *
366
+ * const market = new Market({
367
+ * chainId: 31337,
368
+ * params: {
369
+ * loanToken: "0x0000000000000000000000000000000000006000",
370
+ * collateralParams: [
371
+ * {
372
+ * token: "0x0000000000000000000000000000000000007000",
373
+ * lltv: 770000000000000000n,
374
+ * maxLif: 1061007957559681697n,
375
+ * oracle: "0x0000000000000000000000000000000000008000",
376
+ * },
377
+ * ],
378
+ * maturity: 54_000n,
379
+ * rcfThreshold: 0n,
380
+ * enterGate: "0x0000000000000000000000000000000000000000",
381
+ * liquidatorGate: "0x0000000000000000000000000000000000000000",
382
+ * },
383
+ * totalUnits: 1_000n,
384
+ * lossFactor: 0n,
385
+ * withdrawable: 500n,
386
+ * continuousFeeCredit: 0n,
387
+ * settlementFeeCbps: [1, 2, 3, 4, 5, 6, 7],
388
+ * continuousFee: 10,
389
+ * tickSpacing: 4,
390
+ * });
391
+ * console.log(market.timeToMaturity(0n));
392
+ * ```
393
+ */
394
+ timeToMaturity(timestamp: BigIntish): bigint;
395
+ /**
396
+ * Computes the settlement fee for a time to maturity from the hydrated market state.
397
+ *
398
+ * @param timeToMaturity - Seconds until maturity.
399
+ * @returns WAD-scaled settlement fee.
400
+ * @throws {NegativeValueError} when `timeToMaturity` is negative.
401
+ * @example
402
+ * ```ts
403
+ * import { registerCustomAddresses } from "@morpho-org/morpho-ts";
404
+ * import { Market } from "@morpho-org/midnight-sdk";
405
+ *
406
+ * registerCustomAddresses({
407
+ * addresses: {
408
+ * 31337: {
409
+ * morpho: "0x0000000000000000000000000000000000000001",
410
+ * bundler3: {
411
+ * bundler3: "0x0000000000000000000000000000000000000002",
412
+ * generalAdapter1: "0x0000000000000000000000000000000000000003",
413
+ * },
414
+ * adaptiveCurveIrm: "0x0000000000000000000000000000000000000004",
415
+ * midnight: "0x0000000000000000000000000000000000001000",
416
+ * },
417
+ * },
418
+ * });
419
+ *
420
+ * const market = new Market({
421
+ * chainId: 31337,
422
+ * params: {
423
+ * loanToken: "0x0000000000000000000000000000000000006000",
424
+ * collateralParams: [
425
+ * {
426
+ * token: "0x0000000000000000000000000000000000007000",
427
+ * lltv: 770000000000000000n,
428
+ * maxLif: 1061007957559681697n,
429
+ * oracle: "0x0000000000000000000000000000000000008000",
430
+ * },
431
+ * ],
432
+ * maturity: 54_000n,
433
+ * rcfThreshold: 0n,
434
+ * enterGate: "0x0000000000000000000000000000000000000000",
435
+ * liquidatorGate: "0x0000000000000000000000000000000000000000",
436
+ * },
437
+ * totalUnits: 1_000n,
438
+ * lossFactor: 0n,
439
+ * withdrawable: 500n,
440
+ * continuousFeeCredit: 0n,
441
+ * settlementFeeCbps: [1, 2, 3, 4, 5, 6, 7],
442
+ * continuousFee: 10,
443
+ * tickSpacing: 4,
444
+ * });
445
+ * console.log(market.getSettlementFee(0n));
446
+ * ```
447
+ */
448
+ getSettlementFee(timeToMaturity: BigIntish): bigint;
449
+ /**
450
+ * Returns collateral params by numeric index.
451
+ *
452
+ * @param index - Collateral index.
453
+ * @returns Collateral params, or undefined when the index is not configured.
454
+ * @example
455
+ * ```ts
456
+ * import { registerCustomAddresses } from "@morpho-org/morpho-ts";
457
+ * import { Market } from "@morpho-org/midnight-sdk";
458
+ *
459
+ * registerCustomAddresses({
460
+ * addresses: {
461
+ * 31337: {
462
+ * morpho: "0x0000000000000000000000000000000000000001",
463
+ * bundler3: {
464
+ * bundler3: "0x0000000000000000000000000000000000000002",
465
+ * generalAdapter1: "0x0000000000000000000000000000000000000003",
466
+ * },
467
+ * adaptiveCurveIrm: "0x0000000000000000000000000000000000000004",
468
+ * midnight: "0x0000000000000000000000000000000000001000",
469
+ * },
470
+ * },
471
+ * });
472
+ *
473
+ * const market = new Market({
474
+ * chainId: 31337,
475
+ * params: {
476
+ * loanToken: "0x0000000000000000000000000000000000006000",
477
+ * collateralParams: [
478
+ * {
479
+ * token: "0x0000000000000000000000000000000000007000",
480
+ * lltv: 770000000000000000n,
481
+ * maxLif: 1061007957559681697n,
482
+ * oracle: "0x0000000000000000000000000000000000008000",
483
+ * },
484
+ * ],
485
+ * maturity: 54_000n,
486
+ * rcfThreshold: 0n,
487
+ * enterGate: "0x0000000000000000000000000000000000000000",
488
+ * liquidatorGate: "0x0000000000000000000000000000000000000000",
489
+ * },
490
+ * totalUnits: 1_000n,
491
+ * lossFactor: 0n,
492
+ * withdrawable: 500n,
493
+ * continuousFeeCredit: 0n,
494
+ * settlementFeeCbps: [1, 2, 3, 4, 5, 6, 7],
495
+ * continuousFee: 10,
496
+ * tickSpacing: 4,
497
+ * });
498
+ * const params = market.getCollateralParamsByIndex(0);
499
+ * console.log(params?.token);
500
+ * ```
501
+ */
502
+ getCollateralParamsByIndex(index: BigIntish): CollateralParams | undefined;
503
+ /**
504
+ * Returns the configured collateral index for a token.
505
+ *
506
+ * @param token - Collateral token address.
507
+ * @returns Collateral index, or undefined when the token is not configured.
508
+ * @example
509
+ * ```ts
510
+ * import { registerCustomAddresses } from "@morpho-org/morpho-ts";
511
+ * import { Market } from "@morpho-org/midnight-sdk";
512
+ *
513
+ * registerCustomAddresses({
514
+ * addresses: {
515
+ * 31337: {
516
+ * morpho: "0x0000000000000000000000000000000000000001",
517
+ * bundler3: {
518
+ * bundler3: "0x0000000000000000000000000000000000000002",
519
+ * generalAdapter1: "0x0000000000000000000000000000000000000003",
520
+ * },
521
+ * adaptiveCurveIrm: "0x0000000000000000000000000000000000000004",
522
+ * midnight: "0x0000000000000000000000000000000000001000",
523
+ * },
524
+ * },
525
+ * });
526
+ *
527
+ * const collateralToken = "0x0000000000000000000000000000000000007000";
528
+ * const market = new Market({
529
+ * chainId: 31337,
530
+ * params: {
531
+ * loanToken: "0x0000000000000000000000000000000000006000",
532
+ * collateralParams: [
533
+ * {
534
+ * token: collateralToken,
535
+ * lltv: 770000000000000000n,
536
+ * maxLif: 1061007957559681697n,
537
+ * oracle: "0x0000000000000000000000000000000000008000",
538
+ * },
539
+ * ],
540
+ * maturity: 54_000n,
541
+ * rcfThreshold: 0n,
542
+ * enterGate: "0x0000000000000000000000000000000000000000",
543
+ * liquidatorGate: "0x0000000000000000000000000000000000000000",
544
+ * },
545
+ * totalUnits: 1_000n,
546
+ * lossFactor: 0n,
547
+ * withdrawable: 500n,
548
+ * continuousFeeCredit: 0n,
549
+ * settlementFeeCbps: [1, 2, 3, 4, 5, 6, 7],
550
+ * continuousFee: 10,
551
+ * tickSpacing: 4,
552
+ * });
553
+ * const index = market.getCollateralIndexByToken(collateralToken);
554
+ * console.log(index);
555
+ * ```
556
+ */
557
+ getCollateralIndexByToken(token: Address): number | undefined;
558
+ /**
559
+ * Returns collateral params by token address.
560
+ *
561
+ * @param token - Collateral token address.
562
+ * @returns Collateral params, or undefined when the token is not configured.
563
+ * @example
564
+ * ```ts
565
+ * import { registerCustomAddresses } from "@morpho-org/morpho-ts";
566
+ * import { Market } from "@morpho-org/midnight-sdk";
567
+ *
568
+ * registerCustomAddresses({
569
+ * addresses: {
570
+ * 31337: {
571
+ * morpho: "0x0000000000000000000000000000000000000001",
572
+ * bundler3: {
573
+ * bundler3: "0x0000000000000000000000000000000000000002",
574
+ * generalAdapter1: "0x0000000000000000000000000000000000000003",
575
+ * },
576
+ * adaptiveCurveIrm: "0x0000000000000000000000000000000000000004",
577
+ * midnight: "0x0000000000000000000000000000000000001000",
578
+ * },
579
+ * },
580
+ * });
581
+ *
582
+ * const collateralToken = "0x0000000000000000000000000000000000007000";
583
+ * const market = new Market({
584
+ * chainId: 31337,
585
+ * params: {
586
+ * loanToken: "0x0000000000000000000000000000000000006000",
587
+ * collateralParams: [
588
+ * {
589
+ * token: collateralToken,
590
+ * lltv: 770000000000000000n,
591
+ * maxLif: 1061007957559681697n,
592
+ * oracle: "0x0000000000000000000000000000000000008000",
593
+ * },
594
+ * ],
595
+ * maturity: 54_000n,
596
+ * rcfThreshold: 0n,
597
+ * enterGate: "0x0000000000000000000000000000000000000000",
598
+ * liquidatorGate: "0x0000000000000000000000000000000000000000",
599
+ * },
600
+ * totalUnits: 1_000n,
601
+ * lossFactor: 0n,
602
+ * withdrawable: 500n,
603
+ * continuousFeeCredit: 0n,
604
+ * settlementFeeCbps: [1, 2, 3, 4, 5, 6, 7],
605
+ * continuousFee: 10,
606
+ * tickSpacing: 4,
607
+ * });
608
+ * const params = market.getCollateralParamsByToken(collateralToken);
609
+ * console.log(params?.lltv);
610
+ * ```
611
+ */
612
+ getCollateralParamsByToken(token: Address): CollateralParams | undefined;
613
+ }