@morpho-org/midnight-sdk 2.3.0-next.0 → 2.4.0-next.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.
@@ -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";
@@ -166,6 +166,8 @@ export declare class MidnightApi {
166
166
  * @param params.units - Optional target unit amount. Mutually exclusive with `params.assets`.
167
167
  * @param params.averageWorstPrice - Optional WAD-scaled average worst price guard. Mutually exclusive with `params.slippage`.
168
168
  * @param params.slippage - Optional slippage percentage used to derive the guard. Mutually exclusive with `params.averageWorstPrice`.
169
+ * @param params.taker - Account that will execute the take (the `taker` passed to Midnight `take`).
170
+ * The API leaves out offers made by this account, since Midnight rejects self-takes.
169
171
  * @param params.settlementFee - Optional current WAD-scaled settlement fee used for local guard validation. Defaults to zero.
170
172
  * @param params.baseUrl - Optional Midnight API base URL override.
171
173
  * @param params.fetch - Optional fetch implementation override.
@@ -180,7 +182,7 @@ export declare class MidnightApi {
180
182
  * @throws {InvalidMidnightApiQuoteTargetError} when the runtime input does not set exactly one of `units` or `assets`.
181
183
  * @throws {NegativeValueError} when `settlementFee` is negative.
182
184
  * @throws {MidnightApiError} when the API returns a non-2xx response.
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, 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.
185
+ * @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 an offer's maker matches the requested `taker`, 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.
184
186
  * @throws {SettlementFeeExceedsPriceError} when a bid's settlement fee exceeds its offer price.
185
187
  * @example
186
188
  * ```ts
@@ -211,7 +213,7 @@ export declare class MidnightApi {
211
213
  * @param params.request - Optional fetch options forwarded to this request.
212
214
  * @returns Paginated ABI-ready take objects mapped from the API response.
213
215
  * @throws {MidnightApiError} when the API returns a non-2xx response.
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, when its caps or buy-side receiver are not executable, or when its units exceed its offer `maxUnits`.
216
+ * @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`.
215
217
  * @example
216
218
  * ```ts
217
219
  * import { MidnightApi } from "@morpho-org/midnight-sdk/api";
@@ -396,7 +398,7 @@ export declare class MidnightApi {
396
398
  * @param params.side - Book side to query.
397
399
  * @returns ABI-ready take objects mapped from the API response.
398
400
  * @throws {MidnightApiError} when the API returns a non-2xx response.
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, when its caps or buy-side receiver are not executable, or when its units exceed its offer `maxUnits`.
401
+ * @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`.
400
402
  * @example
401
403
  * ```ts
402
404
  * import { MidnightApi } from "@morpho-org/midnight-sdk/api";
@@ -421,6 +423,8 @@ export declare class MidnightApi {
421
423
  * @param params.units - Optional target unit amount. Mutually exclusive with `params.assets`.
422
424
  * @param params.averageWorstPrice - Optional WAD-scaled average worst price guard. Mutually exclusive with `params.slippage`.
423
425
  * @param params.slippage - Optional slippage percentage used to derive the guard. Mutually exclusive with `params.averageWorstPrice`.
426
+ * @param params.taker - Account that will execute the take (the `taker` passed to Midnight `take`).
427
+ * The API leaves out offers made by this account, since Midnight rejects self-takes.
424
428
  * @param params.settlementFee - Optional current WAD-scaled settlement fee used for local guard validation. Defaults to zero.
425
429
  * @returns Quote and ABI-ready take caps. `averageWorstPrice` equals the caller's guard when provided,
426
430
  * otherwise the API's guard. Offers are returned as the API sends them. An `asks` quote by
@@ -432,7 +436,7 @@ export declare class MidnightApi {
432
436
  * @throws {InvalidMidnightApiQuoteTargetError} when the runtime input does not set exactly one of `units` or `assets`.
433
437
  * @throws {NegativeValueError} when `settlementFee` is negative.
434
438
  * @throws {MidnightApiError} when the API returns a non-2xx response.
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, 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.
439
+ * @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 an offer's maker matches the requested `taker`, 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.
436
440
  * @throws {SettlementFeeExceedsPriceError} when a bid's settlement fee exceeds its offer price.
437
441
  * @example
438
442
  * ```ts
@@ -460,7 +464,7 @@ export declare class MidnightApi {
460
464
  * @param params.cursor - Optional opaque pagination cursor from a previous response.
461
465
  * @returns Paginated ABI-ready take objects mapped from the API response.
462
466
  * @throws {MidnightApiError} when the API returns a non-2xx response.
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, when its caps or buy-side receiver are not executable, or when its units exceed its offer `maxUnits`.
467
+ * @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`.
464
468
  * @example
465
469
  * ```ts
466
470
  * 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";
@@ -248,6 +248,8 @@ class MidnightApi {
248
248
  * @param params.units - Optional target unit amount. Mutually exclusive with `params.assets`.
249
249
  * @param params.averageWorstPrice - Optional WAD-scaled average worst price guard. Mutually exclusive with `params.slippage`.
250
250
  * @param params.slippage - Optional slippage percentage used to derive the guard. Mutually exclusive with `params.averageWorstPrice`.
251
+ * @param params.taker - Account that will execute the take (the `taker` passed to Midnight `take`).
252
+ * The API leaves out offers made by this account, since Midnight rejects self-takes.
251
253
  * @param params.settlementFee - Optional current WAD-scaled settlement fee used for local guard validation. Defaults to zero.
252
254
  * @param params.baseUrl - Optional Midnight API base URL override.
253
255
  * @param params.fetch - Optional fetch implementation override.
@@ -262,7 +264,7 @@ class MidnightApi {
262
264
  * @throws {InvalidMidnightApiQuoteTargetError} when the runtime input does not set exactly one of `units` or `assets`.
263
265
  * @throws {NegativeValueError} when `settlementFee` is negative.
264
266
  * @throws {MidnightApiError} when the API returns a non-2xx response.
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, 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.
267
+ * @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 an offer's maker matches the requested `taker`, 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.
266
268
  * @throws {SettlementFeeExceedsPriceError} when a bid's settlement fee exceeds its offer price.
267
269
  * @example
268
270
  * ```ts
@@ -296,11 +298,13 @@ class MidnightApi {
296
298
  slippage: input.slippage,
297
299
  units: input.units,
298
300
  assets: input.assets,
301
+ taker: input.taker,
299
302
  },
300
303
  });
301
304
  const takeableOffers = (0, helpers_js_1.mapBoundTakeableOffers)(response.data.takeable_offers, {
302
305
  marketId: input.marketId,
303
306
  side: input.side,
307
+ taker: input.taker,
304
308
  });
305
309
  const averageWorstPrice = "averageWorstPrice" in input && input.averageWorstPrice != null
306
310
  ? input.averageWorstPrice
@@ -387,7 +391,7 @@ class MidnightApi {
387
391
  * @param params.request - Optional fetch options forwarded to this request.
388
392
  * @returns Paginated ABI-ready take objects mapped from the API response.
389
393
  * @throws {MidnightApiError} when the API returns a non-2xx response.
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, when its caps or buy-side receiver are not executable, or when its units exceed its offer `maxUnits`.
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 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`.
391
395
  * @example
392
396
  * ```ts
393
397
  * import { MidnightApi } from "@morpho-org/midnight-sdk/api";
@@ -635,7 +639,7 @@ class MidnightApi {
635
639
  * @param params.side - Book side to query.
636
640
  * @returns ABI-ready take objects mapped from the API response.
637
641
  * @throws {MidnightApiError} when the API returns a non-2xx response.
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, when its caps or buy-side receiver are not executable, or when its units exceed its offer `maxUnits`.
642
+ * @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`.
639
643
  * @example
640
644
  * ```ts
641
645
  * import { MidnightApi } from "@morpho-org/midnight-sdk/api";
@@ -665,6 +669,8 @@ class MidnightApi {
665
669
  * @param params.units - Optional target unit amount. Mutually exclusive with `params.assets`.
666
670
  * @param params.averageWorstPrice - Optional WAD-scaled average worst price guard. Mutually exclusive with `params.slippage`.
667
671
  * @param params.slippage - Optional slippage percentage used to derive the guard. Mutually exclusive with `params.averageWorstPrice`.
672
+ * @param params.taker - Account that will execute the take (the `taker` passed to Midnight `take`).
673
+ * The API leaves out offers made by this account, since Midnight rejects self-takes.
668
674
  * @param params.settlementFee - Optional current WAD-scaled settlement fee used for local guard validation. Defaults to zero.
669
675
  * @returns Quote and ABI-ready take caps. `averageWorstPrice` equals the caller's guard when provided,
670
676
  * otherwise the API's guard. Offers are returned as the API sends them. An `asks` quote by
@@ -676,7 +682,7 @@ class MidnightApi {
676
682
  * @throws {InvalidMidnightApiQuoteTargetError} when the runtime input does not set exactly one of `units` or `assets`.
677
683
  * @throws {NegativeValueError} when `settlementFee` is negative.
678
684
  * @throws {MidnightApiError} when the API returns a non-2xx response.
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, 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.
685
+ * @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 an offer's maker matches the requested `taker`, 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.
680
686
  * @throws {SettlementFeeExceedsPriceError} when a bid's settlement fee exceeds its offer price.
681
687
  * @example
682
688
  * ```ts
@@ -709,7 +715,7 @@ class MidnightApi {
709
715
  * @param params.cursor - Optional opaque pagination cursor from a previous response.
710
716
  * @returns Paginated ABI-ready take objects mapped from the API response.
711
717
  * @throws {MidnightApiError} when the API returns a non-2xx response.
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, when its caps or buy-side receiver are not executable, or when its units exceed its offer `maxUnits`.
718
+ * @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`.
713
719
  * @example
714
720
  * ```ts
715
721
  * import { MidnightApi } from "@morpho-org/midnight-sdk/api";
@@ -27,6 +27,8 @@ export interface TakeableOfferContext {
27
27
  readonly marketId?: Hash;
28
28
  readonly side?: MidnightApiBookSide;
29
29
  readonly maker?: Address;
30
+ /** Taker address whose own offers must not appear in the response. */
31
+ readonly taker?: Address;
30
32
  readonly marketIds?: readonly Hash[];
31
33
  readonly groups?: readonly Hash[];
32
34
  }
@@ -277,6 +277,9 @@ function mapBoundTakeableOffers(takeableOffers, context) {
277
277
  if (!(0, viem_1.isAddress)(receiverIfMakerIsSeller)) {
278
278
  throw new errors_js_1.InvalidMidnightApiResponseError(`Midnight API takeable offer receiverIfMakerIsSeller "${receiverIfMakerIsSeller}" is not an address.`);
279
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
+ }
280
283
  try {
281
284
  // Return values unused: called only to enforce the cap-shape and buy-receiver invariants.
282
285
  index_js_2.OfferUtils.validateOfferCaps({ maxUnits, maxAssets });
@@ -313,10 +316,15 @@ function mapBoundTakeableOffers(takeableOffers, context) {
313
316
  !(0, viem_1.isAddressEqual)(take.offer.maker, context.maker)) {
314
317
  throw new errors_js_1.InvalidMidnightApiResponseError(`Midnight API takeable offer maker "${take.offer.maker}" does not match requested maker "${context.maker}".`);
315
318
  }
316
- if (context.groups != null &&
317
- context.groups.length > 0 &&
318
- !context.groups.some((group) => (0, morpho_ts_1.isHexEqual)(group, take.offer.group))) {
319
- throw new errors_js_1.InvalidMidnightApiResponseError(`Midnight API takeable offer group "${take.offer.group}" is outside the requested groups filter.`);
319
+ if (context.taker != null &&
320
+ (0, viem_1.isAddressEqual)(take.offer.maker, context.taker)) {
321
+ throw new errors_js_1.InvalidMidnightApiResponseError(`Midnight API takeable offer maker "${take.offer.maker}" matches the requested taker "${context.taker}".`);
322
+ }
323
+ if (context.groups != null && context.groups.length > 0) {
324
+ const offerGroup = take.offer.group;
325
+ if (!context.groups.some((group) => (0, morpho_ts_1.isHexEqual)(group, offerGroup))) {
326
+ throw new errors_js_1.InvalidMidnightApiResponseError(`Midnight API takeable offer group "${offerGroup}" is outside the requested groups filter.`);
327
+ }
320
328
  }
321
329
  return take;
322
330
  });
@@ -177,6 +177,11 @@ export type FetchBookQuoteParams = MidnightApiConfig & {
177
177
  readonly marketId: Hash;
178
178
  /** Book side to quote. */
179
179
  readonly side: MidnightApiBookSide;
180
+ /**
181
+ * Account that will execute the take (the `taker` passed to Midnight `take`). The API leaves out
182
+ * offers made by this account, since Midnight rejects self-takes.
183
+ */
184
+ readonly taker?: Address;
180
185
  /** Current WAD-scaled settlement fee used for local guard validation. Defaults to zero. */
181
186
  readonly settlementFee?: BigIntish;
182
187
  } & (MidnightApiQuoteAssetsTarget | MidnightApiQuoteUnitsTarget) & (MidnightApiQuoteAverageWorstPriceGuard | MidnightApiQuoteSlippageGuard | MidnightApiQuoteWithoutGuard);
@@ -1,2 +1,2 @@
1
1
  /** @internal Installed Midnight SDK package version. */
2
- export declare const MIDNIGHT_SDK_VERSION = "2.3.0-next.0";
2
+ export declare const MIDNIGHT_SDK_VERSION = "2.4.0-next.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.3.0-next.0";
6
+ exports.MIDNIGHT_SDK_VERSION = "2.4.0-next.0";
@@ -8,10 +8,10 @@ import { type IMarket, type IMarketParams, Market, MarketParams } from "../marke
8
8
  * flow into `Offer.from`, `Group.create`, `Tree.create`, or
9
9
  * take-side conversion helpers. Use {@link Offer.create} instead for new maker
10
10
  * offers so deterministic fields are validated before grouping or signing.
11
- * The `group` field is optional. When omitted, {@link Offer.group} lazily
12
- * derives the content-addressed singleton group id from this offer's
13
- * zero-group hash. `Group.create` copies offers into a shared group and
14
- * overrides this field on the copies it owns.
11
+ * The `group` field is optional. When omitted, the `Offer.group` getter derives
12
+ * the content-addressed singleton group id from this offer's zero-group hash.
13
+ * `Group.create` copies offers into a shared group and overrides this field on
14
+ * the copies it owns.
15
15
  *
16
16
  * @example
17
17
  * ```ts
@@ -90,11 +90,11 @@ export interface IOffer {
90
90
  * `Group.create` for shared-consumption ladders or directly to `Tree.create`
91
91
  * for standalone offers. API/take-side code can convert a plain `IOffer`
92
92
  * into this class before ABI encoding. The class resolves the onchain `group`
93
- * field lazily. Standalone offers derive their content-addressed singleton
94
- * group id from the offer's zero-group hash; `Group.create` copies offers and
95
- * overrides the group on those copies when several offers share one
96
- * consumption bucket. Offers hydrated from API or decoded data may also carry
97
- * a known group id.
93
+ * field when accessed. Standalone offers derive their
94
+ * content-addressed singleton group id from the offer's zero-group hash;
95
+ * `Group.create` copies offers and overrides the group on those copies when
96
+ * several offers share one consumption bucket. Offers hydrated from API or
97
+ * decoded data may also carry a known group id.
98
98
  *
99
99
  * @example
100
100
  * ```ts
@@ -148,9 +148,7 @@ export declare class Offer {
148
148
  readonly expiry: bigint;
149
149
  /** Midnight tick. */
150
150
  readonly tick: bigint;
151
- private cachedGroup;
152
- private cachedHash;
153
- private cachedOnchainHash;
151
+ private readonly explicitGroup;
154
152
  /**
155
153
  * Whether the group id was supplied at construction rather than derived.
156
154
  *
@@ -231,12 +229,11 @@ export declare class Offer {
231
229
  /**
232
230
  * Consumption group id encoded into this offer.
233
231
  *
234
- * When no group id was provided, the value is computed on first access by
235
- * hashing this offer with the protocol zero group id, then hashing that
236
- * result as a singleton group. The computed value is cached because offer
237
- * hashing is resource-intensive. This is equivalent to
238
- * `GroupUtils.hash([offer])`, but is computed directly to keep the offers
239
- * layer from importing signature helpers and creating a circular dependency.
232
+ * When no group id was provided, the value is derived on access by hashing
233
+ * this offer with the protocol zero group id, then hashing that result as a
234
+ * singleton group. This is equivalent to `GroupUtils.hash([offer])`, but is
235
+ * computed directly to keep the offers layer from importing signature
236
+ * helpers and creating a circular dependency.
240
237
  *
241
238
  * @returns Consumption group id.
242
239
  * @example
@@ -284,8 +281,7 @@ export declare class Offer {
284
281
  /**
285
282
  * Canonical protocol offer hash for this offer.
286
283
  *
287
- * The hash includes {@link Offer.group}. It is computed lazily and cached
288
- * because hashing includes market hashing and ABI encoding.
284
+ * The hash includes {@link Offer.group} and is computed when accessed.
289
285
  *
290
286
  * @returns Offer hash.
291
287
  * @example
@@ -340,7 +336,7 @@ export declare class Offer {
340
336
  * `offers`: `buildDescriptor` replaces both the default group and a
341
337
  * `Group.create` group.
342
338
  *
343
- * @returns The cached on-chain offer hash.
339
+ * @returns The on-chain offer hash.
344
340
  * @throws {viem.InvalidAddressError} when an address has an invalid mixed-case checksum.
345
341
  * @throws {viem.IntegerOutOfRangeError} when a uint field overflows its ABI size.
346
342
  * @example
@@ -11,11 +11,11 @@ const OfferUtils_js_1 = require("./OfferUtils.js");
11
11
  * `Group.create` for shared-consumption ladders or directly to `Tree.create`
12
12
  * for standalone offers. API/take-side code can convert a plain `IOffer`
13
13
  * into this class before ABI encoding. The class resolves the onchain `group`
14
- * field lazily. Standalone offers derive their content-addressed singleton
15
- * group id from the offer's zero-group hash; `Group.create` copies offers and
16
- * overrides the group on those copies when several offers share one
17
- * consumption bucket. Offers hydrated from API or decoded data may also carry
18
- * a known group id.
14
+ * field when accessed. Standalone offers derive their
15
+ * content-addressed singleton group id from the offer's zero-group hash;
16
+ * `Group.create` copies offers and overrides the group on those copies when
17
+ * several offers share one consumption bucket. Offers hydrated from API or
18
+ * decoded data may also carry a known group id.
19
19
  *
20
20
  * @example
21
21
  * ```ts
@@ -69,9 +69,7 @@ class Offer {
69
69
  expiry;
70
70
  /** Midnight tick. */
71
71
  tick;
72
- cachedGroup;
73
- cachedHash;
74
- cachedOnchainHash;
72
+ explicitGroup;
75
73
  /**
76
74
  * Whether the group id was supplied at construction rather than derived.
77
75
  *
@@ -112,7 +110,6 @@ class Offer {
112
110
  offer instanceof Offer
113
111
  ? offer.hasExplicitGroup
114
112
  : offer.group !== undefined;
115
- this.cachedGroup = this.hasExplicitGroup ? offer.group : undefined;
116
113
  this.callback = offer.callback;
117
114
  this.callbackData = offer.callbackData;
118
115
  this.receiverIfMakerIsSeller = offer.receiverIfMakerIsSeller;
@@ -121,6 +118,7 @@ class Offer {
121
118
  this.maxUnits = BigInt(offer.maxUnits);
122
119
  this.maxAssets = BigInt(offer.maxAssets);
123
120
  this.continuousFeeCap = BigInt(offer.continuousFeeCap);
121
+ this.explicitGroup = this.hasExplicitGroup ? offer.group : undefined;
124
122
  }
125
123
  /**
126
124
  * Returns an offer instance from class or plain input.
@@ -177,12 +175,11 @@ class Offer {
177
175
  /**
178
176
  * Consumption group id encoded into this offer.
179
177
  *
180
- * When no group id was provided, the value is computed on first access by
181
- * hashing this offer with the protocol zero group id, then hashing that
182
- * result as a singleton group. The computed value is cached because offer
183
- * hashing is resource-intensive. This is equivalent to
184
- * `GroupUtils.hash([offer])`, but is computed directly to keep the offers
185
- * layer from importing signature helpers and creating a circular dependency.
178
+ * When no group id was provided, the value is derived on access by hashing
179
+ * this offer with the protocol zero group id, then hashing that result as a
180
+ * singleton group. This is equivalent to `GroupUtils.hash([offer])`, but is
181
+ * computed directly to keep the offers layer from importing signature
182
+ * helpers and creating a circular dependency.
186
183
  *
187
184
  * @returns Consumption group id.
188
185
  * @example
@@ -227,14 +224,12 @@ class Offer {
227
224
  * ```
228
225
  */
229
226
  get group() {
230
- this.cachedGroup ??= (0, viem_1.keccak256)(OfferUtils_js_1.OfferUtils.groupHash(this));
231
- return this.cachedGroup;
227
+ return this.explicitGroup ?? (0, viem_1.keccak256)(OfferUtils_js_1.OfferUtils.groupHash(this));
232
228
  }
233
229
  /**
234
230
  * Canonical protocol offer hash for this offer.
235
231
  *
236
- * The hash includes {@link Offer.group}. It is computed lazily and cached
237
- * because hashing includes market hashing and ABI encoding.
232
+ * The hash includes {@link Offer.group} and is computed when accessed.
238
233
  *
239
234
  * @returns Offer hash.
240
235
  * @example
@@ -279,8 +274,7 @@ class Offer {
279
274
  * ```
280
275
  */
281
276
  get hash() {
282
- this.cachedHash ??= OfferUtils_js_1.OfferUtils.hash(this);
283
- return this.cachedHash;
277
+ return OfferUtils_js_1.OfferUtils.hash(this);
284
278
  }
285
279
  /**
286
280
  * Returns the on-chain offer identifier emitted by Midnight's `Take` event.
@@ -292,7 +286,7 @@ class Offer {
292
286
  * `offers`: `buildDescriptor` replaces both the default group and a
293
287
  * `Group.create` group.
294
288
  *
295
- * @returns The cached on-chain offer hash.
289
+ * @returns The on-chain offer hash.
296
290
  * @throws {viem.InvalidAddressError} when an address has an invalid mixed-case checksum.
297
291
  * @throws {viem.IntegerOutOfRangeError} when a uint field overflows its ABI size.
298
292
  * @example
@@ -331,8 +325,7 @@ class Offer {
331
325
  * ```
332
326
  */
333
327
  get onchainHash() {
334
- this.cachedOnchainHash ??= OfferUtils_js_1.OfferUtils.onchainHash(this);
335
- return this.cachedOnchainHash;
328
+ return OfferUtils_js_1.OfferUtils.onchainHash(this);
336
329
  }
337
330
  /**
338
331
  * WAD zero-coupon price at this offer's tick.