@morpho-org/midnight-sdk 1.7.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/MIGRATION-v1-to-v2.md +6 -0
  2. package/README.md +63 -61
  3. package/lib/cjs/abis.d.ts +1962 -759
  4. package/lib/cjs/abis.js +2021 -995
  5. package/lib/cjs/api/helpers.d.ts +1 -17
  6. package/lib/cjs/api/helpers.js +0 -4
  7. package/lib/cjs/api/types.d.ts +5 -4
  8. package/lib/cjs/api/version.generated.d.ts +1 -1
  9. package/lib/cjs/api/version.generated.js +2 -2
  10. package/lib/cjs/bundlesV2.d.ts +15 -0
  11. package/lib/cjs/bundlesV2.js +2 -0
  12. package/lib/cjs/constants.d.ts +34 -0
  13. package/lib/cjs/constants.js +35 -1
  14. package/lib/cjs/errors.d.ts +107 -0
  15. package/lib/cjs/errors.js +139 -1
  16. package/lib/cjs/fetch/Ratifier.d.ts +4 -3
  17. package/lib/cjs/fetch/Ratifier.js +6 -4
  18. package/lib/cjs/index.d.ts +8 -0
  19. package/lib/cjs/index.js +16 -1
  20. package/lib/cjs/offers/Offer.d.ts +10 -0
  21. package/lib/cjs/offers/Offer.js +15 -1
  22. package/lib/cjs/offers/OfferUtils.d.ts +3 -0
  23. package/lib/cjs/offers/OfferUtils.js +3 -0
  24. package/lib/cjs/signatures/{EcrecoverRatifierUtils.d.ts → EcrecoverRatifier.d.ts} +118 -2
  25. package/lib/cjs/signatures/{EcrecoverRatifierUtils.js → EcrecoverRatifier.js} +146 -9
  26. package/lib/cjs/signatures/GroupUtils.d.ts +55 -2
  27. package/lib/cjs/signatures/GroupUtils.js +64 -5
  28. package/lib/cjs/signatures/Payload.d.ts +3 -3
  29. package/lib/cjs/signatures/PriceRatifierV1.d.ts +472 -0
  30. package/lib/cjs/signatures/PriceRatifierV1.js +521 -0
  31. package/lib/cjs/signatures/RateRatifierV1.d.ts +581 -0
  32. package/lib/cjs/signatures/RateRatifierV1.js +696 -0
  33. package/lib/{esm/signatures/RatifierUtils.d.ts → cjs/signatures/Ratifier.d.ts} +14 -12
  34. package/lib/cjs/signatures/{RatifierUtils.js → Ratifier.js} +29 -29
  35. package/lib/cjs/signatures/{SetterRatifierUtils.d.ts → SetterRatifier.d.ts} +50 -3
  36. package/lib/cjs/signatures/{SetterRatifierUtils.js → SetterRatifier.js} +65 -7
  37. package/lib/cjs/signatures/Tree.d.ts +94 -17
  38. package/lib/cjs/signatures/Tree.js +146 -111
  39. package/lib/cjs/signatures/TreeUtils.d.ts +191 -21
  40. package/lib/cjs/signatures/TreeUtils.js +320 -134
  41. package/lib/cjs/signatures/index.d.ts +7 -3
  42. package/lib/cjs/signatures/index.js +5 -3
  43. package/lib/cjs/signatures/ratifierRequests.d.ts +55 -0
  44. package/lib/cjs/signatures/ratifierRequests.js +2 -0
  45. package/lib/cjs/signatures/ratifierV1Internal.d.ts +57 -0
  46. package/lib/cjs/signatures/ratifierV1Internal.js +183 -0
  47. package/lib/cjs/signatures/standardRatifierInternal.d.ts +4 -0
  48. package/lib/cjs/signatures/standardRatifierInternal.js +12 -0
  49. package/lib/cjs/signatures/treeMathInternal.d.ts +4 -0
  50. package/lib/cjs/signatures/treeMathInternal.js +12 -0
  51. package/lib/cjs/signatures/treeTypes.d.ts +109 -0
  52. package/lib/cjs/signatures/treeTypes.js +2 -0
  53. package/lib/esm/abis.d.ts +1962 -759
  54. package/lib/esm/abis.js +2020 -994
  55. package/lib/esm/api/helpers.d.ts +1 -17
  56. package/lib/esm/api/helpers.js +4 -4
  57. package/lib/esm/api/types.d.ts +5 -4
  58. package/lib/esm/api/version.generated.d.ts +1 -1
  59. package/lib/esm/api/version.generated.js +2 -2
  60. package/lib/esm/bundlesV2.d.ts +15 -0
  61. package/lib/esm/bundlesV2.js +1 -0
  62. package/lib/esm/constants.d.ts +34 -0
  63. package/lib/esm/constants.js +34 -0
  64. package/lib/esm/errors.d.ts +107 -0
  65. package/lib/esm/errors.js +132 -0
  66. package/lib/esm/fetch/Ratifier.d.ts +4 -3
  67. package/lib/esm/fetch/Ratifier.js +6 -4
  68. package/lib/esm/index.d.ts +8 -0
  69. package/lib/esm/index.js +5 -0
  70. package/lib/esm/offers/Offer.d.ts +10 -0
  71. package/lib/esm/offers/Offer.js +15 -1
  72. package/lib/esm/offers/OfferUtils.d.ts +3 -0
  73. package/lib/esm/offers/OfferUtils.js +3 -0
  74. package/lib/esm/signatures/{EcrecoverRatifierUtils.d.ts → EcrecoverRatifier.d.ts} +118 -2
  75. package/lib/esm/signatures/{EcrecoverRatifierUtils.js → EcrecoverRatifier.js} +146 -9
  76. package/lib/esm/signatures/GroupUtils.d.ts +55 -2
  77. package/lib/esm/signatures/GroupUtils.js +64 -5
  78. package/lib/esm/signatures/Payload.d.ts +3 -3
  79. package/lib/esm/signatures/PriceRatifierV1.d.ts +472 -0
  80. package/lib/esm/signatures/PriceRatifierV1.js +520 -0
  81. package/lib/esm/signatures/RateRatifierV1.d.ts +581 -0
  82. package/lib/esm/signatures/RateRatifierV1.js +695 -0
  83. package/lib/{cjs/signatures/RatifierUtils.d.ts → esm/signatures/Ratifier.d.ts} +14 -12
  84. package/lib/esm/signatures/{RatifierUtils.js → Ratifier.js} +31 -29
  85. package/lib/esm/signatures/{SetterRatifierUtils.d.ts → SetterRatifier.d.ts} +50 -3
  86. package/lib/esm/signatures/{SetterRatifierUtils.js → SetterRatifier.js} +65 -7
  87. package/lib/esm/signatures/Tree.d.ts +94 -17
  88. package/lib/esm/signatures/Tree.js +147 -112
  89. package/lib/esm/signatures/TreeUtils.d.ts +191 -21
  90. package/lib/esm/signatures/TreeUtils.js +318 -132
  91. package/lib/esm/signatures/index.d.ts +7 -3
  92. package/lib/esm/signatures/index.js +5 -3
  93. package/lib/esm/signatures/ratifierRequests.d.ts +55 -0
  94. package/lib/esm/signatures/ratifierRequests.js +1 -0
  95. package/lib/esm/signatures/ratifierV1Internal.d.ts +57 -0
  96. package/lib/esm/signatures/ratifierV1Internal.js +176 -0
  97. package/lib/esm/signatures/standardRatifierInternal.d.ts +4 -0
  98. package/lib/esm/signatures/standardRatifierInternal.js +9 -0
  99. package/lib/esm/signatures/treeMathInternal.d.ts +4 -0
  100. package/lib/esm/signatures/treeMathInternal.js +8 -0
  101. package/lib/esm/signatures/treeTypes.d.ts +109 -0
  102. package/lib/esm/signatures/treeTypes.js +1 -0
  103. package/package.json +9 -8
@@ -0,0 +1,581 @@
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 RateRatifierV1 offer leaf.
9
+ *
10
+ * `rate` is the WAD-scaled per-second simple-interest rate the maker offers.
11
+ * `allowedTaker` optionally restricts the offer to one taker; omit it or pass
12
+ * the zero address to let anyone take.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * import type { IOffer, RateRatifierV1Leaf } from "@morpho-org/midnight-sdk";
17
+ *
18
+ * function leaf(offer: IOffer): RateRatifierV1Leaf {
19
+ * return { offer, rate: 1_0000000000000000n };
20
+ * }
21
+ * ```
22
+ */
23
+ export interface RateRatifierV1Leaf {
24
+ /** Offer carried by the leaf; the offer's `ratifier` must be the RateRatifierV1 address. */
25
+ readonly offer: IOffer;
26
+ /** WAD-scaled per-second rate bound for this leaf. */
27
+ readonly rate: BigIntish;
28
+ /** Optional taker restriction; defaults to the zero address (any taker). */
29
+ readonly allowedTaker?: Address;
30
+ }
31
+ /**
32
+ * ABI-compatible RateRatifierV1 leaf.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * import type { OfferStruct, RateRatifierV1LeafStruct } from "@morpho-org/midnight-sdk";
37
+ * import { zeroAddress } from "viem";
38
+ *
39
+ * function leaf(offer: OfferStruct): RateRatifierV1LeafStruct {
40
+ * return { offer, rate: 0n, allowedTaker: zeroAddress };
41
+ * }
42
+ * ```
43
+ */
44
+ export interface RateRatifierV1LeafStruct {
45
+ /** ABI-compatible offer. */
46
+ readonly offer: OfferStruct;
47
+ /** WAD-scaled per-second rate bound. */
48
+ readonly rate: bigint;
49
+ /** Taker restriction; the zero address means any taker. */
50
+ readonly allowedTaker: Address;
51
+ }
52
+ /**
53
+ * Fully materialized RateRatifierV1 tree descriptor.
54
+ *
55
+ * Use this shape when a caller needs leaf structs, leaf hashes, root, and
56
+ * height, for example before custom signing or proof generation.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * import { RateRatifierV1, type IOffer, type RateRatifierV1TreeDescriptor } from "@morpho-org/midnight-sdk";
61
+ *
62
+ * function build(offer: IOffer): RateRatifierV1TreeDescriptor {
63
+ * return RateRatifierV1.buildDescriptor([{ offer, rate: 0n }]);
64
+ * }
65
+ * ```
66
+ */
67
+ export interface RateRatifierV1TreeDescriptor extends TreeData<RateRatifierV1LeafStruct> {
68
+ }
69
+ /**
70
+ * Decoded RateRatifierV1 ratifier data.
71
+ *
72
+ * Use this on the take-side or in diagnostics after `Payload.decode` when you
73
+ * need to inspect the proof, rate, and allowed taker attached to a
74
+ * RateRatifierV1-ratified offer.
75
+ *
76
+ * @example
77
+ * ```ts
78
+ * import { RateRatifierV1, type DecodedRateRatifierV1Data } from "@morpho-org/midnight-sdk";
79
+ * import { zeroAddress, zeroHash } from "viem";
80
+ *
81
+ * const data = RateRatifierV1.encodeRatifierData({
82
+ * root: zeroHash,
83
+ * leafIndex: 0n,
84
+ * proof: [],
85
+ * rate: 0n,
86
+ * allowedTaker: zeroAddress,
87
+ * });
88
+ * const decoded: DecodedRateRatifierV1Data =
89
+ * RateRatifierV1.decodeRatifierData(data);
90
+ * console.log(decoded.rate);
91
+ * ```
92
+ */
93
+ export interface DecodedRateRatifierV1Data extends TreeProof {
94
+ /** WAD-scaled per-second rate bound proven by the leaf. */
95
+ readonly rate: bigint;
96
+ /** Taker restriction proven by the leaf; the zero address means any taker. */
97
+ readonly allowedTaker: Address;
98
+ }
99
+ /**
100
+ * Tree-like input accepted by RateRatifierV1 helpers.
101
+ *
102
+ * Both a {@link RateRatifierV1TreeDescriptor} and raw leaf input are
103
+ * accepted; caller-provided descriptors are fully re-validated (leaf hashes
104
+ * and root recomputed) before use.
105
+ *
106
+ * @example
107
+ * ```ts
108
+ * import type { IOffer, RateRatifierV1TreeInput } from "@morpho-org/midnight-sdk";
109
+ *
110
+ * function input(offer: IOffer): RateRatifierV1TreeInput {
111
+ * return [{ offer, rate: 0n }];
112
+ * }
113
+ * ```
114
+ */
115
+ export type RateRatifierV1TreeInput = (RateRatifierV1TreeDescriptor & {
116
+ readonly type?: undefined;
117
+ }) | TreeSnapshot<"rateV1"> | readonly RateRatifierV1Leaf[];
118
+ /**
119
+ * RateRatifierV1-specific pure utilities.
120
+ *
121
+ * Use this route when makers ratify a Merkle root of rate-bounded offers
122
+ * onchain. The make-side sequence is: create offers with the RateRatifierV1
123
+ * address, build the tree descriptor, ratify the root onchain (directly or
124
+ * through `setIsRootRatified`), then call `ratify` and pass the returned items
125
+ * to `Payload.encode`.
126
+ *
127
+ * @example
128
+ * ```ts
129
+ * import { RateRatifierV1 } from "@morpho-org/midnight-sdk";
130
+ *
131
+ * console.log(typeof RateRatifierV1.ratify);
132
+ * ```
133
+ */
134
+ export declare namespace RateRatifierV1 {
135
+ /**
136
+ * Lowest nominal `offer.tick` the router accepts for a RateRatifierV1 leaf
137
+ * (tick 3372, price >= 0.5 WAD).
138
+ *
139
+ * The router prices RateRatifierV1 offers from `rate`, but its gatekeeper
140
+ * still validates the committed `offer.tick`; ticks below this are rejected
141
+ * as `min_tick`.
142
+ *
143
+ * @example
144
+ * ```ts
145
+ * import { RateRatifierV1 } from "@morpho-org/midnight-sdk";
146
+ *
147
+ * console.log(RateRatifierV1.MIN_TICK); // 3372n
148
+ * ```
149
+ */
150
+ const MIN_TICK: bigint;
151
+ /**
152
+ * Computes the RateRatifierV1 EIP-712 leaf hash for one leaf struct.
153
+ *
154
+ * This is the SDK port of `HashLib.hashRateRatifierV1Offer`: the offer's
155
+ * `tick` field is replaced by `rate`, and `allowedTaker` is appended.
156
+ *
157
+ * @param leaf - ABI-compatible leaf to hash.
158
+ * @returns Leaf hash used in the ratified Merkle tree.
159
+ * @example
160
+ * ```ts
161
+ * import { RateRatifierV1, type OfferStruct } from "@morpho-org/midnight-sdk";
162
+ * import { zeroAddress } from "viem";
163
+ *
164
+ * function hash(offer: OfferStruct) {
165
+ * return RateRatifierV1.hashLeaf({
166
+ * offer,
167
+ * rate: 0n,
168
+ * allowedTaker: zeroAddress,
169
+ * });
170
+ * }
171
+ * ```
172
+ */
173
+ function hashLeaf(leaf: RateRatifierV1LeafStruct): Hash;
174
+ /**
175
+ * Zero-group member hash of one leaf, as consumed by `GroupUtils.hashMembers`.
176
+ *
177
+ * This is what the router recomputes for its `group_identity` check: the
178
+ * RateRatifierV1 leaf hash with `group = 0`, so the id commits to `rate`
179
+ * and `allowedTaker` rather than to `tick`.
180
+ *
181
+ * @param leaf - Rate-bounded offer leaf.
182
+ * @returns Zero-group RateRatifierV1 leaf hash.
183
+ * @throws {InvalidRateRatifierV1RateError} when `leaf.rate` is negative.
184
+ * @example
185
+ * ```ts
186
+ * import { Offer, RateRatifierV1 } from "@morpho-org/midnight-sdk";
187
+ * import { zeroAddress } from "viem";
188
+ *
189
+ * const offer = Offer.create({
190
+ * market: {
191
+ * chainId: 8453,
192
+ * midnight: "0x0000000000000000000000000000000000001000",
193
+ * loanToken: "0x0000000000000000000000000000000000006000",
194
+ * collateralParams: [
195
+ * {
196
+ * token: "0x0000000000000000000000000000000000007000",
197
+ * lltv: 770000000000000000n,
198
+ * liquidationCursor: 250000000000000000n,
199
+ * oracle: "0x0000000000000000000000000000000000008000",
200
+ * },
201
+ * ],
202
+ * maturity: 54_000n,
203
+ * rcfThreshold: 0n,
204
+ * enterGate: zeroAddress,
205
+ * liquidatorGate: zeroAddress,
206
+ * },
207
+ * buy: true,
208
+ * maker: "0x0000000000000000000000000000000000009000",
209
+ * tick: 5_000n,
210
+ * expiry: 3_600n,
211
+ * ratifier: "0x000000000000000000000000000000000000a111",
212
+ * maxUnits: 100n,
213
+ * });
214
+ *
215
+ * console.log(RateRatifierV1.memberHash({ offer, rate: 0n }));
216
+ * ```
217
+ */
218
+ function memberHash(leaf: RateRatifierV1Leaf): Hash;
219
+ /**
220
+ * Content-addressed consumption group id for RateRatifierV1 leaves.
221
+ *
222
+ * Mirrors `GroupUtils.hash` with the RateRatifierV1 {@link memberHash}, so
223
+ * it matches the router-derived group. Use it to share one group across
224
+ * several leaves; single leaves get this id by default in
225
+ * {@link buildDescriptor}. Leaves sharing a group must satisfy the same
226
+ * constraints as `Group.create` (one maker, side, and cap mode/value); this
227
+ * helper only derives the id and does not check them.
228
+ *
229
+ * @param leaves - Leaves sharing one consumption group.
230
+ * @returns Content-addressed group id.
231
+ * @throws {InvalidOfferGroupError} when `leaves` is empty.
232
+ * @throws {InvalidRateRatifierV1RateError} when a leaf rate is negative.
233
+ * @example
234
+ * ```ts
235
+ * import { Offer, RateRatifierV1 } from "@morpho-org/midnight-sdk";
236
+ * import { zeroAddress } from "viem";
237
+ *
238
+ * const offer = Offer.create({
239
+ * market: {
240
+ * chainId: 8453,
241
+ * midnight: "0x0000000000000000000000000000000000001000",
242
+ * loanToken: "0x0000000000000000000000000000000000006000",
243
+ * collateralParams: [
244
+ * {
245
+ * token: "0x0000000000000000000000000000000000007000",
246
+ * lltv: 770000000000000000n,
247
+ * liquidationCursor: 250000000000000000n,
248
+ * oracle: "0x0000000000000000000000000000000000008000",
249
+ * },
250
+ * ],
251
+ * maturity: 54_000n,
252
+ * rcfThreshold: 0n,
253
+ * enterGate: zeroAddress,
254
+ * liquidatorGate: zeroAddress,
255
+ * },
256
+ * buy: true,
257
+ * maker: "0x0000000000000000000000000000000000009000",
258
+ * tick: 5_000n,
259
+ * expiry: 3_600n,
260
+ * ratifier: "0x000000000000000000000000000000000000a111",
261
+ * maxUnits: 100n,
262
+ * });
263
+ * const leaves = [
264
+ * { offer, rate: 50_000_000_000_000_000n },
265
+ * { offer: Offer.from({ ...offer, tick: 5_004n }), rate: 60_000_000_000_000_000n },
266
+ * ];
267
+ *
268
+ * const group = RateRatifierV1.groupId(leaves);
269
+ * const grouped = leaves.map((leaf) => ({
270
+ * ...leaf,
271
+ * offer: Offer.from({ ...leaf.offer, group }),
272
+ * }));
273
+ * ```
274
+ */
275
+ function groupId(leaves: Iterable<RateRatifierV1Leaf>): Hash;
276
+ /**
277
+ * Builds a RateRatifierV1 tree descriptor from leaf input.
278
+ *
279
+ * Non-power-of-two leaf lists are padded with protocol-zero leaves at the
280
+ * highest leaf indices. A group matching the generic content id of all
281
+ * leaves sharing it (for example from `OfferUtils.toStruct` or
282
+ * `Group.create`) is re-derived with {@link groupId}; other explicit groups
283
+ * are committed as-is. An omitted `group` defaults to the leaf's
284
+ * content-addressed singleton {@link groupId}, which commits to `rate` and
285
+ * `allowedTaker` like the router does.
286
+ *
287
+ * @param leaves - Rate-bounded offer leaves in leaf order.
288
+ * @returns RateRatifierV1 tree descriptor.
289
+ * @throws {InvalidTreeError} when the leaf list is empty, contains duplicate leaf hashes, or mixes ratifier addresses.
290
+ * @throws {InvalidRateRatifierV1RateError} when a leaf rate is negative.
291
+ * @throws {InvalidRateRatifierV1TickError} when a leaf offer tick is below {@link MIN_TICK}.
292
+ * @throws {InvalidTreeHeightError} when the padded tree exceeds supported ratifier typehashes.
293
+ * @example
294
+ * ```ts
295
+ * import { RateRatifierV1, type IOffer } from "@morpho-org/midnight-sdk";
296
+ *
297
+ * function build(offer: IOffer) {
298
+ * return RateRatifierV1.buildDescriptor([{ offer, rate: 0n }]);
299
+ * }
300
+ * ```
301
+ */
302
+ function buildDescriptor(leaves: readonly RateRatifierV1Leaf[]): RateRatifierV1TreeDescriptor;
303
+ /**
304
+ * Builds a Merkle proof for one RateRatifierV1 leaf.
305
+ *
306
+ * @param params.tree - RateRatifierV1 tree descriptor or raw leaf input.
307
+ * @param params.leafIndex - Leaf index to prove.
308
+ * @returns Proof descriptor.
309
+ * @throws {InvalidTreeError} when the tree is invalid or the leaf index is out of range.
310
+ * @throws {InvalidTreeHeightError} when the tree exceeds the supported height.
311
+ * @throws {InvalidRateRatifierV1RateError} when a raw leaf carries a negative rate.
312
+ * @throws {InvalidRateRatifierV1TickError} when a leaf offer tick is below {@link MIN_TICK}, including inside a caller-supplied descriptor.
313
+ * @example
314
+ * ```ts
315
+ * import { RateRatifierV1, type IOffer } from "@morpho-org/midnight-sdk";
316
+ *
317
+ * function build(offer: IOffer) {
318
+ * return RateRatifierV1.buildProof({
319
+ * tree: RateRatifierV1.buildDescriptor([{ offer, rate: 0n }]),
320
+ * leafIndex: 0n,
321
+ * });
322
+ * }
323
+ * ```
324
+ */
325
+ function buildProof(params: {
326
+ readonly tree: RateRatifierV1TreeInput;
327
+ readonly leafIndex: BigIntish;
328
+ }): TreeProof;
329
+ /**
330
+ * Encodes RateRatifierV1 ratifier data.
331
+ *
332
+ * Use only when you already have a root, proof, rate, and allowed taker.
333
+ * Most maker flows call `ratifierData` for one leaf or `ratify` for every
334
+ * leaf in the ratified tree.
335
+ *
336
+ * @param params.root - Merkle root ratified by the maker's RateRatifierV1.
337
+ * @param params.leafIndex - Leaf index proven by `params.proof`.
338
+ * @param params.proof - Merkle proof siblings for the leaf.
339
+ * @param params.rate - WAD-scaled per-second rate bound carried by the leaf.
340
+ * @param params.allowedTaker - Taker restriction carried by the leaf.
341
+ * @returns ABI-encoded ratifier data.
342
+ * @example
343
+ * ```ts
344
+ * import { RateRatifierV1 } from "@morpho-org/midnight-sdk";
345
+ * import { zeroAddress, zeroHash } from "viem";
346
+ *
347
+ * const data = RateRatifierV1.encodeRatifierData({
348
+ * root: zeroHash,
349
+ * leafIndex: 0n,
350
+ * proof: [],
351
+ * rate: 0n,
352
+ * allowedTaker: zeroAddress,
353
+ * });
354
+ * console.log(data);
355
+ * ```
356
+ */
357
+ function encodeRatifierData(params: {
358
+ readonly root: Hash;
359
+ readonly leafIndex: BigIntish;
360
+ readonly proof: readonly Hash[];
361
+ readonly rate: BigIntish;
362
+ readonly allowedTaker: Address;
363
+ }): `0x${string}`;
364
+ /**
365
+ * Decodes RateRatifierV1 ratifier data.
366
+ *
367
+ * Use on the take-side or in tests after `Payload.decode` to inspect the
368
+ * proof, rate, and allowed taker attached to a published offer.
369
+ *
370
+ * @param data - ABI-encoded ratifier data.
371
+ * @returns Decoded RateRatifierV1 ratifier data.
372
+ * @example
373
+ * ```ts
374
+ * import { RateRatifierV1 } from "@morpho-org/midnight-sdk";
375
+ * import { zeroAddress, zeroHash } from "viem";
376
+ *
377
+ * const decoded = RateRatifierV1.decodeRatifierData(
378
+ * RateRatifierV1.encodeRatifierData({
379
+ * root: zeroHash,
380
+ * leafIndex: 0n,
381
+ * proof: [],
382
+ * rate: 0n,
383
+ * allowedTaker: zeroAddress,
384
+ * }),
385
+ * );
386
+ * console.log(decoded.rate);
387
+ * ```
388
+ */
389
+ function decodeRatifierData(data: Hex): DecodedRateRatifierV1Data;
390
+ /**
391
+ * Verifies that RateRatifierV1 ratifier data proves one payload offer
392
+ * belongs to its root.
393
+ *
394
+ * This helper intentionally does not check the onchain
395
+ * `RateRatifierV1.ratification` state or the rate-implied price bound.
396
+ * Consumers can query those values at their own block context after local
397
+ * proof verification.
398
+ *
399
+ * @param params.offer - Offer carried by the payload item.
400
+ * @param params.ratifierData - ABI-encoded RateRatifierV1 ratifier data.
401
+ * @param params.taker - Optional taker to check against the leaf's allowed taker.
402
+ * @returns Decoded RateRatifierV1 ratifier data after proof verification.
403
+ * @throws {InvalidTreeError} when the proof does not include `offer` in `root`.
404
+ * @throws {RatifierV1TakerNotAllowedError} when `taker` is not the leaf's allowed taker.
405
+ * @example
406
+ * ```ts
407
+ * import { RateRatifierV1, type IOffer } from "@morpho-org/midnight-sdk";
408
+ * import type { Hex } from "viem";
409
+ *
410
+ * function check(offer: IOffer, ratifierData: Hex) {
411
+ * return RateRatifierV1.verifyRatifierData({ offer, ratifierData });
412
+ * }
413
+ * ```
414
+ */
415
+ function verifyRatifierData(params: {
416
+ readonly offer: IOffer;
417
+ readonly ratifierData: Hex;
418
+ readonly taker?: Address;
419
+ }): DecodedRateRatifierV1Data;
420
+ /**
421
+ * Builds one ratifier-data value for a tree leaf.
422
+ *
423
+ * Use after root ratification when a caller needs data for one offer leaf.
424
+ * Use `ratify` to produce payload-ready items for the whole tree.
425
+ *
426
+ * @param params.tree - RateRatifierV1 tree descriptor or raw leaf input.
427
+ * @param params.leafIndex - Leaf index to prove.
428
+ * @returns ABI-encoded RateRatifierV1 data.
429
+ * @throws {InvalidTreeError} when the tree is invalid, the leaf index is outside the tree, or the tree contains multiple ratifiers.
430
+ * @throws {InvalidTreeHeightError} when the tree exceeds the supported height.
431
+ * @throws {InvalidRateRatifierV1RateError} when a raw leaf carries a negative rate.
432
+ * @throws {InvalidRateRatifierV1TickError} when a leaf offer tick is below {@link MIN_TICK}, including inside a caller-supplied descriptor.
433
+ * @example
434
+ * ```ts
435
+ * import { RateRatifierV1, type IOffer } from "@morpho-org/midnight-sdk";
436
+ *
437
+ * function build(offer: IOffer) {
438
+ * return RateRatifierV1.ratifierData({
439
+ * tree: [{ offer, rate: 0n }],
440
+ * leafIndex: 0n,
441
+ * });
442
+ * }
443
+ * ```
444
+ */
445
+ function ratifierData(params: {
446
+ readonly tree: RateRatifierV1TreeInput;
447
+ readonly leafIndex: BigIntish;
448
+ }): Hex;
449
+ /**
450
+ * Returns payload-ready items after a RateRatifierV1 root has been ratified.
451
+ *
452
+ * Use after the root ratification transaction has been submitted for every
453
+ * maker in the tree. The returned items can be passed directly to
454
+ * `Payload.encode`. All offers in the tree must use one ratifier address;
455
+ * build separate trees per ratifier.
456
+ *
457
+ * @param params.tree - RateRatifierV1 tree descriptor or raw leaf input whose root has already been ratified onchain.
458
+ * @returns Items containing each non-padding offer and its ratifier data.
459
+ * @throws {InvalidTreeError} when the tree is invalid or contains multiple ratifiers.
460
+ * @throws {InvalidTreeHeightError} when the tree exceeds the supported height.
461
+ * @throws {InvalidRateRatifierV1RateError} when a raw leaf carries a negative rate.
462
+ * @throws {InvalidRateRatifierV1TickError} when a leaf offer tick is below {@link MIN_TICK}, including inside a caller-supplied descriptor.
463
+ * @example
464
+ * ```ts
465
+ * import { RateRatifierV1, type IOffer } from "@morpho-org/midnight-sdk";
466
+ *
467
+ * function build(offer: IOffer) {
468
+ * return RateRatifierV1.ratify({
469
+ * tree: [{ offer, rate: 0n }],
470
+ * });
471
+ * }
472
+ * ```
473
+ */
474
+ function ratify(params: {
475
+ readonly tree: RateRatifierV1TreeInput;
476
+ }): readonly Payload.Item[];
477
+ /**
478
+ * Converts a WAD-scaled per-second rate into the price bound used by
479
+ * `RateRatifierV1.isRatified`.
480
+ *
481
+ * The bound is `WAD * WAD / (WAD + rate * timeToMaturity)`, rounded down
482
+ * for buy offers and up for sell offers, matching the onchain comparison
483
+ * direction.
484
+ *
485
+ * @param params.rate - WAD-scaled per-second rate.
486
+ * @param params.timeToMaturity - Seconds remaining until market maturity.
487
+ * @param params.buy - Whether the maker buys units.
488
+ * @returns WAD-scaled price bound.
489
+ * @throws {InvalidRateRatifierV1RateError} when `rate` is negative.
490
+ * @throws {InvalidRateRatifierV1TimeError} when `timeToMaturity` is negative.
491
+ * @throws {RateRatifierV1BoundOverflowError} when the bound arithmetic exceeds uint256, matching the contract's checked math.
492
+ * @example
493
+ * ```ts
494
+ * import { RateRatifierV1 } from "@morpho-org/midnight-sdk";
495
+ *
496
+ * const bound = RateRatifierV1.priceBound({
497
+ * rate: 0n,
498
+ * timeToMaturity: 0n,
499
+ * buy: true,
500
+ * });
501
+ * console.log(bound);
502
+ * ```
503
+ */
504
+ function priceBound(params: {
505
+ readonly rate: BigIntish;
506
+ readonly timeToMaturity: BigIntish;
507
+ readonly buy: boolean;
508
+ }): bigint;
509
+ /**
510
+ * Checks whether an offer's tick satisfies its rate bound at a timestamp.
511
+ *
512
+ * Mirrors `RateRatifierV1.isRatified`: the offer price must be at or below
513
+ * the rate-implied bound for buy offers, and at or above it for sell
514
+ * offers. Time to maturity floors at zero. Bounds that overflow uint256
515
+ * are unacceptable, matching the contract's revert.
516
+ *
517
+ * @param params.offer - Offer whose `tick`, `buy`, and `market.maturity` are checked.
518
+ * @param params.rate - WAD-scaled per-second rate bound proven by the leaf.
519
+ * @param params.timestamp - Timestamp at which acceptance is evaluated.
520
+ * @returns Whether the offer's tick price satisfies the rate bound.
521
+ * @throws {InvalidRateRatifierV1RateError} when `rate` is negative.
522
+ * @throws {InvalidRateRatifierV1TimeError} when `timestamp` is negative.
523
+ * @throws {NegativeValueError} when `offer.tick` is negative.
524
+ * @throws {TickOutOfRangeError} when `offer.tick` exceeds `MAX_TICK`.
525
+ * @example
526
+ * ```ts
527
+ * import { RateRatifierV1, type IOffer } from "@morpho-org/midnight-sdk";
528
+ *
529
+ * function check(offer: IOffer) {
530
+ * return RateRatifierV1.isPriceAcceptable({
531
+ * offer,
532
+ * rate: 0n,
533
+ * timestamp: 0n,
534
+ * });
535
+ * }
536
+ * ```
537
+ */
538
+ function isPriceAcceptable(params: {
539
+ readonly offer: Pick<IOffer, "tick" | "buy" | "market">;
540
+ readonly rate: BigIntish;
541
+ readonly timestamp: BigIntish;
542
+ }): boolean;
543
+ /**
544
+ * Encodes a `setIsRootRatified` call to a RateRatifierV1 contract.
545
+ *
546
+ * Onchain, the caller must be the maker or an address authorized by the
547
+ * maker on the Midnight instance. The returned descriptor is neutral and
548
+ * never signs or submits anything.
549
+ *
550
+ * @param params.ratifier - RateRatifierV1 contract address.
551
+ * @param params.maker - Maker whose ratification entry is updated.
552
+ * @param params.root - Merkle root to ratify or unratify.
553
+ * @param params.isRatified - New ratification flag for the root.
554
+ * @returns Neutral call descriptor.
555
+ * @throws {InvalidRatifierV1AddressError} when the ratifier address is the zero address.
556
+ * @example
557
+ * ```ts
558
+ * import { RateRatifierV1 } from "@morpho-org/midnight-sdk";
559
+ * import { zeroAddress, zeroHash } from "viem";
560
+ *
561
+ * const call = RateRatifierV1.encodeSetIsRootRatified({
562
+ * ratifier: "0x0000000000000000000000000000000000000001",
563
+ * maker: zeroAddress,
564
+ * root: zeroHash,
565
+ * isRatified: true,
566
+ * });
567
+ * console.log(call.to);
568
+ * ```
569
+ */
570
+ function encodeSetIsRootRatified(params: {
571
+ readonly ratifier: Address;
572
+ readonly maker: Address;
573
+ readonly root: Hash;
574
+ readonly isRatified: boolean;
575
+ }): {
576
+ to: `0x${string}`;
577
+ data: `0x${string}`;
578
+ };
579
+ }
580
+ /** @deprecated Use {@link RateRatifierV1}. Retained for compatibility. */
581
+ export { RateRatifierV1 as RateRatifierV1Utils };