@morpho-org/midnight-sdk 0.1.0 → 1.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.
- package/LICENSE +21 -0
- package/README.md +56 -46
- package/lib/cjs/abis.d.ts +1185 -996
- package/lib/cjs/abis.js +1445 -1211
- package/lib/cjs/api/MidnightApi.d.ts +22 -16
- package/lib/cjs/api/MidnightApi.js +22 -16
- package/lib/cjs/api/helpers.js +6 -3
- package/lib/cjs/api/types.d.ts +35 -9
- package/lib/cjs/constants.d.ts +12 -11
- package/lib/cjs/constants.js +14 -12
- package/lib/cjs/errors.d.ts +74 -1
- package/lib/cjs/errors.js +94 -3
- package/lib/cjs/fetch/Market.js +0 -1
- package/lib/cjs/fetch/index.d.ts +0 -1
- package/lib/cjs/fetch/index.js +0 -1
- package/lib/cjs/index.d.ts +1 -1
- package/lib/cjs/index.js +2 -23
- package/lib/cjs/market/Market.d.ts +99 -33
- package/lib/cjs/market/Market.js +137 -28
- package/lib/cjs/market/MarketUtils.d.ts +61 -41
- package/lib/cjs/market/MarketUtils.js +108 -48
- package/lib/cjs/market/Position.d.ts +16 -11
- package/lib/cjs/market/Position.js +18 -12
- package/lib/cjs/market/PositionUtils.d.ts +6 -4
- package/lib/cjs/market/PositionUtils.js +9 -6
- package/lib/cjs/math/TickLib.d.ts +22 -0
- package/lib/cjs/math/TickLib.js +30 -0
- package/lib/cjs/math/index.d.ts +0 -1
- package/lib/cjs/math/index.js +0 -1
- package/lib/cjs/offers/Offer.d.ts +217 -11
- package/lib/cjs/offers/Offer.js +215 -7
- package/lib/cjs/offers/OfferUtils.d.ts +245 -139
- package/lib/cjs/offers/OfferUtils.js +304 -36
- package/lib/cjs/queries/GetPosition.d.ts +1 -1
- package/lib/cjs/queries/GetPosition.js +1 -1
- package/lib/cjs/signatures/EcrecoverRatifierUtils.d.ts +66 -38
- package/lib/cjs/signatures/EcrecoverRatifierUtils.js +147 -79
- package/lib/cjs/signatures/Group.d.ts +12 -4
- package/lib/cjs/signatures/Group.js +12 -4
- package/lib/cjs/signatures/GroupUtils.d.ts +12 -4
- package/lib/cjs/signatures/GroupUtils.js +6 -2
- package/lib/cjs/signatures/Payload.d.ts +277 -277
- package/lib/cjs/signatures/Payload.js +517 -534
- package/lib/cjs/signatures/RatifierUtils.d.ts +57 -0
- package/lib/cjs/signatures/RatifierUtils.js +94 -0
- package/lib/cjs/signatures/SetterRatifierUtils.d.ts +21 -13
- package/lib/cjs/signatures/SetterRatifierUtils.js +25 -20
- package/lib/cjs/signatures/Tree.d.ts +28 -16
- package/lib/cjs/signatures/Tree.js +25 -13
- package/lib/cjs/signatures/TreeUtils.d.ts +181 -62
- package/lib/cjs/signatures/TreeUtils.js +73 -76
- package/lib/cjs/signatures/index.d.ts +1 -0
- package/lib/cjs/signatures/index.js +3 -0
- package/lib/cjs/signatures/offerStructInternal.d.ts +14 -0
- package/lib/cjs/signatures/offerStructInternal.js +72 -0
- package/lib/esm/abis.d.ts +1185 -996
- package/lib/esm/abis.js +1445 -1211
- package/lib/esm/api/MidnightApi.d.ts +22 -16
- package/lib/esm/api/MidnightApi.js +23 -17
- package/lib/esm/api/helpers.js +6 -3
- package/lib/esm/api/types.d.ts +35 -9
- package/lib/esm/constants.d.ts +12 -11
- package/lib/esm/constants.js +13 -11
- package/lib/esm/errors.d.ts +74 -1
- package/lib/esm/errors.js +89 -2
- package/lib/esm/fetch/Market.js +0 -1
- package/lib/esm/fetch/index.d.ts +0 -1
- package/lib/esm/fetch/index.js +0 -1
- package/lib/esm/index.d.ts +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/esm/market/Market.d.ts +99 -33
- package/lib/esm/market/Market.js +137 -28
- package/lib/esm/market/MarketUtils.d.ts +61 -41
- package/lib/esm/market/MarketUtils.js +109 -49
- package/lib/esm/market/Position.d.ts +16 -11
- package/lib/esm/market/Position.js +19 -13
- package/lib/esm/market/PositionUtils.d.ts +6 -4
- package/lib/esm/market/PositionUtils.js +9 -6
- package/lib/esm/math/TickLib.d.ts +22 -0
- package/lib/esm/math/TickLib.js +31 -1
- package/lib/esm/math/index.d.ts +0 -1
- package/lib/esm/math/index.js +0 -1
- package/lib/esm/offers/Offer.d.ts +217 -11
- package/lib/esm/offers/Offer.js +216 -8
- package/lib/esm/offers/OfferUtils.d.ts +245 -139
- package/lib/esm/offers/OfferUtils.js +306 -38
- package/lib/esm/queries/GetPosition.d.ts +1 -1
- package/lib/esm/queries/GetPosition.js +1 -1
- package/lib/esm/signatures/EcrecoverRatifierUtils.d.ts +66 -38
- package/lib/esm/signatures/EcrecoverRatifierUtils.js +149 -81
- package/lib/esm/signatures/Group.d.ts +12 -4
- package/lib/esm/signatures/Group.js +12 -4
- package/lib/esm/signatures/GroupUtils.d.ts +12 -4
- package/lib/esm/signatures/GroupUtils.js +6 -2
- package/lib/esm/signatures/Payload.d.ts +277 -277
- package/lib/esm/signatures/Payload.js +517 -531
- package/lib/esm/signatures/RatifierUtils.d.ts +57 -0
- package/lib/esm/signatures/RatifierUtils.js +94 -0
- package/lib/esm/signatures/SetterRatifierUtils.d.ts +21 -13
- package/lib/esm/signatures/SetterRatifierUtils.js +25 -20
- package/lib/esm/signatures/Tree.d.ts +28 -16
- package/lib/esm/signatures/Tree.js +25 -13
- package/lib/esm/signatures/TreeUtils.d.ts +181 -62
- package/lib/esm/signatures/TreeUtils.js +75 -78
- package/lib/esm/signatures/index.d.ts +1 -0
- package/lib/esm/signatures/index.js +1 -0
- package/lib/esm/signatures/offerStructInternal.d.ts +14 -0
- package/lib/esm/signatures/offerStructInternal.js +67 -0
- package/package.json +28 -32
- package/src/index.ts +1 -1
- package/lib/cjs/fetch/Offer.d.ts +0 -74
- package/lib/cjs/fetch/Offer.js +0 -119
- package/lib/cjs/math/ConsumableUnitsLib.d.ts +0 -57
- package/lib/cjs/math/ConsumableUnitsLib.js +0 -77
- package/lib/esm/fetch/Offer.d.ts +0 -74
- package/lib/esm/fetch/Offer.js +0 -116
- package/lib/esm/math/ConsumableUnitsLib.d.ts +0 -57
- package/lib/esm/math/ConsumableUnitsLib.js +0 -74
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type BigIntish } from "@morpho-org/morpho-ts";
|
|
2
|
-
import { type Hash } from "viem";
|
|
3
|
-
import type {
|
|
2
|
+
import { type Account, type Address, type Chain, type Client, type Hash, type Transport } from "viem";
|
|
3
|
+
import type { MempoolPayloadValidationSuccess, MidnightApiFetch, MidnightApiRequestOptions } from "../api/types.js";
|
|
4
4
|
import { type IOffer, type OfferStruct } from "../offers/index.js";
|
|
5
|
+
import { type EcrecoverSignatureInput } from "./EcrecoverRatifierUtils.js";
|
|
5
6
|
import { type GroupInput } from "./GroupUtils.js";
|
|
6
7
|
import type { Tree } from "./Tree.js";
|
|
7
8
|
/**
|
|
@@ -18,12 +19,14 @@ import type { Tree } from "./Tree.js";
|
|
|
18
19
|
*
|
|
19
20
|
* const offer = Offer.create({
|
|
20
21
|
* market: {
|
|
22
|
+
* chainId: 8453,
|
|
23
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
21
24
|
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
22
25
|
* collateralParams: [
|
|
23
26
|
* {
|
|
24
27
|
* token: "0x0000000000000000000000000000000000007000",
|
|
25
28
|
* lltv: 770000000000000000n,
|
|
26
|
-
*
|
|
29
|
+
* liquidationCursor: 250000000000000000n,
|
|
27
30
|
* oracle: "0x0000000000000000000000000000000000008000",
|
|
28
31
|
* },
|
|
29
32
|
* ],
|
|
@@ -66,12 +69,14 @@ export interface TreeDescriptor {
|
|
|
66
69
|
*
|
|
67
70
|
* const offer = Offer.create({
|
|
68
71
|
* market: {
|
|
72
|
+
* chainId: 8453,
|
|
73
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
69
74
|
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
70
75
|
* collateralParams: [
|
|
71
76
|
* {
|
|
72
77
|
* token: "0x0000000000000000000000000000000000007000",
|
|
73
78
|
* lltv: 770000000000000000n,
|
|
74
|
-
*
|
|
79
|
+
* liquidationCursor: 250000000000000000n,
|
|
75
80
|
* oracle: "0x0000000000000000000000000000000000008000",
|
|
76
81
|
* },
|
|
77
82
|
* ],
|
|
@@ -113,12 +118,14 @@ export interface TreeProof {
|
|
|
113
118
|
*
|
|
114
119
|
* const offer = Offer.create({
|
|
115
120
|
* market: {
|
|
121
|
+
* chainId: 8453,
|
|
122
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
116
123
|
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
117
124
|
* collateralParams: [
|
|
118
125
|
* {
|
|
119
126
|
* token: "0x0000000000000000000000000000000000007000",
|
|
120
127
|
* lltv: 770000000000000000n,
|
|
121
|
-
*
|
|
128
|
+
* liquidationCursor: 250000000000000000n,
|
|
122
129
|
* oracle: "0x0000000000000000000000000000000000008000",
|
|
123
130
|
* },
|
|
124
131
|
* ],
|
|
@@ -144,8 +151,8 @@ export type TreeCreateParams = readonly GroupInput[];
|
|
|
144
151
|
* Plain creation input or class tree accepted by {@link Tree.from}.
|
|
145
152
|
*
|
|
146
153
|
* Use this only at boundaries that intentionally convert caller input into a
|
|
147
|
-
* `Tree`.
|
|
148
|
-
*
|
|
154
|
+
* `Tree`. Ratifier helpers accept {@link RatifierTreeInput} instead, so they
|
|
155
|
+
* can reuse an existing `Tree` or normalize raw offer/group input.
|
|
149
156
|
*
|
|
150
157
|
* @example
|
|
151
158
|
* ```ts
|
|
@@ -154,12 +161,14 @@ export type TreeCreateParams = readonly GroupInput[];
|
|
|
154
161
|
*
|
|
155
162
|
* const offer = Offer.create({
|
|
156
163
|
* market: {
|
|
164
|
+
* chainId: 8453,
|
|
165
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
157
166
|
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
158
167
|
* collateralParams: [
|
|
159
168
|
* {
|
|
160
169
|
* token: "0x0000000000000000000000000000000000007000",
|
|
161
170
|
* lltv: 770000000000000000n,
|
|
162
|
-
*
|
|
171
|
+
* liquidationCursor: 250000000000000000n,
|
|
163
172
|
* oracle: "0x0000000000000000000000000000000000008000",
|
|
164
173
|
* },
|
|
165
174
|
* ],
|
|
@@ -181,24 +190,28 @@ export type TreeCreateParams = readonly GroupInput[];
|
|
|
181
190
|
*/
|
|
182
191
|
export type TreeInput = Tree | TreeCreateParams;
|
|
183
192
|
/**
|
|
184
|
-
*
|
|
193
|
+
* Tree-shaped data required by ratifier helpers.
|
|
185
194
|
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
195
|
+
* A `Tree` class instance satisfies this shape and is the optimal input when a
|
|
196
|
+
* caller already built one, because the cached offers, leaves, root, and height
|
|
197
|
+
* are reused for signatures and proofs. Plain objects with these fields are
|
|
198
|
+
* also accepted by ratifier helpers.
|
|
188
199
|
*
|
|
189
200
|
* @example
|
|
190
201
|
* ```ts
|
|
191
|
-
* import { Offer, Tree, type
|
|
202
|
+
* import { Offer, Tree, type TreeLike } from "@morpho-org/midnight-sdk";
|
|
192
203
|
* import { zeroAddress } from "viem";
|
|
193
204
|
*
|
|
194
205
|
* const offer = Offer.create({
|
|
195
206
|
* market: {
|
|
207
|
+
* chainId: 8453,
|
|
208
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
196
209
|
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
197
210
|
* collateralParams: [
|
|
198
211
|
* {
|
|
199
212
|
* token: "0x0000000000000000000000000000000000007000",
|
|
200
213
|
* lltv: 770000000000000000n,
|
|
201
|
-
*
|
|
214
|
+
* liquidationCursor: 250000000000000000n,
|
|
202
215
|
* oracle: "0x0000000000000000000000000000000000008000",
|
|
203
216
|
* },
|
|
204
217
|
* ],
|
|
@@ -214,45 +227,44 @@ export type TreeInput = Tree | TreeCreateParams;
|
|
|
214
227
|
* ratifier: "0x0000000000000000000000000000000000004000",
|
|
215
228
|
* maxUnits: 100n,
|
|
216
229
|
* });
|
|
217
|
-
* const tree = Tree.create([offer]);
|
|
218
|
-
*
|
|
219
|
-
* const validation = await tree.mempoolValidate(params);
|
|
220
|
-
* console.log(validation.valid);
|
|
230
|
+
* const tree: TreeLike = Tree.create([offer]);
|
|
231
|
+
* console.log(tree.root);
|
|
221
232
|
* ```
|
|
222
233
|
*/
|
|
223
|
-
export interface
|
|
224
|
-
/**
|
|
225
|
-
readonly
|
|
226
|
-
/**
|
|
227
|
-
readonly
|
|
228
|
-
/**
|
|
229
|
-
readonly
|
|
230
|
-
/**
|
|
231
|
-
readonly
|
|
232
|
-
/**
|
|
233
|
-
readonly
|
|
234
|
+
export interface TreeLike {
|
|
235
|
+
/** Non-padding offers in leaf order. */
|
|
236
|
+
readonly offers: readonly IOffer[];
|
|
237
|
+
/** ABI-compatible offers in leaf order, including protocol-zero padding. */
|
|
238
|
+
readonly paddedOffers: readonly OfferStruct[];
|
|
239
|
+
/** Leaf hashes for `paddedOffers`. */
|
|
240
|
+
readonly leaves: readonly Hash[];
|
|
241
|
+
/** Merkle root. */
|
|
242
|
+
readonly root: Hash;
|
|
243
|
+
/** Tree height. */
|
|
244
|
+
readonly height: number;
|
|
234
245
|
}
|
|
235
246
|
/**
|
|
236
|
-
*
|
|
247
|
+
* Tree-like input accepted by ratifier helpers.
|
|
237
248
|
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
* API.
|
|
249
|
+
* Pass a `Tree` or {@link TreeLike} object to reuse cached hashes and proofs.
|
|
250
|
+
* Pass raw offer/group input when convenience matters more than avoiding a
|
|
251
|
+
* one-time tree materialization.
|
|
242
252
|
*
|
|
243
253
|
* @example
|
|
244
254
|
* ```ts
|
|
245
|
-
* import { Offer,
|
|
255
|
+
* import { Offer, type RatifierTreeInput } from "@morpho-org/midnight-sdk";
|
|
246
256
|
* import { zeroAddress } from "viem";
|
|
247
257
|
*
|
|
248
258
|
* const offer = Offer.create({
|
|
249
259
|
* market: {
|
|
260
|
+
* chainId: 8453,
|
|
261
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
250
262
|
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
251
263
|
* collateralParams: [
|
|
252
264
|
* {
|
|
253
265
|
* token: "0x0000000000000000000000000000000000007000",
|
|
254
266
|
* lltv: 770000000000000000n,
|
|
255
|
-
*
|
|
267
|
+
* liquidationCursor: 250000000000000000n,
|
|
256
268
|
* oracle: "0x0000000000000000000000000000000000008000",
|
|
257
269
|
* },
|
|
258
270
|
* ],
|
|
@@ -268,17 +280,110 @@ export interface TreeMempoolValidateParams {
|
|
|
268
280
|
* ratifier: "0x0000000000000000000000000000000000004000",
|
|
269
281
|
* maxUnits: 100n,
|
|
270
282
|
* });
|
|
271
|
-
* const
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
283
|
+
* const tree: RatifierTreeInput = [offer];
|
|
284
|
+
* console.log(tree);
|
|
285
|
+
* ```
|
|
286
|
+
*/
|
|
287
|
+
export type RatifierTreeInput = TreeLike | TreeCreateParams;
|
|
288
|
+
/**
|
|
289
|
+
* Optional ratification inputs for {@link Tree.mempoolValidate}.
|
|
290
|
+
*
|
|
291
|
+
* Omit this when validating offer policy before the maker signs or approves a
|
|
292
|
+
* tree. Provide it when validating the final payload shape, including real
|
|
293
|
+
* `ratifierData`, after the Ecrecover signature and signer address exist or the
|
|
294
|
+
* Setter root is ready for publication.
|
|
295
|
+
*
|
|
296
|
+
* @example
|
|
297
|
+
* ```ts
|
|
298
|
+
* import { zeroHash, type Signature } from "viem";
|
|
299
|
+
* import type { TreeMempoolValidateRatification } from "@morpho-org/midnight-sdk";
|
|
300
|
+
*
|
|
301
|
+
* const ratification: TreeMempoolValidateRatification = {
|
|
302
|
+
* type: "ecrecover",
|
|
303
|
+
* account: "0x0000000000000000000000000000000000009000",
|
|
304
|
+
* signature: { v: 27, r: zeroHash, s: zeroHash } satisfies Signature,
|
|
305
|
+
* };
|
|
306
|
+
* console.log(ratification.type);
|
|
277
307
|
* ```
|
|
278
308
|
*/
|
|
279
|
-
export
|
|
280
|
-
/**
|
|
281
|
-
readonly
|
|
309
|
+
export type TreeMempoolValidateRatification = {
|
|
310
|
+
/** Ecrecover ratifier route. */
|
|
311
|
+
readonly type: "ecrecover";
|
|
312
|
+
/** Viem client whose transport signs typed data built from the tree. */
|
|
313
|
+
readonly client: Client<Transport, Chain, Account | undefined>;
|
|
314
|
+
/** Account that signs the tree root. */
|
|
315
|
+
readonly account: Account | Address;
|
|
316
|
+
/** Omit when the SDK should request the signature through `client`. */
|
|
317
|
+
readonly signature?: undefined;
|
|
318
|
+
} | {
|
|
319
|
+
/** Ecrecover ratifier route. */
|
|
320
|
+
readonly type: "ecrecover";
|
|
321
|
+
/** Precomputed signature for this tree root. */
|
|
322
|
+
readonly signature: EcrecoverSignatureInput;
|
|
323
|
+
/** Account that produced the signature. It may be the maker or an address authorized by each maker. */
|
|
324
|
+
readonly account: Account | Address;
|
|
325
|
+
/** Omit when a precomputed signature is supplied. */
|
|
326
|
+
readonly client?: undefined;
|
|
327
|
+
} | {
|
|
328
|
+
/** Setter ratifier route. */
|
|
329
|
+
readonly type: "setter";
|
|
330
|
+
};
|
|
331
|
+
/**
|
|
332
|
+
* Parameters for {@link Tree.mempoolValidate}.
|
|
333
|
+
*
|
|
334
|
+
* Use this when an already-created tree should be validated by the Midnight
|
|
335
|
+
* API. By default it validates the pre-ratification tree with empty
|
|
336
|
+
* `ratifierData`; pass `ratification` to validate the final payload shape with
|
|
337
|
+
* real ratifier data.
|
|
338
|
+
*
|
|
339
|
+
* @example
|
|
340
|
+
* ```ts
|
|
341
|
+
* import { Offer, Tree, type TreeMempoolValidateParams } from "@morpho-org/midnight-sdk";
|
|
342
|
+
* import { zeroAddress } from "viem";
|
|
343
|
+
*
|
|
344
|
+
* const offer = Offer.create({
|
|
345
|
+
* market: {
|
|
346
|
+
* chainId: 8453,
|
|
347
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
348
|
+
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
349
|
+
* collateralParams: [
|
|
350
|
+
* {
|
|
351
|
+
* token: "0x0000000000000000000000000000000000007000",
|
|
352
|
+
* lltv: 770000000000000000n,
|
|
353
|
+
* liquidationCursor: 250000000000000000n,
|
|
354
|
+
* oracle: "0x0000000000000000000000000000000000008000",
|
|
355
|
+
* },
|
|
356
|
+
* ],
|
|
357
|
+
* maturity: 54_000n,
|
|
358
|
+
* rcfThreshold: 0n,
|
|
359
|
+
* enterGate: zeroAddress,
|
|
360
|
+
* liquidatorGate: zeroAddress,
|
|
361
|
+
* },
|
|
362
|
+
* buy: true,
|
|
363
|
+
* maker: "0x0000000000000000000000000000000000009000",
|
|
364
|
+
* tick: 5_000n,
|
|
365
|
+
* expiry: 3_600n,
|
|
366
|
+
* ratifier: "0x0000000000000000000000000000000000004000",
|
|
367
|
+
* maxUnits: 100n,
|
|
368
|
+
* });
|
|
369
|
+
* const tree = Tree.create([offer]);
|
|
370
|
+
* const params = { chainId: 8453 } satisfies TreeMempoolValidateParams;
|
|
371
|
+
* await tree.mempoolValidate(params);
|
|
372
|
+
* ```
|
|
373
|
+
*/
|
|
374
|
+
export interface TreeMempoolValidateParams {
|
|
375
|
+
/** Chain id whose API policy should validate the tree. */
|
|
376
|
+
readonly chainId: number;
|
|
377
|
+
/** Midnight API URL used for the validation HTTP request. Defaults to `https://api.morpho.org/v0/midnight`. */
|
|
378
|
+
readonly apiUrl?: string | URL;
|
|
379
|
+
/** Optional ISO-8601 timestamp or `Date` selecting the API policy snapshot. */
|
|
380
|
+
readonly timestamp?: string | Date;
|
|
381
|
+
/** Fetch implementation used for the API call. Defaults to the global `fetch`. */
|
|
382
|
+
readonly fetch?: MidnightApiFetch;
|
|
383
|
+
/** Additional fetch options forwarded to the API request. */
|
|
384
|
+
readonly request?: MidnightApiRequestOptions;
|
|
385
|
+
/** Optional ratification inputs used to validate final payload bytes with real ratifier data. */
|
|
386
|
+
readonly ratification?: TreeMempoolValidateRatification;
|
|
282
387
|
}
|
|
283
388
|
/**
|
|
284
389
|
* Object-compatible tree hashing, root, proof, and verification helpers.
|
|
@@ -299,24 +404,26 @@ export declare namespace TreeUtils {
|
|
|
299
404
|
/**
|
|
300
405
|
* Validates a tree against Midnight mempool API policy.
|
|
301
406
|
*
|
|
302
|
-
* This is an API-backed convenience: it encodes each tree leaf
|
|
303
|
-
* `ratifierData`, then sends the temporary payload to the Midnight
|
|
304
|
-
* `POST /mempool/validate` endpoint.
|
|
305
|
-
*
|
|
306
|
-
*
|
|
407
|
+
* This is an API-backed convenience: by default it encodes each tree leaf
|
|
408
|
+
* with empty `ratifierData`, then sends the temporary payload to the Midnight
|
|
409
|
+
* API `POST /mempool/validate` endpoint. Pass `ratification` after signing or
|
|
410
|
+
* Setter root preparation to validate final payload bytes with real
|
|
411
|
+
* `ratifierData`.
|
|
307
412
|
*
|
|
308
413
|
* @param params.chainId - Chain id whose API policy should validate the tree.
|
|
309
|
-
* @param params.tree - Offer tree to validate
|
|
414
|
+
* @param params.tree - Offer tree to validate.
|
|
310
415
|
* @param params.apiUrl - Optional Midnight API URL override used for the validation HTTP request.
|
|
311
416
|
* @param params.timestamp - Optional ISO-8601 timestamp or `Date` selecting the API policy snapshot.
|
|
312
417
|
* @param params.fetch - Optional fetch implementation override used for the API call.
|
|
313
418
|
* @param params.request - Optional fetch options forwarded to the API request.
|
|
314
|
-
* @
|
|
419
|
+
* @param params.ratification - Optional ratification inputs used to validate final payload bytes with real ratifier data.
|
|
420
|
+
* @returns Successful API validation result with `valid: true`.
|
|
315
421
|
* @throws {InvalidTreeError} when the tree is empty, all padding, or duplicated.
|
|
316
422
|
* @throws {InvalidTreeHeightError} when the resulting height is unsupported.
|
|
317
|
-
* @throws {
|
|
423
|
+
* @throws {PayloadDecodeError} when validation payload encoding fails.
|
|
318
424
|
* @throws {MidnightApiError} when the API returns a non-2xx response.
|
|
319
425
|
* @throws {InvalidMidnightApiResponseError} when the API returns malformed success JSON.
|
|
426
|
+
* @throws {MidnightMempoolValidationError} when the API returns validation issues.
|
|
320
427
|
* @example
|
|
321
428
|
* ```ts
|
|
322
429
|
* import { Offer, TreeUtils } from "@morpho-org/midnight-sdk";
|
|
@@ -324,12 +431,14 @@ export declare namespace TreeUtils {
|
|
|
324
431
|
*
|
|
325
432
|
* const offer = Offer.create({
|
|
326
433
|
* market: {
|
|
434
|
+
* chainId: 8453,
|
|
435
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
327
436
|
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
328
437
|
* collateralParams: [
|
|
329
438
|
* {
|
|
330
439
|
* token: "0x0000000000000000000000000000000000007000",
|
|
331
440
|
* lltv: 770000000000000000n,
|
|
332
|
-
*
|
|
441
|
+
* liquidationCursor: 250000000000000000n,
|
|
333
442
|
* oracle: "0x0000000000000000000000000000000000008000",
|
|
334
443
|
* },
|
|
335
444
|
* ],
|
|
@@ -345,14 +454,16 @@ export declare namespace TreeUtils {
|
|
|
345
454
|
* ratifier: "0x0000000000000000000000000000000000004000",
|
|
346
455
|
* maxUnits: 100n,
|
|
347
456
|
* });
|
|
348
|
-
*
|
|
457
|
+
* await TreeUtils.mempoolValidate({
|
|
349
458
|
* chainId: 8453,
|
|
350
459
|
* tree: [offer],
|
|
351
460
|
* });
|
|
352
|
-
* console.log(validation.valid);
|
|
353
461
|
* ```
|
|
354
462
|
*/
|
|
355
|
-
function mempoolValidate(params:
|
|
463
|
+
function mempoolValidate(params: Pick<TreeMempoolValidateParams, "chainId" | "apiUrl" | "timestamp" | "fetch" | "request"> & {
|
|
464
|
+
readonly tree: TreeInput;
|
|
465
|
+
readonly ratification?: TreeMempoolValidateRatification;
|
|
466
|
+
}): Promise<MempoolPayloadValidationSuccess>;
|
|
356
467
|
/**
|
|
357
468
|
* Computes HashLib node hash from left and right child hashes.
|
|
358
469
|
*
|
|
@@ -393,12 +504,14 @@ export declare namespace TreeUtils {
|
|
|
393
504
|
*
|
|
394
505
|
* const offer = Offer.create({
|
|
395
506
|
* market: {
|
|
507
|
+
* chainId: 8453,
|
|
508
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
396
509
|
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
397
510
|
* collateralParams: [
|
|
398
511
|
* {
|
|
399
512
|
* token: "0x0000000000000000000000000000000000007000",
|
|
400
513
|
* lltv: 770000000000000000n,
|
|
401
|
-
*
|
|
514
|
+
* liquidationCursor: 250000000000000000n,
|
|
402
515
|
* oracle: "0x0000000000000000000000000000000000008000",
|
|
403
516
|
* },
|
|
404
517
|
* ],
|
|
@@ -437,12 +550,14 @@ export declare namespace TreeUtils {
|
|
|
437
550
|
*
|
|
438
551
|
* const offer = Offer.create({
|
|
439
552
|
* market: {
|
|
553
|
+
* chainId: 8453,
|
|
554
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
440
555
|
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
441
556
|
* collateralParams: [
|
|
442
557
|
* {
|
|
443
558
|
* token: "0x0000000000000000000000000000000000007000",
|
|
444
559
|
* lltv: 770000000000000000n,
|
|
445
|
-
*
|
|
560
|
+
* liquidationCursor: 250000000000000000n,
|
|
446
561
|
* oracle: "0x0000000000000000000000000000000000008000",
|
|
447
562
|
* },
|
|
448
563
|
* ],
|
|
@@ -470,7 +585,7 @@ export declare namespace TreeUtils {
|
|
|
470
585
|
* built-in Ecrecover and Setter helpers call this while generating
|
|
471
586
|
* `ratifierData`.
|
|
472
587
|
*
|
|
473
|
-
* @param params.tree - Tree that
|
|
588
|
+
* @param params.tree - Tree-like data with the root and leaves that contain the leaf.
|
|
474
589
|
* @param params.leafIndex - Leaf index to prove.
|
|
475
590
|
* @returns Proof descriptor.
|
|
476
591
|
* @throws {InvalidTreeError} when leaf index is out of range.
|
|
@@ -481,12 +596,14 @@ export declare namespace TreeUtils {
|
|
|
481
596
|
*
|
|
482
597
|
* const offer = Offer.create({
|
|
483
598
|
* market: {
|
|
599
|
+
* chainId: 8453,
|
|
600
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
484
601
|
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
485
602
|
* collateralParams: [
|
|
486
603
|
* {
|
|
487
604
|
* token: "0x0000000000000000000000000000000000007000",
|
|
488
605
|
* lltv: 770000000000000000n,
|
|
489
|
-
*
|
|
606
|
+
* liquidationCursor: 250000000000000000n,
|
|
490
607
|
* oracle: "0x0000000000000000000000000000000000008000",
|
|
491
608
|
* },
|
|
492
609
|
* ],
|
|
@@ -510,7 +627,7 @@ export declare namespace TreeUtils {
|
|
|
510
627
|
* ```
|
|
511
628
|
*/
|
|
512
629
|
function buildProof(params: {
|
|
513
|
-
readonly tree:
|
|
630
|
+
readonly tree: Pick<TreeLike, "leaves" | "root">;
|
|
514
631
|
readonly leafIndex: BigIntish;
|
|
515
632
|
}): TreeProof;
|
|
516
633
|
/**
|
|
@@ -532,12 +649,14 @@ export declare namespace TreeUtils {
|
|
|
532
649
|
*
|
|
533
650
|
* const offer = Offer.create({
|
|
534
651
|
* market: {
|
|
652
|
+
* chainId: 8453,
|
|
653
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
535
654
|
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
536
655
|
* collateralParams: [
|
|
537
656
|
* {
|
|
538
657
|
* token: "0x0000000000000000000000000000000000007000",
|
|
539
658
|
* lltv: 770000000000000000n,
|
|
540
|
-
*
|
|
659
|
+
* liquidationCursor: 250000000000000000n,
|
|
541
660
|
* oracle: "0x0000000000000000000000000000000000008000",
|
|
542
661
|
* },
|
|
543
662
|
* ],
|