@morpho-dev/router 0.4.2 → 0.5.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.
@@ -1,4 +1,4 @@
1
- import { t as __export } from "./chunk-jass6xSI.mjs";
1
+ import { t as __exportAll } from "./chunk-Bo1DHCg-.mjs";
2
2
  import { z } from "zod/v4";
3
3
  import { bytesToHex, decodeAbiParameters, encodeAbiParameters, getAddress, hashMessage, hashTypedData, hexToBytes, isAddress, isHex, keccak256, maxUint256, numberToHex, pad, parseAbi, publicActions, recoverAddress, zeroAddress } from "viem";
4
4
  import { getBlock, getLogs, multicall } from "viem/actions";
@@ -12,8 +12,8 @@ import { ApiBody, ApiOperation, ApiParam, ApiProperty, ApiQuery, ApiResponse, Ap
12
12
  import createOpenApiFetchClient from "openapi-fetch";
13
13
 
14
14
  //#region src/api/Schema/BookResponse.ts
15
- var BookResponse_exports = /* @__PURE__ */ __export({ from: () => from$14 });
16
- function from$14(level) {
15
+ var BookResponse_exports = /* @__PURE__ */ __exportAll({ from: () => from$15 });
16
+ function from$15(level) {
17
17
  return {
18
18
  price: level.price.toString(),
19
19
  assets: level.assets.toString(),
@@ -57,14 +57,14 @@ const RouterStatusResponse = z.object({
57
57
 
58
58
  //#endregion
59
59
  //#region src/api/Schema/ObligationResponse.ts
60
- var ObligationResponse_exports = /* @__PURE__ */ __export({ from: () => from$13 });
60
+ var ObligationResponse_exports = /* @__PURE__ */ __exportAll({ from: () => from$14 });
61
61
  /**
62
62
  * Creates an `ObligationResponse` from a `Obligation`.
63
63
  * @constructor
64
64
  * @param obligation - {@link Obligation}
65
65
  * @returns The created `ObligationResponse`. {@link ObligationResponse}
66
66
  */
67
- function from$13(obligation, quote) {
67
+ function from$14(obligation, quote) {
68
68
  return {
69
69
  id: quote.obligationId,
70
70
  chain_id: obligation.chainId,
@@ -100,7 +100,7 @@ const MetaMorphoFactory = parseAbi(["event CreateMetaMorpho(address indexed meta
100
100
 
101
101
  //#endregion
102
102
  //#region src/core/Abi/index.ts
103
- var Abi_exports = /* @__PURE__ */ __export({
103
+ var Abi_exports = /* @__PURE__ */ __exportAll({
104
104
  ERC4626: () => ERC4626,
105
105
  MetaMorpho: () => MetaMorpho,
106
106
  MetaMorphoFactory: () => MetaMorphoFactory,
@@ -251,41 +251,77 @@ const Morpho = [
251
251
 
252
252
  //#endregion
253
253
  //#region src/core/Callback.ts
254
- var Callback_exports = /* @__PURE__ */ __export({
255
- CallbackType: () => CallbackType,
254
+ var Callback_exports = /* @__PURE__ */ __exportAll({
255
+ Type: () => Type$1,
256
256
  decode: () => decode$2,
257
+ decodeBuyERC20: () => decodeBuyERC20,
257
258
  decodeBuyVaultV1Callback: () => decodeBuyVaultV1Callback,
258
259
  decodeSellERC20Callback: () => decodeSellERC20Callback,
259
260
  encode: () => encode$2,
261
+ encodeBuyERC20: () => encodeBuyERC20,
260
262
  encodeBuyVaultV1Callback: () => encodeBuyVaultV1Callback,
261
263
  encodeSellERC20Callback: () => encodeSellERC20Callback,
262
264
  isEmptyCallback: () => isEmptyCallback
263
265
  });
264
- let CallbackType = /* @__PURE__ */ function(CallbackType$1) {
265
- CallbackType$1["BuyWithEmptyCallback"] = "buy_with_empty_callback";
266
- CallbackType$1["BuyVaultV1Callback"] = "buy_vault_v1_callback";
267
- CallbackType$1["SellERC20Callback"] = "sell_erc20_callback";
268
- return CallbackType$1;
266
+ let Type$1 = /* @__PURE__ */ function(Type) {
267
+ Type["BuyWithEmptyCallback"] = "buy_with_empty_callback";
268
+ Type["BuyERC20"] = "buy_erc20";
269
+ Type["BuyVaultV1Callback"] = "buy_vault_v1_callback";
270
+ Type["SellERC20Callback"] = "sell_erc20_callback";
271
+ return Type;
269
272
  }({});
270
273
  const isEmptyCallback = (offer) => offer.callback.data === "0x";
271
274
  function decode$2(type, data) {
272
275
  switch (type) {
273
- case CallbackType.BuyVaultV1Callback: return decodeBuyVaultV1Callback(data);
274
- case CallbackType.SellERC20Callback: return decodeSellERC20Callback(data);
276
+ case Type$1.BuyERC20: return decodeBuyERC20(data);
277
+ case Type$1.BuyVaultV1Callback: return decodeBuyVaultV1Callback(data);
278
+ case Type$1.SellERC20Callback: return decodeSellERC20Callback(data);
275
279
  default: throw new Error("Invalid callback type");
276
280
  }
277
281
  }
278
282
  function encode$2(type, data) {
279
283
  switch (type) {
280
- case CallbackType.BuyVaultV1Callback:
284
+ case Type$1.BuyERC20:
285
+ if (!("tokens" in data)) throw new Error("Invalid callback data");
286
+ return encodeBuyERC20(data);
287
+ case Type$1.BuyVaultV1Callback:
281
288
  if (!("vaults" in data)) throw new Error("Invalid callback data");
282
289
  return encodeBuyVaultV1Callback(data);
283
- case CallbackType.SellERC20Callback:
290
+ case Type$1.SellERC20Callback:
284
291
  if (!("collaterals" in data)) throw new Error("Invalid callback data");
285
292
  return encodeSellERC20Callback(data);
286
293
  default: throw new Error("Invalid callback type");
287
294
  }
288
295
  }
296
+ /**
297
+ * Decodes BuyERC20 callback data into positions.
298
+ * @param data - The ABI-encoded callback data containing token addresses and amounts.
299
+ * @returns Array of positions with contract address and amount.
300
+ * @throws If data is empty, malformed, or arrays have mismatched lengths.
301
+ */
302
+ function decodeBuyERC20(data) {
303
+ if (!data || data === "0x") throw new Error("Empty callback data");
304
+ let tokens;
305
+ let amounts;
306
+ try {
307
+ [tokens, amounts] = decodeAbiParameters([{ type: "address[]" }, { type: "uint256[]" }], data);
308
+ } catch (_) {
309
+ throw new Error("Invalid BuyERC20 callback data");
310
+ }
311
+ if (tokens.length !== amounts.length) throw new Error("Mismatched array lengths");
312
+ return tokens.map((token, index) => ({
313
+ contract: token,
314
+ amount: amounts[index]
315
+ }));
316
+ }
317
+ /**
318
+ * Encodes BuyERC20 callback parameters into ABI-encoded data.
319
+ * @param parameters - The tokens and amounts to encode.
320
+ * @returns ABI-encoded hex string.
321
+ */
322
+ function encodeBuyERC20(parameters) {
323
+ return encodeAbiParameters([{ type: "address[]" }, { type: "uint256[]" }], [parameters.tokens, parameters.amounts]);
324
+ }
289
325
  function decodeBuyVaultV1Callback(data) {
290
326
  if (!data || data === "0x") throw new Error("Empty callback data");
291
327
  try {
@@ -360,23 +396,23 @@ function atMostOneNonZero(...values) {
360
396
  * // [5]
361
397
  * ```
362
398
  */
363
- function* batch(array, batchSize) {
399
+ function* batch$1(array, batchSize) {
364
400
  for (let i = 0; i < array.length; i += batchSize) yield array.slice(i, i + batchSize);
365
401
  }
366
402
 
367
403
  //#endregion
368
- //#region \0@oxc-project+runtime@0.97.0/helpers/typeof.js
404
+ //#region \0@oxc-project+runtime@0.110.0/helpers/typeof.js
369
405
  function _typeof(o) {
370
406
  "@babel/helpers - typeof";
371
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
372
- return typeof o$1;
373
- } : function(o$1) {
374
- return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
407
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
408
+ return typeof o;
409
+ } : function(o) {
410
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
375
411
  }, _typeof(o);
376
412
  }
377
413
 
378
414
  //#endregion
379
- //#region \0@oxc-project+runtime@0.97.0/helpers/toPrimitive.js
415
+ //#region \0@oxc-project+runtime@0.110.0/helpers/toPrimitive.js
380
416
  function toPrimitive(t, r) {
381
417
  if ("object" != _typeof(t) || !t) return t;
382
418
  var e = t[Symbol.toPrimitive];
@@ -389,14 +425,14 @@ function toPrimitive(t, r) {
389
425
  }
390
426
 
391
427
  //#endregion
392
- //#region \0@oxc-project+runtime@0.97.0/helpers/toPropertyKey.js
428
+ //#region \0@oxc-project+runtime@0.110.0/helpers/toPropertyKey.js
393
429
  function toPropertyKey(t) {
394
430
  var i = toPrimitive(t, "string");
395
431
  return "symbol" == _typeof(i) ? i : i + "";
396
432
  }
397
433
 
398
434
  //#endregion
399
- //#region \0@oxc-project+runtime@0.97.0/helpers/defineProperty.js
435
+ //#region \0@oxc-project+runtime@0.110.0/helpers/defineProperty.js
400
436
  function _defineProperty(e, r, t) {
401
437
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
402
438
  value: t,
@@ -408,7 +444,7 @@ function _defineProperty(e, r, t) {
408
444
 
409
445
  //#endregion
410
446
  //#region src/utils/Errors.ts
411
- var Errors_exports = /* @__PURE__ */ __export({
447
+ var Errors_exports = /* @__PURE__ */ __exportAll({
412
448
  BaseError: () => BaseError,
413
449
  ReorgError: () => ReorgError
414
450
  });
@@ -465,7 +501,7 @@ var ReorgError = class extends BaseError {
465
501
 
466
502
  //#endregion
467
503
  //#region src/core/Chain.ts
468
- var Chain_exports = /* @__PURE__ */ __export({
504
+ var Chain_exports = /* @__PURE__ */ __exportAll({
469
505
  ChainId: () => ChainId,
470
506
  InvalidBatchSizeError: () => InvalidBatchSizeError,
471
507
  InvalidBlockRangeError: () => InvalidBlockRangeError,
@@ -527,7 +563,8 @@ const chains$1 = {
527
563
  address: "0x1897A8997241C1cD4bD0698647e4EB7213535c24",
528
564
  blockCreated: 21439510
529
565
  }
530
- } }
566
+ } },
567
+ callbacks: []
531
568
  }
532
569
  },
533
570
  base: {
@@ -556,7 +593,8 @@ const chains$1 = {
556
593
  address: "0xFf62A7c278C62eD665133147129245053Bbf5918",
557
594
  blockCreated: 23928808
558
595
  }
559
- } }
596
+ } },
597
+ callbacks: []
560
598
  }
561
599
  },
562
600
  "ethereum-virtual-testnet": {
@@ -585,7 +623,8 @@ const chains$1 = {
585
623
  address: "0x1897A8997241C1cD4bD0698647e4EB7213535c24",
586
624
  blockCreated: 21439510
587
625
  }
588
- } }
626
+ } },
627
+ callbacks: []
589
628
  }
590
629
  },
591
630
  anvil: {
@@ -614,7 +653,8 @@ const chains$1 = {
614
653
  address: "0x0000000000000000000000000000000000000000",
615
654
  blockCreated: 0
616
655
  }
617
- } }
656
+ } },
657
+ callbacks: []
618
658
  }
619
659
  }
620
660
  };
@@ -659,7 +699,7 @@ async function* streamLogs(parameters) {
659
699
  if (a.transactionIndex !== b.transactionIndex) return order === "asc" ? a.transactionIndex - b.transactionIndex : b.transactionIndex - a.transactionIndex;
660
700
  return order === "asc" ? a.logIndex - b.logIndex : b.logIndex - a.logIndex;
661
701
  });
662
- for (const logBatch of batch(logs, maxBatchSize)) yield {
702
+ for (const logBatch of batch$1(logs, maxBatchSize)) yield {
663
703
  logs: logBatch,
664
704
  blockNumber: logBatch.length === maxBatchSize ? Number(logBatch[logBatch.length - 1]?.blockNumber) : order === "asc" ? Number(toBlock) : Number(fromBlock)
665
705
  };
@@ -710,10 +750,15 @@ var MissingBlockNumberError = class extends BaseError {
710
750
 
711
751
  //#endregion
712
752
  //#region src/core/ChainRegistry.ts
713
- var ChainRegistry_exports = /* @__PURE__ */ __export({ create: () => create$1 });
714
- function create$1(chains$2) {
753
+ var ChainRegistry_exports = /* @__PURE__ */ __exportAll({ create: () => create$1 });
754
+ /**
755
+ * Creates a chain registry from a list of chains.
756
+ * @param chains - Array of chain objects to register.
757
+ * @returns A registry for looking up chains by ID. {@link ChainRegistry}
758
+ */
759
+ function create$1(chains) {
715
760
  const byId = /* @__PURE__ */ new Map();
716
- for (const chain of chains$2) byId.set(chain.id, chain);
761
+ for (const chain of chains) byId.set(chain.id, chain);
717
762
  return {
718
763
  getById: (chainId) => byId.get(chainId),
719
764
  list: () => Array.from(byId.values())
@@ -722,7 +767,7 @@ function create$1(chains$2) {
722
767
 
723
768
  //#endregion
724
769
  //#region src/utils/Random.ts
725
- var Random_exports = /* @__PURE__ */ __export({
770
+ var Random_exports = /* @__PURE__ */ __exportAll({
726
771
  address: () => address,
727
772
  bool: () => bool,
728
773
  bytes: () => bytes,
@@ -735,16 +780,16 @@ var Random_exports = /* @__PURE__ */ __export({
735
780
  let currentRng = Math.random;
736
781
  const FNV_OFFSET_BASIS = 2166136261;
737
782
  const FNV_PRIME = 16777619;
738
- const hashSeed = (seed$1) => {
739
- let hash$1 = FNV_OFFSET_BASIS;
740
- for (let i = 0; i < seed$1.length; i += 1) {
741
- hash$1 ^= seed$1.charCodeAt(i);
742
- hash$1 = Math.imul(hash$1, FNV_PRIME);
783
+ const hashSeed = (seed) => {
784
+ let hash = FNV_OFFSET_BASIS;
785
+ for (let i = 0; i < seed.length; i += 1) {
786
+ hash ^= seed.charCodeAt(i);
787
+ hash = Math.imul(hash, FNV_PRIME);
743
788
  }
744
- return hash$1 >>> 0;
789
+ return hash >>> 0;
745
790
  };
746
- const createSeededRng = (seed$1) => {
747
- let state = hashSeed(seed$1);
791
+ const createSeededRng = (seed) => {
792
+ let state = hashSeed(seed);
748
793
  return () => {
749
794
  state += 1831565813;
750
795
  let t = Math.imul(state ^ state >>> 15, state | 1);
@@ -755,9 +800,9 @@ const createSeededRng = (seed$1) => {
755
800
  /**
756
801
  * Runs a function with a deterministic RNG derived from the given seed.
757
802
  */
758
- function withSeed(seed$1, fn) {
803
+ function withSeed(seed, fn) {
759
804
  const previous = currentRng;
760
- currentRng = createSeededRng(seed$1);
805
+ currentRng = createSeededRng(seed);
761
806
  try {
762
807
  return fn();
763
808
  } finally {
@@ -767,8 +812,8 @@ function withSeed(seed$1, fn) {
767
812
  /**
768
813
  * Seeds the global RNG for deterministic test runs.
769
814
  */
770
- function seed(seed$1) {
771
- currentRng = createSeededRng(seed$1);
815
+ function seed(seed) {
816
+ currentRng = createSeededRng(seed);
772
817
  }
773
818
  /**
774
819
  * Returns a deterministic random float in [0, 1).
@@ -779,8 +824,8 @@ function float() {
779
824
  /**
780
825
  * Returns a deterministic random integer in [min, maxExclusive).
781
826
  */
782
- function int(maxExclusive, min$1 = 0) {
783
- return Math.floor(float() * (maxExclusive - min$1)) + min$1;
827
+ function int(maxExclusive, min = 0) {
828
+ return Math.floor(float() * (maxExclusive - min)) + min;
784
829
  }
785
830
  /**
786
831
  * Returns a deterministic random boolean.
@@ -893,12 +938,12 @@ const transformAddress = (val, ctx) => {
893
938
 
894
939
  //#endregion
895
940
  //#region src/core/LLTV.ts
896
- var LLTV_exports = /* @__PURE__ */ __export({
941
+ var LLTV_exports = /* @__PURE__ */ __exportAll({
897
942
  InvalidLLTVError: () => InvalidLLTVError,
898
943
  InvalidOptionError: () => InvalidOptionError$1,
899
944
  LLTVSchema: () => LLTVSchema,
900
945
  Options: () => Options,
901
- from: () => from$12
946
+ from: () => from$13
902
947
  });
903
948
  const Options = [
904
949
  .385,
@@ -917,7 +962,7 @@ const LLTV_SCALED = Options.map((lltv) => BigInt(lltv * 10 ** 18));
917
962
  * @param lltv - The LLTV option or the scaled LLTV.
918
963
  * @returns The LLTV.
919
964
  */
920
- function from$12(lltv) {
965
+ function from$13(lltv) {
921
966
  if (typeof lltv === "bigint" && !LLTV_SCALED.includes(lltv)) throw new InvalidLLTVError(lltv);
922
967
  if (typeof lltv === "bigint") return lltv;
923
968
  if (typeof lltv === "number" && !Options.includes(lltv)) throw new InvalidOptionError$1(lltv);
@@ -937,21 +982,21 @@ var InvalidLLTVError = class extends BaseError {
937
982
  };
938
983
  const LLTVSchema = z$1.bigint({ coerce: true }).refine((lltv) => {
939
984
  try {
940
- from$12(lltv);
985
+ from$13(lltv);
941
986
  return true;
942
987
  } catch (_) {
943
988
  return false;
944
989
  }
945
990
  }, { error: () => {
946
991
  return "Invalid LLTV: must be one of 0.385, 0.625, 0.77, 0.86, 0.915, 0.945, 0.965 or 0.98 (scaled by 1e18)";
947
- } }).transform((lltv) => from$12(lltv));
992
+ } }).transform((lltv) => from$13(lltv));
948
993
 
949
994
  //#endregion
950
995
  //#region src/core/Collateral.ts
951
- var Collateral_exports = /* @__PURE__ */ __export({
996
+ var Collateral_exports = /* @__PURE__ */ __exportAll({
952
997
  CollateralSchema: () => CollateralSchema,
953
998
  CollateralsSchema: () => CollateralsSchema,
954
- from: () => from$11,
999
+ from: () => from$12,
955
1000
  random: () => random$3
956
1001
  });
957
1002
  const CollateralSchema = z$1.object({
@@ -971,10 +1016,10 @@ const CollateralsSchema = z$1.array(CollateralSchema).min(1, { message: "At leas
971
1016
  }
972
1017
  return true;
973
1018
  }, { message: "Collaterals must not contain duplicate assets" });
974
- const from$11 = (parameters) => {
1019
+ const from$12 = (parameters) => {
975
1020
  return {
976
1021
  asset: parameters.asset.toLowerCase(),
977
- lltv: from$12(parameters.lltv),
1022
+ lltv: from$13(parameters.lltv),
978
1023
  oracle: parameters.oracle.toLowerCase()
979
1024
  };
980
1025
  };
@@ -988,7 +1033,7 @@ const from$11 = (parameters) => {
988
1033
  * ```
989
1034
  */
990
1035
  function random$3() {
991
- return from$11({
1036
+ return from$12({
992
1037
  asset: address(),
993
1038
  oracle: address(),
994
1039
  lltv: .965
@@ -997,7 +1042,7 @@ function random$3() {
997
1042
 
998
1043
  //#endregion
999
1044
  //#region src/core/ERC4626.ts
1000
- var ERC4626_exports = /* @__PURE__ */ __export({
1045
+ var ERC4626_exports = /* @__PURE__ */ __exportAll({
1001
1046
  DenominatorIsZeroError: () => DenominatorIsZeroError,
1002
1047
  convertToAssets: () => convertToAssets,
1003
1048
  convertToShares: () => convertToShares,
@@ -1060,7 +1105,7 @@ var DenominatorIsZeroError = class extends BaseError {
1060
1105
 
1061
1106
  //#endregion
1062
1107
  //#region src/core/Liquidity.ts
1063
- var Liquidity_exports = /* @__PURE__ */ __export({
1108
+ var Liquidity_exports = /* @__PURE__ */ __exportAll({
1064
1109
  calculateMaxDebt: () => calculateMaxDebt,
1065
1110
  generateAllowancePoolId: () => generateAllowancePoolId,
1066
1111
  generateBalancePoolId: () => generateBalancePoolId,
@@ -1086,23 +1131,23 @@ function calculateMaxDebt(amount, oraclePrice, lltv) {
1086
1131
  * Generate pool ID for balance pools.
1087
1132
  */
1088
1133
  function generateBalancePoolId(parameters) {
1089
- const { user, chainId, token: token$1 } = parameters;
1090
- return `${user}-${chainId.toString()}-${token$1}-balance`.toLowerCase();
1134
+ const { user, chainId, token } = parameters;
1135
+ return `${user}-${chainId.toString()}-${token}-balance`.toLowerCase();
1091
1136
  }
1092
1137
  /**
1093
1138
  * Generate pool ID for allowance pools.
1094
1139
  */
1095
1140
  function generateAllowancePoolId(parameters) {
1096
- const { user, chainId, token: token$1 } = parameters;
1097
- return `${user}-${chainId.toString()}-${token$1}-allowance`.toLowerCase();
1141
+ const { user, chainId, token } = parameters;
1142
+ return `${user}-${chainId.toString()}-${token}-allowance`.toLowerCase();
1098
1143
  }
1099
1144
  /**
1100
1145
  * Generate pool ID for sell ERC20 callback pools.
1101
1146
  * Each offer has its own callback pool to prevent liquidity conflicts.
1102
1147
  */
1103
1148
  function generateSellERC20CallbackPoolId(parameters) {
1104
- const { user, chainId, obligationId: obligationId$1, token: token$1, offerHash } = parameters;
1105
- return `${user}-${chainId.toString()}-${obligationId$1}-${token$1}-${offerHash}-sell_erc20_callback`.toLowerCase();
1149
+ const { user, chainId, obligationId, token, offerHash } = parameters;
1150
+ return `${user}-${chainId.toString()}-${obligationId}-${token}-${offerHash}-sell_erc20_callback`.toLowerCase();
1106
1151
  }
1107
1152
  /**
1108
1153
  * Generate pool ID for obligation collateral pools.
@@ -1110,22 +1155,22 @@ function generateSellERC20CallbackPoolId(parameters) {
1110
1155
  * These pools are shared across all offers with the same obligation.
1111
1156
  */
1112
1157
  function generateObligationCollateralPoolId(parameters) {
1113
- const { user, chainId, obligationId: obligationId$1, token: token$1 } = parameters;
1114
- return `${user}-${chainId.toString()}-${obligationId$1}-${token$1}-obligation-collateral`.toLowerCase();
1158
+ const { user, chainId, obligationId, token } = parameters;
1159
+ return `${user}-${chainId.toString()}-${obligationId}-${token}-obligation-collateral`.toLowerCase();
1115
1160
  }
1116
1161
  /**
1117
1162
  * Generate pool ID for buy vault callback pools.
1118
1163
  */
1119
1164
  function generateBuyVaultCallbackPoolId(parameters) {
1120
1165
  const { user, chainId, vault, offerHash } = parameters;
1121
- return `${user}-${chainId.toString()}-${vault}-${offerHash}-${CallbackType.BuyVaultV1Callback}`.toLowerCase();
1166
+ return `${user}-${chainId.toString()}-${vault}-${offerHash}-${Type$1.BuyVaultV1Callback}`.toLowerCase();
1122
1167
  }
1123
1168
  /**
1124
1169
  * Generate pool ID for debt pools.
1125
1170
  */
1126
1171
  function generateDebtPoolId(parameters) {
1127
- const { user, chainId, obligationId: obligationId$1 } = parameters;
1128
- return `${user}-${chainId.toString()}-${obligationId$1}-debt`.toLowerCase();
1172
+ const { user, chainId, obligationId } = parameters;
1173
+ return `${user}-${chainId.toString()}-${obligationId}-debt`.toLowerCase();
1129
1174
  }
1130
1175
  /**
1131
1176
  * Generate pool ID for user position in a vault.
@@ -1151,17 +1196,17 @@ function generateMarketLiquidityPoolId(parameters) {
1151
1196
 
1152
1197
  //#endregion
1153
1198
  //#region src/core/Maturity.ts
1154
- var Maturity_exports = /* @__PURE__ */ __export({
1199
+ var Maturity_exports = /* @__PURE__ */ __exportAll({
1155
1200
  InvalidDateError: () => InvalidDateError,
1156
1201
  InvalidFormatError: () => InvalidFormatError,
1157
1202
  InvalidOptionError: () => InvalidOptionError,
1158
1203
  MaturitySchema: () => MaturitySchema,
1159
1204
  MaturityType: () => MaturityType,
1160
- from: () => from$10
1205
+ from: () => from$11
1161
1206
  });
1162
- const MaturitySchema = z$1.number().int().refine((maturity$1) => {
1207
+ const MaturitySchema = z$1.number().int().refine((maturity) => {
1163
1208
  try {
1164
- from$10(maturity$1);
1209
+ from$11(maturity);
1165
1210
  return true;
1166
1211
  } catch (_e) {
1167
1212
  return false;
@@ -1172,15 +1217,15 @@ const MaturitySchema = z$1.number().int().refine((maturity$1) => {
1172
1217
  } catch (_) {
1173
1218
  return `The maturity is set to ${issue.input}. It must fall on the allowed settlement cycles (Friday 15:00 UTC at the end of week/month/quarter).`;
1174
1219
  }
1175
- } }).transform((maturity$1) => maturity$1);
1176
- let MaturityType = /* @__PURE__ */ function(MaturityType$1) {
1177
- MaturityType$1["EndOfWeek"] = "end_of_week";
1178
- MaturityType$1["EndOfNextWeek"] = "end_of_next_week";
1179
- MaturityType$1["EndOfMonth"] = "end_of_month";
1180
- MaturityType$1["EndOfNextMonth"] = "end_of_next_month";
1181
- MaturityType$1["EndOfQuarter"] = "end_of_quarter";
1182
- MaturityType$1["EndOfNextQuarter"] = "end_of_next_quarter";
1183
- return MaturityType$1;
1220
+ } }).transform((maturity) => maturity);
1221
+ let MaturityType = /* @__PURE__ */ function(MaturityType) {
1222
+ MaturityType["EndOfWeek"] = "end_of_week";
1223
+ MaturityType["EndOfNextWeek"] = "end_of_next_week";
1224
+ MaturityType["EndOfMonth"] = "end_of_month";
1225
+ MaturityType["EndOfNextMonth"] = "end_of_next_month";
1226
+ MaturityType["EndOfQuarter"] = "end_of_quarter";
1227
+ MaturityType["EndOfNextQuarter"] = "end_of_next_quarter";
1228
+ return MaturityType;
1184
1229
  }({});
1185
1230
  const MaturityOptions = {
1186
1231
  end_of_week: () => endOfWeek(),
@@ -1196,7 +1241,7 @@ const MaturityOptions = {
1196
1241
  * @throws {InvalidDateError} If the maturity is in seconds but not a valid date.
1197
1242
  * @throws {InvalidOptionError} If the maturity is not a valid option.
1198
1243
  */
1199
- function from$10(ts) {
1244
+ function from$11(ts) {
1200
1245
  if (typeof ts === "string") {
1201
1246
  if (ts in MaturityOptions) return MaturityOptions[ts]();
1202
1247
  throw new InvalidOptionError(ts);
@@ -1214,23 +1259,23 @@ const endOfNextWeek = () => fridayOfWeek(1);
1214
1259
  * on that Friday), roll to the next month's last Friday.
1215
1260
  */
1216
1261
  const endOfMonth = () => {
1217
- const now$1 = /* @__PURE__ */ new Date();
1218
- const year = now$1.getUTCFullYear();
1219
- const month = now$1.getUTCMonth();
1220
- const endOfMonth$1 = lastFridayOfMonth(year, month);
1221
- if (now$1.getTime() > endOfMonth$1 * 1e3) return lastFridayOfMonth(year, month + 1);
1222
- return endOfMonth$1;
1262
+ const now = /* @__PURE__ */ new Date();
1263
+ const year = now.getUTCFullYear();
1264
+ const month = now.getUTCMonth();
1265
+ const endOfMonth = lastFridayOfMonth(year, month);
1266
+ if (now.getTime() > endOfMonth * 1e3) return lastFridayOfMonth(year, month + 1);
1267
+ return endOfMonth;
1223
1268
  };
1224
1269
  /** Returns the end of the next month (last friday of the next month at 15:00:00 UTC)
1225
1270
  * Business rule: if we are after the last Friday of the current month (strictly after 15:00 UTC
1226
1271
  * on that Friday), we consider being in the next month already, so "next month" becomes month+2.
1227
1272
  */
1228
1273
  const endOfNextMonth = () => {
1229
- const now$1 = /* @__PURE__ */ new Date();
1230
- const year = now$1.getUTCFullYear();
1231
- const month = now$1.getUTCMonth();
1232
- const endOfMonth$1 = lastFridayOfMonth(year, month);
1233
- if (now$1.getTime() > endOfMonth$1 * 1e3) return lastFridayOfMonth(year, month + 2);
1274
+ const now = /* @__PURE__ */ new Date();
1275
+ const year = now.getUTCFullYear();
1276
+ const month = now.getUTCMonth();
1277
+ const endOfMonth = lastFridayOfMonth(year, month);
1278
+ if (now.getTime() > endOfMonth * 1e3) return lastFridayOfMonth(year, month + 2);
1234
1279
  return lastFridayOfMonth(year, month + 1);
1235
1280
  };
1236
1281
  /** Returns the end of the current quarter (last friday of the quarter at 15:00:00 UTC) */
@@ -1238,10 +1283,10 @@ const endOfQuarter = () => lastFridayOfQuarter(0);
1238
1283
  /** Returns the end of the next quarter (last friday of the next quarter at 15:00:00 UTC) */
1239
1284
  const endOfNextQuarter = () => lastFridayOfQuarter(1);
1240
1285
  const fridayOfWeek = (weeksAhead = 0) => {
1241
- const now$1 = /* @__PURE__ */ new Date();
1242
- const today15H = new Date(Date.UTC(now$1.getUTCFullYear(), now$1.getUTCMonth(), now$1.getUTCDate(), 15));
1286
+ const now = /* @__PURE__ */ new Date();
1287
+ const today15H = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), 15));
1243
1288
  let daysUntilFriday = (5 - today15H.getUTCDay() + 7) % 7;
1244
- if (daysUntilFriday === 0 && now$1.getTime() >= today15H.getTime()) daysUntilFriday = 7;
1289
+ if (daysUntilFriday === 0 && now.getTime() >= today15H.getTime()) daysUntilFriday = 7;
1245
1290
  const friday = new Date(today15H);
1246
1291
  friday.setUTCDate(friday.getUTCDate() + daysUntilFriday + weeksAhead * 7);
1247
1292
  return friday.getTime() / 1e3;
@@ -1252,9 +1297,9 @@ const lastFridayOfMonth = (year, month) => {
1252
1297
  return lastDayOfMonth15H.setUTCDate(lastDayOfMonth15H.getUTCDate()) / 1e3;
1253
1298
  };
1254
1299
  const lastFridayOfQuarter = (quartersAhead = 0) => {
1255
- const now$1 = /* @__PURE__ */ new Date();
1256
- const quarterIndex = Math.floor(now$1.getUTCMonth() / 3) + quartersAhead;
1257
- return lastFridayOfMonth(now$1.getUTCFullYear() + Math.floor(quarterIndex / 4), quarterIndex % 4 * 3 + 2);
1300
+ const now = /* @__PURE__ */ new Date();
1301
+ const quarterIndex = Math.floor(now.getUTCMonth() / 3) + quartersAhead;
1302
+ return lastFridayOfMonth(now.getUTCFullYear() + Math.floor(quarterIndex / 4), quarterIndex % 4 * 3 + 2);
1258
1303
  };
1259
1304
  var InvalidFormatError = class extends BaseError {
1260
1305
  constructor() {
@@ -1277,7 +1322,7 @@ var InvalidOptionError = class extends BaseError {
1277
1322
 
1278
1323
  //#endregion
1279
1324
  //#region src/utils/Format.ts
1280
- var Format_exports = /* @__PURE__ */ __export({
1325
+ var Format_exports = /* @__PURE__ */ __exportAll({
1281
1326
  fromSnakeCase: () => fromSnakeCase$3,
1282
1327
  stringifyBigint: () => stringifyBigint,
1283
1328
  toSnakeCase: () => toSnakeCase$1
@@ -1322,11 +1367,11 @@ function stringifyBigint(value) {
1322
1367
 
1323
1368
  //#endregion
1324
1369
  //#region src/core/Obligation.ts
1325
- var Obligation_exports = /* @__PURE__ */ __export({
1370
+ var Obligation_exports = /* @__PURE__ */ __exportAll({
1326
1371
  CollateralsAreNotSortedError: () => CollateralsAreNotSortedError,
1327
1372
  InvalidObligationError: () => InvalidObligationError,
1328
1373
  ObligationSchema: () => ObligationSchema,
1329
- from: () => from$9,
1374
+ from: () => from$10,
1330
1375
  fromSnakeCase: () => fromSnakeCase$2,
1331
1376
  id: () => id,
1332
1377
  random: () => random$2
@@ -1360,11 +1405,11 @@ const ObligationSchema = z$1.object({
1360
1405
  * });
1361
1406
  * ```
1362
1407
  */
1363
- function from$9(parameters) {
1408
+ function from$10(parameters) {
1364
1409
  try {
1365
1410
  const parsedObligation = ObligationSchema.parse({
1366
1411
  ...parameters,
1367
- maturity: from$10(parameters.maturity)
1412
+ maturity: from$11(parameters.maturity)
1368
1413
  });
1369
1414
  return {
1370
1415
  chainId: parsedObligation.chainId,
@@ -1383,7 +1428,7 @@ function from$9(parameters) {
1383
1428
  * @returns The created obligation. {@link fromSnakeCase.ReturnType}
1384
1429
  */
1385
1430
  function fromSnakeCase$2(input) {
1386
- return from$9(fromSnakeCase$3(input));
1431
+ return from$10(fromSnakeCase$3(input));
1387
1432
  }
1388
1433
  /**
1389
1434
  * Calculates the obligation id based on the smart contract's Obligation struct.
@@ -1448,11 +1493,11 @@ function id(parameters) {
1448
1493
  * ```
1449
1494
  */
1450
1495
  function random$2() {
1451
- return from$9({
1496
+ return from$10({
1452
1497
  chainId: 1,
1453
1498
  loanToken: address(),
1454
1499
  collaterals: [random$3()],
1455
- maturity: from$10("end_of_next_quarter")
1500
+ maturity: from$11("end_of_next_quarter")
1456
1501
  });
1457
1502
  }
1458
1503
  var InvalidObligationError = class extends BaseError {
@@ -1470,7 +1515,7 @@ var CollateralsAreNotSortedError = class extends BaseError {
1470
1515
 
1471
1516
  //#endregion
1472
1517
  //#region src/core/Tree.ts
1473
- var Tree_exports = /* @__PURE__ */ __export({
1518
+ var Tree_exports = /* @__PURE__ */ __exportAll({
1474
1519
  DecodeError: () => DecodeError,
1475
1520
  EncodeError: () => EncodeError,
1476
1521
  TreeError: () => TreeError,
@@ -1478,11 +1523,11 @@ var Tree_exports = /* @__PURE__ */ __export({
1478
1523
  decode: () => decode$1,
1479
1524
  encode: () => encode$1,
1480
1525
  encodeUnsigned: () => encodeUnsigned,
1481
- from: () => from$8,
1526
+ from: () => from$9,
1482
1527
  proofs: () => proofs
1483
1528
  });
1484
1529
  const VERSION = 1;
1485
- const normalizeHash = (hash$1) => hash$1.toLowerCase();
1530
+ const normalizeHash = (hash) => hash.toLowerCase();
1486
1531
  /**
1487
1532
  * Builds a Merkle tree from a list of offers.
1488
1533
  *
@@ -1494,7 +1539,7 @@ const normalizeHash = (hash$1) => hash$1.toLowerCase();
1494
1539
  * @returns A `StandardMerkleTree` of `bytes32` leaves representing the offers.
1495
1540
  * @throws {TreeError} If tree building fails due to offer inconsistencies.
1496
1541
  */
1497
- const from$8 = (offers) => {
1542
+ const from$9 = (offers) => {
1498
1543
  const leaves = offers.map((offer) => [hash(offer)]);
1499
1544
  const tree = StandardMerkleTree.of(leaves, ["bytes32"]);
1500
1545
  const orderedOffers = orderOffers(tree, offers);
@@ -1504,9 +1549,9 @@ const orderOffers = (tree, offers) => {
1504
1549
  const offerByHash = /* @__PURE__ */ new Map();
1505
1550
  for (const offer of offers) offerByHash.set(normalizeHash(hash(offer)), offer);
1506
1551
  const entries = tree.dump().values.map((value) => {
1507
- const hash$1 = normalizeHash(value.value[0]);
1508
- const offer = offerByHash.get(hash$1);
1509
- if (!offer) throw new TreeError(`missing offer for leaf ${hash$1}`);
1552
+ const hash = normalizeHash(value.value[0]);
1553
+ const offer = offerByHash.get(hash);
1554
+ if (!offer) throw new TreeError(`missing offer for leaf ${hash}`);
1510
1555
  return {
1511
1556
  offer,
1512
1557
  treeIndex: value.treeIndex
@@ -1539,10 +1584,10 @@ const assertHex = (value, expectedBytes, name) => {
1539
1584
  const verifySignatureAndRecoverAddress = async (params) => {
1540
1585
  const { root, signature } = params;
1541
1586
  assertHex(signature, 65, "signature");
1542
- const hash$1 = hashMessage({ raw: root });
1587
+ const hash = hashMessage({ raw: root });
1543
1588
  try {
1544
1589
  return await recoverAddress({
1545
- hash: hash$1,
1590
+ hash,
1546
1591
  signature
1547
1592
  });
1548
1593
  } catch {
@@ -1616,7 +1661,7 @@ const encodeUnsigned = (tree) => {
1616
1661
  };
1617
1662
  const validateTreeForEncoding = (tree) => {
1618
1663
  if (VERSION > 255) throw new EncodeError(`version overflow: ${VERSION} exceeds 255`);
1619
- const computed = from$8(tree.offers);
1664
+ const computed = from$9(tree.offers);
1620
1665
  if (tree.root !== computed.root) throw new EncodeError(`root mismatch: expected ${computed.root}, got ${tree.root}`);
1621
1666
  };
1622
1667
  const encodeUnsignedBytes = (tree) => {
@@ -1652,19 +1697,19 @@ const encodeUnsignedBytes = (tree) => {
1652
1697
  * @throws {DecodeError} If version invalid, signature invalid, or root mismatch
1653
1698
  */
1654
1699
  const decode$1 = async (encoded) => {
1655
- const bytes$1 = hexToBytes(encoded);
1656
- if (bytes$1.length < 98) throw new DecodeError("payload too short");
1657
- const version = bytes$1[0];
1700
+ const bytes = hexToBytes(encoded);
1701
+ if (bytes.length < 98) throw new DecodeError("payload too short");
1702
+ const version = bytes[0];
1658
1703
  if (version !== (VERSION & 255)) throw new DecodeError(`invalid version: expected ${VERSION}, got ${version ?? 0}`);
1659
- const signature = bytesToHex(bytes$1.slice(-65));
1660
- const root = bytesToHex(bytes$1.slice(-97, -65));
1704
+ const signature = bytesToHex(bytes.slice(-65));
1705
+ const root = bytesToHex(bytes.slice(-97, -65));
1661
1706
  assertHex(root, 32, "root");
1662
1707
  assertHex(signature, 65, "signature");
1663
1708
  const signer = await verifySignatureAndRecoverAddress({
1664
1709
  root,
1665
1710
  signature
1666
1711
  });
1667
- const compressed = bytes$1.slice(1, -97);
1712
+ const compressed = bytes.slice(1, -97);
1668
1713
  let decoded;
1669
1714
  try {
1670
1715
  decoded = ungzip(compressed, { to: "string" });
@@ -1677,7 +1722,7 @@ const decode$1 = async (encoded) => {
1677
1722
  } catch {
1678
1723
  throw new DecodeError("JSON parse failed");
1679
1724
  }
1680
- const tree = from$8(rawOffers.map((o) => OfferSchema().parse(o)));
1725
+ const tree = from$9(rawOffers.map((o) => OfferSchema().parse(o)));
1681
1726
  if (root !== tree.root) throw new DecodeError(`root mismatch: expected ${tree.root}, got ${root}`);
1682
1727
  return {
1683
1728
  tree,
@@ -1718,7 +1763,7 @@ var DecodeError = class extends BaseError {
1718
1763
 
1719
1764
  //#endregion
1720
1765
  //#region src/core/Offer.ts
1721
- var Offer_exports = /* @__PURE__ */ __export({
1766
+ var Offer_exports = /* @__PURE__ */ __exportAll({
1722
1767
  AccountNotSetError: () => AccountNotSetError,
1723
1768
  InvalidOfferError: () => InvalidOfferError,
1724
1769
  OfferSchema: () => OfferSchema,
@@ -1727,7 +1772,7 @@ var Offer_exports = /* @__PURE__ */ __export({
1727
1772
  decode: () => decode,
1728
1773
  domain: () => domain,
1729
1774
  encode: () => encode,
1730
- from: () => from$7,
1775
+ from: () => from$8,
1731
1776
  fromSnakeCase: () => fromSnakeCase$1,
1732
1777
  hash: () => hash,
1733
1778
  obligationId: () => obligationId,
@@ -1740,10 +1785,10 @@ var Offer_exports = /* @__PURE__ */ __export({
1740
1785
  });
1741
1786
  /** Internal symbol for caching the computed hash. */
1742
1787
  const HASH_CACHE = Symbol("offer.hash");
1743
- let Status = /* @__PURE__ */ function(Status$1) {
1744
- Status$1["VALID"] = "VALID";
1745
- Status$1["SIMULATION_ERROR"] = "SIMULATION_ERROR";
1746
- return Status$1;
1788
+ let Status = /* @__PURE__ */ function(Status) {
1789
+ Status["VALID"] = "VALID";
1790
+ Status["SIMULATION_ERROR"] = "SIMULATION_ERROR";
1791
+ return Status;
1747
1792
  }({});
1748
1793
  const OfferSchema = () => {
1749
1794
  return z$1.object({
@@ -1787,7 +1832,7 @@ const OfferSchema = () => {
1787
1832
  * @param input - The offer to create.
1788
1833
  * @returns The created offer.
1789
1834
  */
1790
- function from$7(input) {
1835
+ function from$8(input) {
1791
1836
  try {
1792
1837
  return OfferSchema().parse(input);
1793
1838
  } catch (error) {
@@ -1801,7 +1846,7 @@ function from$7(input) {
1801
1846
  * @returns The created offer.
1802
1847
  */
1803
1848
  function fromSnakeCase$1(input) {
1804
- return from$7(fromSnakeCase$3(input));
1849
+ return from$8(fromSnakeCase$3(input));
1805
1850
  }
1806
1851
  /**
1807
1852
  * Converts an offer to a snake case object.
@@ -1855,8 +1900,8 @@ function random$1(config) {
1855
1900
  const collateralCandidates = config?.collateralTokens ? config.collateralTokens.filter((a) => a !== loanToken) : [address()];
1856
1901
  const collateralAsset = collateralCandidates[int(collateralCandidates.length)];
1857
1902
  const maturityOption = weightedChoice([["end_of_month", 1], ["end_of_next_month", 1]]);
1858
- const maturity$1 = config?.maturity ?? from$10(maturityOption);
1859
- const lltv = from$12(weightedChoice([
1903
+ const maturity = config?.maturity ?? from$11(maturityOption);
1904
+ const lltv = from$13(weightedChoice([
1860
1905
  [.385, 1],
1861
1906
  [.5, 1],
1862
1907
  [.625, 2],
@@ -1895,15 +1940,15 @@ function random$1(config) {
1895
1940
  })
1896
1941
  };
1897
1942
  })();
1898
- return from$7({
1943
+ return from$8({
1899
1944
  maker: config?.maker ?? address(),
1900
1945
  assets: assetsScaled,
1901
1946
  obligationUnits: config?.obligationUnits ?? 0n,
1902
1947
  obligationShares: config?.obligationShares ?? 0n,
1903
1948
  price,
1904
- maturity: maturity$1,
1905
- expiry: config?.expiry ?? maturity$1 - 1,
1906
- start: config?.start ?? maturity$1 - 10,
1949
+ maturity,
1950
+ expiry: config?.expiry ?? maturity - 1,
1951
+ start: config?.start ?? maturity - 10,
1907
1952
  group: config?.group ?? hex(32),
1908
1953
  session: config?.session ?? hex(32),
1909
1954
  buy,
@@ -2038,7 +2083,7 @@ async function sign(offers, wallet) {
2038
2083
  });
2039
2084
  }
2040
2085
  function signatureMsg(offers) {
2041
- return from$8(offers).root;
2086
+ return from$9(offers).root;
2042
2087
  }
2043
2088
  function hash(offer) {
2044
2089
  const cached = offer[HASH_CACHE];
@@ -2076,7 +2121,7 @@ function hash(offer) {
2076
2121
  * @returns The obligation id as a 32-byte hex string.
2077
2122
  */
2078
2123
  function obligationId(offer) {
2079
- return id(from$9({
2124
+ return id(from$10({
2080
2125
  chainId: offer.chainId,
2081
2126
  loanToken: offer.loanToken,
2082
2127
  collaterals: offer.collaterals,
@@ -2192,13 +2237,13 @@ function decode(data) {
2192
2237
  } catch (error) {
2193
2238
  throw new InvalidOfferError(error);
2194
2239
  }
2195
- return from$7({
2240
+ return from$8({
2196
2241
  maker: decoded[0],
2197
2242
  assets: decoded[1],
2198
2243
  obligationUnits: decoded[2],
2199
2244
  obligationShares: decoded[3],
2200
2245
  price: decoded[4],
2201
- maturity: from$10(Number(decoded[5])),
2246
+ maturity: from$11(Number(decoded[5])),
2202
2247
  expiry: Number(decoded[6]),
2203
2248
  group: decoded[7],
2204
2249
  session: decoded[8],
@@ -2207,7 +2252,7 @@ function decode(data) {
2207
2252
  loanToken: decoded[11],
2208
2253
  start: Number(decoded[12]),
2209
2254
  collaterals: decoded[13].map((c) => {
2210
- return from$11({
2255
+ return from$12({
2211
2256
  asset: c.asset,
2212
2257
  oracle: c.oracle,
2213
2258
  lltv: c.lltv
@@ -2280,16 +2325,16 @@ var AccountNotSetError = class extends BaseError {
2280
2325
 
2281
2326
  //#endregion
2282
2327
  //#region src/core/Oracle.ts
2283
- var Oracle_exports = /* @__PURE__ */ __export({
2328
+ var Oracle_exports = /* @__PURE__ */ __exportAll({
2284
2329
  Conversion: () => Conversion,
2285
- from: () => from$6
2330
+ from: () => from$7
2286
2331
  });
2287
2332
  /**
2288
2333
  * Create an Oracle from a plain object.
2289
2334
  * @param data - The data to create the oracle from.
2290
2335
  * @returns The created oracle.
2291
2336
  */
2292
- function from$6(data) {
2337
+ function from$7(data) {
2293
2338
  return {
2294
2339
  chainId: data.chainId,
2295
2340
  address: data.address.toLowerCase(),
@@ -2312,14 +2357,14 @@ let Conversion;
2312
2357
 
2313
2358
  //#endregion
2314
2359
  //#region src/core/Position.ts
2315
- var Position_exports = /* @__PURE__ */ __export({
2360
+ var Position_exports = /* @__PURE__ */ __exportAll({
2316
2361
  Type: () => Type,
2317
- from: () => from$5
2362
+ from: () => from$6
2318
2363
  });
2319
- let Type = /* @__PURE__ */ function(Type$1) {
2320
- Type$1["ERC20"] = "erc20";
2321
- Type$1["VAULT_V1"] = "vault_v1";
2322
- return Type$1;
2364
+ let Type = /* @__PURE__ */ function(Type) {
2365
+ Type["ERC20"] = "erc20";
2366
+ Type["VAULT_V1"] = "vault_v1";
2367
+ return Type;
2323
2368
  }({});
2324
2369
  /**
2325
2370
  * @constructor
@@ -2327,7 +2372,7 @@ let Type = /* @__PURE__ */ function(Type$1) {
2327
2372
  * @param parameters - {@link from.Parameters}
2328
2373
  * @returns The created Position. {@link from.ReturnType}
2329
2374
  */
2330
- function from$5(parameters) {
2375
+ function from$6(parameters) {
2331
2376
  return {
2332
2377
  chainId: parameters.chainId,
2333
2378
  contract: parameters.contract.toLowerCase(),
@@ -2341,10 +2386,10 @@ function from$5(parameters) {
2341
2386
 
2342
2387
  //#endregion
2343
2388
  //#region src/core/Quote.ts
2344
- var Quote_exports = /* @__PURE__ */ __export({
2389
+ var Quote_exports = /* @__PURE__ */ __exportAll({
2345
2390
  InvalidQuoteError: () => InvalidQuoteError,
2346
2391
  QuoteSchema: () => QuoteSchema,
2347
- from: () => from$4,
2392
+ from: () => from$5,
2348
2393
  fromSnakeCase: () => fromSnakeCase,
2349
2394
  random: () => random
2350
2395
  });
@@ -2365,7 +2410,7 @@ const QuoteSchema = z$1.object({
2365
2410
  * const quote = Quote.from({ obligationId: "0x123", ask: { price: 100n }, bid: { price: 100n } });
2366
2411
  * ```
2367
2412
  */
2368
- function from$4(parameters) {
2413
+ function from$5(parameters) {
2369
2414
  try {
2370
2415
  const parsedQuote = QuoteSchema.parse(parameters);
2371
2416
  return {
@@ -2384,7 +2429,7 @@ function from$4(parameters) {
2384
2429
  * @returns The created quote. {@link fromSnakeCase.ReturnType}
2385
2430
  */
2386
2431
  function fromSnakeCase(snake) {
2387
- return from$4(fromSnakeCase$3(snake));
2432
+ return from$5(fromSnakeCase$3(snake));
2388
2433
  }
2389
2434
  /**
2390
2435
  * Generates a random quote.
@@ -2396,7 +2441,7 @@ function fromSnakeCase(snake) {
2396
2441
  * ```
2397
2442
  */
2398
2443
  function random() {
2399
- return from$4({
2444
+ return from$5({
2400
2445
  obligationId: id(random$2()),
2401
2446
  ask: { price: BigInt(int(1e6)) },
2402
2447
  bid: { price: BigInt(int(1e6)) }
@@ -2409,9 +2454,158 @@ var InvalidQuoteError = class extends BaseError {
2409
2454
  }
2410
2455
  };
2411
2456
 
2457
+ //#endregion
2458
+ //#region src/core/TradingFee.ts
2459
+ var TradingFee_exports = /* @__PURE__ */ __exportAll({
2460
+ BREAKPOINTS: () => BREAKPOINTS,
2461
+ InvalidFeeError: () => InvalidFeeError,
2462
+ InvalidFeesLengthError: () => InvalidFeesLengthError,
2463
+ WAD: () => WAD,
2464
+ activate: () => activate,
2465
+ compute: () => compute,
2466
+ deactivate: () => deactivate,
2467
+ from: () => from$4,
2468
+ getFees: () => getFees,
2469
+ isActivated: () => isActivated
2470
+ });
2471
+ /**
2472
+ * Time breakpoints in seconds for piecewise linear fee interpolation.
2473
+ * Matches on-chain constants: 0d, 1d, 7d, 30d, 90d, 180d.
2474
+ */
2475
+ const BREAKPOINTS = [
2476
+ 0n,
2477
+ 86400n,
2478
+ 604800n,
2479
+ 2592000n,
2480
+ 7776000n,
2481
+ 15552000n
2482
+ ];
2483
+ /** WAD constant (1e18) for fee scaling. */
2484
+ const WAD = 10n ** 18n;
2485
+ /**
2486
+ * Create a TradingFee from an activation flag and 6 fee values.
2487
+ * @param activated - Whether the fee is active.
2488
+ * @param fees - Tuple of 6 fee values in WAD (one per breakpoint: 0d, 1d, 7d, 30d, 90d, 180d).
2489
+ * @returns A new TradingFee instance.
2490
+ * @throws {@link InvalidFeeError} if any fee exceeds WAD (100%).
2491
+ * @throws {@link InvalidFeesLengthError} if fees array doesn't have exactly 6 elements.
2492
+ */
2493
+ function from$4(activated, fees) {
2494
+ if (fees.length !== 6) throw new InvalidFeesLengthError(fees.length);
2495
+ for (let i = 0; i < 6; i++) {
2496
+ const fee = fees[i];
2497
+ if (fee < 0n || fee > WAD) throw new InvalidFeeError(fee, i);
2498
+ }
2499
+ const frozenFees = Object.freeze([...fees]);
2500
+ return Object.freeze({
2501
+ _activated: activated,
2502
+ _fees: frozenFees
2503
+ });
2504
+ }
2505
+ /**
2506
+ * Compute the trading fee for a given time to maturity using piecewise linear interpolation.
2507
+ * @param tradingFee - The TradingFee instance.
2508
+ * @param timeToMaturity - Time to maturity in seconds.
2509
+ * @returns The interpolated fee in WAD. Returns 0n if not activated.
2510
+ */
2511
+ function compute(tradingFee, timeToMaturity) {
2512
+ if (!tradingFee._activated) return 0n;
2513
+ const time = BigInt(Math.max(0, Math.floor(timeToMaturity)));
2514
+ if (time >= BREAKPOINTS[5]) return tradingFee._fees[5];
2515
+ const { index, start, end } = getSegment(time);
2516
+ const feeLower = tradingFee._fees[index];
2517
+ const feeUpper = tradingFee._fees[index + 1];
2518
+ const segmentLength = end - start;
2519
+ return (feeLower * (end - time) + feeUpper * (time - start)) / segmentLength;
2520
+ }
2521
+ /**
2522
+ * Check if the trading fee is activated.
2523
+ * @param tradingFee - The TradingFee instance.
2524
+ * @returns True if activated, false otherwise.
2525
+ */
2526
+ function isActivated(tradingFee) {
2527
+ return tradingFee._activated;
2528
+ }
2529
+ /**
2530
+ * Create a new TradingFee with activation enabled.
2531
+ * @param tradingFee - The TradingFee instance.
2532
+ * @returns A new TradingFee with activated set to true.
2533
+ */
2534
+ function activate(tradingFee) {
2535
+ return Object.freeze({
2536
+ _activated: true,
2537
+ _fees: tradingFee._fees
2538
+ });
2539
+ }
2540
+ /**
2541
+ * Create a new TradingFee with activation disabled.
2542
+ * @param tradingFee - The TradingFee instance.
2543
+ * @returns A new TradingFee with activated set to false.
2544
+ */
2545
+ function deactivate(tradingFee) {
2546
+ return Object.freeze({
2547
+ _activated: false,
2548
+ _fees: tradingFee._fees
2549
+ });
2550
+ }
2551
+ /**
2552
+ * Get the fee values at each breakpoint.
2553
+ * @param tradingFee - The TradingFee instance.
2554
+ * @returns The tuple of 6 fee values.
2555
+ */
2556
+ function getFees(tradingFee) {
2557
+ return tradingFee._fees;
2558
+ }
2559
+ /**
2560
+ * Determine which segment a timeToMaturity falls into for interpolation.
2561
+ * @param timeToMaturity - Time to maturity in seconds.
2562
+ * @returns Object with index, start, and end of the segment.
2563
+ */
2564
+ function getSegment(timeToMaturity) {
2565
+ if (timeToMaturity < BREAKPOINTS[1]) return {
2566
+ index: 0,
2567
+ start: BREAKPOINTS[0],
2568
+ end: BREAKPOINTS[1]
2569
+ };
2570
+ if (timeToMaturity < BREAKPOINTS[2]) return {
2571
+ index: 1,
2572
+ start: BREAKPOINTS[1],
2573
+ end: BREAKPOINTS[2]
2574
+ };
2575
+ if (timeToMaturity < BREAKPOINTS[3]) return {
2576
+ index: 2,
2577
+ start: BREAKPOINTS[2],
2578
+ end: BREAKPOINTS[3]
2579
+ };
2580
+ if (timeToMaturity < BREAKPOINTS[4]) return {
2581
+ index: 3,
2582
+ start: BREAKPOINTS[3],
2583
+ end: BREAKPOINTS[4]
2584
+ };
2585
+ return {
2586
+ index: 4,
2587
+ start: BREAKPOINTS[4],
2588
+ end: BREAKPOINTS[5]
2589
+ };
2590
+ }
2591
+ /** Error thrown when a fee value is invalid (negative or exceeds WAD). */
2592
+ var InvalidFeeError = class extends BaseError {
2593
+ constructor(fee, index) {
2594
+ super(`Invalid fee at index ${index}: ${fee}. Fee must be between 0 and ${WAD} (WAD).`);
2595
+ _defineProperty(this, "name", "TradingFee.InvalidFeeError");
2596
+ }
2597
+ };
2598
+ /** Error thrown when fees array doesn't have exactly 6 elements. */
2599
+ var InvalidFeesLengthError = class extends BaseError {
2600
+ constructor(length) {
2601
+ super(`Invalid fees length: ${length}. Expected exactly 6 fee values.`);
2602
+ _defineProperty(this, "name", "TradingFee.InvalidFeesLengthError");
2603
+ }
2604
+ };
2605
+
2412
2606
  //#endregion
2413
2607
  //#region src/core/Transfer.ts
2414
- var Transfer_exports = /* @__PURE__ */ __export({ from: () => from$3 });
2608
+ var Transfer_exports = /* @__PURE__ */ __exportAll({ from: () => from$3 });
2415
2609
  /**
2416
2610
  * @constructor
2417
2611
  *
@@ -2442,7 +2636,7 @@ const BrandTypeId = Symbol.for("mempool/Brand");
2442
2636
 
2443
2637
  //#endregion
2444
2638
  //#region src/api/Schema/OfferResponse.ts
2445
- var OfferResponse_exports = /* @__PURE__ */ __export({ from: () => from$2 });
2639
+ var OfferResponse_exports = /* @__PURE__ */ __exportAll({ from: () => from$2 });
2446
2640
  /**
2447
2641
  * Creates an `OfferResponse` matching the Solidity Offer struct layout.
2448
2642
  * @constructor
@@ -2450,7 +2644,7 @@ var OfferResponse_exports = /* @__PURE__ */ __export({ from: () => from$2 });
2450
2644
  * @returns The created `OfferResponse`. {@link OfferResponse}
2451
2645
  */
2452
2646
  function from$2(input) {
2453
- const base$1 = {
2647
+ const base = {
2454
2648
  offer: {
2455
2649
  obligation: {
2456
2650
  loan_token: input.loanToken,
@@ -2487,13 +2681,13 @@ function from$2(input) {
2487
2681
  block_number: input.blockNumber
2488
2682
  };
2489
2683
  if (!input.proof || !input.root || !input.signature) return {
2490
- ...base$1,
2684
+ ...base,
2491
2685
  root: null,
2492
2686
  proof: null,
2493
2687
  signature: null
2494
2688
  };
2495
2689
  return {
2496
- ...base$1,
2690
+ ...base,
2497
2691
  root: input.root.toLowerCase(),
2498
2692
  proof: input.proof.map((p) => p.toLowerCase()),
2499
2693
  signature: input.signature.toLowerCase()
@@ -2510,7 +2704,7 @@ const API_ERROR_CODES = [
2510
2704
  ];
2511
2705
 
2512
2706
  //#endregion
2513
- //#region \0@oxc-project+runtime@0.97.0/helpers/decorate.js
2707
+ //#region \0@oxc-project+runtime@0.110.0/helpers/decorate.js
2514
2708
  function __decorate(decorators, target, key, desc) {
2515
2709
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2516
2710
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -3131,7 +3325,7 @@ __decorate([ApiProperty({
3131
3325
  type: () => [BookLevelResponse],
3132
3326
  description: "Aggregated book levels grouped by computed price."
3133
3327
  })], BookListResponse.prototype, "data", void 0);
3134
- let BooksController = class BooksController$1 {
3328
+ let BooksController = class BooksController {
3135
3329
  async getBook() {}
3136
3330
  };
3137
3331
  __decorate([
@@ -3177,7 +3371,7 @@ BooksController = __decorate([ApiTags("Markets"), ApiResponse({
3177
3371
  description: "Bad Request",
3178
3372
  type: BadRequestResponse
3179
3373
  })], BooksController);
3180
- let ValidateController = class ValidateController$1 {
3374
+ let ValidateController = class ValidateController {
3181
3375
  async validateOffers() {}
3182
3376
  };
3183
3377
  __decorate([
@@ -3204,7 +3398,7 @@ ValidateController = __decorate([ApiTags("Make"), ApiResponse({
3204
3398
  description: "Bad Request",
3205
3399
  type: BadRequestResponse
3206
3400
  })], ValidateController);
3207
- let OffersController = class OffersController$1 {
3401
+ let OffersController = class OffersController {
3208
3402
  async getOffers() {}
3209
3403
  };
3210
3404
  __decorate([
@@ -3259,7 +3453,7 @@ OffersController = __decorate([ApiTags("Markets"), ApiResponse({
3259
3453
  description: "Bad Request",
3260
3454
  type: BadRequestResponse
3261
3455
  })], OffersController);
3262
- let HealthController = class HealthController$1 {
3456
+ let HealthController = class HealthController {
3263
3457
  async getRouterStatus() {}
3264
3458
  async getCollectorsHealth() {}
3265
3459
  async getChainsHealth() {}
@@ -3325,31 +3519,17 @@ __decorate([
3325
3519
  })
3326
3520
  ], HealthController.prototype, "getChainsHealth", null);
3327
3521
  HealthController = __decorate([ApiTags("System")], HealthController);
3328
- const maturitiesExample = {
3329
- end_of_month: 1738335600,
3330
- end_of_next_month: 1740754800
3331
- };
3522
+ const callbacksExample = [Type$1.BuyWithEmptyCallback];
3332
3523
  const chainConfigExample = {
3333
3524
  chain_id: 505050505,
3334
3525
  contracts: { mempool: "0xD946246695A9259F3B33a78629026F61B3Ab40aF" },
3335
- maturities: maturitiesExample
3526
+ callbacks: callbacksExample
3336
3527
  };
3337
3528
  var ConfigContractsResponse = class {};
3338
3529
  __decorate([ApiProperty({
3339
3530
  type: "string",
3340
3531
  example: chainConfigExample.contracts.mempool
3341
3532
  })], ConfigContractsResponse.prototype, "mempool", void 0);
3342
- var MaturitiesResponse = class {};
3343
- __decorate([ApiProperty({
3344
- type: "number",
3345
- description: "Unix timestamp for end of current month maturity (last Friday 15:00 UTC).",
3346
- example: maturitiesExample.end_of_month
3347
- })], MaturitiesResponse.prototype, "end_of_month", void 0);
3348
- __decorate([ApiProperty({
3349
- type: "number",
3350
- description: "Unix timestamp for end of next month maturity (last Friday 15:00 UTC).",
3351
- example: maturitiesExample.end_of_next_month
3352
- })], MaturitiesResponse.prototype, "end_of_next_month", void 0);
3353
3533
  var ConfigDataResponse = class {};
3354
3534
  __decorate([ApiProperty({
3355
3535
  type: "number",
@@ -3357,10 +3537,11 @@ __decorate([ApiProperty({
3357
3537
  })], ConfigDataResponse.prototype, "chain_id", void 0);
3358
3538
  __decorate([ApiProperty({ type: () => ConfigContractsResponse })], ConfigDataResponse.prototype, "contracts", void 0);
3359
3539
  __decorate([ApiProperty({
3360
- type: () => MaturitiesResponse,
3361
- description: "Supported maturity timestamps. Offers must use one of these values.",
3362
- example: chainConfigExample.maturities
3363
- })], ConfigDataResponse.prototype, "maturities", void 0);
3540
+ type: () => [String],
3541
+ enum: Object.values(Type$1),
3542
+ description: "Supported callback types for this chain.",
3543
+ example: callbacksExample
3544
+ })], ConfigDataResponse.prototype, "callbacks", void 0);
3364
3545
  var ConfigSuccessResponse = class extends SuccessResponse {};
3365
3546
  __decorate([ApiProperty({
3366
3547
  type: "string",
@@ -3372,21 +3553,21 @@ __decorate([ApiProperty({
3372
3553
  description: "Array of chain configurations for all indexed chains.",
3373
3554
  example: [chainConfigExample]
3374
3555
  })], ConfigSuccessResponse.prototype, "data", void 0);
3375
- let ConfigController = class ConfigController$1 {
3556
+ let ConfigController = class ConfigController {
3376
3557
  async getConfig() {}
3377
3558
  };
3378
3559
  __decorate([ApiOperation({
3379
3560
  methods: ["get"],
3380
3561
  path: "/v1/config",
3381
3562
  summary: "Get router configuration",
3382
- description: "Returns chain configurations including contract addresses and supported maturity timestamps."
3563
+ description: "Returns chain configurations including contract addresses and supported callback types."
3383
3564
  }), ApiResponse({
3384
3565
  status: 200,
3385
3566
  description: "Success",
3386
3567
  type: ConfigSuccessResponse
3387
3568
  })], ConfigController.prototype, "getConfig", null);
3388
3569
  ConfigController = __decorate([ApiTags("System")], ConfigController);
3389
- let ObligationsController = class ObligationsController$1 {
3570
+ let ObligationsController = class ObligationsController {
3390
3571
  async getObligations() {}
3391
3572
  async getObligation() {}
3392
3573
  };
@@ -3410,32 +3591,40 @@ __decorate([
3410
3591
  description: "Maximum number of obligations to return."
3411
3592
  }),
3412
3593
  ApiQuery({
3413
- name: "chain",
3414
- type: "number",
3594
+ name: "chains",
3595
+ type: ["number"],
3415
3596
  required: false,
3416
- example: 1,
3417
- description: "Filter by chain ID."
3597
+ example: "1,8453",
3598
+ description: "Filter by chain IDs (comma-separated).",
3599
+ style: "form",
3600
+ explode: false
3418
3601
  }),
3419
3602
  ApiQuery({
3420
- name: "loan_token",
3421
- type: "string",
3603
+ name: "loan_tokens",
3604
+ type: ["string"],
3422
3605
  required: false,
3423
- example: "0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078",
3424
- description: "Filter by loan token address."
3606
+ example: "0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078,0x34Cf890dB685FC536E05652FB41f02090c3fb751",
3607
+ description: "Filter by loan token addresses (comma-separated).",
3608
+ style: "form",
3609
+ explode: false
3425
3610
  }),
3426
3611
  ApiQuery({
3427
- name: "collateral_token",
3428
- type: "string",
3612
+ name: "collateral_tokens",
3613
+ type: ["string"],
3429
3614
  required: false,
3430
- example: "0x34Cf890dB685FC536E05652FB41f02090c3fb751",
3431
- description: "Filter by collateral token (matches any collateral in the obligation)."
3615
+ example: "0x34Cf890dB685FC536E05652FB41f02090c3fb751,0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078",
3616
+ description: "Filter by collateral tokens (comma-separated, matches any collateral).",
3617
+ style: "form",
3618
+ explode: false
3432
3619
  }),
3433
3620
  ApiQuery({
3434
- name: "maturity",
3435
- type: "number",
3621
+ name: "maturities",
3622
+ type: ["number"],
3436
3623
  required: false,
3437
- example: 1761922800,
3438
- description: "Filter by exact maturity timestamp (unix seconds)."
3624
+ example: "1761922800,1764524800",
3625
+ description: "Filter by exact maturity timestamps (comma-separated, unix seconds).",
3626
+ style: "form",
3627
+ explode: false
3439
3628
  }),
3440
3629
  ApiResponse({
3441
3630
  status: 200,
@@ -3467,7 +3656,7 @@ ObligationsController = __decorate([ApiTags("Markets"), ApiResponse({
3467
3656
  description: "Bad Request",
3468
3657
  type: BadRequestResponse
3469
3658
  })], ObligationsController);
3470
- let UsersController = class UsersController$1 {
3659
+ let UsersController = class UsersController {
3471
3660
  async getUserPositions() {}
3472
3661
  };
3473
3662
  __decorate([
@@ -3557,7 +3746,7 @@ const OpenApi = async (options = {}) => {
3557
3746
 
3558
3747
  //#endregion
3559
3748
  //#region src/api/Schema/PositionResponse.ts
3560
- var PositionResponse_exports = /* @__PURE__ */ __export({ from: () => from$1 });
3749
+ var PositionResponse_exports = /* @__PURE__ */ __exportAll({ from: () => from$1 });
3561
3750
  /**
3562
3751
  * Creates a `PositionResponse` from a `PositionWithReserved`.
3563
3752
  * @param position - {@link PositionWithReserved}
@@ -3588,6 +3777,15 @@ function isValidBase64urlJson(val) {
3588
3777
  return false;
3589
3778
  }
3590
3779
  }
3780
+ const csvArray = (schema) => z$1.preprocess((value) => {
3781
+ if (value === void 0) return void 0;
3782
+ if (Array.isArray(value)) {
3783
+ if (value.some((item) => typeof item !== "string")) return value;
3784
+ return value.flatMap((item) => item.split(",")).map((item) => item.trim()).filter((item) => item.length > 0);
3785
+ }
3786
+ if (typeof value === "string") return value.split(",").map((item) => item.trim()).filter((item) => item.length > 0);
3787
+ return value;
3788
+ }, z$1.array(schema)).optional();
3591
3789
  const PaginationQueryParams = z$1.object({
3592
3790
  cursor: z$1.string().optional().refine((val) => {
3593
3791
  if (!val) return true;
@@ -3638,21 +3836,21 @@ const GetObligationsQueryParams = z$1.object({
3638
3836
  description: "Obligation id cursor",
3639
3837
  example: "0x1234567890123456789012345678901234567890123456789012345678901234"
3640
3838
  }),
3641
- chain: z$1.string().regex(/^[1-9]\d*$/, { message: "Chain must be a positive integer" }).transform((val) => Number.parseInt(val, 10)).optional().meta({
3642
- description: "Filter by chain ID",
3643
- example: "1"
3839
+ chains: csvArray(z$1.string().regex(/^[1-9]\d*$/, { message: "Chain must be a positive integer" }).transform((val) => Number.parseInt(val, 10))).meta({
3840
+ description: "Filter by chain IDs (comma-separated).",
3841
+ example: "1,8453"
3644
3842
  }),
3645
- loan_token: z$1.string().regex(/^0x[a-fA-F0-9]{40}$/, { error: "Loan token must be a valid 20-byte address" }).transform((val) => val.toLowerCase()).optional().meta({
3646
- description: "Filter by loan token address",
3647
- example: "0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078"
3843
+ loan_tokens: csvArray(z$1.string().regex(/^0x[a-fA-F0-9]{40}$/, { error: "Loan token must be a valid 20-byte address" }).transform((val) => val.toLowerCase())).meta({
3844
+ description: "Filter by loan token addresses (comma-separated).",
3845
+ example: "0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078,0x34Cf890dB685FC536E05652FB41f02090c3fb751"
3648
3846
  }),
3649
- collateral_token: z$1.string().regex(/^0x[a-fA-F0-9]{40}$/, { error: "Collateral token must be a valid 20-byte address" }).transform((val) => val.toLowerCase()).optional().meta({
3650
- description: "Filter by collateral token (matches any collateral in the obligation)",
3651
- example: "0x34Cf890dB685FC536E05652FB41f02090c3fb751"
3847
+ collateral_tokens: csvArray(z$1.string().regex(/^0x[a-fA-F0-9]{40}$/, { error: "Collateral token must be a valid 20-byte address" }).transform((val) => val.toLowerCase())).meta({
3848
+ description: "Filter by collateral tokens (comma-separated, matches any collateral).",
3849
+ example: "0x34Cf890dB685FC536E05652FB41f02090c3fb751,0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078"
3652
3850
  }),
3653
- maturity: z$1.string().regex(/^[1-9]\d*$/, { message: "Maturity must be a positive integer" }).transform((val) => Number.parseInt(val, 10)).optional().meta({
3654
- description: "Filter by exact maturity timestamp (unix seconds)",
3655
- example: "1761922800"
3851
+ maturities: csvArray(z$1.string().regex(/^[1-9]\d*$/, { message: "Maturity must be a positive integer" }).transform((val) => Number.parseInt(val, 10))).meta({
3852
+ description: "Filter by exact maturity timestamps (comma-separated, unix seconds).",
3853
+ example: "1761922800,1764524800"
3656
3854
  })
3657
3855
  });
3658
3856
  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({
@@ -3730,7 +3928,7 @@ function safeParse(action, query, error) {
3730
3928
 
3731
3929
  //#endregion
3732
3930
  //#region src/api/Schema/index.ts
3733
- var Schema_exports = /* @__PURE__ */ __export({
3931
+ var Schema_exports = /* @__PURE__ */ __exportAll({
3734
3932
  BookResponse: () => BookResponse_exports,
3735
3933
  BooksController: () => BooksController,
3736
3934
  ChainHealth: () => ChainHealth,
@@ -3754,7 +3952,7 @@ var Schema_exports = /* @__PURE__ */ __export({
3754
3952
 
3755
3953
  //#endregion
3756
3954
  //#region src/client/Client.ts
3757
- var Client_exports = /* @__PURE__ */ __export({
3955
+ var Client_exports$1 = /* @__PURE__ */ __exportAll({
3758
3956
  HttpForbiddenError: () => HttpForbiddenError,
3759
3957
  HttpGetApiFailedError: () => HttpGetApiFailedError,
3760
3958
  HttpRateLimitError: () => HttpRateLimitError,
@@ -3787,12 +3985,16 @@ function connect$1(parameters) {
3787
3985
  };
3788
3986
  const apiClient = createOpenApiFetchClient({
3789
3987
  baseUrl: config.url.toString(),
3790
- headers: config.headers
3988
+ headers: config.headers,
3989
+ querySerializer: { array: {
3990
+ style: "form",
3991
+ explode: false
3992
+ } }
3791
3993
  });
3792
3994
  return {
3793
3995
  ...config,
3794
- getOffers: (parameters$1) => getOffers(apiClient, parameters$1),
3795
- getObligations: (parameters$1) => getObligations(apiClient, parameters$1)
3996
+ getOffers: (parameters) => getOffers(apiClient, parameters),
3997
+ getObligations: (parameters) => getObligations(apiClient, parameters)
3796
3998
  };
3797
3999
  }
3798
4000
  async function getOffers(apiClient, parameters) {
@@ -3819,7 +4021,7 @@ async function getOffers(apiClient, parameters) {
3819
4021
  obligation_units: offerData.obligation_units,
3820
4022
  obligation_shares: offerData.obligation_shares,
3821
4023
  price: offerData.price,
3822
- maturity: from$10(offerData.obligation.maturity),
4024
+ maturity: from$11(offerData.obligation.maturity),
3823
4025
  expiry: offerData.expiry,
3824
4026
  start: offerData.start,
3825
4027
  group: offerData.group,
@@ -3855,10 +4057,10 @@ async function getObligations(apiClient, parameters) {
3855
4057
  const { data, error, response } = await apiClient.GET("/v1/obligations", { params: { query: {
3856
4058
  cursor: parameters?.cursor,
3857
4059
  limit: parameters?.limit,
3858
- chain: parameters?.chainId,
3859
- loan_token: parameters?.loanToken,
3860
- collateral_token: parameters?.collateralToken,
3861
- maturity: parameters?.maturity
4060
+ chains: parameters?.chainIds,
4061
+ loan_tokens: parameters?.loanTokens,
4062
+ collateral_tokens: parameters?.collateralTokens,
4063
+ maturities: parameters?.maturities
3862
4064
  } } });
3863
4065
  if (error !== void 0) {
3864
4066
  switch (response.status) {
@@ -3877,7 +4079,7 @@ async function getObligations(apiClient, parameters) {
3877
4079
  oracle: collateral.oracle,
3878
4080
  lltv: collateral.lltv
3879
4081
  })),
3880
- maturity: from$10(item.maturity)
4082
+ maturity: from$11(item.maturity)
3881
4083
  });
3882
4084
  const { obligationId: _, ...returned } = {
3883
4085
  id: () => id(obligation),
@@ -3926,10 +4128,97 @@ var HttpGetApiFailedError = class extends BaseError {
3926
4128
  }
3927
4129
  };
3928
4130
 
4131
+ //#endregion
4132
+ //#region src/gatekeeper/Client.ts
4133
+ var Client_exports = /* @__PURE__ */ __exportAll({ createHttpClient: () => createHttpClient });
4134
+ const DEFAULT_TIMEOUT_MS = 1e4;
4135
+ /**
4136
+ * Create an HTTP client for a gatekeeper service.
4137
+ * @param config - Gatekeeper client configuration. {@link ClientConfig}
4138
+ * @returns An HTTP-backed gatekeeper client. {@link GatekeeperClient}
4139
+ */
4140
+ function createHttpClient(config) {
4141
+ const fetchFn = config.fetchFn ?? fetch;
4142
+ const timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
4143
+ const baseUrl = normalizeBaseUrl(config.baseUrl);
4144
+ const request = async (path, init) => {
4145
+ const controller = new AbortController();
4146
+ const timeout = setTimeout(() => controller.abort(), timeoutMs);
4147
+ try {
4148
+ return await fetchFn(`${baseUrl}${path}`, {
4149
+ ...init,
4150
+ signal: controller.signal
4151
+ });
4152
+ } finally {
4153
+ clearTimeout(timeout);
4154
+ }
4155
+ };
4156
+ const validate = async (body) => {
4157
+ const response = await request("/v1/validate", {
4158
+ method: "POST",
4159
+ headers: { "content-type": "application/json" },
4160
+ body: JSON.stringify(body)
4161
+ });
4162
+ const json = await response.json();
4163
+ return {
4164
+ statusCode: response.status,
4165
+ body: json
4166
+ };
4167
+ };
4168
+ const getRules = async () => {
4169
+ const response = await request("/v1/rules", { method: "GET" });
4170
+ const json = await response.json();
4171
+ if (!response.ok) throw new Error(`Gatekeeper rules request failed: ${extractErrorMessage(json) ?? response.statusText}`);
4172
+ if (!("data" in json) || !Array.isArray(json.data)) throw new Error("Gatekeeper rules response is invalid.");
4173
+ return json.data;
4174
+ };
4175
+ const isAllowed = async (offers) => {
4176
+ const { statusCode, body } = await validate({ offers: offers.map((offer) => toSnakeCase(offer)) });
4177
+ if (statusCode !== 200) {
4178
+ const errorMessage = extractErrorMessage(body);
4179
+ throw new Error(`Gatekeeper validation failed: ${errorMessage ?? `status ${statusCode}`}`);
4180
+ }
4181
+ const data = body.data;
4182
+ if (!data || typeof data !== "object") throw new Error("Gatekeeper validation response is invalid.");
4183
+ if ("issues" in data) {
4184
+ const issues = data.issues.map((issue) => ({
4185
+ ruleName: issue.rule,
4186
+ message: issue.message,
4187
+ item: offers[issue.index]
4188
+ }));
4189
+ const invalidIndices = new Set(data.issues.map((issue) => issue.index));
4190
+ return {
4191
+ valid: offers.filter((_, index) => !invalidIndices.has(index)),
4192
+ issues
4193
+ };
4194
+ }
4195
+ if (!("payload" in data) || !("root" in data)) throw new Error("Gatekeeper validation response is missing payload data.");
4196
+ return {
4197
+ valid: offers.slice(),
4198
+ issues: []
4199
+ };
4200
+ };
4201
+ return {
4202
+ baseUrl,
4203
+ validate,
4204
+ isAllowed,
4205
+ getRules
4206
+ };
4207
+ }
4208
+ function normalizeBaseUrl(url) {
4209
+ return url.trim().replace(/\/+$/, "");
4210
+ }
4211
+ function extractErrorMessage(payload) {
4212
+ if (!payload || typeof payload !== "object") return void 0;
4213
+ const error = payload.error;
4214
+ if (!error || typeof error !== "object") return void 0;
4215
+ return typeof error.message === "string" ? error.message : void 0;
4216
+ }
4217
+
3929
4218
  //#endregion
3930
4219
  //#region src/gatekeeper/Gate.ts
3931
- var Gate_exports = /* @__PURE__ */ __export({
3932
- batch: () => batch$1,
4220
+ var Gate_exports = /* @__PURE__ */ __exportAll({
4221
+ batch: () => batch,
3933
4222
  run: () => run,
3934
4223
  single: () => single
3935
4224
  });
@@ -3940,12 +4229,12 @@ var Gate_exports = /* @__PURE__ */ __export({
3940
4229
  * @param run - The function that validates the rule.
3941
4230
  * @returns The created rule.
3942
4231
  */
3943
- function single(name, description, run$1) {
4232
+ function single(name, description, run) {
3944
4233
  return {
3945
4234
  kind: "single",
3946
4235
  name,
3947
4236
  description,
3948
- run: run$1
4237
+ run
3949
4238
  };
3950
4239
  }
3951
4240
  /**
@@ -3955,12 +4244,12 @@ function single(name, description, run$1) {
3955
4244
  * @param run - The function that validates the rule.
3956
4245
  * @returns The created rule.
3957
4246
  */
3958
- function batch$1(name, description, run$1) {
4247
+ function batch(name, description, run) {
3959
4248
  return {
3960
4249
  kind: "batch",
3961
4250
  name,
3962
4251
  description,
3963
- run: run$1
4252
+ run
3964
4253
  };
3965
4254
  }
3966
4255
  async function run(parameters) {
@@ -4013,7 +4302,7 @@ async function run(parameters) {
4013
4302
 
4014
4303
  //#endregion
4015
4304
  //#region src/gatekeeper/GateConfig.ts
4016
- var GateConfig_exports = /* @__PURE__ */ __export({
4305
+ var GateConfig_exports = /* @__PURE__ */ __exportAll({
4017
4306
  assets: () => assets,
4018
4307
  configs: () => configs,
4019
4308
  getCallback: () => getCallback,
@@ -4039,8 +4328,8 @@ function getCallback(chain, type) {
4039
4328
  * @param address - Callback contract address
4040
4329
  * @returns The callback type when found, otherwise undefined
4041
4330
  */
4042
- function getCallbackType(chain, address$1) {
4043
- return configs[chain].callbacks?.find((c) => c.type !== CallbackType.BuyWithEmptyCallback && c.addresses.includes(address$1?.toLowerCase()))?.type;
4331
+ function getCallbackType(chain, address) {
4332
+ return configs[chain].callbacks?.find((c) => c.type !== Type$1.BuyWithEmptyCallback && c.addresses.includes(address?.toLowerCase()))?.type;
4044
4333
  }
4045
4334
  /**
4046
4335
  * Returns the callback addresses for a given chain and callback type, if it exists.
@@ -4049,7 +4338,7 @@ function getCallbackType(chain, address$1) {
4049
4338
  * @returns The matching callback addresses or an empty array if not configured
4050
4339
  */
4051
4340
  function getCallbackTypeAddresses(chain, type) {
4052
- if (type === CallbackType.BuyWithEmptyCallback) return [];
4341
+ if (type === Type$1.BuyWithEmptyCallback) return [];
4053
4342
  const match = configs[chain].callbacks?.find((c) => c.type === type);
4054
4343
  return match && "addresses" in match ? match.addresses : [];
4055
4344
  }
@@ -4060,7 +4349,7 @@ function getCallbackTypeAddresses(chain, type) {
4060
4349
  * @returns Array of allowed callback addresses (lowercased). Empty when none configured
4061
4350
  */
4062
4351
  const getCallbackAddresses = (chain) => {
4063
- return configs[chain].callbacks?.filter((c) => c.type !== CallbackType.BuyWithEmptyCallback).flatMap((c) => c.addresses) ?? [];
4352
+ return configs[chain].callbacks?.filter((c) => c.type !== Type$1.BuyWithEmptyCallback).flatMap((c) => c.addresses) ?? [];
4064
4353
  };
4065
4354
  const assets = {
4066
4355
  [ChainId.ETHEREUM.toString()]: [
@@ -4093,60 +4382,60 @@ const configs = {
4093
4382
  ethereum: {
4094
4383
  callbacks: [
4095
4384
  {
4096
- type: CallbackType.BuyVaultV1Callback,
4385
+ type: Type$1.BuyVaultV1Callback,
4097
4386
  addresses: ["0x3333333333333333333333333333333333333333", "0x4444444444444444444444444444444444444444"],
4098
4387
  vaultFactories: ["0xA9c3D3a366466Fa809d1Ae982Fb2c46E5fC41101", "0x1897A8997241C1cD4bD0698647e4EB7213535c24"]
4099
4388
  },
4100
4389
  {
4101
- type: CallbackType.SellERC20Callback,
4390
+ type: Type$1.SellERC20Callback,
4102
4391
  addresses: ["0x1111111111111111111111111111111111111111", "0x2222222222222222222222222222222222222222"]
4103
4392
  },
4104
- { type: CallbackType.BuyWithEmptyCallback }
4393
+ { type: Type$1.BuyWithEmptyCallback }
4105
4394
  ],
4106
4395
  maturities: [MaturityType.EndOfMonth, MaturityType.EndOfNextMonth]
4107
4396
  },
4108
4397
  base: {
4109
4398
  callbacks: [
4110
4399
  {
4111
- type: CallbackType.BuyVaultV1Callback,
4400
+ type: Type$1.BuyVaultV1Callback,
4112
4401
  addresses: ["0x3333333333333333333333333333333333333333", "0x4444444444444444444444444444444444444444"],
4113
4402
  vaultFactories: ["0xA9c3D3a366466Fa809d1Ae982Fb2c46E5fC41101", "0xFf62A7c278C62eD665133147129245053Bbf5918"]
4114
4403
  },
4115
4404
  {
4116
- type: CallbackType.SellERC20Callback,
4405
+ type: Type$1.SellERC20Callback,
4117
4406
  addresses: ["0x1111111111111111111111111111111111111111", "0x2222222222222222222222222222222222222222"]
4118
4407
  },
4119
- { type: CallbackType.BuyWithEmptyCallback }
4408
+ { type: Type$1.BuyWithEmptyCallback }
4120
4409
  ],
4121
4410
  maturities: [MaturityType.EndOfMonth, MaturityType.EndOfNextMonth]
4122
4411
  },
4123
4412
  "ethereum-virtual-testnet": {
4124
4413
  callbacks: [
4125
4414
  {
4126
- type: CallbackType.BuyVaultV1Callback,
4415
+ type: Type$1.BuyVaultV1Callback,
4127
4416
  addresses: ["0x3333333333333333333333333333333333333333", "0x4444444444444444444444444444444444444444"],
4128
4417
  vaultFactories: ["0xA9c3D3a366466Fa809d1Ae982Fb2c46E5fC41101", "0x1897A8997241C1cD4bD0698647e4EB7213535c24"]
4129
4418
  },
4130
4419
  {
4131
- type: CallbackType.SellERC20Callback,
4420
+ type: Type$1.SellERC20Callback,
4132
4421
  addresses: ["0x1111111111111111111111111111111111111111", "0x2222222222222222222222222222222222222222"]
4133
4422
  },
4134
- { type: CallbackType.BuyWithEmptyCallback }
4423
+ { type: Type$1.BuyWithEmptyCallback }
4135
4424
  ],
4136
4425
  maturities: [MaturityType.EndOfMonth, MaturityType.EndOfNextMonth]
4137
4426
  },
4138
4427
  anvil: {
4139
4428
  callbacks: [
4140
4429
  {
4141
- type: CallbackType.BuyVaultV1Callback,
4430
+ type: Type$1.BuyVaultV1Callback,
4142
4431
  addresses: ["0x3333333333333333333333333333333333333333", "0x4444444444444444444444444444444444444444"],
4143
4432
  vaultFactories: ["0xA9c3D3a366466Fa809d1Ae982Fb2c46E5fC41101", "0x1897A8997241C1cD4bD0698647e4EB7213535c24"]
4144
4433
  },
4145
4434
  {
4146
- type: CallbackType.SellERC20Callback,
4435
+ type: Type$1.SellERC20Callback,
4147
4436
  addresses: ["0x1111111111111111111111111111111111111111", "0x2222222222222222222222222222222222222222"]
4148
4437
  },
4149
- { type: CallbackType.BuyWithEmptyCallback }
4438
+ { type: Type$1.BuyWithEmptyCallback }
4150
4439
  ],
4151
4440
  maturities: [MaturityType.EndOfMonth, MaturityType.EndOfNextMonth]
4152
4441
  }
@@ -4154,22 +4443,31 @@ const configs = {
4154
4443
 
4155
4444
  //#endregion
4156
4445
  //#region src/gatekeeper/Gatekeeper.ts
4157
- var Gatekeeper_exports = /* @__PURE__ */ __export({ create: () => create });
4446
+ var Gatekeeper_exports = /* @__PURE__ */ __exportAll({ create: () => create });
4447
+ /**
4448
+ * Create a gatekeeper instance with the provided rules.
4449
+ * @param parameters - Gatekeeper parameters. {@link GatekeeperParameters}
4450
+ * @returns Gatekeeper instance. {@link Gatekeeper}
4451
+ */
4158
4452
  function create(parameters) {
4453
+ const { rules } = parameters;
4159
4454
  return {
4160
- rules: parameters.rules,
4161
4455
  isAllowed: async (offers) => {
4162
4456
  return await run({
4163
4457
  items: offers,
4164
- rules: parameters.rules
4458
+ rules
4165
4459
  });
4166
- }
4460
+ },
4461
+ getRules: async () => rules.map((rule) => ({
4462
+ name: rule.name,
4463
+ description: rule.description
4464
+ }))
4167
4465
  };
4168
4466
  }
4169
4467
 
4170
4468
  //#endregion
4171
4469
  //#region src/gatekeeper/Rules.ts
4172
- var Rules_exports = /* @__PURE__ */ __export({
4470
+ var Rules_exports = /* @__PURE__ */ __exportAll({
4173
4471
  amountMutualExclusivity: () => amountMutualExclusivity,
4174
4472
  callback: () => callback,
4175
4473
  chains: () => chains,
@@ -4188,21 +4486,21 @@ function validity(parameters) {
4188
4486
  const { client } = parameters;
4189
4487
  const sellErc20CallbackInvalid = single("sell_erc20_callback_invalid", "Validates that sell offers have valid ERC20 callback data matching offer collaterals", (offer) => {
4190
4488
  const callbackType = getCallbackType(client.chain.name, offer.callback.address);
4191
- if (callbackType !== CallbackType.SellERC20Callback) return;
4489
+ if (callbackType !== Type$1.SellERC20Callback) return;
4192
4490
  const decoded = decode$2(callbackType, offer.callback.data);
4193
4491
  if (decoded.length === 0) return { message: "Callback data cannot be decoded or is empty." };
4194
- if (callbackType === CallbackType.SellERC20Callback) {
4492
+ if (callbackType === Type$1.SellERC20Callback) {
4195
4493
  const offerCollaterals = new Set(offer.collaterals.map((c) => c.asset.toLowerCase()));
4196
4494
  if (decoded.length !== offer.collaterals.length) return { message: `Sell callback collateral length mismatch. Expected ${offer.collaterals.length}, got ${decoded.length}.` };
4197
4495
  for (const { contract } of decoded) if (!offerCollaterals.has(contract.toLowerCase())) return { message: "Sell callback collateral is not part of offer collaterals." };
4198
4496
  }
4199
4497
  });
4200
- const buyCallbackVaultInvalid = batch$1("buy_offers_callback_vault_invalid", "Validates that buy offers have valid vault callbacks registered in allowed factories with matching assets", async (offers) => {
4498
+ const buyCallbackVaultInvalid = batch("buy_offers_callback_vault_invalid", "Validates that buy offers have valid vault callbacks registered in allowed factories with matching assets", async (offers) => {
4201
4499
  const validationIssues = /* @__PURE__ */ new Map();
4202
4500
  const offersByVaultAddress = /* @__PURE__ */ new Map();
4203
4501
  for (let i = 0; i < offers.length; i++) {
4204
4502
  const offer = offers[i];
4205
- if (getCallbackType(client.chain.name, offer.callback.address) !== CallbackType.BuyVaultV1Callback) continue;
4503
+ if (getCallbackType(client.chain.name, offer.callback.address) !== Type$1.BuyVaultV1Callback) continue;
4206
4504
  try {
4207
4505
  const callbackVaults = decodeBuyVaultV1Callback(offer.callback.data);
4208
4506
  for (const { contract } of callbackVaults) {
@@ -4217,7 +4515,7 @@ function validity(parameters) {
4217
4515
  }
4218
4516
  const uniqueVaultAddresses = Array.from(offersByVaultAddress.keys());
4219
4517
  if (uniqueVaultAddresses.length === 0) return validationIssues;
4220
- const allowedFactories = getCallback(client.chain.name, CallbackType.BuyVaultV1Callback)?.vaultFactories.map((f) => f.toLowerCase());
4518
+ const allowedFactories = getCallback(client.chain.name, Type$1.BuyVaultV1Callback)?.vaultFactories.map((f) => f.toLowerCase());
4221
4519
  if (!allowedFactories) return validationIssues;
4222
4520
  const multicallContracts = [];
4223
4521
  for (const vaultAddress of uniqueVaultAddresses) {
@@ -4285,16 +4583,16 @@ function validity(parameters) {
4285
4583
  buyCallbackVaultInvalid
4286
4584
  ];
4287
4585
  }
4288
- const chains = ({ chains: chains$2 }) => single("chain_ids", `Validates that offer chain is one of: [${chains$2.map((c) => c.id).join(", ")}]`, (offer) => {
4289
- const allowedChainIds = chains$2.map((c) => c.id);
4290
- if (!allowedChainIds.some((id$1) => id$1 === offer.chainId)) return { message: `Chain ID ${offer.chainId} is not in the allowed chains (${allowedChainIds.join(", ")})` };
4586
+ const chains = ({ chains }) => single("chain_ids", `Validates that offer chain is one of: [${chains.map((c) => c.id).join(", ")}]`, (offer) => {
4587
+ const allowedChainIds = chains.map((c) => c.id);
4588
+ if (!allowedChainIds.some((id) => id === offer.chainId)) return { message: `Chain ID ${offer.chainId} is not in the allowed chains (${allowedChainIds.join(", ")})` };
4291
4589
  });
4292
4590
  const maturity = ({ maturities }) => single("maturity", `Validates that offer maturity is one of: [${maturities.join(", ")}]`, (offer) => {
4293
- const allowedMaturities = maturities.map((m) => from$10(m));
4591
+ const allowedMaturities = maturities.map((m) => from$11(m));
4294
4592
  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}` };
4295
4593
  });
4296
- const callback = ({ callbacks, allowedAddresses }) => single("callback", `Validates callbacks: buy empty callback is ${callbacks.includes(CallbackType.BuyWithEmptyCallback) ? "allowed" : "not allowed"}; sell offers must use a non-empty callback; non-empty callbacks must target one of [${allowedAddresses.map((a) => a.toLowerCase()).join(", ")}]`, (offer) => {
4297
- if (isEmptyCallback(offer) && offer.buy && !callbacks?.find((c) => c === CallbackType.BuyWithEmptyCallback)) return { message: "Buy offers with empty callback not allowed." };
4594
+ const callback = ({ callbacks, allowedAddresses }) => single("callback", `Validates callbacks: buy empty callback is ${callbacks.includes(Type$1.BuyWithEmptyCallback) ? "allowed" : "not allowed"}; sell offers must use a non-empty callback; non-empty callbacks must target one of [${allowedAddresses.map((a) => a.toLowerCase()).join(", ")}]`, (offer) => {
4595
+ if (isEmptyCallback(offer) && offer.buy && !callbacks?.find((c) => c === Type$1.BuyWithEmptyCallback)) return { message: "Buy offers with empty callback not allowed." };
4298
4596
  if (isEmptyCallback(offer) && !offer.buy) return { message: "Sell offers require a non-empty callback." };
4299
4597
  if (!isEmptyCallback(offer)) {
4300
4598
  if (!allowedAddresses.includes(offer.callback.address?.toLowerCase())) return { message: `Callback address ${offer.callback.address} is not allowed.` };
@@ -4316,7 +4614,7 @@ const token = ({ assetsByChainId }) => single("token", "Validates that offer loa
4316
4614
  * Returns an issue only for the first non-conforming offer.
4317
4615
  * This rule is signing-agnostic; signer verification is handled at the collector level.
4318
4616
  */
4319
- const sameMaker = () => batch$1("mixed_maker", "Validates that all offers in a batch have the same maker address", (offers) => {
4617
+ const sameMaker = () => batch("mixed_maker", "Validates that all offers in a batch have the same maker address", (offers) => {
4320
4618
  const issues = /* @__PURE__ */ new Map();
4321
4619
  if (offers.length === 0) return issues;
4322
4620
  const firstMaker = offers[0].maker.toLowerCase();
@@ -4350,9 +4648,9 @@ const morphoRules = (chains$2) => {
4350
4648
  maturity({ maturities: [MaturityType.EndOfMonth, MaturityType.EndOfNextMonth] }),
4351
4649
  callback({
4352
4650
  callbacks: [
4353
- CallbackType.BuyWithEmptyCallback,
4354
- CallbackType.BuyVaultV1Callback,
4355
- CallbackType.SellERC20Callback
4651
+ Type$1.BuyWithEmptyCallback,
4652
+ Type$1.BuyVaultV1Callback,
4653
+ Type$1.SellERC20Callback
4356
4654
  ],
4357
4655
  allowedAddresses: chains$2.flatMap((c) => getCallbackAddresses(c.name))
4358
4656
  }),
@@ -4370,9 +4668,9 @@ function from(parameters) {
4370
4668
  blockWindow: parameters.blockWindow
4371
4669
  };
4372
4670
  return {
4373
- add: (parameters$1) => add(config, parameters$1),
4374
- get: (parameters$1) => get(config, parameters$1),
4375
- stream: (parameters$1) => streamOffers(config, parameters$1)
4671
+ add: (parameters) => add(config, parameters),
4672
+ get: (parameters) => get(config, parameters),
4673
+ stream: (parameters) => streamOffers(config, parameters)
4376
4674
  };
4377
4675
  }
4378
4676
  /**
@@ -4384,7 +4682,7 @@ function from(parameters) {
4384
4682
  */
4385
4683
  async function add(config, offers) {
4386
4684
  if (!config.client.account) throw new WalletAccountNotSetError();
4387
- const tree = from$8(offers.map((o) => from$7(o)));
4685
+ const tree = from$9(offers.map((o) => from$8(o)));
4388
4686
  const chainId = await getChainId(config.client);
4389
4687
  for (const offer of tree.offers) if (chainId !== offer.chainId) throw new ChainIdMismatchError(offer.chainId, chainId);
4390
4688
  const signature = await sign(tree.offers, config.client);
@@ -4496,7 +4794,7 @@ var ChainIdMismatchError = class extends BaseError {
4496
4794
 
4497
4795
  //#endregion
4498
4796
  //#region src/mempool/MempoolClient.ts
4499
- var MempoolClient_exports = /* @__PURE__ */ __export({ connect: () => connect });
4797
+ var MempoolClient_exports = /* @__PURE__ */ __exportAll({ connect: () => connect });
4500
4798
  /**
4501
4799
  * Client to interact with the Mempool contract on a specific chain.
4502
4800
  */
@@ -4529,7 +4827,7 @@ const retry = async (fn, attempts = 3, delayMs = 50) => {
4529
4827
  async function batchMulticall(parameters) {
4530
4828
  const { client, calls, batchSize, retryAttempts, retryDelayMs, blockNumber } = parameters;
4531
4829
  const results = [];
4532
- for (const callsBatch of batch(calls, batchSize)) {
4830
+ for (const callsBatch of batch$1(calls, batchSize)) {
4533
4831
  const batchResults = await retry(() => multicall(client, {
4534
4832
  allowFailure: false,
4535
4833
  contracts: callsBatch,
@@ -4542,7 +4840,7 @@ async function batchMulticall(parameters) {
4542
4840
 
4543
4841
  //#endregion
4544
4842
  //#region src/utils/Group.ts
4545
- var Group_exports = /* @__PURE__ */ __export({ fromNumber: () => fromNumber });
4843
+ var Group_exports = /* @__PURE__ */ __exportAll({ fromNumber: () => fromNumber });
4546
4844
  /**
4547
4845
  * Creates a bytes32 group identifier from a number.
4548
4846
  * @param n - A non-negative integer.
@@ -4566,7 +4864,7 @@ function lazy(pollFn) {
4566
4864
  let active = true;
4567
4865
  let resolveNext = null;
4568
4866
  const queue = [];
4569
- const wait$1 = () => new Promise((resolve) => {
4867
+ const wait = () => new Promise((resolve) => {
4570
4868
  resolveNext = resolve;
4571
4869
  });
4572
4870
  const emit = (item) => {
@@ -4584,7 +4882,7 @@ function lazy(pollFn) {
4584
4882
  unpoll = pollFn(emit, { stop });
4585
4883
  try {
4586
4884
  while (active) {
4587
- if (queue.length === 0) await wait$1();
4885
+ if (queue.length === 0) await wait();
4588
4886
  while (queue.length > 0 && active) yield queue.shift();
4589
4887
  }
4590
4888
  } finally {
@@ -4623,7 +4921,7 @@ function poll(fn, { interval }) {
4623
4921
 
4624
4922
  //#endregion
4625
4923
  //#region src/utils/time.ts
4626
- var time_exports = /* @__PURE__ */ __export({
4924
+ var time_exports = /* @__PURE__ */ __exportAll({
4627
4925
  max: () => max,
4628
4926
  now: () => now
4629
4927
  });
@@ -4636,14 +4934,14 @@ function max() {
4636
4934
 
4637
4935
  //#endregion
4638
4936
  //#region src/utils/index.ts
4639
- var utils_exports = /* @__PURE__ */ __export({
4937
+ var utils_exports = /* @__PURE__ */ __exportAll({
4640
4938
  BaseError: () => BaseError,
4641
4939
  Group: () => Group_exports,
4642
4940
  Random: () => Random_exports,
4643
4941
  ReorgError: () => ReorgError,
4644
4942
  Time: () => time_exports,
4645
4943
  atMostOneNonZero: () => atMostOneNonZero,
4646
- batch: () => batch,
4944
+ batch: () => batch$1,
4647
4945
  batchMulticall: () => batchMulticall,
4648
4946
  fromSnakeCase: () => fromSnakeCase$3,
4649
4947
  lazy: () => lazy,
@@ -4657,5 +4955,5 @@ var utils_exports = /* @__PURE__ */ __export({
4657
4955
  });
4658
4956
 
4659
4957
  //#endregion
4660
- export { Abi_exports as Abi, BrandTypeId, Callback_exports as Callback, Chain_exports as Chain, ChainRegistry_exports as ChainRegistry, Collateral_exports as Collateral, ERC4626_exports as ERC4626, Errors_exports as Errors, Format_exports as Format, GateConfig_exports as GateConfig, Gatekeeper_exports as Gatekeeper, LLTV_exports as LLTV, Liquidity_exports as Liquidity, Maturity_exports as Maturity, MempoolClient_exports as Mempool, Obligation_exports as Obligation, Offer_exports as Offer, Oracle_exports as Oracle, Position_exports as Position, Quote_exports as Quote, Schema_exports as RouterApi, Client_exports as RouterClient, Rules_exports as Rules, time_exports as Time, Transfer_exports as Transfer, Tree_exports as Tree, utils_exports as Utils, Gate_exports as Validation, morphoRules };
4958
+ export { Abi_exports as Abi, BrandTypeId, Callback_exports as Callback, Chain_exports as Chain, ChainRegistry_exports as ChainRegistry, Collateral_exports as Collateral, ERC4626_exports as ERC4626, Errors_exports as Errors, Format_exports as Format, GateConfig_exports as GateConfig, Gatekeeper_exports as Gatekeeper, Client_exports as GatekeeperClient, LLTV_exports as LLTV, Liquidity_exports as Liquidity, Maturity_exports as Maturity, MempoolClient_exports as Mempool, Obligation_exports as Obligation, Offer_exports as Offer, Oracle_exports as Oracle, Position_exports as Position, Quote_exports as Quote, Schema_exports as RouterApi, Client_exports$1 as RouterClient, Rules_exports as Rules, time_exports as Time, TradingFee_exports as TradingFee, Transfer_exports as Transfer, Tree_exports as Tree, utils_exports as Utils, Gate_exports as Validation, morphoRules };
4661
4959
  //# sourceMappingURL=index.browser.mjs.map