@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";
@@ -203,7 +203,7 @@ export class MidnightApi {
203
203
  * @param params.request - Optional fetch options forwarded to this request.
204
204
  * @returns ABI-ready take objects mapped from the API response.
205
205
  * @throws {MidnightApiError} when the API returns a non-2xx response.
206
- * @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned offer cannot be mapped (malformed numeric or hex fields), when its `market_id` does not match, or cannot be derived from, its embedded market, when it falls outside the requested filters, when its `receiverIfMakerIsSeller` is not a well-formed address, when its caps or buy-side receiver are not executable, or when its units exceed its offer `maxUnits`.
206
+ * @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned offer cannot be mapped (malformed numeric or hex fields), when its `market_id` does not match, or cannot be derived from, its embedded market, when it falls outside the requested filters, when its `receiverIfMakerIsSeller` is not a well-formed address or is the zero address on a sell offer, when its caps or buy-side receiver are not executable, or when its units exceed its offer `maxUnits`.
207
207
  * @example
208
208
  * ```ts
209
209
  * import { MidnightApi } from "@morpho-org/midnight-sdk/api";
@@ -244,6 +244,8 @@ export class MidnightApi {
244
244
  * @param params.units - Optional target unit amount. Mutually exclusive with `params.assets`.
245
245
  * @param params.averageWorstPrice - Optional WAD-scaled average worst price guard. Mutually exclusive with `params.slippage`.
246
246
  * @param params.slippage - Optional slippage percentage used to derive the guard. Mutually exclusive with `params.averageWorstPrice`.
247
+ * @param params.taker - Account that will execute the take (the `taker` passed to Midnight `take`).
248
+ * The API leaves out offers made by this account, since Midnight rejects self-takes.
247
249
  * @param params.settlementFee - Optional current WAD-scaled settlement fee used for local guard validation. Defaults to zero.
248
250
  * @param params.baseUrl - Optional Midnight API base URL override.
249
251
  * @param params.fetch - Optional fetch implementation override.
@@ -258,7 +260,7 @@ export class MidnightApi {
258
260
  * @throws {InvalidMidnightApiQuoteTargetError} when the runtime input does not set exactly one of `units` or `assets`.
259
261
  * @throws {NegativeValueError} when `settlementFee` is negative.
260
262
  * @throws {MidnightApiError} when the API returns a non-2xx response.
261
- * @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned offer cannot be mapped (malformed numeric or hex fields), when its `market_id` does not match, or cannot be derived from, its embedded market, when it falls outside the requested filters, when its `receiverIfMakerIsSeller` is not a well-formed address, 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.
263
+ * @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.
262
264
  * @throws {SettlementFeeExceedsPriceError} when a bid's settlement fee exceeds its offer price.
263
265
  * @example
264
266
  * ```ts
@@ -292,11 +294,13 @@ export class MidnightApi {
292
294
  slippage: input.slippage,
293
295
  units: input.units,
294
296
  assets: input.assets,
297
+ taker: input.taker,
295
298
  },
296
299
  });
297
300
  const takeableOffers = mapBoundTakeableOffers(response.data.takeable_offers, {
298
301
  marketId: input.marketId,
299
302
  side: input.side,
303
+ taker: input.taker,
300
304
  });
301
305
  const averageWorstPrice = "averageWorstPrice" in input && input.averageWorstPrice != null
302
306
  ? input.averageWorstPrice
@@ -383,7 +387,7 @@ export class MidnightApi {
383
387
  * @param params.request - Optional fetch options forwarded to this request.
384
388
  * @returns Paginated ABI-ready take objects mapped from the API response.
385
389
  * @throws {MidnightApiError} when the API returns a non-2xx response.
386
- * @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned offer cannot be mapped (malformed numeric or hex fields), when its `market_id` does not match, or cannot be derived from, its embedded market, when it falls outside the requested filters, when its `receiverIfMakerIsSeller` is not a well-formed address, 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`.
387
391
  * @example
388
392
  * ```ts
389
393
  * import { MidnightApi } from "@morpho-org/midnight-sdk/api";
@@ -631,7 +635,7 @@ export class MidnightApi {
631
635
  * @param params.side - Book side to query.
632
636
  * @returns ABI-ready take objects mapped from the API response.
633
637
  * @throws {MidnightApiError} when the API returns a non-2xx response.
634
- * @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned offer cannot be mapped (malformed numeric or hex fields), when its `market_id` does not match, or cannot be derived from, its embedded market, when it falls outside the requested filters, when its `receiverIfMakerIsSeller` is not a well-formed address, 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`.
635
639
  * @example
636
640
  * ```ts
637
641
  * import { MidnightApi } from "@morpho-org/midnight-sdk/api";
@@ -661,6 +665,8 @@ export class MidnightApi {
661
665
  * @param params.units - Optional target unit amount. Mutually exclusive with `params.assets`.
662
666
  * @param params.averageWorstPrice - Optional WAD-scaled average worst price guard. Mutually exclusive with `params.slippage`.
663
667
  * @param params.slippage - Optional slippage percentage used to derive the guard. Mutually exclusive with `params.averageWorstPrice`.
668
+ * @param params.taker - Account that will execute the take (the `taker` passed to Midnight `take`).
669
+ * The API leaves out offers made by this account, since Midnight rejects self-takes.
664
670
  * @param params.settlementFee - Optional current WAD-scaled settlement fee used for local guard validation. Defaults to zero.
665
671
  * @returns Quote and ABI-ready take caps. `averageWorstPrice` equals the caller's guard when provided,
666
672
  * otherwise the API's guard. Offers are returned as the API sends them. An `asks` quote by
@@ -672,7 +678,7 @@ export class MidnightApi {
672
678
  * @throws {InvalidMidnightApiQuoteTargetError} when the runtime input does not set exactly one of `units` or `assets`.
673
679
  * @throws {NegativeValueError} when `settlementFee` is negative.
674
680
  * @throws {MidnightApiError} when the API returns a non-2xx response.
675
- * @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned offer cannot be mapped (malformed numeric or hex fields), when its `market_id` does not match, or cannot be derived from, its embedded market, when it falls outside the requested filters, when its `receiverIfMakerIsSeller` is not a well-formed address, 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.
681
+ * @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.
676
682
  * @throws {SettlementFeeExceedsPriceError} when a bid's settlement fee exceeds its offer price.
677
683
  * @example
678
684
  * ```ts
@@ -705,7 +711,7 @@ export class MidnightApi {
705
711
  * @param params.cursor - Optional opaque pagination cursor from a previous response.
706
712
  * @returns Paginated ABI-ready take objects mapped from the API response.
707
713
  * @throws {MidnightApiError} when the API returns a non-2xx response.
708
- * @throws {InvalidMidnightApiResponseError} when the API success response is not JSON, when a returned offer cannot be mapped (malformed numeric or hex fields), when its `market_id` does not match, or cannot be derived from, its embedded market, when it falls outside the requested filters, when its `receiverIfMakerIsSeller` is not a well-formed address, when its caps or buy-side receiver are not executable, or when its units exceed its offer `maxUnits`.
714
+ * @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`.
709
715
  * @example
710
716
  * ```ts
711
717
  * 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
  }
@@ -1,5 +1,5 @@
1
1
  import { BLUE_API_BASE_URL, isHexEqual } from "@morpho-org/morpho-ts";
2
- import { isAddress, isAddressEqual, maxUint256, } from "viem";
2
+ import { isAddress, isAddressEqual, maxUint256, zeroAddress, } from "viem";
3
3
  import { InvalidMidnightApiResponseError, InvalidOfferParameterError, MidnightApiError, } from "../errors.js";
4
4
  import { MarketUtils } from "../market/index.js";
5
5
  import { OfferUtils } from "../offers/index.js";
@@ -268,6 +268,9 @@ export function mapBoundTakeableOffers(takeableOffers, context) {
268
268
  if (!isAddress(receiverIfMakerIsSeller)) {
269
269
  throw new InvalidMidnightApiResponseError(`Midnight API takeable offer receiverIfMakerIsSeller "${receiverIfMakerIsSeller}" is not an address.`);
270
270
  }
271
+ if (!buy && isAddressEqual(receiverIfMakerIsSeller, zeroAddress)) {
272
+ throw new InvalidMidnightApiResponseError(`Midnight API sell offer for market_id "${take.marketId}" routes seller proceeds to the zero address. Sell offers must use a non-zero receiverIfMakerIsSeller.`);
273
+ }
271
274
  try {
272
275
  // Return values unused: called only to enforce the cap-shape and buy-receiver invariants.
273
276
  OfferUtils.validateOfferCaps({ maxUnits, maxAssets });
@@ -304,10 +307,15 @@ export function mapBoundTakeableOffers(takeableOffers, context) {
304
307
  !isAddressEqual(take.offer.maker, context.maker)) {
305
308
  throw new InvalidMidnightApiResponseError(`Midnight API takeable offer maker "${take.offer.maker}" does not match requested maker "${context.maker}".`);
306
309
  }
307
- if (context.groups != null &&
308
- context.groups.length > 0 &&
309
- !context.groups.some((group) => isHexEqual(group, take.offer.group))) {
310
- throw new InvalidMidnightApiResponseError(`Midnight API takeable offer group "${take.offer.group}" is outside the requested groups filter.`);
310
+ if (context.taker != null &&
311
+ isAddressEqual(take.offer.maker, context.taker)) {
312
+ throw new InvalidMidnightApiResponseError(`Midnight API takeable offer maker "${take.offer.maker}" matches the requested taker "${context.taker}".`);
313
+ }
314
+ if (context.groups != null && context.groups.length > 0) {
315
+ const offerGroup = take.offer.group;
316
+ if (!context.groups.some((group) => isHexEqual(group, offerGroup))) {
317
+ throw new InvalidMidnightApiResponseError(`Midnight API takeable offer group "${offerGroup}" is outside the requested groups filter.`);
318
+ }
311
319
  }
312
320
  return take;
313
321
  });
@@ -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";
@@ -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.3.0-next.0";
3
+ export const 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
@@ -8,11 +8,11 @@ import { OfferUtils } from "./OfferUtils.js";
8
8
  * `Group.create` for shared-consumption ladders or directly to `Tree.create`
9
9
  * for standalone offers. API/take-side code can convert a plain `IOffer`
10
10
  * into this class before ABI encoding. The class resolves the onchain `group`
11
- * field lazily. Standalone offers derive their content-addressed singleton
12
- * group id from the offer's zero-group hash; `Group.create` copies offers and
13
- * overrides the group on those copies when several offers share one
14
- * consumption bucket. Offers hydrated from API or decoded data may also carry
15
- * a known group id.
11
+ * field when accessed. Standalone offers derive their
12
+ * content-addressed singleton group id from the offer's zero-group hash;
13
+ * `Group.create` copies offers and overrides the group on those copies when
14
+ * several offers share one consumption bucket. Offers hydrated from API or
15
+ * decoded data may also carry a known group id.
16
16
  *
17
17
  * @example
18
18
  * ```ts
@@ -66,9 +66,7 @@ export class Offer {
66
66
  expiry;
67
67
  /** Midnight tick. */
68
68
  tick;
69
- cachedGroup;
70
- cachedHash;
71
- cachedOnchainHash;
69
+ explicitGroup;
72
70
  /**
73
71
  * Whether the group id was supplied at construction rather than derived.
74
72
  *
@@ -109,7 +107,6 @@ export class Offer {
109
107
  offer instanceof Offer
110
108
  ? offer.hasExplicitGroup
111
109
  : offer.group !== undefined;
112
- this.cachedGroup = this.hasExplicitGroup ? offer.group : undefined;
113
110
  this.callback = offer.callback;
114
111
  this.callbackData = offer.callbackData;
115
112
  this.receiverIfMakerIsSeller = offer.receiverIfMakerIsSeller;
@@ -118,6 +115,7 @@ export class Offer {
118
115
  this.maxUnits = BigInt(offer.maxUnits);
119
116
  this.maxAssets = BigInt(offer.maxAssets);
120
117
  this.continuousFeeCap = BigInt(offer.continuousFeeCap);
118
+ this.explicitGroup = this.hasExplicitGroup ? offer.group : undefined;
121
119
  }
122
120
  /**
123
121
  * Returns an offer instance from class or plain input.
@@ -174,12 +172,11 @@ export class Offer {
174
172
  /**
175
173
  * Consumption group id encoded into this offer.
176
174
  *
177
- * When no group id was provided, the value is computed on first access by
178
- * hashing this offer with the protocol zero group id, then hashing that
179
- * result as a singleton group. The computed value is cached because offer
180
- * hashing is resource-intensive. This is equivalent to
181
- * `GroupUtils.hash([offer])`, but is computed directly to keep the offers
182
- * layer from importing signature helpers and creating a circular dependency.
175
+ * When no group id was provided, the value is derived on access by hashing
176
+ * this offer with the protocol zero group id, then hashing that result as a
177
+ * singleton group. This is equivalent to `GroupUtils.hash([offer])`, but is
178
+ * computed directly to keep the offers layer from importing signature
179
+ * helpers and creating a circular dependency.
183
180
  *
184
181
  * @returns Consumption group id.
185
182
  * @example
@@ -224,14 +221,12 @@ export class Offer {
224
221
  * ```
225
222
  */
226
223
  get group() {
227
- this.cachedGroup ??= keccak256(OfferUtils.groupHash(this));
228
- return this.cachedGroup;
224
+ return this.explicitGroup ?? keccak256(OfferUtils.groupHash(this));
229
225
  }
230
226
  /**
231
227
  * Canonical protocol offer hash for this offer.
232
228
  *
233
- * The hash includes {@link Offer.group}. It is computed lazily and cached
234
- * because hashing includes market hashing and ABI encoding.
229
+ * The hash includes {@link Offer.group} and is computed when accessed.
235
230
  *
236
231
  * @returns Offer hash.
237
232
  * @example
@@ -276,8 +271,7 @@ export class Offer {
276
271
  * ```
277
272
  */
278
273
  get hash() {
279
- this.cachedHash ??= OfferUtils.hash(this);
280
- return this.cachedHash;
274
+ return OfferUtils.hash(this);
281
275
  }
282
276
  /**
283
277
  * Returns the on-chain offer identifier emitted by Midnight's `Take` event.
@@ -289,7 +283,7 @@ export class Offer {
289
283
  * `offers`: `buildDescriptor` replaces both the default group and a
290
284
  * `Group.create` group.
291
285
  *
292
- * @returns The cached on-chain offer hash.
286
+ * @returns The on-chain offer hash.
293
287
  * @throws {viem.InvalidAddressError} when an address has an invalid mixed-case checksum.
294
288
  * @throws {viem.IntegerOutOfRangeError} when a uint field overflows its ABI size.
295
289
  * @example
@@ -328,8 +322,7 @@ export class Offer {
328
322
  * ```
329
323
  */
330
324
  get onchainHash() {
331
- this.cachedOnchainHash ??= OfferUtils.onchainHash(this);
332
- return this.cachedOnchainHash;
325
+ return OfferUtils.onchainHash(this);
333
326
  }
334
327
  /**
335
328
  * WAD zero-coupon price at this offer's tick.
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.3.0-next.0",
4
+ "version": "2.4.0-next.0",
5
5
  "author": "Morpho Association <contact@morpho.org>",
6
6
  "repository": {
7
7
  "type": "git",
@@ -45,8 +45,8 @@
45
45
  "viem": "^2.0.0"
46
46
  },
47
47
  "devDependencies": {
48
- "@morpho-org/morpho-ts": "^4.2.0-next.0",
49
- "@morpho-org/test": "^2.12.0-next.1",
48
+ "@morpho-org/morpho-ts": "^4.2.0-next.1",
49
+ "@morpho-org/test": "^2.13.0-next.0",
50
50
  "fast-check": "^4.9.0",
51
51
  "typescript": "7.0.2",
52
52
  "viem": "^2.55.10",