@morpho-org/midnight-sdk 0.1.0 → 1.1.1

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 (128) 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 +89 -19
  7. package/lib/cjs/api/helpers.d.ts +11 -1
  8. package/lib/cjs/api/helpers.js +54 -4
  9. package/lib/cjs/api/types.d.ts +35 -9
  10. package/lib/cjs/constants.d.ts +12 -11
  11. package/lib/cjs/constants.js +14 -12
  12. package/lib/cjs/errors.d.ts +89 -1
  13. package/lib/cjs/errors.js +114 -3
  14. package/lib/cjs/fetch/Market.js +37 -3
  15. package/lib/cjs/fetch/index.d.ts +0 -1
  16. package/lib/cjs/fetch/index.js +0 -1
  17. package/lib/cjs/fetch/utils.d.ts +1 -1
  18. package/lib/cjs/fetch/utils.js +9 -2
  19. package/lib/cjs/index.d.ts +1 -1
  20. package/lib/cjs/index.js +2 -23
  21. package/lib/cjs/market/Market.d.ts +99 -33
  22. package/lib/cjs/market/Market.js +137 -28
  23. package/lib/cjs/market/MarketUtils.d.ts +61 -41
  24. package/lib/cjs/market/MarketUtils.js +108 -48
  25. package/lib/cjs/market/Position.d.ts +16 -11
  26. package/lib/cjs/market/Position.js +18 -12
  27. package/lib/cjs/market/PositionUtils.d.ts +6 -4
  28. package/lib/cjs/market/PositionUtils.js +9 -6
  29. package/lib/cjs/math/TickLib.d.ts +22 -0
  30. package/lib/cjs/math/TickLib.js +30 -0
  31. package/lib/cjs/math/index.d.ts +0 -1
  32. package/lib/cjs/math/index.js +0 -1
  33. package/lib/cjs/offers/Offer.d.ts +218 -12
  34. package/lib/cjs/offers/Offer.js +215 -7
  35. package/lib/cjs/offers/OfferUtils.d.ts +249 -143
  36. package/lib/cjs/offers/OfferUtils.js +326 -45
  37. package/lib/cjs/queries/GetPosition.d.ts +1 -1
  38. package/lib/cjs/queries/GetPosition.js +1 -1
  39. package/lib/cjs/signatures/EcrecoverRatifierUtils.d.ts +184 -38
  40. package/lib/cjs/signatures/EcrecoverRatifierUtils.js +296 -80
  41. package/lib/cjs/signatures/Group.d.ts +12 -4
  42. package/lib/cjs/signatures/Group.js +17 -7
  43. package/lib/cjs/signatures/GroupUtils.d.ts +60 -4
  44. package/lib/cjs/signatures/GroupUtils.js +57 -2
  45. package/lib/cjs/signatures/Payload.d.ts +277 -277
  46. package/lib/cjs/signatures/Payload.js +517 -534
  47. package/lib/cjs/signatures/RatifierUtils.d.ts +57 -0
  48. package/lib/cjs/signatures/RatifierUtils.js +105 -0
  49. package/lib/cjs/signatures/SetterRatifierUtils.d.ts +52 -13
  50. package/lib/cjs/signatures/SetterRatifierUtils.js +62 -19
  51. package/lib/cjs/signatures/Tree.d.ts +28 -16
  52. package/lib/cjs/signatures/Tree.js +35 -15
  53. package/lib/cjs/signatures/TreeUtils.d.ts +185 -63
  54. package/lib/cjs/signatures/TreeUtils.js +89 -79
  55. package/lib/cjs/signatures/eip712.d.ts +22 -0
  56. package/lib/cjs/signatures/eip712.js +26 -0
  57. package/lib/cjs/signatures/index.d.ts +2 -0
  58. package/lib/cjs/signatures/index.js +4 -0
  59. package/lib/cjs/signatures/offerStructInternal.d.ts +14 -0
  60. package/lib/cjs/signatures/offerStructInternal.js +72 -0
  61. package/lib/esm/abis.d.ts +1185 -996
  62. package/lib/esm/abis.js +1445 -1211
  63. package/lib/esm/api/MidnightApi.d.ts +22 -16
  64. package/lib/esm/api/MidnightApi.js +91 -21
  65. package/lib/esm/api/helpers.d.ts +11 -1
  66. package/lib/esm/api/helpers.js +54 -5
  67. package/lib/esm/api/types.d.ts +35 -9
  68. package/lib/esm/constants.d.ts +12 -11
  69. package/lib/esm/constants.js +13 -11
  70. package/lib/esm/errors.d.ts +89 -1
  71. package/lib/esm/errors.js +108 -2
  72. package/lib/esm/fetch/Market.js +38 -4
  73. package/lib/esm/fetch/index.d.ts +0 -1
  74. package/lib/esm/fetch/index.js +0 -1
  75. package/lib/esm/fetch/utils.d.ts +1 -1
  76. package/lib/esm/fetch/utils.js +9 -2
  77. package/lib/esm/index.d.ts +1 -1
  78. package/lib/esm/index.js +1 -1
  79. package/lib/esm/market/Market.d.ts +99 -33
  80. package/lib/esm/market/Market.js +137 -28
  81. package/lib/esm/market/MarketUtils.d.ts +61 -41
  82. package/lib/esm/market/MarketUtils.js +109 -49
  83. package/lib/esm/market/Position.d.ts +16 -11
  84. package/lib/esm/market/Position.js +19 -13
  85. package/lib/esm/market/PositionUtils.d.ts +6 -4
  86. package/lib/esm/market/PositionUtils.js +9 -6
  87. package/lib/esm/math/TickLib.d.ts +22 -0
  88. package/lib/esm/math/TickLib.js +31 -1
  89. package/lib/esm/math/index.d.ts +0 -1
  90. package/lib/esm/math/index.js +0 -1
  91. package/lib/esm/offers/Offer.d.ts +218 -12
  92. package/lib/esm/offers/Offer.js +216 -8
  93. package/lib/esm/offers/OfferUtils.d.ts +249 -143
  94. package/lib/esm/offers/OfferUtils.js +329 -48
  95. package/lib/esm/queries/GetPosition.d.ts +1 -1
  96. package/lib/esm/queries/GetPosition.js +1 -1
  97. package/lib/esm/signatures/EcrecoverRatifierUtils.d.ts +184 -38
  98. package/lib/esm/signatures/EcrecoverRatifierUtils.js +298 -82
  99. package/lib/esm/signatures/Group.d.ts +12 -4
  100. package/lib/esm/signatures/Group.js +17 -7
  101. package/lib/esm/signatures/GroupUtils.d.ts +60 -4
  102. package/lib/esm/signatures/GroupUtils.js +57 -2
  103. package/lib/esm/signatures/Payload.d.ts +277 -277
  104. package/lib/esm/signatures/Payload.js +517 -531
  105. package/lib/esm/signatures/RatifierUtils.d.ts +57 -0
  106. package/lib/esm/signatures/RatifierUtils.js +105 -0
  107. package/lib/esm/signatures/SetterRatifierUtils.d.ts +52 -13
  108. package/lib/esm/signatures/SetterRatifierUtils.js +62 -19
  109. package/lib/esm/signatures/Tree.d.ts +28 -16
  110. package/lib/esm/signatures/Tree.js +36 -16
  111. package/lib/esm/signatures/TreeUtils.d.ts +185 -63
  112. package/lib/esm/signatures/TreeUtils.js +91 -81
  113. package/lib/esm/signatures/eip712.d.ts +22 -0
  114. package/lib/esm/signatures/eip712.js +22 -0
  115. package/lib/esm/signatures/index.d.ts +2 -0
  116. package/lib/esm/signatures/index.js +2 -0
  117. package/lib/esm/signatures/offerStructInternal.d.ts +14 -0
  118. package/lib/esm/signatures/offerStructInternal.js +67 -0
  119. package/package.json +31 -34
  120. package/lib/cjs/fetch/Offer.d.ts +0 -74
  121. package/lib/cjs/fetch/Offer.js +0 -119
  122. package/lib/cjs/math/ConsumableUnitsLib.d.ts +0 -57
  123. package/lib/cjs/math/ConsumableUnitsLib.js +0 -77
  124. package/lib/esm/fetch/Offer.d.ts +0 -74
  125. package/lib/esm/fetch/Offer.js +0 -116
  126. package/lib/esm/math/ConsumableUnitsLib.d.ts +0 -57
  127. package/lib/esm/math/ConsumableUnitsLib.js +0 -74
  128. package/src/index.ts +0 -19
@@ -19,14 +19,15 @@ import type { IPosition } from "./Position.js";
19
19
  * collateral: [50n],
20
20
  * },
21
21
  * market: {
22
- * chainId: 8453,
23
22
  * params: {
23
+ * chainId: 8453,
24
+ * midnight: "0x0000000000000000000000000000000000001000",
24
25
  * loanToken: "0x0000000000000000000000000000000000006000",
25
26
  * collateralParams: [
26
27
  * {
27
28
  * token: "0x0000000000000000000000000000000000007000",
28
29
  * lltv: 770000000000000000n,
29
- * maxLif: 1061007957559681697n,
30
+ * liquidationCursor: 250000000000000000n,
30
31
  * oracle: "0x0000000000000000000000000000000000008000",
31
32
  * },
32
33
  * ],
@@ -74,14 +75,15 @@ export declare namespace PositionUtils {
74
75
  * collateral: [50n],
75
76
  * },
76
77
  * market: {
77
- * chainId: 8453,
78
78
  * params: {
79
+ * chainId: 8453,
80
+ * midnight: "0x0000000000000000000000000000000000001000",
79
81
  * loanToken: "0x0000000000000000000000000000000000006000",
80
82
  * collateralParams: [
81
83
  * {
82
84
  * token: "0x0000000000000000000000000000000000007000",
83
85
  * lltv: 770000000000000000n,
84
- * maxLif: 1061007957559681697n,
86
+ * liquidationCursor: 250000000000000000n,
85
87
  * oracle: "0x0000000000000000000000000000000000008000",
86
88
  * },
87
89
  * ],
@@ -21,14 +21,15 @@ const errors_js_1 = require("../errors.js");
21
21
  * collateral: [50n],
22
22
  * },
23
23
  * market: {
24
- * chainId: 8453,
25
24
  * params: {
25
+ * chainId: 8453,
26
+ * midnight: "0x0000000000000000000000000000000000001000",
26
27
  * loanToken: "0x0000000000000000000000000000000000006000",
27
28
  * collateralParams: [
28
29
  * {
29
30
  * token: "0x0000000000000000000000000000000000007000",
30
31
  * lltv: 770000000000000000n,
31
- * maxLif: 1061007957559681697n,
32
+ * liquidationCursor: 250000000000000000n,
32
33
  * oracle: "0x0000000000000000000000000000000000008000",
33
34
  * },
34
35
  * ],
@@ -77,14 +78,15 @@ var PositionUtils;
77
78
  * collateral: [50n],
78
79
  * },
79
80
  * market: {
80
- * chainId: 8453,
81
81
  * params: {
82
+ * chainId: 8453,
83
+ * midnight: "0x0000000000000000000000000000000000001000",
82
84
  * loanToken: "0x0000000000000000000000000000000000006000",
83
85
  * collateralParams: [
84
86
  * {
85
87
  * token: "0x0000000000000000000000000000000000007000",
86
88
  * lltv: 770000000000000000n,
87
- * maxLif: 1061007957559681697n,
89
+ * liquidationCursor: 250000000000000000n,
88
90
  * oracle: "0x0000000000000000000000000000000000008000",
89
91
  * },
90
92
  * ],
@@ -146,10 +148,12 @@ var PositionUtils;
146
148
  const collateralParams = params.market.params.collateralParams.map((collateralParam) => ({
147
149
  token: collateralParam.token,
148
150
  lltv: BigInt(collateralParam.lltv),
149
- maxLif: BigInt(collateralParam.maxLif),
151
+ liquidationCursor: BigInt(collateralParam.liquidationCursor),
150
152
  oracle: collateralParam.oracle,
151
153
  }));
152
154
  const marketParams = {
155
+ chainId: BigInt(params.market.params.chainId),
156
+ midnight: params.market.params.midnight,
153
157
  loanToken: params.market.params.loanToken,
154
158
  collateralParams,
155
159
  maturity,
@@ -177,7 +181,6 @@ var PositionUtils;
177
181
  collateral,
178
182
  },
179
183
  market: {
180
- chainId: BigInt(params.market.chainId),
181
184
  params: marketParams,
182
185
  totalUnits: BigInt(params.market.totalUnits),
183
186
  lossFactor: marketLossFactor,
@@ -178,6 +178,28 @@ export declare namespace TickLib {
178
178
  * ```
179
179
  */
180
180
  function tickToRate(tick: BigIntish): bigint;
181
+ /**
182
+ * Converts a Midnight tick into a WAD simple annual percentage rate.
183
+ *
184
+ * This is an SDK-only rate display convenience. It annualizes the fixed
185
+ * period rate from {@link tickToRate} over `timeToMaturity` seconds.
186
+ *
187
+ * @param tick - Midnight tick.
188
+ * @param timeToMaturity - Seconds until the market matures.
189
+ * @returns WAD simple APR rounded up.
190
+ * @throws {NegativeValueError} when `tick` or `timeToMaturity` is negative.
191
+ * @throws {TickOutOfRangeError} when `tick` exceeds `MAX_TICK`.
192
+ * @throws {DivisionByZeroError} when the tick price or `timeToMaturity` is zero.
193
+ * @example
194
+ * ```ts
195
+ * import { TickLib } from "@morpho-org/midnight-sdk";
196
+ * import { Time } from "@morpho-org/morpho-ts";
197
+ *
198
+ * const apr = TickLib.tickToApr(6744n, Time.s.from.y(1n));
199
+ * console.log(apr);
200
+ * ```
201
+ */
202
+ function tickToApr(tick: BigIntish, timeToMaturity: BigIntish): bigint;
181
203
  /**
182
204
  * Asserts that a tick is aligned to the provided spacing.
183
205
  *
@@ -239,6 +239,36 @@ var TickLib;
239
239
  return morpho_ts_1.MathLib.mulDiv(morpho_ts_1.MathLib.WAD, morpho_ts_1.MathLib.WAD, price, "Up") - morpho_ts_1.MathLib.WAD;
240
240
  }
241
241
  TickLib.tickToRate = tickToRate;
242
+ /**
243
+ * Converts a Midnight tick into a WAD simple annual percentage rate.
244
+ *
245
+ * This is an SDK-only rate display convenience. It annualizes the fixed
246
+ * period rate from {@link tickToRate} over `timeToMaturity` seconds.
247
+ *
248
+ * @param tick - Midnight tick.
249
+ * @param timeToMaturity - Seconds until the market matures.
250
+ * @returns WAD simple APR rounded up.
251
+ * @throws {NegativeValueError} when `tick` or `timeToMaturity` is negative.
252
+ * @throws {TickOutOfRangeError} when `tick` exceeds `MAX_TICK`.
253
+ * @throws {DivisionByZeroError} when the tick price or `timeToMaturity` is zero.
254
+ * @example
255
+ * ```ts
256
+ * import { TickLib } from "@morpho-org/midnight-sdk";
257
+ * import { Time } from "@morpho-org/morpho-ts";
258
+ *
259
+ * const apr = TickLib.tickToApr(6744n, Time.s.from.y(1n));
260
+ * console.log(apr);
261
+ * ```
262
+ */
263
+ function tickToApr(tick, timeToMaturity) {
264
+ const normalizedTimeToMaturity = BigInt(timeToMaturity);
265
+ (0, morpho_ts_1.assertNonNegative)("timeToMaturity", normalizedTimeToMaturity);
266
+ if (normalizedTimeToMaturity === 0n) {
267
+ throw new morpho_ts_1.DivisionByZeroError("timeToMaturity");
268
+ }
269
+ return morpho_ts_1.MathLib.mulDiv(tickToRate(tick), morpho_ts_1.Time.s.from.y(1n), normalizedTimeToMaturity, "Up");
270
+ }
271
+ TickLib.tickToApr = tickToApr;
242
272
  /**
243
273
  * Asserts that a tick is aligned to the provided spacing.
244
274
  *
@@ -1,3 +1,2 @@
1
- export * from "./ConsumableUnitsLib.js";
2
1
  export * from "./TakeAmountsLib.js";
3
2
  export * from "./TickLib.js";
@@ -14,6 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./ConsumableUnitsLib.js"), exports);
18
17
  __exportStar(require("./TakeAmountsLib.js"), exports);
19
18
  __exportStar(require("./TickLib.js"), exports);
@@ -1,6 +1,6 @@
1
1
  import type { BigIntish } from "@morpho-org/morpho-ts";
2
2
  import type { Address, Hash, Hex } from "viem";
3
- import { type IMarket, type IMarketParams, MarketParams } from "../market/index.js";
3
+ import { type IMarket, type IMarketParams, Market, MarketParams } from "../market/index.js";
4
4
  /**
5
5
  * Plain make-side offer input accepted by {@link Offer}.
6
6
  *
@@ -19,12 +19,14 @@ import { type IMarket, type IMarketParams, MarketParams } from "../market/index.
19
19
  *
20
20
  * const offer: IOffer = {
21
21
  * market: {
22
+ * chainId: 8453,
23
+ * midnight: "0x0000000000000000000000000000000000001000",
22
24
  * loanToken: "0x0000000000000000000000000000000000000001",
23
25
  * collateralParams: [
24
26
  * {
25
27
  * token: "0x0000000000000000000000000000000000007000",
26
28
  * lltv: 770000000000000000n,
27
- * maxLif: 1061007957559681697n,
29
+ * liquidationCursor: 250000000000000000n,
28
30
  * oracle: "0x0000000000000000000000000000000000008000",
29
31
  * },
30
32
  * ],
@@ -99,12 +101,14 @@ export interface IOffer {
99
101
  *
100
102
  * const offer = Offer.create({
101
103
  * market: {
104
+ * chainId: 8453,
105
+ * midnight: "0x0000000000000000000000000000000000001000",
102
106
  * loanToken: "0x0000000000000000000000000000000000000001",
103
107
  * collateralParams: [
104
108
  * {
105
109
  * token: "0x0000000000000000000000000000000000007000",
106
110
  * lltv: 770000000000000000n,
107
- * maxLif: 1061007957559681697n,
111
+ * liquidationCursor: 250000000000000000n,
108
112
  * oracle: "0x0000000000000000000000000000000000008000",
109
113
  * },
110
114
  * ],
@@ -132,7 +136,7 @@ export interface IOffer {
132
136
  */
133
137
  export declare class Offer {
134
138
  /** Market this offer trades. */
135
- readonly market: MarketParams;
139
+ readonly market: MarketParams | Market;
136
140
  /** Whether the maker buys units. */
137
141
  readonly buy: boolean;
138
142
  /** Offer maker. */
@@ -178,12 +182,14 @@ export declare class Offer {
178
182
  *
179
183
  * const offer = Offer.from({
180
184
  * market: {
185
+ * chainId: 8453,
186
+ * midnight: "0x0000000000000000000000000000000000001000",
181
187
  * loanToken: "0x0000000000000000000000000000000000006000",
182
188
  * collateralParams: [
183
189
  * {
184
190
  * token: "0x0000000000000000000000000000000000007000",
185
191
  * lltv: 770000000000000000n,
186
- * maxLif: 1061007957559681697n,
192
+ * liquidationCursor: 250000000000000000n,
187
193
  * oracle: "0x0000000000000000000000000000000000008000",
188
194
  * },
189
195
  * ],
@@ -231,12 +237,14 @@ export declare class Offer {
231
237
  *
232
238
  * const offer = Offer.create({
233
239
  * market: {
240
+ * chainId: 8453,
241
+ * midnight: "0x0000000000000000000000000000000000001000",
234
242
  * loanToken,
235
243
  * collateralParams: [
236
244
  * {
237
245
  * token: collateralToken,
238
246
  * lltv: 770000000000000000n,
239
- * maxLif: 1061007957559681697n,
247
+ * liquidationCursor: 250000000000000000n,
240
248
  * oracle,
241
249
  * },
242
250
  * ],
@@ -254,7 +262,7 @@ export declare class Offer {
254
262
  * });
255
263
  *
256
264
  * const group = offer.group;
257
- * // group satisfies Hash
265
+ * console.log(group);
258
266
  * ```
259
267
  */
260
268
  get group(): Hash;
@@ -278,12 +286,14 @@ export declare class Offer {
278
286
  *
279
287
  * const offer = Offer.create({
280
288
  * market: {
289
+ * chainId: 8453,
290
+ * midnight: "0x0000000000000000000000000000000000001000",
281
291
  * loanToken,
282
292
  * collateralParams: [
283
293
  * {
284
294
  * token: collateralToken,
285
295
  * lltv: 770000000000000000n,
286
- * maxLif: 1061007957559681697n,
296
+ * liquidationCursor: 250000000000000000n,
287
297
  * oracle,
288
298
  * },
289
299
  * ],
@@ -305,6 +315,196 @@ export declare class Offer {
305
315
  * ```
306
316
  */
307
317
  get hash(): Hash;
318
+ /**
319
+ * WAD zero-coupon price at this offer's tick.
320
+ *
321
+ * @returns WAD price rounded to the protocol price quantum.
322
+ * @throws {NegativeValueError} when `tick` is negative.
323
+ * @throws {TickOutOfRangeError} when `tick` exceeds `MAX_TICK`.
324
+ * @example
325
+ * ```ts
326
+ * import { Offer } from "@morpho-org/midnight-sdk";
327
+ *
328
+ * const offer = Offer.create({
329
+ * market: {
330
+ * loanToken: "0x0000000000000000000000000000000000006000",
331
+ * collateralParams: [
332
+ * {
333
+ * token: "0x0000000000000000000000000000000000007000",
334
+ * lltv: 770000000000000000n,
335
+ * liquidationCursor: 250000000000000000n,
336
+ * oracle: "0x0000000000000000000000000000000000008000",
337
+ * },
338
+ * ],
339
+ * maturity: 54_000n,
340
+ * rcfThreshold: 0n,
341
+ * enterGate: "0x0000000000000000000000000000000000000000",
342
+ * liquidatorGate: "0x0000000000000000000000000000000000000000",
343
+ * },
344
+ * buy: true,
345
+ * maker: "0x0000000000000000000000000000000000009000",
346
+ * tick: 5_000n,
347
+ * expiry: 3_600n,
348
+ * ratifier: "0x0000000000000000000000000000000000004000",
349
+ * maxUnits: 100n,
350
+ * });
351
+ * console.log(offer.price);
352
+ * ```
353
+ */
354
+ get price(): bigint;
355
+ /**
356
+ * Converts this offer's tick into a WAD per-second simple rate at a timestamp.
357
+ *
358
+ * @param timestamp - Timestamp at which the rate is calculated.
359
+ * @returns WAD per-second simple rate rounded up.
360
+ * @throws {NegativeValueError} when market maturity, `timestamp`, or `tick` is negative.
361
+ * @throws {TickOutOfRangeError} when `tick` exceeds `MAX_TICK`.
362
+ * @throws {DivisionByZeroError} when the tick price is zero or `timestamp` is at or after maturity.
363
+ * @example
364
+ * ```ts
365
+ * import { Offer } from "@morpho-org/midnight-sdk";
366
+ *
367
+ * const offer = Offer.create({
368
+ * market: {
369
+ * loanToken: "0x0000000000000000000000000000000000006000",
370
+ * collateralParams: [
371
+ * {
372
+ * token: "0x0000000000000000000000000000000000007000",
373
+ * lltv: 770000000000000000n,
374
+ * liquidationCursor: 250000000000000000n,
375
+ * oracle: "0x0000000000000000000000000000000000008000",
376
+ * },
377
+ * ],
378
+ * maturity: 54_000n,
379
+ * rcfThreshold: 0n,
380
+ * enterGate: "0x0000000000000000000000000000000000000000",
381
+ * liquidatorGate: "0x0000000000000000000000000000000000000000",
382
+ * },
383
+ * buy: true,
384
+ * maker: "0x0000000000000000000000000000000000009000",
385
+ * tick: 5_000n,
386
+ * expiry: 3_600n,
387
+ * ratifier: "0x0000000000000000000000000000000000004000",
388
+ * maxUnits: 100n,
389
+ * });
390
+ * const rate = offer.getRate(1_000n);
391
+ * console.log(rate);
392
+ * ```
393
+ */
394
+ getRate(timestamp: BigIntish): bigint;
395
+ /**
396
+ * Converts this offer's tick into a WAD simple annual percentage rate at a timestamp.
397
+ *
398
+ * @param timestamp - Timestamp at which the APR is calculated.
399
+ * @returns WAD simple APR rounded up.
400
+ * @throws {NegativeValueError} when market maturity, `timestamp`, or `tick` is negative.
401
+ * @throws {TickOutOfRangeError} when `tick` exceeds `MAX_TICK`.
402
+ * @throws {DivisionByZeroError} when the tick price is zero or `timestamp` is at or after maturity.
403
+ * @example
404
+ * ```ts
405
+ * import { Offer } from "@morpho-org/midnight-sdk";
406
+ *
407
+ * const offer = Offer.create({
408
+ * market: {
409
+ * loanToken: "0x0000000000000000000000000000000000006000",
410
+ * collateralParams: [
411
+ * {
412
+ * token: "0x0000000000000000000000000000000000007000",
413
+ * lltv: 770000000000000000n,
414
+ * liquidationCursor: 250000000000000000n,
415
+ * oracle: "0x0000000000000000000000000000000000008000",
416
+ * },
417
+ * ],
418
+ * maturity: 54_000n,
419
+ * rcfThreshold: 0n,
420
+ * enterGate: "0x0000000000000000000000000000000000000000",
421
+ * liquidatorGate: "0x0000000000000000000000000000000000000000",
422
+ * },
423
+ * buy: true,
424
+ * maker: "0x0000000000000000000000000000000000009000",
425
+ * tick: 5_000n,
426
+ * expiry: 3_600n,
427
+ * ratifier: "0x0000000000000000000000000000000000004000",
428
+ * maxUnits: 100n,
429
+ * });
430
+ * const apr = offer.getApr(1_000n);
431
+ * console.log(apr);
432
+ * ```
433
+ */
434
+ getApr(timestamp: BigIntish): bigint;
435
+ /**
436
+ * Returns remaining units accepted by this offer's cap at a timestamp.
437
+ *
438
+ * The offer must carry a hydrated {@link Market} so the current market
439
+ * continuous fee and settlement-fee buckets are available locally. Fetch the
440
+ * current `consumed(maker, group)` value separately and pass it as input.
441
+ *
442
+ * @param params.consumed - Amount already consumed from this offer's group.
443
+ * @param params.timestamp - Timestamp used to compute the market time to maturity.
444
+ * @returns Remaining consumable units accepted by Midnight `take`.
445
+ * @throws {InvalidOfferParameterError} when this offer does not carry hydrated market state or has invalid caps.
446
+ * @throws {NegativeValueError} when `consumed`, `timestamp`, offer limits, or delegated math inputs are negative.
447
+ * @throws {TickOutOfRangeError} when `tick` exceeds `MAX_TICK`.
448
+ * @throws {SettlementFeeExceedsPriceError} when settlement fee exceeds a buy-offer price.
449
+ * @example
450
+ * ```ts
451
+ * import { Offer } from "@morpho-org/midnight-sdk";
452
+ *
453
+ * const offer = Offer.from({
454
+ * market: {
455
+ * params: {
456
+ * chainId: 8453,
457
+ * midnight: "0x0000000000000000000000000000000000001000",
458
+ * loanToken: "0x0000000000000000000000000000000000006000",
459
+ * collateralParams: [
460
+ * {
461
+ * token: "0x0000000000000000000000000000000000007000",
462
+ * lltv: 770000000000000000n,
463
+ * liquidationCursor: 250000000000000000n,
464
+ * oracle: "0x0000000000000000000000000000000000008000",
465
+ * },
466
+ * ],
467
+ * maturity: 54_000n,
468
+ * rcfThreshold: 0n,
469
+ * enterGate: "0x0000000000000000000000000000000000000000",
470
+ * liquidatorGate: "0x0000000000000000000000000000000000000000",
471
+ * },
472
+ * totalUnits: 1_000n,
473
+ * lossFactor: 0n,
474
+ * withdrawable: 500n,
475
+ * continuousFeeCredit: 0n,
476
+ * settlementFeeCbps: [1, 2, 3, 4, 5, 6, 7],
477
+ * continuousFee: 10,
478
+ * tickSpacing: 4,
479
+ * },
480
+ * buy: true,
481
+ * maker: "0x0000000000000000000000000000000000009000",
482
+ * start: 0n,
483
+ * expiry: 3_600n,
484
+ * tick: 5_000n,
485
+ * callback: "0x0000000000000000000000000000000000000000",
486
+ * callbackData: "0x",
487
+ * receiverIfMakerIsSeller: "0x0000000000000000000000000000000000000000",
488
+ * ratifier: "0x0000000000000000000000000000000000004000",
489
+ * reduceOnly: false,
490
+ * maxUnits: 100n,
491
+ * maxAssets: 0n,
492
+ * continuousFeeCap: 317097919n,
493
+ * });
494
+ * const consumed = await readContract(client, {
495
+ * address: "0x0000000000000000000000000000000000001000",
496
+ * abi: midnightAbi,
497
+ * functionName: "consumed",
498
+ * args: [offer.maker, offer.group],
499
+ * });
500
+ * const units = offer.getConsumableUnits({ consumed, timestamp: 1_000n });
501
+ * console.log(units);
502
+ * ```
503
+ */
504
+ getConsumableUnits(params: {
505
+ readonly consumed: BigIntish;
506
+ readonly timestamp: BigIntish;
507
+ }): bigint;
308
508
  /**
309
509
  * Creates a validated maker-side Midnight offer.
310
510
  *
@@ -347,12 +547,14 @@ export declare class Offer {
347
547
  *
348
548
  * const offer = Offer.create({
349
549
  * market: {
550
+ * chainId: 8453,
551
+ * midnight: "0x0000000000000000000000000000000000001000",
350
552
  * loanToken,
351
553
  * collateralParams: [
352
554
  * {
353
555
  * token: collateralToken,
354
556
  * lltv: 770000000000000000n,
355
- * maxLif: 1061007957559681697n,
557
+ * liquidationCursor: 250000000000000000n,
356
558
  * oracle,
357
559
  * },
358
560
  * ],
@@ -390,12 +592,14 @@ export declare class Offer {
390
592
  *
391
593
  * const offer: OfferStruct = {
392
594
  * market: {
595
+ * chainId: 8453,
596
+ * midnight: "0x0000000000000000000000000000000000001000",
393
597
  * loanToken: "0x0000000000000000000000000000000000006000",
394
598
  * collateralParams: [
395
599
  * {
396
600
  * token: "0x0000000000000000000000000000000000007000",
397
601
  * lltv: 770000000000000000n,
398
- * maxLif: 1061007957559681697n,
602
+ * liquidationCursor: 250000000000000000n,
399
603
  * oracle: "0x0000000000000000000000000000000000008000",
400
604
  * },
401
605
  * ],
@@ -470,12 +674,14 @@ export interface OfferStruct {
470
674
  *
471
675
  * const params: BuildOfferParams = {
472
676
  * market: {
677
+ * chainId: 8453,
678
+ * midnight: "0x0000000000000000000000000000000000001000",
473
679
  * loanToken: "0x0000000000000000000000000000000000006000",
474
680
  * collateralParams: [
475
681
  * {
476
682
  * token: "0x0000000000000000000000000000000000007000",
477
683
  * lltv: 770000000000000000n,
478
- * maxLif: 1061007957559681697n,
684
+ * liquidationCursor: 250000000000000000n,
479
685
  * oracle: "0x0000000000000000000000000000000000008000",
480
686
  * },
481
687
  * ],
@@ -515,7 +721,7 @@ export interface BuildOfferParams {
515
721
  readonly maxUnits?: BigIntish;
516
722
  /** Maximum buyer or seller assets; defaults to zero. Exactly one of `maxUnits` and `maxAssets` must be non-zero. */
517
723
  readonly maxAssets?: BigIntish;
518
- /** Maximum market continuous fee accepted by this offer; defaults to the protocol maximum. */
724
+ /** Maximum market continuous fee accepted by this offer; defaults to zero. */
519
725
  readonly continuousFeeCap?: BigIntish;
520
726
  /** Offer start timestamp; defaults to zero. */
521
727
  readonly start?: BigIntish;