@morpho-org/midnight-sdk 0.1.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 (157) hide show
  1. package/README.md +252 -0
  2. package/lib/cjs/abis.d.ts +3170 -0
  3. package/lib/cjs/abis.js +4073 -0
  4. package/lib/cjs/api/MidnightApi.d.ts +532 -0
  5. package/lib/cjs/api/MidnightApi.js +713 -0
  6. package/lib/cjs/api/helpers.d.ts +20 -0
  7. package/lib/cjs/api/helpers.js +189 -0
  8. package/lib/cjs/api/index.d.ts +2 -0
  9. package/lib/cjs/api/index.js +21 -0
  10. package/lib/cjs/api/types.d.ts +453 -0
  11. package/lib/cjs/api/types.js +2 -0
  12. package/lib/cjs/constants.d.ts +168 -0
  13. package/lib/cjs/constants.js +187 -0
  14. package/lib/cjs/errors.d.ts +253 -0
  15. package/lib/cjs/errors.js +309 -0
  16. package/lib/cjs/fetch/Market.d.ts +65 -0
  17. package/lib/cjs/fetch/Market.js +117 -0
  18. package/lib/cjs/fetch/Offer.d.ts +74 -0
  19. package/lib/cjs/fetch/Offer.js +119 -0
  20. package/lib/cjs/fetch/Position.d.ts +85 -0
  21. package/lib/cjs/fetch/Position.js +148 -0
  22. package/lib/cjs/fetch/Ratifier.d.ts +38 -0
  23. package/lib/cjs/fetch/Ratifier.js +57 -0
  24. package/lib/cjs/fetch/index.d.ts +5 -0
  25. package/lib/cjs/fetch/index.js +21 -0
  26. package/lib/cjs/fetch/types.d.ts +57 -0
  27. package/lib/cjs/fetch/types.js +2 -0
  28. package/lib/cjs/fetch/utils.d.ts +8 -0
  29. package/lib/cjs/fetch/utils.js +18 -0
  30. package/lib/cjs/index.d.ts +18 -0
  31. package/lib/cjs/index.js +57 -0
  32. package/lib/cjs/market/Market.d.ts +613 -0
  33. package/lib/cjs/market/Market.js +503 -0
  34. package/lib/cjs/market/MarketUtils.d.ts +189 -0
  35. package/lib/cjs/market/MarketUtils.js +303 -0
  36. package/lib/cjs/market/Position.d.ts +424 -0
  37. package/lib/cjs/market/Position.js +425 -0
  38. package/lib/cjs/market/PositionUtils.d.ts +115 -0
  39. package/lib/cjs/market/PositionUtils.js +194 -0
  40. package/lib/cjs/market/index.d.ts +4 -0
  41. package/lib/cjs/market/index.js +20 -0
  42. package/lib/cjs/math/ConsumableUnitsLib.d.ts +57 -0
  43. package/lib/cjs/math/ConsumableUnitsLib.js +77 -0
  44. package/lib/cjs/math/TakeAmountsLib.d.ts +175 -0
  45. package/lib/cjs/math/TakeAmountsLib.js +199 -0
  46. package/lib/cjs/math/TickLib.d.ts +200 -0
  47. package/lib/cjs/math/TickLib.js +272 -0
  48. package/lib/cjs/math/index.d.ts +3 -0
  49. package/lib/cjs/math/index.js +19 -0
  50. package/lib/cjs/offers/Offer.d.ts +534 -0
  51. package/lib/cjs/offers/Offer.js +343 -0
  52. package/lib/cjs/offers/OfferUtils.d.ts +565 -0
  53. package/lib/cjs/offers/OfferUtils.js +659 -0
  54. package/lib/cjs/offers/index.d.ts +2 -0
  55. package/lib/cjs/offers/index.js +18 -0
  56. package/lib/cjs/package.json +1 -0
  57. package/lib/cjs/queries/GetPosition.d.ts +55 -0
  58. package/lib/cjs/queries/GetPosition.js +74 -0
  59. package/lib/cjs/queries/index.d.ts +1 -0
  60. package/lib/cjs/queries/index.js +37 -0
  61. package/lib/cjs/signatures/EcrecoverRatifierUtils.d.ts +733 -0
  62. package/lib/cjs/signatures/EcrecoverRatifierUtils.js +618 -0
  63. package/lib/cjs/signatures/Group.d.ts +178 -0
  64. package/lib/cjs/signatures/Group.js +193 -0
  65. package/lib/cjs/signatures/GroupUtils.d.ts +191 -0
  66. package/lib/cjs/signatures/GroupUtils.js +127 -0
  67. package/lib/cjs/signatures/Payload.d.ts +283 -0
  68. package/lib/cjs/signatures/Payload.js +570 -0
  69. package/lib/cjs/signatures/RatifierUtils.d.ts +109 -0
  70. package/lib/cjs/signatures/RatifierUtils.js +76 -0
  71. package/lib/cjs/signatures/SetterRatifierUtils.d.ts +243 -0
  72. package/lib/cjs/signatures/SetterRatifierUtils.js +217 -0
  73. package/lib/cjs/signatures/Tree.d.ts +241 -0
  74. package/lib/cjs/signatures/Tree.js +263 -0
  75. package/lib/cjs/signatures/TreeUtils.d.ts +573 -0
  76. package/lib/cjs/signatures/TreeUtils.js +461 -0
  77. package/lib/cjs/signatures/index.d.ts +7 -0
  78. package/lib/cjs/signatures/index.js +23 -0
  79. package/lib/esm/abis.d.ts +3170 -0
  80. package/lib/esm/abis.js +4070 -0
  81. package/lib/esm/api/MidnightApi.d.ts +532 -0
  82. package/lib/esm/api/MidnightApi.js +709 -0
  83. package/lib/esm/api/helpers.d.ts +20 -0
  84. package/lib/esm/api/helpers.js +180 -0
  85. package/lib/esm/api/index.d.ts +2 -0
  86. package/lib/esm/api/index.js +2 -0
  87. package/lib/esm/api/types.d.ts +453 -0
  88. package/lib/esm/api/types.js +1 -0
  89. package/lib/esm/constants.d.ts +168 -0
  90. package/lib/esm/constants.js +184 -0
  91. package/lib/esm/errors.d.ts +253 -0
  92. package/lib/esm/errors.js +291 -0
  93. package/lib/esm/fetch/Market.d.ts +65 -0
  94. package/lib/esm/fetch/Market.js +113 -0
  95. package/lib/esm/fetch/Offer.d.ts +74 -0
  96. package/lib/esm/fetch/Offer.js +116 -0
  97. package/lib/esm/fetch/Position.d.ts +85 -0
  98. package/lib/esm/fetch/Position.js +144 -0
  99. package/lib/esm/fetch/Ratifier.d.ts +38 -0
  100. package/lib/esm/fetch/Ratifier.js +54 -0
  101. package/lib/esm/fetch/index.d.ts +5 -0
  102. package/lib/esm/fetch/index.js +5 -0
  103. package/lib/esm/fetch/types.d.ts +57 -0
  104. package/lib/esm/fetch/types.js +1 -0
  105. package/lib/esm/fetch/utils.d.ts +8 -0
  106. package/lib/esm/fetch/utils.js +12 -0
  107. package/lib/esm/index.d.ts +18 -0
  108. package/lib/esm/index.js +18 -0
  109. package/lib/esm/market/Market.d.ts +613 -0
  110. package/lib/esm/market/Market.js +498 -0
  111. package/lib/esm/market/MarketUtils.d.ts +189 -0
  112. package/lib/esm/market/MarketUtils.js +300 -0
  113. package/lib/esm/market/Position.d.ts +424 -0
  114. package/lib/esm/market/Position.js +420 -0
  115. package/lib/esm/market/PositionUtils.d.ts +115 -0
  116. package/lib/esm/market/PositionUtils.js +191 -0
  117. package/lib/esm/market/index.d.ts +4 -0
  118. package/lib/esm/market/index.js +4 -0
  119. package/lib/esm/math/ConsumableUnitsLib.d.ts +57 -0
  120. package/lib/esm/math/ConsumableUnitsLib.js +74 -0
  121. package/lib/esm/math/TakeAmountsLib.d.ts +175 -0
  122. package/lib/esm/math/TakeAmountsLib.js +196 -0
  123. package/lib/esm/math/TickLib.d.ts +200 -0
  124. package/lib/esm/math/TickLib.js +269 -0
  125. package/lib/esm/math/index.d.ts +3 -0
  126. package/lib/esm/math/index.js +3 -0
  127. package/lib/esm/offers/Offer.d.ts +534 -0
  128. package/lib/esm/offers/Offer.js +339 -0
  129. package/lib/esm/offers/OfferUtils.d.ts +565 -0
  130. package/lib/esm/offers/OfferUtils.js +656 -0
  131. package/lib/esm/offers/index.d.ts +2 -0
  132. package/lib/esm/offers/index.js +2 -0
  133. package/lib/esm/package.json +1 -0
  134. package/lib/esm/queries/GetPosition.d.ts +55 -0
  135. package/lib/esm/queries/GetPosition.js +71 -0
  136. package/lib/esm/queries/index.d.ts +1 -0
  137. package/lib/esm/queries/index.js +1 -0
  138. package/lib/esm/signatures/EcrecoverRatifierUtils.d.ts +733 -0
  139. package/lib/esm/signatures/EcrecoverRatifierUtils.js +615 -0
  140. package/lib/esm/signatures/Group.d.ts +178 -0
  141. package/lib/esm/signatures/Group.js +189 -0
  142. package/lib/esm/signatures/GroupUtils.d.ts +191 -0
  143. package/lib/esm/signatures/GroupUtils.js +124 -0
  144. package/lib/esm/signatures/Payload.d.ts +283 -0
  145. package/lib/esm/signatures/Payload.js +564 -0
  146. package/lib/esm/signatures/RatifierUtils.d.ts +109 -0
  147. package/lib/esm/signatures/RatifierUtils.js +73 -0
  148. package/lib/esm/signatures/SetterRatifierUtils.d.ts +243 -0
  149. package/lib/esm/signatures/SetterRatifierUtils.js +214 -0
  150. package/lib/esm/signatures/Tree.d.ts +241 -0
  151. package/lib/esm/signatures/Tree.js +259 -0
  152. package/lib/esm/signatures/TreeUtils.d.ts +573 -0
  153. package/lib/esm/signatures/TreeUtils.js +458 -0
  154. package/lib/esm/signatures/index.d.ts +7 -0
  155. package/lib/esm/signatures/index.js +7 -0
  156. package/package.json +69 -0
  157. package/src/index.ts +19 -0
@@ -0,0 +1,733 @@
1
+ import { type BigIntish } from "@morpho-org/morpho-ts";
2
+ import { type Account, type Address, type Chain, type Client, type Hash, type Hex, type Signature, type Transport } from "viem";
3
+ import type { Item as PayloadItem } from "./Payload.js";
4
+ import type { Tree } from "./Tree.js";
5
+ import type { TreeProof } from "./TreeUtils.js";
6
+ declare const typedDataTypes: {
7
+ readonly EIP712Domain: readonly [{
8
+ readonly name: "chainId";
9
+ readonly type: "uint256";
10
+ }, {
11
+ readonly name: "verifyingContract";
12
+ readonly type: "address";
13
+ }];
14
+ readonly CollateralParams: readonly [{
15
+ readonly name: "token";
16
+ readonly type: "address";
17
+ }, {
18
+ readonly name: "lltv";
19
+ readonly type: "uint256";
20
+ }, {
21
+ readonly name: "maxLif";
22
+ readonly type: "uint256";
23
+ }, {
24
+ readonly name: "oracle";
25
+ readonly type: "address";
26
+ }];
27
+ readonly Market: readonly [{
28
+ readonly name: "loanToken";
29
+ readonly type: "address";
30
+ }, {
31
+ readonly name: "collateralParams";
32
+ readonly type: "CollateralParams[]";
33
+ }, {
34
+ readonly name: "maturity";
35
+ readonly type: "uint256";
36
+ }, {
37
+ readonly name: "rcfThreshold";
38
+ readonly type: "uint256";
39
+ }, {
40
+ readonly name: "enterGate";
41
+ readonly type: "address";
42
+ }, {
43
+ readonly name: "liquidatorGate";
44
+ readonly type: "address";
45
+ }];
46
+ readonly Offer: readonly [{
47
+ readonly name: "market";
48
+ readonly type: "Market";
49
+ }, {
50
+ readonly name: "buy";
51
+ readonly type: "bool";
52
+ }, {
53
+ readonly name: "maker";
54
+ readonly type: "address";
55
+ }, {
56
+ readonly name: "start";
57
+ readonly type: "uint256";
58
+ }, {
59
+ readonly name: "expiry";
60
+ readonly type: "uint256";
61
+ }, {
62
+ readonly name: "tick";
63
+ readonly type: "uint256";
64
+ }, {
65
+ readonly name: "group";
66
+ readonly type: "bytes32";
67
+ }, {
68
+ readonly name: "callback";
69
+ readonly type: "address";
70
+ }, {
71
+ readonly name: "callbackData";
72
+ readonly type: "bytes";
73
+ }, {
74
+ readonly name: "receiverIfMakerIsSeller";
75
+ readonly type: "address";
76
+ }, {
77
+ readonly name: "ratifier";
78
+ readonly type: "address";
79
+ }, {
80
+ readonly name: "reduceOnly";
81
+ readonly type: "bool";
82
+ }, {
83
+ readonly name: "maxUnits";
84
+ readonly type: "uint256";
85
+ }, {
86
+ readonly name: "maxAssets";
87
+ readonly type: "uint256";
88
+ }, {
89
+ readonly name: "continuousFeeCap";
90
+ readonly type: "uint256";
91
+ }];
92
+ };
93
+ /**
94
+ * Decoded EcrecoverRatifier ratifier data.
95
+ *
96
+ * Use this on the take-side or in diagnostics after `Payload.decode` when you
97
+ * need to inspect the signature and proof attached to an Ecrecover offer.
98
+ *
99
+ * @example
100
+ * ```ts
101
+ * import { EcrecoverRatifierUtils, type DecodedEcrecoverRatifierData } from "@morpho-org/midnight-sdk";
102
+ * import { zeroHash } from "viem";
103
+ *
104
+ * const data = EcrecoverRatifierUtils.encodeRatifierData({
105
+ * signature: { v: 27, r: zeroHash, s: zeroHash },
106
+ * root: zeroHash,
107
+ * leafIndex: 0n,
108
+ * proof: [],
109
+ * });
110
+ * const decoded: DecodedEcrecoverRatifierData =
111
+ * EcrecoverRatifierUtils.decodeRatifierData(data);
112
+ * console.log(decoded.signature.v);
113
+ * ```
114
+ */
115
+ export interface DecodedEcrecoverRatifierData extends TreeProof {
116
+ /** Ecrecover signature tuple decoded from ratifier data. */
117
+ readonly signature: Signature<number, number> & {
118
+ readonly v: number;
119
+ };
120
+ }
121
+ /**
122
+ * Ecrecover typed-data descriptor returned to signing code.
123
+ *
124
+ * Pass this descriptor to the maker or authorized signer before payload
125
+ * encoding. The resulting signature is later embedded into every payload item
126
+ * for the tree.
127
+ *
128
+ * @example
129
+ * ```ts
130
+ * import { EcrecoverRatifierUtils, Offer, Tree, type EcrecoverRatificationTypedData } from "@morpho-org/midnight-sdk";
131
+ * import { zeroAddress } from "viem";
132
+ *
133
+ * const offer = Offer.create({
134
+ * market: {
135
+ * loanToken: "0x0000000000000000000000000000000000006000",
136
+ * collateralParams: [
137
+ * {
138
+ * token: "0x0000000000000000000000000000000000007000",
139
+ * lltv: 770000000000000000n,
140
+ * maxLif: 1061007957559681697n,
141
+ * oracle: "0x0000000000000000000000000000000000008000",
142
+ * },
143
+ * ],
144
+ * maturity: 54_000n,
145
+ * rcfThreshold: 0n,
146
+ * enterGate: zeroAddress,
147
+ * liquidatorGate: zeroAddress,
148
+ * },
149
+ * buy: true,
150
+ * maker: "0x0000000000000000000000000000000000009000",
151
+ * tick: 5_000n,
152
+ * expiry: 3_600n,
153
+ * ratifier: "0x0000000000000000000000000000000000004000",
154
+ * maxUnits: 100n,
155
+ * });
156
+ * const typedData: EcrecoverRatificationTypedData =
157
+ * EcrecoverRatifierUtils.typedData({
158
+ * tree: Tree.create([offer]),
159
+ * chainId: 8453n,
160
+ * });
161
+ * console.log(typedData.primaryType);
162
+ * ```
163
+ */
164
+ export interface EcrecoverRatificationTypedData {
165
+ /** EIP-712 domain. */
166
+ readonly domain: {
167
+ readonly chainId: bigint;
168
+ readonly verifyingContract: Address;
169
+ };
170
+ /** EIP-712 type map. */
171
+ readonly types: typeof typedDataTypes & {
172
+ readonly OfferTree: readonly [
173
+ {
174
+ readonly name: "offerTree";
175
+ readonly type: string;
176
+ }
177
+ ];
178
+ };
179
+ /** Primary typed-data type. */
180
+ readonly primaryType: "OfferTree";
181
+ /** Typed-data message. */
182
+ readonly message: {
183
+ readonly offerTree: unknown;
184
+ };
185
+ }
186
+ /**
187
+ * Hex string or viem signature accepted by Ecrecover ratifier helpers.
188
+ *
189
+ * @example
190
+ * ```ts
191
+ * import type { EcrecoverSignatureInput } from "@morpho-org/midnight-sdk";
192
+ *
193
+ * const signature = "0x" as EcrecoverSignatureInput;
194
+ * console.log(signature);
195
+ * ```
196
+ */
197
+ export type EcrecoverSignatureInput = Hex | Signature | Signature<number, number>;
198
+ /**
199
+ * Parameters for {@link EcrecoverRatifierUtils.typedData}.
200
+ *
201
+ * Use these after `Tree.create` and after the maker route has been classified
202
+ * as `ecrecover`.
203
+ *
204
+ * @example
205
+ * ```ts
206
+ * import { Offer, Tree, type EcrecoverRatifierTypedDataParams } from "@morpho-org/midnight-sdk";
207
+ * import { zeroAddress } from "viem";
208
+ *
209
+ * const offer = Offer.create({
210
+ * market: {
211
+ * loanToken: "0x0000000000000000000000000000000000006000",
212
+ * collateralParams: [
213
+ * {
214
+ * token: "0x0000000000000000000000000000000000007000",
215
+ * lltv: 770000000000000000n,
216
+ * maxLif: 1061007957559681697n,
217
+ * oracle: "0x0000000000000000000000000000000000008000",
218
+ * },
219
+ * ],
220
+ * maturity: 54_000n,
221
+ * rcfThreshold: 0n,
222
+ * enterGate: zeroAddress,
223
+ * liquidatorGate: zeroAddress,
224
+ * },
225
+ * buy: true,
226
+ * maker: "0x0000000000000000000000000000000000009000",
227
+ * tick: 5_000n,
228
+ * expiry: 3_600n,
229
+ * ratifier: "0x0000000000000000000000000000000000004000",
230
+ * maxUnits: 100n,
231
+ * });
232
+ * const params: EcrecoverRatifierTypedDataParams = {
233
+ * tree: Tree.create([offer]),
234
+ * chainId: 8453n,
235
+ * };
236
+ * console.log(params.chainId);
237
+ * ```
238
+ */
239
+ export interface EcrecoverRatifierTypedDataParams {
240
+ /** Tree being ratified. */
241
+ readonly tree: Tree;
242
+ /** Chain id used by the EIP-712 domain. */
243
+ readonly chainId: BigIntish;
244
+ }
245
+ /**
246
+ * Parameters for {@link EcrecoverRatifierUtils.ratify}.
247
+ *
248
+ * Use this after tree validation. Provide either a signing client plus account
249
+ * or a signature that was produced from `typedData`.
250
+ *
251
+ * @example
252
+ * ```ts
253
+ * import { Offer, Tree, type EcrecoverRatifierRatifyParams } from "@morpho-org/midnight-sdk";
254
+ * import { zeroAddress, zeroHash } from "viem";
255
+ *
256
+ * const offer = Offer.create({
257
+ * market: {
258
+ * loanToken: "0x0000000000000000000000000000000000006000",
259
+ * collateralParams: [
260
+ * {
261
+ * token: "0x0000000000000000000000000000000000007000",
262
+ * lltv: 770000000000000000n,
263
+ * maxLif: 1061007957559681697n,
264
+ * oracle: "0x0000000000000000000000000000000000008000",
265
+ * },
266
+ * ],
267
+ * maturity: 54_000n,
268
+ * rcfThreshold: 0n,
269
+ * enterGate: zeroAddress,
270
+ * liquidatorGate: zeroAddress,
271
+ * },
272
+ * buy: true,
273
+ * maker: "0x0000000000000000000000000000000000009000",
274
+ * tick: 5_000n,
275
+ * expiry: 3_600n,
276
+ * ratifier: "0x0000000000000000000000000000000000004000",
277
+ * maxUnits: 100n,
278
+ * });
279
+ * const params: EcrecoverRatifierRatifyParams = {
280
+ * tree: Tree.create([offer]),
281
+ * signature: { v: 27, r: zeroHash, s: zeroHash },
282
+ * };
283
+ * console.log(params.tree);
284
+ * ```
285
+ */
286
+ export type EcrecoverRatifierRatifyParams = {
287
+ /** Tree being ratified. */
288
+ readonly tree: Tree;
289
+ /** Viem client whose transport signs the typed data built from `tree`. */
290
+ readonly client: Client<Transport, Chain, Account | undefined>;
291
+ /** Account that signs the tree root. It may be the maker or an address authorized by each maker. */
292
+ readonly account: Account | Address;
293
+ /** Omit when the SDK should request the signature through `client`. */
294
+ readonly signature?: undefined;
295
+ } | {
296
+ /** Tree being ratified. */
297
+ readonly tree: Tree;
298
+ /** Precomputed signature for this tree root. */
299
+ readonly signature: EcrecoverSignatureInput;
300
+ /** Omit when a precomputed signature is supplied. */
301
+ readonly client?: undefined;
302
+ /** Omit when a precomputed signature is supplied. */
303
+ readonly account?: undefined;
304
+ /** Omit when a precomputed signature is supplied. */
305
+ readonly chainId?: undefined;
306
+ };
307
+ /**
308
+ * Parameters for one EcrecoverRatifier ratifier-data value.
309
+ *
310
+ * @example
311
+ * ```ts
312
+ * import { Offer, Tree, type EcrecoverRatifierDataParams } from "@morpho-org/midnight-sdk";
313
+ * import { zeroAddress, zeroHash } from "viem";
314
+ *
315
+ * const offer = Offer.create({
316
+ * market: {
317
+ * loanToken: "0x0000000000000000000000000000000000006000",
318
+ * collateralParams: [
319
+ * {
320
+ * token: "0x0000000000000000000000000000000000007000",
321
+ * lltv: 770000000000000000n,
322
+ * maxLif: 1061007957559681697n,
323
+ * oracle: "0x0000000000000000000000000000000000008000",
324
+ * },
325
+ * ],
326
+ * maturity: 54_000n,
327
+ * rcfThreshold: 0n,
328
+ * enterGate: zeroAddress,
329
+ * liquidatorGate: zeroAddress,
330
+ * },
331
+ * buy: true,
332
+ * maker: "0x0000000000000000000000000000000000009000",
333
+ * tick: 5_000n,
334
+ * expiry: 3_600n,
335
+ * ratifier: "0x0000000000000000000000000000000000004000",
336
+ * maxUnits: 100n,
337
+ * });
338
+ * const params: EcrecoverRatifierDataParams = {
339
+ * tree: Tree.create([offer]),
340
+ * leafIndex: 0n,
341
+ * signature: { v: 27, r: zeroHash, s: zeroHash },
342
+ * };
343
+ * console.log(params.leafIndex);
344
+ * ```
345
+ */
346
+ export interface EcrecoverRatifierDataParams {
347
+ /** Tree that produced the proof. */
348
+ readonly tree: Tree;
349
+ /** Leaf index to prove. */
350
+ readonly leafIndex: BigIntish;
351
+ /** Ecrecover signature for the tree root. */
352
+ readonly signature: EcrecoverSignatureInput;
353
+ }
354
+ /**
355
+ * EcrecoverRatifier-specific pure utilities.
356
+ *
357
+ * Use this route for EOA and EIP-7702 makers. The make-side sequence is:
358
+ * create offers with the Ecrecover ratifier address, build the group/tree,
359
+ * validate the tree, sign the typed data, call `ratify`, then pass the returned
360
+ * items to `Payload.encode`. Ecrecover trees must contain one ratifier; split
361
+ * trees by ratifier before signing. The signer may be the maker or an address
362
+ * authorized by every maker in the tree.
363
+ *
364
+ * @example
365
+ * ```ts
366
+ * import { EcrecoverRatifierUtils } from "@morpho-org/midnight-sdk";
367
+ *
368
+ * console.log(EcrecoverRatifierUtils.treeTypeHash(0));
369
+ * ```
370
+ */
371
+ export declare namespace EcrecoverRatifierUtils {
372
+ /**
373
+ * Returns the Solidity HashLib tree typehash for a tree height.
374
+ *
375
+ * @param height - Tree height.
376
+ * @returns Tree typehash.
377
+ * @throws {InvalidTreeHeightError} when height exceeds 20.
378
+ * @example
379
+ * ```ts
380
+ * import { EcrecoverRatifierUtils } from "@morpho-org/midnight-sdk";
381
+ *
382
+ * console.log(EcrecoverRatifierUtils.treeTypeHash(0));
383
+ * ```
384
+ */
385
+ function treeTypeHash(height: number): "0xc27c38e446b48c820ab9c4373dc63a4a750a08165cb4bb488206ebabe045d650" | "0x4e15d8736f4406e07bf9844b1653474472a827130c61e899bf1f574a88b8d987" | "0x46d107447b480c38ef5b7f54603dba0cb23b887f302b01a998b9d8a80320dd53" | "0xd1f3607a8e81454bb3baf5f898274ab47541fffc690278a74f13e174e116be72" | "0xb2d98adca9d116c9bc02ce59ec599ac3c2d33db1c0d1217c7e411d9198d427be" | "0x5931e0597fcf986027f3118b2495a9ac22139d133f9ad2c2198e6738dc3886c5" | "0x3967d37928614a085b47e8758fbc3869a8aed63bdf60ccee8536ff2b5064da06" | "0xd6b9f5f45915a260f6e521d9b40f86c385730b6bc330590fcde212e2fea64263" | "0x080caa519dbd5328c119d9907e0fa3d9a50dc2ae4bf6dd42c93c100dbc89b51a" | "0x45da471048924165ea2ad1855ba940e454b486e71dcf1666c71a928c8844c419" | "0xa49a9434fc1836bd08097368325b31039b6a0fd44919f53e4d8f4bf814084cb0" | "0xd3e93e4525132f0187a6964dc01fef33fde414538ffd212e9f2f478c3263e0a0" | "0x25990db2d26547f92c711988300df317af57bad5cd5d9d8e787a82f95c929474" | "0x8e0c648afa977572ead40a1d10a6db2c425b8099545006d834a7b849c6166643" | "0x4b635250efa6243e277fdd0cf6df993c2943b64f10f3a0756ceb1f47ef8f9b18" | "0xbde1c927f6222c07c8df264e68b42b8382c7c2b85f4729e0df94297cfeebfa91" | "0x4d58aea1a67f94be21ab1415bf3b602592430eb9112268fd0fc4e141b1a35e76" | "0x14c03281bce13010b158e5a4a3378be394ac9e16118aedb17d82ced51e66836c" | "0x99fd3e76f43b2cc221cb9860bc6c96cda95af3fa07ef5f04e071b54aa9386d06" | "0x1b1c2f1a04968094d8d0453d49838f7a809d1202ae04a1c2e0964e442ff7988b" | "0xc8ccd3cb3267dd76f563584920ac60f2283b719917481b85fe5e10b754932455";
386
+ /**
387
+ * Builds EcrecoverRatifier typed data for a tree.
388
+ *
389
+ * Use after the tree is built and validated, before requesting the signer
390
+ * signature. The EIP-712 verifier is derived from the shared ratifier address
391
+ * on the tree offers. `ratify` calls this for you when given a client and
392
+ * account.
393
+ *
394
+ * @param params.tree - Ecrecover-ratified offer tree to sign.
395
+ * @param params.chainId - EIP-155 chain id included in the EIP-712 domain.
396
+ * @returns EIP-712 typed-data descriptor.
397
+ * @throws {InvalidTreeError} when the tree is invalid or contains multiple ratifiers.
398
+ * @throws {InvalidTreeHeightError} when the tree height is unsupported.
399
+ * @example
400
+ * ```ts
401
+ * import { EcrecoverRatifierUtils, Tree } from "@morpho-org/midnight-sdk";
402
+ * import { Offer } from "@morpho-org/midnight-sdk";
403
+ * import { zeroAddress } from "viem";
404
+ *
405
+ * const offer = Offer.create({
406
+ * market: {
407
+ * loanToken: "0x0000000000000000000000000000000000006000",
408
+ * collateralParams: [
409
+ * {
410
+ * token: "0x0000000000000000000000000000000000007000",
411
+ * lltv: 770000000000000000n,
412
+ * maxLif: 1061007957559681697n,
413
+ * oracle: "0x0000000000000000000000000000000000008000",
414
+ * },
415
+ * ],
416
+ * maturity: 54_000n,
417
+ * rcfThreshold: 0n,
418
+ * enterGate: zeroAddress,
419
+ * liquidatorGate: zeroAddress,
420
+ * },
421
+ * buy: true,
422
+ * maker: "0x0000000000000000000000000000000000009000",
423
+ * tick: 5_000n,
424
+ * expiry: 3_600n,
425
+ * ratifier: "0x0000000000000000000000000000000000004000",
426
+ * maxUnits: 100n,
427
+ * });
428
+ *
429
+ * const typedData = EcrecoverRatifierUtils.typedData({
430
+ * tree: Tree.create([offer]),
431
+ * chainId: 8453n,
432
+ * });
433
+ * console.log(typedData.primaryType);
434
+ * ```
435
+ */
436
+ function typedData(params: EcrecoverRatifierTypedDataParams): EcrecoverRatificationTypedData;
437
+ /**
438
+ * Builds the EcrecoverRatifier digest used by the Solidity ratifier.
439
+ *
440
+ * @param params.tree - Ecrecover-ratified offer tree to hash.
441
+ * @param params.chainId - EIP-155 chain id included in the EIP-712 domain.
442
+ * @returns EIP-712 digest.
443
+ * @throws {InvalidTreeError} when the tree contains multiple ratifiers.
444
+ * @throws {InvalidTreeHeightError} when height exceeds 20.
445
+ * @example
446
+ * ```ts
447
+ * import { EcrecoverRatifierUtils, Tree } from "@morpho-org/midnight-sdk";
448
+ * import { Offer } from "@morpho-org/midnight-sdk";
449
+ * import { zeroAddress } from "viem";
450
+ *
451
+ * const offer = Offer.create({
452
+ * market: {
453
+ * loanToken: "0x0000000000000000000000000000000000006000",
454
+ * collateralParams: [
455
+ * {
456
+ * token: "0x0000000000000000000000000000000000007000",
457
+ * lltv: 770000000000000000n,
458
+ * maxLif: 1061007957559681697n,
459
+ * oracle: "0x0000000000000000000000000000000000008000",
460
+ * },
461
+ * ],
462
+ * maturity: 54_000n,
463
+ * rcfThreshold: 0n,
464
+ * enterGate: zeroAddress,
465
+ * liquidatorGate: zeroAddress,
466
+ * },
467
+ * buy: true,
468
+ * maker: "0x0000000000000000000000000000000000009000",
469
+ * tick: 5_000n,
470
+ * expiry: 3_600n,
471
+ * ratifier: "0x0000000000000000000000000000000000004000",
472
+ * maxUnits: 100n,
473
+ * });
474
+ *
475
+ * const digest = EcrecoverRatifierUtils.digest({
476
+ * tree: Tree.create([offer]),
477
+ * chainId: 8453n,
478
+ * });
479
+ * console.log(digest);
480
+ * ```
481
+ */
482
+ function digest(params: EcrecoverRatifierTypedDataParams): `0x${string}`;
483
+ /**
484
+ * Signs EcrecoverRatifier typed data through a viem client.
485
+ *
486
+ * Use when app code wants the signature separately from payload item
487
+ * construction. If you only need payload items, call `ratify` with the same
488
+ * client and account. The account may be the maker or an address authorized
489
+ * by every maker in the tree; the protocol checks that authorization onchain.
490
+ *
491
+ * @param params.tree - Ecrecover-ratified offer tree to sign.
492
+ * @param params.client - Viem client whose transport signs the tree typed data.
493
+ * @param params.account - Account used to sign the tree typed data.
494
+ * @returns Signature returned by the client.
495
+ * @throws {InvalidTreeError} when the tree is invalid or contains multiple ratifiers.
496
+ * @throws {InvalidTreeHeightError} when the tree height is unsupported.
497
+ * @throws {InvalidTypedDataSignatureError} when the returned signature does not recover to `params.account`.
498
+ * @example
499
+ * ```ts
500
+ * import { EcrecoverRatifierUtils, Tree } from "@morpho-org/midnight-sdk";
501
+ * import { Offer } from "@morpho-org/midnight-sdk";
502
+ * import { createWalletClient, http, zeroAddress } from "viem";
503
+ * import { base } from "viem/chains";
504
+ *
505
+ * const offer = Offer.create({
506
+ * market: {
507
+ * loanToken: "0x0000000000000000000000000000000000006000",
508
+ * collateralParams: [
509
+ * {
510
+ * token: "0x0000000000000000000000000000000000007000",
511
+ * lltv: 770000000000000000n,
512
+ * maxLif: 1061007957559681697n,
513
+ * oracle: "0x0000000000000000000000000000000000008000",
514
+ * },
515
+ * ],
516
+ * maturity: 54_000n,
517
+ * rcfThreshold: 0n,
518
+ * enterGate: zeroAddress,
519
+ * liquidatorGate: zeroAddress,
520
+ * },
521
+ * buy: true,
522
+ * maker: "0x0000000000000000000000000000000000009000",
523
+ * tick: 5_000n,
524
+ * expiry: 3_600n,
525
+ * ratifier: "0x0000000000000000000000000000000000004000",
526
+ * maxUnits: 100n,
527
+ * });
528
+ * const client = createWalletClient({
529
+ * chain: base,
530
+ * transport: http(),
531
+ * });
532
+ *
533
+ * const signature = await EcrecoverRatifierUtils.sign({
534
+ * tree: Tree.create([offer]),
535
+ * client,
536
+ * account: offer.maker,
537
+ * });
538
+ * console.log(signature);
539
+ * ```
540
+ */
541
+ function sign(params: {
542
+ readonly tree: Tree;
543
+ readonly client: Client<Transport, Chain, Account | undefined>;
544
+ readonly account: Account | Address;
545
+ }): Promise<Hex>;
546
+ /**
547
+ * Converts a hex ECDSA signature into the Solidity tuple shape.
548
+ *
549
+ * @param signature - Hex string or tuple signature.
550
+ * @returns Signature tuple.
551
+ * @example
552
+ * ```ts
553
+ * import { EcrecoverRatifierUtils } from "@morpho-org/midnight-sdk";
554
+ * import { zeroHash } from "viem";
555
+ *
556
+ * const signature = EcrecoverRatifierUtils.toSignature({
557
+ * v: 27,
558
+ * r: zeroHash,
559
+ * s: zeroHash,
560
+ * });
561
+ * console.log(signature.v);
562
+ * ```
563
+ */
564
+ function toSignature(signature: EcrecoverSignatureInput): Signature<number, number> & {
565
+ readonly v: number;
566
+ };
567
+ /**
568
+ * Encodes EcrecoverRatifier ratifier data.
569
+ *
570
+ * Use only when you already have a signature and proof. Most maker flows call
571
+ * `ratifierData` for one leaf or `ratify` for every leaf in the tree.
572
+ *
573
+ * @param params.signature - Signature tuple encoded into the ratifier data.
574
+ * @param params.root - Merkle root approved by the signature.
575
+ * @param params.leafIndex - Leaf index proven by `params.proof`.
576
+ * @param params.proof - Merkle proof siblings for the leaf.
577
+ * @returns ABI-encoded ratifier data.
578
+ * @example
579
+ * ```ts
580
+ * import { EcrecoverRatifierUtils } from "@morpho-org/midnight-sdk";
581
+ *
582
+ * const data = EcrecoverRatifierUtils.encodeRatifierData({
583
+ * signature: {
584
+ * v: 27,
585
+ * r: "0x0000000000000000000000000000000000000000000000000000000000000000",
586
+ * s: "0x0000000000000000000000000000000000000000000000000000000000000000",
587
+ * },
588
+ * root: "0x0000000000000000000000000000000000000000000000000000000000000000",
589
+ * leafIndex: 0n,
590
+ * proof: [],
591
+ * });
592
+ * console.log(data);
593
+ * ```
594
+ */
595
+ function encodeRatifierData(params: {
596
+ readonly signature: Signature | Signature<number, number>;
597
+ readonly root: Hash;
598
+ readonly leafIndex: BigIntish;
599
+ readonly proof: readonly Hash[];
600
+ }): `0x${string}`;
601
+ /**
602
+ * Decodes EcrecoverRatifier ratifier data.
603
+ *
604
+ * Use on the take-side or in tests after `Payload.decode` to inspect the
605
+ * proof/signature attached to a published offer.
606
+ *
607
+ * @param data - ABI-encoded ratifier data.
608
+ * @returns Decoded Ecrecover ratifier data.
609
+ * @example
610
+ * ```ts
611
+ * import { EcrecoverRatifierUtils } from "@morpho-org/midnight-sdk";
612
+ * import { zeroHash } from "viem";
613
+ *
614
+ * const data = EcrecoverRatifierUtils.encodeRatifierData({
615
+ * signature: { v: 27, r: zeroHash, s: zeroHash },
616
+ * root: zeroHash,
617
+ * leafIndex: 0n,
618
+ * proof: [],
619
+ * });
620
+ * const decoded = EcrecoverRatifierUtils.decodeRatifierData(data);
621
+ * console.log(decoded.leafIndex);
622
+ * ```
623
+ */
624
+ function decodeRatifierData(data: Hex): DecodedEcrecoverRatifierData;
625
+ /**
626
+ * Builds one ratifier-data value for a tree leaf.
627
+ *
628
+ * Use after a tree has been signed when a caller needs data for one offer
629
+ * leaf. Use `ratify` to produce payload-ready items for the whole tree.
630
+ *
631
+ * @param params.tree - Ecrecover-ratified offer tree that produced the proof.
632
+ * @param params.leafIndex - Leaf index to prove.
633
+ * @param params.signature - Ecrecover signature for the tree root.
634
+ * @returns ABI-encoded EcrecoverRatifier data.
635
+ * @throws {InvalidTreeError} when the leaf index is outside the tree or the tree contains multiple ratifiers.
636
+ * @example
637
+ * ```ts
638
+ * import { EcrecoverRatifierUtils, Offer, Tree } from "@morpho-org/midnight-sdk";
639
+ * import { zeroAddress, zeroHash } from "viem";
640
+ *
641
+ * const offer = Offer.create({
642
+ * market: {
643
+ * loanToken: "0x0000000000000000000000000000000000006000",
644
+ * collateralParams: [
645
+ * {
646
+ * token: "0x0000000000000000000000000000000000007000",
647
+ * lltv: 770000000000000000n,
648
+ * maxLif: 1061007957559681697n,
649
+ * oracle: "0x0000000000000000000000000000000000008000",
650
+ * },
651
+ * ],
652
+ * maturity: 54_000n,
653
+ * rcfThreshold: 0n,
654
+ * enterGate: zeroAddress,
655
+ * liquidatorGate: zeroAddress,
656
+ * },
657
+ * buy: true,
658
+ * maker: "0x0000000000000000000000000000000000009000",
659
+ * tick: 5_000n,
660
+ * expiry: 3_600n,
661
+ * ratifier: "0x0000000000000000000000000000000000004000",
662
+ * maxUnits: 100n,
663
+ * });
664
+ * const data = EcrecoverRatifierUtils.ratifierData({
665
+ * tree: Tree.create([offer]),
666
+ * leafIndex: 0n,
667
+ * signature: { v: 27, r: zeroHash, s: zeroHash },
668
+ * });
669
+ * console.log(data);
670
+ * ```
671
+ */
672
+ function ratifierData(params: EcrecoverRatifierDataParams): Hex;
673
+ /**
674
+ * Signs or consumes a tree signature and returns payload-ready items.
675
+ *
676
+ * Use after `Tree.mempoolValidate` and before `Payload.encode`.
677
+ * The returned items preserve tree leaf order and include ratifier data
678
+ * required by takers. The group id is stored on each inline offer.
679
+ *
680
+ * @param params.tree - Ecrecover-ratified offer tree to ratify.
681
+ * @param params.client - Optional viem client whose transport signs typed data built from `params.tree`.
682
+ * @param params.account - Optional account used to sign typed data built from `params.tree`.
683
+ * @param params.signature - Optional precomputed signature for `params.tree`.
684
+ * @returns Items containing each offer and its ratifier data.
685
+ * @throws {InvalidTreeError} when the tree is invalid or contains multiple ratifiers.
686
+ * @throws {InvalidTreeHeightError} when the tree height is unsupported.
687
+ * @throws {InvalidTypedDataSignatureError} when client signing returns a signature that does not recover to `params.account`.
688
+ * @example
689
+ * ```ts
690
+ * import { EcrecoverRatifierUtils, Tree } from "@morpho-org/midnight-sdk";
691
+ * import { Offer } from "@morpho-org/midnight-sdk";
692
+ * import { createWalletClient, http, zeroAddress } from "viem";
693
+ * import { base } from "viem/chains";
694
+ *
695
+ * const offer = Offer.create({
696
+ * market: {
697
+ * loanToken: "0x0000000000000000000000000000000000006000",
698
+ * collateralParams: [
699
+ * {
700
+ * token: "0x0000000000000000000000000000000000007000",
701
+ * lltv: 770000000000000000n,
702
+ * maxLif: 1061007957559681697n,
703
+ * oracle: "0x0000000000000000000000000000000000008000",
704
+ * },
705
+ * ],
706
+ * maturity: 54_000n,
707
+ * rcfThreshold: 0n,
708
+ * enterGate: zeroAddress,
709
+ * liquidatorGate: zeroAddress,
710
+ * },
711
+ * buy: true,
712
+ * maker: "0x0000000000000000000000000000000000009000",
713
+ * tick: 5_000n,
714
+ * expiry: 3_600n,
715
+ * ratifier: "0x0000000000000000000000000000000000004000",
716
+ * maxUnits: 100n,
717
+ * });
718
+ * const client = createWalletClient({
719
+ * chain: base,
720
+ * transport: http(),
721
+ * });
722
+ *
723
+ * const items = await EcrecoverRatifierUtils.ratify({
724
+ * tree: Tree.create([offer]),
725
+ * client,
726
+ * account: offer.maker,
727
+ * });
728
+ * console.log(items.length);
729
+ * ```
730
+ */
731
+ function ratify(params: EcrecoverRatifierRatifyParams): Promise<readonly PayloadItem[]>;
732
+ }
733
+ export {};