@morpho-org/midnight-sdk 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -171,7 +171,12 @@ 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.
@@ -418,7 +423,12 @@ 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.
@@ -253,7 +253,12 @@ 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.
@@ -662,7 +667,12 @@ 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.
@@ -1,2 +1,2 @@
1
1
  /** @internal Installed Midnight SDK package version. */
2
- export declare const MIDNIGHT_SDK_VERSION = "2.1.0";
2
+ export declare const MIDNIGHT_SDK_VERSION = "2.2.0";
@@ -3,4 +3,4 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.MIDNIGHT_SDK_VERSION = void 0;
5
5
  /** @internal Installed Midnight SDK package version. */
6
- exports.MIDNIGHT_SDK_VERSION = "2.1.0";
6
+ exports.MIDNIGHT_SDK_VERSION = "2.2.0";
@@ -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. An omitted `group` defaults to the leaf's
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. An omitted `group` defaults to the leaf's
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. An omitted `group` defaults to the leaf's
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. An omitted `group` defaults to the leaf's
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[];
@@ -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
  /**
@@ -171,7 +171,12 @@ 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.
@@ -418,7 +423,12 @@ 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.
@@ -249,7 +249,12 @@ 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.
@@ -658,7 +663,12 @@ 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.
@@ -1,2 +1,2 @@
1
1
  /** @internal Installed Midnight SDK package version. */
2
- export declare const MIDNIGHT_SDK_VERSION = "2.1.0";
2
+ export declare const MIDNIGHT_SDK_VERSION = "2.2.0";
@@ -1,3 +1,3 @@
1
1
  // Generated by scripts/generate-midnight-package-version.ts. Do not edit.
2
2
  /** @internal Installed Midnight SDK package version. */
3
- export const MIDNIGHT_SDK_VERSION = "2.1.0";
3
+ export const MIDNIGHT_SDK_VERSION = "2.2.0";
@@ -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. An omitted `group` defaults to the leaf's
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. An omitted `group` defaults to the leaf's
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. An omitted `group` defaults to the leaf's
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. An omitted `group` defaults to the leaf's
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.
@@ -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[];
@@ -6,7 +6,7 @@ import { GroupUtils } from "./GroupUtils.js";
6
6
  import { isZeroAddress } from "./offerStructInternal.js";
7
7
  import { TreeUtils } from "./TreeUtils.js";
8
8
  import { isPowerOfTwo, nextPowerOfTwo } from "./treeMathInternal.js";
9
- /** @internal Resolves V1 leaf groups mirroring the router's group_identity content ids. */
9
+ /** @internal Resolves V1 leaf groups mirroring the router's group_identity content ids and validates explicit groups. */
10
10
  export function assignRatifierV1Groups(leaves, groupId) {
11
11
  const offers = leaves.map((leaf) => leaf.offer.hasExplicitGroup
12
12
  ? leaf.offer
@@ -24,6 +24,10 @@ export function assignRatifierV1Groups(leaves, groupId) {
24
24
  }
25
25
  for (const [label, indices] of buckets) {
26
26
  const bucketLeaves = indices.map((index) => leaves[index]);
27
+ // Called only to throw on incompatible group members.
28
+ OfferUtils.validateOfferGroup({
29
+ offers: bucketLeaves.map((leaf) => leaf.offer),
30
+ });
27
31
  if (GroupUtils.hash(bucketLeaves.map((leaf) => leaf.offer)).toLowerCase() !==
28
32
  label) {
29
33
  continue;
@@ -33,6 +37,25 @@ export function assignRatifierV1Groups(leaves, groupId) {
33
37
  offers[index] = Offer.from({ ...leaves[index].offer, group });
34
38
  }
35
39
  }
40
+ const finalGroups = new Map();
41
+ for (const [index, offer] of offers.entries()) {
42
+ const label = offer.group.toLowerCase();
43
+ const hasExplicitGroup = leaves[index].offer.hasExplicitGroup;
44
+ const bucket = finalGroups.get(label);
45
+ if (bucket) {
46
+ bucket.offers.push(offer);
47
+ bucket.hasExplicitGroup ||= hasExplicitGroup;
48
+ }
49
+ else {
50
+ finalGroups.set(label, { offers: [offer], hasExplicitGroup });
51
+ }
52
+ }
53
+ for (const { offers: groupOffers, hasExplicitGroup, } of finalGroups.values()) {
54
+ if (!hasExplicitGroup)
55
+ continue;
56
+ // Catches explicit groups that collide with a defaulted or re-derived id.
57
+ OfferUtils.validateOfferGroup({ offers: groupOffers });
58
+ }
36
59
  return offers;
37
60
  }
38
61
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@morpho-org/midnight-sdk",
3
3
  "description": "Viem-based package for Morpho Midnight that exports protocol utilities, fetch helpers, and Midnight API utilities under a dedicated API subpath.",
4
- "version": "2.1.0",
4
+ "version": "2.2.0",
5
5
  "author": "Morpho Association <contact@morpho.org>",
6
6
  "repository": {
7
7
  "type": "git",
@@ -45,12 +45,12 @@
45
45
  "viem": "^2.0.0"
46
46
  },
47
47
  "devDependencies": {
48
- "@morpho-org/morpho-ts": "^4.0.1",
48
+ "@morpho-org/morpho-ts": "^4.1.0",
49
49
  "@morpho-org/test": "^2.11.0",
50
50
  "fast-check": "^4.9.0",
51
51
  "typescript": "7.0.2",
52
52
  "viem": "^2.55.10",
53
- "vitest": "^4.1.11"
53
+ "vitest": "^4.1.12"
54
54
  },
55
55
  "scripts": {
56
56
  "prepublish": "pnpm build",