@morpho-org/midnight-sdk 0.1.0 → 1.0.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 (118) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +56 -46
  3. package/lib/cjs/abis.d.ts +1185 -996
  4. package/lib/cjs/abis.js +1445 -1211
  5. package/lib/cjs/api/MidnightApi.d.ts +22 -16
  6. package/lib/cjs/api/MidnightApi.js +22 -16
  7. package/lib/cjs/api/helpers.js +6 -3
  8. package/lib/cjs/api/types.d.ts +35 -9
  9. package/lib/cjs/constants.d.ts +12 -11
  10. package/lib/cjs/constants.js +14 -12
  11. package/lib/cjs/errors.d.ts +74 -1
  12. package/lib/cjs/errors.js +94 -3
  13. package/lib/cjs/fetch/Market.js +0 -1
  14. package/lib/cjs/fetch/index.d.ts +0 -1
  15. package/lib/cjs/fetch/index.js +0 -1
  16. package/lib/cjs/index.d.ts +1 -1
  17. package/lib/cjs/index.js +2 -23
  18. package/lib/cjs/market/Market.d.ts +99 -33
  19. package/lib/cjs/market/Market.js +137 -28
  20. package/lib/cjs/market/MarketUtils.d.ts +61 -41
  21. package/lib/cjs/market/MarketUtils.js +108 -48
  22. package/lib/cjs/market/Position.d.ts +16 -11
  23. package/lib/cjs/market/Position.js +18 -12
  24. package/lib/cjs/market/PositionUtils.d.ts +6 -4
  25. package/lib/cjs/market/PositionUtils.js +9 -6
  26. package/lib/cjs/math/TickLib.d.ts +22 -0
  27. package/lib/cjs/math/TickLib.js +30 -0
  28. package/lib/cjs/math/index.d.ts +0 -1
  29. package/lib/cjs/math/index.js +0 -1
  30. package/lib/cjs/offers/Offer.d.ts +217 -11
  31. package/lib/cjs/offers/Offer.js +215 -7
  32. package/lib/cjs/offers/OfferUtils.d.ts +245 -139
  33. package/lib/cjs/offers/OfferUtils.js +304 -36
  34. package/lib/cjs/queries/GetPosition.d.ts +1 -1
  35. package/lib/cjs/queries/GetPosition.js +1 -1
  36. package/lib/cjs/signatures/EcrecoverRatifierUtils.d.ts +66 -38
  37. package/lib/cjs/signatures/EcrecoverRatifierUtils.js +147 -79
  38. package/lib/cjs/signatures/Group.d.ts +12 -4
  39. package/lib/cjs/signatures/Group.js +12 -4
  40. package/lib/cjs/signatures/GroupUtils.d.ts +12 -4
  41. package/lib/cjs/signatures/GroupUtils.js +6 -2
  42. package/lib/cjs/signatures/Payload.d.ts +277 -277
  43. package/lib/cjs/signatures/Payload.js +517 -534
  44. package/lib/cjs/signatures/RatifierUtils.d.ts +57 -0
  45. package/lib/cjs/signatures/RatifierUtils.js +94 -0
  46. package/lib/cjs/signatures/SetterRatifierUtils.d.ts +21 -13
  47. package/lib/cjs/signatures/SetterRatifierUtils.js +25 -20
  48. package/lib/cjs/signatures/Tree.d.ts +28 -16
  49. package/lib/cjs/signatures/Tree.js +25 -13
  50. package/lib/cjs/signatures/TreeUtils.d.ts +181 -62
  51. package/lib/cjs/signatures/TreeUtils.js +73 -76
  52. package/lib/cjs/signatures/index.d.ts +1 -0
  53. package/lib/cjs/signatures/index.js +3 -0
  54. package/lib/cjs/signatures/offerStructInternal.d.ts +14 -0
  55. package/lib/cjs/signatures/offerStructInternal.js +72 -0
  56. package/lib/esm/abis.d.ts +1185 -996
  57. package/lib/esm/abis.js +1445 -1211
  58. package/lib/esm/api/MidnightApi.d.ts +22 -16
  59. package/lib/esm/api/MidnightApi.js +23 -17
  60. package/lib/esm/api/helpers.js +6 -3
  61. package/lib/esm/api/types.d.ts +35 -9
  62. package/lib/esm/constants.d.ts +12 -11
  63. package/lib/esm/constants.js +13 -11
  64. package/lib/esm/errors.d.ts +74 -1
  65. package/lib/esm/errors.js +89 -2
  66. package/lib/esm/fetch/Market.js +0 -1
  67. package/lib/esm/fetch/index.d.ts +0 -1
  68. package/lib/esm/fetch/index.js +0 -1
  69. package/lib/esm/index.d.ts +1 -1
  70. package/lib/esm/index.js +1 -1
  71. package/lib/esm/market/Market.d.ts +99 -33
  72. package/lib/esm/market/Market.js +137 -28
  73. package/lib/esm/market/MarketUtils.d.ts +61 -41
  74. package/lib/esm/market/MarketUtils.js +109 -49
  75. package/lib/esm/market/Position.d.ts +16 -11
  76. package/lib/esm/market/Position.js +19 -13
  77. package/lib/esm/market/PositionUtils.d.ts +6 -4
  78. package/lib/esm/market/PositionUtils.js +9 -6
  79. package/lib/esm/math/TickLib.d.ts +22 -0
  80. package/lib/esm/math/TickLib.js +31 -1
  81. package/lib/esm/math/index.d.ts +0 -1
  82. package/lib/esm/math/index.js +0 -1
  83. package/lib/esm/offers/Offer.d.ts +217 -11
  84. package/lib/esm/offers/Offer.js +216 -8
  85. package/lib/esm/offers/OfferUtils.d.ts +245 -139
  86. package/lib/esm/offers/OfferUtils.js +306 -38
  87. package/lib/esm/queries/GetPosition.d.ts +1 -1
  88. package/lib/esm/queries/GetPosition.js +1 -1
  89. package/lib/esm/signatures/EcrecoverRatifierUtils.d.ts +66 -38
  90. package/lib/esm/signatures/EcrecoverRatifierUtils.js +149 -81
  91. package/lib/esm/signatures/Group.d.ts +12 -4
  92. package/lib/esm/signatures/Group.js +12 -4
  93. package/lib/esm/signatures/GroupUtils.d.ts +12 -4
  94. package/lib/esm/signatures/GroupUtils.js +6 -2
  95. package/lib/esm/signatures/Payload.d.ts +277 -277
  96. package/lib/esm/signatures/Payload.js +517 -531
  97. package/lib/esm/signatures/RatifierUtils.d.ts +57 -0
  98. package/lib/esm/signatures/RatifierUtils.js +94 -0
  99. package/lib/esm/signatures/SetterRatifierUtils.d.ts +21 -13
  100. package/lib/esm/signatures/SetterRatifierUtils.js +25 -20
  101. package/lib/esm/signatures/Tree.d.ts +28 -16
  102. package/lib/esm/signatures/Tree.js +25 -13
  103. package/lib/esm/signatures/TreeUtils.d.ts +181 -62
  104. package/lib/esm/signatures/TreeUtils.js +75 -78
  105. package/lib/esm/signatures/index.d.ts +1 -0
  106. package/lib/esm/signatures/index.js +1 -0
  107. package/lib/esm/signatures/offerStructInternal.d.ts +14 -0
  108. package/lib/esm/signatures/offerStructInternal.js +67 -0
  109. package/package.json +28 -32
  110. package/src/index.ts +1 -1
  111. package/lib/cjs/fetch/Offer.d.ts +0 -74
  112. package/lib/cjs/fetch/Offer.js +0 -119
  113. package/lib/cjs/math/ConsumableUnitsLib.d.ts +0 -57
  114. package/lib/cjs/math/ConsumableUnitsLib.js +0 -77
  115. package/lib/esm/fetch/Offer.d.ts +0 -74
  116. package/lib/esm/fetch/Offer.js +0 -116
  117. package/lib/esm/math/ConsumableUnitsLib.d.ts +0 -57
  118. package/lib/esm/math/ConsumableUnitsLib.js +0 -74
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Market = exports.MarketParams = void 0;
4
4
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
5
+ const constants_js_1 = require("../constants.js");
5
6
  const errors_js_1 = require("../errors.js");
6
7
  const MarketUtils_js_1 = require("./MarketUtils.js");
7
8
  /**
@@ -12,12 +13,14 @@ const MarketUtils_js_1 = require("./MarketUtils.js");
12
13
  * import { MarketParams } from "@morpho-org/midnight-sdk";
13
14
  *
14
15
  * const params = new MarketParams({
16
+ * chainId: 8453,
17
+ * midnight: "0x0000000000000000000000000000000000001000",
15
18
  * loanToken: "0x0000000000000000000000000000000000000001",
16
19
  * collateralParams: [
17
20
  * {
18
21
  * token: "0x0000000000000000000000000000000000000002",
19
22
  * lltv: 770000000000000000n,
20
- * maxLif: 1061007957559681697n,
23
+ * liquidationCursor: 250000000000000000n,
21
24
  * oracle: "0x0000000000000000000000000000000000000003",
22
25
  * },
23
26
  * ],
@@ -30,6 +33,10 @@ const MarketUtils_js_1 = require("./MarketUtils.js");
30
33
  * ```
31
34
  */
32
35
  class MarketParams {
36
+ /** EIP-155 chain id captured in the market struct. */
37
+ chainId;
38
+ /** Core Midnight contract address captured in the market struct. */
39
+ midnight;
33
40
  /** Loan token address. */
34
41
  loanToken;
35
42
  /** Collateral definitions sorted by token. */
@@ -46,11 +53,30 @@ class MarketParams {
46
53
  * Creates normalized market params.
47
54
  *
48
55
  * @param params - Market params to normalize.
49
- * @throws {InvalidMarketParameterError} when the collateral list is empty, contains duplicate tokens, or has LLTV outside `[0, WAD]`.
56
+ * @throws {InvalidMarketParameterError} when the chain id is malformed or negative, or when the collateral list is empty, exceeds {@link MAX_COLLATERALS}, contains duplicate tokens, has LLTV outside `[0, WAD]`, has liquidation cursor outside `[0, WAD)`, or computes an invalid maximum liquidation incentive factor.
50
57
  */
51
58
  constructor(params) {
59
+ try {
60
+ this.chainId = BigInt(params.chainId);
61
+ }
62
+ catch (cause) {
63
+ throw new errors_js_1.InvalidMarketParameterError({
64
+ parameter: "chainId",
65
+ value: params.chainId,
66
+ instruction: "Provide a bigint-compatible EIP-155 chain id.",
67
+ cause,
68
+ });
69
+ }
70
+ this.midnight = params.midnight;
52
71
  this.loanToken = params.loanToken;
53
72
  const collateralParams = params.collateralParams.map(MarketUtils_js_1.MarketUtils.toCollateralParams);
73
+ if (this.chainId < 0n) {
74
+ throw new errors_js_1.InvalidMarketParameterError({
75
+ parameter: "chainId",
76
+ value: this.chainId,
77
+ instruction: "Use a non-negative EIP-155 chain id.",
78
+ });
79
+ }
54
80
  if (collateralParams.length === 0) {
55
81
  throw new errors_js_1.InvalidMarketParameterError({
56
82
  parameter: "collateralParams",
@@ -58,6 +84,13 @@ class MarketParams {
58
84
  instruction: "Provide at least one collateral.",
59
85
  });
60
86
  }
87
+ if (collateralParams.length > Number(constants_js_1.MAX_COLLATERALS)) {
88
+ throw new errors_js_1.InvalidMarketParameterError({
89
+ parameter: "collateralParams",
90
+ value: collateralParams.length,
91
+ instruction: `Provide at most ${constants_js_1.MAX_COLLATERALS} collaterals.`,
92
+ });
93
+ }
61
94
  const seenCollateralTokens = new Set();
62
95
  for (const collateral of collateralParams) {
63
96
  if (collateral.lltv < 0n || collateral.lltv > morpho_ts_1.MathLib.WAD) {
@@ -67,6 +100,31 @@ class MarketParams {
67
100
  instruction: "Use an LLTV between 0 and WAD.",
68
101
  });
69
102
  }
103
+ if (collateral.liquidationCursor < 0n ||
104
+ collateral.liquidationCursor >= morpho_ts_1.MathLib.WAD) {
105
+ throw new errors_js_1.InvalidMarketParameterError({
106
+ parameter: "collateralParams.liquidationCursor",
107
+ value: collateral.liquidationCursor,
108
+ instruction: "Use a liquidation cursor between 0 and WAD, exclusive of WAD.",
109
+ });
110
+ }
111
+ const maxLif = morpho_ts_1.MathLib.mulDivDown(morpho_ts_1.MathLib.WAD, morpho_ts_1.MathLib.WAD, morpho_ts_1.MathLib.WAD -
112
+ morpho_ts_1.MathLib.mulDivDown(collateral.liquidationCursor, morpho_ts_1.MathLib.WAD - collateral.lltv, morpho_ts_1.MathLib.WAD));
113
+ if (maxLif > 2n * morpho_ts_1.MathLib.WAD) {
114
+ throw new errors_js_1.InvalidMarketParameterError({
115
+ parameter: "collateralParams.liquidationCursor",
116
+ value: collateral.liquidationCursor,
117
+ instruction: "Use a liquidation cursor whose computed maximum LIF is at most 2 WAD.",
118
+ });
119
+ }
120
+ if (collateral.lltv !== morpho_ts_1.MathLib.WAD &&
121
+ collateral.lltv * maxLif > 999000000000000000n * morpho_ts_1.MathLib.WAD) {
122
+ throw new errors_js_1.InvalidMarketParameterError({
123
+ parameter: "collateralParams.liquidationCursor",
124
+ value: collateral.liquidationCursor,
125
+ instruction: "Use an LLTV and liquidation cursor whose computed maximum LIF product satisfies the protocol bound.",
126
+ });
127
+ }
70
128
  const token = collateral.token.toLowerCase();
71
129
  if (seenCollateralTokens.has(token)) {
72
130
  throw new errors_js_1.InvalidMarketParameterError({
@@ -96,12 +154,14 @@ class MarketParams {
96
154
  * import { MarketParams } from "@morpho-org/midnight-sdk";
97
155
  *
98
156
  * const params = MarketParams.from({
157
+ * chainId: 8453,
158
+ * midnight: "0x0000000000000000000000000000000000001000",
99
159
  * loanToken: "0x0000000000000000000000000000000000006000",
100
160
  * collateralParams: [
101
161
  * {
102
162
  * token: "0x0000000000000000000000000000000000007000",
103
163
  * lltv: 770000000000000000n,
104
- * maxLif: 1061007957559681697n,
164
+ * liquidationCursor: 250000000000000000n,
105
165
  * oracle: "0x0000000000000000000000000000000000008000",
106
166
  * },
107
167
  * ],
@@ -143,14 +203,15 @@ exports.MarketParams = MarketParams;
143
203
  * });
144
204
  *
145
205
  * const market = new Market({
146
- * chainId: 31337,
147
206
  * params: {
207
+ * chainId: 31337,
208
+ * midnight: "0x0000000000000000000000000000000000001000",
148
209
  * loanToken: "0x0000000000000000000000000000000000006000",
149
210
  * collateralParams: [
150
211
  * {
151
212
  * token: "0x0000000000000000000000000000000000007000",
152
213
  * lltv: 770000000000000000n,
153
- * maxLif: 1061007957559681697n,
214
+ * liquidationCursor: 250000000000000000n,
154
215
  * oracle: "0x0000000000000000000000000000000000008000",
155
216
  * },
156
217
  * ],
@@ -173,7 +234,7 @@ exports.MarketParams = MarketParams;
173
234
  class Market {
174
235
  /** Market id. */
175
236
  id;
176
- /** EIP-155 chain id used to derive the market id. */
237
+ /** EIP-155 chain id captured in the market struct. */
177
238
  chainId;
178
239
  /** Immutable market configuration. */
179
240
  params;
@@ -192,9 +253,9 @@ class Market {
192
253
  /** Market tick spacing. */
193
254
  tickSpacing;
194
255
  constructor(market) {
195
- this.chainId = BigInt(market.chainId);
196
256
  this.params = MarketParams.from(market.params);
197
- this.id = MarketUtils_js_1.MarketUtils.toId({ market: this.params, chainId: this.chainId });
257
+ this.chainId = this.params.chainId;
258
+ this.id = MarketUtils_js_1.MarketUtils.toId(this.params);
198
259
  this.totalUnits = BigInt(market.totalUnits);
199
260
  this.lossFactor = BigInt(market.lossFactor);
200
261
  this.withdrawable = BigInt(market.withdrawable);
@@ -203,6 +264,52 @@ class Market {
203
264
  this.continuousFee = market.continuousFee;
204
265
  this.tickSpacing = market.tickSpacing;
205
266
  }
267
+ /**
268
+ * Returns a hydrated market instance from class or plain input.
269
+ *
270
+ * Existing `Market` instances are returned as-is. Plain hydrated market objects
271
+ * are normalized through the constructor so nested params and bigint fields use
272
+ * the SDK's canonical shapes.
273
+ *
274
+ * @param market - Hydrated market class or plain market input.
275
+ * @returns Hydrated market instance.
276
+ * @throws {InvalidMarketParameterError} when nested market params are invalid.
277
+ * @example
278
+ * ```ts
279
+ * import { Market } from "@morpho-org/midnight-sdk";
280
+ *
281
+ * const market = Market.from({
282
+ * params: {
283
+ * chainId: 8453,
284
+ * midnight: "0x0000000000000000000000000000000000001000",
285
+ * loanToken: "0x0000000000000000000000000000000000006000",
286
+ * collateralParams: [
287
+ * {
288
+ * token: "0x0000000000000000000000000000000000007000",
289
+ * lltv: 770000000000000000n,
290
+ * liquidationCursor: 250000000000000000n,
291
+ * oracle: "0x0000000000000000000000000000000000008000",
292
+ * },
293
+ * ],
294
+ * maturity: 54_000n,
295
+ * rcfThreshold: 0n,
296
+ * enterGate: "0x0000000000000000000000000000000000000000",
297
+ * liquidatorGate: "0x0000000000000000000000000000000000000000",
298
+ * },
299
+ * totalUnits: 1_000n,
300
+ * lossFactor: 0n,
301
+ * withdrawable: 500n,
302
+ * continuousFeeCredit: 0n,
303
+ * settlementFeeCbps: [1, 2, 3, 4, 5, 6, 7],
304
+ * continuousFee: 10,
305
+ * tickSpacing: 4,
306
+ * });
307
+ * console.log(market.id);
308
+ * ```
309
+ */
310
+ static from(market) {
311
+ return market instanceof Market ? market : new Market(market);
312
+ }
206
313
  /**
207
314
  * Returns the non-negative time remaining before maturity.
208
315
  *
@@ -229,14 +336,15 @@ class Market {
229
336
  * });
230
337
  *
231
338
  * const market = new Market({
232
- * chainId: 31337,
233
339
  * params: {
340
+ * chainId: 31337,
341
+ * midnight: "0x0000000000000000000000000000000000001000",
234
342
  * loanToken: "0x0000000000000000000000000000000000006000",
235
343
  * collateralParams: [
236
344
  * {
237
345
  * token: "0x0000000000000000000000000000000000007000",
238
346
  * lltv: 770000000000000000n,
239
- * maxLif: 1061007957559681697n,
347
+ * liquidationCursor: 250000000000000000n,
240
348
  * oracle: "0x0000000000000000000000000000000000008000",
241
349
  * },
242
350
  * ],
@@ -289,14 +397,15 @@ class Market {
289
397
  * });
290
398
  *
291
399
  * const market = new Market({
292
- * chainId: 31337,
293
400
  * params: {
401
+ * chainId: 31337,
402
+ * midnight: "0x0000000000000000000000000000000000001000",
294
403
  * loanToken: "0x0000000000000000000000000000000000006000",
295
404
  * collateralParams: [
296
405
  * {
297
406
  * token: "0x0000000000000000000000000000000000007000",
298
407
  * lltv: 770000000000000000n,
299
- * maxLif: 1061007957559681697n,
408
+ * liquidationCursor: 250000000000000000n,
300
409
  * oracle: "0x0000000000000000000000000000000000008000",
301
410
  * },
302
411
  * ],
@@ -323,10 +432,11 @@ class Market {
323
432
  });
324
433
  }
325
434
  /**
326
- * Returns collateral params by numeric index.
435
+ * Returns collateral by numeric index.
327
436
  *
328
437
  * @param index - Collateral index.
329
- * @returns Collateral params, or undefined when the index is not configured.
438
+ * @returns Collateral entry for the configured index.
439
+ * @throws {UnknownCollateralIndexError} when the index is not configured.
330
440
  * @example
331
441
  * ```ts
332
442
  * import { registerCustomAddresses } from "@morpho-org/morpho-ts";
@@ -347,14 +457,15 @@ class Market {
347
457
  * });
348
458
  *
349
459
  * const market = new Market({
350
- * chainId: 31337,
351
460
  * params: {
461
+ * chainId: 31337,
462
+ * midnight: "0x0000000000000000000000000000000000001000",
352
463
  * loanToken: "0x0000000000000000000000000000000000006000",
353
464
  * collateralParams: [
354
465
  * {
355
466
  * token: "0x0000000000000000000000000000000000007000",
356
467
  * lltv: 770000000000000000n,
357
- * maxLif: 1061007957559681697n,
468
+ * liquidationCursor: 250000000000000000n,
358
469
  * oracle: "0x0000000000000000000000000000000000008000",
359
470
  * },
360
471
  * ],
@@ -371,16 +482,12 @@ class Market {
371
482
  * continuousFee: 10,
372
483
  * tickSpacing: 4,
373
484
  * });
374
- * const params = market.getCollateralParamsByIndex(0);
375
- * console.log(params?.token);
485
+ * const collateral = market.getCollateralByIndex(0);
486
+ * console.log(collateral.token);
376
487
  * ```
377
488
  */
378
- getCollateralParamsByIndex(index) {
379
- const normalizedIndex = BigInt(index);
380
- if (normalizedIndex < 0n ||
381
- normalizedIndex > BigInt(Number.MAX_SAFE_INTEGER))
382
- return undefined;
383
- return this.params.collateralParams[Number(normalizedIndex)];
489
+ getCollateralByIndex(index) {
490
+ return MarketUtils_js_1.MarketUtils.getCollateralByIndex(this, index);
384
491
  }
385
492
  /**
386
493
  * Returns the configured collateral index for a token.
@@ -408,14 +515,15 @@ class Market {
408
515
  *
409
516
  * const collateralToken = "0x0000000000000000000000000000000000007000";
410
517
  * const market = new Market({
411
- * chainId: 31337,
412
518
  * params: {
519
+ * chainId: 31337,
520
+ * midnight: "0x0000000000000000000000000000000000001000",
413
521
  * loanToken: "0x0000000000000000000000000000000000006000",
414
522
  * collateralParams: [
415
523
  * {
416
524
  * token: collateralToken,
417
525
  * lltv: 770000000000000000n,
418
- * maxLif: 1061007957559681697n,
526
+ * liquidationCursor: 250000000000000000n,
419
527
  * oracle: "0x0000000000000000000000000000000000008000",
420
528
  * },
421
529
  * ],
@@ -467,14 +575,15 @@ class Market {
467
575
  *
468
576
  * const collateralToken = "0x0000000000000000000000000000000000007000";
469
577
  * const market = new Market({
470
- * chainId: 31337,
471
578
  * params: {
579
+ * chainId: 31337,
580
+ * midnight: "0x0000000000000000000000000000000000001000",
472
581
  * loanToken: "0x0000000000000000000000000000000000006000",
473
582
  * collateralParams: [
474
583
  * {
475
584
  * token: collateralToken,
476
585
  * lltv: 770000000000000000n,
477
- * maxLif: 1061007957559681697n,
586
+ * liquidationCursor: 250000000000000000n,
478
587
  * oracle: "0x0000000000000000000000000000000000008000",
479
588
  * },
480
589
  * ],
@@ -17,7 +17,7 @@ export declare namespace MarketUtils {
17
17
  *
18
18
  * @param params.token - Collateral token address.
19
19
  * @param params.lltv - WAD-scaled liquidation loan-to-value.
20
- * @param params.maxLif - WAD-scaled maximum liquidation incentive factor.
20
+ * @param params.liquidationCursor - WAD-scaled liquidation cursor.
21
21
  * @param params.oracle - Oracle address used to price this collateral.
22
22
  * @returns Collateral params with bigint fields.
23
23
  * @example
@@ -27,10 +27,10 @@ export declare namespace MarketUtils {
27
27
  * const collateral = MarketUtils.toCollateralParams({
28
28
  * token: "0x0000000000000000000000000000000000000001",
29
29
  * lltv: 770000000000000000n,
30
- * maxLif: 1061007957559681697n,
30
+ * liquidationCursor: 250000000000000000n,
31
31
  * oracle: "0x0000000000000000000000000000000000000002",
32
32
  * });
33
- * console.log(collateral.maxLif);
33
+ * console.log(collateral.liquidationCursor);
34
34
  * ```
35
35
  */
36
36
  function toCollateralParams(params: CollateralParamsInput): CollateralParams;
@@ -44,12 +44,14 @@ export declare namespace MarketUtils {
44
44
  * import { MarketUtils } from "@morpho-org/midnight-sdk";
45
45
  *
46
46
  * const struct = MarketUtils.toStruct({
47
+ * chainId: 8453,
48
+ * midnight: "0x0000000000000000000000000000000000001000",
47
49
  * loanToken: "0x0000000000000000000000000000000000006000",
48
50
  * collateralParams: [
49
51
  * {
50
52
  * token: "0x0000000000000000000000000000000000007000",
51
53
  * lltv: 770000000000000000n,
52
- * maxLif: 1061007957559681697n,
54
+ * liquidationCursor: 250000000000000000n,
53
55
  * oracle: "0x0000000000000000000000000000000000008000",
54
56
  * },
55
57
  * ],
@@ -62,19 +64,51 @@ export declare namespace MarketUtils {
62
64
  * ```
63
65
  */
64
66
  function toStruct(market: MarketInput): MarketParams;
67
+ /**
68
+ * Returns configured collateral by index.
69
+ *
70
+ * @param market - Market params or hydrated market.
71
+ * @param index - Collateral index to look up.
72
+ * @returns Collateral entry for the configured index.
73
+ * @throws {UnknownCollateralIndexError} when the index is not configured.
74
+ * @example
75
+ * ```ts
76
+ * import { MarketUtils } from "@morpho-org/midnight-sdk";
77
+ *
78
+ * const collateral = MarketUtils.getCollateralByIndex({
79
+ * chainId: 8453,
80
+ * midnight: "0x0000000000000000000000000000000000001000",
81
+ * loanToken: "0x0000000000000000000000000000000000000001",
82
+ * collateralParams: [
83
+ * {
84
+ * token: "0x0000000000000000000000000000000000000002",
85
+ * lltv: 770000000000000000n,
86
+ * liquidationCursor: 250000000000000000n,
87
+ * oracle: "0x0000000000000000000000000000000000000003",
88
+ * },
89
+ * ],
90
+ * maturity: 1n,
91
+ * rcfThreshold: 0n,
92
+ * enterGate: "0x0000000000000000000000000000000000000000",
93
+ * liquidatorGate: "0x0000000000000000000000000000000000000000",
94
+ * }, 0n);
95
+ * console.log(collateral.token);
96
+ * ```
97
+ */
98
+ function getCollateralByIndex(market: MarketInput, index: BigIntish): CollateralParams;
65
99
  /**
66
100
  * Returns the liquidation incentive factor for an LLTV and liquidation cursor.
67
101
  *
68
102
  * @param input - WAD-scaled LLTV or collateral params carrying an LLTV.
69
- * @param cursor - WAD-scaled liquidation cursor, usually `LIQUIDATION_CURSOR_LOW` or `LIQUIDATION_CURSOR_HIGH`.
103
+ * @param cursor - WAD-scaled liquidation cursor.
70
104
  * @returns WAD-scaled liquidation incentive factor.
71
105
  * @example
72
106
  * ```ts
73
- * import { LIQUIDATION_CURSOR_LOW, MarketUtils } from "@morpho-org/midnight-sdk";
107
+ * import { MarketUtils } from "@morpho-org/midnight-sdk";
74
108
  *
75
109
  * const liquidationIncentiveFactor = MarketUtils.getLiquidationIncentiveFactor(
76
110
  * 770000000000000000n,
77
- * LIQUIDATION_CURSOR_LOW,
111
+ * 250000000000000000n,
78
112
  * );
79
113
  * console.log(liquidationIncentiveFactor);
80
114
  * ```
@@ -121,12 +155,14 @@ export declare namespace MarketUtils {
121
155
  * import { MarketUtils } from "@morpho-org/midnight-sdk";
122
156
  *
123
157
  * const hash = MarketUtils.hash({
158
+ * chainId: 8453,
159
+ * midnight: "0x0000000000000000000000000000000000001000",
124
160
  * loanToken: "0x0000000000000000000000000000000000000001",
125
161
  * collateralParams: [
126
162
  * {
127
163
  * token: "0x0000000000000000000000000000000000000002",
128
164
  * lltv: 770000000000000000n,
129
- * maxLif: 1061007957559681697n,
165
+ * liquidationCursor: 250000000000000000n,
130
166
  * oracle: "0x0000000000000000000000000000000000000003",
131
167
  * },
132
168
  * ],
@@ -142,48 +178,32 @@ export declare namespace MarketUtils {
142
178
  /**
143
179
  * Computes the Midnight id for a market using `IdLib.toId`.
144
180
  *
145
- * @param params.market - Market to hash.
146
- * @param params.chainId - EIP-155 chain id used to resolve the core Midnight address from the registry.
181
+ * @param market - Market to hash.
147
182
  * @returns Market id.
148
- * @throws {UnsupportedChainIdError} when no address registry exists for `chainId`.
149
- * @throws {UnknownAddressError} when the registry has no Midnight address for `chainId`.
150
183
  * @example
151
184
  * ```ts
152
- * import { ChainId, registerCustomAddresses } from "@morpho-org/morpho-ts";
153
185
  * import { MarketUtils } from "@morpho-org/midnight-sdk";
154
186
  *
155
- * registerCustomAddresses({
156
- * addresses: {
157
- * [ChainId.BaseMainnet]: {
158
- * midnight: "0x0000000000000000000000000000000000000001",
159
- * },
160
- * },
161
- * });
162
- *
163
187
  * const id = MarketUtils.toId({
164
- * market: {
165
- * loanToken: "0x0000000000000000000000000000000000000001",
166
- * collateralParams: [
167
- * {
168
- * token: "0x0000000000000000000000000000000000000002",
169
- * lltv: 770000000000000000n,
170
- * maxLif: 1061007957559681697n,
171
- * oracle: "0x0000000000000000000000000000000000000003",
172
- * },
173
- * ],
174
- * maturity: 1n,
175
- * rcfThreshold: 0n,
176
- * enterGate: "0x0000000000000000000000000000000000000000",
177
- * liquidatorGate: "0x0000000000000000000000000000000000000000",
178
- * },
179
- * chainId: ChainId.BaseMainnet,
188
+ * chainId: 8453,
189
+ * midnight: "0x0000000000000000000000000000000000001000",
190
+ * loanToken: "0x0000000000000000000000000000000000000001",
191
+ * collateralParams: [
192
+ * {
193
+ * token: "0x0000000000000000000000000000000000000002",
194
+ * lltv: 770000000000000000n,
195
+ * liquidationCursor: 250000000000000000n,
196
+ * oracle: "0x0000000000000000000000000000000000000003",
197
+ * },
198
+ * ],
199
+ * maturity: 1n,
200
+ * rcfThreshold: 0n,
201
+ * enterGate: "0x0000000000000000000000000000000000000000",
202
+ * liquidatorGate: "0x0000000000000000000000000000000000000000",
180
203
  * });
181
204
  * console.log(id);
182
205
  * ```
183
206
  */
184
- function toId(params: {
185
- readonly market: MarketInput;
186
- readonly chainId: BigIntish;
187
- }): `0x${string}`;
207
+ function toId(market: MarketInput): `0x${string}`;
188
208
  }
189
209
  export {};