@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,565 @@
1
+ import type { BigIntish } from "@morpho-org/morpho-ts";
2
+ import type { Address, Hash } from "viem";
3
+ import { type BuildOfferParams, type IOffer, Offer, type OfferStruct } from "./Offer.js";
4
+ /**
5
+ * Parameters for {@link OfferUtils.validateOfferGroup}.
6
+ *
7
+ * Use this lower-level shape when validating a would-be `Group` before the
8
+ * offers are committed to a tree.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import type { ValidateOfferGroupParams } from "@morpho-org/midnight-sdk";
13
+ *
14
+ * const params = { offers: [] } as ValidateOfferGroupParams;
15
+ * console.log(Array.from(params.offers).length);
16
+ * ```
17
+ */
18
+ export interface ValidateOfferGroupParams {
19
+ /** Offers to validate as one protocol consumption group. */
20
+ readonly offers: Iterable<IOffer>;
21
+ }
22
+ /**
23
+ * Parameters for {@link OfferUtils.toStruct}.
24
+ *
25
+ * The group id is read from the offer by default. Supply `group` only when a
26
+ * caller intentionally needs to encode the same offer with an override, such as
27
+ * deriving a group id from an offer hashed with the zero group id.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * import { Offer, type OfferStructParams } from "@morpho-org/midnight-sdk";
32
+ * import { zeroAddress } from "viem";
33
+ *
34
+ * const params: OfferStructParams = {
35
+ * offer: Offer.create({
36
+ * market: {
37
+ * loanToken: "0x0000000000000000000000000000000000006000",
38
+ * collateralParams: [
39
+ * {
40
+ * token: "0x0000000000000000000000000000000000007000",
41
+ * lltv: 770000000000000000n,
42
+ * maxLif: 1061007957559681697n,
43
+ * oracle: "0x0000000000000000000000000000000000008000",
44
+ * },
45
+ * ],
46
+ * maturity: 54_000n,
47
+ * rcfThreshold: 0n,
48
+ * enterGate: zeroAddress,
49
+ * liquidatorGate: zeroAddress,
50
+ * },
51
+ * buy: true,
52
+ * maker: "0x0000000000000000000000000000000000009000",
53
+ * tick: 5_000n,
54
+ * expiry: 3_600n,
55
+ * ratifier: "0x0000000000000000000000000000000000004000",
56
+ * maxUnits: 100n,
57
+ * }),
58
+ * };
59
+ * console.log(params.offer);
60
+ * ```
61
+ */
62
+ export interface OfferStructParams {
63
+ /** Offer to encode. */
64
+ readonly offer: IOffer;
65
+ /** Optional protocol group id override encoded into the ABI offer. */
66
+ readonly group?: Hash;
67
+ }
68
+ /**
69
+ * Deterministic make-offer parameters after protocol validation.
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * import type { ValidatedOfferParams } from "@morpho-org/midnight-sdk";
74
+ * import { zeroAddress } from "viem";
75
+ *
76
+ * const params: ValidatedOfferParams = {
77
+ * tick: 5_000n,
78
+ * tickSpacing: 4n,
79
+ * start: 0n,
80
+ * expiry: 3_600n,
81
+ * maxUnits: 100n,
82
+ * maxAssets: 0n,
83
+ * receiverIfMakerIsSeller: zeroAddress,
84
+ * };
85
+ * console.log(params.tick);
86
+ * ```
87
+ */
88
+ export interface ValidatedOfferParams {
89
+ /** Tick in the deployed range and aligned to `tickSpacing`. */
90
+ readonly tick: bigint;
91
+ /** Market tick spacing used to validate tick accessibility. */
92
+ readonly tickSpacing: bigint;
93
+ /** Offer start timestamp. */
94
+ readonly start: bigint;
95
+ /** Offer expiry timestamp. */
96
+ readonly expiry: bigint;
97
+ /** Maximum units, with exactly one cap non-zero. */
98
+ readonly maxUnits: bigint;
99
+ /** Maximum buyer or seller assets, with exactly one cap non-zero. */
100
+ readonly maxAssets: bigint;
101
+ /** Maximum market continuous fee accepted by this offer. */
102
+ readonly continuousFeeCap: bigint;
103
+ /** Receiver used only when maker is seller. */
104
+ readonly receiverIfMakerIsSeller: Address;
105
+ }
106
+ /**
107
+ * Object-compatible helpers for Midnight offer construction, grouping, and
108
+ * take-side encoding.
109
+ *
110
+ * Make-side apps usually call {@link Offer.create}, then `Group.create` or
111
+ * `Tree.create`. Use these helpers when you need the same validation or ABI
112
+ * conversion without depending on class instances, or when converting API data
113
+ * into the structs consumed by payload and take encoders.
114
+ *
115
+ * @example
116
+ * ```ts
117
+ * import { OfferUtils } from "@morpho-org/midnight-sdk";
118
+ *
119
+ * console.log(typeof OfferUtils.getOfferExpiry);
120
+ * ```
121
+ */
122
+ export declare namespace OfferUtils {
123
+ /**
124
+ * Converts an offer into the tuple object expected by viem ABI encoders.
125
+ *
126
+ * This is the bridge from SDK/domain objects
127
+ * into Merkle leaf hashing, payload items, and take calldata encoding.
128
+ *
129
+ * @param params.offer - Offer class or plain offer input to encode.
130
+ * @param params.group - Optional protocol group id override encoded into the ABI offer.
131
+ * @returns ABI-compatible offer.
132
+ * @example
133
+ * ```ts
134
+ * import { Offer, OfferUtils } from "@morpho-org/midnight-sdk";
135
+ * import { zeroAddress } from "viem";
136
+ *
137
+ * const offer = Offer.create({
138
+ * market: {
139
+ * loanToken: "0x0000000000000000000000000000000000006000",
140
+ * collateralParams: [
141
+ * {
142
+ * token: "0x0000000000000000000000000000000000007000",
143
+ * lltv: 770000000000000000n,
144
+ * maxLif: 1061007957559681697n,
145
+ * oracle: "0x0000000000000000000000000000000000008000",
146
+ * },
147
+ * ],
148
+ * maturity: 54_000n,
149
+ * rcfThreshold: 0n,
150
+ * enterGate: zeroAddress,
151
+ * liquidatorGate: zeroAddress,
152
+ * },
153
+ * buy: true,
154
+ * maker: "0x0000000000000000000000000000000000009000",
155
+ * tick: 5_000n,
156
+ * expiry: 3_600n,
157
+ * ratifier: "0x0000000000000000000000000000000000004000",
158
+ * maxUnits: 100n,
159
+ * });
160
+ * const struct = OfferUtils.toStruct({ offer });
161
+ * console.log(struct.tick);
162
+ * ```
163
+ */
164
+ function toStruct(params: OfferStructParams): OfferStruct;
165
+ /**
166
+ * Computes the canonical protocol offer hash for an ABI-compatible offer.
167
+ *
168
+ * Use when you already have an `OfferStruct`, for example from
169
+ * `GroupUtils.toStructs`, `TreeUtils.buildDescriptor`, or decoded payload
170
+ * bytes. Use `hash` when you still have a grouped `Offer` or grouped plain
171
+ * offer input, and `groupHash` when deriving a group id from the zero-group
172
+ * hash.
173
+ *
174
+ * @param offerStruct - ABI-compatible offer to hash.
175
+ * @returns Offer hash.
176
+ * @example
177
+ * ```ts
178
+ * import { Offer, OfferUtils } from "@morpho-org/midnight-sdk";
179
+ * import { zeroAddress, zeroHash } from "viem";
180
+ *
181
+ * const offer = Offer.create({
182
+ * market: {
183
+ * loanToken: "0x0000000000000000000000000000000000006000",
184
+ * collateralParams: [
185
+ * {
186
+ * token: "0x0000000000000000000000000000000000007000",
187
+ * lltv: 770000000000000000n,
188
+ * maxLif: 1061007957559681697n,
189
+ * oracle: "0x0000000000000000000000000000000000008000",
190
+ * },
191
+ * ],
192
+ * maturity: 54_000n,
193
+ * rcfThreshold: 0n,
194
+ * enterGate: zeroAddress,
195
+ * liquidatorGate: zeroAddress,
196
+ * },
197
+ * buy: true,
198
+ * maker: "0x0000000000000000000000000000000000009000",
199
+ * tick: 5_000n,
200
+ * expiry: 3_600n,
201
+ * ratifier: "0x0000000000000000000000000000000000004000",
202
+ * maxUnits: 100n,
203
+ * });
204
+ * const hash = OfferUtils.hashStruct(
205
+ * OfferUtils.toStruct({ offer, group: zeroHash }),
206
+ * );
207
+ * console.log(hash);
208
+ * ```
209
+ */
210
+ function hashStruct(offerStruct: OfferStruct): Hash;
211
+ /**
212
+ * Computes the canonical protocol offer hash from the offer's group id.
213
+ *
214
+ * Use this for final tree leaves and payload offers after a group has been
215
+ * assigned. Use `groupHash` for the zero-group hash that derives a group id.
216
+ *
217
+ * @param offer - Offer with the protocol group id encoded into the hash.
218
+ * @returns Offer hash.
219
+ * @example
220
+ * ```ts
221
+ * import { Offer, OfferUtils } from "@morpho-org/midnight-sdk";
222
+ * import { zeroAddress, zeroHash } from "viem";
223
+ *
224
+ * const offer = Offer.create({
225
+ * market: {
226
+ * loanToken: "0x0000000000000000000000000000000000006000",
227
+ * collateralParams: [
228
+ * {
229
+ * token: "0x0000000000000000000000000000000000007000",
230
+ * lltv: 770000000000000000n,
231
+ * maxLif: 1061007957559681697n,
232
+ * oracle: "0x0000000000000000000000000000000000008000",
233
+ * },
234
+ * ],
235
+ * maturity: 54_000n,
236
+ * rcfThreshold: 0n,
237
+ * enterGate: zeroAddress,
238
+ * liquidatorGate: zeroAddress,
239
+ * },
240
+ * buy: true,
241
+ * maker: "0x0000000000000000000000000000000000009000",
242
+ * tick: 5_000n,
243
+ * group: zeroHash,
244
+ * expiry: 3_600n,
245
+ * ratifier: "0x0000000000000000000000000000000000004000",
246
+ * maxUnits: 100n,
247
+ * });
248
+ * const hash = OfferUtils.hash(offer);
249
+ * console.log(hash);
250
+ * ```
251
+ */
252
+ function hash(offer: IOffer & {
253
+ readonly group: Hash;
254
+ }): Hash;
255
+ /**
256
+ * Computes the offer hash used to derive a content-addressed group id.
257
+ *
258
+ * The encoded group is always the protocol zero hash. Use this only for
259
+ * standalone or grouped-offer id derivation, not for final tree leaves or
260
+ * payload offers.
261
+ *
262
+ * @param offer - Offer to hash without a group id.
263
+ * @returns Offer hash encoded with the protocol zero group id.
264
+ * @example
265
+ * ```ts
266
+ * import { Offer, OfferUtils } from "@morpho-org/midnight-sdk";
267
+ * import { zeroAddress } from "viem";
268
+ *
269
+ * const offer = Offer.create({
270
+ * market: {
271
+ * loanToken: "0x0000000000000000000000000000000000006000",
272
+ * collateralParams: [
273
+ * {
274
+ * token: "0x0000000000000000000000000000000000007000",
275
+ * lltv: 770000000000000000n,
276
+ * maxLif: 1061007957559681697n,
277
+ * oracle: "0x0000000000000000000000000000000000008000",
278
+ * },
279
+ * ],
280
+ * maturity: 54_000n,
281
+ * rcfThreshold: 0n,
282
+ * enterGate: zeroAddress,
283
+ * liquidatorGate: zeroAddress,
284
+ * },
285
+ * buy: true,
286
+ * maker: "0x0000000000000000000000000000000000009000",
287
+ * tick: 5_000n,
288
+ * expiry: 3_600n,
289
+ * ratifier: "0x0000000000000000000000000000000000004000",
290
+ * maxUnits: 100n,
291
+ * });
292
+ * const hash = OfferUtils.groupHash(offer);
293
+ * console.log(hash);
294
+ * ```
295
+ */
296
+ function groupHash(offer: Omit<IOffer, "group">): Hash;
297
+ /**
298
+ * Validates and normalizes a Midnight offer tick and spacing.
299
+ *
300
+ * Use this for form-level validation before `Offer.create` when you want to
301
+ * surface a tick-specific issue. `Offer.create` calls it internally.
302
+ *
303
+ * @param params.tick - Offer tick to validate.
304
+ * @param params.tickSpacing - Optional market tick spacing; defaults to `DEFAULT_TICK_SPACING`.
305
+ * @returns Normalized tick and tick spacing.
306
+ * @throws {InvalidOfferParameterError} when the tick or spacing cannot be accepted by Midnight.
307
+ * @example
308
+ * ```ts
309
+ * import { OfferUtils } from "@morpho-org/midnight-sdk";
310
+ *
311
+ * const { tick } = OfferUtils.validateOfferTick({ tick: 4n });
312
+ * console.log(tick);
313
+ * ```
314
+ */
315
+ function validateOfferTick(params: {
316
+ readonly tick: BigIntish;
317
+ readonly tickSpacing?: BigIntish;
318
+ }): {
319
+ tick: bigint;
320
+ tickSpacing: bigint;
321
+ };
322
+ /**
323
+ * Validates and normalizes an offer start/expiry range.
324
+ *
325
+ * Use this before `Offer.create` when a UI edits dates separately from other
326
+ * offer fields. `Offer.create` calls it internally.
327
+ *
328
+ * @param params.start - Optional offer start timestamp; defaults to zero.
329
+ * @param params.expiry - Offer expiry timestamp.
330
+ * @returns Normalized start and expiry timestamps.
331
+ * @throws {InvalidOfferParameterError} when the range is negative or not strictly increasing.
332
+ * @example
333
+ * ```ts
334
+ * import { OfferUtils } from "@morpho-org/midnight-sdk";
335
+ *
336
+ * const range = OfferUtils.validateOfferTimeRange({ start: 0n, expiry: 1n });
337
+ * console.log(range.expiry);
338
+ * ```
339
+ */
340
+ function validateOfferTimeRange(params: {
341
+ readonly start?: BigIntish;
342
+ readonly expiry: BigIntish;
343
+ }): {
344
+ start: bigint;
345
+ expiry: bigint;
346
+ };
347
+ /**
348
+ * Validates and normalizes mutually exclusive offer caps.
349
+ *
350
+ * Use this before `Offer.create` when a UI lets makers choose between a unit
351
+ * cap and an asset cap. `Offer.create` calls it internally.
352
+ *
353
+ * @param params.maxUnits - Optional unit cap; defaults to zero.
354
+ * @param params.maxAssets - Optional buyer or seller asset cap; defaults to zero.
355
+ * @returns Normalized unit and asset caps.
356
+ * @throws {InvalidOfferParameterError} when caps are negative, both zero, or both non-zero.
357
+ * @example
358
+ * ```ts
359
+ * import { OfferUtils } from "@morpho-org/midnight-sdk";
360
+ *
361
+ * const caps = OfferUtils.validateOfferCaps({ maxAssets: 100n });
362
+ * console.log(caps.maxAssets);
363
+ * ```
364
+ */
365
+ function validateOfferCaps(params: {
366
+ readonly maxUnits?: BigIntish;
367
+ readonly maxAssets?: BigIntish;
368
+ }): {
369
+ maxUnits: bigint;
370
+ maxAssets: bigint;
371
+ };
372
+ /**
373
+ * Validates and normalizes the maximum continuous fee an offer accepts.
374
+ *
375
+ * Use this before `Offer.create` when a maker UI exposes fee tolerance.
376
+ * `Offer.create` calls it internally and defaults omitted values to
377
+ * {@link MAX_CONTINUOUS_FEE}.
378
+ *
379
+ * @param params.continuousFeeCap - Optional maximum market continuous fee accepted by this offer.
380
+ * @returns Normalized continuous fee cap.
381
+ * @throws {InvalidOfferParameterError} when the cap is negative.
382
+ * @example
383
+ * ```ts
384
+ * import { OfferUtils } from "@morpho-org/midnight-sdk";
385
+ *
386
+ * const cap = OfferUtils.validateContinuousFeeCap({});
387
+ * console.log(cap.continuousFeeCap);
388
+ * ```
389
+ */
390
+ function validateContinuousFeeCap(params: {
391
+ readonly continuousFeeCap?: BigIntish;
392
+ }): {
393
+ continuousFeeCap: bigint;
394
+ };
395
+ /**
396
+ * Resolves and validates the maker-seller receiver field for an offer side.
397
+ *
398
+ * Use this before `Offer.create` when side-specific receiver defaults must be
399
+ * displayed to a maker. `Offer.create` calls it internally.
400
+ *
401
+ * @param params.buy - Whether the maker buys loan assets.
402
+ * @param params.maker - Maker address used as the default sell-side receiver.
403
+ * @param params.receiverIfMakerIsSeller - Optional receiver used when maker is seller.
404
+ * @returns Receiver address to put on the offer.
405
+ * @throws {InvalidOfferParameterError} when a buy offer sets a non-zero maker-seller receiver.
406
+ * @example
407
+ * ```ts
408
+ * import { OfferUtils } from "@morpho-org/midnight-sdk";
409
+ *
410
+ * const receiver = OfferUtils.resolveReceiverIfMakerIsSeller({
411
+ * buy: true,
412
+ * maker: "0x0000000000000000000000000000000000000001",
413
+ * });
414
+ * console.log(receiver);
415
+ * ```
416
+ */
417
+ function resolveReceiverIfMakerIsSeller(params: {
418
+ readonly buy: boolean;
419
+ readonly maker: Address;
420
+ readonly receiverIfMakerIsSeller?: Address;
421
+ }): `0x${string}`;
422
+ /**
423
+ * Validates deterministic make-offer parameters without constructing an offer.
424
+ *
425
+ * Use when an app needs normalized maker input or field-level errors before
426
+ * instantiating an `Offer`. `Offer.create` uses the same validation and then
427
+ * constructs the class instance for grouping and trees.
428
+ *
429
+ * @param params.market - Market params or hydrated market this offer trades.
430
+ * @param params.buy - Whether the maker buys loan assets.
431
+ * @param params.maker - Maker address.
432
+ * @param params.tick - Offer tick.
433
+ * @param params.group - Optional consumption group id for already-grouped offers.
434
+ * @param params.tickSpacing - Optional market tick spacing; defaults to `DEFAULT_TICK_SPACING`.
435
+ * @param params.maxUnits - Optional unit cap; defaults to zero.
436
+ * @param params.maxAssets - Optional buyer or seller asset cap; defaults to zero.
437
+ * @param params.continuousFeeCap - Optional maximum market continuous fee accepted by this offer; defaults to `MAX_CONTINUOUS_FEE`.
438
+ * @param params.start - Optional offer start timestamp; defaults to zero.
439
+ * @param params.expiry - Offer expiry timestamp.
440
+ * @param params.callback - Optional callback address; defaults to the zero address.
441
+ * @param params.callbackData - Optional callback payload; defaults to `0x`.
442
+ * @param params.receiverIfMakerIsSeller - Optional receiver used when maker is seller.
443
+ * @param params.ratifier - Ratifier contract address.
444
+ * @param params.reduceOnly - Optional flag restricting the offer to exposure-reducing execution.
445
+ * @returns Normalized deterministic offer parameters.
446
+ * @throws {InvalidOfferParameterError} when a deterministic offer parameter cannot satisfy protocol rules.
447
+ * @example
448
+ * ```ts
449
+ * import { OfferUtils } from "@morpho-org/midnight-sdk";
450
+ *
451
+ * const params = OfferUtils.validateOfferParams({
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: "0x0000000000000000000000000000000000000000",
465
+ * liquidatorGate: "0x0000000000000000000000000000000000000000",
466
+ * },
467
+ * buy: true,
468
+ * maker: "0x0000000000000000000000000000000000009000",
469
+ * tick: 5_000n,
470
+ * expiry: 3_600n,
471
+ * ratifier: "0x0000000000000000000000000000000000004000",
472
+ * maxUnits: 100n,
473
+ * });
474
+ * console.log(params.maxAssets);
475
+ * ```
476
+ */
477
+ function validateOfferParams(params: BuildOfferParams): ValidatedOfferParams;
478
+ /**
479
+ * Validates protocol-level mechanics for one Midnight offer consumption group.
480
+ *
481
+ * Use before deriving a content-addressed group id. Grouped offers must share
482
+ * maker, side, loan token, cap mode, and cap value because Midnight tracks one
483
+ * consumed scalar per maker and group. `Group.create` calls this automatically;
484
+ * call it directly only when you need the normalized offers without
485
+ * constructing a `Group`.
486
+ *
487
+ * @param params.offers - Offers to validate as one protocol consumption group.
488
+ * @returns Normalized offers in the same order as the input entries.
489
+ * @throws {InvalidOfferGroupError} when the group violates protocol mechanics.
490
+ * @example
491
+ * ```ts
492
+ * import { Offer, OfferUtils } from "@morpho-org/midnight-sdk";
493
+ * import { zeroAddress } from "viem";
494
+ *
495
+ * const offer = Offer.create({
496
+ * market: {
497
+ * loanToken: "0x0000000000000000000000000000000000006000",
498
+ * collateralParams: [
499
+ * {
500
+ * token: "0x0000000000000000000000000000000000007000",
501
+ * lltv: 770000000000000000n,
502
+ * maxLif: 1061007957559681697n,
503
+ * oracle: "0x0000000000000000000000000000000000008000",
504
+ * },
505
+ * ],
506
+ * maturity: 54_000n,
507
+ * rcfThreshold: 0n,
508
+ * enterGate: zeroAddress,
509
+ * liquidatorGate: zeroAddress,
510
+ * },
511
+ * buy: true,
512
+ * maker: "0x0000000000000000000000000000000000009000",
513
+ * tick: 5_000n,
514
+ * expiry: 3_600n,
515
+ * ratifier: "0x0000000000000000000000000000000000004000",
516
+ * maxUnits: 100n,
517
+ * });
518
+ * const offers = OfferUtils.validateOfferGroup({ offers: [offer] });
519
+ * console.log(offers.length);
520
+ * ```
521
+ */
522
+ function validateOfferGroup(params: ValidateOfferGroupParams): readonly Offer[];
523
+ /**
524
+ * Returns an offer expiry timestamp.
525
+ *
526
+ * Use in maker UIs, API response mappers, or quote filters when accepting
527
+ * any plain object matching `IOffer` or an `Offer` instance. This does not validate
528
+ * whether the offer is still live at the current block time.
529
+ *
530
+ * @param offer - Offer to inspect.
531
+ * @returns Offer expiry.
532
+ * @example
533
+ * ```ts
534
+ * import { Offer, OfferUtils } from "@morpho-org/midnight-sdk";
535
+ * import { zeroAddress } from "viem";
536
+ *
537
+ * const offer = Offer.create({
538
+ * market: {
539
+ * loanToken: "0x0000000000000000000000000000000000006000",
540
+ * collateralParams: [
541
+ * {
542
+ * token: "0x0000000000000000000000000000000000007000",
543
+ * lltv: 770000000000000000n,
544
+ * maxLif: 1061007957559681697n,
545
+ * oracle: "0x0000000000000000000000000000000000008000",
546
+ * },
547
+ * ],
548
+ * maturity: 54_000n,
549
+ * rcfThreshold: 0n,
550
+ * enterGate: zeroAddress,
551
+ * liquidatorGate: zeroAddress,
552
+ * },
553
+ * buy: true,
554
+ * maker: "0x0000000000000000000000000000000000009000",
555
+ * tick: 5_000n,
556
+ * expiry: 3_600n,
557
+ * ratifier: "0x0000000000000000000000000000000000004000",
558
+ * maxUnits: 100n,
559
+ * });
560
+ * const expiry = OfferUtils.getOfferExpiry(offer);
561
+ * console.log(expiry);
562
+ * ```
563
+ */
564
+ function getOfferExpiry(offer: IOffer): bigint;
565
+ }