@morpho-org/midnight-sdk 1.7.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
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
import { type BigIntish } from "@morpho-org/morpho-ts";
|
|
2
|
+
import { type Address, type Hash, type Hex } from "viem";
|
|
3
|
+
import { type IOffer, type OfferStruct } from "../offers/index.js";
|
|
4
|
+
import type { Payload } from "./Payload.js";
|
|
5
|
+
import { type TreeProof } from "./TreeUtils.js";
|
|
6
|
+
import type { TreeData, TreeSnapshot } from "./treeTypes.js";
|
|
7
|
+
/**
|
|
8
|
+
* One PriceRatifierV1 offer leaf.
|
|
9
|
+
*
|
|
10
|
+
* `allowedTaker` optionally restricts the offer to one taker; omit it or pass
|
|
11
|
+
* the zero address to let anyone take.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import type { IOffer, PriceRatifierV1Leaf } from "@morpho-org/midnight-sdk";
|
|
16
|
+
*
|
|
17
|
+
* function leaf(offer: IOffer): PriceRatifierV1Leaf {
|
|
18
|
+
* return { offer };
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export interface PriceRatifierV1Leaf {
|
|
23
|
+
/** Offer carried by the leaf; the offer's `ratifier` must be the PriceRatifierV1 address. */
|
|
24
|
+
readonly offer: IOffer;
|
|
25
|
+
/** Optional taker restriction; defaults to the zero address (any taker). */
|
|
26
|
+
readonly allowedTaker?: Address;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* ABI-compatible PriceRatifierV1 leaf.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* import type { OfferStruct, PriceRatifierV1LeafStruct } from "@morpho-org/midnight-sdk";
|
|
34
|
+
* import { zeroAddress } from "viem";
|
|
35
|
+
*
|
|
36
|
+
* function leaf(offer: OfferStruct): PriceRatifierV1LeafStruct {
|
|
37
|
+
* return { offer, allowedTaker: zeroAddress };
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export interface PriceRatifierV1LeafStruct {
|
|
42
|
+
/** ABI-compatible offer. */
|
|
43
|
+
readonly offer: OfferStruct;
|
|
44
|
+
/** Taker restriction; the zero address means any taker. */
|
|
45
|
+
readonly allowedTaker: Address;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Fully materialized PriceRatifierV1 tree descriptor.
|
|
49
|
+
*
|
|
50
|
+
* Use this shape when a caller needs leaf structs, leaf hashes, root, and
|
|
51
|
+
* height, for example before custom signing or proof generation.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* import { PriceRatifierV1, type IOffer, type PriceRatifierV1TreeDescriptor } from "@morpho-org/midnight-sdk";
|
|
56
|
+
*
|
|
57
|
+
* function build(offer: IOffer): PriceRatifierV1TreeDescriptor {
|
|
58
|
+
* return PriceRatifierV1.buildDescriptor([{ offer }]);
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export interface PriceRatifierV1TreeDescriptor extends TreeData<PriceRatifierV1LeafStruct> {
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Decoded PriceRatifierV1 ratifier data.
|
|
66
|
+
*
|
|
67
|
+
* Use this on the take-side or in diagnostics after `Payload.decode` when you
|
|
68
|
+
* need to inspect the proof and allowed taker attached to a
|
|
69
|
+
* PriceRatifierV1-ratified offer.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* import { PriceRatifierV1, type DecodedPriceRatifierV1Data } from "@morpho-org/midnight-sdk";
|
|
74
|
+
* import { zeroAddress, zeroHash } from "viem";
|
|
75
|
+
*
|
|
76
|
+
* const data = PriceRatifierV1.encodeRatifierData({
|
|
77
|
+
* root: zeroHash,
|
|
78
|
+
* leafIndex: 0n,
|
|
79
|
+
* proof: [],
|
|
80
|
+
* allowedTaker: zeroAddress,
|
|
81
|
+
* });
|
|
82
|
+
* const decoded: DecodedPriceRatifierV1Data =
|
|
83
|
+
* PriceRatifierV1.decodeRatifierData(data);
|
|
84
|
+
* console.log(decoded.allowedTaker);
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
export interface DecodedPriceRatifierV1Data extends TreeProof {
|
|
88
|
+
/** Taker restriction proven by the leaf; the zero address means any taker. */
|
|
89
|
+
readonly allowedTaker: Address;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Tree-like input accepted by PriceRatifierV1 helpers.
|
|
93
|
+
*
|
|
94
|
+
* Both a {@link PriceRatifierV1TreeDescriptor} and raw leaf input are
|
|
95
|
+
* accepted; caller-provided descriptors are fully re-validated (leaf hashes
|
|
96
|
+
* and root recomputed) before use.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* import type { IOffer, PriceRatifierV1TreeInput } from "@morpho-org/midnight-sdk";
|
|
101
|
+
*
|
|
102
|
+
* function input(offer: IOffer): PriceRatifierV1TreeInput {
|
|
103
|
+
* return [{ offer }];
|
|
104
|
+
* }
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
export type PriceRatifierV1TreeInput = (PriceRatifierV1TreeDescriptor & {
|
|
108
|
+
readonly type?: undefined;
|
|
109
|
+
}) | TreeSnapshot<"priceV1"> | readonly PriceRatifierV1Leaf[];
|
|
110
|
+
/**
|
|
111
|
+
* PriceRatifierV1-specific pure utilities.
|
|
112
|
+
*
|
|
113
|
+
* Use this route when makers ratify a Merkle root of price-bounded offers
|
|
114
|
+
* onchain. The make-side sequence is: create offers with the PriceRatifierV1
|
|
115
|
+
* address, build the tree descriptor, ratify the root onchain (directly or
|
|
116
|
+
* through `setIsRootRatified`), then call `ratify` and pass the returned items
|
|
117
|
+
* to `Payload.encode`.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* import { PriceRatifierV1 } from "@morpho-org/midnight-sdk";
|
|
122
|
+
*
|
|
123
|
+
* console.log(typeof PriceRatifierV1.ratify);
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
export declare namespace PriceRatifierV1 {
|
|
127
|
+
/**
|
|
128
|
+
* Computes the PriceRatifierV1 EIP-712 leaf hash for one leaf struct.
|
|
129
|
+
*
|
|
130
|
+
* This is the SDK port of `HashLib.hashPriceRatifierV1Offer`: the offer's
|
|
131
|
+
* `tick` is kept and `allowedTaker` is appended after it.
|
|
132
|
+
*
|
|
133
|
+
* @param leaf - ABI-compatible leaf to hash.
|
|
134
|
+
* @returns Leaf hash used in the ratified Merkle tree.
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts
|
|
137
|
+
* import { PriceRatifierV1, type OfferStruct } from "@morpho-org/midnight-sdk";
|
|
138
|
+
* import { zeroAddress } from "viem";
|
|
139
|
+
*
|
|
140
|
+
* function hash(offer: OfferStruct) {
|
|
141
|
+
* return PriceRatifierV1.hashLeaf({
|
|
142
|
+
* offer,
|
|
143
|
+
* allowedTaker: zeroAddress,
|
|
144
|
+
* });
|
|
145
|
+
* }
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
function hashLeaf(leaf: PriceRatifierV1LeafStruct): Hash;
|
|
149
|
+
/**
|
|
150
|
+
* Zero-group member hash of one leaf, as consumed by `GroupUtils.hashMembers`.
|
|
151
|
+
*
|
|
152
|
+
* This is what the router recomputes for its `group_identity` check: the
|
|
153
|
+
* PriceRatifierV1 leaf hash with `group = 0`, so the id also commits to
|
|
154
|
+
* `allowedTaker`.
|
|
155
|
+
*
|
|
156
|
+
* @param leaf - Price-committed offer leaf.
|
|
157
|
+
* @returns Zero-group PriceRatifierV1 leaf hash.
|
|
158
|
+
* @example
|
|
159
|
+
* ```ts
|
|
160
|
+
* import { Offer, PriceRatifierV1 } from "@morpho-org/midnight-sdk";
|
|
161
|
+
* import { zeroAddress } from "viem";
|
|
162
|
+
*
|
|
163
|
+
* const offer = Offer.create({
|
|
164
|
+
* market: {
|
|
165
|
+
* chainId: 8453,
|
|
166
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
167
|
+
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
168
|
+
* collateralParams: [
|
|
169
|
+
* {
|
|
170
|
+
* token: "0x0000000000000000000000000000000000007000",
|
|
171
|
+
* lltv: 770000000000000000n,
|
|
172
|
+
* liquidationCursor: 250000000000000000n,
|
|
173
|
+
* oracle: "0x0000000000000000000000000000000000008000",
|
|
174
|
+
* },
|
|
175
|
+
* ],
|
|
176
|
+
* maturity: 54_000n,
|
|
177
|
+
* rcfThreshold: 0n,
|
|
178
|
+
* enterGate: zeroAddress,
|
|
179
|
+
* liquidatorGate: zeroAddress,
|
|
180
|
+
* },
|
|
181
|
+
* buy: true,
|
|
182
|
+
* maker: "0x0000000000000000000000000000000000009000",
|
|
183
|
+
* tick: 5_000n,
|
|
184
|
+
* expiry: 3_600n,
|
|
185
|
+
* ratifier: "0x000000000000000000000000000000000000a111",
|
|
186
|
+
* maxUnits: 100n,
|
|
187
|
+
* });
|
|
188
|
+
*
|
|
189
|
+
* console.log(PriceRatifierV1.memberHash({ offer }));
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
function memberHash(leaf: PriceRatifierV1Leaf): Hash;
|
|
193
|
+
/**
|
|
194
|
+
* Content-addressed consumption group id for PriceRatifierV1 leaves.
|
|
195
|
+
*
|
|
196
|
+
* Mirrors `GroupUtils.hash` with the PriceRatifierV1 {@link memberHash}, so
|
|
197
|
+
* it matches the router-derived group. Use it to share one group across
|
|
198
|
+
* several leaves; single leaves get this id by default in
|
|
199
|
+
* {@link buildDescriptor}. Leaves sharing a group must satisfy the same
|
|
200
|
+
* constraints as `Group.create` (one maker, side, and cap mode/value); this
|
|
201
|
+
* helper only derives the id and does not check them.
|
|
202
|
+
*
|
|
203
|
+
* @param leaves - Leaves sharing one consumption group.
|
|
204
|
+
* @returns Content-addressed group id.
|
|
205
|
+
* @throws {InvalidOfferGroupError} when `leaves` is empty.
|
|
206
|
+
* @example
|
|
207
|
+
* ```ts
|
|
208
|
+
* import { Offer, PriceRatifierV1 } from "@morpho-org/midnight-sdk";
|
|
209
|
+
* import { zeroAddress } from "viem";
|
|
210
|
+
*
|
|
211
|
+
* const offer = Offer.create({
|
|
212
|
+
* market: {
|
|
213
|
+
* chainId: 8453,
|
|
214
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
215
|
+
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
216
|
+
* collateralParams: [
|
|
217
|
+
* {
|
|
218
|
+
* token: "0x0000000000000000000000000000000000007000",
|
|
219
|
+
* lltv: 770000000000000000n,
|
|
220
|
+
* liquidationCursor: 250000000000000000n,
|
|
221
|
+
* oracle: "0x0000000000000000000000000000000000008000",
|
|
222
|
+
* },
|
|
223
|
+
* ],
|
|
224
|
+
* maturity: 54_000n,
|
|
225
|
+
* rcfThreshold: 0n,
|
|
226
|
+
* enterGate: zeroAddress,
|
|
227
|
+
* liquidatorGate: zeroAddress,
|
|
228
|
+
* },
|
|
229
|
+
* buy: true,
|
|
230
|
+
* maker: "0x0000000000000000000000000000000000009000",
|
|
231
|
+
* tick: 5_000n,
|
|
232
|
+
* expiry: 3_600n,
|
|
233
|
+
* ratifier: "0x000000000000000000000000000000000000a111",
|
|
234
|
+
* maxUnits: 100n,
|
|
235
|
+
* });
|
|
236
|
+
* const leaves = [{ offer }, { offer: Offer.from({ ...offer, tick: 5_004n }) }];
|
|
237
|
+
*
|
|
238
|
+
* const group = PriceRatifierV1.groupId(leaves);
|
|
239
|
+
* const grouped = leaves.map((leaf) => ({
|
|
240
|
+
* ...leaf,
|
|
241
|
+
* offer: Offer.from({ ...leaf.offer, group }),
|
|
242
|
+
* }));
|
|
243
|
+
* ```
|
|
244
|
+
*/
|
|
245
|
+
function groupId(leaves: Iterable<PriceRatifierV1Leaf>): Hash;
|
|
246
|
+
/**
|
|
247
|
+
* Builds a PriceRatifierV1 tree descriptor from leaf input.
|
|
248
|
+
*
|
|
249
|
+
* Non-power-of-two leaf lists are padded with protocol-zero leaves at the
|
|
250
|
+
* highest leaf indices. A group matching the generic content id of all
|
|
251
|
+
* leaves sharing it (for example from `OfferUtils.toStruct` or
|
|
252
|
+
* `Group.create`) is re-derived with {@link groupId}; other explicit groups
|
|
253
|
+
* are committed as-is. An omitted `group` defaults to the leaf's
|
|
254
|
+
* content-addressed singleton {@link groupId}, which commits to
|
|
255
|
+
* `allowedTaker` like the router does.
|
|
256
|
+
*
|
|
257
|
+
* @param leaves - Price-bounded offer leaves in leaf order.
|
|
258
|
+
* @returns PriceRatifierV1 tree descriptor.
|
|
259
|
+
* @throws {InvalidTreeError} when the leaf list is empty, contains duplicate leaf hashes, or mixes ratifier addresses.
|
|
260
|
+
* @throws {InvalidTreeHeightError} when the padded tree exceeds supported ratifier typehashes.
|
|
261
|
+
* @example
|
|
262
|
+
* ```ts
|
|
263
|
+
* import { PriceRatifierV1, type IOffer } from "@morpho-org/midnight-sdk";
|
|
264
|
+
*
|
|
265
|
+
* function build(offer: IOffer) {
|
|
266
|
+
* return PriceRatifierV1.buildDescriptor([{ offer }]);
|
|
267
|
+
* }
|
|
268
|
+
* ```
|
|
269
|
+
*/
|
|
270
|
+
function buildDescriptor(leaves: readonly PriceRatifierV1Leaf[]): PriceRatifierV1TreeDescriptor;
|
|
271
|
+
/**
|
|
272
|
+
* Builds a Merkle proof for one PriceRatifierV1 leaf.
|
|
273
|
+
*
|
|
274
|
+
* @param params.tree - PriceRatifierV1 tree descriptor or raw leaf input.
|
|
275
|
+
* @param params.leafIndex - Leaf index to prove.
|
|
276
|
+
* @returns Proof descriptor.
|
|
277
|
+
* @throws {InvalidTreeError} when the tree is invalid or the leaf index is out of range.
|
|
278
|
+
* @throws {InvalidTreeHeightError} when the tree exceeds the supported height.
|
|
279
|
+
* @example
|
|
280
|
+
* ```ts
|
|
281
|
+
* import { PriceRatifierV1, type IOffer } from "@morpho-org/midnight-sdk";
|
|
282
|
+
*
|
|
283
|
+
* function build(offer: IOffer) {
|
|
284
|
+
* return PriceRatifierV1.buildProof({
|
|
285
|
+
* tree: PriceRatifierV1.buildDescriptor([{ offer }]),
|
|
286
|
+
* leafIndex: 0n,
|
|
287
|
+
* });
|
|
288
|
+
* }
|
|
289
|
+
* ```
|
|
290
|
+
*/
|
|
291
|
+
function buildProof(params: {
|
|
292
|
+
readonly tree: PriceRatifierV1TreeInput;
|
|
293
|
+
readonly leafIndex: BigIntish;
|
|
294
|
+
}): TreeProof;
|
|
295
|
+
/**
|
|
296
|
+
* Encodes PriceRatifierV1 ratifier data.
|
|
297
|
+
*
|
|
298
|
+
* Use only when you already have a root, proof, and allowed taker. Most
|
|
299
|
+
* maker flows call `ratifierData` for one leaf or `ratify` for every leaf
|
|
300
|
+
* in the ratified tree.
|
|
301
|
+
*
|
|
302
|
+
* @param params.root - Merkle root ratified by the maker's PriceRatifierV1.
|
|
303
|
+
* @param params.leafIndex - Leaf index proven by `params.proof`.
|
|
304
|
+
* @param params.proof - Merkle proof siblings for the leaf.
|
|
305
|
+
* @param params.allowedTaker - Taker restriction carried by the leaf.
|
|
306
|
+
* @returns ABI-encoded ratifier data.
|
|
307
|
+
* @example
|
|
308
|
+
* ```ts
|
|
309
|
+
* import { PriceRatifierV1 } from "@morpho-org/midnight-sdk";
|
|
310
|
+
* import { zeroAddress, zeroHash } from "viem";
|
|
311
|
+
*
|
|
312
|
+
* const data = PriceRatifierV1.encodeRatifierData({
|
|
313
|
+
* root: zeroHash,
|
|
314
|
+
* leafIndex: 0n,
|
|
315
|
+
* proof: [],
|
|
316
|
+
* allowedTaker: zeroAddress,
|
|
317
|
+
* });
|
|
318
|
+
* console.log(data);
|
|
319
|
+
* ```
|
|
320
|
+
*/
|
|
321
|
+
function encodeRatifierData(params: {
|
|
322
|
+
readonly root: Hash;
|
|
323
|
+
readonly leafIndex: BigIntish;
|
|
324
|
+
readonly proof: readonly Hash[];
|
|
325
|
+
readonly allowedTaker: Address;
|
|
326
|
+
}): `0x${string}`;
|
|
327
|
+
/**
|
|
328
|
+
* Decodes PriceRatifierV1 ratifier data.
|
|
329
|
+
*
|
|
330
|
+
* Use on the take-side or in tests after `Payload.decode` to inspect the
|
|
331
|
+
* proof and allowed taker attached to a published offer.
|
|
332
|
+
*
|
|
333
|
+
* @param data - ABI-encoded ratifier data.
|
|
334
|
+
* @returns Decoded PriceRatifierV1 ratifier data.
|
|
335
|
+
* @example
|
|
336
|
+
* ```ts
|
|
337
|
+
* import { PriceRatifierV1 } from "@morpho-org/midnight-sdk";
|
|
338
|
+
* import { zeroAddress, zeroHash } from "viem";
|
|
339
|
+
*
|
|
340
|
+
* const decoded = PriceRatifierV1.decodeRatifierData(
|
|
341
|
+
* PriceRatifierV1.encodeRatifierData({
|
|
342
|
+
* root: zeroHash,
|
|
343
|
+
* leafIndex: 0n,
|
|
344
|
+
* proof: [],
|
|
345
|
+
* allowedTaker: zeroAddress,
|
|
346
|
+
* }),
|
|
347
|
+
* );
|
|
348
|
+
* console.log(decoded.allowedTaker);
|
|
349
|
+
* ```
|
|
350
|
+
*/
|
|
351
|
+
function decodeRatifierData(data: Hex): DecodedPriceRatifierV1Data;
|
|
352
|
+
/**
|
|
353
|
+
* Verifies that PriceRatifierV1 ratifier data proves one payload offer
|
|
354
|
+
* belongs to its root.
|
|
355
|
+
*
|
|
356
|
+
* This helper intentionally does not check the onchain
|
|
357
|
+
* `PriceRatifierV1.ratification` state. Consumers can query that value at
|
|
358
|
+
* their own block context after local proof verification.
|
|
359
|
+
*
|
|
360
|
+
* @param params.offer - Offer carried by the payload item.
|
|
361
|
+
* @param params.ratifierData - ABI-encoded PriceRatifierV1 ratifier data.
|
|
362
|
+
* @param params.taker - Optional taker to check against the leaf's allowed taker.
|
|
363
|
+
* @returns Decoded PriceRatifierV1 ratifier data after proof verification.
|
|
364
|
+
* @throws {InvalidTreeError} when the proof does not include `offer` in `root`.
|
|
365
|
+
* @throws {RatifierV1TakerNotAllowedError} when `taker` is not the leaf's allowed taker.
|
|
366
|
+
* @example
|
|
367
|
+
* ```ts
|
|
368
|
+
* import { PriceRatifierV1, type IOffer } from "@morpho-org/midnight-sdk";
|
|
369
|
+
* import type { Hex } from "viem";
|
|
370
|
+
*
|
|
371
|
+
* function check(offer: IOffer, ratifierData: Hex) {
|
|
372
|
+
* return PriceRatifierV1.verifyRatifierData({ offer, ratifierData });
|
|
373
|
+
* }
|
|
374
|
+
* ```
|
|
375
|
+
*/
|
|
376
|
+
function verifyRatifierData(params: {
|
|
377
|
+
readonly offer: IOffer;
|
|
378
|
+
readonly ratifierData: Hex;
|
|
379
|
+
readonly taker?: Address;
|
|
380
|
+
}): DecodedPriceRatifierV1Data;
|
|
381
|
+
/**
|
|
382
|
+
* Builds one ratifier-data value for a tree leaf.
|
|
383
|
+
*
|
|
384
|
+
* Use after root ratification when a caller needs data for one offer leaf.
|
|
385
|
+
* Use `ratify` to produce payload-ready items for the whole tree.
|
|
386
|
+
*
|
|
387
|
+
* @param params.tree - PriceRatifierV1 tree descriptor or raw leaf input.
|
|
388
|
+
* @param params.leafIndex - Leaf index to prove.
|
|
389
|
+
* @returns ABI-encoded PriceRatifierV1 data.
|
|
390
|
+
* @throws {InvalidTreeError} when the tree is invalid, the leaf index is outside the tree, or the tree contains multiple ratifiers.
|
|
391
|
+
* @throws {InvalidTreeHeightError} when the tree exceeds the supported height.
|
|
392
|
+
* @example
|
|
393
|
+
* ```ts
|
|
394
|
+
* import { PriceRatifierV1, type IOffer } from "@morpho-org/midnight-sdk";
|
|
395
|
+
*
|
|
396
|
+
* function build(offer: IOffer) {
|
|
397
|
+
* return PriceRatifierV1.ratifierData({
|
|
398
|
+
* tree: [{ offer }],
|
|
399
|
+
* leafIndex: 0n,
|
|
400
|
+
* });
|
|
401
|
+
* }
|
|
402
|
+
* ```
|
|
403
|
+
*/
|
|
404
|
+
function ratifierData(params: {
|
|
405
|
+
readonly tree: PriceRatifierV1TreeInput;
|
|
406
|
+
readonly leafIndex: BigIntish;
|
|
407
|
+
}): Hex;
|
|
408
|
+
/**
|
|
409
|
+
* Returns payload-ready items after a PriceRatifierV1 root has been ratified.
|
|
410
|
+
*
|
|
411
|
+
* Use after the root ratification transaction has been submitted for every
|
|
412
|
+
* maker in the tree. The returned items can be passed directly to
|
|
413
|
+
* `Payload.encode`. All offers in the tree must use one ratifier address;
|
|
414
|
+
* build separate trees per ratifier.
|
|
415
|
+
*
|
|
416
|
+
* @param params.tree - PriceRatifierV1 tree descriptor or raw leaf input whose root has already been ratified onchain.
|
|
417
|
+
* @returns Items containing each non-padding offer and its ratifier data.
|
|
418
|
+
* @throws {InvalidTreeError} when the tree is invalid or contains multiple ratifiers.
|
|
419
|
+
* @throws {InvalidTreeHeightError} when the tree exceeds the supported height.
|
|
420
|
+
* @example
|
|
421
|
+
* ```ts
|
|
422
|
+
* import { PriceRatifierV1, type IOffer } from "@morpho-org/midnight-sdk";
|
|
423
|
+
*
|
|
424
|
+
* function build(offer: IOffer) {
|
|
425
|
+
* return PriceRatifierV1.ratify({
|
|
426
|
+
* tree: [{ offer }],
|
|
427
|
+
* });
|
|
428
|
+
* }
|
|
429
|
+
* ```
|
|
430
|
+
*/
|
|
431
|
+
function ratify(params: {
|
|
432
|
+
readonly tree: PriceRatifierV1TreeInput;
|
|
433
|
+
}): readonly Payload.Item[];
|
|
434
|
+
/**
|
|
435
|
+
* Encodes a `setIsRootRatified` call to a PriceRatifierV1 contract.
|
|
436
|
+
*
|
|
437
|
+
* Onchain, the caller must be the maker or an address authorized by the
|
|
438
|
+
* maker on the Midnight instance. The returned descriptor is neutral and
|
|
439
|
+
* never signs or submits anything.
|
|
440
|
+
*
|
|
441
|
+
* @param params.ratifier - PriceRatifierV1 contract address.
|
|
442
|
+
* @param params.maker - Maker whose ratification entry is updated.
|
|
443
|
+
* @param params.root - Merkle root to ratify or unratify.
|
|
444
|
+
* @param params.isRatified - New ratification flag for the root.
|
|
445
|
+
* @returns Neutral call descriptor.
|
|
446
|
+
* @throws {InvalidRatifierV1AddressError} when the ratifier address is the zero address.
|
|
447
|
+
* @example
|
|
448
|
+
* ```ts
|
|
449
|
+
* import { PriceRatifierV1 } from "@morpho-org/midnight-sdk";
|
|
450
|
+
* import { zeroAddress, zeroHash } from "viem";
|
|
451
|
+
*
|
|
452
|
+
* const call = PriceRatifierV1.encodeSetIsRootRatified({
|
|
453
|
+
* ratifier: "0x0000000000000000000000000000000000000001",
|
|
454
|
+
* maker: zeroAddress,
|
|
455
|
+
* root: zeroHash,
|
|
456
|
+
* isRatified: true,
|
|
457
|
+
* });
|
|
458
|
+
* console.log(call.to);
|
|
459
|
+
* ```
|
|
460
|
+
*/
|
|
461
|
+
function encodeSetIsRootRatified(params: {
|
|
462
|
+
readonly ratifier: Address;
|
|
463
|
+
readonly maker: Address;
|
|
464
|
+
readonly root: Hash;
|
|
465
|
+
readonly isRatified: boolean;
|
|
466
|
+
}): {
|
|
467
|
+
to: `0x${string}`;
|
|
468
|
+
data: `0x${string}`;
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
/** @deprecated Use {@link PriceRatifierV1}. Retained for compatibility. */
|
|
472
|
+
export { PriceRatifierV1 as PriceRatifierV1Utils };
|