@morpho-dev/router 0.8.0 → 0.9.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.
@@ -242,6 +242,7 @@ var ObligationResponse_exports = /* @__PURE__ */ __exportAll({ from: () => from$
242
242
  * Creates an `ObligationResponse` from a `Obligation`.
243
243
  * @constructor
244
244
  * @param obligation - {@link Obligation}
245
+ * @param quote - {@link Quote}
245
246
  * @returns The created `ObligationResponse`. {@link ObligationResponse}
246
247
  */
247
248
  function from$14(obligation, quote) {
@@ -255,8 +256,14 @@ function from$14(obligation, quote) {
255
256
  oracle: c.oracle
256
257
  })),
257
258
  maturity: obligation.maturity,
258
- ask: { price: quote.ask.price.toString() },
259
- bid: { price: quote.bid.price.toString() }
259
+ ask: {
260
+ tick: quote.ask.tick,
261
+ price: quote.ask.price.toString()
262
+ },
263
+ bid: {
264
+ tick: quote.bid.tick,
265
+ price: quote.bid.price.toString()
266
+ }
260
267
  };
261
268
  }
262
269
 
@@ -302,18 +309,18 @@ const MorphoV2 = parseAbi([
302
309
  "function setFeeSetter(address newFeeSetter)",
303
310
  "function setObligationTradingFee(bytes32 id, uint256 index, uint256 newTradingFee)",
304
311
  "function setOwner(address newOwner)",
305
- "function setTradingFeeRecipient(address recipient)",
312
+ "function setTradingFeeRecipient(address feeRecipient)",
306
313
  "function sharesOf(bytes32 id, address user) view returns (uint256)",
307
314
  "function shuffleSession()",
308
315
  "function supplyCollateral((address loanToken, (address token, uint256 lltv, address oracle)[] collaterals, uint256 maturity) obligation, address collateral, uint256 assets, address onBehalf)",
309
- "function take(uint256 buyerAssets, uint256 sellerAssets, uint256 obligationUnits, uint256 obligationShares, address taker, ((address loanToken, (address token, uint256 lltv, address oracle)[] collaterals, uint256 maturity) obligation, bool buy, address maker, uint256 assets, uint256 obligationUnits, uint256 obligationShares, uint256 start, uint256 expiry, uint256 tick, bytes32 group, bytes32 session, address callback, bytes callbackData) offer, (uint8 v, bytes32 r, bytes32 s) sig, bytes32 root, bytes32[] proof, address takerCallback, bytes takerCallbackData) returns (uint256, uint256, uint256, uint256)",
316
+ "function take(uint256 buyerAssets, uint256 sellerAssets, uint256 obligationUnits, uint256 obligationShares, address taker, address takerCallback, bytes takerCallbackData, address receiverIfTakerIsSeller, ((address loanToken, (address token, uint256 lltv, address oracle)[] collaterals, uint256 maturity) obligation, bool buy, address maker, uint256 assets, uint256 obligationUnits, uint256 obligationShares, uint256 start, uint256 expiry, uint256 tick, bytes32 group, bytes32 session, address callback, bytes callbackData, address receiverIfMakerIsSeller) offer, (uint8 v, bytes32 r, bytes32 s) sig, bytes32 root, bytes32[] proof) returns (uint256, uint256, uint256, uint256)",
310
317
  "function totalShares(bytes32 id) view returns (uint256)",
311
318
  "function totalUnits(bytes32 id) view returns (uint256)",
312
319
  "function touchObligation((address loanToken, (address token, uint256 lltv, address oracle)[] collaterals, uint256 maturity) obligation) returns (bytes32)",
313
320
  "function tradingFee(bytes32 id, uint256 timeToMaturity) view returns (uint256)",
314
321
  "function tradingFeeRecipient() view returns (address)",
315
- "function withdraw((address loanToken, (address token, uint256 lltv, address oracle)[] collaterals, uint256 maturity) obligation, uint256 obligationUnits, uint256 shares, address onBehalf) returns (uint256, uint256)",
316
- "function withdrawCollateral((address loanToken, (address token, uint256 lltv, address oracle)[] collaterals, uint256 maturity) obligation, address collateral, uint256 assets, address onBehalf)",
322
+ "function withdraw((address loanToken, (address token, uint256 lltv, address oracle)[] collaterals, uint256 maturity) obligation, uint256 obligationUnits, uint256 shares, address onBehalf, address receiver) returns (uint256, uint256)",
323
+ "function withdrawCollateral((address loanToken, (address token, uint256 lltv, address oracle)[] collaterals, uint256 maturity) obligation, address collateral, uint256 assets, address onBehalf, address receiver)",
317
324
  "function withdrawable(bytes32 id) view returns (uint256)",
318
325
  "event Constructor(address indexed owner)",
319
326
  "event Consume(address indexed user, bytes32 indexed group, uint256 amount)",
@@ -325,12 +332,12 @@ const MorphoV2 = parseAbi([
325
332
  "event SetFeeSetter(address indexed feeSetter)",
326
333
  "event SetObligationTradingFee(bytes32 indexed id, uint256 indexed index, uint256 newTradingFee)",
327
334
  "event SetOwner(address indexed owner)",
328
- "event SetTradingFeeRecipient(address indexed recipient)",
335
+ "event SetTradingFeeRecipient(address indexed feeRecipient)",
329
336
  "event ShuffleSession(address indexed user, bytes32 session)",
330
337
  "event SupplyCollateral(address caller, bytes32 indexed id, address indexed collateral, uint256 assets, address indexed onBehalf)",
331
- "event Take(address caller, bytes32 indexed id, address indexed maker, address indexed taker, bool offerIsBuy, uint256 buyerAssets, uint256 sellerAssets, uint256 obligationUnits, uint256 obligationShares, bool buyerIsLender, bool sellerIsBorrower, bytes32 group, uint256 consumed)",
332
- "event Withdraw(address indexed caller, bytes32 indexed id, uint256 obligationUnits, uint256 shares, address indexed onBehalf)",
333
- "event WithdrawCollateral(address caller, bytes32 indexed id, address indexed collateral, uint256 assets, address indexed onBehalf)"
338
+ "event Take(address caller, bytes32 indexed id, address indexed maker, address indexed taker, bool offerIsBuy, uint256 buyerAssets, uint256 sellerAssets, uint256 obligationUnits, uint256 obligationShares, bool buyerIsLender, bool sellerIsBorrower, address sellerReceiver, bytes32 group, uint256 consumed)",
339
+ "event Withdraw(address caller, bytes32 indexed id, uint256 obligationUnits, uint256 shares, address indexed onBehalf, address indexed receiver)",
340
+ "event WithdrawCollateral(address caller, bytes32 indexed id, address indexed collateral, uint256 assets, address indexed onBehalf, address receiver)"
334
341
  ]);
335
342
 
336
343
  //#endregion
@@ -647,8 +654,8 @@ const chains$1 = {
647
654
  name: "ethereum-virtual-testnet",
648
655
  custom: {
649
656
  morpho: {
650
- address: "0x634b095371e4e45feed94c1a45c37798e173ea50",
651
- blockCreated: 23226700
657
+ address: "0xc9f3c65996fc46b9500608b2c9a9152c01c540f7",
658
+ blockCreated: 23226871
652
659
  },
653
660
  morphoBlue: {
654
661
  address: "0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb",
@@ -1610,7 +1617,8 @@ const OfferSchema = () => {
1610
1617
  callback: z$1.object({
1611
1618
  address: z$1.string().transform(transformAddress),
1612
1619
  data: z$1.string().transform(transformHex)
1613
- })
1620
+ }),
1621
+ receiverIfMakerIsSeller: z$1.string().transform(transformAddress)
1614
1622
  }).refine((data) => data.start < data.expiry, {
1615
1623
  message: "start must be before expiry",
1616
1624
  path: ["start"]
@@ -1626,8 +1634,12 @@ const OfferSchema = () => {
1626
1634
  * @returns The created offer.
1627
1635
  */
1628
1636
  function from$9(input) {
1637
+ const normalizedInput = {
1638
+ ...input,
1639
+ receiverIfMakerIsSeller: input.receiverIfMakerIsSeller ?? input.maker
1640
+ };
1629
1641
  try {
1630
- return OfferSchema().parse(input);
1642
+ return OfferSchema().parse(normalizedInput);
1631
1643
  } catch (error) {
1632
1644
  throw new InvalidOfferError(error);
1633
1645
  }
@@ -1679,6 +1691,7 @@ const serialize = (offer) => ({
1679
1691
  address: offer.callback.address,
1680
1692
  data: offer.callback.data
1681
1693
  },
1694
+ receiverIfMakerIsSeller: offer.receiverIfMakerIsSeller,
1682
1695
  hash: hash(offer)
1683
1696
  });
1684
1697
  /**
@@ -1721,8 +1734,9 @@ function random$1(config) {
1721
1734
  address: zeroAddress,
1722
1735
  data: "0x"
1723
1736
  };
1737
+ const maker = config?.maker ?? address();
1724
1738
  return from$9({
1725
- maker: config?.maker ?? address(),
1739
+ maker,
1726
1740
  assets: assetsScaled,
1727
1741
  obligationUnits: config?.obligationUnits ?? 0n,
1728
1742
  obligationShares: config?.obligationShares ?? 0n,
@@ -1739,7 +1753,8 @@ function random$1(config) {
1739
1753
  ...random$3(),
1740
1754
  lltv
1741
1755
  })).sort((a, b) => a.asset.localeCompare(b.asset)),
1742
- callback: config?.callback ?? emptyCallback
1756
+ callback: config?.callback ?? emptyCallback,
1757
+ receiverIfMakerIsSeller: config?.receiverIfMakerIsSeller ?? maker
1743
1758
  });
1744
1759
  }
1745
1760
  const weightedChoice = (pairs) => {
@@ -1825,6 +1840,10 @@ const types = {
1825
1840
  {
1826
1841
  name: "callback",
1827
1842
  type: "Callback"
1843
+ },
1844
+ {
1845
+ name: "receiverIfMakerIsSeller",
1846
+ type: "address"
1828
1847
  }
1829
1848
  ],
1830
1849
  Collateral: [
@@ -1870,7 +1889,8 @@ function hash(offer) {
1870
1889
  callback: {
1871
1890
  address: offer.callback.address.toLowerCase(),
1872
1891
  data: offer.callback.data
1873
- }
1892
+ },
1893
+ receiverIfMakerIsSeller: offer.receiverIfMakerIsSeller.toLowerCase()
1874
1894
  },
1875
1895
  primaryType: "Offer",
1876
1896
  types
@@ -1973,6 +1993,10 @@ const OfferAbi = [
1973
1993
  name: "data",
1974
1994
  type: "bytes"
1975
1995
  }]
1996
+ },
1997
+ {
1998
+ name: "receiverIfMakerIsSeller",
1999
+ type: "address"
1976
2000
  }
1977
2001
  ];
1978
2002
  function encode$1(offer) {
@@ -1991,7 +2015,8 @@ function encode$1(offer) {
1991
2015
  offer.loanToken,
1992
2016
  BigInt(offer.start),
1993
2017
  offer.collaterals,
1994
- offer.callback
2018
+ offer.callback,
2019
+ offer.receiverIfMakerIsSeller
1995
2020
  ]);
1996
2021
  }
1997
2022
  function decode$1(data) {
@@ -2025,7 +2050,8 @@ function decode$1(data) {
2025
2050
  callback: {
2026
2051
  address: decoded[14].address,
2027
2052
  data: decoded[14].data
2028
- }
2053
+ },
2054
+ receiverIfMakerIsSeller: decoded[15]
2029
2055
  });
2030
2056
  }
2031
2057
  /**
@@ -2101,6 +2127,12 @@ const takeEvent = {
2101
2127
  indexed: false,
2102
2128
  internalType: "bool"
2103
2129
  },
2130
+ {
2131
+ name: "sellerReceiver",
2132
+ type: "address",
2133
+ indexed: false,
2134
+ internalType: "address"
2135
+ },
2104
2136
  {
2105
2137
  name: "group",
2106
2138
  type: "bytes32",
@@ -2290,16 +2322,16 @@ function from$7(parameters) {
2290
2322
  //#region src/core/Quote.ts
2291
2323
  var Quote_exports = /* @__PURE__ */ __exportAll({
2292
2324
  InvalidQuoteError: () => InvalidQuoteError,
2293
- QuoteSchema: () => QuoteSchema,
2294
2325
  from: () => from$6,
2295
2326
  fromSnakeCase: () => fromSnakeCase,
2296
2327
  random: () => random
2297
2328
  });
2298
- const QuoteSchema = z$1.object({
2329
+ const SideInputSchema = z$1.object({ tick: z$1.number().int().min(0).max(TICK_RANGE).nullable() }).strict();
2330
+ const QuoteInputSchema = z$1.object({
2299
2331
  obligationId: z$1.string().transform(transformHex),
2300
- ask: z$1.object({ price: z$1.bigint({ coerce: true }).min(0n).max(maxUint256) }),
2301
- bid: z$1.object({ price: z$1.bigint({ coerce: true }).min(0n).max(maxUint256) })
2302
- });
2332
+ ask: SideInputSchema,
2333
+ bid: SideInputSchema
2334
+ }).strict();
2303
2335
  /**
2304
2336
  * Creates a quote for a given obligation.
2305
2337
  * @constructor
@@ -2309,16 +2341,16 @@ const QuoteSchema = z$1.object({
2309
2341
  *
2310
2342
  * @example
2311
2343
  * ```ts
2312
- * const quote = Quote.from({ obligationId: "0x123", ask: { price: 100n }, bid: { price: 100n } });
2344
+ * const quote = Quote.from({ obligationId: "0x123", ask: { tick: 500 }, bid: { tick: 510 } });
2313
2345
  * ```
2314
2346
  */
2315
2347
  function from$6(parameters) {
2316
2348
  try {
2317
- const parsedQuote = QuoteSchema.parse(parameters);
2349
+ const parsedQuote = QuoteInputSchema.parse(parameters);
2318
2350
  return {
2319
2351
  obligationId: parsedQuote.obligationId,
2320
- ask: parsedQuote.ask,
2321
- bid: parsedQuote.bid
2352
+ ask: sideFromTick(parsedQuote.ask),
2353
+ bid: sideFromTick(parsedQuote.bid)
2322
2354
  };
2323
2355
  } catch (error) {
2324
2356
  throw new InvalidQuoteError(error);
@@ -2345,8 +2377,8 @@ function fromSnakeCase(snake) {
2345
2377
  function random() {
2346
2378
  return from$6({
2347
2379
  obligationId: id(random$2()),
2348
- ask: { price: BigInt(int(1e6)) },
2349
- bid: { price: BigInt(int(1e6)) }
2380
+ ask: { tick: int(TICK_RANGE + 1) },
2381
+ bid: { tick: int(TICK_RANGE + 1) }
2350
2382
  });
2351
2383
  }
2352
2384
  var InvalidQuoteError = class extends BaseError {
@@ -2355,6 +2387,12 @@ var InvalidQuoteError = class extends BaseError {
2355
2387
  _defineProperty(this, "name", "Quote.InvalidQuoteError");
2356
2388
  }
2357
2389
  };
2390
+ function sideFromTick(side) {
2391
+ return {
2392
+ tick: side.tick,
2393
+ price: side.tick === null ? 0n : tickToPrice(side.tick)
2394
+ };
2395
+ }
2358
2396
 
2359
2397
  //#endregion
2360
2398
  //#region src/core/TradingFee.ts
@@ -2911,7 +2949,8 @@ function from$2(input) {
2911
2949
  group: input.group,
2912
2950
  session: input.session,
2913
2951
  callback: input.callback.address,
2914
- callback_data: input.callback.data
2952
+ callback_data: input.callback.data,
2953
+ receiver_if_maker_is_seller: input.receiverIfMakerIsSeller
2915
2954
  },
2916
2955
  offer_hash: input.hash,
2917
2956
  obligation_id: id({
@@ -2961,7 +3000,7 @@ function __decorate(decorators, target, key, desc) {
2961
3000
  //#region src/api/Schema/openapi.ts
2962
3001
  const timestampExample = "2024-01-01T12:00:00.000Z";
2963
3002
  const offerCursorExample = "eyJvZmZzZXQiOjEwMH0";
2964
- const obligationCursorExample = "0x25690ae1aee324a005be565f3bcdd16dbf8daf7969b26c181c8b8f467dad9abc";
3003
+ const obligationCursorExample = "eyJzb3J0IjpbImlkIl0sImlkIjoiMHgxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAiLCJhc2siOiIwIiwiYmlkIjoiMCIsIm1hdHVyaXR5IjoxNzYxOTIyODAwfQ";
2965
3004
  const offerExample = {
2966
3005
  offer: {
2967
3006
  obligation: {
@@ -2984,7 +3023,8 @@ const offerExample = {
2984
3023
  group: "0x000000000000000000000000000000000000000000000000000000000008b8f4",
2985
3024
  session: "0x0000000000000000000000000000000000000000000000000000000000000000",
2986
3025
  callback: "0x0000000000000000000000000000000000000000",
2987
- callback_data: "0x"
3026
+ callback_data: "0x",
3027
+ receiver_if_maker_is_seller: "0x7b093658BE7f90B63D7c359e8f408e503c2D9401"
2988
3028
  },
2989
3029
  offer_hash: "0xac4bd8318ec914f89f8af913f162230575b0ac0696a19256bc12138c5cfe1427",
2990
3030
  obligation_id: "0x25690ae1aee324a005be565f3bcdd16dbf8daf7969b26c181c8b8f467dad9abc",
@@ -3038,7 +3078,8 @@ const validateOfferExample = {
3038
3078
  callback: {
3039
3079
  address: "0x0000000000000000000000000000000000000000",
3040
3080
  data: "0x"
3041
- }
3081
+ },
3082
+ receiver_if_maker_is_seller: "0x7b093658BE7f90B63D7c359e8f408e503c2D9401"
3042
3083
  };
3043
3084
  const routerStatusExample = {
3044
3085
  status: "live",
@@ -3109,11 +3150,23 @@ __decorate([ApiProperty({
3109
3150
  example: validateOfferExample.callback.data
3110
3151
  })], ValidateCallbackRequest.prototype, "data", void 0);
3111
3152
  var AskResponse = class {};
3153
+ __decorate([ApiProperty({
3154
+ type: "number",
3155
+ nullable: true,
3156
+ example: 500,
3157
+ description: "Best ask tick. Null when there is no active ask quote."
3158
+ })], AskResponse.prototype, "tick", void 0);
3112
3159
  __decorate([ApiProperty({
3113
3160
  type: "string",
3114
3161
  example: "1000000000000000000"
3115
3162
  })], AskResponse.prototype, "price", void 0);
3116
3163
  var BidResponse = class {};
3164
+ __decorate([ApiProperty({
3165
+ type: "number",
3166
+ nullable: true,
3167
+ example: 500,
3168
+ description: "Best bid tick. Null when there is no active bid quote."
3169
+ })], BidResponse.prototype, "tick", void 0);
3117
3170
  __decorate([ApiProperty({
3118
3171
  type: "string",
3119
3172
  example: "1000000000000000000"
@@ -3186,6 +3239,10 @@ __decorate([ApiProperty({
3186
3239
  type: "string",
3187
3240
  example: offerExample.offer.callback_data
3188
3241
  })], OfferDataResponse.prototype, "callback_data", void 0);
3242
+ __decorate([ApiProperty({
3243
+ type: "string",
3244
+ example: offerExample.offer.receiver_if_maker_is_seller
3245
+ })], OfferDataResponse.prototype, "receiver_if_maker_is_seller", void 0);
3189
3246
  var OfferListItemResponse = class {};
3190
3247
  __decorate([ApiProperty({
3191
3248
  type: () => OfferDataResponse,
@@ -3455,6 +3512,10 @@ __decorate([ApiProperty({
3455
3512
  type: () => ValidateCallbackRequest,
3456
3513
  example: validateOfferExample.callback
3457
3514
  })], ValidateOfferRequest.prototype, "callback", void 0);
3515
+ __decorate([ApiProperty({
3516
+ type: "string",
3517
+ example: validateOfferExample.receiver_if_maker_is_seller
3518
+ })], ValidateOfferRequest.prototype, "receiver_if_maker_is_seller", void 0);
3458
3519
  var ValidateOffersRequest = class {};
3459
3520
  __decorate([ApiProperty({
3460
3521
  type: () => [ValidateOfferRequest],
@@ -4007,13 +4068,13 @@ __decorate([
4007
4068
  methods: ["get"],
4008
4069
  path: "/v1/obligations",
4009
4070
  summary: "List all obligations",
4010
- description: "Returns a list of obligations with their current best ask and bid. Obligations are sorted by their id in ascending order by default."
4071
+ description: "Returns a list of obligations with their current best ask and bid. Sorting is customizable with the sort parameter and defaults to id ascending."
4011
4072
  }),
4012
4073
  ApiQuery({
4013
4074
  name: "cursor",
4014
4075
  type: "string",
4015
4076
  example: obligationCursorExample,
4016
- description: "Obligation id cursor for pagination."
4077
+ description: "Pagination cursor in base64url-encoded format."
4017
4078
  }),
4018
4079
  ApiQuery({
4019
4080
  name: "limit",
@@ -4057,6 +4118,15 @@ __decorate([
4057
4118
  style: "form",
4058
4119
  explode: false
4059
4120
  }),
4121
+ ApiQuery({
4122
+ name: "sort",
4123
+ type: "string",
4124
+ required: false,
4125
+ example: "-ask,bid,maturity",
4126
+ description: "Sort order as comma-separated fields (`id`, `ask`, `bid`, `maturity`). Prefix with `-` for descending order. Max 3 fields.",
4127
+ style: "form",
4128
+ explode: false
4129
+ }),
4060
4130
  ApiResponse({
4061
4131
  status: 200,
4062
4132
  description: "Success",
@@ -4193,10 +4263,12 @@ function from$1(position) {
4193
4263
  //#region src/api/Schema/requests.ts
4194
4264
  const MAX_LIMIT = 100;
4195
4265
  const DEFAULT_LIMIT = 20;
4266
+ const MAX_OBLIGATION_SORT_FIELDS = 3;
4196
4267
  const CONFIG_RULES_MAX_LIMIT = 1e3;
4197
4268
  const CONFIG_RULES_DEFAULT_LIMIT = 100;
4198
4269
  const CONFIG_CONTRACTS_MAX_LIMIT = 1e3;
4199
4270
  const CONFIG_CONTRACTS_DEFAULT_LIMIT = 1e3;
4271
+ const OBLIGATION_SORT_ENTRY_REGEX = /^-?(id|ask|bid|maturity)$/;
4200
4272
  /** Validate cursor is a valid base64url-encoded JSON object.
4201
4273
  * Domain layer handles semantic validation of cursor fields. */
4202
4274
  function isValidBase64urlJson(val) {
@@ -4326,9 +4398,12 @@ const GetOffersQueryParams = PaginationQueryParams.omit({ cursor: true }).extend
4326
4398
  });
4327
4399
  const GetObligationsQueryParams = z$1.object({
4328
4400
  ...PaginationQueryParams.shape,
4329
- cursor: z$1.string().optional().meta({
4330
- description: "Obligation id cursor",
4331
- example: "0x1234567890123456789012345678901234567890123456789012345678901234"
4401
+ cursor: z$1.string().optional().refine((val) => {
4402
+ if (!val) return true;
4403
+ return isValidBase64urlJson(val);
4404
+ }, { message: "Invalid cursor format. Must be a valid base64url-encoded cursor object" }).meta({
4405
+ description: "Pagination cursor in base64url-encoded format.",
4406
+ example: "eyJzb3J0IjpbImlkIl0sImlkIjoiMHgxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAiLCJhc2siOiIwIiwiYmlkIjoiMCIsIm1hdHVyaXR5IjoxNzYxOTIyODAwfQ"
4332
4407
  }),
4333
4408
  chains: csvArray(z$1.string().regex(/^[1-9]\d*$/, { message: "Chain must be a positive integer" }).transform((val) => Number.parseInt(val, 10))).meta({
4334
4409
  description: "Filter by chain IDs (comma-separated).",
@@ -4345,6 +4420,24 @@ const GetObligationsQueryParams = z$1.object({
4345
4420
  maturities: csvArray(z$1.string().regex(/^[1-9]\d*$/, { message: "Maturity must be a positive integer" }).transform((val) => Number.parseInt(val, 10))).meta({
4346
4421
  description: "Filter by exact maturity timestamps (comma-separated, unix seconds).",
4347
4422
  example: "1761922800,1764524800"
4423
+ }),
4424
+ sort: csvArray(z$1.string().regex(OBLIGATION_SORT_ENTRY_REGEX, { message: "Sort entries must be one of: id, ask, bid, maturity (optionally prefixed with '-')" })).refine((entries) => entries === void 0 || entries.length <= MAX_OBLIGATION_SORT_FIELDS, { message: `Sort cannot include more than ${MAX_OBLIGATION_SORT_FIELDS} fields` }).superRefine((entries, ctx) => {
4425
+ if (!entries) return;
4426
+ const seen = /* @__PURE__ */ new Set();
4427
+ for (const entry of entries) {
4428
+ const field = entry.startsWith("-") ? entry.slice(1) : entry;
4429
+ if (seen.has(field)) {
4430
+ ctx.addIssue({
4431
+ code: "custom",
4432
+ message: `Duplicate sort field: ${field}`
4433
+ });
4434
+ return;
4435
+ }
4436
+ seen.add(field);
4437
+ }
4438
+ }).meta({
4439
+ description: "Sort order as comma-separated fields. Prefix a field with '-' for descending order. Max 3 fields.",
4440
+ example: "-ask,bid,maturity"
4348
4441
  })
4349
4442
  });
4350
4443
  const GetObligationParams = z$1.object({ obligation_id: z$1.string({ error: "Obligation id is required and must be a valid 32-byte hex string" }).regex(/^0x[a-fA-F0-9]{64}$/, { error: "Obligation id must be a valid 32-byte hex string" }).transform((val) => val.toLowerCase()).meta({
@@ -4533,7 +4626,8 @@ async function getOffers(apiClient, parameters) {
4533
4626
  callback: {
4534
4627
  address: offerData.callback,
4535
4628
  data: offerData.callback_data
4536
- }
4629
+ },
4630
+ receiver_if_maker_is_seller: offerData.receiver_if_maker_is_seller
4537
4631
  }),
4538
4632
  hash: item.offer_hash,
4539
4633
  consumed: BigInt(item.consumed),
@@ -4550,13 +4644,15 @@ async function getOffers(apiClient, parameters) {
4550
4644
  };
4551
4645
  }
4552
4646
  async function getObligations(apiClient, parameters) {
4647
+ const sort = parameters?.sort?.length ? parameters.sort.join(",") : void 0;
4553
4648
  const { data, error, response } = await apiClient.GET("/v1/obligations", { params: { query: {
4554
4649
  cursor: parameters?.cursor,
4555
4650
  limit: parameters?.limit,
4556
4651
  chains: parameters?.chainIds,
4557
4652
  loan_tokens: parameters?.loanTokens,
4558
4653
  collateral_tokens: parameters?.collateralTokens,
4559
- maturities: parameters?.maturities
4654
+ maturities: parameters?.maturities,
4655
+ sort
4560
4656
  } } });
4561
4657
  if (error !== void 0) {
4562
4658
  switch (response.status) {
@@ -4580,10 +4676,10 @@ async function getObligations(apiClient, parameters) {
4580
4676
  const { obligationId: _, ...returned } = {
4581
4677
  id: () => id(obligation),
4582
4678
  ...obligation,
4583
- ...fromSnakeCase({
4584
- obligation_id: item.id,
4585
- ask: item.ask,
4586
- bid: item.bid
4679
+ ...from$6({
4680
+ obligationId: item.id,
4681
+ ask: { tick: item.ask.tick },
4682
+ bid: { tick: item.bid.tick }
4587
4683
  })
4588
4684
  };
4589
4685
  return returned;
@@ -4931,19 +5027,19 @@ const oracles = {
4931
5027
  const configs = {
4932
5028
  ethereum: {
4933
5029
  callbacks: [{ type: Type$1.BuyWithEmptyCallback }, { type: Type$1.SellWithEmptyCallback }],
4934
- maturities: [MaturityType.EndOfMonth, MaturityType.EndOfNextMonth]
5030
+ maturities: [MaturityType.EndOfWeek, MaturityType.EndOfNextWeek]
4935
5031
  },
4936
5032
  base: {
4937
5033
  callbacks: [{ type: Type$1.BuyWithEmptyCallback }, { type: Type$1.SellWithEmptyCallback }],
4938
- maturities: [MaturityType.EndOfMonth, MaturityType.EndOfNextMonth]
5034
+ maturities: [MaturityType.EndOfWeek, MaturityType.EndOfNextWeek]
4939
5035
  },
4940
5036
  "ethereum-virtual-testnet": {
4941
5037
  callbacks: [{ type: Type$1.BuyWithEmptyCallback }, { type: Type$1.SellWithEmptyCallback }],
4942
- maturities: [MaturityType.EndOfMonth, MaturityType.EndOfNextMonth]
5038
+ maturities: [MaturityType.EndOfWeek, MaturityType.EndOfNextWeek]
4943
5039
  },
4944
5040
  anvil: {
4945
5041
  callbacks: [{ type: Type$1.BuyWithEmptyCallback }, { type: Type$1.SellWithEmptyCallback }],
4946
- maturities: [MaturityType.EndOfMonth, MaturityType.EndOfNextMonth]
5042
+ maturities: [MaturityType.EndOfWeek, MaturityType.EndOfNextWeek]
4947
5043
  }
4948
5044
  };
4949
5045
 
@@ -4977,7 +5073,7 @@ const chains = ({ chains }) => single("chain_ids", `Validates that offer chain i
4977
5073
  });
4978
5074
  const maturity = ({ maturities }) => single("maturity", `Validates that offer maturity is one of: [${maturities.join(", ")}]`, (offer) => {
4979
5075
  const allowedMaturities = maturities.map((m) => from$11(m));
4980
- if (!allowedMaturities.includes(offer.maturity)) return { message: `Maturity must be end of current month (${allowedMaturities[0]}) or end of next month (${allowedMaturities[1]}). Got: ${offer.maturity}` };
5076
+ if (!allowedMaturities.includes(offer.maturity)) return { message: `Maturity must be one of (${allowedMaturities.join(", ")}). Got: ${offer.maturity}` };
4981
5077
  });
4982
5078
  const callback = ({ callbacks }) => single("callback", `Validates callbacks: buy empty callback is ${callbacks.includes(Type$1.BuyWithEmptyCallback) ? "allowed" : "not allowed"}; sell empty callback is ${callbacks.includes(Type$1.SellWithEmptyCallback) ? "allowed" : "not allowed"}; non-empty callbacks are rejected`, (offer) => {
4983
5079
  if (!isEmptyCallback(offer)) return { message: "Non-empty callbacks are not supported." };
@@ -5057,7 +5153,7 @@ const morphoRules = (chains$2) => {
5057
5153
  sameMaker(),
5058
5154
  amountMutualExclusivity(),
5059
5155
  chains({ chains: chains$2 }),
5060
- maturity({ maturities: [MaturityType.EndOfMonth, MaturityType.EndOfNextMonth] }),
5156
+ maturity({ maturities: [MaturityType.EndOfWeek, MaturityType.EndOfNextWeek] }),
5061
5157
  callback({
5062
5158
  callbacks: [Type$1.BuyWithEmptyCallback, Type$1.SellWithEmptyCallback],
5063
5159
  allowedAddresses: []