@morpho-org/midnight-sdk 0.1.0 → 1.1.1
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 +89 -19
- package/lib/cjs/api/helpers.d.ts +11 -1
- package/lib/cjs/api/helpers.js +54 -4
- 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 +89 -1
- package/lib/cjs/errors.js +114 -3
- package/lib/cjs/fetch/Market.js +37 -3
- package/lib/cjs/fetch/index.d.ts +0 -1
- package/lib/cjs/fetch/index.js +0 -1
- package/lib/cjs/fetch/utils.d.ts +1 -1
- package/lib/cjs/fetch/utils.js +9 -2
- 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 +218 -12
- package/lib/cjs/offers/Offer.js +215 -7
- package/lib/cjs/offers/OfferUtils.d.ts +249 -143
- package/lib/cjs/offers/OfferUtils.js +326 -45
- package/lib/cjs/queries/GetPosition.d.ts +1 -1
- package/lib/cjs/queries/GetPosition.js +1 -1
- package/lib/cjs/signatures/EcrecoverRatifierUtils.d.ts +184 -38
- package/lib/cjs/signatures/EcrecoverRatifierUtils.js +296 -80
- package/lib/cjs/signatures/Group.d.ts +12 -4
- package/lib/cjs/signatures/Group.js +17 -7
- package/lib/cjs/signatures/GroupUtils.d.ts +60 -4
- package/lib/cjs/signatures/GroupUtils.js +57 -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 +105 -0
- package/lib/cjs/signatures/SetterRatifierUtils.d.ts +52 -13
- package/lib/cjs/signatures/SetterRatifierUtils.js +62 -19
- package/lib/cjs/signatures/Tree.d.ts +28 -16
- package/lib/cjs/signatures/Tree.js +35 -15
- package/lib/cjs/signatures/TreeUtils.d.ts +185 -63
- package/lib/cjs/signatures/TreeUtils.js +89 -79
- package/lib/cjs/signatures/eip712.d.ts +22 -0
- package/lib/cjs/signatures/eip712.js +26 -0
- package/lib/cjs/signatures/index.d.ts +2 -0
- package/lib/cjs/signatures/index.js +4 -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 +91 -21
- package/lib/esm/api/helpers.d.ts +11 -1
- package/lib/esm/api/helpers.js +54 -5
- 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 +89 -1
- package/lib/esm/errors.js +108 -2
- package/lib/esm/fetch/Market.js +38 -4
- package/lib/esm/fetch/index.d.ts +0 -1
- package/lib/esm/fetch/index.js +0 -1
- package/lib/esm/fetch/utils.d.ts +1 -1
- package/lib/esm/fetch/utils.js +9 -2
- 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 +218 -12
- package/lib/esm/offers/Offer.js +216 -8
- package/lib/esm/offers/OfferUtils.d.ts +249 -143
- package/lib/esm/offers/OfferUtils.js +329 -48
- package/lib/esm/queries/GetPosition.d.ts +1 -1
- package/lib/esm/queries/GetPosition.js +1 -1
- package/lib/esm/signatures/EcrecoverRatifierUtils.d.ts +184 -38
- package/lib/esm/signatures/EcrecoverRatifierUtils.js +298 -82
- package/lib/esm/signatures/Group.d.ts +12 -4
- package/lib/esm/signatures/Group.js +17 -7
- package/lib/esm/signatures/GroupUtils.d.ts +60 -4
- package/lib/esm/signatures/GroupUtils.js +57 -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 +105 -0
- package/lib/esm/signatures/SetterRatifierUtils.d.ts +52 -13
- package/lib/esm/signatures/SetterRatifierUtils.js +62 -19
- package/lib/esm/signatures/Tree.d.ts +28 -16
- package/lib/esm/signatures/Tree.js +36 -16
- package/lib/esm/signatures/TreeUtils.d.ts +185 -63
- package/lib/esm/signatures/TreeUtils.js +91 -81
- package/lib/esm/signatures/eip712.d.ts +22 -0
- package/lib/esm/signatures/eip712.js +22 -0
- package/lib/esm/signatures/index.d.ts +2 -0
- package/lib/esm/signatures/index.js +2 -0
- package/lib/esm/signatures/offerStructInternal.d.ts +14 -0
- package/lib/esm/signatures/offerStructInternal.js +67 -0
- package/package.json +31 -34
- 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
- package/src/index.ts +0 -19
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type BigIntish } from "@morpho-org/morpho-ts";
|
|
2
2
|
import { type Account, type Address, type Chain, type Client, type Hash, type Hex, type Signature, type Transport } from "viem";
|
|
3
|
-
import
|
|
4
|
-
import type {
|
|
5
|
-
import type
|
|
3
|
+
import { type IOffer } from "../offers/index.js";
|
|
4
|
+
import type { Payload } from "./Payload.js";
|
|
5
|
+
import { type RatifierTreeInput, type TreeProof } from "./TreeUtils.js";
|
|
6
6
|
declare const typedDataTypes: {
|
|
7
7
|
readonly EIP712Domain: readonly [{
|
|
8
8
|
readonly name: "chainId";
|
|
@@ -18,13 +18,19 @@ declare const typedDataTypes: {
|
|
|
18
18
|
readonly name: "lltv";
|
|
19
19
|
readonly type: "uint256";
|
|
20
20
|
}, {
|
|
21
|
-
readonly name: "
|
|
21
|
+
readonly name: "liquidationCursor";
|
|
22
22
|
readonly type: "uint256";
|
|
23
23
|
}, {
|
|
24
24
|
readonly name: "oracle";
|
|
25
25
|
readonly type: "address";
|
|
26
26
|
}];
|
|
27
27
|
readonly Market: readonly [{
|
|
28
|
+
readonly name: "chainId";
|
|
29
|
+
readonly type: "uint256";
|
|
30
|
+
}, {
|
|
31
|
+
readonly name: "midnight";
|
|
32
|
+
readonly type: "address";
|
|
33
|
+
}, {
|
|
28
34
|
readonly name: "loanToken";
|
|
29
35
|
readonly type: "address";
|
|
30
36
|
}, {
|
|
@@ -81,10 +87,10 @@ declare const typedDataTypes: {
|
|
|
81
87
|
readonly type: "bool";
|
|
82
88
|
}, {
|
|
83
89
|
readonly name: "maxUnits";
|
|
84
|
-
readonly type: "
|
|
90
|
+
readonly type: "uint128";
|
|
85
91
|
}, {
|
|
86
92
|
readonly name: "maxAssets";
|
|
87
|
-
readonly type: "
|
|
93
|
+
readonly type: "uint128";
|
|
88
94
|
}, {
|
|
89
95
|
readonly name: "continuousFeeCap";
|
|
90
96
|
readonly type: "uint256";
|
|
@@ -132,12 +138,14 @@ export interface DecodedEcrecoverRatifierData extends TreeProof {
|
|
|
132
138
|
*
|
|
133
139
|
* const offer = Offer.create({
|
|
134
140
|
* market: {
|
|
141
|
+
* chainId: 8453,
|
|
142
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
135
143
|
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
136
144
|
* collateralParams: [
|
|
137
145
|
* {
|
|
138
146
|
* token: "0x0000000000000000000000000000000000007000",
|
|
139
147
|
* lltv: 770000000000000000n,
|
|
140
|
-
*
|
|
148
|
+
* liquidationCursor: 250000000000000000n,
|
|
141
149
|
* oracle: "0x0000000000000000000000000000000000008000",
|
|
142
150
|
* },
|
|
143
151
|
* ],
|
|
@@ -208,12 +216,14 @@ export type EcrecoverSignatureInput = Hex | Signature | Signature<number, number
|
|
|
208
216
|
*
|
|
209
217
|
* const offer = Offer.create({
|
|
210
218
|
* market: {
|
|
219
|
+
* chainId: 8453,
|
|
220
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
211
221
|
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
212
222
|
* collateralParams: [
|
|
213
223
|
* {
|
|
214
224
|
* token: "0x0000000000000000000000000000000000007000",
|
|
215
225
|
* lltv: 770000000000000000n,
|
|
216
|
-
*
|
|
226
|
+
* liquidationCursor: 250000000000000000n,
|
|
217
227
|
* oracle: "0x0000000000000000000000000000000000008000",
|
|
218
228
|
* },
|
|
219
229
|
* ],
|
|
@@ -237,8 +247,8 @@ export type EcrecoverSignatureInput = Hex | Signature | Signature<number, number
|
|
|
237
247
|
* ```
|
|
238
248
|
*/
|
|
239
249
|
export interface EcrecoverRatifierTypedDataParams {
|
|
240
|
-
/** Tree being ratified. */
|
|
241
|
-
readonly tree:
|
|
250
|
+
/** Tree-like input being ratified. Existing `Tree` instances reuse cached hashes and proofs. */
|
|
251
|
+
readonly tree: RatifierTreeInput;
|
|
242
252
|
/** Chain id used by the EIP-712 domain. */
|
|
243
253
|
readonly chainId: BigIntish;
|
|
244
254
|
}
|
|
@@ -246,7 +256,7 @@ export interface EcrecoverRatifierTypedDataParams {
|
|
|
246
256
|
* Parameters for {@link EcrecoverRatifierUtils.ratify}.
|
|
247
257
|
*
|
|
248
258
|
* Use this after tree validation. Provide either a signing client plus account
|
|
249
|
-
* or a signature that
|
|
259
|
+
* or a precomputed signature plus the account that produced it.
|
|
250
260
|
*
|
|
251
261
|
* @example
|
|
252
262
|
* ```ts
|
|
@@ -255,12 +265,14 @@ export interface EcrecoverRatifierTypedDataParams {
|
|
|
255
265
|
*
|
|
256
266
|
* const offer = Offer.create({
|
|
257
267
|
* market: {
|
|
268
|
+
* chainId: 8453,
|
|
269
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
258
270
|
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
259
271
|
* collateralParams: [
|
|
260
272
|
* {
|
|
261
273
|
* token: "0x0000000000000000000000000000000000007000",
|
|
262
274
|
* lltv: 770000000000000000n,
|
|
263
|
-
*
|
|
275
|
+
* liquidationCursor: 250000000000000000n,
|
|
264
276
|
* oracle: "0x0000000000000000000000000000000000008000",
|
|
265
277
|
* },
|
|
266
278
|
* ],
|
|
@@ -278,14 +290,15 @@ export interface EcrecoverRatifierTypedDataParams {
|
|
|
278
290
|
* });
|
|
279
291
|
* const params: EcrecoverRatifierRatifyParams = {
|
|
280
292
|
* tree: Tree.create([offer]),
|
|
293
|
+
* account: "0x0000000000000000000000000000000000009000",
|
|
281
294
|
* signature: { v: 27, r: zeroHash, s: zeroHash },
|
|
282
295
|
* };
|
|
283
296
|
* console.log(params.tree);
|
|
284
297
|
* ```
|
|
285
298
|
*/
|
|
286
299
|
export type EcrecoverRatifierRatifyParams = {
|
|
287
|
-
/** Tree being ratified. */
|
|
288
|
-
readonly tree:
|
|
300
|
+
/** Tree-like input being ratified. */
|
|
301
|
+
readonly tree: RatifierTreeInput;
|
|
289
302
|
/** Viem client whose transport signs the typed data built from `tree`. */
|
|
290
303
|
readonly client: Client<Transport, Chain, Account | undefined>;
|
|
291
304
|
/** Account that signs the tree root. It may be the maker or an address authorized by each maker. */
|
|
@@ -293,15 +306,15 @@ export type EcrecoverRatifierRatifyParams = {
|
|
|
293
306
|
/** Omit when the SDK should request the signature through `client`. */
|
|
294
307
|
readonly signature?: undefined;
|
|
295
308
|
} | {
|
|
296
|
-
/** Tree being ratified. */
|
|
297
|
-
readonly tree:
|
|
309
|
+
/** Tree-like input being ratified. */
|
|
310
|
+
readonly tree: RatifierTreeInput;
|
|
298
311
|
/** Precomputed signature for this tree root. */
|
|
299
312
|
readonly signature: EcrecoverSignatureInput;
|
|
313
|
+
/** Account that produced the signature. It may be the maker or an address authorized by each maker. */
|
|
314
|
+
readonly account: Account | Address;
|
|
300
315
|
/** Omit when a precomputed signature is supplied. */
|
|
301
316
|
readonly client?: undefined;
|
|
302
317
|
/** Omit when a precomputed signature is supplied. */
|
|
303
|
-
readonly account?: undefined;
|
|
304
|
-
/** Omit when a precomputed signature is supplied. */
|
|
305
318
|
readonly chainId?: undefined;
|
|
306
319
|
};
|
|
307
320
|
/**
|
|
@@ -314,12 +327,14 @@ export type EcrecoverRatifierRatifyParams = {
|
|
|
314
327
|
*
|
|
315
328
|
* const offer = Offer.create({
|
|
316
329
|
* market: {
|
|
330
|
+
* chainId: 8453,
|
|
331
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
317
332
|
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
318
333
|
* collateralParams: [
|
|
319
334
|
* {
|
|
320
335
|
* token: "0x0000000000000000000000000000000000007000",
|
|
321
336
|
* lltv: 770000000000000000n,
|
|
322
|
-
*
|
|
337
|
+
* liquidationCursor: 250000000000000000n,
|
|
323
338
|
* oracle: "0x0000000000000000000000000000000000008000",
|
|
324
339
|
* },
|
|
325
340
|
* ],
|
|
@@ -344,13 +359,47 @@ export type EcrecoverRatifierRatifyParams = {
|
|
|
344
359
|
* ```
|
|
345
360
|
*/
|
|
346
361
|
export interface EcrecoverRatifierDataParams {
|
|
347
|
-
/** Tree that produced the proof. */
|
|
348
|
-
readonly tree:
|
|
362
|
+
/** Tree-like input that produced the proof. Existing `Tree` instances reuse cached hashes and proofs. */
|
|
363
|
+
readonly tree: RatifierTreeInput;
|
|
349
364
|
/** Leaf index to prove. */
|
|
350
365
|
readonly leafIndex: BigIntish;
|
|
351
366
|
/** Ecrecover signature for the tree root. */
|
|
352
367
|
readonly signature: EcrecoverSignatureInput;
|
|
353
368
|
}
|
|
369
|
+
/** Parameters for reconstructing an EcrecoverRatifier digest from decoded ratifier data fields. */
|
|
370
|
+
export interface EcrecoverRatifierRootDigestParams {
|
|
371
|
+
/** Observed EIP-155 chain id from the log or execution context. Must match `offer.market.chainId`. */
|
|
372
|
+
readonly chainId: BigIntish;
|
|
373
|
+
/** Offer whose ratifier address and market chain id define the EIP-712 domain. */
|
|
374
|
+
readonly offer: IOffer;
|
|
375
|
+
/** Merkle root embedded in the ratifier data. */
|
|
376
|
+
readonly root: Hash;
|
|
377
|
+
/** Number of sibling hashes in the Merkle proof. */
|
|
378
|
+
readonly proofLength: number;
|
|
379
|
+
}
|
|
380
|
+
/** Parameters for reconstructing an EcrecoverRatifier digest from encoded ratifier data. */
|
|
381
|
+
export interface EcrecoverRatifierDataDigestParams {
|
|
382
|
+
/** Observed EIP-155 chain id from the log or execution context. Must match `offer.market.chainId`. */
|
|
383
|
+
readonly chainId: BigIntish;
|
|
384
|
+
/** Offer carried by the payload item. */
|
|
385
|
+
readonly offer: IOffer;
|
|
386
|
+
/** ABI-encoded Ecrecover ratifier data carried by the payload item. */
|
|
387
|
+
readonly ratifierData: Hex;
|
|
388
|
+
}
|
|
389
|
+
/** Parameters for locally verifying Ecrecover ratifier data attached to one payload item. */
|
|
390
|
+
export interface EcrecoverRatifierDataVerificationParams {
|
|
391
|
+
/** Observed EIP-155 chain id from the log or execution context. Must match `offer.market.chainId`. */
|
|
392
|
+
readonly chainId: BigIntish;
|
|
393
|
+
/** Offer carried by the payload item. */
|
|
394
|
+
readonly offer: IOffer;
|
|
395
|
+
/** ABI-encoded Ecrecover ratifier data carried by the payload item. */
|
|
396
|
+
readonly ratifierData: Hex;
|
|
397
|
+
}
|
|
398
|
+
/** Decoded Ecrecover ratifier data after local proof verification and signature recovery. */
|
|
399
|
+
export interface VerifiedEcrecoverRatifierData extends DecodedEcrecoverRatifierData {
|
|
400
|
+
/** Signer recovered from the Ecrecover typed-data digest. */
|
|
401
|
+
readonly signer: Address;
|
|
402
|
+
}
|
|
354
403
|
/**
|
|
355
404
|
* EcrecoverRatifier-specific pure utilities.
|
|
356
405
|
*
|
|
@@ -359,7 +408,10 @@ export interface EcrecoverRatifierDataParams {
|
|
|
359
408
|
* validate the tree, sign the typed data, call `ratify`, then pass the returned
|
|
360
409
|
* items to `Payload.encode`. Ecrecover trees must contain one ratifier; split
|
|
361
410
|
* trees by ratifier before signing. The signer may be the maker or an address
|
|
362
|
-
* authorized by every maker in the tree.
|
|
411
|
+
* authorized by every maker in the tree. Ratifier helpers accept tree-like
|
|
412
|
+
* inputs rather than requiring the `Tree` class. Passing an existing `Tree`
|
|
413
|
+
* remains the optimal path because its cached offers, leaves, root, and height
|
|
414
|
+
* are reused for typed data and per-leaf proofs.
|
|
363
415
|
*
|
|
364
416
|
* @example
|
|
365
417
|
* ```ts
|
|
@@ -382,16 +434,16 @@ export declare namespace EcrecoverRatifierUtils {
|
|
|
382
434
|
* console.log(EcrecoverRatifierUtils.treeTypeHash(0));
|
|
383
435
|
* ```
|
|
384
436
|
*/
|
|
385
|
-
function treeTypeHash(height: number): "
|
|
437
|
+
function treeTypeHash(height: number): "0x270da1ebafc0f24637af3612fb8c3a1d828fcb56d3637c24e86dd006b12ca7f9" | "0x828b9cdf8326a1cf234328e4d5229546a98fb72ef73624f5b6b31538e555b96c" | "0xfcb7a3ca4094246b8185620c4cf025c93032b6f0384805aa3f22afe04290e982" | "0xcc97cb1955496a5269b5a7afca62ba694edcab26ba838a1adbd257931249de92" | "0xda3feb08db360ad9e09540132ff04d2b6a596fdaa4747892217aaa4c7c9bcc31" | "0x15bd6e2aa1a7a61614187ac16d2cbf8610c8f2f3c3d9eaa380ae7a501ee3cf06" | "0xb726cb7fab1a24c28213cbd482fa5a301f127fb25feb01da341919983a72711a" | "0xcea9cd557c6f821868ea287304199d0e0554af630bfa8fe36c64eb3bbacca418" | "0xf7dbde8234e8e345cec8fc0a8ac5909ee336b214882751ecd51e7b37df4f6cdd" | "0x5400a5d43d39e6bfe910af8cb84ac77bf501d310413769dffd62ccecda8b00c6" | "0x0754209b60d99d0822b3ecd5a970f9db09df9c8998a8441e24b81f06d6c76fee" | "0xf5d561d88647c3b38ed6636709d3166819fc66f8ed52a0daf4ae186387b4646c" | "0x5801c07a6c7df039ce00a7a2b8bd92aa1cf333c30b0bc3d78768590b6063d09e" | "0xc9da7190eaf4b14c7cb1c14f9898256c0adb6b1dc303afe79594dea64fe199c0" | "0xa47534c85ac57c583568465d40fd46683d2d558d8129fe1aca01e93023afca92" | "0xb1e841691fb54f4ef85e2ed9de45d610e57f49e1e6eb2510ceead16e447dd519" | "0x4fa4f16f09f0c36c7670449a4032073380d28a60071e12ee8874bb3e5a8318fc" | "0x817bbaac8bb863670f488b454cdd5d0990d9d81871a68e9df381c3c13d3f2ba2" | "0xc447f06079bddf4b011523c4bce119e9e90fdf937de4ee88f48010406560e9c1" | "0x1608d5eb56943c667c34b413f9f8a1c24a84ddfe1301a9c25487e638de1f5822" | "0x3a677100d2e855c24a62d1e9c365bff90d02287f066a07064843ca1ee70ea113";
|
|
386
438
|
/**
|
|
387
|
-
* Builds EcrecoverRatifier typed data for a tree.
|
|
439
|
+
* Builds EcrecoverRatifier typed data for a tree-like input.
|
|
388
440
|
*
|
|
389
441
|
* Use after the tree is built and validated, before requesting the signer
|
|
390
442
|
* signature. The EIP-712 verifier is derived from the shared ratifier address
|
|
391
443
|
* on the tree offers. `ratify` calls this for you when given a client and
|
|
392
444
|
* account.
|
|
393
445
|
*
|
|
394
|
-
* @param params.tree - Ecrecover-ratified offer tree to sign.
|
|
446
|
+
* @param params.tree - Ecrecover-ratified offer tree-like input to sign.
|
|
395
447
|
* @param params.chainId - EIP-155 chain id included in the EIP-712 domain.
|
|
396
448
|
* @returns EIP-712 typed-data descriptor.
|
|
397
449
|
* @throws {InvalidTreeError} when the tree is invalid or contains multiple ratifiers.
|
|
@@ -404,12 +456,14 @@ export declare namespace EcrecoverRatifierUtils {
|
|
|
404
456
|
*
|
|
405
457
|
* const offer = Offer.create({
|
|
406
458
|
* market: {
|
|
459
|
+
* chainId: 8453,
|
|
460
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
407
461
|
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
408
462
|
* collateralParams: [
|
|
409
463
|
* {
|
|
410
464
|
* token: "0x0000000000000000000000000000000000007000",
|
|
411
465
|
* lltv: 770000000000000000n,
|
|
412
|
-
*
|
|
466
|
+
* liquidationCursor: 250000000000000000n,
|
|
413
467
|
* oracle: "0x0000000000000000000000000000000000008000",
|
|
414
468
|
* },
|
|
415
469
|
* ],
|
|
@@ -437,7 +491,7 @@ export declare namespace EcrecoverRatifierUtils {
|
|
|
437
491
|
/**
|
|
438
492
|
* Builds the EcrecoverRatifier digest used by the Solidity ratifier.
|
|
439
493
|
*
|
|
440
|
-
* @param params.tree - Ecrecover-ratified offer tree to hash.
|
|
494
|
+
* @param params.tree - Ecrecover-ratified offer tree-like input to hash.
|
|
441
495
|
* @param params.chainId - EIP-155 chain id included in the EIP-712 domain.
|
|
442
496
|
* @returns EIP-712 digest.
|
|
443
497
|
* @throws {InvalidTreeError} when the tree contains multiple ratifiers.
|
|
@@ -450,12 +504,14 @@ export declare namespace EcrecoverRatifierUtils {
|
|
|
450
504
|
*
|
|
451
505
|
* const offer = Offer.create({
|
|
452
506
|
* market: {
|
|
507
|
+
* chainId: 8453,
|
|
508
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
453
509
|
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
454
510
|
* collateralParams: [
|
|
455
511
|
* {
|
|
456
512
|
* token: "0x0000000000000000000000000000000000007000",
|
|
457
513
|
* lltv: 770000000000000000n,
|
|
458
|
-
*
|
|
514
|
+
* liquidationCursor: 250000000000000000n,
|
|
459
515
|
* oracle: "0x0000000000000000000000000000000000008000",
|
|
460
516
|
* },
|
|
461
517
|
* ],
|
|
@@ -480,6 +536,89 @@ export declare namespace EcrecoverRatifierUtils {
|
|
|
480
536
|
* ```
|
|
481
537
|
*/
|
|
482
538
|
function digest(params: EcrecoverRatifierTypedDataParams): `0x${string}`;
|
|
539
|
+
/**
|
|
540
|
+
* Builds the EcrecoverRatifier digest from a payload offer, root, and proof height.
|
|
541
|
+
*
|
|
542
|
+
* Use this on the take-side or in indexers after decoding ratifier data, when
|
|
543
|
+
* the original full tree is not available but the payload item includes the
|
|
544
|
+
* offer and proof metadata needed to reconstruct the signed digest. Pass the
|
|
545
|
+
* observed log or execution chain id so cross-chain-spoofed payloads are
|
|
546
|
+
* rejected before signature recovery.
|
|
547
|
+
*
|
|
548
|
+
* @param params.chainId - Observed EIP-155 chain id from the log or execution context.
|
|
549
|
+
* @param params.offer - Offer carried by the payload item.
|
|
550
|
+
* @param params.root - Merkle root embedded in the ratifier data.
|
|
551
|
+
* @param params.proofLength - Number of sibling hashes in the Merkle proof.
|
|
552
|
+
* @returns EIP-712 digest signed by the maker or authorized signer.
|
|
553
|
+
* @throws {ChainIdMismatchError} when `params.chainId` does not match `offer.market.chainId`.
|
|
554
|
+
* @throws {InvalidTreeHeightError} when `proofLength` exceeds 20.
|
|
555
|
+
* @example
|
|
556
|
+
* ```ts
|
|
557
|
+
* import { EcrecoverRatifierUtils } from "@morpho-org/midnight-sdk";
|
|
558
|
+
* import { zeroHash } from "viem";
|
|
559
|
+
*
|
|
560
|
+
* const digest = EcrecoverRatifierUtils.digestForRoot({
|
|
561
|
+
* chainId: 8453n,
|
|
562
|
+
* offer,
|
|
563
|
+
* root: zeroHash,
|
|
564
|
+
* proofLength: 0,
|
|
565
|
+
* });
|
|
566
|
+
* console.log(digest);
|
|
567
|
+
* ```
|
|
568
|
+
*/
|
|
569
|
+
function digestForRoot(params: EcrecoverRatifierRootDigestParams): Hash;
|
|
570
|
+
/**
|
|
571
|
+
* Builds the EcrecoverRatifier digest from one payload item's encoded ratifier data.
|
|
572
|
+
*
|
|
573
|
+
* @param params.chainId - Observed EIP-155 chain id from the log or execution context.
|
|
574
|
+
* @param params.offer - Offer carried by the payload item.
|
|
575
|
+
* @param params.ratifierData - ABI-encoded Ecrecover ratifier data.
|
|
576
|
+
* @returns EIP-712 digest signed by the maker or authorized signer.
|
|
577
|
+
* @throws {ChainIdMismatchError} when `params.chainId` does not match `offer.market.chainId`.
|
|
578
|
+
* @throws {InvalidTreeHeightError} when the proof height exceeds 20.
|
|
579
|
+
* @example
|
|
580
|
+
* ```ts
|
|
581
|
+
* import { EcrecoverRatifierUtils } from "@morpho-org/midnight-sdk";
|
|
582
|
+
*
|
|
583
|
+
* const digest = EcrecoverRatifierUtils.digestRatifierData({
|
|
584
|
+
* chainId: 8453n,
|
|
585
|
+
* offer,
|
|
586
|
+
* ratifierData,
|
|
587
|
+
* });
|
|
588
|
+
* console.log(digest);
|
|
589
|
+
* ```
|
|
590
|
+
*/
|
|
591
|
+
function digestRatifierData(params: EcrecoverRatifierDataDigestParams): Hash;
|
|
592
|
+
/**
|
|
593
|
+
* Verifies an Ecrecover ratifier-data proof and recovers its signer.
|
|
594
|
+
*
|
|
595
|
+
* This helper intentionally does not check `Midnight.isAuthorized` or
|
|
596
|
+
* `EcrecoverRatifier.isRootCanceled` state. Consumers must query both at the
|
|
597
|
+
* observed block before treating a recovered item as executable: the returned
|
|
598
|
+
* signer must be the maker or authorized by the maker, the offer ratifier must
|
|
599
|
+
* be authorized by the maker, and `isRootCanceled(maker, root)` must be false.
|
|
600
|
+
*
|
|
601
|
+
* @param params.chainId - Observed EIP-155 chain id from the log or execution context.
|
|
602
|
+
* @param params.offer - Offer carried by the payload item.
|
|
603
|
+
* @param params.ratifierData - ABI-encoded Ecrecover ratifier data.
|
|
604
|
+
* @returns Decoded ratifier data plus recovered signer.
|
|
605
|
+
* @throws {ChainIdMismatchError} when `params.chainId` does not match `offer.market.chainId`.
|
|
606
|
+
* @throws {InvalidEcrecoverSignatureVError} when the decoded signature `v` is not 27 or 28.
|
|
607
|
+
* @throws {InvalidTreeError} when the proof does not include `offer` in `root`.
|
|
608
|
+
* @throws {InvalidTreeHeightError} when the proof height exceeds 20.
|
|
609
|
+
* @example
|
|
610
|
+
* ```ts
|
|
611
|
+
* import { EcrecoverRatifierUtils } from "@morpho-org/midnight-sdk";
|
|
612
|
+
*
|
|
613
|
+
* const verified = await EcrecoverRatifierUtils.verifyRatifierData({
|
|
614
|
+
* chainId: 8453n,
|
|
615
|
+
* offer,
|
|
616
|
+
* ratifierData,
|
|
617
|
+
* });
|
|
618
|
+
* console.log(verified.signer);
|
|
619
|
+
* ```
|
|
620
|
+
*/
|
|
621
|
+
function verifyRatifierData(params: EcrecoverRatifierDataVerificationParams): Promise<VerifiedEcrecoverRatifierData>;
|
|
483
622
|
/**
|
|
484
623
|
* Signs EcrecoverRatifier typed data through a viem client.
|
|
485
624
|
*
|
|
@@ -488,12 +627,13 @@ export declare namespace EcrecoverRatifierUtils {
|
|
|
488
627
|
* client and account. The account may be the maker or an address authorized
|
|
489
628
|
* by every maker in the tree; the protocol checks that authorization onchain.
|
|
490
629
|
*
|
|
491
|
-
* @param params.tree - Ecrecover-ratified offer tree to sign.
|
|
630
|
+
* @param params.tree - Ecrecover-ratified offer tree-like input to sign.
|
|
492
631
|
* @param params.client - Viem client whose transport signs the tree typed data.
|
|
493
632
|
* @param params.account - Account used to sign the tree typed data.
|
|
494
633
|
* @returns Signature returned by the client.
|
|
495
|
-
* @throws {InvalidTreeError} when the tree is invalid or
|
|
634
|
+
* @throws {InvalidTreeError} when the tree is invalid, contains multiple ratifiers, or spans multiple chain ids.
|
|
496
635
|
* @throws {InvalidTreeHeightError} when the tree height is unsupported.
|
|
636
|
+
* @throws {ChainIdMismatchError} when `params.client.chain?.id` does not match the tree offer chain id.
|
|
497
637
|
* @throws {InvalidTypedDataSignatureError} when the returned signature does not recover to `params.account`.
|
|
498
638
|
* @example
|
|
499
639
|
* ```ts
|
|
@@ -504,12 +644,14 @@ export declare namespace EcrecoverRatifierUtils {
|
|
|
504
644
|
*
|
|
505
645
|
* const offer = Offer.create({
|
|
506
646
|
* market: {
|
|
647
|
+
* chainId: 8453,
|
|
648
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
507
649
|
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
508
650
|
* collateralParams: [
|
|
509
651
|
* {
|
|
510
652
|
* token: "0x0000000000000000000000000000000000007000",
|
|
511
653
|
* lltv: 770000000000000000n,
|
|
512
|
-
*
|
|
654
|
+
* liquidationCursor: 250000000000000000n,
|
|
513
655
|
* oracle: "0x0000000000000000000000000000000000008000",
|
|
514
656
|
* },
|
|
515
657
|
* ],
|
|
@@ -539,7 +681,7 @@ export declare namespace EcrecoverRatifierUtils {
|
|
|
539
681
|
* ```
|
|
540
682
|
*/
|
|
541
683
|
function sign(params: {
|
|
542
|
-
readonly tree:
|
|
684
|
+
readonly tree: RatifierTreeInput;
|
|
543
685
|
readonly client: Client<Transport, Chain, Account | undefined>;
|
|
544
686
|
readonly account: Account | Address;
|
|
545
687
|
}): Promise<Hex>;
|
|
@@ -628,7 +770,7 @@ export declare namespace EcrecoverRatifierUtils {
|
|
|
628
770
|
* Use after a tree has been signed when a caller needs data for one offer
|
|
629
771
|
* leaf. Use `ratify` to produce payload-ready items for the whole tree.
|
|
630
772
|
*
|
|
631
|
-
* @param params.tree - Ecrecover-ratified offer tree that produced the proof.
|
|
773
|
+
* @param params.tree - Ecrecover-ratified offer tree-like input that produced the proof.
|
|
632
774
|
* @param params.leafIndex - Leaf index to prove.
|
|
633
775
|
* @param params.signature - Ecrecover signature for the tree root.
|
|
634
776
|
* @returns ABI-encoded EcrecoverRatifier data.
|
|
@@ -640,12 +782,14 @@ export declare namespace EcrecoverRatifierUtils {
|
|
|
640
782
|
*
|
|
641
783
|
* const offer = Offer.create({
|
|
642
784
|
* market: {
|
|
785
|
+
* chainId: 8453,
|
|
786
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
643
787
|
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
644
788
|
* collateralParams: [
|
|
645
789
|
* {
|
|
646
790
|
* token: "0x0000000000000000000000000000000000007000",
|
|
647
791
|
* lltv: 770000000000000000n,
|
|
648
|
-
*
|
|
792
|
+
* liquidationCursor: 250000000000000000n,
|
|
649
793
|
* oracle: "0x0000000000000000000000000000000000008000",
|
|
650
794
|
* },
|
|
651
795
|
* ],
|
|
@@ -677,14 +821,14 @@ export declare namespace EcrecoverRatifierUtils {
|
|
|
677
821
|
* The returned items preserve tree leaf order and include ratifier data
|
|
678
822
|
* required by takers. The group id is stored on each inline offer.
|
|
679
823
|
*
|
|
680
|
-
* @param params.tree - Ecrecover-ratified offer tree to ratify.
|
|
824
|
+
* @param params.tree - Ecrecover-ratified offer tree-like input to ratify.
|
|
681
825
|
* @param params.client - Optional viem client whose transport signs typed data built from `params.tree`.
|
|
682
826
|
* @param params.account - Optional account used to sign typed data built from `params.tree`.
|
|
683
827
|
* @param params.signature - Optional precomputed signature for `params.tree`.
|
|
684
828
|
* @returns Items containing each offer and its ratifier data.
|
|
685
829
|
* @throws {InvalidTreeError} when the tree is invalid or contains multiple ratifiers.
|
|
686
830
|
* @throws {InvalidTreeHeightError} when the tree height is unsupported.
|
|
687
|
-
* @throws {InvalidTypedDataSignatureError} when client signing
|
|
831
|
+
* @throws {InvalidTypedDataSignatureError} when client signing or a precomputed signature does not recover to `params.account`.
|
|
688
832
|
* @example
|
|
689
833
|
* ```ts
|
|
690
834
|
* import { EcrecoverRatifierUtils, Tree } from "@morpho-org/midnight-sdk";
|
|
@@ -694,12 +838,14 @@ export declare namespace EcrecoverRatifierUtils {
|
|
|
694
838
|
*
|
|
695
839
|
* const offer = Offer.create({
|
|
696
840
|
* market: {
|
|
841
|
+
* chainId: 8453,
|
|
842
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
697
843
|
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
698
844
|
* collateralParams: [
|
|
699
845
|
* {
|
|
700
846
|
* token: "0x0000000000000000000000000000000000007000",
|
|
701
847
|
* lltv: 770000000000000000n,
|
|
702
|
-
*
|
|
848
|
+
* liquidationCursor: 250000000000000000n,
|
|
703
849
|
* oracle: "0x0000000000000000000000000000000000008000",
|
|
704
850
|
* },
|
|
705
851
|
* ],
|
|
@@ -728,6 +874,6 @@ export declare namespace EcrecoverRatifierUtils {
|
|
|
728
874
|
* console.log(items.length);
|
|
729
875
|
* ```
|
|
730
876
|
*/
|
|
731
|
-
function ratify(params: EcrecoverRatifierRatifyParams): Promise<readonly
|
|
877
|
+
function ratify(params: EcrecoverRatifierRatifyParams): Promise<readonly Payload.Item[]>;
|
|
732
878
|
}
|
|
733
879
|
export {};
|