@morpho-org/midnight-sdk 0.1.0 → 1.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.
- package/LICENSE +21 -0
- package/README.md +56 -46
- package/lib/cjs/abis.d.ts +1185 -996
- package/lib/cjs/abis.js +1445 -1211
- package/lib/cjs/api/MidnightApi.d.ts +22 -16
- package/lib/cjs/api/MidnightApi.js +22 -16
- package/lib/cjs/api/helpers.js +6 -3
- package/lib/cjs/api/types.d.ts +35 -9
- package/lib/cjs/constants.d.ts +12 -11
- package/lib/cjs/constants.js +14 -12
- package/lib/cjs/errors.d.ts +74 -1
- package/lib/cjs/errors.js +94 -3
- package/lib/cjs/fetch/Market.js +0 -1
- package/lib/cjs/fetch/index.d.ts +0 -1
- package/lib/cjs/fetch/index.js +0 -1
- package/lib/cjs/index.d.ts +1 -1
- package/lib/cjs/index.js +2 -23
- package/lib/cjs/market/Market.d.ts +99 -33
- package/lib/cjs/market/Market.js +137 -28
- package/lib/cjs/market/MarketUtils.d.ts +61 -41
- package/lib/cjs/market/MarketUtils.js +108 -48
- package/lib/cjs/market/Position.d.ts +16 -11
- package/lib/cjs/market/Position.js +18 -12
- package/lib/cjs/market/PositionUtils.d.ts +6 -4
- package/lib/cjs/market/PositionUtils.js +9 -6
- package/lib/cjs/math/TickLib.d.ts +22 -0
- package/lib/cjs/math/TickLib.js +30 -0
- package/lib/cjs/math/index.d.ts +0 -1
- package/lib/cjs/math/index.js +0 -1
- package/lib/cjs/offers/Offer.d.ts +217 -11
- package/lib/cjs/offers/Offer.js +215 -7
- package/lib/cjs/offers/OfferUtils.d.ts +245 -139
- package/lib/cjs/offers/OfferUtils.js +304 -36
- package/lib/cjs/queries/GetPosition.d.ts +1 -1
- package/lib/cjs/queries/GetPosition.js +1 -1
- package/lib/cjs/signatures/EcrecoverRatifierUtils.d.ts +66 -38
- package/lib/cjs/signatures/EcrecoverRatifierUtils.js +147 -79
- package/lib/cjs/signatures/Group.d.ts +12 -4
- package/lib/cjs/signatures/Group.js +12 -4
- package/lib/cjs/signatures/GroupUtils.d.ts +12 -4
- package/lib/cjs/signatures/GroupUtils.js +6 -2
- package/lib/cjs/signatures/Payload.d.ts +277 -277
- package/lib/cjs/signatures/Payload.js +517 -534
- package/lib/cjs/signatures/RatifierUtils.d.ts +57 -0
- package/lib/cjs/signatures/RatifierUtils.js +94 -0
- package/lib/cjs/signatures/SetterRatifierUtils.d.ts +21 -13
- package/lib/cjs/signatures/SetterRatifierUtils.js +25 -20
- package/lib/cjs/signatures/Tree.d.ts +28 -16
- package/lib/cjs/signatures/Tree.js +25 -13
- package/lib/cjs/signatures/TreeUtils.d.ts +181 -62
- package/lib/cjs/signatures/TreeUtils.js +73 -76
- package/lib/cjs/signatures/index.d.ts +1 -0
- package/lib/cjs/signatures/index.js +3 -0
- package/lib/cjs/signatures/offerStructInternal.d.ts +14 -0
- package/lib/cjs/signatures/offerStructInternal.js +72 -0
- package/lib/esm/abis.d.ts +1185 -996
- package/lib/esm/abis.js +1445 -1211
- package/lib/esm/api/MidnightApi.d.ts +22 -16
- package/lib/esm/api/MidnightApi.js +23 -17
- package/lib/esm/api/helpers.js +6 -3
- package/lib/esm/api/types.d.ts +35 -9
- package/lib/esm/constants.d.ts +12 -11
- package/lib/esm/constants.js +13 -11
- package/lib/esm/errors.d.ts +74 -1
- package/lib/esm/errors.js +89 -2
- package/lib/esm/fetch/Market.js +0 -1
- package/lib/esm/fetch/index.d.ts +0 -1
- package/lib/esm/fetch/index.js +0 -1
- package/lib/esm/index.d.ts +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/esm/market/Market.d.ts +99 -33
- package/lib/esm/market/Market.js +137 -28
- package/lib/esm/market/MarketUtils.d.ts +61 -41
- package/lib/esm/market/MarketUtils.js +109 -49
- package/lib/esm/market/Position.d.ts +16 -11
- package/lib/esm/market/Position.js +19 -13
- package/lib/esm/market/PositionUtils.d.ts +6 -4
- package/lib/esm/market/PositionUtils.js +9 -6
- package/lib/esm/math/TickLib.d.ts +22 -0
- package/lib/esm/math/TickLib.js +31 -1
- package/lib/esm/math/index.d.ts +0 -1
- package/lib/esm/math/index.js +0 -1
- package/lib/esm/offers/Offer.d.ts +217 -11
- package/lib/esm/offers/Offer.js +216 -8
- package/lib/esm/offers/OfferUtils.d.ts +245 -139
- package/lib/esm/offers/OfferUtils.js +306 -38
- package/lib/esm/queries/GetPosition.d.ts +1 -1
- package/lib/esm/queries/GetPosition.js +1 -1
- package/lib/esm/signatures/EcrecoverRatifierUtils.d.ts +66 -38
- package/lib/esm/signatures/EcrecoverRatifierUtils.js +149 -81
- package/lib/esm/signatures/Group.d.ts +12 -4
- package/lib/esm/signatures/Group.js +12 -4
- package/lib/esm/signatures/GroupUtils.d.ts +12 -4
- package/lib/esm/signatures/GroupUtils.js +6 -2
- package/lib/esm/signatures/Payload.d.ts +277 -277
- package/lib/esm/signatures/Payload.js +517 -531
- package/lib/esm/signatures/RatifierUtils.d.ts +57 -0
- package/lib/esm/signatures/RatifierUtils.js +94 -0
- package/lib/esm/signatures/SetterRatifierUtils.d.ts +21 -13
- package/lib/esm/signatures/SetterRatifierUtils.js +25 -20
- package/lib/esm/signatures/Tree.d.ts +28 -16
- package/lib/esm/signatures/Tree.js +25 -13
- package/lib/esm/signatures/TreeUtils.d.ts +181 -62
- package/lib/esm/signatures/TreeUtils.js +75 -78
- package/lib/esm/signatures/index.d.ts +1 -0
- package/lib/esm/signatures/index.js +1 -0
- package/lib/esm/signatures/offerStructInternal.d.ts +14 -0
- package/lib/esm/signatures/offerStructInternal.js +67 -0
- package/package.json +28 -32
- package/src/index.ts +1 -1
- package/lib/cjs/fetch/Offer.d.ts +0 -74
- package/lib/cjs/fetch/Offer.js +0 -119
- package/lib/cjs/math/ConsumableUnitsLib.d.ts +0 -57
- package/lib/cjs/math/ConsumableUnitsLib.js +0 -77
- package/lib/esm/fetch/Offer.d.ts +0 -74
- package/lib/esm/fetch/Offer.js +0 -116
- package/lib/esm/math/ConsumableUnitsLib.d.ts +0 -57
- package/lib/esm/math/ConsumableUnitsLib.js +0 -74
|
@@ -6,59 +6,12 @@ const viem_1 = require("viem");
|
|
|
6
6
|
const MidnightApi_js_1 = require("../api/MidnightApi.js");
|
|
7
7
|
const errors_js_1 = require("../errors.js");
|
|
8
8
|
const index_js_1 = require("../offers/index.js");
|
|
9
|
+
const EcrecoverRatifierUtils_js_1 = require("./EcrecoverRatifierUtils.js");
|
|
9
10
|
const Group_js_1 = require("./Group.js");
|
|
10
11
|
const GroupUtils_js_1 = require("./GroupUtils.js");
|
|
12
|
+
const offerStructInternal_js_1 = require("./offerStructInternal.js");
|
|
11
13
|
const Payload_js_1 = require("./Payload.js");
|
|
12
|
-
const
|
|
13
|
-
const ZERO_BYTES32 = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
14
|
-
const EMPTY_OFFER_STRUCT = {
|
|
15
|
-
market: {
|
|
16
|
-
loanToken: ZERO_ADDRESS,
|
|
17
|
-
collateralParams: [],
|
|
18
|
-
maturity: 0n,
|
|
19
|
-
rcfThreshold: 0n,
|
|
20
|
-
enterGate: ZERO_ADDRESS,
|
|
21
|
-
liquidatorGate: ZERO_ADDRESS,
|
|
22
|
-
},
|
|
23
|
-
buy: false,
|
|
24
|
-
maker: ZERO_ADDRESS,
|
|
25
|
-
start: 0n,
|
|
26
|
-
expiry: 0n,
|
|
27
|
-
tick: 0n,
|
|
28
|
-
group: ZERO_BYTES32,
|
|
29
|
-
callback: ZERO_ADDRESS,
|
|
30
|
-
callbackData: "0x",
|
|
31
|
-
receiverIfMakerIsSeller: ZERO_ADDRESS,
|
|
32
|
-
ratifier: ZERO_ADDRESS,
|
|
33
|
-
reduceOnly: false,
|
|
34
|
-
maxUnits: 0n,
|
|
35
|
-
maxAssets: 0n,
|
|
36
|
-
continuousFeeCap: 0n,
|
|
37
|
-
};
|
|
38
|
-
const EMPTY_OFFER_DEFAULT_GROUP = index_js_1.OfferUtils.hashStruct(EMPTY_OFFER_STRUCT);
|
|
39
|
-
function isEmptyOfferStruct(offer) {
|
|
40
|
-
return (offer.market.loanToken === ZERO_ADDRESS &&
|
|
41
|
-
offer.market.collateralParams.length === 0 &&
|
|
42
|
-
offer.market.maturity === 0n &&
|
|
43
|
-
offer.market.rcfThreshold === 0n &&
|
|
44
|
-
offer.market.enterGate === ZERO_ADDRESS &&
|
|
45
|
-
offer.market.liquidatorGate === ZERO_ADDRESS &&
|
|
46
|
-
offer.buy === false &&
|
|
47
|
-
offer.maker === ZERO_ADDRESS &&
|
|
48
|
-
offer.start === 0n &&
|
|
49
|
-
offer.expiry === 0n &&
|
|
50
|
-
offer.tick === 0n &&
|
|
51
|
-
(offer.group === ZERO_BYTES32 ||
|
|
52
|
-
offer.group === EMPTY_OFFER_DEFAULT_GROUP) &&
|
|
53
|
-
offer.callback === ZERO_ADDRESS &&
|
|
54
|
-
offer.callbackData === "0x" &&
|
|
55
|
-
offer.receiverIfMakerIsSeller === ZERO_ADDRESS &&
|
|
56
|
-
offer.ratifier === ZERO_ADDRESS &&
|
|
57
|
-
offer.reduceOnly === false &&
|
|
58
|
-
offer.maxUnits === 0n &&
|
|
59
|
-
offer.maxAssets === 0n &&
|
|
60
|
-
offer.continuousFeeCap === 0n);
|
|
61
|
-
}
|
|
14
|
+
const SetterRatifierUtils_js_1 = require("./SetterRatifierUtils.js");
|
|
62
15
|
function isPowerOfTwo(value) {
|
|
63
16
|
return value > 0 && (value & (value - 1)) === 0;
|
|
64
17
|
}
|
|
@@ -71,13 +24,13 @@ function padOfferStructs(offers) {
|
|
|
71
24
|
const paddedLength = nextPowerOfTwo(offers.length);
|
|
72
25
|
return [
|
|
73
26
|
...offers,
|
|
74
|
-
...Array.from({ length: paddedLength - offers.length }, () => EMPTY_OFFER_STRUCT),
|
|
27
|
+
...Array.from({ length: paddedLength - offers.length }, () => offerStructInternal_js_1.EMPTY_OFFER_STRUCT),
|
|
75
28
|
];
|
|
76
29
|
}
|
|
77
30
|
function assertLeafOffers(offers, leafHashes) {
|
|
78
31
|
const seen = new Set();
|
|
79
32
|
for (const [index, offer] of offers.entries()) {
|
|
80
|
-
if (isEmptyOfferStruct(offer))
|
|
33
|
+
if ((0, offerStructInternal_js_1.isEmptyOfferStruct)(offer, { allowDefaultGroup: true }))
|
|
81
34
|
continue;
|
|
82
35
|
const leafHash = leafHashes[index];
|
|
83
36
|
if (seen.has(leafHash)) {
|
|
@@ -109,24 +62,26 @@ var TreeUtils;
|
|
|
109
62
|
/**
|
|
110
63
|
* Validates a tree against Midnight mempool API policy.
|
|
111
64
|
*
|
|
112
|
-
* This is an API-backed convenience: it encodes each tree leaf
|
|
113
|
-
* `ratifierData`, then sends the temporary payload to the Midnight
|
|
114
|
-
* `POST /mempool/validate` endpoint.
|
|
115
|
-
*
|
|
116
|
-
*
|
|
65
|
+
* This is an API-backed convenience: by default it encodes each tree leaf
|
|
66
|
+
* with empty `ratifierData`, then sends the temporary payload to the Midnight
|
|
67
|
+
* API `POST /mempool/validate` endpoint. Pass `ratification` after signing or
|
|
68
|
+
* Setter root preparation to validate final payload bytes with real
|
|
69
|
+
* `ratifierData`.
|
|
117
70
|
*
|
|
118
71
|
* @param params.chainId - Chain id whose API policy should validate the tree.
|
|
119
|
-
* @param params.tree - Offer tree to validate
|
|
72
|
+
* @param params.tree - Offer tree to validate.
|
|
120
73
|
* @param params.apiUrl - Optional Midnight API URL override used for the validation HTTP request.
|
|
121
74
|
* @param params.timestamp - Optional ISO-8601 timestamp or `Date` selecting the API policy snapshot.
|
|
122
75
|
* @param params.fetch - Optional fetch implementation override used for the API call.
|
|
123
76
|
* @param params.request - Optional fetch options forwarded to the API request.
|
|
124
|
-
* @
|
|
77
|
+
* @param params.ratification - Optional ratification inputs used to validate final payload bytes with real ratifier data.
|
|
78
|
+
* @returns Successful API validation result with `valid: true`.
|
|
125
79
|
* @throws {InvalidTreeError} when the tree is empty, all padding, or duplicated.
|
|
126
80
|
* @throws {InvalidTreeHeightError} when the resulting height is unsupported.
|
|
127
|
-
* @throws {
|
|
81
|
+
* @throws {PayloadDecodeError} when validation payload encoding fails.
|
|
128
82
|
* @throws {MidnightApiError} when the API returns a non-2xx response.
|
|
129
83
|
* @throws {InvalidMidnightApiResponseError} when the API returns malformed success JSON.
|
|
84
|
+
* @throws {MidnightMempoolValidationError} when the API returns validation issues.
|
|
130
85
|
* @example
|
|
131
86
|
* ```ts
|
|
132
87
|
* import { Offer, TreeUtils } from "@morpho-org/midnight-sdk";
|
|
@@ -134,12 +89,14 @@ var TreeUtils;
|
|
|
134
89
|
*
|
|
135
90
|
* const offer = Offer.create({
|
|
136
91
|
* market: {
|
|
92
|
+
* chainId: 8453,
|
|
93
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
137
94
|
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
138
95
|
* collateralParams: [
|
|
139
96
|
* {
|
|
140
97
|
* token: "0x0000000000000000000000000000000000007000",
|
|
141
98
|
* lltv: 770000000000000000n,
|
|
142
|
-
*
|
|
99
|
+
* liquidationCursor: 250000000000000000n,
|
|
143
100
|
* oracle: "0x0000000000000000000000000000000000008000",
|
|
144
101
|
* },
|
|
145
102
|
* ],
|
|
@@ -155,20 +112,49 @@ var TreeUtils;
|
|
|
155
112
|
* ratifier: "0x0000000000000000000000000000000000004000",
|
|
156
113
|
* maxUnits: 100n,
|
|
157
114
|
* });
|
|
158
|
-
*
|
|
115
|
+
* await TreeUtils.mempoolValidate({
|
|
159
116
|
* chainId: 8453,
|
|
160
117
|
* tree: [offer],
|
|
161
118
|
* });
|
|
162
|
-
* console.log(validation.valid);
|
|
163
119
|
* ```
|
|
164
120
|
*/
|
|
165
121
|
async function mempoolValidate(params) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
122
|
+
let items;
|
|
123
|
+
if (params.ratification == null) {
|
|
124
|
+
const offers = "paddedOffers" in params.tree
|
|
125
|
+
? params.tree.offers
|
|
126
|
+
: params.tree.flatMap((entry) => "offers" in entry
|
|
127
|
+
? Group_js_1.Group.from(entry).offers
|
|
128
|
+
: [index_js_1.Offer.from(entry)]);
|
|
129
|
+
if (!("paddedOffers" in params.tree)) {
|
|
130
|
+
buildDescriptor(params.tree);
|
|
131
|
+
}
|
|
132
|
+
items = offers.map((offer) => ({
|
|
133
|
+
offer,
|
|
134
|
+
ratifierData: "0x",
|
|
135
|
+
}));
|
|
136
|
+
}
|
|
137
|
+
else if (params.ratification.type === "ecrecover") {
|
|
138
|
+
if (params.ratification.signature != null) {
|
|
139
|
+
items = await EcrecoverRatifierUtils_js_1.EcrecoverRatifierUtils.ratify({
|
|
140
|
+
tree: params.tree,
|
|
141
|
+
signature: params.ratification.signature,
|
|
142
|
+
account: params.ratification.account,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
items = await EcrecoverRatifierUtils_js_1.EcrecoverRatifierUtils.ratify({
|
|
147
|
+
tree: params.tree,
|
|
148
|
+
client: params.ratification.client,
|
|
149
|
+
account: params.ratification.account,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
items = SetterRatifierUtils_js_1.SetterRatifierUtils.ratify({ tree: params.tree });
|
|
155
|
+
}
|
|
156
|
+
const payload = await Payload_js_1.Payload.encode(items);
|
|
157
|
+
const validation = await MidnightApi_js_1.MidnightApi.validateMempoolPayload({
|
|
172
158
|
baseUrl: params.apiUrl,
|
|
173
159
|
fetch: params.fetch,
|
|
174
160
|
request: params.request,
|
|
@@ -176,6 +162,10 @@ var TreeUtils;
|
|
|
176
162
|
timestamp: params.timestamp,
|
|
177
163
|
payload,
|
|
178
164
|
});
|
|
165
|
+
if (!validation.valid) {
|
|
166
|
+
throw new errors_js_1.MidnightMempoolValidationError(validation.issues);
|
|
167
|
+
}
|
|
168
|
+
return { valid: true, issues: validation.issues };
|
|
179
169
|
}
|
|
180
170
|
TreeUtils.mempoolValidate = mempoolValidate;
|
|
181
171
|
/**
|
|
@@ -221,12 +211,14 @@ var TreeUtils;
|
|
|
221
211
|
*
|
|
222
212
|
* const offer = Offer.create({
|
|
223
213
|
* market: {
|
|
214
|
+
* chainId: 8453,
|
|
215
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
224
216
|
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
225
217
|
* collateralParams: [
|
|
226
218
|
* {
|
|
227
219
|
* token: "0x0000000000000000000000000000000000007000",
|
|
228
220
|
* lltv: 770000000000000000n,
|
|
229
|
-
*
|
|
221
|
+
* liquidationCursor: 250000000000000000n,
|
|
230
222
|
* oracle: "0x0000000000000000000000000000000000008000",
|
|
231
223
|
* },
|
|
232
224
|
* ],
|
|
@@ -293,12 +285,14 @@ var TreeUtils;
|
|
|
293
285
|
*
|
|
294
286
|
* const offer = Offer.create({
|
|
295
287
|
* market: {
|
|
288
|
+
* chainId: 8453,
|
|
289
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
296
290
|
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
297
291
|
* collateralParams: [
|
|
298
292
|
* {
|
|
299
293
|
* token: "0x0000000000000000000000000000000000007000",
|
|
300
294
|
* lltv: 770000000000000000n,
|
|
301
|
-
*
|
|
295
|
+
* liquidationCursor: 250000000000000000n,
|
|
302
296
|
* oracle: "0x0000000000000000000000000000000000008000",
|
|
303
297
|
* },
|
|
304
298
|
* ],
|
|
@@ -329,7 +323,7 @@ var TreeUtils;
|
|
|
329
323
|
* built-in Ecrecover and Setter helpers call this while generating
|
|
330
324
|
* `ratifierData`.
|
|
331
325
|
*
|
|
332
|
-
* @param params.tree - Tree that
|
|
326
|
+
* @param params.tree - Tree-like data with the root and leaves that contain the leaf.
|
|
333
327
|
* @param params.leafIndex - Leaf index to prove.
|
|
334
328
|
* @returns Proof descriptor.
|
|
335
329
|
* @throws {InvalidTreeError} when leaf index is out of range.
|
|
@@ -340,12 +334,14 @@ var TreeUtils;
|
|
|
340
334
|
*
|
|
341
335
|
* const offer = Offer.create({
|
|
342
336
|
* market: {
|
|
337
|
+
* chainId: 8453,
|
|
338
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
343
339
|
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
344
340
|
* collateralParams: [
|
|
345
341
|
* {
|
|
346
342
|
* token: "0x0000000000000000000000000000000000007000",
|
|
347
343
|
* lltv: 770000000000000000n,
|
|
348
|
-
*
|
|
344
|
+
* liquidationCursor: 250000000000000000n,
|
|
349
345
|
* oracle: "0x0000000000000000000000000000000000008000",
|
|
350
346
|
* },
|
|
351
347
|
* ],
|
|
@@ -370,8 +366,7 @@ var TreeUtils;
|
|
|
370
366
|
*/
|
|
371
367
|
function buildProof(params) {
|
|
372
368
|
const leafIndex = BigInt(params.leafIndex);
|
|
373
|
-
if (leafIndex < 0n ||
|
|
374
|
-
leafIndex >= BigInt(params.tree.paddedOffers.length)) {
|
|
369
|
+
if (leafIndex < 0n || leafIndex >= BigInt(params.tree.leaves.length)) {
|
|
375
370
|
throw new errors_js_1.InvalidTreeError(`Leaf index "${leafIndex}" is outside the tree.`);
|
|
376
371
|
}
|
|
377
372
|
let index = Number(leafIndex);
|
|
@@ -408,12 +403,14 @@ var TreeUtils;
|
|
|
408
403
|
*
|
|
409
404
|
* const offer = Offer.create({
|
|
410
405
|
* market: {
|
|
406
|
+
* chainId: 8453,
|
|
407
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
411
408
|
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
412
409
|
* collateralParams: [
|
|
413
410
|
* {
|
|
414
411
|
* token: "0x0000000000000000000000000000000000007000",
|
|
415
412
|
* lltv: 770000000000000000n,
|
|
416
|
-
*
|
|
413
|
+
* liquidationCursor: 250000000000000000n,
|
|
417
414
|
* oracle: "0x0000000000000000000000000000000000008000",
|
|
418
415
|
* },
|
|
419
416
|
* ],
|
|
@@ -14,9 +14,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.Payload = void 0;
|
|
17
18
|
__exportStar(require("./EcrecoverRatifierUtils.js"), exports);
|
|
18
19
|
__exportStar(require("./Group.js"), exports);
|
|
19
20
|
__exportStar(require("./GroupUtils.js"), exports);
|
|
21
|
+
var Payload_js_1 = require("./Payload.js");
|
|
22
|
+
Object.defineProperty(exports, "Payload", { enumerable: true, get: function () { return Payload_js_1.Payload; } });
|
|
20
23
|
__exportStar(require("./RatifierUtils.js"), exports);
|
|
21
24
|
__exportStar(require("./SetterRatifierUtils.js"), exports);
|
|
22
25
|
__exportStar(require("./Tree.js"), exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type OfferStruct } from "../offers/index.js";
|
|
2
|
+
/** @internal Empty protocol offer struct used for Merkle padding. */
|
|
3
|
+
export declare const EMPTY_OFFER_STRUCT: OfferStruct;
|
|
4
|
+
/** @internal Returns whether an address value is the zero address. */
|
|
5
|
+
export declare function isZeroAddress(value: string): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* @internal Returns whether an offer struct is the protocol empty offer.
|
|
8
|
+
*
|
|
9
|
+
* Tree padding may carry the empty offer's derived default group, while payload
|
|
10
|
+
* decoding only treats the canonical zero-group empty struct as padding.
|
|
11
|
+
*/
|
|
12
|
+
export declare function isEmptyOfferStruct(offer: OfferStruct, options?: {
|
|
13
|
+
readonly allowDefaultGroup?: boolean;
|
|
14
|
+
}): boolean;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EMPTY_OFFER_STRUCT = void 0;
|
|
4
|
+
exports.isZeroAddress = isZeroAddress;
|
|
5
|
+
exports.isEmptyOfferStruct = isEmptyOfferStruct;
|
|
6
|
+
const viem_1 = require("viem");
|
|
7
|
+
const index_js_1 = require("../offers/index.js");
|
|
8
|
+
/** @internal Empty protocol offer struct used for Merkle padding. */
|
|
9
|
+
exports.EMPTY_OFFER_STRUCT = {
|
|
10
|
+
market: {
|
|
11
|
+
chainId: 0n,
|
|
12
|
+
midnight: viem_1.zeroAddress,
|
|
13
|
+
loanToken: viem_1.zeroAddress,
|
|
14
|
+
collateralParams: [],
|
|
15
|
+
maturity: 0n,
|
|
16
|
+
rcfThreshold: 0n,
|
|
17
|
+
enterGate: viem_1.zeroAddress,
|
|
18
|
+
liquidatorGate: viem_1.zeroAddress,
|
|
19
|
+
},
|
|
20
|
+
buy: false,
|
|
21
|
+
maker: viem_1.zeroAddress,
|
|
22
|
+
start: 0n,
|
|
23
|
+
expiry: 0n,
|
|
24
|
+
tick: 0n,
|
|
25
|
+
group: viem_1.zeroHash,
|
|
26
|
+
callback: viem_1.zeroAddress,
|
|
27
|
+
callbackData: "0x",
|
|
28
|
+
receiverIfMakerIsSeller: viem_1.zeroAddress,
|
|
29
|
+
ratifier: viem_1.zeroAddress,
|
|
30
|
+
reduceOnly: false,
|
|
31
|
+
maxUnits: 0n,
|
|
32
|
+
maxAssets: 0n,
|
|
33
|
+
continuousFeeCap: 0n,
|
|
34
|
+
};
|
|
35
|
+
const EMPTY_OFFER_DEFAULT_GROUP = index_js_1.OfferUtils.hashStruct(exports.EMPTY_OFFER_STRUCT);
|
|
36
|
+
/** @internal Returns whether an address value is the zero address. */
|
|
37
|
+
function isZeroAddress(value) {
|
|
38
|
+
return value.toLowerCase() === viem_1.zeroAddress;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* @internal Returns whether an offer struct is the protocol empty offer.
|
|
42
|
+
*
|
|
43
|
+
* Tree padding may carry the empty offer's derived default group, while payload
|
|
44
|
+
* decoding only treats the canonical zero-group empty struct as padding.
|
|
45
|
+
*/
|
|
46
|
+
function isEmptyOfferStruct(offer, options = {}) {
|
|
47
|
+
const hasEmptyGroup = offer.group === viem_1.zeroHash ||
|
|
48
|
+
(options.allowDefaultGroup === true &&
|
|
49
|
+
offer.group === EMPTY_OFFER_DEFAULT_GROUP);
|
|
50
|
+
return (offer.market.chainId === 0n &&
|
|
51
|
+
isZeroAddress(offer.market.midnight) &&
|
|
52
|
+
isZeroAddress(offer.market.loanToken) &&
|
|
53
|
+
offer.market.collateralParams.length === 0 &&
|
|
54
|
+
offer.market.maturity === 0n &&
|
|
55
|
+
offer.market.rcfThreshold === 0n &&
|
|
56
|
+
isZeroAddress(offer.market.enterGate) &&
|
|
57
|
+
isZeroAddress(offer.market.liquidatorGate) &&
|
|
58
|
+
offer.buy === false &&
|
|
59
|
+
isZeroAddress(offer.maker) &&
|
|
60
|
+
offer.start === 0n &&
|
|
61
|
+
offer.expiry === 0n &&
|
|
62
|
+
offer.tick === 0n &&
|
|
63
|
+
hasEmptyGroup &&
|
|
64
|
+
isZeroAddress(offer.callback) &&
|
|
65
|
+
offer.callbackData === "0x" &&
|
|
66
|
+
isZeroAddress(offer.receiverIfMakerIsSeller) &&
|
|
67
|
+
isZeroAddress(offer.ratifier) &&
|
|
68
|
+
offer.reduceOnly === false &&
|
|
69
|
+
offer.maxUnits === 0n &&
|
|
70
|
+
offer.maxAssets === 0n &&
|
|
71
|
+
offer.continuousFeeCap === 0n);
|
|
72
|
+
}
|