@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
|
@@ -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";
|
|
@@ -207,7 +207,7 @@ class MidnightApi {
|
|
|
207
207
|
* @param params.request - Optional fetch options forwarded to this request.
|
|
208
208
|
* @returns ABI-ready take objects mapped from the API response.
|
|
209
209
|
* @throws {MidnightApiError} when the API returns a non-2xx response.
|
|
210
|
-
* @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`.
|
|
210
|
+
* @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`.
|
|
211
211
|
* @example
|
|
212
212
|
* ```ts
|
|
213
213
|
* import { MidnightApi } from "@morpho-org/midnight-sdk/api";
|
|
@@ -253,11 +253,16 @@ class MidnightApi {
|
|
|
253
253
|
* @param params.fetch - Optional fetch implementation override.
|
|
254
254
|
* @param params.request - Optional fetch options forwarded to this request.
|
|
255
255
|
* @returns Quote and ABI-ready take caps. `averageWorstPrice` equals the caller's guard when provided,
|
|
256
|
-
* otherwise the API's guard.
|
|
256
|
+
* otherwise the API's guard. Offers are returned as the API sends them. An `asks` quote by
|
|
257
|
+
* `assets` can include a sell offer whose buyer price (offer price plus the market's settlement
|
|
258
|
+
* fee) exceeds one asset per unit, such as a `MAX_TICK` ask when the fee is positive. The
|
|
259
|
+
* `MidnightBundlesV2` assets-target buy reverts on such an offer before its per-offer error
|
|
260
|
+
* handling, so the whole bundle fails. Drop these offers before building an assets-target buy,
|
|
261
|
+
* or use a `units` target.
|
|
257
262
|
* @throws {InvalidMidnightApiQuoteTargetError} when the runtime input does not set exactly one of `units` or `assets`.
|
|
258
263
|
* @throws {NegativeValueError} when `settlementFee` is negative.
|
|
259
264
|
* @throws {MidnightApiError} when the API returns a non-2xx response.
|
|
260
|
-
* @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.
|
|
265
|
+
* @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.
|
|
261
266
|
* @throws {SettlementFeeExceedsPriceError} when a bid's settlement fee exceeds its offer price.
|
|
262
267
|
* @example
|
|
263
268
|
* ```ts
|
|
@@ -382,7 +387,7 @@ class MidnightApi {
|
|
|
382
387
|
* @param params.request - Optional fetch options forwarded to this request.
|
|
383
388
|
* @returns Paginated ABI-ready take objects mapped from the API response.
|
|
384
389
|
* @throws {MidnightApiError} when the API returns a non-2xx response.
|
|
385
|
-
* @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`.
|
|
390
|
+
* @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`.
|
|
386
391
|
* @example
|
|
387
392
|
* ```ts
|
|
388
393
|
* import { MidnightApi } from "@morpho-org/midnight-sdk/api";
|
|
@@ -630,7 +635,7 @@ class MidnightApi {
|
|
|
630
635
|
* @param params.side - Book side to query.
|
|
631
636
|
* @returns ABI-ready take objects mapped from the API response.
|
|
632
637
|
* @throws {MidnightApiError} when the API returns a non-2xx response.
|
|
633
|
-
* @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`.
|
|
638
|
+
* @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`.
|
|
634
639
|
* @example
|
|
635
640
|
* ```ts
|
|
636
641
|
* import { MidnightApi } from "@morpho-org/midnight-sdk/api";
|
|
@@ -662,11 +667,16 @@ class MidnightApi {
|
|
|
662
667
|
* @param params.slippage - Optional slippage percentage used to derive the guard. Mutually exclusive with `params.averageWorstPrice`.
|
|
663
668
|
* @param params.settlementFee - Optional current WAD-scaled settlement fee used for local guard validation. Defaults to zero.
|
|
664
669
|
* @returns Quote and ABI-ready take caps. `averageWorstPrice` equals the caller's guard when provided,
|
|
665
|
-
* otherwise the API's guard.
|
|
670
|
+
* otherwise the API's guard. Offers are returned as the API sends them. An `asks` quote by
|
|
671
|
+
* `assets` can include a sell offer whose buyer price (offer price plus the market's settlement
|
|
672
|
+
* fee) exceeds one asset per unit, such as a `MAX_TICK` ask when the fee is positive. The
|
|
673
|
+
* `MidnightBundlesV2` assets-target buy reverts on such an offer before its per-offer error
|
|
674
|
+
* handling, so the whole bundle fails. Drop these offers before building an assets-target buy,
|
|
675
|
+
* or use a `units` target.
|
|
666
676
|
* @throws {InvalidMidnightApiQuoteTargetError} when the runtime input does not set exactly one of `units` or `assets`.
|
|
667
677
|
* @throws {NegativeValueError} when `settlementFee` is negative.
|
|
668
678
|
* @throws {MidnightApiError} when the API returns a non-2xx response.
|
|
669
|
-
* @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.
|
|
679
|
+
* @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.
|
|
670
680
|
* @throws {SettlementFeeExceedsPriceError} when a bid's settlement fee exceeds its offer price.
|
|
671
681
|
* @example
|
|
672
682
|
* ```ts
|
|
@@ -699,7 +709,7 @@ class MidnightApi {
|
|
|
699
709
|
* @param params.cursor - Optional opaque pagination cursor from a previous response.
|
|
700
710
|
* @returns Paginated ABI-ready take objects mapped from the API response.
|
|
701
711
|
* @throws {MidnightApiError} when the API returns a non-2xx response.
|
|
702
|
-
* @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`.
|
|
712
|
+
* @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`.
|
|
703
713
|
* @example
|
|
704
714
|
* ```ts
|
|
705
715
|
* import { MidnightApi } from "@morpho-org/midnight-sdk/api";
|
package/lib/cjs/api/helpers.js
CHANGED
|
@@ -210,7 +210,11 @@ function mapPriceLevels(levels, side) {
|
|
|
210
210
|
.map(mapPriceLevel)
|
|
211
211
|
.sort((a, b) => (side === "asks" ? a.tick - b.tick : b.tick - a.tick));
|
|
212
212
|
}
|
|
213
|
-
/**
|
|
213
|
+
/**
|
|
214
|
+
* @internal Maps a takeable-offer API payload, returning its market collaterals
|
|
215
|
+
* in canonical protocol order so the struct validated by the SDK is the one
|
|
216
|
+
* ABI-encoded onchain.
|
|
217
|
+
*/
|
|
214
218
|
function mapTakeableOffer(takeableOffer) {
|
|
215
219
|
const offer = takeableOffer.offer;
|
|
216
220
|
return {
|
|
@@ -221,7 +225,9 @@ function mapTakeableOffer(takeableOffer) {
|
|
|
221
225
|
chainId: BigInt(offer.market.chain_id),
|
|
222
226
|
midnight: offer.market.midnight,
|
|
223
227
|
loanToken: offer.market.loan_token,
|
|
224
|
-
collateralParams: offer.market.collaterals
|
|
228
|
+
collateralParams: [...offer.market.collaterals]
|
|
229
|
+
.sort(index_js_1.MarketUtils.compareCollateralTokens)
|
|
230
|
+
.map((collateral) => ({
|
|
225
231
|
token: collateral.token,
|
|
226
232
|
lltv: BigInt(collateral.lltv),
|
|
227
233
|
liquidationCursor: BigInt(collateral.liquidation_cursor),
|
|
@@ -271,6 +277,9 @@ function mapBoundTakeableOffers(takeableOffers, context) {
|
|
|
271
277
|
if (!(0, viem_1.isAddress)(receiverIfMakerIsSeller)) {
|
|
272
278
|
throw new errors_js_1.InvalidMidnightApiResponseError(`Midnight API takeable offer receiverIfMakerIsSeller "${receiverIfMakerIsSeller}" is not an address.`);
|
|
273
279
|
}
|
|
280
|
+
if (!buy && (0, viem_1.isAddressEqual)(receiverIfMakerIsSeller, viem_1.zeroAddress)) {
|
|
281
|
+
throw new errors_js_1.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.`);
|
|
282
|
+
}
|
|
274
283
|
try {
|
|
275
284
|
// Return values unused: called only to enforce the cap-shape and buy-receiver invariants.
|
|
276
285
|
index_js_2.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/cjs/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/cjs/errors.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InvalidMidnightApiQuoteTargetError = exports.InvalidMidnightApiResponseError = exports.MidnightApiError = exports.InvalidEcrecoverSignatureVError = exports.InvalidTypedDataSignatureError = exports.MidnightMempoolValidationError = exports.ChainIdMismatchError = exports.RatifierV1TakerNotAllowedError = exports.InvalidRatifierV1AddressError = exports.InvalidRateRatifierV1TimeError = exports.InvalidRateRatifierV1TickError = exports.RateRatifierV1BoundOverflowError = exports.InvalidRateRatifierV1RateError = exports.InvalidTreeError = exports.InvalidTreeHeightError = exports.PayloadDecodeError = exports.InvalidOfferParameterError = exports.UnknownCollateralIndexError = exports.InvalidMarketParameterError = exports.InvalidPositionAccrualStateError = exports.InvalidPositionLossFactorError = exports.InvalidPositionAccrualTimestampError = exports.SettlementFeeExceedsPriceError = exports.InvalidTickSpacingError = exports.PriceGreaterThanOneError = exports.TickOutOfRangeError = exports.InvalidOfferGroupError = void 0;
|
|
4
|
-
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
5
4
|
/**
|
|
6
5
|
* Thrown when a Midnight offer group violates protocol-level group mechanics.
|
|
7
6
|
*
|
|
@@ -90,25 +89,57 @@ class SettlementFeeExceedsPriceError extends Error {
|
|
|
90
89
|
}
|
|
91
90
|
}
|
|
92
91
|
exports.SettlementFeeExceedsPriceError = SettlementFeeExceedsPriceError;
|
|
93
|
-
// Temporary compatibility exception for these shared morpho-ts errors.
|
|
94
92
|
/**
|
|
95
93
|
* Thrown when a local position accrual is requested for an impossible timestamp.
|
|
96
94
|
*
|
|
97
|
-
* @
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* import { InvalidPositionAccrualTimestampError } from "@morpho-org/midnight-sdk";
|
|
98
|
+
*
|
|
99
|
+
* throw new InvalidPositionAccrualTimestampError(1n, 2n);
|
|
100
|
+
* ```
|
|
98
101
|
*/
|
|
99
|
-
|
|
102
|
+
class InvalidPositionAccrualTimestampError extends Error {
|
|
103
|
+
constructor(timestamp, lastAccrual) {
|
|
104
|
+
super(`Position accrual timestamp "${timestamp}" is before last accrual "${lastAccrual}". Use a timestamp greater than or equal to last accrual.`);
|
|
105
|
+
this.name = "InvalidPositionAccrualTimestampError";
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.InvalidPositionAccrualTimestampError = InvalidPositionAccrualTimestampError;
|
|
100
109
|
/**
|
|
101
110
|
* Thrown when a local position accrual sees a market loss factor older than the position.
|
|
102
111
|
*
|
|
103
|
-
* @
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* import { InvalidPositionLossFactorError } from "@morpho-org/midnight-sdk";
|
|
115
|
+
*
|
|
116
|
+
* throw new InvalidPositionLossFactorError(1n, 2n);
|
|
117
|
+
* ```
|
|
104
118
|
*/
|
|
105
|
-
|
|
119
|
+
class InvalidPositionLossFactorError extends Error {
|
|
120
|
+
constructor(marketLossFactor, positionLossFactor) {
|
|
121
|
+
super(`Market loss factor "${marketLossFactor}" is below position loss factor "${positionLossFactor}". Fetch a consistent market and position at the same block.`);
|
|
122
|
+
this.name = "InvalidPositionLossFactorError";
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
exports.InvalidPositionLossFactorError = InvalidPositionLossFactorError;
|
|
106
126
|
/**
|
|
107
127
|
* Thrown when local position accrual inputs violate Midnight accounting invariants.
|
|
108
128
|
*
|
|
109
|
-
* @
|
|
129
|
+
* @example
|
|
130
|
+
* ```ts
|
|
131
|
+
* import { InvalidPositionAccrualStateError } from "@morpho-org/midnight-sdk";
|
|
132
|
+
*
|
|
133
|
+
* throw new InvalidPositionAccrualStateError("Pending fee exceeds credit.");
|
|
134
|
+
* ```
|
|
110
135
|
*/
|
|
111
|
-
|
|
136
|
+
class InvalidPositionAccrualStateError extends Error {
|
|
137
|
+
constructor(reason) {
|
|
138
|
+
super(`Invalid Midnight position accrual state. ${reason}`);
|
|
139
|
+
this.name = "InvalidPositionAccrualStateError";
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
exports.InvalidPositionAccrualStateError = InvalidPositionAccrualStateError;
|
|
112
143
|
/**
|
|
113
144
|
* Thrown when a market parameter cannot satisfy Midnight protocol rules.
|
|
114
145
|
*
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PositionUtils = void 0;
|
|
4
4
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
5
|
+
const errors_js_1 = require("../errors.js");
|
|
5
6
|
/**
|
|
6
7
|
* Domain helpers for Midnight positions.
|
|
7
8
|
*
|
|
@@ -134,17 +135,40 @@ var PositionUtils;
|
|
|
134
135
|
*/
|
|
135
136
|
function accrueInterest(params) {
|
|
136
137
|
const timestamp = BigInt(params.timestamp);
|
|
138
|
+
const credit = BigInt(params.position.credit);
|
|
139
|
+
const pendingFee = BigInt(params.position.pendingFee);
|
|
140
|
+
const lastLossFactor = BigInt(params.position.lastLossFactor);
|
|
141
|
+
const lastAccrual = BigInt(params.position.lastAccrual);
|
|
137
142
|
const marketLossFactor = BigInt(params.market.lossFactor);
|
|
143
|
+
if (timestamp < lastAccrual) {
|
|
144
|
+
throw new errors_js_1.InvalidPositionAccrualTimestampError(timestamp, lastAccrual);
|
|
145
|
+
}
|
|
146
|
+
if (marketLossFactor < lastLossFactor) {
|
|
147
|
+
throw new errors_js_1.InvalidPositionLossFactorError(marketLossFactor, lastLossFactor);
|
|
148
|
+
}
|
|
149
|
+
if (pendingFee > credit) {
|
|
150
|
+
throw new errors_js_1.InvalidPositionAccrualStateError("Pending fee must be less than or equal to credit.");
|
|
151
|
+
}
|
|
152
|
+
const postSlashCredit = lastLossFactor < morpho_ts_1.MathLib.MAX_UINT_128
|
|
153
|
+
? morpho_ts_1.MathLib.mulDivDown(credit, morpho_ts_1.MathLib.MAX_UINT_128 - marketLossFactor, morpho_ts_1.MathLib.MAX_UINT_128 - lastLossFactor)
|
|
154
|
+
: 0n;
|
|
155
|
+
if (postSlashCredit > credit) {
|
|
156
|
+
throw new errors_js_1.InvalidPositionAccrualStateError("Post-slash credit cannot exceed stored credit.");
|
|
157
|
+
}
|
|
158
|
+
const creditDecrease = credit - postSlashCredit;
|
|
159
|
+
const pendingFeeDecrease = credit > 0n ? morpho_ts_1.MathLib.mulDivUp(pendingFee, creditDecrease, credit) : 0n;
|
|
160
|
+
if (pendingFeeDecrease > pendingFee) {
|
|
161
|
+
throw new errors_js_1.InvalidPositionAccrualStateError("Pending-fee decrease cannot exceed pending fee.");
|
|
162
|
+
}
|
|
163
|
+
const postSlashPendingFee = pendingFee - pendingFeeDecrease;
|
|
138
164
|
const maturity = BigInt(params.market.params.maturity);
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
timestamp,
|
|
147
|
-
});
|
|
165
|
+
const accrualEnd = timestamp < maturity ? timestamp : maturity;
|
|
166
|
+
const accruedFee = lastAccrual < maturity
|
|
167
|
+
? morpho_ts_1.MathLib.mulDivDown(postSlashPendingFee, accrualEnd - lastAccrual, maturity - lastAccrual)
|
|
168
|
+
: 0n;
|
|
169
|
+
if (accruedFee > postSlashCredit || accruedFee > postSlashPendingFee) {
|
|
170
|
+
throw new errors_js_1.InvalidPositionAccrualStateError("Accrued fee cannot exceed post-slash credit or pending fee.");
|
|
171
|
+
}
|
|
148
172
|
const collateral = params.position.collateral.map((assets) => BigInt(assets));
|
|
149
173
|
const collateralParams = params.market.params.collateralParams.map((collateralParam) => ({
|
|
150
174
|
token: collateralParam.token,
|
|
@@ -175,8 +199,8 @@ var PositionUtils;
|
|
|
175
199
|
position: {
|
|
176
200
|
user: params.position.user,
|
|
177
201
|
marketId: params.position.marketId,
|
|
178
|
-
credit,
|
|
179
|
-
pendingFee,
|
|
202
|
+
credit: postSlashCredit - accruedFee,
|
|
203
|
+
pendingFee: postSlashPendingFee - accruedFee,
|
|
180
204
|
lastLossFactor: marketLossFactor,
|
|
181
205
|
lastAccrual: timestamp,
|
|
182
206
|
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
|
|
@@ -213,12 +213,14 @@ var PriceRatifierV1;
|
|
|
213
213
|
* highest leaf indices. A group matching the generic content id of all
|
|
214
214
|
* leaves sharing it (for example from `OfferUtils.toStruct` or
|
|
215
215
|
* `Group.create`) is re-derived with {@link groupId}; other explicit groups
|
|
216
|
-
* are committed as-is.
|
|
216
|
+
* are committed as-is. Every explicit group is first checked with
|
|
217
|
+
* {@link OfferUtils.validateOfferGroup}. An omitted `group` defaults to the leaf's
|
|
217
218
|
* content-addressed singleton {@link groupId}, which commits to
|
|
218
219
|
* `allowedTaker` like the router does.
|
|
219
220
|
*
|
|
220
221
|
* @param leaves - Price-bounded offer leaves in leaf order.
|
|
221
222
|
* @returns PriceRatifierV1 tree descriptor.
|
|
223
|
+
* @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`).
|
|
222
224
|
* @throws {InvalidTreeError} when the leaf list is empty, contains duplicate leaf hashes, or mixes ratifier addresses.
|
|
223
225
|
* @throws {InvalidTreeHeightError} when the padded tree exceeds supported ratifier typehashes.
|
|
224
226
|
* @example
|
|
@@ -272,6 +274,7 @@ var PriceRatifierV1;
|
|
|
272
274
|
* @param params.tree - PriceRatifierV1 tree descriptor or raw leaf input.
|
|
273
275
|
* @param params.leafIndex - Leaf index to prove.
|
|
274
276
|
* @returns Proof descriptor.
|
|
277
|
+
* @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.
|
|
275
278
|
* @throws {InvalidTreeError} when the tree is invalid or the leaf index is out of range.
|
|
276
279
|
* @throws {InvalidTreeHeightError} when the tree exceeds the supported height.
|
|
277
280
|
* @example
|
|
@@ -409,6 +412,7 @@ var PriceRatifierV1;
|
|
|
409
412
|
* @param params.tree - PriceRatifierV1 tree descriptor or raw leaf input.
|
|
410
413
|
* @param params.leafIndex - Leaf index to prove.
|
|
411
414
|
* @returns ABI-encoded PriceRatifierV1 data.
|
|
415
|
+
* @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.
|
|
412
416
|
* @throws {InvalidTreeError} when the tree is invalid, the leaf index is outside the tree, or the tree contains multiple ratifiers.
|
|
413
417
|
* @throws {InvalidTreeHeightError} when the tree exceeds the supported height.
|
|
414
418
|
* @example
|
|
@@ -445,6 +449,7 @@ var PriceRatifierV1;
|
|
|
445
449
|
*
|
|
446
450
|
* @param params.tree - PriceRatifierV1 tree descriptor or raw leaf input whose root has already been ratified onchain.
|
|
447
451
|
* @returns Items containing each non-padding offer and its ratifier data.
|
|
452
|
+
* @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.
|
|
448
453
|
* @throws {InvalidTreeError} when the tree is invalid or contains multiple ratifiers.
|
|
449
454
|
* @throws {InvalidTreeHeightError} when the tree exceeds the supported height.
|
|
450
455
|
* @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.
|
|
@@ -243,12 +243,14 @@ var RateRatifierV1;
|
|
|
243
243
|
* highest leaf indices. A group matching the generic content id of all
|
|
244
244
|
* leaves sharing it (for example from `OfferUtils.toStruct` or
|
|
245
245
|
* `Group.create`) is re-derived with {@link groupId}; other explicit groups
|
|
246
|
-
* are committed as-is.
|
|
246
|
+
* are committed as-is. Every explicit group is first checked with
|
|
247
|
+
* {@link OfferUtils.validateOfferGroup}. An omitted `group` defaults to the leaf's
|
|
247
248
|
* content-addressed singleton {@link groupId}, which commits to `rate` and
|
|
248
249
|
* `allowedTaker` like the router does.
|
|
249
250
|
*
|
|
250
251
|
* @param leaves - Rate-bounded offer leaves in leaf order.
|
|
251
252
|
* @returns RateRatifierV1 tree descriptor.
|
|
253
|
+
* @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`).
|
|
252
254
|
* @throws {InvalidTreeError} when the leaf list is empty, contains duplicate leaf hashes, or mixes ratifier addresses.
|
|
253
255
|
* @throws {InvalidRateRatifierV1RateError} when a leaf rate is negative.
|
|
254
256
|
* @throws {InvalidRateRatifierV1TickError} when a leaf offer tick is below {@link MIN_TICK}.
|
|
@@ -320,6 +322,7 @@ var RateRatifierV1;
|
|
|
320
322
|
* @param params.tree - RateRatifierV1 tree descriptor or raw leaf input.
|
|
321
323
|
* @param params.leafIndex - Leaf index to prove.
|
|
322
324
|
* @returns Proof descriptor.
|
|
325
|
+
* @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.
|
|
323
326
|
* @throws {InvalidTreeError} when the tree is invalid or the leaf index is out of range.
|
|
324
327
|
* @throws {InvalidTreeHeightError} when the tree exceeds the supported height.
|
|
325
328
|
* @throws {InvalidRateRatifierV1RateError} when a raw leaf carries a negative rate.
|
|
@@ -471,6 +474,7 @@ var RateRatifierV1;
|
|
|
471
474
|
* @param params.tree - RateRatifierV1 tree descriptor or raw leaf input.
|
|
472
475
|
* @param params.leafIndex - Leaf index to prove.
|
|
473
476
|
* @returns ABI-encoded RateRatifierV1 data.
|
|
477
|
+
* @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.
|
|
474
478
|
* @throws {InvalidTreeError} when the tree is invalid, the leaf index is outside the tree, or the tree contains multiple ratifiers.
|
|
475
479
|
* @throws {InvalidTreeHeightError} when the tree exceeds the supported height.
|
|
476
480
|
* @throws {InvalidRateRatifierV1RateError} when a raw leaf carries a negative rate.
|
|
@@ -510,6 +514,7 @@ var RateRatifierV1;
|
|
|
510
514
|
*
|
|
511
515
|
* @param params.tree - RateRatifierV1 tree descriptor or raw leaf input whose root has already been ratified onchain.
|
|
512
516
|
* @returns Items containing each non-padding offer and its ratifier data.
|
|
517
|
+
* @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.
|
|
513
518
|
* @throws {InvalidTreeError} when the tree is invalid or contains multiple ratifiers.
|
|
514
519
|
* @throws {InvalidTreeHeightError} when the tree exceeds the supported height.
|
|
515
520
|
* @throws {InvalidRateRatifierV1RateError} when a raw leaf carries a negative rate.
|
|
@@ -74,6 +74,7 @@ export declare class Tree<K extends RatifierKind | undefined = undefined> {
|
|
|
74
74
|
* @returns Tree instance.
|
|
75
75
|
* @throws {InvalidTreeError} when the tree is empty, all padding, or duplicated.
|
|
76
76
|
* @throws {InvalidTreeHeightError} when the resulting height is unsupported.
|
|
77
|
+
* @throws {InvalidOfferGroupError} for priceV1/rateV1 entries whose explicit groups break `OfferUtils.validateOfferGroup` rules.
|
|
77
78
|
* @throws {InvalidRateRatifierV1RateError} when a Rate leaf has a negative rate.
|
|
78
79
|
* @throws {InvalidRateRatifierV1TickError} when a Rate leaf offer tick is below `RateRatifierV1.MIN_TICK`.
|
|
79
80
|
* @example
|
|
@@ -141,6 +142,7 @@ export declare class Tree<K extends RatifierKind | undefined = undefined> {
|
|
|
141
142
|
* @returns A tree whose entries and validation options are inferred from the route.
|
|
142
143
|
* @throws {InvalidTreeError} when the tree is empty, all padding, or duplicated.
|
|
143
144
|
* @throws {InvalidTreeHeightError} when the resulting height is unsupported.
|
|
145
|
+
* @throws {InvalidOfferGroupError} for priceV1/rateV1 entries whose explicit groups break `OfferUtils.validateOfferGroup` rules.
|
|
144
146
|
* @throws {InvalidRateRatifierV1RateError} when a Rate leaf has a negative rate.
|
|
145
147
|
* @throws {InvalidRateRatifierV1TickError} when a Rate leaf offer tick is below `RateRatifierV1.MIN_TICK`.
|
|
146
148
|
* @example
|
|
@@ -535,6 +535,7 @@ export declare namespace TreeUtils {
|
|
|
535
535
|
* @returns Tree descriptor.
|
|
536
536
|
* @throws {InvalidTreeError} when the offer count is empty, all padding, or duplicated.
|
|
537
537
|
* @throws {InvalidTreeHeightError} when the padded tree exceeds supported ratifier typehashes.
|
|
538
|
+
* @throws {InvalidOfferGroupError} for priceV1/rateV1 entries whose explicit groups break `OfferUtils.validateOfferGroup` rules.
|
|
538
539
|
* @throws {InvalidRateRatifierV1RateError} when a Rate leaf has a negative rate.
|
|
539
540
|
* @throws {InvalidRateRatifierV1TickError} when a Rate leaf offer tick is below `RateRatifierV1.MIN_TICK`.
|
|
540
541
|
* @example
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Address, type Hash } from "viem";
|
|
2
2
|
import { type IOffer, Offer, type OfferStruct } from "../offers/index.js";
|
|
3
3
|
import type { TreeData } from "./treeTypes.js";
|
|
4
|
-
/** @internal Resolves V1 leaf groups mirroring the router's group_identity content ids. */
|
|
4
|
+
/** @internal Resolves V1 leaf groups mirroring the router's group_identity content ids and validates explicit groups. */
|
|
5
5
|
export declare function assignRatifierV1Groups<TLeaf extends {
|
|
6
6
|
readonly offer: Offer;
|
|
7
7
|
}>(leaves: readonly TLeaf[], groupId: (leaves: readonly TLeaf[]) => Hash): Offer[];
|