@morpho-org/midnight-sdk 2.2.0-next.0 → 2.2.1
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/lib/cjs/api/MidnightApi.d.ts +18 -8
- package/lib/cjs/api/MidnightApi.js +18 -8
- package/lib/cjs/api/helpers.js +11 -2
- package/lib/cjs/api/version.generated.d.ts +1 -1
- package/lib/cjs/api/version.generated.js +1 -1
- package/lib/cjs/errors.d.ts +27 -13
- package/lib/cjs/errors.js +39 -8
- package/lib/cjs/position/PositionUtils.js +35 -11
- package/lib/cjs/signatures/PriceRatifierV1.d.ts +6 -1
- package/lib/cjs/signatures/PriceRatifierV1.js +6 -1
- package/lib/cjs/signatures/RateRatifierV1.d.ts +6 -1
- package/lib/cjs/signatures/RateRatifierV1.js +6 -1
- package/lib/cjs/signatures/Tree.d.ts +2 -0
- package/lib/cjs/signatures/TreeUtils.d.ts +1 -0
- package/lib/cjs/signatures/ratifierV1Internal.d.ts +1 -1
- package/lib/cjs/signatures/ratifierV1Internal.js +24 -1
- package/lib/esm/api/MidnightApi.d.ts +18 -8
- package/lib/esm/api/MidnightApi.js +18 -8
- package/lib/esm/api/helpers.js +12 -3
- package/lib/esm/api/version.generated.d.ts +1 -1
- package/lib/esm/api/version.generated.js +1 -1
- package/lib/esm/errors.d.ts +27 -13
- package/lib/esm/errors.js +36 -8
- package/lib/esm/position/PositionUtils.js +36 -12
- package/lib/esm/signatures/PriceRatifierV1.d.ts +6 -1
- package/lib/esm/signatures/PriceRatifierV1.js +6 -1
- package/lib/esm/signatures/RateRatifierV1.d.ts +6 -1
- package/lib/esm/signatures/RateRatifierV1.js +6 -1
- package/lib/esm/signatures/Tree.d.ts +2 -0
- package/lib/esm/signatures/TreeUtils.d.ts +1 -0
- package/lib/esm/signatures/ratifierV1Internal.d.ts +1 -1
- package/lib/esm/signatures/ratifierV1Internal.js +24 -1
- package/package.json +5 -5
|
@@ -13,7 +13,7 @@ const GroupUtils_js_1 = require("./GroupUtils.js");
|
|
|
13
13
|
const offerStructInternal_js_1 = require("./offerStructInternal.js");
|
|
14
14
|
const TreeUtils_js_1 = require("./TreeUtils.js");
|
|
15
15
|
const treeMathInternal_js_1 = require("./treeMathInternal.js");
|
|
16
|
-
/** @internal Resolves V1 leaf groups mirroring the router's group_identity content ids. */
|
|
16
|
+
/** @internal Resolves V1 leaf groups mirroring the router's group_identity content ids and validates explicit groups. */
|
|
17
17
|
function assignRatifierV1Groups(leaves, groupId) {
|
|
18
18
|
const offers = leaves.map((leaf) => leaf.offer.hasExplicitGroup
|
|
19
19
|
? leaf.offer
|
|
@@ -31,6 +31,10 @@ function assignRatifierV1Groups(leaves, groupId) {
|
|
|
31
31
|
}
|
|
32
32
|
for (const [label, indices] of buckets) {
|
|
33
33
|
const bucketLeaves = indices.map((index) => leaves[index]);
|
|
34
|
+
// Called only to throw on incompatible group members.
|
|
35
|
+
index_js_1.OfferUtils.validateOfferGroup({
|
|
36
|
+
offers: bucketLeaves.map((leaf) => leaf.offer),
|
|
37
|
+
});
|
|
34
38
|
if (GroupUtils_js_1.GroupUtils.hash(bucketLeaves.map((leaf) => leaf.offer)).toLowerCase() !==
|
|
35
39
|
label) {
|
|
36
40
|
continue;
|
|
@@ -40,6 +44,25 @@ function assignRatifierV1Groups(leaves, groupId) {
|
|
|
40
44
|
offers[index] = index_js_1.Offer.from({ ...leaves[index].offer, group });
|
|
41
45
|
}
|
|
42
46
|
}
|
|
47
|
+
const finalGroups = new Map();
|
|
48
|
+
for (const [index, offer] of offers.entries()) {
|
|
49
|
+
const label = offer.group.toLowerCase();
|
|
50
|
+
const hasExplicitGroup = leaves[index].offer.hasExplicitGroup;
|
|
51
|
+
const bucket = finalGroups.get(label);
|
|
52
|
+
if (bucket) {
|
|
53
|
+
bucket.offers.push(offer);
|
|
54
|
+
bucket.hasExplicitGroup ||= hasExplicitGroup;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
finalGroups.set(label, { offers: [offer], hasExplicitGroup });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
for (const { offers: groupOffers, hasExplicitGroup, } of finalGroups.values()) {
|
|
61
|
+
if (!hasExplicitGroup)
|
|
62
|
+
continue;
|
|
63
|
+
// Catches explicit groups that collide with a defaulted or re-derived id.
|
|
64
|
+
index_js_1.OfferUtils.validateOfferGroup({ offers: groupOffers });
|
|
65
|
+
}
|
|
43
66
|
return offers;
|
|
44
67
|
}
|
|
45
68
|
/**
|
|
@@ -142,7 +142,7 @@ export declare class MidnightApi {
|
|
|
142
142
|
* @param params.request - Optional fetch options forwarded to this request.
|
|
143
143
|
* @returns ABI-ready take objects mapped from the API response.
|
|
144
144
|
* @throws {MidnightApiError} when the API returns a non-2xx response.
|
|
145
|
-
* @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned offer cannot be mapped (malformed numeric or hex fields), when its `market_id` does not match, or cannot be derived from, its embedded market, when it falls outside the requested filters, when its `receiverIfMakerIsSeller` is not a well-formed address, when its caps or buy-side receiver are not executable, or when its units exceed its offer `maxUnits`.
|
|
145
|
+
* @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned offer cannot be mapped (malformed numeric or hex fields), when its `market_id` does not match, or cannot be derived from, its embedded market, when it falls outside the requested filters, when its `receiverIfMakerIsSeller` is not a well-formed address or is the zero address on a sell offer, when its caps or buy-side receiver are not executable, or when its units exceed its offer `maxUnits`.
|
|
146
146
|
* @example
|
|
147
147
|
* ```ts
|
|
148
148
|
* import { MidnightApi } from "@morpho-org/midnight-sdk/api";
|
|
@@ -171,11 +171,16 @@ export declare class MidnightApi {
|
|
|
171
171
|
* @param params.fetch - Optional fetch implementation override.
|
|
172
172
|
* @param params.request - Optional fetch options forwarded to this request.
|
|
173
173
|
* @returns Quote and ABI-ready take caps. `averageWorstPrice` equals the caller's guard when provided,
|
|
174
|
-
* otherwise the API's guard.
|
|
174
|
+
* otherwise the API's guard. Offers are returned as the API sends them. An `asks` quote by
|
|
175
|
+
* `assets` can include a sell offer whose buyer price (offer price plus the market's settlement
|
|
176
|
+
* fee) exceeds one asset per unit, such as a `MAX_TICK` ask when the fee is positive. The
|
|
177
|
+
* `MidnightBundlesV2` assets-target buy reverts on such an offer before its per-offer error
|
|
178
|
+
* handling, so the whole bundle fails. Drop these offers before building an assets-target buy,
|
|
179
|
+
* or use a `units` target.
|
|
175
180
|
* @throws {InvalidMidnightApiQuoteTargetError} when the runtime input does not set exactly one of `units` or `assets`.
|
|
176
181
|
* @throws {NegativeValueError} when `settlementFee` is negative.
|
|
177
182
|
* @throws {MidnightApiError} when the API returns a non-2xx response.
|
|
178
|
-
* @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned offer cannot be mapped (malformed numeric or hex fields), when its `market_id` does not match, or cannot be derived from, its embedded market, when it falls outside the requested filters, when its `receiverIfMakerIsSeller` is not a well-formed address, when its caps or buy-side receiver are not executable, when its units exceed its offer `maxUnits`, or when the returned offers imply a rounded aggregate settlement price outside the effective average-worst-price guard.
|
|
183
|
+
* @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned offer cannot be mapped (malformed numeric or hex fields), when its `market_id` does not match, or cannot be derived from, its embedded market, when it falls outside the requested filters, when its `receiverIfMakerIsSeller` is not a well-formed address or is the zero address on a sell offer, when its caps or buy-side receiver are not executable, when its units exceed its offer `maxUnits`, or when the returned offers imply a rounded aggregate settlement price outside the effective average-worst-price guard.
|
|
179
184
|
* @throws {SettlementFeeExceedsPriceError} when a bid's settlement fee exceeds its offer price.
|
|
180
185
|
* @example
|
|
181
186
|
* ```ts
|
|
@@ -206,7 +211,7 @@ export declare class MidnightApi {
|
|
|
206
211
|
* @param params.request - Optional fetch options forwarded to this request.
|
|
207
212
|
* @returns Paginated ABI-ready take objects mapped from the API response.
|
|
208
213
|
* @throws {MidnightApiError} when the API returns a non-2xx response.
|
|
209
|
-
* @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned offer cannot be mapped (malformed numeric or hex fields), when its `market_id` does not match, or cannot be derived from, its embedded market, when it falls outside the requested filters, when its `receiverIfMakerIsSeller` is not a well-formed address, when its caps or buy-side receiver are not executable, or when its units exceed its offer `maxUnits`.
|
|
214
|
+
* @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned offer cannot be mapped (malformed numeric or hex fields), when its `market_id` does not match, or cannot be derived from, its embedded market, when it falls outside the requested filters, when its `receiverIfMakerIsSeller` is not a well-formed address or is the zero address on a sell offer, when its caps or buy-side receiver are not executable, or when its units exceed its offer `maxUnits`.
|
|
210
215
|
* @example
|
|
211
216
|
* ```ts
|
|
212
217
|
* import { MidnightApi } from "@morpho-org/midnight-sdk/api";
|
|
@@ -391,7 +396,7 @@ export declare class MidnightApi {
|
|
|
391
396
|
* @param params.side - Book side to query.
|
|
392
397
|
* @returns ABI-ready take objects mapped from the API response.
|
|
393
398
|
* @throws {MidnightApiError} when the API returns a non-2xx response.
|
|
394
|
-
* @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned offer cannot be mapped (malformed numeric or hex fields), when its `market_id` does not match, or cannot be derived from, its embedded market, when it falls outside the requested filters, when its `receiverIfMakerIsSeller` is not a well-formed address, when its caps or buy-side receiver are not executable, or when its units exceed its offer `maxUnits`.
|
|
399
|
+
* @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned offer cannot be mapped (malformed numeric or hex fields), when its `market_id` does not match, or cannot be derived from, its embedded market, when it falls outside the requested filters, when its `receiverIfMakerIsSeller` is not a well-formed address or is the zero address on a sell offer, when its caps or buy-side receiver are not executable, or when its units exceed its offer `maxUnits`.
|
|
395
400
|
* @example
|
|
396
401
|
* ```ts
|
|
397
402
|
* import { MidnightApi } from "@morpho-org/midnight-sdk/api";
|
|
@@ -418,11 +423,16 @@ export declare class MidnightApi {
|
|
|
418
423
|
* @param params.slippage - Optional slippage percentage used to derive the guard. Mutually exclusive with `params.averageWorstPrice`.
|
|
419
424
|
* @param params.settlementFee - Optional current WAD-scaled settlement fee used for local guard validation. Defaults to zero.
|
|
420
425
|
* @returns Quote and ABI-ready take caps. `averageWorstPrice` equals the caller's guard when provided,
|
|
421
|
-
* otherwise the API's guard.
|
|
426
|
+
* otherwise the API's guard. Offers are returned as the API sends them. An `asks` quote by
|
|
427
|
+
* `assets` can include a sell offer whose buyer price (offer price plus the market's settlement
|
|
428
|
+
* fee) exceeds one asset per unit, such as a `MAX_TICK` ask when the fee is positive. The
|
|
429
|
+
* `MidnightBundlesV2` assets-target buy reverts on such an offer before its per-offer error
|
|
430
|
+
* handling, so the whole bundle fails. Drop these offers before building an assets-target buy,
|
|
431
|
+
* or use a `units` target.
|
|
422
432
|
* @throws {InvalidMidnightApiQuoteTargetError} when the runtime input does not set exactly one of `units` or `assets`.
|
|
423
433
|
* @throws {NegativeValueError} when `settlementFee` is negative.
|
|
424
434
|
* @throws {MidnightApiError} when the API returns a non-2xx response.
|
|
425
|
-
* @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned offer cannot be mapped (malformed numeric or hex fields), when its `market_id` does not match, or cannot be derived from, its embedded market, when it falls outside the requested filters, when its `receiverIfMakerIsSeller` is not a well-formed address, when its caps or buy-side receiver are not executable, when its units exceed its offer `maxUnits`, or when the returned offers imply a rounded aggregate settlement price outside the effective average-worst-price guard.
|
|
435
|
+
* @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned offer cannot be mapped (malformed numeric or hex fields), when its `market_id` does not match, or cannot be derived from, its embedded market, when it falls outside the requested filters, when its `receiverIfMakerIsSeller` is not a well-formed address or is the zero address on a sell offer, when its caps or buy-side receiver are not executable, when its units exceed its offer `maxUnits`, or when the returned offers imply a rounded aggregate settlement price outside the effective average-worst-price guard.
|
|
426
436
|
* @throws {SettlementFeeExceedsPriceError} when a bid's settlement fee exceeds its offer price.
|
|
427
437
|
* @example
|
|
428
438
|
* ```ts
|
|
@@ -450,7 +460,7 @@ export declare class MidnightApi {
|
|
|
450
460
|
* @param params.cursor - Optional opaque pagination cursor from a previous response.
|
|
451
461
|
* @returns Paginated ABI-ready take objects mapped from the API response.
|
|
452
462
|
* @throws {MidnightApiError} when the API returns a non-2xx response.
|
|
453
|
-
* @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned offer cannot be mapped (malformed numeric or hex fields), when its `market_id` does not match, or cannot be derived from, its embedded market, when it falls outside the requested filters, when its `receiverIfMakerIsSeller` is not a well-formed address, when its caps or buy-side receiver are not executable, or when its units exceed its offer `maxUnits`.
|
|
463
|
+
* @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned offer cannot be mapped (malformed numeric or hex fields), when its `market_id` does not match, or cannot be derived from, its embedded market, when it falls outside the requested filters, when its `receiverIfMakerIsSeller` is not a well-formed address or is the zero address on a sell offer, when its caps or buy-side receiver are not executable, or when its units exceed its offer `maxUnits`.
|
|
454
464
|
* @example
|
|
455
465
|
* ```ts
|
|
456
466
|
* import { MidnightApi } from "@morpho-org/midnight-sdk/api";
|
|
@@ -203,7 +203,7 @@ export class MidnightApi {
|
|
|
203
203
|
* @param params.request - Optional fetch options forwarded to this request.
|
|
204
204
|
* @returns ABI-ready take objects mapped from the API response.
|
|
205
205
|
* @throws {MidnightApiError} when the API returns a non-2xx response.
|
|
206
|
-
* @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned offer cannot be mapped (malformed numeric or hex fields), when its `market_id` does not match, or cannot be derived from, its embedded market, when it falls outside the requested filters, when its `receiverIfMakerIsSeller` is not a well-formed address, when its caps or buy-side receiver are not executable, or when its units exceed its offer `maxUnits`.
|
|
206
|
+
* @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned offer cannot be mapped (malformed numeric or hex fields), when its `market_id` does not match, or cannot be derived from, its embedded market, when it falls outside the requested filters, when its `receiverIfMakerIsSeller` is not a well-formed address or is the zero address on a sell offer, when its caps or buy-side receiver are not executable, or when its units exceed its offer `maxUnits`.
|
|
207
207
|
* @example
|
|
208
208
|
* ```ts
|
|
209
209
|
* import { MidnightApi } from "@morpho-org/midnight-sdk/api";
|
|
@@ -249,11 +249,16 @@ export class MidnightApi {
|
|
|
249
249
|
* @param params.fetch - Optional fetch implementation override.
|
|
250
250
|
* @param params.request - Optional fetch options forwarded to this request.
|
|
251
251
|
* @returns Quote and ABI-ready take caps. `averageWorstPrice` equals the caller's guard when provided,
|
|
252
|
-
* otherwise the API's guard.
|
|
252
|
+
* otherwise the API's guard. Offers are returned as the API sends them. An `asks` quote by
|
|
253
|
+
* `assets` can include a sell offer whose buyer price (offer price plus the market's settlement
|
|
254
|
+
* fee) exceeds one asset per unit, such as a `MAX_TICK` ask when the fee is positive. The
|
|
255
|
+
* `MidnightBundlesV2` assets-target buy reverts on such an offer before its per-offer error
|
|
256
|
+
* handling, so the whole bundle fails. Drop these offers before building an assets-target buy,
|
|
257
|
+
* or use a `units` target.
|
|
253
258
|
* @throws {InvalidMidnightApiQuoteTargetError} when the runtime input does not set exactly one of `units` or `assets`.
|
|
254
259
|
* @throws {NegativeValueError} when `settlementFee` is negative.
|
|
255
260
|
* @throws {MidnightApiError} when the API returns a non-2xx response.
|
|
256
|
-
* @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned offer cannot be mapped (malformed numeric or hex fields), when its `market_id` does not match, or cannot be derived from, its embedded market, when it falls outside the requested filters, when its `receiverIfMakerIsSeller` is not a well-formed address, when its caps or buy-side receiver are not executable, when its units exceed its offer `maxUnits`, or when the returned offers imply a rounded aggregate settlement price outside the effective average-worst-price guard.
|
|
261
|
+
* @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned offer cannot be mapped (malformed numeric or hex fields), when its `market_id` does not match, or cannot be derived from, its embedded market, when it falls outside the requested filters, when its `receiverIfMakerIsSeller` is not a well-formed address or is the zero address on a sell offer, when its caps or buy-side receiver are not executable, when its units exceed its offer `maxUnits`, or when the returned offers imply a rounded aggregate settlement price outside the effective average-worst-price guard.
|
|
257
262
|
* @throws {SettlementFeeExceedsPriceError} when a bid's settlement fee exceeds its offer price.
|
|
258
263
|
* @example
|
|
259
264
|
* ```ts
|
|
@@ -378,7 +383,7 @@ export class MidnightApi {
|
|
|
378
383
|
* @param params.request - Optional fetch options forwarded to this request.
|
|
379
384
|
* @returns Paginated ABI-ready take objects mapped from the API response.
|
|
380
385
|
* @throws {MidnightApiError} when the API returns a non-2xx response.
|
|
381
|
-
* @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned offer cannot be mapped (malformed numeric or hex fields), when its `market_id` does not match, or cannot be derived from, its embedded market, when it falls outside the requested filters, when its `receiverIfMakerIsSeller` is not a well-formed address, when its caps or buy-side receiver are not executable, or when its units exceed its offer `maxUnits`.
|
|
386
|
+
* @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned offer cannot be mapped (malformed numeric or hex fields), when its `market_id` does not match, or cannot be derived from, its embedded market, when it falls outside the requested filters, when its `receiverIfMakerIsSeller` is not a well-formed address or is the zero address on a sell offer, when its caps or buy-side receiver are not executable, or when its units exceed its offer `maxUnits`.
|
|
382
387
|
* @example
|
|
383
388
|
* ```ts
|
|
384
389
|
* import { MidnightApi } from "@morpho-org/midnight-sdk/api";
|
|
@@ -626,7 +631,7 @@ export class MidnightApi {
|
|
|
626
631
|
* @param params.side - Book side to query.
|
|
627
632
|
* @returns ABI-ready take objects mapped from the API response.
|
|
628
633
|
* @throws {MidnightApiError} when the API returns a non-2xx response.
|
|
629
|
-
* @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned offer cannot be mapped (malformed numeric or hex fields), when its `market_id` does not match, or cannot be derived from, its embedded market, when it falls outside the requested filters, when its `receiverIfMakerIsSeller` is not a well-formed address, when its caps or buy-side receiver are not executable, or when its units exceed its offer `maxUnits`.
|
|
634
|
+
* @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned offer cannot be mapped (malformed numeric or hex fields), when its `market_id` does not match, or cannot be derived from, its embedded market, when it falls outside the requested filters, when its `receiverIfMakerIsSeller` is not a well-formed address or is the zero address on a sell offer, when its caps or buy-side receiver are not executable, or when its units exceed its offer `maxUnits`.
|
|
630
635
|
* @example
|
|
631
636
|
* ```ts
|
|
632
637
|
* import { MidnightApi } from "@morpho-org/midnight-sdk/api";
|
|
@@ -658,11 +663,16 @@ export class MidnightApi {
|
|
|
658
663
|
* @param params.slippage - Optional slippage percentage used to derive the guard. Mutually exclusive with `params.averageWorstPrice`.
|
|
659
664
|
* @param params.settlementFee - Optional current WAD-scaled settlement fee used for local guard validation. Defaults to zero.
|
|
660
665
|
* @returns Quote and ABI-ready take caps. `averageWorstPrice` equals the caller's guard when provided,
|
|
661
|
-
* otherwise the API's guard.
|
|
666
|
+
* otherwise the API's guard. Offers are returned as the API sends them. An `asks` quote by
|
|
667
|
+
* `assets` can include a sell offer whose buyer price (offer price plus the market's settlement
|
|
668
|
+
* fee) exceeds one asset per unit, such as a `MAX_TICK` ask when the fee is positive. The
|
|
669
|
+
* `MidnightBundlesV2` assets-target buy reverts on such an offer before its per-offer error
|
|
670
|
+
* handling, so the whole bundle fails. Drop these offers before building an assets-target buy,
|
|
671
|
+
* or use a `units` target.
|
|
662
672
|
* @throws {InvalidMidnightApiQuoteTargetError} when the runtime input does not set exactly one of `units` or `assets`.
|
|
663
673
|
* @throws {NegativeValueError} when `settlementFee` is negative.
|
|
664
674
|
* @throws {MidnightApiError} when the API returns a non-2xx response.
|
|
665
|
-
* @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned offer cannot be mapped (malformed numeric or hex fields), when its `market_id` does not match, or cannot be derived from, its embedded market, when it falls outside the requested filters, when its `receiverIfMakerIsSeller` is not a well-formed address, when its caps or buy-side receiver are not executable, when its units exceed its offer `maxUnits`, or when the returned offers imply a rounded aggregate settlement price outside the effective average-worst-price guard.
|
|
675
|
+
* @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned offer cannot be mapped (malformed numeric or hex fields), when its `market_id` does not match, or cannot be derived from, its embedded market, when it falls outside the requested filters, when its `receiverIfMakerIsSeller` is not a well-formed address or is the zero address on a sell offer, when its caps or buy-side receiver are not executable, when its units exceed its offer `maxUnits`, or when the returned offers imply a rounded aggregate settlement price outside the effective average-worst-price guard.
|
|
666
676
|
* @throws {SettlementFeeExceedsPriceError} when a bid's settlement fee exceeds its offer price.
|
|
667
677
|
* @example
|
|
668
678
|
* ```ts
|
|
@@ -695,7 +705,7 @@ export class MidnightApi {
|
|
|
695
705
|
* @param params.cursor - Optional opaque pagination cursor from a previous response.
|
|
696
706
|
* @returns Paginated ABI-ready take objects mapped from the API response.
|
|
697
707
|
* @throws {MidnightApiError} when the API returns a non-2xx response.
|
|
698
|
-
* @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned offer cannot be mapped (malformed numeric or hex fields), when its `market_id` does not match, or cannot be derived from, its embedded market, when it falls outside the requested filters, when its `receiverIfMakerIsSeller` is not a well-formed address, when its caps or buy-side receiver are not executable, or when its units exceed its offer `maxUnits`.
|
|
708
|
+
* @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned offer cannot be mapped (malformed numeric or hex fields), when its `market_id` does not match, or cannot be derived from, its embedded market, when it falls outside the requested filters, when its `receiverIfMakerIsSeller` is not a well-formed address or is the zero address on a sell offer, when its caps or buy-side receiver are not executable, or when its units exceed its offer `maxUnits`.
|
|
699
709
|
* @example
|
|
700
710
|
* ```ts
|
|
701
711
|
* import { MidnightApi } from "@morpho-org/midnight-sdk/api";
|
package/lib/esm/api/helpers.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BLUE_API_BASE_URL, isHexEqual } from "@morpho-org/morpho-ts";
|
|
2
|
-
import { isAddress, isAddressEqual, maxUint256, } from "viem";
|
|
2
|
+
import { isAddress, isAddressEqual, maxUint256, zeroAddress, } from "viem";
|
|
3
3
|
import { InvalidMidnightApiResponseError, InvalidOfferParameterError, MidnightApiError, } from "../errors.js";
|
|
4
4
|
import { MarketUtils } from "../market/index.js";
|
|
5
5
|
import { OfferUtils } from "../offers/index.js";
|
|
@@ -201,7 +201,11 @@ export function mapPriceLevels(levels, side) {
|
|
|
201
201
|
.map(mapPriceLevel)
|
|
202
202
|
.sort((a, b) => (side === "asks" ? a.tick - b.tick : b.tick - a.tick));
|
|
203
203
|
}
|
|
204
|
-
/**
|
|
204
|
+
/**
|
|
205
|
+
* @internal Maps a takeable-offer API payload, returning its market collaterals
|
|
206
|
+
* in canonical protocol order so the struct validated by the SDK is the one
|
|
207
|
+
* ABI-encoded onchain.
|
|
208
|
+
*/
|
|
205
209
|
function mapTakeableOffer(takeableOffer) {
|
|
206
210
|
const offer = takeableOffer.offer;
|
|
207
211
|
return {
|
|
@@ -212,7 +216,9 @@ function mapTakeableOffer(takeableOffer) {
|
|
|
212
216
|
chainId: BigInt(offer.market.chain_id),
|
|
213
217
|
midnight: offer.market.midnight,
|
|
214
218
|
loanToken: offer.market.loan_token,
|
|
215
|
-
collateralParams: offer.market.collaterals
|
|
219
|
+
collateralParams: [...offer.market.collaterals]
|
|
220
|
+
.sort(MarketUtils.compareCollateralTokens)
|
|
221
|
+
.map((collateral) => ({
|
|
216
222
|
token: collateral.token,
|
|
217
223
|
lltv: BigInt(collateral.lltv),
|
|
218
224
|
liquidationCursor: BigInt(collateral.liquidation_cursor),
|
|
@@ -262,6 +268,9 @@ export function mapBoundTakeableOffers(takeableOffers, context) {
|
|
|
262
268
|
if (!isAddress(receiverIfMakerIsSeller)) {
|
|
263
269
|
throw new InvalidMidnightApiResponseError(`Midnight API takeable offer receiverIfMakerIsSeller "${receiverIfMakerIsSeller}" is not an address.`);
|
|
264
270
|
}
|
|
271
|
+
if (!buy && isAddressEqual(receiverIfMakerIsSeller, zeroAddress)) {
|
|
272
|
+
throw new InvalidMidnightApiResponseError(`Midnight API sell offer for market_id "${take.marketId}" routes seller proceeds to the zero address. Sell offers must use a non-zero receiverIfMakerIsSeller.`);
|
|
273
|
+
}
|
|
265
274
|
try {
|
|
266
275
|
// Return values unused: called only to enforce the cap-shape and buy-receiver invariants.
|
|
267
276
|
OfferUtils.validateOfferCaps({ maxUnits, maxAssets });
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** @internal Installed Midnight SDK package version. */
|
|
2
|
-
export declare const MIDNIGHT_SDK_VERSION = "2.2.
|
|
2
|
+
export declare const MIDNIGHT_SDK_VERSION = "2.2.1";
|
package/lib/esm/errors.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { InvalidPositionAccrualStateError as SharedInvalidPositionAccrualStateError, InvalidPositionAccrualTimestampError as SharedInvalidPositionAccrualTimestampError, InvalidPositionLossFactorError as SharedInvalidPositionLossFactorError } from "@morpho-org/morpho-ts";
|
|
2
1
|
import type { Address } from "viem";
|
|
3
2
|
import type { MempoolPayloadValidationIssue } from "./api/types.js";
|
|
4
3
|
/**
|
|
@@ -71,27 +70,42 @@ export declare class SettlementFeeExceedsPriceError extends Error {
|
|
|
71
70
|
/**
|
|
72
71
|
* Thrown when a local position accrual is requested for an impossible timestamp.
|
|
73
72
|
*
|
|
74
|
-
* @
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* import { InvalidPositionAccrualTimestampError } from "@morpho-org/midnight-sdk";
|
|
76
|
+
*
|
|
77
|
+
* throw new InvalidPositionAccrualTimestampError(1n, 2n);
|
|
78
|
+
* ```
|
|
75
79
|
*/
|
|
76
|
-
export declare
|
|
77
|
-
|
|
78
|
-
|
|
80
|
+
export declare class InvalidPositionAccrualTimestampError extends Error {
|
|
81
|
+
constructor(timestamp: bigint, lastAccrual: bigint);
|
|
82
|
+
}
|
|
79
83
|
/**
|
|
80
84
|
* Thrown when a local position accrual sees a market loss factor older than the position.
|
|
81
85
|
*
|
|
82
|
-
* @
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* import { InvalidPositionLossFactorError } from "@morpho-org/midnight-sdk";
|
|
89
|
+
*
|
|
90
|
+
* throw new InvalidPositionLossFactorError(1n, 2n);
|
|
91
|
+
* ```
|
|
83
92
|
*/
|
|
84
|
-
export declare
|
|
85
|
-
|
|
86
|
-
|
|
93
|
+
export declare class InvalidPositionLossFactorError extends Error {
|
|
94
|
+
constructor(marketLossFactor: bigint, positionLossFactor: bigint);
|
|
95
|
+
}
|
|
87
96
|
/**
|
|
88
97
|
* Thrown when local position accrual inputs violate Midnight accounting invariants.
|
|
89
98
|
*
|
|
90
|
-
* @
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* import { InvalidPositionAccrualStateError } from "@morpho-org/midnight-sdk";
|
|
102
|
+
*
|
|
103
|
+
* throw new InvalidPositionAccrualStateError("Pending fee exceeds credit.");
|
|
104
|
+
* ```
|
|
91
105
|
*/
|
|
92
|
-
export declare
|
|
93
|
-
|
|
94
|
-
|
|
106
|
+
export declare class InvalidPositionAccrualStateError extends Error {
|
|
107
|
+
constructor(reason: string);
|
|
108
|
+
}
|
|
95
109
|
/**
|
|
96
110
|
* Thrown when a market parameter cannot satisfy Midnight protocol rules.
|
|
97
111
|
*
|
package/lib/esm/errors.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { InvalidPositionAccrualStateError as SharedInvalidPositionAccrualStateError, InvalidPositionAccrualTimestampError as SharedInvalidPositionAccrualTimestampError, InvalidPositionLossFactorError as SharedInvalidPositionLossFactorError, } from "@morpho-org/morpho-ts";
|
|
2
1
|
/**
|
|
3
2
|
* Thrown when a Midnight offer group violates protocol-level group mechanics.
|
|
4
3
|
*
|
|
@@ -82,25 +81,54 @@ export class SettlementFeeExceedsPriceError extends Error {
|
|
|
82
81
|
this.name = "SettlementFeeExceedsPriceError";
|
|
83
82
|
}
|
|
84
83
|
}
|
|
85
|
-
// Temporary compatibility exception for these shared morpho-ts errors.
|
|
86
84
|
/**
|
|
87
85
|
* Thrown when a local position accrual is requested for an impossible timestamp.
|
|
88
86
|
*
|
|
89
|
-
* @
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* import { InvalidPositionAccrualTimestampError } from "@morpho-org/midnight-sdk";
|
|
90
|
+
*
|
|
91
|
+
* throw new InvalidPositionAccrualTimestampError(1n, 2n);
|
|
92
|
+
* ```
|
|
90
93
|
*/
|
|
91
|
-
export
|
|
94
|
+
export class InvalidPositionAccrualTimestampError extends Error {
|
|
95
|
+
constructor(timestamp, lastAccrual) {
|
|
96
|
+
super(`Position accrual timestamp "${timestamp}" is before last accrual "${lastAccrual}". Use a timestamp greater than or equal to last accrual.`);
|
|
97
|
+
this.name = "InvalidPositionAccrualTimestampError";
|
|
98
|
+
}
|
|
99
|
+
}
|
|
92
100
|
/**
|
|
93
101
|
* Thrown when a local position accrual sees a market loss factor older than the position.
|
|
94
102
|
*
|
|
95
|
-
* @
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* import { InvalidPositionLossFactorError } from "@morpho-org/midnight-sdk";
|
|
106
|
+
*
|
|
107
|
+
* throw new InvalidPositionLossFactorError(1n, 2n);
|
|
108
|
+
* ```
|
|
96
109
|
*/
|
|
97
|
-
export
|
|
110
|
+
export class InvalidPositionLossFactorError extends Error {
|
|
111
|
+
constructor(marketLossFactor, positionLossFactor) {
|
|
112
|
+
super(`Market loss factor "${marketLossFactor}" is below position loss factor "${positionLossFactor}". Fetch a consistent market and position at the same block.`);
|
|
113
|
+
this.name = "InvalidPositionLossFactorError";
|
|
114
|
+
}
|
|
115
|
+
}
|
|
98
116
|
/**
|
|
99
117
|
* Thrown when local position accrual inputs violate Midnight accounting invariants.
|
|
100
118
|
*
|
|
101
|
-
* @
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* import { InvalidPositionAccrualStateError } from "@morpho-org/midnight-sdk";
|
|
122
|
+
*
|
|
123
|
+
* throw new InvalidPositionAccrualStateError("Pending fee exceeds credit.");
|
|
124
|
+
* ```
|
|
102
125
|
*/
|
|
103
|
-
export
|
|
126
|
+
export class InvalidPositionAccrualStateError extends Error {
|
|
127
|
+
constructor(reason) {
|
|
128
|
+
super(`Invalid Midnight position accrual state. ${reason}`);
|
|
129
|
+
this.name = "InvalidPositionAccrualStateError";
|
|
130
|
+
}
|
|
131
|
+
}
|
|
104
132
|
/**
|
|
105
133
|
* Thrown when a market parameter cannot satisfy Midnight protocol rules.
|
|
106
134
|
*
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { MathLib
|
|
1
|
+
import { MathLib } from "@morpho-org/morpho-ts";
|
|
2
|
+
import { InvalidPositionAccrualStateError, InvalidPositionAccrualTimestampError, InvalidPositionLossFactorError, } from "../errors.js";
|
|
2
3
|
/**
|
|
3
4
|
* Domain helpers for Midnight positions.
|
|
4
5
|
*
|
|
@@ -131,17 +132,40 @@ export var PositionUtils;
|
|
|
131
132
|
*/
|
|
132
133
|
function accrueInterest(params) {
|
|
133
134
|
const timestamp = BigInt(params.timestamp);
|
|
135
|
+
const credit = BigInt(params.position.credit);
|
|
136
|
+
const pendingFee = BigInt(params.position.pendingFee);
|
|
137
|
+
const lastLossFactor = BigInt(params.position.lastLossFactor);
|
|
138
|
+
const lastAccrual = BigInt(params.position.lastAccrual);
|
|
134
139
|
const marketLossFactor = BigInt(params.market.lossFactor);
|
|
140
|
+
if (timestamp < lastAccrual) {
|
|
141
|
+
throw new InvalidPositionAccrualTimestampError(timestamp, lastAccrual);
|
|
142
|
+
}
|
|
143
|
+
if (marketLossFactor < lastLossFactor) {
|
|
144
|
+
throw new InvalidPositionLossFactorError(marketLossFactor, lastLossFactor);
|
|
145
|
+
}
|
|
146
|
+
if (pendingFee > credit) {
|
|
147
|
+
throw new InvalidPositionAccrualStateError("Pending fee must be less than or equal to credit.");
|
|
148
|
+
}
|
|
149
|
+
const postSlashCredit = lastLossFactor < MathLib.MAX_UINT_128
|
|
150
|
+
? MathLib.mulDivDown(credit, MathLib.MAX_UINT_128 - marketLossFactor, MathLib.MAX_UINT_128 - lastLossFactor)
|
|
151
|
+
: 0n;
|
|
152
|
+
if (postSlashCredit > credit) {
|
|
153
|
+
throw new InvalidPositionAccrualStateError("Post-slash credit cannot exceed stored credit.");
|
|
154
|
+
}
|
|
155
|
+
const creditDecrease = credit - postSlashCredit;
|
|
156
|
+
const pendingFeeDecrease = credit > 0n ? MathLib.mulDivUp(pendingFee, creditDecrease, credit) : 0n;
|
|
157
|
+
if (pendingFeeDecrease > pendingFee) {
|
|
158
|
+
throw new InvalidPositionAccrualStateError("Pending-fee decrease cannot exceed pending fee.");
|
|
159
|
+
}
|
|
160
|
+
const postSlashPendingFee = pendingFee - pendingFeeDecrease;
|
|
135
161
|
const maturity = BigInt(params.market.params.maturity);
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
timestamp,
|
|
144
|
-
});
|
|
162
|
+
const accrualEnd = timestamp < maturity ? timestamp : maturity;
|
|
163
|
+
const accruedFee = lastAccrual < maturity
|
|
164
|
+
? MathLib.mulDivDown(postSlashPendingFee, accrualEnd - lastAccrual, maturity - lastAccrual)
|
|
165
|
+
: 0n;
|
|
166
|
+
if (accruedFee > postSlashCredit || accruedFee > postSlashPendingFee) {
|
|
167
|
+
throw new InvalidPositionAccrualStateError("Accrued fee cannot exceed post-slash credit or pending fee.");
|
|
168
|
+
}
|
|
145
169
|
const collateral = params.position.collateral.map((assets) => BigInt(assets));
|
|
146
170
|
const collateralParams = params.market.params.collateralParams.map((collateralParam) => ({
|
|
147
171
|
token: collateralParam.token,
|
|
@@ -172,8 +196,8 @@ export var PositionUtils;
|
|
|
172
196
|
position: {
|
|
173
197
|
user: params.position.user,
|
|
174
198
|
marketId: params.position.marketId,
|
|
175
|
-
credit,
|
|
176
|
-
pendingFee,
|
|
199
|
+
credit: postSlashCredit - accruedFee,
|
|
200
|
+
pendingFee: postSlashPendingFee - accruedFee,
|
|
177
201
|
lastLossFactor: marketLossFactor,
|
|
178
202
|
lastAccrual: timestamp,
|
|
179
203
|
debt: BigInt(params.position.debt),
|
|
@@ -250,12 +250,14 @@ export declare namespace PriceRatifierV1 {
|
|
|
250
250
|
* highest leaf indices. A group matching the generic content id of all
|
|
251
251
|
* leaves sharing it (for example from `OfferUtils.toStruct` or
|
|
252
252
|
* `Group.create`) is re-derived with {@link groupId}; other explicit groups
|
|
253
|
-
* are committed as-is.
|
|
253
|
+
* are committed as-is. Every explicit group is first checked with
|
|
254
|
+
* {@link OfferUtils.validateOfferGroup}. An omitted `group` defaults to the leaf's
|
|
254
255
|
* content-addressed singleton {@link groupId}, which commits to
|
|
255
256
|
* `allowedTaker` like the router does.
|
|
256
257
|
*
|
|
257
258
|
* @param leaves - Price-bounded offer leaves in leaf order.
|
|
258
259
|
* @returns PriceRatifierV1 tree descriptor.
|
|
260
|
+
* @throws {InvalidOfferGroupError} when an explicitly grouped offer breaks `OfferUtils.validateOfferGroup` rules (members differ in maker, side, loan token, chain, Midnight contract or cap mode/value, an offer has an invalid cap, or a buy offer sets `receiverIfMakerIsSeller`).
|
|
259
261
|
* @throws {InvalidTreeError} when the leaf list is empty, contains duplicate leaf hashes, or mixes ratifier addresses.
|
|
260
262
|
* @throws {InvalidTreeHeightError} when the padded tree exceeds supported ratifier typehashes.
|
|
261
263
|
* @example
|
|
@@ -274,6 +276,7 @@ export declare namespace PriceRatifierV1 {
|
|
|
274
276
|
* @param params.tree - PriceRatifierV1 tree descriptor or raw leaf input.
|
|
275
277
|
* @param params.leafIndex - Leaf index to prove.
|
|
276
278
|
* @returns Proof descriptor.
|
|
279
|
+
* @throws {InvalidOfferGroupError} when an explicitly grouped offer breaks `OfferUtils.validateOfferGroup` rules (members differ in maker, side, loan token, chain, Midnight contract or cap mode/value, an offer has an invalid cap, or a buy offer sets `receiverIfMakerIsSeller`). For raw leaf input only.
|
|
277
280
|
* @throws {InvalidTreeError} when the tree is invalid or the leaf index is out of range.
|
|
278
281
|
* @throws {InvalidTreeHeightError} when the tree exceeds the supported height.
|
|
279
282
|
* @example
|
|
@@ -387,6 +390,7 @@ export declare namespace PriceRatifierV1 {
|
|
|
387
390
|
* @param params.tree - PriceRatifierV1 tree descriptor or raw leaf input.
|
|
388
391
|
* @param params.leafIndex - Leaf index to prove.
|
|
389
392
|
* @returns ABI-encoded PriceRatifierV1 data.
|
|
393
|
+
* @throws {InvalidOfferGroupError} when an explicitly grouped offer breaks `OfferUtils.validateOfferGroup` rules (members differ in maker, side, loan token, chain, Midnight contract or cap mode/value, an offer has an invalid cap, or a buy offer sets `receiverIfMakerIsSeller`). For raw leaf input only.
|
|
390
394
|
* @throws {InvalidTreeError} when the tree is invalid, the leaf index is outside the tree, or the tree contains multiple ratifiers.
|
|
391
395
|
* @throws {InvalidTreeHeightError} when the tree exceeds the supported height.
|
|
392
396
|
* @example
|
|
@@ -415,6 +419,7 @@ export declare namespace PriceRatifierV1 {
|
|
|
415
419
|
*
|
|
416
420
|
* @param params.tree - PriceRatifierV1 tree descriptor or raw leaf input whose root has already been ratified onchain.
|
|
417
421
|
* @returns Items containing each non-padding offer and its ratifier data.
|
|
422
|
+
* @throws {InvalidOfferGroupError} when an explicitly grouped offer breaks `OfferUtils.validateOfferGroup` rules (members differ in maker, side, loan token, chain, Midnight contract or cap mode/value, an offer has an invalid cap, or a buy offer sets `receiverIfMakerIsSeller`). For raw leaf input only.
|
|
418
423
|
* @throws {InvalidTreeError} when the tree is invalid or contains multiple ratifiers.
|
|
419
424
|
* @throws {InvalidTreeHeightError} when the tree exceeds the supported height.
|
|
420
425
|
* @example
|
|
@@ -210,12 +210,14 @@ export var PriceRatifierV1;
|
|
|
210
210
|
* highest leaf indices. A group matching the generic content id of all
|
|
211
211
|
* leaves sharing it (for example from `OfferUtils.toStruct` or
|
|
212
212
|
* `Group.create`) is re-derived with {@link groupId}; other explicit groups
|
|
213
|
-
* are committed as-is.
|
|
213
|
+
* are committed as-is. Every explicit group is first checked with
|
|
214
|
+
* {@link OfferUtils.validateOfferGroup}. An omitted `group` defaults to the leaf's
|
|
214
215
|
* content-addressed singleton {@link groupId}, which commits to
|
|
215
216
|
* `allowedTaker` like the router does.
|
|
216
217
|
*
|
|
217
218
|
* @param leaves - Price-bounded offer leaves in leaf order.
|
|
218
219
|
* @returns PriceRatifierV1 tree descriptor.
|
|
220
|
+
* @throws {InvalidOfferGroupError} when an explicitly grouped offer breaks `OfferUtils.validateOfferGroup` rules (members differ in maker, side, loan token, chain, Midnight contract or cap mode/value, an offer has an invalid cap, or a buy offer sets `receiverIfMakerIsSeller`).
|
|
219
221
|
* @throws {InvalidTreeError} when the leaf list is empty, contains duplicate leaf hashes, or mixes ratifier addresses.
|
|
220
222
|
* @throws {InvalidTreeHeightError} when the padded tree exceeds supported ratifier typehashes.
|
|
221
223
|
* @example
|
|
@@ -269,6 +271,7 @@ export var PriceRatifierV1;
|
|
|
269
271
|
* @param params.tree - PriceRatifierV1 tree descriptor or raw leaf input.
|
|
270
272
|
* @param params.leafIndex - Leaf index to prove.
|
|
271
273
|
* @returns Proof descriptor.
|
|
274
|
+
* @throws {InvalidOfferGroupError} when an explicitly grouped offer breaks `OfferUtils.validateOfferGroup` rules (members differ in maker, side, loan token, chain, Midnight contract or cap mode/value, an offer has an invalid cap, or a buy offer sets `receiverIfMakerIsSeller`). For raw leaf input only.
|
|
272
275
|
* @throws {InvalidTreeError} when the tree is invalid or the leaf index is out of range.
|
|
273
276
|
* @throws {InvalidTreeHeightError} when the tree exceeds the supported height.
|
|
274
277
|
* @example
|
|
@@ -406,6 +409,7 @@ export var PriceRatifierV1;
|
|
|
406
409
|
* @param params.tree - PriceRatifierV1 tree descriptor or raw leaf input.
|
|
407
410
|
* @param params.leafIndex - Leaf index to prove.
|
|
408
411
|
* @returns ABI-encoded PriceRatifierV1 data.
|
|
412
|
+
* @throws {InvalidOfferGroupError} when an explicitly grouped offer breaks `OfferUtils.validateOfferGroup` rules (members differ in maker, side, loan token, chain, Midnight contract or cap mode/value, an offer has an invalid cap, or a buy offer sets `receiverIfMakerIsSeller`). For raw leaf input only.
|
|
409
413
|
* @throws {InvalidTreeError} when the tree is invalid, the leaf index is outside the tree, or the tree contains multiple ratifiers.
|
|
410
414
|
* @throws {InvalidTreeHeightError} when the tree exceeds the supported height.
|
|
411
415
|
* @example
|
|
@@ -442,6 +446,7 @@ export var PriceRatifierV1;
|
|
|
442
446
|
*
|
|
443
447
|
* @param params.tree - PriceRatifierV1 tree descriptor or raw leaf input whose root has already been ratified onchain.
|
|
444
448
|
* @returns Items containing each non-padding offer and its ratifier data.
|
|
449
|
+
* @throws {InvalidOfferGroupError} when an explicitly grouped offer breaks `OfferUtils.validateOfferGroup` rules (members differ in maker, side, loan token, chain, Midnight contract or cap mode/value, an offer has an invalid cap, or a buy offer sets `receiverIfMakerIsSeller`). For raw leaf input only.
|
|
445
450
|
* @throws {InvalidTreeError} when the tree is invalid or contains multiple ratifiers.
|
|
446
451
|
* @throws {InvalidTreeHeightError} when the tree exceeds the supported height.
|
|
447
452
|
* @example
|
|
@@ -280,12 +280,14 @@ export declare namespace RateRatifierV1 {
|
|
|
280
280
|
* highest leaf indices. A group matching the generic content id of all
|
|
281
281
|
* leaves sharing it (for example from `OfferUtils.toStruct` or
|
|
282
282
|
* `Group.create`) is re-derived with {@link groupId}; other explicit groups
|
|
283
|
-
* are committed as-is.
|
|
283
|
+
* are committed as-is. Every explicit group is first checked with
|
|
284
|
+
* {@link OfferUtils.validateOfferGroup}. An omitted `group` defaults to the leaf's
|
|
284
285
|
* content-addressed singleton {@link groupId}, which commits to `rate` and
|
|
285
286
|
* `allowedTaker` like the router does.
|
|
286
287
|
*
|
|
287
288
|
* @param leaves - Rate-bounded offer leaves in leaf order.
|
|
288
289
|
* @returns RateRatifierV1 tree descriptor.
|
|
290
|
+
* @throws {InvalidOfferGroupError} when an explicitly grouped offer breaks `OfferUtils.validateOfferGroup` rules (members differ in maker, side, loan token, chain, Midnight contract or cap mode/value, an offer has an invalid cap, or a buy offer sets `receiverIfMakerIsSeller`).
|
|
289
291
|
* @throws {InvalidTreeError} when the leaf list is empty, contains duplicate leaf hashes, or mixes ratifier addresses.
|
|
290
292
|
* @throws {InvalidRateRatifierV1RateError} when a leaf rate is negative.
|
|
291
293
|
* @throws {InvalidRateRatifierV1TickError} when a leaf offer tick is below {@link MIN_TICK}.
|
|
@@ -306,6 +308,7 @@ export declare namespace RateRatifierV1 {
|
|
|
306
308
|
* @param params.tree - RateRatifierV1 tree descriptor or raw leaf input.
|
|
307
309
|
* @param params.leafIndex - Leaf index to prove.
|
|
308
310
|
* @returns Proof descriptor.
|
|
311
|
+
* @throws {InvalidOfferGroupError} when an explicitly grouped offer breaks `OfferUtils.validateOfferGroup` rules (members differ in maker, side, loan token, chain, Midnight contract or cap mode/value, an offer has an invalid cap, or a buy offer sets `receiverIfMakerIsSeller`). For raw leaf input only.
|
|
309
312
|
* @throws {InvalidTreeError} when the tree is invalid or the leaf index is out of range.
|
|
310
313
|
* @throws {InvalidTreeHeightError} when the tree exceeds the supported height.
|
|
311
314
|
* @throws {InvalidRateRatifierV1RateError} when a raw leaf carries a negative rate.
|
|
@@ -426,6 +429,7 @@ export declare namespace RateRatifierV1 {
|
|
|
426
429
|
* @param params.tree - RateRatifierV1 tree descriptor or raw leaf input.
|
|
427
430
|
* @param params.leafIndex - Leaf index to prove.
|
|
428
431
|
* @returns ABI-encoded RateRatifierV1 data.
|
|
432
|
+
* @throws {InvalidOfferGroupError} when an explicitly grouped offer breaks `OfferUtils.validateOfferGroup` rules (members differ in maker, side, loan token, chain, Midnight contract or cap mode/value, an offer has an invalid cap, or a buy offer sets `receiverIfMakerIsSeller`). For raw leaf input only.
|
|
429
433
|
* @throws {InvalidTreeError} when the tree is invalid, the leaf index is outside the tree, or the tree contains multiple ratifiers.
|
|
430
434
|
* @throws {InvalidTreeHeightError} when the tree exceeds the supported height.
|
|
431
435
|
* @throws {InvalidRateRatifierV1RateError} when a raw leaf carries a negative rate.
|
|
@@ -456,6 +460,7 @@ export declare namespace RateRatifierV1 {
|
|
|
456
460
|
*
|
|
457
461
|
* @param params.tree - RateRatifierV1 tree descriptor or raw leaf input whose root has already been ratified onchain.
|
|
458
462
|
* @returns Items containing each non-padding offer and its ratifier data.
|
|
463
|
+
* @throws {InvalidOfferGroupError} when an explicitly grouped offer breaks `OfferUtils.validateOfferGroup` rules (members differ in maker, side, loan token, chain, Midnight contract or cap mode/value, an offer has an invalid cap, or a buy offer sets `receiverIfMakerIsSeller`). For raw leaf input only.
|
|
459
464
|
* @throws {InvalidTreeError} when the tree is invalid or contains multiple ratifiers.
|
|
460
465
|
* @throws {InvalidTreeHeightError} when the tree exceeds the supported height.
|
|
461
466
|
* @throws {InvalidRateRatifierV1RateError} when a raw leaf carries a negative rate.
|
|
@@ -240,12 +240,14 @@ export var RateRatifierV1;
|
|
|
240
240
|
* highest leaf indices. A group matching the generic content id of all
|
|
241
241
|
* leaves sharing it (for example from `OfferUtils.toStruct` or
|
|
242
242
|
* `Group.create`) is re-derived with {@link groupId}; other explicit groups
|
|
243
|
-
* are committed as-is.
|
|
243
|
+
* are committed as-is. Every explicit group is first checked with
|
|
244
|
+
* {@link OfferUtils.validateOfferGroup}. An omitted `group` defaults to the leaf's
|
|
244
245
|
* content-addressed singleton {@link groupId}, which commits to `rate` and
|
|
245
246
|
* `allowedTaker` like the router does.
|
|
246
247
|
*
|
|
247
248
|
* @param leaves - Rate-bounded offer leaves in leaf order.
|
|
248
249
|
* @returns RateRatifierV1 tree descriptor.
|
|
250
|
+
* @throws {InvalidOfferGroupError} when an explicitly grouped offer breaks `OfferUtils.validateOfferGroup` rules (members differ in maker, side, loan token, chain, Midnight contract or cap mode/value, an offer has an invalid cap, or a buy offer sets `receiverIfMakerIsSeller`).
|
|
249
251
|
* @throws {InvalidTreeError} when the leaf list is empty, contains duplicate leaf hashes, or mixes ratifier addresses.
|
|
250
252
|
* @throws {InvalidRateRatifierV1RateError} when a leaf rate is negative.
|
|
251
253
|
* @throws {InvalidRateRatifierV1TickError} when a leaf offer tick is below {@link MIN_TICK}.
|
|
@@ -317,6 +319,7 @@ export var RateRatifierV1;
|
|
|
317
319
|
* @param params.tree - RateRatifierV1 tree descriptor or raw leaf input.
|
|
318
320
|
* @param params.leafIndex - Leaf index to prove.
|
|
319
321
|
* @returns Proof descriptor.
|
|
322
|
+
* @throws {InvalidOfferGroupError} when an explicitly grouped offer breaks `OfferUtils.validateOfferGroup` rules (members differ in maker, side, loan token, chain, Midnight contract or cap mode/value, an offer has an invalid cap, or a buy offer sets `receiverIfMakerIsSeller`). For raw leaf input only.
|
|
320
323
|
* @throws {InvalidTreeError} when the tree is invalid or the leaf index is out of range.
|
|
321
324
|
* @throws {InvalidTreeHeightError} when the tree exceeds the supported height.
|
|
322
325
|
* @throws {InvalidRateRatifierV1RateError} when a raw leaf carries a negative rate.
|
|
@@ -468,6 +471,7 @@ export var RateRatifierV1;
|
|
|
468
471
|
* @param params.tree - RateRatifierV1 tree descriptor or raw leaf input.
|
|
469
472
|
* @param params.leafIndex - Leaf index to prove.
|
|
470
473
|
* @returns ABI-encoded RateRatifierV1 data.
|
|
474
|
+
* @throws {InvalidOfferGroupError} when an explicitly grouped offer breaks `OfferUtils.validateOfferGroup` rules (members differ in maker, side, loan token, chain, Midnight contract or cap mode/value, an offer has an invalid cap, or a buy offer sets `receiverIfMakerIsSeller`). For raw leaf input only.
|
|
471
475
|
* @throws {InvalidTreeError} when the tree is invalid, the leaf index is outside the tree, or the tree contains multiple ratifiers.
|
|
472
476
|
* @throws {InvalidTreeHeightError} when the tree exceeds the supported height.
|
|
473
477
|
* @throws {InvalidRateRatifierV1RateError} when a raw leaf carries a negative rate.
|
|
@@ -507,6 +511,7 @@ export var RateRatifierV1;
|
|
|
507
511
|
*
|
|
508
512
|
* @param params.tree - RateRatifierV1 tree descriptor or raw leaf input whose root has already been ratified onchain.
|
|
509
513
|
* @returns Items containing each non-padding offer and its ratifier data.
|
|
514
|
+
* @throws {InvalidOfferGroupError} when an explicitly grouped offer breaks `OfferUtils.validateOfferGroup` rules (members differ in maker, side, loan token, chain, Midnight contract or cap mode/value, an offer has an invalid cap, or a buy offer sets `receiverIfMakerIsSeller`). For raw leaf input only.
|
|
510
515
|
* @throws {InvalidTreeError} when the tree is invalid or contains multiple ratifiers.
|
|
511
516
|
* @throws {InvalidTreeHeightError} when the tree exceeds the supported height.
|
|
512
517
|
* @throws {InvalidRateRatifierV1RateError} when a raw leaf carries a negative rate.
|