@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.
- package/README.md +61 -61
- package/lib/cjs/abis.d.ts +794 -0
- package/lib/cjs/abis.js +502 -1
- package/lib/cjs/api/version.generated.d.ts +1 -1
- package/lib/cjs/api/version.generated.js +2 -2
- package/lib/cjs/constants.d.ts +34 -0
- package/lib/cjs/constants.js +35 -1
- package/lib/cjs/errors.d.ts +107 -0
- package/lib/cjs/errors.js +139 -1
- package/lib/cjs/fetch/Ratifier.d.ts +4 -3
- package/lib/cjs/fetch/Ratifier.js +5 -4
- package/lib/cjs/index.d.ts +7 -0
- package/lib/cjs/index.js +16 -1
- package/lib/cjs/offers/Offer.d.ts +10 -0
- package/lib/cjs/offers/Offer.js +15 -1
- package/lib/cjs/offers/OfferUtils.d.ts +3 -0
- package/lib/cjs/offers/OfferUtils.js +3 -0
- package/lib/cjs/signatures/{EcrecoverRatifierUtils.d.ts → EcrecoverRatifier.d.ts} +118 -2
- package/lib/cjs/signatures/{EcrecoverRatifierUtils.js → EcrecoverRatifier.js} +146 -9
- package/lib/cjs/signatures/GroupUtils.d.ts +55 -2
- package/lib/cjs/signatures/GroupUtils.js +64 -5
- package/lib/cjs/signatures/Payload.d.ts +3 -3
- package/lib/cjs/signatures/PriceRatifierV1.d.ts +472 -0
- package/lib/cjs/signatures/PriceRatifierV1.js +521 -0
- package/lib/cjs/signatures/RateRatifierV1.d.ts +581 -0
- package/lib/cjs/signatures/RateRatifierV1.js +696 -0
- package/lib/{esm/signatures/RatifierUtils.d.ts → cjs/signatures/Ratifier.d.ts} +14 -12
- package/lib/cjs/signatures/{RatifierUtils.js → Ratifier.js} +29 -29
- package/lib/cjs/signatures/{SetterRatifierUtils.d.ts → SetterRatifier.d.ts} +50 -3
- package/lib/cjs/signatures/{SetterRatifierUtils.js → SetterRatifier.js} +65 -7
- package/lib/cjs/signatures/Tree.d.ts +94 -17
- package/lib/cjs/signatures/Tree.js +146 -111
- package/lib/cjs/signatures/TreeUtils.d.ts +191 -21
- package/lib/cjs/signatures/TreeUtils.js +320 -134
- package/lib/cjs/signatures/index.d.ts +7 -3
- package/lib/cjs/signatures/index.js +5 -3
- package/lib/cjs/signatures/ratifierRequests.d.ts +55 -0
- package/lib/cjs/signatures/ratifierRequests.js +2 -0
- package/lib/cjs/signatures/ratifierV1Internal.d.ts +57 -0
- package/lib/cjs/signatures/ratifierV1Internal.js +183 -0
- package/lib/cjs/signatures/standardRatifierInternal.d.ts +4 -0
- package/lib/cjs/signatures/standardRatifierInternal.js +12 -0
- package/lib/cjs/signatures/treeMathInternal.d.ts +4 -0
- package/lib/cjs/signatures/treeMathInternal.js +12 -0
- package/lib/cjs/signatures/treeTypes.d.ts +109 -0
- package/lib/cjs/signatures/treeTypes.js +2 -0
- package/lib/esm/abis.d.ts +794 -0
- package/lib/esm/abis.js +501 -0
- package/lib/esm/api/version.generated.d.ts +1 -1
- package/lib/esm/api/version.generated.js +2 -2
- package/lib/esm/constants.d.ts +34 -0
- package/lib/esm/constants.js +34 -0
- package/lib/esm/errors.d.ts +107 -0
- package/lib/esm/errors.js +132 -0
- package/lib/esm/fetch/Ratifier.d.ts +4 -3
- package/lib/esm/fetch/Ratifier.js +5 -4
- package/lib/esm/index.d.ts +7 -0
- package/lib/esm/index.js +5 -0
- package/lib/esm/offers/Offer.d.ts +10 -0
- package/lib/esm/offers/Offer.js +15 -1
- package/lib/esm/offers/OfferUtils.d.ts +3 -0
- package/lib/esm/offers/OfferUtils.js +3 -0
- package/lib/esm/signatures/{EcrecoverRatifierUtils.d.ts → EcrecoverRatifier.d.ts} +118 -2
- package/lib/esm/signatures/{EcrecoverRatifierUtils.js → EcrecoverRatifier.js} +146 -9
- package/lib/esm/signatures/GroupUtils.d.ts +55 -2
- package/lib/esm/signatures/GroupUtils.js +64 -5
- package/lib/esm/signatures/Payload.d.ts +3 -3
- package/lib/esm/signatures/PriceRatifierV1.d.ts +472 -0
- package/lib/esm/signatures/PriceRatifierV1.js +520 -0
- package/lib/esm/signatures/RateRatifierV1.d.ts +581 -0
- package/lib/esm/signatures/RateRatifierV1.js +695 -0
- package/lib/{cjs/signatures/RatifierUtils.d.ts → esm/signatures/Ratifier.d.ts} +14 -12
- package/lib/esm/signatures/{RatifierUtils.js → Ratifier.js} +31 -29
- package/lib/esm/signatures/{SetterRatifierUtils.d.ts → SetterRatifier.d.ts} +50 -3
- package/lib/esm/signatures/{SetterRatifierUtils.js → SetterRatifier.js} +65 -7
- package/lib/esm/signatures/Tree.d.ts +94 -17
- package/lib/esm/signatures/Tree.js +147 -112
- package/lib/esm/signatures/TreeUtils.d.ts +191 -21
- package/lib/esm/signatures/TreeUtils.js +318 -132
- package/lib/esm/signatures/index.d.ts +7 -3
- package/lib/esm/signatures/index.js +5 -3
- package/lib/esm/signatures/ratifierRequests.d.ts +55 -0
- package/lib/esm/signatures/ratifierRequests.js +1 -0
- package/lib/esm/signatures/ratifierV1Internal.d.ts +57 -0
- package/lib/esm/signatures/ratifierV1Internal.js +176 -0
- package/lib/esm/signatures/standardRatifierInternal.d.ts +4 -0
- package/lib/esm/signatures/standardRatifierInternal.js +9 -0
- package/lib/esm/signatures/treeMathInternal.d.ts +4 -0
- package/lib/esm/signatures/treeMathInternal.js +8 -0
- package/lib/esm/signatures/treeTypes.d.ts +109 -0
- package/lib/esm/signatures/treeTypes.js +1 -0
- package/package.json +4 -4
|
@@ -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
|
|
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 {
|
|
63
|
+
* import { Ratifier } from "@morpho-org/midnight-sdk";
|
|
64
64
|
*
|
|
65
|
-
* console.log(
|
|
65
|
+
* console.log(Ratifier.isEip7702Designator("0xef0100"));
|
|
66
66
|
* ```
|
|
67
67
|
*/
|
|
68
|
-
export declare namespace
|
|
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,
|
|
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 } =
|
|
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 {
|
|
135
|
+
* import { Ratifier } from "@morpho-org/midnight-sdk";
|
|
136
136
|
*
|
|
137
|
-
* console.log(
|
|
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
|
-
* `
|
|
147
|
-
* root and call `
|
|
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 {
|
|
155
|
+
* import { Ratifier } from "@morpho-org/midnight-sdk";
|
|
156
156
|
*
|
|
157
|
-
* const info =
|
|
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,9 +1,9 @@
|
|
|
1
|
+
import { MAX_TREE_HEIGHT } from "../constants.js";
|
|
1
2
|
import { InvalidTreeError, InvalidTreeHeightError } from "../errors.js";
|
|
2
|
-
import {
|
|
3
|
-
import { Group } from "./Group.js";
|
|
4
|
-
import { GroupUtils } from "./GroupUtils.js";
|
|
3
|
+
import { OfferUtils } from "../offers/index.js";
|
|
5
4
|
import { isEmptyOfferStruct } from "./offerStructInternal.js";
|
|
6
5
|
import { TreeUtils } from "./TreeUtils.js";
|
|
6
|
+
import { nextPowerOfTwo } from "./treeMathInternal.js";
|
|
7
7
|
function isTreeLike(tree) {
|
|
8
8
|
return (!Array.isArray(tree) &&
|
|
9
9
|
"offers" in tree &&
|
|
@@ -14,13 +14,15 @@ function isTreeLike(tree) {
|
|
|
14
14
|
}
|
|
15
15
|
function normalizeTree(tree) {
|
|
16
16
|
if (isTreeLike(tree)) {
|
|
17
|
-
if (!Number.isInteger(tree.height) ||
|
|
17
|
+
if (!Number.isInteger(tree.height) ||
|
|
18
|
+
tree.height < 0 ||
|
|
19
|
+
tree.height > MAX_TREE_HEIGHT) {
|
|
18
20
|
throw new InvalidTreeHeightError(tree.height);
|
|
19
21
|
}
|
|
20
22
|
const expectedLength = 2 ** tree.height;
|
|
21
23
|
if (tree.paddedOffers.length !== expectedLength ||
|
|
22
24
|
tree.leaves.length !== expectedLength ||
|
|
23
|
-
tree.offers.length
|
|
25
|
+
expectedLength !== nextPowerOfTwo(tree.offers.length)) {
|
|
24
26
|
throw new InvalidTreeError("Tree offers, leaves, and height describe different trees.");
|
|
25
27
|
}
|
|
26
28
|
const computedLeaves = tree.paddedOffers.map(OfferUtils.hashStruct);
|
|
@@ -60,14 +62,7 @@ function normalizeTree(tree) {
|
|
|
60
62
|
return tree;
|
|
61
63
|
}
|
|
62
64
|
const entries = Array.isArray(tree) ? tree : [tree];
|
|
63
|
-
const offers =
|
|
64
|
-
? Group.from(entry).offers
|
|
65
|
-
: [
|
|
66
|
-
new Offer({
|
|
67
|
-
...Offer.from(entry),
|
|
68
|
-
group: GroupUtils.hash([entry]),
|
|
69
|
-
}),
|
|
70
|
-
]);
|
|
65
|
+
const offers = TreeUtils.normalizeEntries(entries);
|
|
71
66
|
const descriptor = TreeUtils.buildDescriptor(entries);
|
|
72
67
|
return {
|
|
73
68
|
offers,
|
|
@@ -101,13 +96,13 @@ function assertRatifierTree(params) {
|
|
|
101
96
|
*
|
|
102
97
|
* @example
|
|
103
98
|
* ```ts
|
|
104
|
-
* import {
|
|
99
|
+
* import { Ratifier } from "@morpho-org/midnight-sdk";
|
|
105
100
|
*
|
|
106
|
-
* console.log(
|
|
101
|
+
* console.log(Ratifier.isEip7702Designator("0xef0100"));
|
|
107
102
|
* ```
|
|
108
103
|
*/
|
|
109
|
-
export var
|
|
110
|
-
(function (
|
|
104
|
+
export var Ratifier;
|
|
105
|
+
(function (Ratifier) {
|
|
111
106
|
/**
|
|
112
107
|
* Normalizes a ratifier tree input and asserts it uses one ratifier address.
|
|
113
108
|
*
|
|
@@ -122,7 +117,7 @@ export var RatifierUtils;
|
|
|
122
117
|
* @throws {InvalidTreeHeightError} when the tree height is unsupported.
|
|
123
118
|
* @example
|
|
124
119
|
* ```ts
|
|
125
|
-
* import { Offer,
|
|
120
|
+
* import { Offer, Ratifier } from "@morpho-org/midnight-sdk";
|
|
126
121
|
* import { zeroAddress } from "viem";
|
|
127
122
|
*
|
|
128
123
|
* const offer = Offer.create({
|
|
@@ -150,7 +145,7 @@ export var RatifierUtils;
|
|
|
150
145
|
* ratifier: "0x0000000000000000000000000000000000004000",
|
|
151
146
|
* maxUnits: 100n,
|
|
152
147
|
* });
|
|
153
|
-
* const { tree, ratifier } =
|
|
148
|
+
* const { tree, ratifier } = Ratifier.normalizeRatifierTree({
|
|
154
149
|
* tree: [offer],
|
|
155
150
|
* label: "Ecrecover",
|
|
156
151
|
* });
|
|
@@ -158,11 +153,16 @@ export var RatifierUtils;
|
|
|
158
153
|
* ```
|
|
159
154
|
*/
|
|
160
155
|
function normalizeRatifierTree(params) {
|
|
156
|
+
if ("type" in params.tree &&
|
|
157
|
+
params.tree.type != null &&
|
|
158
|
+
params.tree.type !== params.label.toLowerCase()) {
|
|
159
|
+
throw new InvalidTreeError("Ratifier route does not match the tree route.");
|
|
160
|
+
}
|
|
161
161
|
const tree = normalizeTree(params.tree);
|
|
162
162
|
const ratifier = assertRatifierTree({ tree, label: params.label });
|
|
163
163
|
return { tree, ratifier };
|
|
164
164
|
}
|
|
165
|
-
|
|
165
|
+
Ratifier.normalizeRatifierTree = normalizeRatifierTree;
|
|
166
166
|
/**
|
|
167
167
|
* Checks whether bytecode is an EIP-7702 designator.
|
|
168
168
|
*
|
|
@@ -173,22 +173,22 @@ export var RatifierUtils;
|
|
|
173
173
|
* @returns Whether the bytecode starts with `0xef0100`.
|
|
174
174
|
* @example
|
|
175
175
|
* ```ts
|
|
176
|
-
* import {
|
|
176
|
+
* import { Ratifier } from "@morpho-org/midnight-sdk";
|
|
177
177
|
*
|
|
178
|
-
* console.log(
|
|
178
|
+
* console.log(Ratifier.isEip7702Designator("0xef0100"));
|
|
179
179
|
* ```
|
|
180
180
|
*/
|
|
181
181
|
function isEip7702Designator(bytecode) {
|
|
182
182
|
return bytecode.toLowerCase().startsWith("0xef0100");
|
|
183
183
|
}
|
|
184
|
-
|
|
184
|
+
Ratifier.isEip7702Designator = isEip7702Designator;
|
|
185
185
|
/**
|
|
186
186
|
* Selects Ecrecover for EOAs/EIP-7702 accounts and Setter for deployed-code
|
|
187
187
|
* accounts.
|
|
188
188
|
*
|
|
189
189
|
* Use the returned `ratifier` address in `Offer.create`. Later, use
|
|
190
|
-
* `
|
|
191
|
-
* root and call `
|
|
190
|
+
* `EcrecoverRatifier.ratify` when `type` is `ecrecover`, or approve the
|
|
191
|
+
* root and call `SetterRatifier.ratify` when `type` is `setter`.
|
|
192
192
|
*
|
|
193
193
|
* @param params.bytecode - Maker bytecode returned by `eth_getCode`.
|
|
194
194
|
* @param params.ecrecoverRatifier - Ratifier address used for EOAs and EIP-7702 accounts.
|
|
@@ -196,9 +196,9 @@ export var RatifierUtils;
|
|
|
196
196
|
* @returns Ratifier information for the maker.
|
|
197
197
|
* @example
|
|
198
198
|
* ```ts
|
|
199
|
-
* import {
|
|
199
|
+
* import { Ratifier } from "@morpho-org/midnight-sdk";
|
|
200
200
|
*
|
|
201
|
-
* const info =
|
|
201
|
+
* const info = Ratifier.getRatifierInfo({
|
|
202
202
|
* bytecode: "0x",
|
|
203
203
|
* ecrecoverRatifier: "0x0000000000000000000000000000000000000001",
|
|
204
204
|
* setterRatifier: "0x0000000000000000000000000000000000000002",
|
|
@@ -217,5 +217,7 @@ export var RatifierUtils;
|
|
|
217
217
|
}
|
|
218
218
|
return { type: "setter", ratifier: setterRatifier };
|
|
219
219
|
}
|
|
220
|
-
|
|
221
|
-
})(
|
|
220
|
+
Ratifier.getRatifierInfo = getRatifierInfo;
|
|
221
|
+
})(Ratifier || (Ratifier = {}));
|
|
222
|
+
/** @deprecated Use {@link Ratifier}. Retained for compatibility. */
|
|
223
|
+
export { Ratifier as RatifierUtils };
|
|
@@ -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 {
|
|
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 `
|
|
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,
|
|
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
|
+
}
|
|
@@ -2,8 +2,9 @@ import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
|
2
2
|
import { decodeAbiParameters, encodeAbiParameters, } from "viem";
|
|
3
3
|
import { InvalidTreeError } from "../errors.js";
|
|
4
4
|
import { Offer } from "../offers/index.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { Ratifier } from "./Ratifier.js";
|
|
6
|
+
import { parseStandardRatifierTree } from "./standardRatifierInternal.js";
|
|
7
|
+
import { TreeUtils } from "./TreeUtils.js";
|
|
7
8
|
const setterRatifierDataAbi = [
|
|
8
9
|
{ name: "root", type: "bytes32" },
|
|
9
10
|
{ name: "leafIndex", type: "uint256" },
|
|
@@ -26,6 +27,7 @@ const setterRatifierDataAbi = [
|
|
|
26
27
|
*
|
|
27
28
|
* console.log(typeof SetterRatifierUtils.encodeRatifierData);
|
|
28
29
|
* ```
|
|
30
|
+
* @deprecated Use {@link SetterRatifier} with a tagged tree.
|
|
29
31
|
*/
|
|
30
32
|
export var SetterRatifierUtils;
|
|
31
33
|
(function (SetterRatifierUtils) {
|
|
@@ -90,7 +92,7 @@ export var SetterRatifierUtils;
|
|
|
90
92
|
/**
|
|
91
93
|
* Verifies that Setter ratifier data proves one payload offer belongs to its root.
|
|
92
94
|
*
|
|
93
|
-
* This helper intentionally does not check `
|
|
95
|
+
* This helper intentionally does not check `SetterRatifierUtils.isRootRatified` or
|
|
94
96
|
* `Midnight.isAuthorized` state. Consumers can query those values at their
|
|
95
97
|
* own block context after local proof verification.
|
|
96
98
|
*
|
|
@@ -137,7 +139,7 @@ export var SetterRatifierUtils;
|
|
|
137
139
|
* @throws {InvalidTreeError} when the leaf index is outside the tree or the tree contains multiple ratifiers.
|
|
138
140
|
* @example
|
|
139
141
|
* ```ts
|
|
140
|
-
* import { Offer,
|
|
142
|
+
* import { Offer, SetterRatifier, Tree } from "@morpho-org/midnight-sdk";
|
|
141
143
|
* import { zeroAddress } from "viem";
|
|
142
144
|
*
|
|
143
145
|
* const offer = Offer.create({
|
|
@@ -173,7 +175,7 @@ export var SetterRatifierUtils;
|
|
|
173
175
|
* ```
|
|
174
176
|
*/
|
|
175
177
|
function ratifierData(params) {
|
|
176
|
-
const { tree } =
|
|
178
|
+
const { tree } = Ratifier.normalizeRatifierTree({
|
|
177
179
|
tree: params.tree,
|
|
178
180
|
label: "Setter",
|
|
179
181
|
});
|
|
@@ -237,14 +239,70 @@ export var SetterRatifierUtils;
|
|
|
237
239
|
* ```
|
|
238
240
|
*/
|
|
239
241
|
function ratify(params) {
|
|
240
|
-
const { tree } =
|
|
242
|
+
const { tree } = Ratifier.normalizeRatifierTree({
|
|
241
243
|
tree: params.tree,
|
|
242
244
|
label: "Setter",
|
|
243
245
|
});
|
|
246
|
+
const proofs = TreeUtils.buildProofs({
|
|
247
|
+
tree,
|
|
248
|
+
count: tree.offers.length,
|
|
249
|
+
});
|
|
244
250
|
return tree.offers.map((offer, leafIndex) => ({
|
|
245
251
|
offer,
|
|
246
|
-
ratifierData: encodeRatifierData(
|
|
252
|
+
ratifierData: encodeRatifierData(proofs[leafIndex]),
|
|
247
253
|
}));
|
|
248
254
|
}
|
|
249
255
|
SetterRatifierUtils.ratify = ratify;
|
|
250
256
|
})(SetterRatifierUtils || (SetterRatifierUtils = {}));
|
|
257
|
+
/**
|
|
258
|
+
* Tagged-tree API for SetterRatifier with validated portable leaf commitments.
|
|
259
|
+
* Legacy untagged inputs remain available through {@link SetterRatifierUtils}.
|
|
260
|
+
*/
|
|
261
|
+
export var SetterRatifier;
|
|
262
|
+
(function (SetterRatifier) {
|
|
263
|
+
/**
|
|
264
|
+
* Encodes the proof for one tagged Setter leaf.
|
|
265
|
+
* @param request.tree - Matching tagged tree or portable snapshot; commitments are validated before use.
|
|
266
|
+
* @param request.leafIndex - Leaf to prove.
|
|
267
|
+
* @returns ABI-encoded ratifier data for the requested leaf.
|
|
268
|
+
* @throws {InvalidTreeError} When the tag, commitments, or root are invalid.
|
|
269
|
+
* @throws {InvalidTreeHeightError} When the descriptor height is unsupported.
|
|
270
|
+
* @example
|
|
271
|
+
* ```ts
|
|
272
|
+
* import { SetterRatifier, type SetterRatifierDataRequest } from "@morpho-org/midnight-sdk";
|
|
273
|
+
* function execute(request: SetterRatifierDataRequest) {
|
|
274
|
+
* return SetterRatifier.ratifierData(request);
|
|
275
|
+
* }
|
|
276
|
+
* ```
|
|
277
|
+
*/
|
|
278
|
+
function ratifierData(request) {
|
|
279
|
+
const tree = parseStandardRatifierTree(request.tree, "setter");
|
|
280
|
+
return SetterRatifierUtils.ratifierData({ ...request, tree });
|
|
281
|
+
}
|
|
282
|
+
SetterRatifier.ratifierData = ratifierData;
|
|
283
|
+
/**
|
|
284
|
+
* Builds payload items for a tagged Setter tree after onchain root approval.
|
|
285
|
+
* @param request.tree - Matching tagged tree or portable snapshot; commitments are validated before use.
|
|
286
|
+
* @returns One payload item per non-padding offer, including its ratifier data.
|
|
287
|
+
* @throws {InvalidTreeError} When the tag, commitments, or root are invalid.
|
|
288
|
+
* @throws {InvalidTreeHeightError} When the descriptor height is unsupported.
|
|
289
|
+
* @example
|
|
290
|
+
* ```ts
|
|
291
|
+
* import { SetterRatifier, type SetterRatifierRatifyRequest } from "@morpho-org/midnight-sdk";
|
|
292
|
+
* function execute(request: SetterRatifierRatifyRequest) {
|
|
293
|
+
* return SetterRatifier.ratify(request);
|
|
294
|
+
* }
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
297
|
+
function ratify(request) {
|
|
298
|
+
const tree = parseStandardRatifierTree(request.tree, "setter");
|
|
299
|
+
return SetterRatifierUtils.ratify({ ...request, tree });
|
|
300
|
+
}
|
|
301
|
+
SetterRatifier.ratify = ratify;
|
|
302
|
+
/** {@inheritDoc SetterRatifierUtils.encodeRatifierData} */
|
|
303
|
+
SetterRatifier.encodeRatifierData = SetterRatifierUtils.encodeRatifierData;
|
|
304
|
+
/** {@inheritDoc SetterRatifierUtils.decodeRatifierData} */
|
|
305
|
+
SetterRatifier.decodeRatifierData = SetterRatifierUtils.decodeRatifierData;
|
|
306
|
+
/** {@inheritDoc SetterRatifierUtils.verifyRatifierData} */
|
|
307
|
+
SetterRatifier.verifyRatifierData = SetterRatifierUtils.verifyRatifierData;
|
|
308
|
+
})(SetterRatifier || (SetterRatifier = {}));
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import type
|
|
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
|
|
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 `
|
|
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
|
|
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`, `
|
|
111
|
-
* `
|
|
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 -
|
|
116
|
-
* @
|
|
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
|
|
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:
|
|
286
|
+
mempoolValidate(params: TypedTreeMempoolValidateParams<K>): Promise<MempoolPayloadValidationSuccess>;
|
|
210
287
|
/**
|
|
211
288
|
* Builds a Merkle proof for one leaf.
|
|
212
289
|
*
|