@morpho-org/midnight-sdk 1.7.0-next.0 → 1.8.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 (92) hide show
  1. package/README.md +61 -61
  2. package/lib/cjs/abis.d.ts +794 -0
  3. package/lib/cjs/abis.js +502 -1
  4. package/lib/cjs/api/version.generated.d.ts +1 -1
  5. package/lib/cjs/api/version.generated.js +2 -2
  6. package/lib/cjs/constants.d.ts +34 -0
  7. package/lib/cjs/constants.js +35 -1
  8. package/lib/cjs/errors.d.ts +107 -0
  9. package/lib/cjs/errors.js +139 -1
  10. package/lib/cjs/fetch/Ratifier.d.ts +4 -3
  11. package/lib/cjs/fetch/Ratifier.js +5 -4
  12. package/lib/cjs/index.d.ts +7 -0
  13. package/lib/cjs/index.js +16 -1
  14. package/lib/cjs/offers/Offer.d.ts +10 -0
  15. package/lib/cjs/offers/Offer.js +15 -1
  16. package/lib/cjs/offers/OfferUtils.d.ts +3 -0
  17. package/lib/cjs/offers/OfferUtils.js +3 -0
  18. package/lib/cjs/signatures/{EcrecoverRatifierUtils.d.ts → EcrecoverRatifier.d.ts} +118 -2
  19. package/lib/cjs/signatures/{EcrecoverRatifierUtils.js → EcrecoverRatifier.js} +146 -9
  20. package/lib/cjs/signatures/GroupUtils.d.ts +55 -2
  21. package/lib/cjs/signatures/GroupUtils.js +64 -5
  22. package/lib/cjs/signatures/Payload.d.ts +3 -3
  23. package/lib/cjs/signatures/PriceRatifierV1.d.ts +472 -0
  24. package/lib/cjs/signatures/PriceRatifierV1.js +521 -0
  25. package/lib/cjs/signatures/RateRatifierV1.d.ts +581 -0
  26. package/lib/cjs/signatures/RateRatifierV1.js +696 -0
  27. package/lib/{esm/signatures/RatifierUtils.d.ts → cjs/signatures/Ratifier.d.ts} +14 -12
  28. package/lib/cjs/signatures/{RatifierUtils.js → Ratifier.js} +29 -29
  29. package/lib/cjs/signatures/{SetterRatifierUtils.d.ts → SetterRatifier.d.ts} +50 -3
  30. package/lib/cjs/signatures/{SetterRatifierUtils.js → SetterRatifier.js} +65 -7
  31. package/lib/cjs/signatures/Tree.d.ts +94 -17
  32. package/lib/cjs/signatures/Tree.js +146 -111
  33. package/lib/cjs/signatures/TreeUtils.d.ts +191 -21
  34. package/lib/cjs/signatures/TreeUtils.js +320 -134
  35. package/lib/cjs/signatures/index.d.ts +7 -3
  36. package/lib/cjs/signatures/index.js +5 -3
  37. package/lib/cjs/signatures/ratifierRequests.d.ts +55 -0
  38. package/lib/cjs/signatures/ratifierRequests.js +2 -0
  39. package/lib/cjs/signatures/ratifierV1Internal.d.ts +57 -0
  40. package/lib/cjs/signatures/ratifierV1Internal.js +183 -0
  41. package/lib/cjs/signatures/standardRatifierInternal.d.ts +4 -0
  42. package/lib/cjs/signatures/standardRatifierInternal.js +12 -0
  43. package/lib/cjs/signatures/treeMathInternal.d.ts +4 -0
  44. package/lib/cjs/signatures/treeMathInternal.js +12 -0
  45. package/lib/cjs/signatures/treeTypes.d.ts +109 -0
  46. package/lib/cjs/signatures/treeTypes.js +2 -0
  47. package/lib/esm/abis.d.ts +794 -0
  48. package/lib/esm/abis.js +501 -0
  49. package/lib/esm/api/version.generated.d.ts +1 -1
  50. package/lib/esm/api/version.generated.js +2 -2
  51. package/lib/esm/constants.d.ts +34 -0
  52. package/lib/esm/constants.js +34 -0
  53. package/lib/esm/errors.d.ts +107 -0
  54. package/lib/esm/errors.js +132 -0
  55. package/lib/esm/fetch/Ratifier.d.ts +4 -3
  56. package/lib/esm/fetch/Ratifier.js +5 -4
  57. package/lib/esm/index.d.ts +7 -0
  58. package/lib/esm/index.js +5 -0
  59. package/lib/esm/offers/Offer.d.ts +10 -0
  60. package/lib/esm/offers/Offer.js +15 -1
  61. package/lib/esm/offers/OfferUtils.d.ts +3 -0
  62. package/lib/esm/offers/OfferUtils.js +3 -0
  63. package/lib/esm/signatures/{EcrecoverRatifierUtils.d.ts → EcrecoverRatifier.d.ts} +118 -2
  64. package/lib/esm/signatures/{EcrecoverRatifierUtils.js → EcrecoverRatifier.js} +146 -9
  65. package/lib/esm/signatures/GroupUtils.d.ts +55 -2
  66. package/lib/esm/signatures/GroupUtils.js +64 -5
  67. package/lib/esm/signatures/Payload.d.ts +3 -3
  68. package/lib/esm/signatures/PriceRatifierV1.d.ts +472 -0
  69. package/lib/esm/signatures/PriceRatifierV1.js +520 -0
  70. package/lib/esm/signatures/RateRatifierV1.d.ts +581 -0
  71. package/lib/esm/signatures/RateRatifierV1.js +695 -0
  72. package/lib/{cjs/signatures/RatifierUtils.d.ts → esm/signatures/Ratifier.d.ts} +14 -12
  73. package/lib/esm/signatures/{RatifierUtils.js → Ratifier.js} +31 -29
  74. package/lib/esm/signatures/{SetterRatifierUtils.d.ts → SetterRatifier.d.ts} +50 -3
  75. package/lib/esm/signatures/{SetterRatifierUtils.js → SetterRatifier.js} +65 -7
  76. package/lib/esm/signatures/Tree.d.ts +94 -17
  77. package/lib/esm/signatures/Tree.js +147 -112
  78. package/lib/esm/signatures/TreeUtils.d.ts +191 -21
  79. package/lib/esm/signatures/TreeUtils.js +318 -132
  80. package/lib/esm/signatures/index.d.ts +7 -3
  81. package/lib/esm/signatures/index.js +5 -3
  82. package/lib/esm/signatures/ratifierRequests.d.ts +55 -0
  83. package/lib/esm/signatures/ratifierRequests.js +1 -0
  84. package/lib/esm/signatures/ratifierV1Internal.d.ts +57 -0
  85. package/lib/esm/signatures/ratifierV1Internal.js +176 -0
  86. package/lib/esm/signatures/standardRatifierInternal.d.ts +4 -0
  87. package/lib/esm/signatures/standardRatifierInternal.js +9 -0
  88. package/lib/esm/signatures/treeMathInternal.d.ts +4 -0
  89. package/lib/esm/signatures/treeMathInternal.js +8 -0
  90. package/lib/esm/signatures/treeTypes.d.ts +109 -0
  91. package/lib/esm/signatures/treeTypes.js +1 -0
  92. package/package.json +4 -4
@@ -228,6 +228,113 @@ export declare class InvalidTreeHeightError extends Error {
228
228
  export declare class InvalidTreeError extends Error {
229
229
  constructor(message: string);
230
230
  }
231
+ /**
232
+ * Thrown when a RateRatifierV1 leaf receives a negative rate.
233
+ *
234
+ * @example
235
+ * ```ts
236
+ * import { InvalidRateRatifierV1RateError } from "@morpho-org/midnight-sdk";
237
+ *
238
+ * throw new InvalidRateRatifierV1RateError(-1n);
239
+ * ```
240
+ */
241
+ export declare class InvalidRateRatifierV1RateError extends Error {
242
+ /** Negative rate that was rejected. */
243
+ readonly rate: bigint;
244
+ constructor(rate: bigint);
245
+ }
246
+ /**
247
+ * Thrown when RateRatifierV1 price-bound arithmetic overflows uint256.
248
+ *
249
+ * @example
250
+ * ```ts
251
+ * import { RateRatifierV1BoundOverflowError } from "@morpho-org/midnight-sdk";
252
+ *
253
+ * throw new RateRatifierV1BoundOverflowError(2n ** 255n, 10n);
254
+ * ```
255
+ */
256
+ export declare class RateRatifierV1BoundOverflowError extends Error {
257
+ /** Rate whose bound arithmetic overflowed. */
258
+ readonly rate: bigint;
259
+ /** Time to maturity used in the overflowing bound. */
260
+ readonly timeToMaturity: bigint;
261
+ constructor(rate: bigint, timeToMaturity: bigint);
262
+ }
263
+ /**
264
+ * Thrown when a RateRatifierV1 leaf offer commits a nominal tick below the
265
+ * router's minimum takeable tick.
266
+ *
267
+ * @example
268
+ * ```ts
269
+ * import { InvalidRateRatifierV1TickError } from "@morpho-org/midnight-sdk";
270
+ *
271
+ * throw new InvalidRateRatifierV1TickError(0n, 3372n);
272
+ * ```
273
+ */
274
+ export declare class InvalidRateRatifierV1TickError extends Error {
275
+ /** Nominal tick that was rejected. */
276
+ readonly tick: bigint;
277
+ /** Minimum accepted tick. */
278
+ readonly minTick: bigint;
279
+ constructor(tick: bigint, minTick: bigint);
280
+ }
281
+ /**
282
+ * Thrown when a RateRatifierV1 time parameter is negative.
283
+ *
284
+ * @example
285
+ * ```ts
286
+ * import { InvalidRateRatifierV1TimeError } from "@morpho-org/midnight-sdk";
287
+ *
288
+ * throw new InvalidRateRatifierV1TimeError(-1n, "timestamp");
289
+ * ```
290
+ */
291
+ export declare class InvalidRateRatifierV1TimeError extends Error {
292
+ /** Negative time value that was rejected. */
293
+ readonly value: bigint;
294
+ /** Parameter that carried the negative value. */
295
+ readonly field: "timeToMaturity" | "timestamp";
296
+ constructor(value: bigint, field: "timeToMaturity" | "timestamp");
297
+ }
298
+ /**
299
+ * Thrown when a V1 ratifier address is the zero address.
300
+ *
301
+ * @example
302
+ * ```ts
303
+ * import { InvalidRatifierV1AddressError } from "@morpho-org/midnight-sdk";
304
+ *
305
+ * throw new InvalidRatifierV1AddressError(
306
+ * "0x0000000000000000000000000000000000000000",
307
+ * );
308
+ * ```
309
+ */
310
+ export declare class InvalidRatifierV1AddressError extends Error {
311
+ /** Zero ratifier address that was rejected. */
312
+ readonly ratifier: Address;
313
+ constructor(ratifier: Address);
314
+ }
315
+ /**
316
+ * Thrown when a taker is not the allowed taker of a V1 ratifier leaf.
317
+ *
318
+ * @example
319
+ * ```ts
320
+ * import { RatifierV1TakerNotAllowedError } from "@morpho-org/midnight-sdk";
321
+ *
322
+ * throw new RatifierV1TakerNotAllowedError({
323
+ * taker: "0x0000000000000000000000000000000000000001",
324
+ * allowedTaker: "0x0000000000000000000000000000000000000002",
325
+ * });
326
+ * ```
327
+ */
328
+ export declare class RatifierV1TakerNotAllowedError extends Error {
329
+ /** Taker that attempted to take the offer. */
330
+ readonly taker: Address;
331
+ /** Taker allowed by the ratified leaf. */
332
+ readonly allowedTaker: Address;
333
+ constructor(params: {
334
+ readonly taker: Address;
335
+ readonly allowedTaker: Address;
336
+ });
337
+ }
231
338
  /**
232
339
  * Thrown when a viem client's chain id does not match the chain id required by a signing flow.
233
340
  *
package/lib/cjs/errors.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InvalidMidnightApiQuoteTargetError = exports.InvalidMidnightApiResponseError = exports.MidnightApiError = exports.InvalidEcrecoverSignatureVError = 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;
3
+ exports.InvalidMidnightApiQuoteTargetError = exports.InvalidMidnightApiResponseError = exports.MidnightApiError = exports.InvalidEcrecoverSignatureVError = exports.InvalidTypedDataSignatureError = exports.MidnightMempoolValidationError = exports.ChainIdMismatchError = exports.RatifierV1TakerNotAllowedError = exports.InvalidRatifierV1AddressError = exports.InvalidRateRatifierV1TimeError = exports.InvalidRateRatifierV1TickError = exports.RateRatifierV1BoundOverflowError = exports.InvalidRateRatifierV1RateError = 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
  *
@@ -280,6 +280,144 @@ class InvalidTreeError extends Error {
280
280
  }
281
281
  }
282
282
  exports.InvalidTreeError = InvalidTreeError;
283
+ /**
284
+ * Thrown when a RateRatifierV1 leaf receives a negative rate.
285
+ *
286
+ * @example
287
+ * ```ts
288
+ * import { InvalidRateRatifierV1RateError } from "@morpho-org/midnight-sdk";
289
+ *
290
+ * throw new InvalidRateRatifierV1RateError(-1n);
291
+ * ```
292
+ */
293
+ class InvalidRateRatifierV1RateError extends Error {
294
+ /** Negative rate that was rejected. */
295
+ rate;
296
+ constructor(rate) {
297
+ super(`Rate "${rate}" is negative. Use a non-negative WAD-scaled rate.`);
298
+ this.name = "InvalidRateRatifierV1RateError";
299
+ this.rate = rate;
300
+ }
301
+ }
302
+ exports.InvalidRateRatifierV1RateError = InvalidRateRatifierV1RateError;
303
+ /**
304
+ * Thrown when RateRatifierV1 price-bound arithmetic overflows uint256.
305
+ *
306
+ * @example
307
+ * ```ts
308
+ * import { RateRatifierV1BoundOverflowError } from "@morpho-org/midnight-sdk";
309
+ *
310
+ * throw new RateRatifierV1BoundOverflowError(2n ** 255n, 10n);
311
+ * ```
312
+ */
313
+ class RateRatifierV1BoundOverflowError extends Error {
314
+ /** Rate whose bound arithmetic overflowed. */
315
+ rate;
316
+ /** Time to maturity used in the overflowing bound. */
317
+ timeToMaturity;
318
+ constructor(rate, timeToMaturity) {
319
+ super(`Rate bound arithmetic overflows uint256 for rate "${rate}" and timeToMaturity "${timeToMaturity}". Lower the rate or time to maturity.`);
320
+ this.name = "RateRatifierV1BoundOverflowError";
321
+ this.rate = rate;
322
+ this.timeToMaturity = timeToMaturity;
323
+ }
324
+ }
325
+ exports.RateRatifierV1BoundOverflowError = RateRatifierV1BoundOverflowError;
326
+ /**
327
+ * Thrown when a RateRatifierV1 leaf offer commits a nominal tick below the
328
+ * router's minimum takeable tick.
329
+ *
330
+ * @example
331
+ * ```ts
332
+ * import { InvalidRateRatifierV1TickError } from "@morpho-org/midnight-sdk";
333
+ *
334
+ * throw new InvalidRateRatifierV1TickError(0n, 3372n);
335
+ * ```
336
+ */
337
+ class InvalidRateRatifierV1TickError extends Error {
338
+ /** Nominal tick that was rejected. */
339
+ tick;
340
+ /** Minimum accepted tick. */
341
+ minTick;
342
+ constructor(tick, minTick) {
343
+ super(`Offer tick "${tick}" is below the minimum "${minTick}" (price >= 0.5 WAD). RateRatifierV1 prices from \`rate\`, but the router still validates the committed tick; set a nominal tick of at least "${minTick}".`);
344
+ this.name = "InvalidRateRatifierV1TickError";
345
+ this.tick = tick;
346
+ this.minTick = minTick;
347
+ }
348
+ }
349
+ exports.InvalidRateRatifierV1TickError = InvalidRateRatifierV1TickError;
350
+ /**
351
+ * Thrown when a RateRatifierV1 time parameter is negative.
352
+ *
353
+ * @example
354
+ * ```ts
355
+ * import { InvalidRateRatifierV1TimeError } from "@morpho-org/midnight-sdk";
356
+ *
357
+ * throw new InvalidRateRatifierV1TimeError(-1n, "timestamp");
358
+ * ```
359
+ */
360
+ class InvalidRateRatifierV1TimeError extends Error {
361
+ /** Negative time value that was rejected. */
362
+ value;
363
+ /** Parameter that carried the negative value. */
364
+ field;
365
+ constructor(value, field) {
366
+ super(`${field} "${value}" is negative. Use a non-negative number of seconds.`);
367
+ this.name = "InvalidRateRatifierV1TimeError";
368
+ this.value = value;
369
+ this.field = field;
370
+ }
371
+ }
372
+ exports.InvalidRateRatifierV1TimeError = InvalidRateRatifierV1TimeError;
373
+ /**
374
+ * Thrown when a V1 ratifier address is the zero address.
375
+ *
376
+ * @example
377
+ * ```ts
378
+ * import { InvalidRatifierV1AddressError } from "@morpho-org/midnight-sdk";
379
+ *
380
+ * throw new InvalidRatifierV1AddressError(
381
+ * "0x0000000000000000000000000000000000000000",
382
+ * );
383
+ * ```
384
+ */
385
+ class InvalidRatifierV1AddressError extends Error {
386
+ /** Zero ratifier address that was rejected. */
387
+ ratifier;
388
+ constructor(ratifier) {
389
+ super(`Ratifier address "${ratifier}" is the zero address. Use a deployed PriceRatifierV1 or RateRatifierV1 address.`);
390
+ this.name = "InvalidRatifierV1AddressError";
391
+ this.ratifier = ratifier;
392
+ }
393
+ }
394
+ exports.InvalidRatifierV1AddressError = InvalidRatifierV1AddressError;
395
+ /**
396
+ * Thrown when a taker is not the allowed taker of a V1 ratifier leaf.
397
+ *
398
+ * @example
399
+ * ```ts
400
+ * import { RatifierV1TakerNotAllowedError } from "@morpho-org/midnight-sdk";
401
+ *
402
+ * throw new RatifierV1TakerNotAllowedError({
403
+ * taker: "0x0000000000000000000000000000000000000001",
404
+ * allowedTaker: "0x0000000000000000000000000000000000000002",
405
+ * });
406
+ * ```
407
+ */
408
+ class RatifierV1TakerNotAllowedError extends Error {
409
+ /** Taker that attempted to take the offer. */
410
+ taker;
411
+ /** Taker allowed by the ratified leaf. */
412
+ allowedTaker;
413
+ constructor(params) {
414
+ super(`Taker "${params.taker}" is not the allowed taker "${params.allowedTaker}". Use the allowed taker or an offer without a taker restriction.`);
415
+ this.name = "RatifierV1TakerNotAllowedError";
416
+ this.taker = params.taker;
417
+ this.allowedTaker = params.allowedTaker;
418
+ }
419
+ }
420
+ exports.RatifierV1TakerNotAllowedError = RatifierV1TakerNotAllowedError;
283
421
  /**
284
422
  * Thrown when a viem client's chain id does not match the chain id required by a signing flow.
285
423
  *
@@ -1,5 +1,5 @@
1
1
  import type { Address, Client } from "viem";
2
- import { type RatifierInfo } from "../signatures/RatifierUtils.js";
2
+ import { type RatifierInfo } from "../signatures/Ratifier.js";
3
3
  import type { MidnightCallParameters } from "./types.js";
4
4
  /**
5
5
  * Fetches maker bytecode and classifies the ratifier route for new offers.
@@ -9,7 +9,7 @@ import type { MidnightCallParameters } from "./types.js";
9
9
  * the maker is an EOA or EIP-7702 account that can use Ecrecover signatures, or
10
10
  * a deployed-code account that should use Setter root approval. Put the returned
11
11
  * `ratifier` address on `Offer.create`, then use the returned `type` to choose
12
- * `EcrecoverRatifierUtils.ratify` or `SetterRatifierUtils.ratify` after the tree
12
+ * `EcrecoverRatifier.ratify` or `SetterRatifier.ratify` after the tree
13
13
  * has been built.
14
14
  *
15
15
  * Reads `eth_chainId` only when the viem client has no configured chain id,
@@ -29,7 +29,8 @@ import type { MidnightCallParameters } from "./types.js";
29
29
  * const maker = "0x7b093658BE7f90B63D7c359e8f408e503c2D9401";
30
30
  * const info = await fetchRatifierInfo(client, { maker });
31
31
  * // Pass info.ratifier to Offer.create(...), then use info.type after
32
- * // Tree.create([...]) to choose the Ecrecover or Setter ratifier flow.
32
+ * // Tree.create({ type: info.type, entries: [...] }) to choose the Ecrecover
33
+ * // or Setter ratifier flow.
33
34
  * console.log(info.type, info.ratifier);
34
35
  * ```
35
36
  */
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fetchRatifierInfo = fetchRatifierInfo;
4
4
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
5
5
  const actions_1 = require("viem/actions");
6
- const RatifierUtils_js_1 = require("../signatures/RatifierUtils.js");
6
+ const Ratifier_js_1 = require("../signatures/Ratifier.js");
7
7
  const utils_js_1 = require("./utils.js");
8
8
  /**
9
9
  * Fetches maker bytecode and classifies the ratifier route for new offers.
@@ -13,7 +13,7 @@ const utils_js_1 = require("./utils.js");
13
13
  * the maker is an EOA or EIP-7702 account that can use Ecrecover signatures, or
14
14
  * a deployed-code account that should use Setter root approval. Put the returned
15
15
  * `ratifier` address on `Offer.create`, then use the returned `type` to choose
16
- * `EcrecoverRatifierUtils.ratify` or `SetterRatifierUtils.ratify` after the tree
16
+ * `EcrecoverRatifier.ratify` or `SetterRatifier.ratify` after the tree
17
17
  * has been built.
18
18
  *
19
19
  * Reads `eth_chainId` only when the viem client has no configured chain id,
@@ -33,7 +33,8 @@ const utils_js_1 = require("./utils.js");
33
33
  * const maker = "0x7b093658BE7f90B63D7c359e8f408e503c2D9401";
34
34
  * const info = await fetchRatifierInfo(client, { maker });
35
35
  * // Pass info.ratifier to Offer.create(...), then use info.type after
36
- * // Tree.create([...]) to choose the Ecrecover or Setter ratifier flow.
36
+ * // Tree.create({ type: info.type, entries: [...] }) to choose the Ecrecover
37
+ * // or Setter ratifier flow.
37
38
  * console.log(info.type, info.ratifier);
38
39
  * ```
39
40
  */
@@ -49,7 +50,7 @@ async function fetchRatifierInfo(client, params) {
49
50
  : {}),
50
51
  address: params.maker,
51
52
  });
52
- return RatifierUtils_js_1.RatifierUtils.getRatifierInfo({
53
+ return Ratifier_js_1.Ratifier.getRatifierInfo({
53
54
  bytecode,
54
55
  ecrecoverRatifier,
55
56
  setterRatifier,
@@ -6,6 +6,7 @@ export * from "./market/index.js";
6
6
  export * from "./math/index.js";
7
7
  export * from "./offers/index.js";
8
8
  export * from "./position/index.js";
9
+ export { EcrecoverRatifier, EcrecoverRatifierUtils, } from "./signatures/EcrecoverRatifier.js";
9
10
  export * from "./signatures/index.js";
10
11
  /**
11
12
  * Namespace for Midnight mempool payload utilities.
@@ -17,3 +18,9 @@ export * from "./signatures/index.js";
17
18
  * mempool submission calldata.
18
19
  */
19
20
  export { Payload } from "./signatures/Payload.js";
21
+ export { PriceRatifierV1, PriceRatifierV1Utils, } from "./signatures/PriceRatifierV1.js";
22
+ export { RateRatifierV1, RateRatifierV1Utils, } from "./signatures/RateRatifierV1.js";
23
+ export { Ratifier, RatifierUtils } from "./signatures/Ratifier.js";
24
+ export type { EcrecoverRatifierDataRequest, EcrecoverRatifierRatifyRequest, EcrecoverRatifierSignRequest, EcrecoverRatifierTypedDataRequest, SetterRatifierDataRequest, SetterRatifierRatifyRequest, } from "./signatures/ratifierRequests.js";
25
+ export { SetterRatifier, SetterRatifierUtils, } from "./signatures/SetterRatifier.js";
26
+ export type { AnyTree, AnyTreeSnapshot, EcrecoverTreeCreateRequest, PriceRatifierV1TreeCreateRequest, RateRatifierV1TreeCreateRequest, RatifierKind, RatifierTypes, SetterTreeCreateRequest, TreeCreateRequest, TreeData, TreeEntry, TreeSnapshot, TypedRatifierTreeInput, TypedTreeMempoolValidateParams, } from "./signatures/treeTypes.js";
package/lib/cjs/index.js CHANGED
@@ -14,7 +14,7 @@ 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
- exports.Payload = void 0;
17
+ exports.SetterRatifierUtils = exports.SetterRatifier = exports.RatifierUtils = exports.Ratifier = exports.RateRatifierV1Utils = exports.RateRatifierV1 = exports.PriceRatifierV1Utils = exports.PriceRatifierV1 = exports.Payload = exports.EcrecoverRatifierUtils = exports.EcrecoverRatifier = void 0;
18
18
  __exportStar(require("./abis.js"), exports);
19
19
  __exportStar(require("./constants.js"), exports);
20
20
  __exportStar(require("./errors.js"), exports);
@@ -23,6 +23,9 @@ __exportStar(require("./market/index.js"), exports);
23
23
  __exportStar(require("./math/index.js"), exports);
24
24
  __exportStar(require("./offers/index.js"), exports);
25
25
  __exportStar(require("./position/index.js"), exports);
26
+ var EcrecoverRatifier_js_1 = require("./signatures/EcrecoverRatifier.js");
27
+ Object.defineProperty(exports, "EcrecoverRatifier", { enumerable: true, get: function () { return EcrecoverRatifier_js_1.EcrecoverRatifier; } });
28
+ Object.defineProperty(exports, "EcrecoverRatifierUtils", { enumerable: true, get: function () { return EcrecoverRatifier_js_1.EcrecoverRatifierUtils; } });
26
29
  __exportStar(require("./signatures/index.js"), exports);
27
30
  /**
28
31
  * Namespace for Midnight mempool payload utilities.
@@ -35,3 +38,15 @@ __exportStar(require("./signatures/index.js"), exports);
35
38
  */
36
39
  var Payload_js_1 = require("./signatures/Payload.js");
37
40
  Object.defineProperty(exports, "Payload", { enumerable: true, get: function () { return Payload_js_1.Payload; } });
41
+ var PriceRatifierV1_js_1 = require("./signatures/PriceRatifierV1.js");
42
+ Object.defineProperty(exports, "PriceRatifierV1", { enumerable: true, get: function () { return PriceRatifierV1_js_1.PriceRatifierV1; } });
43
+ Object.defineProperty(exports, "PriceRatifierV1Utils", { enumerable: true, get: function () { return PriceRatifierV1_js_1.PriceRatifierV1Utils; } });
44
+ var RateRatifierV1_js_1 = require("./signatures/RateRatifierV1.js");
45
+ Object.defineProperty(exports, "RateRatifierV1", { enumerable: true, get: function () { return RateRatifierV1_js_1.RateRatifierV1; } });
46
+ Object.defineProperty(exports, "RateRatifierV1Utils", { enumerable: true, get: function () { return RateRatifierV1_js_1.RateRatifierV1Utils; } });
47
+ var Ratifier_js_1 = require("./signatures/Ratifier.js");
48
+ Object.defineProperty(exports, "Ratifier", { enumerable: true, get: function () { return Ratifier_js_1.Ratifier; } });
49
+ Object.defineProperty(exports, "RatifierUtils", { enumerable: true, get: function () { return Ratifier_js_1.RatifierUtils; } });
50
+ var SetterRatifier_js_1 = require("./signatures/SetterRatifier.js");
51
+ Object.defineProperty(exports, "SetterRatifier", { enumerable: true, get: function () { return SetterRatifier_js_1.SetterRatifier; } });
52
+ Object.defineProperty(exports, "SetterRatifierUtils", { enumerable: true, get: function () { return SetterRatifier_js_1.SetterRatifierUtils; } });
@@ -150,6 +150,16 @@ export declare class Offer {
150
150
  readonly tick: bigint;
151
151
  private cachedGroup;
152
152
  private cachedHash;
153
+ /**
154
+ * Whether the group id was supplied at construction rather than derived.
155
+ *
156
+ * Ratifier-specific tree builders only substitute their scheme's
157
+ * content-addressed singleton group when this is `false`; an explicit
158
+ * group is always committed as-is.
159
+ *
160
+ * @internal
161
+ */
162
+ readonly hasExplicitGroup: boolean;
153
163
  /** Optional maker callback. */
154
164
  readonly callback: Address;
155
165
  /** Callback payload. */
@@ -71,6 +71,16 @@ class Offer {
71
71
  tick;
72
72
  cachedGroup;
73
73
  cachedHash;
74
+ /**
75
+ * Whether the group id was supplied at construction rather than derived.
76
+ *
77
+ * Ratifier-specific tree builders only substitute their scheme's
78
+ * content-addressed singleton group when this is `false`; an explicit
79
+ * group is always committed as-is.
80
+ *
81
+ * @internal
82
+ */
83
+ hasExplicitGroup;
74
84
  /** Optional maker callback. */
75
85
  callback;
76
86
  /** Callback payload. */
@@ -97,7 +107,11 @@ class Offer {
97
107
  this.start = BigInt(offer.start);
98
108
  this.expiry = BigInt(offer.expiry);
99
109
  this.tick = BigInt(offer.tick);
100
- this.cachedGroup = offer.group;
110
+ this.hasExplicitGroup =
111
+ offer instanceof Offer
112
+ ? offer.hasExplicitGroup
113
+ : offer.group !== undefined;
114
+ this.cachedGroup = this.hasExplicitGroup ? offer.group : undefined;
101
115
  this.callback = offer.callback;
102
116
  this.callbackData = offer.callbackData;
103
117
  this.receiverIfMakerIsSeller = offer.receiverIfMakerIsSeller;
@@ -24,6 +24,9 @@ export declare namespace OfferUtils {
24
24
  * This is the bridge from SDK/domain objects
25
25
  * into Merkle leaf hashing, payload items, and take calldata encoding.
26
26
  *
27
+ * The struct carries a materialized group (the generic default when omitted);
28
+ * V1 tree builders re-derive that generic default under their scheme.
29
+ *
27
30
  * @param params.offer - Offer class or plain offer input to encode.
28
31
  * @param params.group - Optional protocol group id override encoded into the ABI offer.
29
32
  * @returns ABI-compatible offer.
@@ -50,6 +50,9 @@ var OfferUtils;
50
50
  * This is the bridge from SDK/domain objects
51
51
  * into Merkle leaf hashing, payload items, and take calldata encoding.
52
52
  *
53
+ * The struct carries a materialized group (the generic default when omitted);
54
+ * V1 tree builders re-derive that generic default under their scheme.
55
+ *
53
56
  * @param params.offer - Offer class or plain offer input to encode.
54
57
  * @param params.group - Optional protocol group id override encoded into the ABI offer.
55
58
  * @returns ABI-compatible offer.
@@ -2,7 +2,9 @@ import { type BigIntish } from "@morpho-org/morpho-ts";
2
2
  import { type Account, type Address, type Chain, type Client, type Hash, type Hex, type Signature, type Transport } from "viem";
3
3
  import { type IOffer } from "../offers/index.js";
4
4
  import type { Payload } from "./Payload.js";
5
- import { type RatifierTreeInput, type TreeProof } from "./TreeUtils.js";
5
+ import type { EcrecoverRatifierDataRequest, EcrecoverRatifierRatifyRequest, EcrecoverRatifierSignRequest, EcrecoverRatifierTypedDataRequest } from "./ratifierRequests.js";
6
+ import type { RatifierTreeInput } from "./TreeUtils.js";
7
+ import { type TreeProof } from "./TreeUtils.js";
6
8
  declare const typedDataTypes: {
7
9
  readonly EIP712Domain: readonly [{
8
10
  readonly name: "chainId";
@@ -245,6 +247,7 @@ export type EcrecoverSignatureInput = Hex | Signature | Signature<number, number
245
247
  * };
246
248
  * console.log(params.chainId);
247
249
  * ```
250
+ * @deprecated Use {@link EcrecoverRatifierTypedDataRequest} with {@link EcrecoverRatifier}.
248
251
  */
249
252
  export interface EcrecoverRatifierTypedDataParams {
250
253
  /** Tree-like input being ratified. Existing `Tree` instances reuse cached hashes and proofs. */
@@ -295,6 +298,7 @@ export interface EcrecoverRatifierTypedDataParams {
295
298
  * };
296
299
  * console.log(params.tree);
297
300
  * ```
301
+ * @deprecated Use {@link EcrecoverRatifierRatifyRequest} with {@link EcrecoverRatifier}.
298
302
  */
299
303
  export type EcrecoverRatifierRatifyParams = {
300
304
  /** Tree-like input being ratified. */
@@ -357,6 +361,7 @@ export type EcrecoverRatifierRatifyParams = {
357
361
  * };
358
362
  * console.log(params.leafIndex);
359
363
  * ```
364
+ * @deprecated Use {@link EcrecoverRatifierDataRequest} with {@link EcrecoverRatifier}.
360
365
  */
361
366
  export interface EcrecoverRatifierDataParams {
362
367
  /** Tree-like input that produced the proof. Existing `Tree` instances reuse cached hashes and proofs. */
@@ -419,6 +424,7 @@ export interface VerifiedEcrecoverRatifierData extends DecodedEcrecoverRatifierD
419
424
  *
420
425
  * console.log(EcrecoverRatifierUtils.treeTypeHash(0));
421
426
  * ```
427
+ * @deprecated Use {@link EcrecoverRatifier} with a tagged tree.
422
428
  */
423
429
  export declare namespace EcrecoverRatifierUtils {
424
430
  /**
@@ -593,7 +599,7 @@ export declare namespace EcrecoverRatifierUtils {
593
599
  * Verifies an Ecrecover ratifier-data proof and recovers its signer.
594
600
  *
595
601
  * This helper intentionally does not check `Midnight.isAuthorized` or
596
- * `EcrecoverRatifier.isRootCanceled` state. Consumers must query both at the
602
+ * `EcrecoverRatifierUtils.isRootCanceled` state. Consumers must query both at the
597
603
  * observed block before treating a recovered item as executable: the returned
598
604
  * signer must be the maker or authorized by the maker, the offer ratifier must
599
605
  * be authorized by the maker, and `isRootCanceled(maker, root)` must be false.
@@ -876,4 +882,114 @@ export declare namespace EcrecoverRatifierUtils {
876
882
  */
877
883
  function ratify(params: EcrecoverRatifierRatifyParams): Promise<readonly Payload.Item[]>;
878
884
  }
885
+ /**
886
+ * Tagged-tree API for EcrecoverRatifier with validated portable leaf commitments.
887
+ * Legacy untagged inputs remain available through {@link EcrecoverRatifierUtils}.
888
+ */
889
+ export declare namespace EcrecoverRatifier {
890
+ /**
891
+ * Builds Ecrecover signing data from a tagged tree.
892
+ * @param request.tree - Matching tagged tree or portable snapshot; commitments are validated before use.
893
+ * @param request.chainId - Chain defining the EIP-712 domain.
894
+ * @returns EIP-712 domain, type definitions, and offer-tree message.
895
+ * @throws {InvalidTreeError} When the tag, commitments, or root are invalid.
896
+ * @throws {InvalidTreeHeightError} When the descriptor height is unsupported.
897
+ * @example
898
+ * ```ts
899
+ * import { EcrecoverRatifier, type EcrecoverRatifierTypedDataRequest } from "@morpho-org/midnight-sdk";
900
+ * function execute(request: EcrecoverRatifierTypedDataRequest) {
901
+ * return EcrecoverRatifier.typedData(request);
902
+ * }
903
+ * ```
904
+ */
905
+ function typedData(request: EcrecoverRatifierTypedDataRequest): EcrecoverRatificationTypedData;
906
+ /**
907
+ * Computes the signing digest of a tagged Ecrecover tree.
908
+ * @param request.tree - Matching tagged tree or portable snapshot; commitments are validated before use.
909
+ * @param request.chainId - Chain defining the EIP-712 domain.
910
+ * @returns The EIP-712 signing digest.
911
+ * @throws {InvalidTreeError} When the tag, commitments, or root are invalid.
912
+ * @throws {InvalidTreeHeightError} When the descriptor height is unsupported.
913
+ * @example
914
+ * ```ts
915
+ * import { EcrecoverRatifier, type EcrecoverRatifierTypedDataRequest } from "@morpho-org/midnight-sdk";
916
+ * function execute(request: EcrecoverRatifierTypedDataRequest) {
917
+ * return EcrecoverRatifier.digest(request);
918
+ * }
919
+ * ```
920
+ */
921
+ function digest(request: EcrecoverRatifierTypedDataRequest): Hash;
922
+ /**
923
+ * Signs a tagged Ecrecover tree using the supplied client and account.
924
+ * @param request.tree - Matching tagged tree or portable snapshot; commitments are validated before use.
925
+ * @param request.account - Maker or authorized signer.
926
+ * @param request.client - Signing client; omit when ratify receives a precomputed signature.
927
+ * @returns A verified hex signature over the tree.
928
+ * @throws {InvalidTreeError} When the tag, commitments, or root are invalid.
929
+ * @throws {InvalidTreeHeightError} When the descriptor height is unsupported.
930
+ * @throws {ChainIdMismatchError} When the signing client's chain differs from the offers.
931
+ * @throws {InvalidTypedDataSignatureError} When the signature does not recover to the supplied account.
932
+ * @example
933
+ * ```ts
934
+ * import { EcrecoverRatifier, type EcrecoverRatifierSignRequest } from "@morpho-org/midnight-sdk";
935
+ * function execute(request: EcrecoverRatifierSignRequest) {
936
+ * return EcrecoverRatifier.sign(request);
937
+ * }
938
+ * ```
939
+ */
940
+ function sign(request: EcrecoverRatifierSignRequest): Promise<Hex>;
941
+ /**
942
+ * Encodes the signature and proof for one tagged Ecrecover leaf.
943
+ * @param request.tree - Matching tagged tree or portable snapshot; commitments are validated before use.
944
+ * @param request.signature - Tree signature; ratify may instead request one through the supplied client.
945
+ * @param request.leafIndex - Leaf to prove.
946
+ * @returns ABI-encoded ratifier data for the requested leaf.
947
+ * @throws {InvalidTreeError} When the tag, commitments, or root are invalid.
948
+ * @throws {InvalidTreeHeightError} When the descriptor height is unsupported.
949
+ * @throws {InvalidEcrecoverSignatureVError} When a supplied signature has an unsupported recovery value.
950
+ * @example
951
+ * ```ts
952
+ * import { EcrecoverRatifier, type EcrecoverRatifierDataRequest } from "@morpho-org/midnight-sdk";
953
+ * function execute(request: EcrecoverRatifierDataRequest) {
954
+ * return EcrecoverRatifier.ratifierData(request);
955
+ * }
956
+ * ```
957
+ */
958
+ function ratifierData(request: EcrecoverRatifierDataRequest): Hex;
959
+ /**
960
+ * Builds payload items from a tagged tree and a verified signature.
961
+ * @param request.tree - Matching tagged tree or portable snapshot; commitments are validated before use.
962
+ * @param request.account - Maker or authorized signer.
963
+ * @param request.client - Signing client; omit when ratify receives a precomputed signature.
964
+ * @param request.signature - Tree signature; ratify may instead request one through the supplied client.
965
+ * @returns One payload item per non-padding offer, including its ratifier data.
966
+ * @throws {InvalidTreeError} When the tag, commitments, or root are invalid.
967
+ * @throws {InvalidTreeHeightError} When the descriptor height is unsupported.
968
+ * @throws {ChainIdMismatchError} When the signing client's chain differs from the offers.
969
+ * @throws {InvalidTypedDataSignatureError} When the signature does not recover to the supplied account.
970
+ * @throws {InvalidEcrecoverSignatureVError} When a supplied signature has an unsupported recovery value.
971
+ * @example
972
+ * ```ts
973
+ * import { EcrecoverRatifier, type EcrecoverRatifierRatifyRequest } from "@morpho-org/midnight-sdk";
974
+ * function execute(request: EcrecoverRatifierRatifyRequest) {
975
+ * return EcrecoverRatifier.ratify(request);
976
+ * }
977
+ * ```
978
+ */
979
+ function ratify(request: EcrecoverRatifierRatifyRequest): Promise<readonly Payload.Item[]>;
980
+ /** {@inheritDoc EcrecoverRatifierUtils.treeTypeHash} */
981
+ const treeTypeHash: typeof EcrecoverRatifierUtils.treeTypeHash;
982
+ /** {@inheritDoc EcrecoverRatifierUtils.digestForRoot} */
983
+ const digestForRoot: typeof EcrecoverRatifierUtils.digestForRoot;
984
+ /** {@inheritDoc EcrecoverRatifierUtils.digestRatifierData} */
985
+ const digestRatifierData: typeof EcrecoverRatifierUtils.digestRatifierData;
986
+ /** {@inheritDoc EcrecoverRatifierUtils.verifyRatifierData} */
987
+ const verifyRatifierData: typeof EcrecoverRatifierUtils.verifyRatifierData;
988
+ /** {@inheritDoc EcrecoverRatifierUtils.toSignature} */
989
+ const toSignature: typeof EcrecoverRatifierUtils.toSignature;
990
+ /** {@inheritDoc EcrecoverRatifierUtils.encodeRatifierData} */
991
+ const encodeRatifierData: typeof EcrecoverRatifierUtils.encodeRatifierData;
992
+ /** {@inheritDoc EcrecoverRatifierUtils.decodeRatifierData} */
993
+ const decodeRatifierData: typeof EcrecoverRatifierUtils.decodeRatifierData;
994
+ }
879
995
  export {};