@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/esm/errors.js CHANGED
@@ -263,6 +263,138 @@ export class InvalidTreeError extends Error {
263
263
  this.name = "InvalidTreeError";
264
264
  }
265
265
  }
266
+ /**
267
+ * Thrown when a RateRatifierV1 leaf receives a negative rate.
268
+ *
269
+ * @example
270
+ * ```ts
271
+ * import { InvalidRateRatifierV1RateError } from "@morpho-org/midnight-sdk";
272
+ *
273
+ * throw new InvalidRateRatifierV1RateError(-1n);
274
+ * ```
275
+ */
276
+ export class InvalidRateRatifierV1RateError extends Error {
277
+ /** Negative rate that was rejected. */
278
+ rate;
279
+ constructor(rate) {
280
+ super(`Rate "${rate}" is negative. Use a non-negative WAD-scaled rate.`);
281
+ this.name = "InvalidRateRatifierV1RateError";
282
+ this.rate = rate;
283
+ }
284
+ }
285
+ /**
286
+ * Thrown when RateRatifierV1 price-bound arithmetic overflows uint256.
287
+ *
288
+ * @example
289
+ * ```ts
290
+ * import { RateRatifierV1BoundOverflowError } from "@morpho-org/midnight-sdk";
291
+ *
292
+ * throw new RateRatifierV1BoundOverflowError(2n ** 255n, 10n);
293
+ * ```
294
+ */
295
+ export class RateRatifierV1BoundOverflowError extends Error {
296
+ /** Rate whose bound arithmetic overflowed. */
297
+ rate;
298
+ /** Time to maturity used in the overflowing bound. */
299
+ timeToMaturity;
300
+ constructor(rate, timeToMaturity) {
301
+ super(`Rate bound arithmetic overflows uint256 for rate "${rate}" and timeToMaturity "${timeToMaturity}". Lower the rate or time to maturity.`);
302
+ this.name = "RateRatifierV1BoundOverflowError";
303
+ this.rate = rate;
304
+ this.timeToMaturity = timeToMaturity;
305
+ }
306
+ }
307
+ /**
308
+ * Thrown when a RateRatifierV1 leaf offer commits a nominal tick below the
309
+ * router's minimum takeable tick.
310
+ *
311
+ * @example
312
+ * ```ts
313
+ * import { InvalidRateRatifierV1TickError } from "@morpho-org/midnight-sdk";
314
+ *
315
+ * throw new InvalidRateRatifierV1TickError(0n, 3372n);
316
+ * ```
317
+ */
318
+ export class InvalidRateRatifierV1TickError extends Error {
319
+ /** Nominal tick that was rejected. */
320
+ tick;
321
+ /** Minimum accepted tick. */
322
+ minTick;
323
+ constructor(tick, minTick) {
324
+ 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}".`);
325
+ this.name = "InvalidRateRatifierV1TickError";
326
+ this.tick = tick;
327
+ this.minTick = minTick;
328
+ }
329
+ }
330
+ /**
331
+ * Thrown when a RateRatifierV1 time parameter is negative.
332
+ *
333
+ * @example
334
+ * ```ts
335
+ * import { InvalidRateRatifierV1TimeError } from "@morpho-org/midnight-sdk";
336
+ *
337
+ * throw new InvalidRateRatifierV1TimeError(-1n, "timestamp");
338
+ * ```
339
+ */
340
+ export class InvalidRateRatifierV1TimeError extends Error {
341
+ /** Negative time value that was rejected. */
342
+ value;
343
+ /** Parameter that carried the negative value. */
344
+ field;
345
+ constructor(value, field) {
346
+ super(`${field} "${value}" is negative. Use a non-negative number of seconds.`);
347
+ this.name = "InvalidRateRatifierV1TimeError";
348
+ this.value = value;
349
+ this.field = field;
350
+ }
351
+ }
352
+ /**
353
+ * Thrown when a V1 ratifier address is the zero address.
354
+ *
355
+ * @example
356
+ * ```ts
357
+ * import { InvalidRatifierV1AddressError } from "@morpho-org/midnight-sdk";
358
+ *
359
+ * throw new InvalidRatifierV1AddressError(
360
+ * "0x0000000000000000000000000000000000000000",
361
+ * );
362
+ * ```
363
+ */
364
+ export class InvalidRatifierV1AddressError extends Error {
365
+ /** Zero ratifier address that was rejected. */
366
+ ratifier;
367
+ constructor(ratifier) {
368
+ super(`Ratifier address "${ratifier}" is the zero address. Use a deployed PriceRatifierV1 or RateRatifierV1 address.`);
369
+ this.name = "InvalidRatifierV1AddressError";
370
+ this.ratifier = ratifier;
371
+ }
372
+ }
373
+ /**
374
+ * Thrown when a taker is not the allowed taker of a V1 ratifier leaf.
375
+ *
376
+ * @example
377
+ * ```ts
378
+ * import { RatifierV1TakerNotAllowedError } from "@morpho-org/midnight-sdk";
379
+ *
380
+ * throw new RatifierV1TakerNotAllowedError({
381
+ * taker: "0x0000000000000000000000000000000000000001",
382
+ * allowedTaker: "0x0000000000000000000000000000000000000002",
383
+ * });
384
+ * ```
385
+ */
386
+ export class RatifierV1TakerNotAllowedError extends Error {
387
+ /** Taker that attempted to take the offer. */
388
+ taker;
389
+ /** Taker allowed by the ratified leaf. */
390
+ allowedTaker;
391
+ constructor(params) {
392
+ super(`Taker "${params.taker}" is not the allowed taker "${params.allowedTaker}". Use the allowed taker or an offer without a taker restriction.`);
393
+ this.name = "RatifierV1TakerNotAllowedError";
394
+ this.taker = params.taker;
395
+ this.allowedTaker = params.allowedTaker;
396
+ }
397
+ }
266
398
  /**
267
399
  * Thrown when a viem client's chain id does not match the chain id required by a signing flow.
268
400
  *
@@ -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
  */
@@ -1,6 +1,6 @@
1
1
  import { getChainAddress } from "@morpho-org/morpho-ts";
2
2
  import { getBytecode } from "viem/actions";
3
- import { RatifierUtils, } from "../signatures/RatifierUtils.js";
3
+ import { Ratifier } from "../signatures/Ratifier.js";
4
4
  import { resolveChainId } from "./utils.js";
5
5
  /**
6
6
  * Fetches maker bytecode and classifies the ratifier route for new offers.
@@ -10,7 +10,7 @@ import { resolveChainId } from "./utils.js";
10
10
  * the maker is an EOA or EIP-7702 account that can use Ecrecover signatures, or
11
11
  * a deployed-code account that should use Setter root approval. Put the returned
12
12
  * `ratifier` address on `Offer.create`, then use the returned `type` to choose
13
- * `EcrecoverRatifierUtils.ratify` or `SetterRatifierUtils.ratify` after the tree
13
+ * `EcrecoverRatifier.ratify` or `SetterRatifier.ratify` after the tree
14
14
  * has been built.
15
15
  *
16
16
  * Reads `eth_chainId` only when the viem client has no configured chain id,
@@ -30,7 +30,8 @@ import { resolveChainId } from "./utils.js";
30
30
  * const maker = "0x7b093658BE7f90B63D7c359e8f408e503c2D9401";
31
31
  * const info = await fetchRatifierInfo(client, { maker });
32
32
  * // Pass info.ratifier to Offer.create(...), then use info.type after
33
- * // Tree.create([...]) to choose the Ecrecover or Setter ratifier flow.
33
+ * // Tree.create({ type: info.type, entries: [...] }) to choose the Ecrecover
34
+ * // or Setter ratifier flow.
34
35
  * console.log(info.type, info.ratifier);
35
36
  * ```
36
37
  */
@@ -46,7 +47,7 @@ export async function fetchRatifierInfo(client, params) {
46
47
  : {}),
47
48
  address: params.maker,
48
49
  });
49
- return RatifierUtils.getRatifierInfo({
50
+ return Ratifier.getRatifierInfo({
50
51
  bytecode,
51
52
  ecrecoverRatifier,
52
53
  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/esm/index.js CHANGED
@@ -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,7 @@ 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 { SetterRatifier, SetterRatifierUtils, } from "./signatures/SetterRatifier.js";
@@ -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. */
@@ -68,6 +68,16 @@ export class Offer {
68
68
  tick;
69
69
  cachedGroup;
70
70
  cachedHash;
71
+ /**
72
+ * Whether the group id was supplied at construction rather than derived.
73
+ *
74
+ * Ratifier-specific tree builders only substitute their scheme's
75
+ * content-addressed singleton group when this is `false`; an explicit
76
+ * group is always committed as-is.
77
+ *
78
+ * @internal
79
+ */
80
+ hasExplicitGroup;
71
81
  /** Optional maker callback. */
72
82
  callback;
73
83
  /** Callback payload. */
@@ -94,7 +104,11 @@ export class Offer {
94
104
  this.start = BigInt(offer.start);
95
105
  this.expiry = BigInt(offer.expiry);
96
106
  this.tick = BigInt(offer.tick);
97
- this.cachedGroup = offer.group;
107
+ this.hasExplicitGroup =
108
+ offer instanceof Offer
109
+ ? offer.hasExplicitGroup
110
+ : offer.group !== undefined;
111
+ this.cachedGroup = this.hasExplicitGroup ? offer.group : undefined;
98
112
  this.callback = offer.callback;
99
113
  this.callbackData = offer.callbackData;
100
114
  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.
@@ -47,6 +47,9 @@ export var OfferUtils;
47
47
  * This is the bridge from SDK/domain objects
48
48
  * into Merkle leaf hashing, payload items, and take calldata encoding.
49
49
  *
50
+ * The struct carries a materialized group (the generic default when omitted);
51
+ * V1 tree builders re-derive that generic default under their scheme.
52
+ *
50
53
  * @param params.offer - Offer class or plain offer input to encode.
51
54
  * @param params.group - Optional protocol group id override encoded into the ABI offer.
52
55
  * @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 {};