@morpho-org/midnight-sdk 1.7.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/MIGRATION-v1-to-v2.md +6 -0
  2. package/README.md +63 -61
  3. package/lib/cjs/abis.d.ts +1962 -759
  4. package/lib/cjs/abis.js +2021 -995
  5. package/lib/cjs/api/helpers.d.ts +1 -17
  6. package/lib/cjs/api/helpers.js +0 -4
  7. package/lib/cjs/api/types.d.ts +5 -4
  8. package/lib/cjs/api/version.generated.d.ts +1 -1
  9. package/lib/cjs/api/version.generated.js +2 -2
  10. package/lib/cjs/bundlesV2.d.ts +15 -0
  11. package/lib/cjs/bundlesV2.js +2 -0
  12. package/lib/cjs/constants.d.ts +34 -0
  13. package/lib/cjs/constants.js +35 -1
  14. package/lib/cjs/errors.d.ts +107 -0
  15. package/lib/cjs/errors.js +139 -1
  16. package/lib/cjs/fetch/Ratifier.d.ts +4 -3
  17. package/lib/cjs/fetch/Ratifier.js +6 -4
  18. package/lib/cjs/index.d.ts +8 -0
  19. package/lib/cjs/index.js +16 -1
  20. package/lib/cjs/offers/Offer.d.ts +10 -0
  21. package/lib/cjs/offers/Offer.js +15 -1
  22. package/lib/cjs/offers/OfferUtils.d.ts +3 -0
  23. package/lib/cjs/offers/OfferUtils.js +3 -0
  24. package/lib/cjs/signatures/{EcrecoverRatifierUtils.d.ts → EcrecoverRatifier.d.ts} +118 -2
  25. package/lib/cjs/signatures/{EcrecoverRatifierUtils.js → EcrecoverRatifier.js} +146 -9
  26. package/lib/cjs/signatures/GroupUtils.d.ts +55 -2
  27. package/lib/cjs/signatures/GroupUtils.js +64 -5
  28. package/lib/cjs/signatures/Payload.d.ts +3 -3
  29. package/lib/cjs/signatures/PriceRatifierV1.d.ts +472 -0
  30. package/lib/cjs/signatures/PriceRatifierV1.js +521 -0
  31. package/lib/cjs/signatures/RateRatifierV1.d.ts +581 -0
  32. package/lib/cjs/signatures/RateRatifierV1.js +696 -0
  33. package/lib/{esm/signatures/RatifierUtils.d.ts → cjs/signatures/Ratifier.d.ts} +14 -12
  34. package/lib/cjs/signatures/{RatifierUtils.js → Ratifier.js} +29 -29
  35. package/lib/cjs/signatures/{SetterRatifierUtils.d.ts → SetterRatifier.d.ts} +50 -3
  36. package/lib/cjs/signatures/{SetterRatifierUtils.js → SetterRatifier.js} +65 -7
  37. package/lib/cjs/signatures/Tree.d.ts +94 -17
  38. package/lib/cjs/signatures/Tree.js +146 -111
  39. package/lib/cjs/signatures/TreeUtils.d.ts +191 -21
  40. package/lib/cjs/signatures/TreeUtils.js +320 -134
  41. package/lib/cjs/signatures/index.d.ts +7 -3
  42. package/lib/cjs/signatures/index.js +5 -3
  43. package/lib/cjs/signatures/ratifierRequests.d.ts +55 -0
  44. package/lib/cjs/signatures/ratifierRequests.js +2 -0
  45. package/lib/cjs/signatures/ratifierV1Internal.d.ts +57 -0
  46. package/lib/cjs/signatures/ratifierV1Internal.js +183 -0
  47. package/lib/cjs/signatures/standardRatifierInternal.d.ts +4 -0
  48. package/lib/cjs/signatures/standardRatifierInternal.js +12 -0
  49. package/lib/cjs/signatures/treeMathInternal.d.ts +4 -0
  50. package/lib/cjs/signatures/treeMathInternal.js +12 -0
  51. package/lib/cjs/signatures/treeTypes.d.ts +109 -0
  52. package/lib/cjs/signatures/treeTypes.js +2 -0
  53. package/lib/esm/abis.d.ts +1962 -759
  54. package/lib/esm/abis.js +2020 -994
  55. package/lib/esm/api/helpers.d.ts +1 -17
  56. package/lib/esm/api/helpers.js +4 -4
  57. package/lib/esm/api/types.d.ts +5 -4
  58. package/lib/esm/api/version.generated.d.ts +1 -1
  59. package/lib/esm/api/version.generated.js +2 -2
  60. package/lib/esm/bundlesV2.d.ts +15 -0
  61. package/lib/esm/bundlesV2.js +1 -0
  62. package/lib/esm/constants.d.ts +34 -0
  63. package/lib/esm/constants.js +34 -0
  64. package/lib/esm/errors.d.ts +107 -0
  65. package/lib/esm/errors.js +132 -0
  66. package/lib/esm/fetch/Ratifier.d.ts +4 -3
  67. package/lib/esm/fetch/Ratifier.js +6 -4
  68. package/lib/esm/index.d.ts +8 -0
  69. package/lib/esm/index.js +5 -0
  70. package/lib/esm/offers/Offer.d.ts +10 -0
  71. package/lib/esm/offers/Offer.js +15 -1
  72. package/lib/esm/offers/OfferUtils.d.ts +3 -0
  73. package/lib/esm/offers/OfferUtils.js +3 -0
  74. package/lib/esm/signatures/{EcrecoverRatifierUtils.d.ts → EcrecoverRatifier.d.ts} +118 -2
  75. package/lib/esm/signatures/{EcrecoverRatifierUtils.js → EcrecoverRatifier.js} +146 -9
  76. package/lib/esm/signatures/GroupUtils.d.ts +55 -2
  77. package/lib/esm/signatures/GroupUtils.js +64 -5
  78. package/lib/esm/signatures/Payload.d.ts +3 -3
  79. package/lib/esm/signatures/PriceRatifierV1.d.ts +472 -0
  80. package/lib/esm/signatures/PriceRatifierV1.js +520 -0
  81. package/lib/esm/signatures/RateRatifierV1.d.ts +581 -0
  82. package/lib/esm/signatures/RateRatifierV1.js +695 -0
  83. package/lib/{cjs/signatures/RatifierUtils.d.ts → esm/signatures/Ratifier.d.ts} +14 -12
  84. package/lib/esm/signatures/{RatifierUtils.js → Ratifier.js} +31 -29
  85. package/lib/esm/signatures/{SetterRatifierUtils.d.ts → SetterRatifier.d.ts} +50 -3
  86. package/lib/esm/signatures/{SetterRatifierUtils.js → SetterRatifier.js} +65 -7
  87. package/lib/esm/signatures/Tree.d.ts +94 -17
  88. package/lib/esm/signatures/Tree.js +147 -112
  89. package/lib/esm/signatures/TreeUtils.d.ts +191 -21
  90. package/lib/esm/signatures/TreeUtils.js +318 -132
  91. package/lib/esm/signatures/index.d.ts +7 -3
  92. package/lib/esm/signatures/index.js +5 -3
  93. package/lib/esm/signatures/ratifierRequests.d.ts +55 -0
  94. package/lib/esm/signatures/ratifierRequests.js +1 -0
  95. package/lib/esm/signatures/ratifierV1Internal.d.ts +57 -0
  96. package/lib/esm/signatures/ratifierV1Internal.js +176 -0
  97. package/lib/esm/signatures/standardRatifierInternal.d.ts +4 -0
  98. package/lib/esm/signatures/standardRatifierInternal.js +9 -0
  99. package/lib/esm/signatures/treeMathInternal.d.ts +4 -0
  100. package/lib/esm/signatures/treeMathInternal.js +8 -0
  101. package/lib/esm/signatures/treeTypes.d.ts +109 -0
  102. package/lib/esm/signatures/treeTypes.js +1 -0
  103. package/package.json +9 -8
@@ -1,7 +1,7 @@
1
1
  import type { Address, Hex } from "viem";
2
2
  import type { RatifierTreeInput, TreeLike } from "./TreeUtils.js";
3
3
  /**
4
- * Parameters for {@link RatifierUtils.getRatifierInfo}.
4
+ * Parameters for {@link Ratifier.getRatifierInfo}.
5
5
  *
6
6
  * Pass the maker account bytecode read at the same block context used to build
7
7
  * the offer. The bytecode is used only to choose the ratifier address to put on
@@ -60,12 +60,12 @@ export interface RatifierInfo {
60
60
  *
61
61
  * @example
62
62
  * ```ts
63
- * import { RatifierUtils } from "@morpho-org/midnight-sdk";
63
+ * import { Ratifier } from "@morpho-org/midnight-sdk";
64
64
  *
65
- * console.log(RatifierUtils.isEip7702Designator("0xef0100"));
65
+ * console.log(Ratifier.isEip7702Designator("0xef0100"));
66
66
  * ```
67
67
  */
68
- export declare namespace RatifierUtils {
68
+ export declare namespace Ratifier {
69
69
  /**
70
70
  * Normalizes a ratifier tree input and asserts it uses one ratifier address.
71
71
  *
@@ -80,7 +80,7 @@ export declare namespace RatifierUtils {
80
80
  * @throws {InvalidTreeHeightError} when the tree height is unsupported.
81
81
  * @example
82
82
  * ```ts
83
- * import { Offer, RatifierUtils } from "@morpho-org/midnight-sdk";
83
+ * import { Offer, Ratifier } from "@morpho-org/midnight-sdk";
84
84
  * import { zeroAddress } from "viem";
85
85
  *
86
86
  * const offer = Offer.create({
@@ -108,7 +108,7 @@ export declare namespace RatifierUtils {
108
108
  * ratifier: "0x0000000000000000000000000000000000004000",
109
109
  * maxUnits: 100n,
110
110
  * });
111
- * const { tree, ratifier } = RatifierUtils.normalizeRatifierTree({
111
+ * const { tree, ratifier } = Ratifier.normalizeRatifierTree({
112
112
  * tree: [offer],
113
113
  * label: "Ecrecover",
114
114
  * });
@@ -132,9 +132,9 @@ export declare namespace RatifierUtils {
132
132
  * @returns Whether the bytecode starts with `0xef0100`.
133
133
  * @example
134
134
  * ```ts
135
- * import { RatifierUtils } from "@morpho-org/midnight-sdk";
135
+ * import { Ratifier } from "@morpho-org/midnight-sdk";
136
136
  *
137
- * console.log(RatifierUtils.isEip7702Designator("0xef0100"));
137
+ * console.log(Ratifier.isEip7702Designator("0xef0100"));
138
138
  * ```
139
139
  */
140
140
  function isEip7702Designator(bytecode: Hex): boolean;
@@ -143,8 +143,8 @@ export declare namespace RatifierUtils {
143
143
  * accounts.
144
144
  *
145
145
  * Use the returned `ratifier` address in `Offer.create`. Later, use
146
- * `EcrecoverRatifierUtils.ratify` when `type` is `ecrecover`, or approve the
147
- * root and call `SetterRatifierUtils.ratify` when `type` is `setter`.
146
+ * `EcrecoverRatifier.ratify` when `type` is `ecrecover`, or approve the
147
+ * root and call `SetterRatifier.ratify` when `type` is `setter`.
148
148
  *
149
149
  * @param params.bytecode - Maker bytecode returned by `eth_getCode`.
150
150
  * @param params.ecrecoverRatifier - Ratifier address used for EOAs and EIP-7702 accounts.
@@ -152,9 +152,9 @@ export declare namespace RatifierUtils {
152
152
  * @returns Ratifier information for the maker.
153
153
  * @example
154
154
  * ```ts
155
- * import { RatifierUtils } from "@morpho-org/midnight-sdk";
155
+ * import { Ratifier } from "@morpho-org/midnight-sdk";
156
156
  *
157
- * const info = RatifierUtils.getRatifierInfo({
157
+ * const info = Ratifier.getRatifierInfo({
158
158
  * bytecode: "0x",
159
159
  * ecrecoverRatifier: "0x0000000000000000000000000000000000000001",
160
160
  * setterRatifier: "0x0000000000000000000000000000000000000002",
@@ -164,3 +164,5 @@ export declare namespace RatifierUtils {
164
164
  */
165
165
  function getRatifierInfo(params: GetRatifierInfoParams): RatifierInfo;
166
166
  }
167
+ /** @deprecated Use {@link Ratifier}. Retained for compatibility. */
168
+ export { Ratifier as RatifierUtils };
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RatifierUtils = void 0;
3
+ exports.RatifierUtils = exports.Ratifier = void 0;
4
+ const constants_js_1 = require("../constants.js");
4
5
  const errors_js_1 = require("../errors.js");
5
6
  const index_js_1 = require("../offers/index.js");
6
- const Group_js_1 = require("./Group.js");
7
- const GroupUtils_js_1 = require("./GroupUtils.js");
8
7
  const offerStructInternal_js_1 = require("./offerStructInternal.js");
9
8
  const TreeUtils_js_1 = require("./TreeUtils.js");
9
+ const treeMathInternal_js_1 = require("./treeMathInternal.js");
10
10
  function isTreeLike(tree) {
11
11
  return (!Array.isArray(tree) &&
12
12
  "offers" in tree &&
@@ -17,13 +17,15 @@ function isTreeLike(tree) {
17
17
  }
18
18
  function normalizeTree(tree) {
19
19
  if (isTreeLike(tree)) {
20
- if (!Number.isInteger(tree.height) || tree.height < 0 || tree.height > 20) {
20
+ if (!Number.isInteger(tree.height) ||
21
+ tree.height < 0 ||
22
+ tree.height > constants_js_1.MAX_TREE_HEIGHT) {
21
23
  throw new errors_js_1.InvalidTreeHeightError(tree.height);
22
24
  }
23
25
  const expectedLength = 2 ** tree.height;
24
26
  if (tree.paddedOffers.length !== expectedLength ||
25
27
  tree.leaves.length !== expectedLength ||
26
- tree.offers.length > expectedLength) {
28
+ expectedLength !== (0, treeMathInternal_js_1.nextPowerOfTwo)(tree.offers.length)) {
27
29
  throw new errors_js_1.InvalidTreeError("Tree offers, leaves, and height describe different trees.");
28
30
  }
29
31
  const computedLeaves = tree.paddedOffers.map(index_js_1.OfferUtils.hashStruct);
@@ -63,14 +65,7 @@ function normalizeTree(tree) {
63
65
  return tree;
64
66
  }
65
67
  const entries = Array.isArray(tree) ? tree : [tree];
66
- const offers = entries.flatMap((entry) => GroupUtils_js_1.GroupUtils.isGroupInput(entry)
67
- ? Group_js_1.Group.from(entry).offers
68
- : [
69
- new index_js_1.Offer({
70
- ...index_js_1.Offer.from(entry),
71
- group: GroupUtils_js_1.GroupUtils.hash([entry]),
72
- }),
73
- ]);
68
+ const offers = TreeUtils_js_1.TreeUtils.normalizeEntries(entries);
74
69
  const descriptor = TreeUtils_js_1.TreeUtils.buildDescriptor(entries);
75
70
  return {
76
71
  offers,
@@ -104,13 +99,13 @@ function assertRatifierTree(params) {
104
99
  *
105
100
  * @example
106
101
  * ```ts
107
- * import { RatifierUtils } from "@morpho-org/midnight-sdk";
102
+ * import { Ratifier } from "@morpho-org/midnight-sdk";
108
103
  *
109
- * console.log(RatifierUtils.isEip7702Designator("0xef0100"));
104
+ * console.log(Ratifier.isEip7702Designator("0xef0100"));
110
105
  * ```
111
106
  */
112
- var RatifierUtils;
113
- (function (RatifierUtils) {
107
+ var Ratifier;
108
+ (function (Ratifier) {
114
109
  /**
115
110
  * Normalizes a ratifier tree input and asserts it uses one ratifier address.
116
111
  *
@@ -125,7 +120,7 @@ var RatifierUtils;
125
120
  * @throws {InvalidTreeHeightError} when the tree height is unsupported.
126
121
  * @example
127
122
  * ```ts
128
- * import { Offer, RatifierUtils } from "@morpho-org/midnight-sdk";
123
+ * import { Offer, Ratifier } from "@morpho-org/midnight-sdk";
129
124
  * import { zeroAddress } from "viem";
130
125
  *
131
126
  * const offer = Offer.create({
@@ -153,7 +148,7 @@ var RatifierUtils;
153
148
  * ratifier: "0x0000000000000000000000000000000000004000",
154
149
  * maxUnits: 100n,
155
150
  * });
156
- * const { tree, ratifier } = RatifierUtils.normalizeRatifierTree({
151
+ * const { tree, ratifier } = Ratifier.normalizeRatifierTree({
157
152
  * tree: [offer],
158
153
  * label: "Ecrecover",
159
154
  * });
@@ -161,11 +156,16 @@ var RatifierUtils;
161
156
  * ```
162
157
  */
163
158
  function normalizeRatifierTree(params) {
159
+ if ("type" in params.tree &&
160
+ params.tree.type != null &&
161
+ params.tree.type !== params.label.toLowerCase()) {
162
+ throw new errors_js_1.InvalidTreeError("Ratifier route does not match the tree route.");
163
+ }
164
164
  const tree = normalizeTree(params.tree);
165
165
  const ratifier = assertRatifierTree({ tree, label: params.label });
166
166
  return { tree, ratifier };
167
167
  }
168
- RatifierUtils.normalizeRatifierTree = normalizeRatifierTree;
168
+ Ratifier.normalizeRatifierTree = normalizeRatifierTree;
169
169
  /**
170
170
  * Checks whether bytecode is an EIP-7702 designator.
171
171
  *
@@ -176,22 +176,22 @@ var RatifierUtils;
176
176
  * @returns Whether the bytecode starts with `0xef0100`.
177
177
  * @example
178
178
  * ```ts
179
- * import { RatifierUtils } from "@morpho-org/midnight-sdk";
179
+ * import { Ratifier } from "@morpho-org/midnight-sdk";
180
180
  *
181
- * console.log(RatifierUtils.isEip7702Designator("0xef0100"));
181
+ * console.log(Ratifier.isEip7702Designator("0xef0100"));
182
182
  * ```
183
183
  */
184
184
  function isEip7702Designator(bytecode) {
185
185
  return bytecode.toLowerCase().startsWith("0xef0100");
186
186
  }
187
- RatifierUtils.isEip7702Designator = isEip7702Designator;
187
+ Ratifier.isEip7702Designator = isEip7702Designator;
188
188
  /**
189
189
  * Selects Ecrecover for EOAs/EIP-7702 accounts and Setter for deployed-code
190
190
  * accounts.
191
191
  *
192
192
  * Use the returned `ratifier` address in `Offer.create`. Later, use
193
- * `EcrecoverRatifierUtils.ratify` when `type` is `ecrecover`, or approve the
194
- * root and call `SetterRatifierUtils.ratify` when `type` is `setter`.
193
+ * `EcrecoverRatifier.ratify` when `type` is `ecrecover`, or approve the
194
+ * root and call `SetterRatifier.ratify` when `type` is `setter`.
195
195
  *
196
196
  * @param params.bytecode - Maker bytecode returned by `eth_getCode`.
197
197
  * @param params.ecrecoverRatifier - Ratifier address used for EOAs and EIP-7702 accounts.
@@ -199,9 +199,9 @@ var RatifierUtils;
199
199
  * @returns Ratifier information for the maker.
200
200
  * @example
201
201
  * ```ts
202
- * import { RatifierUtils } from "@morpho-org/midnight-sdk";
202
+ * import { Ratifier } from "@morpho-org/midnight-sdk";
203
203
  *
204
- * const info = RatifierUtils.getRatifierInfo({
204
+ * const info = Ratifier.getRatifierInfo({
205
205
  * bytecode: "0x",
206
206
  * ecrecoverRatifier: "0x0000000000000000000000000000000000000001",
207
207
  * setterRatifier: "0x0000000000000000000000000000000000000002",
@@ -220,5 +220,5 @@ var RatifierUtils;
220
220
  }
221
221
  return { type: "setter", ratifier: setterRatifier };
222
222
  }
223
- RatifierUtils.getRatifierInfo = getRatifierInfo;
224
- })(RatifierUtils || (exports.RatifierUtils = RatifierUtils = {}));
223
+ Ratifier.getRatifierInfo = getRatifierInfo;
224
+ })(Ratifier || (exports.RatifierUtils = exports.Ratifier = Ratifier = {}));
@@ -2,7 +2,9 @@ import { type BigIntish } from "@morpho-org/morpho-ts";
2
2
  import { type Hash, type Hex } 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 { SetterRatifierDataRequest, SetterRatifierRatifyRequest } from "./ratifierRequests.js";
6
+ import type { RatifierTreeInput } from "./TreeUtils.js";
7
+ import { type TreeProof } from "./TreeUtils.js";
6
8
  /**
7
9
  * Decoded SetterRatifier ratifier data.
8
10
  *
@@ -68,6 +70,7 @@ export type DecodedSetterRatifierData = TreeProof;
68
70
  * };
69
71
  * console.log(params.leafIndex);
70
72
  * ```
73
+ * @deprecated Use {@link SetterRatifierDataRequest} with {@link SetterRatifier}.
71
74
  */
72
75
  export interface SetterRatifierDataParams {
73
76
  /** Tree-like input that produced the proof. Existing `Tree` instances reuse cached hashes and proofs. */
@@ -99,6 +102,7 @@ export interface SetterRatifierDataVerificationParams {
99
102
  *
100
103
  * console.log(typeof SetterRatifierUtils.encodeRatifierData);
101
104
  * ```
105
+ * @deprecated Use {@link SetterRatifier} with a tagged tree.
102
106
  */
103
107
  export declare namespace SetterRatifierUtils {
104
108
  /**
@@ -155,7 +159,7 @@ export declare namespace SetterRatifierUtils {
155
159
  /**
156
160
  * Verifies that Setter ratifier data proves one payload offer belongs to its root.
157
161
  *
158
- * This helper intentionally does not check `SetterRatifier.isRootRatified` or
162
+ * This helper intentionally does not check `SetterRatifierUtils.isRootRatified` or
159
163
  * `Midnight.isAuthorized` state. Consumers can query those values at their
160
164
  * own block context after local proof verification.
161
165
  *
@@ -189,7 +193,7 @@ export declare namespace SetterRatifierUtils {
189
193
  * @throws {InvalidTreeError} when the leaf index is outside the tree or the tree contains multiple ratifiers.
190
194
  * @example
191
195
  * ```ts
192
- * import { Offer, SetterRatifierUtils, Tree } from "@morpho-org/midnight-sdk";
196
+ * import { Offer, SetterRatifier, Tree } from "@morpho-org/midnight-sdk";
193
197
  * import { zeroAddress } from "viem";
194
198
  *
195
199
  * const offer = Offer.create({
@@ -280,3 +284,46 @@ export declare namespace SetterRatifierUtils {
280
284
  readonly tree: RatifierTreeInput;
281
285
  }): readonly Payload.Item[];
282
286
  }
287
+ /**
288
+ * Tagged-tree API for SetterRatifier with validated portable leaf commitments.
289
+ * Legacy untagged inputs remain available through {@link SetterRatifierUtils}.
290
+ */
291
+ export declare namespace SetterRatifier {
292
+ /**
293
+ * Encodes the proof for one tagged Setter leaf.
294
+ * @param request.tree - Matching tagged tree or portable snapshot; commitments are validated before use.
295
+ * @param request.leafIndex - Leaf to prove.
296
+ * @returns ABI-encoded ratifier data for the requested leaf.
297
+ * @throws {InvalidTreeError} When the tag, commitments, or root are invalid.
298
+ * @throws {InvalidTreeHeightError} When the descriptor height is unsupported.
299
+ * @example
300
+ * ```ts
301
+ * import { SetterRatifier, type SetterRatifierDataRequest } from "@morpho-org/midnight-sdk";
302
+ * function execute(request: SetterRatifierDataRequest) {
303
+ * return SetterRatifier.ratifierData(request);
304
+ * }
305
+ * ```
306
+ */
307
+ function ratifierData(request: SetterRatifierDataRequest): Hex;
308
+ /**
309
+ * Builds payload items for a tagged Setter tree after onchain root approval.
310
+ * @param request.tree - Matching tagged tree or portable snapshot; commitments are validated before use.
311
+ * @returns One payload item per non-padding offer, including its ratifier data.
312
+ * @throws {InvalidTreeError} When the tag, commitments, or root are invalid.
313
+ * @throws {InvalidTreeHeightError} When the descriptor height is unsupported.
314
+ * @example
315
+ * ```ts
316
+ * import { SetterRatifier, type SetterRatifierRatifyRequest } from "@morpho-org/midnight-sdk";
317
+ * function execute(request: SetterRatifierRatifyRequest) {
318
+ * return SetterRatifier.ratify(request);
319
+ * }
320
+ * ```
321
+ */
322
+ function ratify(request: SetterRatifierRatifyRequest): readonly Payload.Item[];
323
+ /** {@inheritDoc SetterRatifierUtils.encodeRatifierData} */
324
+ const encodeRatifierData: typeof SetterRatifierUtils.encodeRatifierData;
325
+ /** {@inheritDoc SetterRatifierUtils.decodeRatifierData} */
326
+ const decodeRatifierData: typeof SetterRatifierUtils.decodeRatifierData;
327
+ /** {@inheritDoc SetterRatifierUtils.verifyRatifierData} */
328
+ const verifyRatifierData: typeof SetterRatifierUtils.verifyRatifierData;
329
+ }
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SetterRatifierUtils = void 0;
3
+ exports.SetterRatifier = exports.SetterRatifierUtils = void 0;
4
4
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
5
5
  const viem_1 = require("viem");
6
6
  const errors_js_1 = require("../errors.js");
7
7
  const index_js_1 = require("../offers/index.js");
8
- const RatifierUtils_js_1 = require("./RatifierUtils.js");
8
+ const Ratifier_js_1 = require("./Ratifier.js");
9
+ const standardRatifierInternal_js_1 = require("./standardRatifierInternal.js");
9
10
  const TreeUtils_js_1 = require("./TreeUtils.js");
10
11
  const setterRatifierDataAbi = [
11
12
  { name: "root", type: "bytes32" },
@@ -29,6 +30,7 @@ const setterRatifierDataAbi = [
29
30
  *
30
31
  * console.log(typeof SetterRatifierUtils.encodeRatifierData);
31
32
  * ```
33
+ * @deprecated Use {@link SetterRatifier} with a tagged tree.
32
34
  */
33
35
  var SetterRatifierUtils;
34
36
  (function (SetterRatifierUtils) {
@@ -93,7 +95,7 @@ var SetterRatifierUtils;
93
95
  /**
94
96
  * Verifies that Setter ratifier data proves one payload offer belongs to its root.
95
97
  *
96
- * This helper intentionally does not check `SetterRatifier.isRootRatified` or
98
+ * This helper intentionally does not check `SetterRatifierUtils.isRootRatified` or
97
99
  * `Midnight.isAuthorized` state. Consumers can query those values at their
98
100
  * own block context after local proof verification.
99
101
  *
@@ -140,7 +142,7 @@ var SetterRatifierUtils;
140
142
  * @throws {InvalidTreeError} when the leaf index is outside the tree or the tree contains multiple ratifiers.
141
143
  * @example
142
144
  * ```ts
143
- * import { Offer, SetterRatifierUtils, Tree } from "@morpho-org/midnight-sdk";
145
+ * import { Offer, SetterRatifier, Tree } from "@morpho-org/midnight-sdk";
144
146
  * import { zeroAddress } from "viem";
145
147
  *
146
148
  * const offer = Offer.create({
@@ -176,7 +178,7 @@ var SetterRatifierUtils;
176
178
  * ```
177
179
  */
178
180
  function ratifierData(params) {
179
- const { tree } = RatifierUtils_js_1.RatifierUtils.normalizeRatifierTree({
181
+ const { tree } = Ratifier_js_1.Ratifier.normalizeRatifierTree({
180
182
  tree: params.tree,
181
183
  label: "Setter",
182
184
  });
@@ -240,14 +242,70 @@ var SetterRatifierUtils;
240
242
  * ```
241
243
  */
242
244
  function ratify(params) {
243
- const { tree } = RatifierUtils_js_1.RatifierUtils.normalizeRatifierTree({
245
+ const { tree } = Ratifier_js_1.Ratifier.normalizeRatifierTree({
244
246
  tree: params.tree,
245
247
  label: "Setter",
246
248
  });
249
+ const proofs = TreeUtils_js_1.TreeUtils.buildProofs({
250
+ tree,
251
+ count: tree.offers.length,
252
+ });
247
253
  return tree.offers.map((offer, leafIndex) => ({
248
254
  offer,
249
- ratifierData: encodeRatifierData(TreeUtils_js_1.TreeUtils.buildProof({ tree, leafIndex })),
255
+ ratifierData: encodeRatifierData(proofs[leafIndex]),
250
256
  }));
251
257
  }
252
258
  SetterRatifierUtils.ratify = ratify;
253
259
  })(SetterRatifierUtils || (exports.SetterRatifierUtils = SetterRatifierUtils = {}));
260
+ /**
261
+ * Tagged-tree API for SetterRatifier with validated portable leaf commitments.
262
+ * Legacy untagged inputs remain available through {@link SetterRatifierUtils}.
263
+ */
264
+ var SetterRatifier;
265
+ (function (SetterRatifier) {
266
+ /**
267
+ * Encodes the proof for one tagged Setter leaf.
268
+ * @param request.tree - Matching tagged tree or portable snapshot; commitments are validated before use.
269
+ * @param request.leafIndex - Leaf to prove.
270
+ * @returns ABI-encoded ratifier data for the requested leaf.
271
+ * @throws {InvalidTreeError} When the tag, commitments, or root are invalid.
272
+ * @throws {InvalidTreeHeightError} When the descriptor height is unsupported.
273
+ * @example
274
+ * ```ts
275
+ * import { SetterRatifier, type SetterRatifierDataRequest } from "@morpho-org/midnight-sdk";
276
+ * function execute(request: SetterRatifierDataRequest) {
277
+ * return SetterRatifier.ratifierData(request);
278
+ * }
279
+ * ```
280
+ */
281
+ function ratifierData(request) {
282
+ const tree = (0, standardRatifierInternal_js_1.parseStandardRatifierTree)(request.tree, "setter");
283
+ return SetterRatifierUtils.ratifierData({ ...request, tree });
284
+ }
285
+ SetterRatifier.ratifierData = ratifierData;
286
+ /**
287
+ * Builds payload items for a tagged Setter tree after onchain root approval.
288
+ * @param request.tree - Matching tagged tree or portable snapshot; commitments are validated before use.
289
+ * @returns One payload item per non-padding offer, including its ratifier data.
290
+ * @throws {InvalidTreeError} When the tag, commitments, or root are invalid.
291
+ * @throws {InvalidTreeHeightError} When the descriptor height is unsupported.
292
+ * @example
293
+ * ```ts
294
+ * import { SetterRatifier, type SetterRatifierRatifyRequest } from "@morpho-org/midnight-sdk";
295
+ * function execute(request: SetterRatifierRatifyRequest) {
296
+ * return SetterRatifier.ratify(request);
297
+ * }
298
+ * ```
299
+ */
300
+ function ratify(request) {
301
+ const tree = (0, standardRatifierInternal_js_1.parseStandardRatifierTree)(request.tree, "setter");
302
+ return SetterRatifierUtils.ratify({ ...request, tree });
303
+ }
304
+ SetterRatifier.ratify = ratify;
305
+ /** {@inheritDoc SetterRatifierUtils.encodeRatifierData} */
306
+ SetterRatifier.encodeRatifierData = SetterRatifierUtils.encodeRatifierData;
307
+ /** {@inheritDoc SetterRatifierUtils.decodeRatifierData} */
308
+ SetterRatifier.decodeRatifierData = SetterRatifierUtils.decodeRatifierData;
309
+ /** {@inheritDoc SetterRatifierUtils.verifyRatifierData} */
310
+ SetterRatifier.verifyRatifierData = SetterRatifierUtils.verifyRatifierData;
311
+ })(SetterRatifier || (exports.SetterRatifier = SetterRatifier = {}));
@@ -1,15 +1,17 @@
1
- import type { BigIntish } from "@morpho-org/morpho-ts";
1
+ import { type BigIntish } from "@morpho-org/morpho-ts";
2
2
  import type { Hash } from "viem";
3
3
  import type { MempoolPayloadValidationSuccess } from "../api/types.js";
4
4
  import { Offer, type OfferStruct } from "../offers/index.js";
5
- import { type TreeCreateParams, type TreeInput, type TreeMempoolValidateParams, type TreeProof } from "./TreeUtils.js";
5
+ import { type TreeCreateParams, type TreeInput, type TreeProof } from "./TreeUtils.js";
6
+ import type { AnyTree, AnyTreeSnapshot, RatifierKind, TreeCreateRequest, TreeEntry, TreeSnapshot, TypedTreeMempoolValidateParams } from "./treeTypes.js";
6
7
  export type { RatifierTreeInput, TreeCreateParams, TreeDescriptor, TreeInput, TreeLike, TreeMempoolValidateParams, TreeMempoolValidateRatification, TreeProof, } from "./TreeUtils.js";
7
8
  /**
8
9
  * Maker-side Merkle tree used by Midnight ratifiers.
9
10
  *
10
11
  * Build a tree after offers have been created and related offers have been
11
12
  * grouped. The tree root is what Ecrecover makers sign, Setter makers approve,
12
- * and payload items later prove with per-leaf ratifier data.
13
+ * and payload items later prove with per-leaf ratifier data. Price/Rate V1
14
+ * trees carry their additional leaf commitments and use onchain root approval.
13
15
  *
14
16
  * @example
15
17
  * ```ts
@@ -41,16 +43,20 @@ export type { RatifierTreeInput, TreeCreateParams, TreeDescriptor, TreeInput, Tr
41
43
  * ratifier: "0x0000000000000000000000000000000000004000",
42
44
  * maxUnits: 100n,
43
45
  * });
44
- * const tree = Tree.create([offer]);
46
+ * const tree = Tree.create({ type: "ecrecover", entries: [offer] });
45
47
  * console.log(tree.root);
46
48
  * ```
47
49
  */
48
- export declare class Tree {
50
+ export declare class Tree<K extends RatifierKind | undefined = undefined> {
51
+ /** Explicit route, or undefined for a legacy standard tree. */
52
+ readonly type: K;
53
+ /** Complete padded leaf commitments for this route. */
54
+ readonly entries: readonly TreeEntry<K>[];
49
55
  /** Non-padding offers in leaf order. */
50
56
  readonly offers: readonly Offer[];
51
57
  /** ABI-compatible offers in leaf order, including protocol-zero padding. */
52
58
  readonly paddedOffers: readonly OfferStruct[];
53
- /** Leaf hashes for `paddedOffers`. */
59
+ /** Leaf hashes for the complete padded `entries`. */
54
60
  readonly leaves: readonly Hash[];
55
61
  /** Merkle root. */
56
62
  readonly root: Hash;
@@ -68,6 +74,8 @@ export declare class Tree {
68
74
  * @returns Tree instance.
69
75
  * @throws {InvalidTreeError} when the tree is empty, all padding, or duplicated.
70
76
  * @throws {InvalidTreeHeightError} when the resulting height is unsupported.
77
+ * @throws {InvalidRateRatifierV1RateError} when a Rate leaf has a negative rate.
78
+ * @throws {InvalidRateRatifierV1TickError} when a Rate leaf offer tick is below `RateRatifierV1.MIN_TICK`.
71
79
  * @example
72
80
  * ```ts
73
81
  * import { Offer, Tree } from "@morpho-org/midnight-sdk";
@@ -98,24 +106,43 @@ export declare class Tree {
98
106
  * ratifier: "0x0000000000000000000000000000000000004000",
99
107
  * maxUnits: 100n,
100
108
  * });
101
- * const tree = Tree.from([offer]);
109
+ * const tree = Tree.from({ type: "ecrecover", entries: [offer] });
102
110
  * console.log(tree.root);
103
111
  * ```
104
112
  */
113
+ static from<T extends AnyTree | AnyTreeSnapshot | TreeCreateRequest>(tree: T): Extract<AnyTree, {
114
+ readonly type: T["type"];
115
+ }>;
116
+ /**
117
+ * Resolves an untagged standard tree or legacy creation input.
118
+ * @deprecated Pass a tagged TreeCreateRequest or a route-typed Tree instead.
119
+ * @param tree - Legacy tree, offer, group, or array of entries.
120
+ * @returns Untagged standard tree.
121
+ * @throws {InvalidTreeError} When entries are empty, all padding, or duplicated.
122
+ * @throws {InvalidTreeHeightError} When the tree height is unsupported.
123
+ * @example
124
+ * ```ts
125
+ * import { Tree, type TreeInput } from "@morpho-org/midnight-sdk";
126
+ * function legacyTree(input: TreeInput) { return Tree.from(input); }
127
+ * ```
128
+ */
105
129
  static from(tree: TreeInput): Tree;
106
130
  /**
107
- * Creates a tree from groups or standalone offers.
131
+ * Creates a route-typed tree from standard offer/groups or Price/Rate leaf inputs.
108
132
  *
109
133
  * Use after `Offer.create` and optional `Group.create`, before
110
- * `Tree.mempoolValidate`, `EcrecoverRatifierUtils.ratify`, or
111
- * `SetterRatifierUtils.ratify`. Groups are flattened, and every standalone
134
+ * `Tree.mempoolValidate`, `EcrecoverRatifier.ratify`, or
135
+ * `SetterRatifier.ratify`. Groups are flattened, and every standalone
112
136
  * offer is normalized as a singleton group using the router-compatible group
113
137
  * id algorithm.
114
138
  *
115
- * @param params - Groups or standalone offers in leaf order.
116
- * @returns Tree instance.
139
+ * @param params.type - Ratifier route selecting the leaf commitment format.
140
+ * @param params.entries - Standard offer/groups or route-specific leaves in leaf order.
141
+ * @returns A tree whose entries and validation options are inferred from the route.
117
142
  * @throws {InvalidTreeError} when the tree is empty, all padding, or duplicated.
118
143
  * @throws {InvalidTreeHeightError} when the resulting height is unsupported.
144
+ * @throws {InvalidRateRatifierV1RateError} when a Rate leaf has a negative rate.
145
+ * @throws {InvalidRateRatifierV1TickError} when a Rate leaf offer tick is below `RateRatifierV1.MIN_TICK`.
119
146
  * @example
120
147
  * ```ts
121
148
  * import { Offer, Tree } from "@morpho-org/midnight-sdk";
@@ -146,11 +173,58 @@ export declare class Tree {
146
173
  * ratifier: "0x0000000000000000000000000000000000004000",
147
174
  * maxUnits: 100n,
148
175
  * });
149
- * const tree = Tree.create([offer]);
176
+ * const tree = Tree.create({ type: "ecrecover", entries: [offer] });
150
177
  * console.log(tree.height);
151
178
  * ```
152
179
  */
180
+ static create<R extends TreeCreateRequest>(params: R): Extract<AnyTree, {
181
+ readonly type: R["type"];
182
+ }>;
183
+ /**
184
+ * Creates a legacy tree compatible with Ecrecover and Setter.
185
+ * @deprecated Pass `{ type, entries }` to select a ratifier explicitly.
186
+ * @param params - Standard offer/group inputs.
187
+ * @returns Untagged standard tree.
188
+ * @throws {InvalidTreeError} when the tree is empty, all padding, or duplicated.
189
+ * @throws {InvalidTreeHeightError} when the resulting height is unsupported.
190
+ * @example
191
+ * ```ts
192
+ * import { Tree, type IOffer } from "@morpho-org/midnight-sdk";
193
+ * function legacyTree(offers: readonly IOffer[]) { return Tree.create(offers); }
194
+ * ```
195
+ */
153
196
  static create(params: TreeCreateParams): Tree;
197
+ /**
198
+ * Exports plain normalized data for transport; does not claim root authorization.
199
+ * @returns Descriptor with the same route and padded commitments.
200
+ * @example
201
+ * ```ts
202
+ * import { Tree, type IOffer } from "@morpho-org/midnight-sdk";
203
+ * function prepare(offers: readonly IOffer[]) {
204
+ * return Tree.create({ type: "setter", entries: offers }).toDescriptor();
205
+ * }
206
+ * ```
207
+ */
208
+ toDescriptor(): TreeSnapshot<K>;
209
+ /**
210
+ * Validates portable data before constructing a tree. Hashes and padding are checked again.
211
+ * @param descriptor - Tagged descriptor, or legacy untagged snapshot.
212
+ * @returns A new tree with the descriptor's route.
213
+ * @throws {InvalidTreeError} When entries, offers, padding, hashes or root disagree.
214
+ * @throws {InvalidTreeHeightError} When height is unsupported.
215
+ * @throws {InvalidRateRatifierV1TickError} when a rateV1 snapshot entry's offer tick is below `RateRatifierV1.MIN_TICK`.
216
+ * @example
217
+ * ```ts
218
+ * import { Tree, type TreeSnapshot } from "@morpho-org/midnight-sdk";
219
+ * function resume(snapshot: TreeSnapshot<"rateV1">) {
220
+ * return Tree.fromDescriptor(snapshot); // Tree<"rateV1">
221
+ * }
222
+ * ```
223
+ */
224
+ static fromDescriptor<D extends AnyTreeSnapshot>(descriptor: D): Extract<AnyTree, {
225
+ readonly type: D["type"];
226
+ }>;
227
+ static fromDescriptor(descriptor: TreeSnapshot<undefined>): Tree;
154
228
  /**
155
229
  * Validates this tree against Midnight mempool API policy.
156
230
  *
@@ -158,15 +232,18 @@ export declare class Tree {
158
232
  * with empty `ratifierData`, then sends the temporary payload to the Midnight
159
233
  * API `POST /mempool/validate` endpoint. Pass `ratification` after signing or
160
234
  * Setter root preparation to validate final payload bytes with real
161
- * `ratifierData`.
235
+ * `ratifierData`. Price/Rate V1 routes always post their real ratifier data
236
+ * because the router decodes it to identify each offer; their
237
+ * `ratification` only asserts the route.
162
238
  *
163
239
  * @param params.chainId - Chain id whose API policy should validate this tree.
164
240
  * @param params.apiUrl - Optional Midnight API URL override used for the validation HTTP request.
165
241
  * @param params.timestamp - Optional ISO-8601 timestamp or `Date` selecting the API policy snapshot.
166
242
  * @param params.fetch - Optional fetch implementation override used for the API call.
167
243
  * @param params.request - Optional fetch options forwarded to the API request.
168
- * @param params.ratification - Optional ratification inputs used to validate final payload bytes with real ratifier data.
244
+ * @param params.ratification - Optional route-matching authorization inputs; Price/Rate routes require their root to have been approved onchain.
169
245
  * @returns Successful API validation result with `valid: true`.
246
+ * @throws {InvalidTreeError} when the ratification route differs from the tree route.
170
247
  * @throws {PayloadDecodeError} when validation payload encoding fails.
171
248
  * @throws {MidnightApiError} when the API returns a non-2xx response.
172
249
  * @throws {InvalidMidnightApiResponseError} when the API returns malformed success JSON.
@@ -201,12 +278,12 @@ export declare class Tree {
201
278
  * ratifier: "0x0000000000000000000000000000000000004000",
202
279
  * maxUnits: 100n,
203
280
  * });
204
- * await Tree.create([offer]).mempoolValidate({
281
+ * await Tree.create({ type: "ecrecover", entries: [offer] }).mempoolValidate({
205
282
  * chainId: 8453,
206
283
  * });
207
284
  * ```
208
285
  */
209
- mempoolValidate(params: TreeMempoolValidateParams): Promise<MempoolPayloadValidationSuccess>;
286
+ mempoolValidate(params: TypedTreeMempoolValidateParams<K>): Promise<MempoolPayloadValidationSuccess>;
210
287
  /**
211
288
  * Builds a Merkle proof for one leaf.
212
289
  *