@morpho-dev/router 0.12.0 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -77,10 +77,10 @@ var Tick_exports = /* @__PURE__ */ __exportAll({
77
77
  InvalidTickError: () => InvalidTickError,
78
78
  MAX_PRICE: () => MAX_PRICE,
79
79
  TICK_RANGE: () => TICK_RANGE,
80
- assetsToObligationUnits: () => assetsToObligationUnits,
81
- obligationUnitsToAssets: () => obligationUnitsToAssets,
80
+ assetsToUnits: () => assetsToUnits,
82
81
  priceToTick: () => priceToTick,
83
- tickToPrice: () => tickToPrice
82
+ tickToPrice: () => tickToPrice,
83
+ unitsToAssets: () => unitsToAssets
84
84
  });
85
85
  /** ln(1 + 0.025), scaled by 1e18. Matches TickLib onchain constant. */
86
86
  const LN_ONE_PLUS_DELTA = 24692612590371501n;
@@ -139,24 +139,79 @@ function assertPrice(price) {
139
139
  if (price < 0n || price > MAX_PRICE) throw new InvalidPriceError(price);
140
140
  }
141
141
  /**
142
- * Converts obligation units to assets using the tick price (mulDivDown).
143
- * @param obligationUnits - The obligation units to convert.
142
+ * Converts units into maker-side assets using the raw tick price surface.
143
+ * This is the public forward conversion used by the router for lot sizing and other maker-facing capacity math.
144
+ * - `buy = true` -> `floor(units * price / WAD)`
145
+ * - `buy = false` -> `ceil(units * price / WAD)`
146
+ * @param units - The units to convert.
144
147
  * @param tick - The offer tick.
145
- * @returns The equivalent amount in assets.
148
+ * @param buy - Whether the maker side of the offer is buy (`true`) or sell (`false`).
149
+ * @returns The equivalent amount in maker-side assets.
146
150
  */
147
- function obligationUnitsToAssets(obligationUnits, tick) {
148
- return obligationUnits * tickToPrice(tick) / WAD$1;
151
+ function unitsToAssets(units, tick, buy) {
152
+ const price = tickToPrice(tick);
153
+ return buy ? unitsToFloorAssets(units, price) : unitsToCeilAssets(units, price);
149
154
  }
150
155
  /**
151
- * Converts assets to obligation units using the tick price (mulDivUp).
152
- * @param assets - The asset amount to convert.
156
+ * Converts a maker-side asset cap into a safe units cap using the raw tick price.
157
+ * Buy offers use the max-safe inverse of `floor(units * price / WAD)`.
158
+ * Sell offers use the max-safe inverse of `ceil(units * price / WAD)`.
159
+ * The result is clamped to the remaining offer size because the asset cap may have been rounded before inversion.
160
+ * Zero integer asset caps can still admit positive units on floor-rounded sub-WAD buy ticks, and tick=0 keeps the
161
+ * whole remaining interval safe because the raw maker-asset surface stays at zero.
162
+ * @param assets - The integer maker-side asset cap.
153
163
  * @param tick - The offer tick.
154
- * @returns The equivalent amount in obligation units.
164
+ * @param buy - Whether the maker side of the offer is buy (`true`) or sell (`false`).
165
+ * @param remainingUnits - The maximum units still available on the offer.
166
+ * @returns The greatest safe units amount under the maker-side raw-price surface.
155
167
  */
156
- function assetsToObligationUnits(assets, tick) {
168
+ function assetsToUnits(assets, tick, buy, remainingUnits) {
169
+ if (remainingUnits <= 0n) return 0n;
170
+ if (assets < 0n) return 0n;
157
171
  const price = tickToPrice(tick);
158
- if (price === 0n) return 0n;
159
- return (assets * WAD$1 + price - 1n) / price;
172
+ if (price === 0n) return remainingUnits;
173
+ const units = buy ? floorAssetsToUnits(assets, price) : ceilAssetsToUnits(assets, price);
174
+ return units > remainingUnits ? remainingUnits : units;
175
+ }
176
+ /**
177
+ * Forward conversion for raw-price floor surfaces.
178
+ * This matches buy-side maker assets and the legacy floor-only helper.
179
+ * @param units - The units to convert.
180
+ * @param price - The raw tick price.
181
+ * @returns The floor-rounded maker-side assets.
182
+ */
183
+ function unitsToFloorAssets(units, price) {
184
+ return units * price / WAD$1;
185
+ }
186
+ /**
187
+ * Forward conversion for raw-price ceil surfaces.
188
+ * This matches sell-side maker assets, where the maker receives `sellerAssets` rounded up onchain.
189
+ * @param units - The units to convert.
190
+ * @param price - The raw tick price.
191
+ * @returns The ceil-rounded maker-side assets.
192
+ */
193
+ function unitsToCeilAssets(units, price) {
194
+ return (units * price + WAD$1 - 1n) / WAD$1;
195
+ }
196
+ /**
197
+ * Max-safe inverse for floor surfaces.
198
+ * It returns the greatest units value whose floor-rounded maker assets stay within `assets`.
199
+ * @param assets - The maker-side asset cap.
200
+ * @param price - The raw tick price.
201
+ * @returns The greatest safe obligation-units amount under `floor(units * price / WAD) <= assets`.
202
+ */
203
+ function floorAssetsToUnits(assets, price) {
204
+ return ((assets + 1n) * WAD$1 - 1n) / price;
205
+ }
206
+ /**
207
+ * Max-safe inverse for ceil surfaces.
208
+ * It returns the greatest units value whose ceil-rounded maker assets stay within `assets`.
209
+ * @param assets - The maker-side asset cap.
210
+ * @param price - The raw tick price.
211
+ * @returns The greatest safe obligation-units amount under `ceil(units * price / WAD) <= assets`.
212
+ */
213
+ function ceilAssetsToUnits(assets, price) {
214
+ return assets * WAD$1 / price;
160
215
  }
161
216
  var InvalidTickError = class extends BaseError {
162
217
  name = "Tick.InvalidTickError";
@@ -179,7 +234,7 @@ function from$15(level) {
179
234
  return {
180
235
  tick: level.tick,
181
236
  price: price.toString(),
182
- obligation_units: level.obligationUnits.toString(),
237
+ max_units: level.maxUnits.toString(),
183
238
  count: level.count
184
239
  };
185
240
  }
@@ -290,7 +345,7 @@ function from$13(input) {
290
345
  },
291
346
  buy: input.buy,
292
347
  maker: input.maker,
293
- obligation_units: input.obligationUnits.toString(),
348
+ max_units: input.maxUnits.toString(),
294
349
  start: input.start,
295
350
  expiry: input.expiry,
296
351
  tick: input.tick,
@@ -360,7 +415,7 @@ const offerExample = {
360
415
  },
361
416
  buy: false,
362
417
  maker: "0x7b093658BE7f90B63D7c359e8f408e503c2D9401",
363
- obligation_units: "369216000000000000000000",
418
+ max_units: "369216000000000000000000",
364
419
  start: 1761922790,
365
420
  expiry: 1761922799,
366
421
  tick: 495,
@@ -403,7 +458,7 @@ const missingCollectorExample = {
403
458
  };
404
459
  const validateOfferExample = {
405
460
  maker: "0x7b093658BE7f90B63D7c359e8f408e503c2D9401",
406
- obligation_units: "369216000000000000000000",
461
+ max_units: "369216000000000000000000",
407
462
  tick: 495,
408
463
  maturity: 1761922799,
409
464
  rcf_threshold: "0",
@@ -557,8 +612,8 @@ __decorate([ApiProperty({
557
612
  })], OfferDataResponse.prototype, "maker", void 0);
558
613
  __decorate([ApiProperty({
559
614
  type: "string",
560
- example: offerExample.offer.obligation_units
561
- })], OfferDataResponse.prototype, "obligation_units", void 0);
615
+ example: offerExample.offer.max_units
616
+ })], OfferDataResponse.prototype, "max_units", void 0);
562
617
  __decorate([ApiProperty({
563
618
  type: "number",
564
619
  example: offerExample.offer.start
@@ -812,9 +867,9 @@ __decorate([ApiProperty({
812
867
  })], ValidateOfferRequest.prototype, "maker", void 0);
813
868
  __decorate([ApiProperty({
814
869
  type: "string",
815
- example: validateOfferExample.obligation_units,
870
+ example: validateOfferExample.max_units,
816
871
  required: false
817
- })], ValidateOfferRequest.prototype, "obligation_units", void 0);
872
+ })], ValidateOfferRequest.prototype, "max_units", void 0);
818
873
  __decorate([ApiProperty({
819
874
  type: "number",
820
875
  example: validateOfferExample.tick,
@@ -948,7 +1003,7 @@ __decorate([ApiProperty({
948
1003
  __decorate([ApiProperty({
949
1004
  type: "string",
950
1005
  example: "369216000000000000000000"
951
- })], BookLevelResponse.prototype, "obligation_units", void 0);
1006
+ })], BookLevelResponse.prototype, "max_units", void 0);
952
1007
  __decorate([ApiProperty({
953
1008
  type: "number",
954
1009
  example: 5
@@ -1961,7 +2016,7 @@ const MorphoV2 = parseAbi([
1961
2016
  "function obligationCreated(bytes32 id) view returns (bool)",
1962
2017
  "function obligationState(bytes32 id) view returns (uint128 totalUnits, uint256 withdrawable, uint128 lossIndex, bool created)",
1963
2018
  "function owner() view returns (address)",
1964
- "function repay((address loanToken, (address token, uint256 lltv, uint256 maxLif, address oracle)[] collaterals, uint256 maturity, uint256 rcfThreshold) obligation, uint256 obligationUnits, address onBehalf)",
2019
+ "function repay((address loanToken, (address token, uint256 lltv, uint256 maxLif, address oracle)[] collaterals, uint256 maturity, uint256 rcfThreshold) obligation, uint256 units, address onBehalf)",
1965
2020
  "function session(address user) view returns (bytes32)",
1966
2021
  "function setConsumed(bytes32 group, uint256 amount, address onBehalf)",
1967
2022
  "function setDefaultTradingFee(address loanToken, uint256 index, uint256 newTradingFee)",
@@ -1976,7 +2031,7 @@ const MorphoV2 = parseAbi([
1976
2031
  "function shuffleSession(address onBehalf)",
1977
2032
  "function slash(bytes32 id, address user)",
1978
2033
  "function supplyCollateral((address loanToken, (address token, uint256 lltv, uint256 maxLif, address oracle)[] collaterals, uint256 maturity, uint256 rcfThreshold) obligation, uint256 collateralIndex, uint256 assets, address onBehalf)",
1979
- "function take(uint256 obligationUnits, address taker, address takerCallback, bytes takerCallbackData, address receiverIfTakerIsSeller, ((address loanToken, (address token, uint256 lltv, uint256 maxLif, address oracle)[] collaterals, uint256 maturity, uint256 rcfThreshold) obligation, bool buy, address maker, uint256 obligationUnits, uint256 start, uint256 expiry, uint256 tick, bytes32 group, bytes32 session, address callback, bytes callbackData, address receiverIfMakerIsSeller, bool exitOnly) offer, (uint8 v, bytes32 r, bytes32 s) sig, bytes32 root, bytes32[] proof) returns (uint256, uint256, uint256)",
2034
+ "function take(uint256 units, address taker, address takerCallback, bytes takerCallbackData, address receiverIfTakerIsSeller, ((address loanToken, (address token, uint256 lltv, uint256 maxLif, address oracle)[] collaterals, uint256 maturity, uint256 rcfThreshold) obligation, bool buy, address maker, uint256 maxUnits, uint256 start, uint256 expiry, uint256 tick, bytes32 group, bytes32 session, address callback, bytes callbackData, address receiverIfMakerIsSeller, bool exitOnly) offer, (uint8 v, bytes32 r, bytes32 s) sig, bytes32 root, bytes32[] proof) returns (uint256, uint256, uint256)",
1980
2035
  "function toId((address loanToken, (address token, uint256 lltv, uint256 maxLif, address oracle)[] collaterals, uint256 maturity, uint256 rcfThreshold) obligation) view returns (bytes32)",
1981
2036
  "function toObligation(bytes32 id) view returns ((address loanToken, (address token, uint256 lltv, uint256 maxLif, address oracle)[] collaterals, uint256 maturity, uint256 rcfThreshold))",
1982
2037
  "function totalUnits(bytes32 id) view returns (uint256)",
@@ -1984,14 +2039,14 @@ const MorphoV2 = parseAbi([
1984
2039
  "function tradingFee(bytes32 id, uint256 timeToMaturity) view returns (uint256)",
1985
2040
  "function tradingFeeRecipient() view returns (address)",
1986
2041
  "function userLossIndex(bytes32 id, address user) view returns (uint128)",
1987
- "function withdraw((address loanToken, (address token, uint256 lltv, uint256 maxLif, address oracle)[] collaterals, uint256 maturity, uint256 rcfThreshold) obligation, uint256 obligationUnits, address onBehalf, address receiver)",
2042
+ "function withdraw((address loanToken, (address token, uint256 lltv, uint256 maxLif, address oracle)[] collaterals, uint256 maturity, uint256 rcfThreshold) obligation, uint256 units, address onBehalf, address receiver)",
1988
2043
  "function withdrawCollateral((address loanToken, (address token, uint256 lltv, uint256 maxLif, address oracle)[] collaterals, uint256 maturity, uint256 rcfThreshold) obligation, uint256 collateralIndex, uint256 assets, address onBehalf, address receiver)",
1989
2044
  "function withdrawable(bytes32 id) view returns (uint256)",
1990
2045
  "event Constructor(address indexed owner)",
1991
2046
  "event FlashLoan(address indexed caller, address indexed token, uint256 assets)",
1992
2047
  "event Liquidate(address indexed caller, bytes32 indexed id_, uint256 collateralIndex, uint256 seizedAssets, uint256 repaidUnits, address indexed borrower, uint256 badDebt, uint256 latestLossIndex)",
1993
2048
  "event ObligationCreated(bytes32 indexed id_, (address loanToken, (address token, uint256 lltv, uint256 maxLif, address oracle)[] collaterals, uint256 maturity, uint256 rcfThreshold) obligation)",
1994
- "event Repay(address indexed caller, bytes32 indexed id_, uint256 obligationUnits, address indexed onBehalf)",
2049
+ "event Repay(address indexed caller, bytes32 indexed id_, uint256 units, address indexed onBehalf)",
1995
2050
  "event SetConsumed(address indexed caller, address indexed onBehalf, bytes32 indexed group, uint256 amount)",
1996
2051
  "event SetDefaultTradingFee(address indexed loanToken, uint256 indexed index, uint256 newTradingFee)",
1997
2052
  "event SetFeeSetter(address indexed feeSetter)",
@@ -2005,8 +2060,8 @@ const MorphoV2 = parseAbi([
2005
2060
  "event ShuffleSession(address indexed caller, address indexed onBehalf, bytes32 session)",
2006
2061
  "event Slash(address caller, bytes32 indexed id_, address indexed user, uint256 credit, uint256 latestLossIndex)",
2007
2062
  "event SupplyCollateral(address caller, bytes32 indexed id_, address indexed collateral, uint256 assets, address indexed onBehalf)",
2008
- "event Take(address caller, bytes32 indexed id_, address indexed maker, address indexed taker, bool offerIsBuy, uint256 buyerAssets, uint256 sellerAssets, uint256 obligationUnits, address sellerReceiver, bytes32 group, uint256 consumed, uint256 totalUnits)",
2009
- "event Withdraw(address caller, bytes32 indexed id_, uint256 obligationUnits, address indexed onBehalf, address indexed receiver)",
2063
+ "event Take(address caller, bytes32 indexed id_, address indexed maker, address indexed taker, bool offerIsBuy, uint256 buyerAssets, uint256 sellerAssets, uint256 units, address sellerReceiver, bytes32 group, uint256 consumed, uint256 totalUnits)",
2064
+ "event Withdraw(address caller, bytes32 indexed id_, uint256 units, address indexed onBehalf, address indexed receiver)",
2010
2065
  "event WithdrawCollateral(address caller, bytes32 indexed id_, address indexed collateral, uint256 assets, address indexed onBehalf, address receiver)"
2011
2066
  ]);
2012
2067
 
@@ -2300,8 +2355,8 @@ const chains$1 = {
2300
2355
  name: "base",
2301
2356
  custom: {
2302
2357
  morpho: {
2303
- address: "0xee437005ba0a3d0e9bc6510775c41f23ed2909e1",
2304
- blockCreated: 43515847
2358
+ address: "0x26378861d9c740fe86e7472752aef5b1a783c60b",
2359
+ blockCreated: 43606117
2305
2360
  },
2306
2361
  morphoBlue: {
2307
2362
  address: "0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb",
@@ -2330,8 +2385,8 @@ const chains$1 = {
2330
2385
  name: "ethereum-virtual-testnet",
2331
2386
  custom: {
2332
2387
  morpho: {
2333
- address: "0xc1c6e6fa308eeef18e96be420d8ccb218215a26c",
2334
- blockCreated: 23244321
2388
+ address: "0x94c576ee728ee290116ee65c0d1e9fed4a1b5041",
2389
+ blockCreated: 23244323
2335
2390
  },
2336
2391
  morphoBlue: {
2337
2392
  address: "0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb",
@@ -2752,6 +2807,7 @@ const transformAddress = (val, ctx) => {
2752
2807
  });
2753
2808
  return z$1.NEVER;
2754
2809
  };
2810
+ const AddressSchema = z$1.string().transform(transformAddress);
2755
2811
 
2756
2812
  //#endregion
2757
2813
  //#region src/core/LLTV.ts
@@ -2836,10 +2892,10 @@ const abi$1 = [
2836
2892
  }
2837
2893
  ];
2838
2894
  const CollateralSchema = z$1.object({
2839
- asset: z$1.string().transform(transformAddress),
2840
- oracle: z$1.string().transform(transformAddress),
2895
+ asset: AddressSchema,
2896
+ oracle: AddressSchema,
2841
2897
  lltv: LLTVSchema,
2842
- maxLif: z$1.bigint({ coerce: true }).min(0n).optional().default(0n)
2898
+ maxLif: z$1.bigint({ coerce: true }).min(0n)
2843
2899
  });
2844
2900
  const CollateralsSchema = z$1.array(CollateralSchema).min(1, { message: "At least one collateral is required" }).refine((collaterals) => {
2845
2901
  for (let i = 1; i < collaterals.length; i++) if (collaterals[i - 1].asset.toLowerCase() > collaterals[i].asset.toLowerCase()) return false;
@@ -2857,7 +2913,7 @@ const from$10 = (parameters) => {
2857
2913
  return {
2858
2914
  asset: parameters.asset.toLowerCase(),
2859
2915
  lltv: from$11(parameters.lltv),
2860
- maxLif: parameters.maxLif ?? 0n,
2916
+ maxLif: parameters.maxLif,
2861
2917
  oracle: parameters.oracle.toLowerCase()
2862
2918
  };
2863
2919
  };
@@ -2997,14 +3053,8 @@ var Maturity_exports = /* @__PURE__ */ __exportAll({
2997
3053
  MaturityType: () => MaturityType,
2998
3054
  from: () => from$9
2999
3055
  });
3000
- const MaturitySchema = z$1.number().int().refine((maturity) => {
3001
- try {
3002
- from$9(maturity);
3003
- return true;
3004
- } catch (_e) {
3005
- return false;
3006
- }
3007
- }, { error: (issue) => {
3056
+ const MAX_TIMESTAMP_SECONDS = 999999999999;
3057
+ const MaturitySchema = z$1.number().int().max(MAX_TIMESTAMP_SECONDS).refine(isAt15UTC, { error: (issue) => {
3008
3058
  try {
3009
3059
  return `The maturity is set to ${/* @__PURE__ */ new Date(issue.input * 1e3)}. It must be at 15:00:00 UTC.`;
3010
3060
  } catch (_) {
@@ -3039,7 +3089,7 @@ function from$9(ts) {
3039
3089
  if (ts in MaturityOptions) return MaturityOptions[ts]();
3040
3090
  throw new InvalidOptionError(ts);
3041
3091
  }
3042
- if (typeof ts === "number" && ts > 0xe8d4a51000) throw new InvalidFormatError();
3092
+ if (typeof ts === "number" && ts > MAX_TIMESTAMP_SECONDS) throw new InvalidFormatError();
3043
3093
  if (!isAt15UTC(ts)) throw new InvalidDateError(ts);
3044
3094
  return ts;
3045
3095
  }
@@ -3133,7 +3183,7 @@ var Obligation_exports = /* @__PURE__ */ __exportAll({
3133
3183
  tupleAbi: () => tupleAbi
3134
3184
  });
3135
3185
  const ObligationSchema = z$1.object({
3136
- loanToken: z$1.string().transform(transformAddress),
3186
+ loanToken: AddressSchema,
3137
3187
  collaterals: CollateralsSchema,
3138
3188
  maturity: MaturitySchema,
3139
3189
  rcfThreshold: z$1.bigint({ coerce: true }).min(0n)
@@ -3176,7 +3226,8 @@ const tupleAbi = [{
3176
3226
  * Collateral.from({
3177
3227
  * asset: privateKeyToAccount(generatePrivateKey()).address,
3178
3228
  * oracle: privateKeyToAccount(generatePrivateKey()).address,
3179
- * lltv: 0.965
3229
+ * lltv: 0.965,
3230
+ * maxLif: 0n,
3180
3231
  * }),
3181
3232
  * ],
3182
3233
  * maturity: Maturity.from("end_of_next_quarter"),
@@ -3235,7 +3286,7 @@ function key(parameters) {
3235
3286
  parameters.collaterals.map((c) => ({
3236
3287
  token: c.asset.toLowerCase(),
3237
3288
  lltv: c.lltv,
3238
- maxLif: c.maxLif ?? 0n,
3289
+ maxLif: c.maxLif,
3239
3290
  oracle: c.oracle.toLowerCase()
3240
3291
  })),
3241
3292
  BigInt(parameters.maturity),
@@ -3308,7 +3359,7 @@ function creationCode(parameters) {
3308
3359
  collaterals: parameters.obligation.collaterals.map((collateral) => ({
3309
3360
  token: collateral.asset.toLowerCase(),
3310
3361
  lltv: collateral.lltv,
3311
- maxLif: collateral.maxLif ?? 0n,
3362
+ maxLif: collateral.maxLif,
3312
3363
  oracle: collateral.oracle.toLowerCase()
3313
3364
  })),
3314
3365
  maturity: BigInt(parameters.obligation.maturity),
@@ -3435,8 +3486,8 @@ let Status = /* @__PURE__ */ function(Status) {
3435
3486
  }({});
3436
3487
  const OfferSchema = () => {
3437
3488
  return z$1.object({
3438
- maker: z$1.string().transform(transformAddress),
3439
- obligationUnits: z$1.bigint({ coerce: true }).min(0n).max(maxUint256).optional().default(0n),
3489
+ maker: AddressSchema,
3490
+ maxUnits: z$1.bigint({ coerce: true }).min(0n).max(maxUint256).optional().default(0n),
3440
3491
  tick: z$1.coerce.number().int().min(0).max(990),
3441
3492
  maturity: MaturitySchema,
3442
3493
  rcfThreshold: z$1.bigint({ coerce: true }).min(0n).max(maxUint256),
@@ -3453,13 +3504,13 @@ const OfferSchema = () => {
3453
3504
  z$1.bigint()
3454
3505
  ]).optional().default("0x0000000000000000000000000000000000000000000000000000000000000000").transform(transformBytes32),
3455
3506
  buy: z$1.boolean(),
3456
- loanToken: z$1.string().transform(transformAddress),
3507
+ loanToken: AddressSchema,
3457
3508
  collaterals: CollateralsSchema,
3458
3509
  callback: z$1.object({
3459
- address: z$1.string().transform(transformAddress),
3510
+ address: AddressSchema,
3460
3511
  data: z$1.string().transform(transformHex)
3461
3512
  }),
3462
- receiverIfMakerIsSeller: z$1.string().transform(transformAddress),
3513
+ receiverIfMakerIsSeller: AddressSchema,
3463
3514
  exitOnly: z$1.boolean().optional().default(false)
3464
3515
  }).refine((data) => data.start < data.expiry, {
3465
3516
  message: "start must be before expiry",
@@ -3512,7 +3563,7 @@ function toSnakeCase(offer) {
3512
3563
  */
3513
3564
  const serialize = (offer) => ({
3514
3565
  maker: offer.maker,
3515
- obligationUnits: offer.obligationUnits.toString(),
3566
+ maxUnits: offer.maxUnits.toString(),
3516
3567
  tick: offer.tick,
3517
3568
  maturity: Number(offer.maturity),
3518
3569
  rcfThreshold: offer.rcfThreshold.toString(),
@@ -3570,7 +3621,7 @@ function random$1(config) {
3570
3621
  const loanTokenDecimals = config?.assetsDecimals?.[loanToken] ?? 18;
3571
3622
  const unit = BigInt(10) ** BigInt(loanTokenDecimals);
3572
3623
  const amountBase = BigInt(100 + int(999901));
3573
- const obligationUnitsScaled = config?.obligationUnits ?? amountBase * unit;
3624
+ const maxUnitsScaled = config?.maxUnits ?? amountBase * unit;
3574
3625
  const emptyCallback = {
3575
3626
  address: zeroAddress,
3576
3627
  data: "0x"
@@ -3578,7 +3629,7 @@ function random$1(config) {
3578
3629
  const maker = config?.maker ?? address();
3579
3630
  return from$7({
3580
3631
  maker,
3581
- obligationUnits: obligationUnitsScaled,
3632
+ maxUnits: maxUnitsScaled,
3582
3633
  tick,
3583
3634
  maturity,
3584
3635
  rcfThreshold: config?.rcfThreshold ?? 0n,
@@ -3632,7 +3683,7 @@ function hash(offer) {
3632
3683
  * Obligation obligation; // nested tuple
3633
3684
  * bool buy;
3634
3685
  * address maker;
3635
- * uint256 obligationUnits;
3686
+ * uint256 maxUnits;
3636
3687
  * uint256 start;
3637
3688
  * uint256 expiry;
3638
3689
  * uint256 tick;
@@ -3698,7 +3749,7 @@ const OfferAbi = [{
3698
3749
  type: "address"
3699
3750
  },
3700
3751
  {
3701
- name: "obligationUnits",
3752
+ name: "maxUnits",
3702
3753
  type: "uint256"
3703
3754
  },
3704
3755
  {
@@ -3746,7 +3797,7 @@ function encode$1(offer) {
3746
3797
  collaterals: offer.collaterals.map((c) => ({
3747
3798
  token: c.asset,
3748
3799
  lltv: c.lltv,
3749
- maxLif: c.maxLif ?? 0n,
3800
+ maxLif: c.maxLif,
3750
3801
  oracle: c.oracle
3751
3802
  })),
3752
3803
  maturity: BigInt(offer.maturity),
@@ -3754,7 +3805,7 @@ function encode$1(offer) {
3754
3805
  },
3755
3806
  buy: offer.buy,
3756
3807
  maker: offer.maker,
3757
- obligationUnits: offer.obligationUnits,
3808
+ maxUnits: offer.maxUnits,
3758
3809
  start: BigInt(offer.start),
3759
3810
  expiry: BigInt(offer.expiry),
3760
3811
  tick: BigInt(offer.tick),
@@ -3788,7 +3839,7 @@ function decode$1(data) {
3788
3839
  rcfThreshold: s.obligation.rcfThreshold,
3789
3840
  buy: s.buy,
3790
3841
  maker: s.maker,
3791
- obligationUnits: s.obligationUnits,
3842
+ maxUnits: s.maxUnits,
3792
3843
  start: Number(s.start),
3793
3844
  expiry: Number(s.expiry),
3794
3845
  tick: Number(s.tick),
@@ -3852,7 +3903,7 @@ const takeEvent = {
3852
3903
  internalType: "uint256"
3853
3904
  },
3854
3905
  {
3855
- name: "obligationUnits",
3906
+ name: "units",
3856
3907
  type: "uint256",
3857
3908
  indexed: false,
3858
3909
  internalType: "uint256"
@@ -3938,7 +3989,7 @@ const repayEvent = {
3938
3989
  internalType: "bytes32"
3939
3990
  },
3940
3991
  {
3941
- name: "obligationUnits",
3992
+ name: "units",
3942
3993
  type: "uint256",
3943
3994
  indexed: false,
3944
3995
  internalType: "uint256"
@@ -4947,7 +4998,7 @@ async function getOffers(apiClient, parameters) {
4947
4998
  return {
4948
4999
  ...fromSnakeCase$1({
4949
5000
  maker: offerData.maker,
4950
- obligation_units: offerData.obligation_units,
5001
+ max_units: offerData.max_units,
4951
5002
  tick: offerData.tick,
4952
5003
  maturity: from$9(offerData.obligation.maturity),
4953
5004
  rcf_threshold: offerData.obligation.rcf_threshold,
@@ -5304,7 +5355,6 @@ const assets = {
5304
5355
  "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
5305
5356
  "0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb",
5306
5357
  "0x4200000000000000000000000000000000000006",
5307
- "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
5308
5358
  "0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf",
5309
5359
  "0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452",
5310
5360
  "0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42"
@@ -5610,7 +5660,7 @@ var utils_exports = /* @__PURE__ */ __exportAll({
5610
5660
 
5611
5661
  //#endregion
5612
5662
  //#region src/database/drizzle/VERSION.ts
5613
- const VERSION = "router_v1.15";
5663
+ const VERSION = "router_v1.16";
5614
5664
 
5615
5665
  //#endregion
5616
5666
  //#region src/database/drizzle/schema.ts
@@ -5729,7 +5779,7 @@ const oracles = s.table(EnumTableName.ORACLES, {
5729
5779
  const offers = s.table(EnumTableName.OFFERS, {
5730
5780
  hash: varchar("hash", { length: 66 }).notNull(),
5731
5781
  obligationId: varchar("obligation_id", { length: 66 }).notNull().references(() => obligationIdKeys.obligationId, { onDelete: "cascade" }),
5732
- obligationUnits: numeric("obligation_units", {
5782
+ maxUnits: numeric("max_units", {
5733
5783
  precision: 78,
5734
5784
  scale: 0
5735
5785
  }).notNull().default("0"),
@@ -5770,8 +5820,8 @@ const offers = s.table(EnumTableName.OFFERS, {
5770
5820
  index("offers_obligation_side_tick_idx").on(table.obligationId, table.buy, table.tick),
5771
5821
  index("offers_obligation_active_tick_idx").on(table.obligationId, table.buy, table.expiry, table.maturity, table.start, table.tick),
5772
5822
  index("offers_group_maker_idx").on(table.groupMaker, table.hash, table.obligationId),
5773
- index("offers_group_winner_expr_idx").on(table.groupChainId, table.groupMaker, table.group, table.obligationId, table.buy, sql`(CASE WHEN "buy" THEN -"tick" ELSE "tick" END)`, table.blockNumber, sql`"obligation_units" DESC`, table.hash),
5774
- index("offers_book_winners_covering_idx").on(table.obligationId, table.buy, table.groupChainId, table.groupMaker, table.group, sql`(CASE WHEN "buy" THEN -"tick" ELSE "tick" END)`, table.blockNumber, sql`"obligation_units" DESC`, table.hash)
5823
+ index("offers_group_winner_expr_idx").on(table.groupChainId, table.groupMaker, table.group, table.obligationId, table.buy, sql`(CASE WHEN "buy" THEN -"tick" ELSE "tick" END)`, table.blockNumber, sql`"max_units" DESC`, table.hash),
5824
+ index("offers_book_winners_covering_idx").on(table.obligationId, table.buy, table.groupChainId, table.groupMaker, table.group, sql`(CASE WHEN "buy" THEN -"tick" ELSE "tick" END)`, table.blockNumber, sql`"max_units" DESC`, table.hash)
5775
5825
  ]);
5776
5826
  const offersCallbacks = s.table(EnumTableName.OFFERS_CALLBACKS, {
5777
5827
  offerHash: varchar("offer_hash", { length: 66 }).notNull(),
@@ -6164,16 +6214,16 @@ const maxCollaterals = ({ max }) => single("max_collaterals", `Validates that an
6164
6214
  if (offer.collaterals.length > max) return { message: `Offer has ${offer.collaterals.length} collaterals, exceeding the maximum of ${max}` };
6165
6215
  });
6166
6216
  /**
6167
- * A validation rule that checks if the offer's obligationUnits is non-zero.
6217
+ * A validation rule that checks if the offer's maxUnits is non-zero.
6168
6218
  * The contract requires a positive amount; this rule rejects early.
6169
6219
  * @returns The issue that was found. If the offer is valid, this will be undefined.
6170
6220
  */
6171
- const amountNonZero = () => single("amount_non_zero", "Validates that obligationUnits is non-zero", (offer) => {
6172
- if (offer.obligationUnits === 0n) return { message: "obligationUnits must be non-zero" };
6221
+ const amountNonZero = () => single("amount_non_zero", "Validates that maxUnits is non-zero", (offer) => {
6222
+ if (offer.maxUnits === 0n) return { message: "maxUnits must be non-zero" };
6173
6223
  });
6174
6224
  /**
6175
6225
  * A batch validation rule that ensures all offers within the same group are consistent.
6176
- * All offers sharing the same group must have the same loan token, obligationUnits,
6226
+ * All offers sharing the same group must have the same loan token, maxUnits,
6177
6227
  * and side (buy/sell). The contract tracks consumed per group and requires these to match.
6178
6228
  */
6179
6229
  const groupConsistency = () => batch("group_consistency", "Validates that all offers in a group have the same loan token, obligation amounts, and side", (offers) => {
@@ -6190,13 +6240,13 @@ const groupConsistency = () => batch("group_consistency", "Validates that all of
6190
6240
  if (indices.length <= 1) continue;
6191
6241
  const reference = offers[indices[0]];
6192
6242
  const refLoanToken = reference.loanToken.toLowerCase();
6193
- const refUnits = reference.obligationUnits;
6243
+ const refUnits = reference.maxUnits;
6194
6244
  const refBuy = reference.buy;
6195
6245
  for (let j = 1; j < indices.length; j++) {
6196
6246
  const idx = indices[j];
6197
6247
  const offer = offers[idx];
6198
6248
  if (offer.loanToken.toLowerCase() !== refLoanToken) issues.set(idx, { message: `All offers in a group must have the same loan token. Expected ${reference.loanToken}, got ${offer.loanToken}` });
6199
- else if (offer.obligationUnits !== refUnits) issues.set(idx, { message: `All offers in a group must have the same obligationUnits. Expected ${refUnits}, got ${offer.obligationUnits}` });
6249
+ else if (offer.maxUnits !== refUnits) issues.set(idx, { message: `All offers in a group must have the same maxUnits. Expected ${refUnits}, got ${offer.maxUnits}` });
6200
6250
  else if (offer.buy !== refBuy) issues.set(idx, { message: `All offers in a group must be on the same side. Expected ${refBuy ? "buy" : "sell"}, got ${offer.buy ? "buy" : "sell"}` });
6201
6251
  }
6202
6252
  }