@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
package/lib/cjs/errors.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InvalidMidnightApiResponseError = exports.MidnightApiError = exports.InvalidTypedDataSignatureError = exports.InvalidTreeError = exports.InvalidTreeHeightError = exports.InvalidOfferParameterError = exports.InvalidMarketParameterError = exports.InvalidPositionAccrualStateError = exports.InvalidPositionLossFactorError = exports.InvalidPositionAccrualTimestampError = exports.SettlementFeeExceedsPriceError = exports.InvalidTickSpacingError = exports.PriceGreaterThanOneError = exports.TickOutOfRangeError = exports.InvalidOfferGroupError = void 0;
3
+ exports.InvalidMidnightApiResponseError = exports.MidnightApiError = exports.InvalidTypedDataSignatureError = exports.MidnightMempoolValidationError = exports.ChainIdMismatchError = exports.InvalidTreeError = exports.InvalidTreeHeightError = exports.PayloadDecodeError = exports.InvalidOfferParameterError = exports.UnknownCollateralIndexError = exports.InvalidMarketParameterError = exports.InvalidPositionAccrualStateError = exports.InvalidPositionLossFactorError = exports.InvalidPositionAccrualTimestampError = exports.SettlementFeeExceedsPriceError = exports.InvalidTickSpacingError = exports.PriceGreaterThanOneError = exports.TickOutOfRangeError = exports.InvalidOfferGroupError = void 0;
4
4
  /**
5
5
  * Thrown when a Midnight offer group violates protocol-level group mechanics.
6
6
  *
@@ -171,6 +171,34 @@ class InvalidMarketParameterError extends Error {
171
171
  }
172
172
  }
173
173
  exports.InvalidMarketParameterError = InvalidMarketParameterError;
174
+ /**
175
+ * Thrown when a Midnight market collateral index is not configured.
176
+ *
177
+ * @example
178
+ * ```ts
179
+ * import { UnknownCollateralIndexError } from "@morpho-org/midnight-sdk";
180
+ *
181
+ * throw new UnknownCollateralIndexError({
182
+ * market: "0x1111111111111111111111111111111111111111111111111111111111111111",
183
+ * collateralIndex: 2n,
184
+ * });
185
+ * ```
186
+ * @param params.market - Market id whose collateral list was queried.
187
+ * @param params.collateralIndex - Missing collateral index.
188
+ */
189
+ class UnknownCollateralIndexError extends Error {
190
+ /** Market id whose collateral list was queried. */
191
+ market;
192
+ /** Missing collateral index. */
193
+ collateralIndex;
194
+ constructor(params) {
195
+ super(`Midnight market "${params.market}" has no collateral at index "${params.collateralIndex}". Use a configured collateral index.`);
196
+ this.name = "UnknownCollateralIndexError";
197
+ this.market = params.market;
198
+ this.collateralIndex = params.collateralIndex;
199
+ }
200
+ }
201
+ exports.UnknownCollateralIndexError = UnknownCollateralIndexError;
174
202
  /**
175
203
  * Thrown when an offer builder receives a parameter that cannot satisfy Midnight protocol rules.
176
204
  *
@@ -198,6 +226,26 @@ class InvalidOfferParameterError extends Error {
198
226
  }
199
227
  }
200
228
  exports.InvalidOfferParameterError = InvalidOfferParameterError;
229
+ /**
230
+ * Thrown when Midnight mempool payload bytes cannot be encoded or decoded.
231
+ *
232
+ * @example
233
+ * ```ts
234
+ * import { PayloadDecodeError } from "@morpho-org/midnight-sdk";
235
+ *
236
+ * throw new PayloadDecodeError("payload too short for header");
237
+ * ```
238
+ */
239
+ class PayloadDecodeError extends Error {
240
+ /** Machine-readable decode failure reason without the class message prefix. */
241
+ reason;
242
+ constructor(reason, cause) {
243
+ super(`Failed to decode payload: ${reason}`, cause ? { cause } : undefined);
244
+ this.name = "PayloadDecodeError";
245
+ this.reason = reason;
246
+ }
247
+ }
248
+ exports.PayloadDecodeError = PayloadDecodeError;
201
249
  /**
202
250
  * Thrown when a tree height exceeds the ratifier typehash table.
203
251
  *
@@ -232,6 +280,49 @@ class InvalidTreeError extends Error {
232
280
  }
233
281
  }
234
282
  exports.InvalidTreeError = InvalidTreeError;
283
+ /**
284
+ * Thrown when a viem client's chain id does not match the chain id required by a signing flow.
285
+ *
286
+ * @example
287
+ * ```ts
288
+ * import { ChainIdMismatchError } from "@morpho-org/midnight-sdk";
289
+ *
290
+ * throw new ChainIdMismatchError(1, 8453n);
291
+ * ```
292
+ */
293
+ class ChainIdMismatchError extends Error {
294
+ /** Chain id reported by the viem client, when configured. */
295
+ clientChainId;
296
+ /** Chain id required by the data being signed. */
297
+ expectedChainId;
298
+ constructor(clientChainId, expectedChainId) {
299
+ super(`Client chain id "${clientChainId}" does not match expected chain id "${expectedChainId}". Switch the viem client to the offer market chain before signing.`);
300
+ this.name = "ChainIdMismatchError";
301
+ this.clientChainId = clientChainId;
302
+ this.expectedChainId = expectedChainId;
303
+ }
304
+ }
305
+ exports.ChainIdMismatchError = ChainIdMismatchError;
306
+ /**
307
+ * Thrown when the Midnight API rejects a tree during mempool policy validation.
308
+ *
309
+ * @example
310
+ * ```ts
311
+ * import { MidnightMempoolValidationError } from "@morpho-org/midnight-sdk";
312
+ *
313
+ * throw new MidnightMempoolValidationError([{ rule: "tick_spacing" }]);
314
+ * ```
315
+ */
316
+ class MidnightMempoolValidationError extends Error {
317
+ /** Validation issues returned by the Midnight API. */
318
+ issues;
319
+ constructor(issues) {
320
+ super(`Midnight mempool validation failed with "${issues.length}" issue${issues.length === 1 ? "" : "s"}. Adjust the offer parameters and try again.`);
321
+ this.name = "MidnightMempoolValidationError";
322
+ this.issues = issues;
323
+ }
324
+ }
325
+ exports.MidnightMempoolValidationError = MidnightMempoolValidationError;
235
326
  /**
236
327
  * Thrown when a typed-data signature does not recover to the expected signer.
237
328
  *
@@ -247,8 +338,8 @@ exports.InvalidTreeError = InvalidTreeError;
247
338
  class InvalidTypedDataSignatureError extends Error {
248
339
  /** Signer address the signature was expected to recover. */
249
340
  signer;
250
- constructor(signer) {
251
- super(`Typed-data signature does not recover to signer "${signer}". Check the wallet account or signing transport.`);
341
+ constructor(signer, cause) {
342
+ super(`Typed-data signature does not recover to signer "${signer}". Check the wallet account or signing transport.`, cause === undefined ? undefined : { cause });
252
343
  this.name = "InvalidTypedDataSignatureError";
253
344
  this.signer = signer;
254
345
  }
@@ -96,7 +96,6 @@ async function fetchMarket(client, params) {
96
96
  ]);
97
97
  const [totalUnits, lossFactor, withdrawable, continuousFeeCredit, settlementFeeCbps0, settlementFeeCbps1, settlementFeeCbps2, settlementFeeCbps3, settlementFeeCbps4, settlementFeeCbps5, settlementFeeCbps6, continuousFee, tickSpacing,] = state;
98
98
  return new index_js_1.Market({
99
- chainId,
100
99
  params: new index_js_1.MarketParams(market),
101
100
  totalUnits,
102
101
  lossFactor,
@@ -1,5 +1,4 @@
1
1
  export * from "./Market.js";
2
- export * from "./Offer.js";
3
2
  export * from "./Position.js";
4
3
  export * from "./Ratifier.js";
5
4
  export * from "./types.js";
@@ -15,7 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./Market.js"), exports);
18
- __exportStar(require("./Offer.js"), exports);
19
18
  __exportStar(require("./Position.js"), exports);
20
19
  __exportStar(require("./Ratifier.js"), exports);
21
20
  __exportStar(require("./types.js"), exports);
@@ -15,4 +15,4 @@ export * from "./signatures/index.js";
15
15
  * Encoded payloads are always `Hex` strings ready to be included in onchain
16
16
  * mempool submission calldata.
17
17
  */
18
- export * as Payload from "./signatures/Payload.js";
18
+ export { Payload } from "./signatures/Payload.js";
package/lib/cjs/index.js CHANGED
@@ -10,31 +10,9 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
10
10
  if (k2 === undefined) k2 = k;
11
11
  o[k2] = m[k];
12
12
  }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
19
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20
15
  };
21
- var __importStar = (this && this.__importStar) || (function () {
22
- var ownKeys = function(o) {
23
- ownKeys = Object.getOwnPropertyNames || function (o) {
24
- var ar = [];
25
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
- return ar;
27
- };
28
- return ownKeys(o);
29
- };
30
- return function (mod) {
31
- if (mod && mod.__esModule) return mod;
32
- var result = {};
33
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
- __setModuleDefault(result, mod);
35
- return result;
36
- };
37
- })();
38
16
  Object.defineProperty(exports, "__esModule", { value: true });
39
17
  exports.Payload = void 0;
40
18
  __exportStar(require("./abis.js"), exports);
@@ -54,4 +32,5 @@ __exportStar(require("./signatures/index.js"), exports);
54
32
  * Encoded payloads are always `Hex` strings ready to be included in onchain
55
33
  * mempool submission calldata.
56
34
  */
57
- exports.Payload = __importStar(require("./signatures/Payload.js"));
35
+ var Payload_js_1 = require("./signatures/Payload.js");
36
+ Object.defineProperty(exports, "Payload", { enumerable: true, get: function () { return Payload_js_1.Payload; } });
@@ -30,7 +30,7 @@ export type SettlementFeeCbps = readonly [
30
30
  * const params: ICollateralParams = {
31
31
  * token: "0x0000000000000000000000000000000000000001",
32
32
  * lltv: 770000000000000000n,
33
- * maxLif: 1061007957559681697n,
33
+ * liquidationCursor: 250000000000000000n,
34
34
  * oracle: "0x0000000000000000000000000000000000000002",
35
35
  * };
36
36
  * ```
@@ -40,8 +40,8 @@ export interface ICollateralParams {
40
40
  readonly token: Address;
41
41
  /** WAD-scaled liquidation loan-to-value. */
42
42
  readonly lltv: BigIntish;
43
- /** WAD-scaled maximum liquidation incentive factor. */
44
- readonly maxLif: BigIntish;
43
+ /** WAD-scaled liquidation cursor used to compute the maximum liquidation incentive factor. */
44
+ readonly liquidationCursor: BigIntish;
45
45
  /** Oracle address for this collateral. */
46
46
  readonly oracle: Address;
47
47
  }
@@ -55,7 +55,7 @@ export interface ICollateralParams {
55
55
  * const params: CollateralParams = {
56
56
  * token: "0x0000000000000000000000000000000000000001",
57
57
  * lltv: 770000000000000000n,
58
- * maxLif: 1298701298701298701n,
58
+ * liquidationCursor: 250000000000000000n,
59
59
  * oracle: "0x0000000000000000000000000000000000000002",
60
60
  * };
61
61
  * console.log(params.lltv);
@@ -66,8 +66,8 @@ export interface CollateralParams {
66
66
  readonly token: Address;
67
67
  /** WAD-scaled liquidation loan-to-value. */
68
68
  readonly lltv: bigint;
69
- /** WAD-scaled maximum liquidation incentive factor. */
70
- readonly maxLif: bigint;
69
+ /** WAD-scaled liquidation cursor used to compute the maximum liquidation incentive factor. */
70
+ readonly liquidationCursor: bigint;
71
71
  /** Oracle address for this collateral. */
72
72
  readonly oracle: Address;
73
73
  }
@@ -79,12 +79,14 @@ export interface CollateralParams {
79
79
  * import type { IMarketParams } from "@morpho-org/midnight-sdk";
80
80
  *
81
81
  * const params: IMarketParams = {
82
+ * chainId: 8453,
83
+ * midnight: "0x0000000000000000000000000000000000001000",
82
84
  * loanToken: "0x0000000000000000000000000000000000000001",
83
85
  * collateralParams: [
84
86
  * {
85
87
  * token: "0x0000000000000000000000000000000000000002",
86
88
  * lltv: 770000000000000000n,
87
- * maxLif: 1061007957559681697n,
89
+ * liquidationCursor: 250000000000000000n,
88
90
  * oracle: "0x0000000000000000000000000000000000000003",
89
91
  * },
90
92
  * ],
@@ -96,6 +98,10 @@ export interface CollateralParams {
96
98
  * ```
97
99
  */
98
100
  export interface IMarketParams {
101
+ /** EIP-155 chain id captured in the market struct. */
102
+ readonly chainId: BigIntish;
103
+ /** Core Midnight contract address captured in the market struct. */
104
+ readonly midnight: Address;
99
105
  /** Loan token address. */
100
106
  readonly loanToken: Address;
101
107
  /** Collateral definitions; `MarketParams` stores them sorted by token and rejects duplicate tokens. */
@@ -117,12 +123,14 @@ export interface IMarketParams {
117
123
  * import { MarketParams } from "@morpho-org/midnight-sdk";
118
124
  *
119
125
  * const params = new MarketParams({
126
+ * chainId: 8453,
127
+ * midnight: "0x0000000000000000000000000000000000001000",
120
128
  * loanToken: "0x0000000000000000000000000000000000000001",
121
129
  * collateralParams: [
122
130
  * {
123
131
  * token: "0x0000000000000000000000000000000000000002",
124
132
  * lltv: 770000000000000000n,
125
- * maxLif: 1061007957559681697n,
133
+ * liquidationCursor: 250000000000000000n,
126
134
  * oracle: "0x0000000000000000000000000000000000000003",
127
135
  * },
128
136
  * ],
@@ -135,6 +143,10 @@ export interface IMarketParams {
135
143
  * ```
136
144
  */
137
145
  export declare class MarketParams {
146
+ /** EIP-155 chain id captured in the market struct. */
147
+ readonly chainId: bigint;
148
+ /** Core Midnight contract address captured in the market struct. */
149
+ readonly midnight: Address;
138
150
  /** Loan token address. */
139
151
  readonly loanToken: Address;
140
152
  /** Collateral definitions sorted by token. */
@@ -151,7 +163,7 @@ export declare class MarketParams {
151
163
  * Creates normalized market params.
152
164
  *
153
165
  * @param params - Market params to normalize.
154
- * @throws {InvalidMarketParameterError} when the collateral list is empty, contains duplicate tokens, or has LLTV outside `[0, WAD]`.
166
+ * @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.
155
167
  */
156
168
  constructor(params: IMarketParams);
157
169
  /**
@@ -167,12 +179,14 @@ export declare class MarketParams {
167
179
  * import { MarketParams } from "@morpho-org/midnight-sdk";
168
180
  *
169
181
  * const params = MarketParams.from({
182
+ * chainId: 8453,
183
+ * midnight: "0x0000000000000000000000000000000000001000",
170
184
  * loanToken: "0x0000000000000000000000000000000000006000",
171
185
  * collateralParams: [
172
186
  * {
173
187
  * token: "0x0000000000000000000000000000000000007000",
174
188
  * lltv: 770000000000000000n,
175
- * maxLif: 1061007957559681697n,
189
+ * liquidationCursor: 250000000000000000n,
176
190
  * oracle: "0x0000000000000000000000000000000000008000",
177
191
  * },
178
192
  * ],
@@ -194,14 +208,15 @@ export declare class MarketParams {
194
208
  * import type { IMarket } from "@morpho-org/midnight-sdk";
195
209
  *
196
210
  * const market: IMarket = {
197
- * chainId: 31337,
198
211
  * params: {
212
+ * chainId: 31337,
213
+ * midnight: "0x0000000000000000000000000000000000001000",
199
214
  * loanToken: "0x0000000000000000000000000000000000000001",
200
215
  * collateralParams: [
201
216
  * {
202
217
  * token: "0x0000000000000000000000000000000000000002",
203
218
  * lltv: 770000000000000000n,
204
- * maxLif: 1061007957559681697n,
219
+ * liquidationCursor: 250000000000000000n,
205
220
  * oracle: "0x0000000000000000000000000000000000000003",
206
221
  * },
207
222
  * ],
@@ -221,8 +236,6 @@ export declare class MarketParams {
221
236
  * ```
222
237
  */
223
238
  export interface IMarket {
224
- /** EIP-155 chain id used to derive the market id. */
225
- readonly chainId: BigIntish;
226
239
  /** Immutable market configuration. */
227
240
  readonly params: IMarketParams;
228
241
  /** Total market units. */
@@ -248,12 +261,14 @@ export interface IMarket {
248
261
  * import type { MarketInput } from "@morpho-org/midnight-sdk";
249
262
  *
250
263
  * const market: MarketInput = {
264
+ * chainId: 8453,
265
+ * midnight: "0x0000000000000000000000000000000000001000",
251
266
  * loanToken: "0x0000000000000000000000000000000000006000",
252
267
  * collateralParams: [
253
268
  * {
254
269
  * token: "0x0000000000000000000000000000000000007000",
255
270
  * lltv: 770000000000000000n,
256
- * maxLif: 1061007957559681697n,
271
+ * liquidationCursor: 250000000000000000n,
257
272
  * oracle: "0x0000000000000000000000000000000000008000",
258
273
  * },
259
274
  * ],
@@ -289,14 +304,15 @@ export type MarketInput = IMarketParams | IMarket;
289
304
  * });
290
305
  *
291
306
  * const market = new Market({
292
- * chainId: 31337,
293
307
  * params: {
308
+ * chainId: 31337,
309
+ * midnight: "0x0000000000000000000000000000000000001000",
294
310
  * loanToken: "0x0000000000000000000000000000000000006000",
295
311
  * collateralParams: [
296
312
  * {
297
313
  * token: "0x0000000000000000000000000000000000007000",
298
314
  * lltv: 770000000000000000n,
299
- * maxLif: 1061007957559681697n,
315
+ * liquidationCursor: 250000000000000000n,
300
316
  * oracle: "0x0000000000000000000000000000000000008000",
301
317
  * },
302
318
  * ],
@@ -319,7 +335,7 @@ export type MarketInput = IMarketParams | IMarket;
319
335
  export declare class Market {
320
336
  /** Market id. */
321
337
  readonly id: Hash;
322
- /** EIP-155 chain id used to derive the market id. */
338
+ /** EIP-155 chain id captured in the market struct. */
323
339
  readonly chainId: bigint;
324
340
  /** Immutable market configuration. */
325
341
  readonly params: MarketParams;
@@ -338,6 +354,50 @@ export declare class Market {
338
354
  /** Market tick spacing. */
339
355
  readonly tickSpacing: number;
340
356
  constructor(market: IMarket);
357
+ /**
358
+ * Returns a hydrated market instance from class or plain input.
359
+ *
360
+ * Existing `Market` instances are returned as-is. Plain hydrated market objects
361
+ * are normalized through the constructor so nested params and bigint fields use
362
+ * the SDK's canonical shapes.
363
+ *
364
+ * @param market - Hydrated market class or plain market input.
365
+ * @returns Hydrated market instance.
366
+ * @throws {InvalidMarketParameterError} when nested market params are invalid.
367
+ * @example
368
+ * ```ts
369
+ * import { Market } from "@morpho-org/midnight-sdk";
370
+ *
371
+ * const market = Market.from({
372
+ * params: {
373
+ * chainId: 8453,
374
+ * midnight: "0x0000000000000000000000000000000000001000",
375
+ * loanToken: "0x0000000000000000000000000000000000006000",
376
+ * collateralParams: [
377
+ * {
378
+ * token: "0x0000000000000000000000000000000000007000",
379
+ * lltv: 770000000000000000n,
380
+ * liquidationCursor: 250000000000000000n,
381
+ * oracle: "0x0000000000000000000000000000000000008000",
382
+ * },
383
+ * ],
384
+ * maturity: 54_000n,
385
+ * rcfThreshold: 0n,
386
+ * enterGate: "0x0000000000000000000000000000000000000000",
387
+ * liquidatorGate: "0x0000000000000000000000000000000000000000",
388
+ * },
389
+ * totalUnits: 1_000n,
390
+ * lossFactor: 0n,
391
+ * withdrawable: 500n,
392
+ * continuousFeeCredit: 0n,
393
+ * settlementFeeCbps: [1, 2, 3, 4, 5, 6, 7],
394
+ * continuousFee: 10,
395
+ * tickSpacing: 4,
396
+ * });
397
+ * console.log(market.id);
398
+ * ```
399
+ */
400
+ static from(market: IMarket | Market): Market;
341
401
  /**
342
402
  * Returns the non-negative time remaining before maturity.
343
403
  *
@@ -364,14 +424,15 @@ export declare class Market {
364
424
  * });
365
425
  *
366
426
  * const market = new Market({
367
- * chainId: 31337,
368
427
  * params: {
428
+ * chainId: 31337,
429
+ * midnight: "0x0000000000000000000000000000000000001000",
369
430
  * loanToken: "0x0000000000000000000000000000000000006000",
370
431
  * collateralParams: [
371
432
  * {
372
433
  * token: "0x0000000000000000000000000000000000007000",
373
434
  * lltv: 770000000000000000n,
374
- * maxLif: 1061007957559681697n,
435
+ * liquidationCursor: 250000000000000000n,
375
436
  * oracle: "0x0000000000000000000000000000000000008000",
376
437
  * },
377
438
  * ],
@@ -418,14 +479,15 @@ export declare class Market {
418
479
  * });
419
480
  *
420
481
  * const market = new Market({
421
- * chainId: 31337,
422
482
  * params: {
483
+ * chainId: 31337,
484
+ * midnight: "0x0000000000000000000000000000000000001000",
423
485
  * loanToken: "0x0000000000000000000000000000000000006000",
424
486
  * collateralParams: [
425
487
  * {
426
488
  * token: "0x0000000000000000000000000000000000007000",
427
489
  * lltv: 770000000000000000n,
428
- * maxLif: 1061007957559681697n,
490
+ * liquidationCursor: 250000000000000000n,
429
491
  * oracle: "0x0000000000000000000000000000000000008000",
430
492
  * },
431
493
  * ],
@@ -447,10 +509,11 @@ export declare class Market {
447
509
  */
448
510
  getSettlementFee(timeToMaturity: BigIntish): bigint;
449
511
  /**
450
- * Returns collateral params by numeric index.
512
+ * Returns collateral by numeric index.
451
513
  *
452
514
  * @param index - Collateral index.
453
- * @returns Collateral params, or undefined when the index is not configured.
515
+ * @returns Collateral entry for the configured index.
516
+ * @throws {UnknownCollateralIndexError} when the index is not configured.
454
517
  * @example
455
518
  * ```ts
456
519
  * import { registerCustomAddresses } from "@morpho-org/morpho-ts";
@@ -471,14 +534,15 @@ export declare class Market {
471
534
  * });
472
535
  *
473
536
  * const market = new Market({
474
- * chainId: 31337,
475
537
  * params: {
538
+ * chainId: 31337,
539
+ * midnight: "0x0000000000000000000000000000000000001000",
476
540
  * loanToken: "0x0000000000000000000000000000000000006000",
477
541
  * collateralParams: [
478
542
  * {
479
543
  * token: "0x0000000000000000000000000000000000007000",
480
544
  * lltv: 770000000000000000n,
481
- * maxLif: 1061007957559681697n,
545
+ * liquidationCursor: 250000000000000000n,
482
546
  * oracle: "0x0000000000000000000000000000000000008000",
483
547
  * },
484
548
  * ],
@@ -495,11 +559,11 @@ export declare class Market {
495
559
  * continuousFee: 10,
496
560
  * tickSpacing: 4,
497
561
  * });
498
- * const params = market.getCollateralParamsByIndex(0);
499
- * console.log(params?.token);
562
+ * const collateral = market.getCollateralByIndex(0);
563
+ * console.log(collateral.token);
500
564
  * ```
501
565
  */
502
- getCollateralParamsByIndex(index: BigIntish): CollateralParams | undefined;
566
+ getCollateralByIndex(index: BigIntish): CollateralParams;
503
567
  /**
504
568
  * Returns the configured collateral index for a token.
505
569
  *
@@ -526,14 +590,15 @@ export declare class Market {
526
590
  *
527
591
  * const collateralToken = "0x0000000000000000000000000000000000007000";
528
592
  * const market = new Market({
529
- * chainId: 31337,
530
593
  * params: {
594
+ * chainId: 31337,
595
+ * midnight: "0x0000000000000000000000000000000000001000",
531
596
  * loanToken: "0x0000000000000000000000000000000000006000",
532
597
  * collateralParams: [
533
598
  * {
534
599
  * token: collateralToken,
535
600
  * lltv: 770000000000000000n,
536
- * maxLif: 1061007957559681697n,
601
+ * liquidationCursor: 250000000000000000n,
537
602
  * oracle: "0x0000000000000000000000000000000000008000",
538
603
  * },
539
604
  * ],
@@ -581,14 +646,15 @@ export declare class Market {
581
646
  *
582
647
  * const collateralToken = "0x0000000000000000000000000000000000007000";
583
648
  * const market = new Market({
584
- * chainId: 31337,
585
649
  * params: {
650
+ * chainId: 31337,
651
+ * midnight: "0x0000000000000000000000000000000000001000",
586
652
  * loanToken: "0x0000000000000000000000000000000000006000",
587
653
  * collateralParams: [
588
654
  * {
589
655
  * token: collateralToken,
590
656
  * lltv: 770000000000000000n,
591
- * maxLif: 1061007957559681697n,
657
+ * liquidationCursor: 250000000000000000n,
592
658
  * oracle: "0x0000000000000000000000000000000000008000",
593
659
  * },
594
660
  * ],