@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.
@@ -5,21 +5,30 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (all) => {
8
+ var __exportAll = (all, symbols) => {
9
9
  let target = {};
10
- for (var name in all) __defProp(target, name, {
11
- get: all[name],
12
- enumerable: true
13
- });
10
+ for (var name in all) {
11
+ __defProp(target, name, {
12
+ get: all[name],
13
+ enumerable: true
14
+ });
15
+ }
16
+ if (symbols) {
17
+ __defProp(target, Symbol.toStringTag, { value: "Module" });
18
+ }
14
19
  return target;
15
20
  };
16
- var __copyProps = (to, from$15, except, desc) => {
17
- if (from$15 && typeof from$15 === "object" || typeof from$15 === "function") for (var keys = __getOwnPropNames(from$15), i = 0, n = keys.length, key; i < n; i++) {
18
- key = keys[i];
19
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
20
- get: ((k) => from$15[k]).bind(null, key),
21
- enumerable: !(desc = __getOwnPropDesc(from$15, key)) || desc.enumerable
22
- });
21
+ var __copyProps = (to, from, except, desc) => {
22
+ if (from && typeof from === "object" || typeof from === "function") {
23
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
24
+ key = keys[i];
25
+ if (!__hasOwnProp.call(to, key) && key !== except) {
26
+ __defProp(to, key, {
27
+ get: ((k) => from[k]).bind(null, key),
28
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
29
+ });
30
+ }
31
+ }
23
32
  }
24
33
  return to;
25
34
  };
@@ -35,7 +44,7 @@ let viem_actions = require("viem/actions");
35
44
  let viem_chains = require("viem/chains");
36
45
  let zod = require("zod");
37
46
  zod = __toESM(zod);
38
- let __openzeppelin_merkle_tree = require("@openzeppelin/merkle-tree");
47
+ let _openzeppelin_merkle_tree = require("@openzeppelin/merkle-tree");
39
48
  let pako = require("pako");
40
49
  require("reflect-metadata");
41
50
  let openapi_metadata = require("openapi-metadata");
@@ -44,8 +53,8 @@ let openapi_fetch = require("openapi-fetch");
44
53
  openapi_fetch = __toESM(openapi_fetch);
45
54
 
46
55
  //#region src/api/Schema/BookResponse.ts
47
- var BookResponse_exports = /* @__PURE__ */ __export({ from: () => from$14 });
48
- function from$14(level) {
56
+ var BookResponse_exports = /* @__PURE__ */ __exportAll({ from: () => from$15 });
57
+ function from$15(level) {
49
58
  return {
50
59
  price: level.price.toString(),
51
60
  assets: level.assets.toString(),
@@ -89,14 +98,14 @@ const RouterStatusResponse = zod_v4.z.object({
89
98
 
90
99
  //#endregion
91
100
  //#region src/api/Schema/ObligationResponse.ts
92
- var ObligationResponse_exports = /* @__PURE__ */ __export({ from: () => from$13 });
101
+ var ObligationResponse_exports = /* @__PURE__ */ __exportAll({ from: () => from$14 });
93
102
  /**
94
103
  * Creates an `ObligationResponse` from a `Obligation`.
95
104
  * @constructor
96
105
  * @param obligation - {@link Obligation}
97
106
  * @returns The created `ObligationResponse`. {@link ObligationResponse}
98
107
  */
99
- function from$13(obligation, quote) {
108
+ function from$14(obligation, quote) {
100
109
  return {
101
110
  id: quote.obligationId,
102
111
  chain_id: obligation.chainId,
@@ -132,7 +141,7 @@ const MetaMorphoFactory = (0, viem.parseAbi)(["event CreateMetaMorpho(address in
132
141
 
133
142
  //#endregion
134
143
  //#region src/core/Abi/index.ts
135
- var Abi_exports = /* @__PURE__ */ __export({
144
+ var Abi_exports = /* @__PURE__ */ __exportAll({
136
145
  ERC4626: () => ERC4626,
137
146
  MetaMorpho: () => MetaMorpho,
138
147
  MetaMorphoFactory: () => MetaMorphoFactory,
@@ -283,41 +292,77 @@ const Morpho = [
283
292
 
284
293
  //#endregion
285
294
  //#region src/core/Callback.ts
286
- var Callback_exports = /* @__PURE__ */ __export({
287
- CallbackType: () => CallbackType,
295
+ var Callback_exports = /* @__PURE__ */ __exportAll({
296
+ Type: () => Type$1,
288
297
  decode: () => decode$2,
298
+ decodeBuyERC20: () => decodeBuyERC20,
289
299
  decodeBuyVaultV1Callback: () => decodeBuyVaultV1Callback,
290
300
  decodeSellERC20Callback: () => decodeSellERC20Callback,
291
301
  encode: () => encode$2,
302
+ encodeBuyERC20: () => encodeBuyERC20,
292
303
  encodeBuyVaultV1Callback: () => encodeBuyVaultV1Callback,
293
304
  encodeSellERC20Callback: () => encodeSellERC20Callback,
294
305
  isEmptyCallback: () => isEmptyCallback
295
306
  });
296
- let CallbackType = /* @__PURE__ */ function(CallbackType$1) {
297
- CallbackType$1["BuyWithEmptyCallback"] = "buy_with_empty_callback";
298
- CallbackType$1["BuyVaultV1Callback"] = "buy_vault_v1_callback";
299
- CallbackType$1["SellERC20Callback"] = "sell_erc20_callback";
300
- return CallbackType$1;
307
+ let Type$1 = /* @__PURE__ */ function(Type) {
308
+ Type["BuyWithEmptyCallback"] = "buy_with_empty_callback";
309
+ Type["BuyERC20"] = "buy_erc20";
310
+ Type["BuyVaultV1Callback"] = "buy_vault_v1_callback";
311
+ Type["SellERC20Callback"] = "sell_erc20_callback";
312
+ return Type;
301
313
  }({});
302
314
  const isEmptyCallback = (offer) => offer.callback.data === "0x";
303
315
  function decode$2(type, data) {
304
316
  switch (type) {
305
- case CallbackType.BuyVaultV1Callback: return decodeBuyVaultV1Callback(data);
306
- case CallbackType.SellERC20Callback: return decodeSellERC20Callback(data);
317
+ case Type$1.BuyERC20: return decodeBuyERC20(data);
318
+ case Type$1.BuyVaultV1Callback: return decodeBuyVaultV1Callback(data);
319
+ case Type$1.SellERC20Callback: return decodeSellERC20Callback(data);
307
320
  default: throw new Error("Invalid callback type");
308
321
  }
309
322
  }
310
323
  function encode$2(type, data) {
311
324
  switch (type) {
312
- case CallbackType.BuyVaultV1Callback:
325
+ case Type$1.BuyERC20:
326
+ if (!("tokens" in data)) throw new Error("Invalid callback data");
327
+ return encodeBuyERC20(data);
328
+ case Type$1.BuyVaultV1Callback:
313
329
  if (!("vaults" in data)) throw new Error("Invalid callback data");
314
330
  return encodeBuyVaultV1Callback(data);
315
- case CallbackType.SellERC20Callback:
331
+ case Type$1.SellERC20Callback:
316
332
  if (!("collaterals" in data)) throw new Error("Invalid callback data");
317
333
  return encodeSellERC20Callback(data);
318
334
  default: throw new Error("Invalid callback type");
319
335
  }
320
336
  }
337
+ /**
338
+ * Decodes BuyERC20 callback data into positions.
339
+ * @param data - The ABI-encoded callback data containing token addresses and amounts.
340
+ * @returns Array of positions with contract address and amount.
341
+ * @throws If data is empty, malformed, or arrays have mismatched lengths.
342
+ */
343
+ function decodeBuyERC20(data) {
344
+ if (!data || data === "0x") throw new Error("Empty callback data");
345
+ let tokens;
346
+ let amounts;
347
+ try {
348
+ [tokens, amounts] = (0, viem.decodeAbiParameters)([{ type: "address[]" }, { type: "uint256[]" }], data);
349
+ } catch (_) {
350
+ throw new Error("Invalid BuyERC20 callback data");
351
+ }
352
+ if (tokens.length !== amounts.length) throw new Error("Mismatched array lengths");
353
+ return tokens.map((token, index) => ({
354
+ contract: token,
355
+ amount: amounts[index]
356
+ }));
357
+ }
358
+ /**
359
+ * Encodes BuyERC20 callback parameters into ABI-encoded data.
360
+ * @param parameters - The tokens and amounts to encode.
361
+ * @returns ABI-encoded hex string.
362
+ */
363
+ function encodeBuyERC20(parameters) {
364
+ return (0, viem.encodeAbiParameters)([{ type: "address[]" }, { type: "uint256[]" }], [parameters.tokens, parameters.amounts]);
365
+ }
321
366
  function decodeBuyVaultV1Callback(data) {
322
367
  if (!data || data === "0x") throw new Error("Empty callback data");
323
368
  try {
@@ -392,23 +437,23 @@ function atMostOneNonZero(...values) {
392
437
  * // [5]
393
438
  * ```
394
439
  */
395
- function* batch(array, batchSize) {
440
+ function* batch$1(array, batchSize) {
396
441
  for (let i = 0; i < array.length; i += batchSize) yield array.slice(i, i + batchSize);
397
442
  }
398
443
 
399
444
  //#endregion
400
- //#region \0@oxc-project+runtime@0.97.0/helpers/typeof.js
445
+ //#region \0@oxc-project+runtime@0.110.0/helpers/typeof.js
401
446
  function _typeof(o) {
402
447
  "@babel/helpers - typeof";
403
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
404
- return typeof o$1;
405
- } : function(o$1) {
406
- return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
448
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
449
+ return typeof o;
450
+ } : function(o) {
451
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
407
452
  }, _typeof(o);
408
453
  }
409
454
 
410
455
  //#endregion
411
- //#region \0@oxc-project+runtime@0.97.0/helpers/toPrimitive.js
456
+ //#region \0@oxc-project+runtime@0.110.0/helpers/toPrimitive.js
412
457
  function toPrimitive(t, r) {
413
458
  if ("object" != _typeof(t) || !t) return t;
414
459
  var e = t[Symbol.toPrimitive];
@@ -421,14 +466,14 @@ function toPrimitive(t, r) {
421
466
  }
422
467
 
423
468
  //#endregion
424
- //#region \0@oxc-project+runtime@0.97.0/helpers/toPropertyKey.js
469
+ //#region \0@oxc-project+runtime@0.110.0/helpers/toPropertyKey.js
425
470
  function toPropertyKey(t) {
426
471
  var i = toPrimitive(t, "string");
427
472
  return "symbol" == _typeof(i) ? i : i + "";
428
473
  }
429
474
 
430
475
  //#endregion
431
- //#region \0@oxc-project+runtime@0.97.0/helpers/defineProperty.js
476
+ //#region \0@oxc-project+runtime@0.110.0/helpers/defineProperty.js
432
477
  function _defineProperty(e, r, t) {
433
478
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
434
479
  value: t,
@@ -440,7 +485,7 @@ function _defineProperty(e, r, t) {
440
485
 
441
486
  //#endregion
442
487
  //#region src/utils/Errors.ts
443
- var Errors_exports = /* @__PURE__ */ __export({
488
+ var Errors_exports = /* @__PURE__ */ __exportAll({
444
489
  BaseError: () => BaseError,
445
490
  ReorgError: () => ReorgError
446
491
  });
@@ -497,7 +542,7 @@ var ReorgError = class extends BaseError {
497
542
 
498
543
  //#endregion
499
544
  //#region src/core/Chain.ts
500
- var Chain_exports = /* @__PURE__ */ __export({
545
+ var Chain_exports = /* @__PURE__ */ __exportAll({
501
546
  ChainId: () => ChainId,
502
547
  InvalidBatchSizeError: () => InvalidBatchSizeError,
503
548
  InvalidBlockRangeError: () => InvalidBlockRangeError,
@@ -559,7 +604,8 @@ const chains$1 = {
559
604
  address: "0x1897A8997241C1cD4bD0698647e4EB7213535c24",
560
605
  blockCreated: 21439510
561
606
  }
562
- } }
607
+ } },
608
+ callbacks: []
563
609
  }
564
610
  },
565
611
  base: {
@@ -588,7 +634,8 @@ const chains$1 = {
588
634
  address: "0xFf62A7c278C62eD665133147129245053Bbf5918",
589
635
  blockCreated: 23928808
590
636
  }
591
- } }
637
+ } },
638
+ callbacks: []
592
639
  }
593
640
  },
594
641
  "ethereum-virtual-testnet": {
@@ -617,7 +664,8 @@ const chains$1 = {
617
664
  address: "0x1897A8997241C1cD4bD0698647e4EB7213535c24",
618
665
  blockCreated: 21439510
619
666
  }
620
- } }
667
+ } },
668
+ callbacks: []
621
669
  }
622
670
  },
623
671
  anvil: {
@@ -646,7 +694,8 @@ const chains$1 = {
646
694
  address: "0x0000000000000000000000000000000000000000",
647
695
  blockCreated: 0
648
696
  }
649
- } }
697
+ } },
698
+ callbacks: []
650
699
  }
651
700
  }
652
701
  };
@@ -691,7 +740,7 @@ async function* streamLogs(parameters) {
691
740
  if (a.transactionIndex !== b.transactionIndex) return order === "asc" ? a.transactionIndex - b.transactionIndex : b.transactionIndex - a.transactionIndex;
692
741
  return order === "asc" ? a.logIndex - b.logIndex : b.logIndex - a.logIndex;
693
742
  });
694
- for (const logBatch of batch(logs, maxBatchSize)) yield {
743
+ for (const logBatch of batch$1(logs, maxBatchSize)) yield {
695
744
  logs: logBatch,
696
745
  blockNumber: logBatch.length === maxBatchSize ? Number(logBatch[logBatch.length - 1]?.blockNumber) : order === "asc" ? Number(toBlock) : Number(fromBlock)
697
746
  };
@@ -742,10 +791,15 @@ var MissingBlockNumberError = class extends BaseError {
742
791
 
743
792
  //#endregion
744
793
  //#region src/core/ChainRegistry.ts
745
- var ChainRegistry_exports = /* @__PURE__ */ __export({ create: () => create$1 });
746
- function create$1(chains$2) {
794
+ var ChainRegistry_exports = /* @__PURE__ */ __exportAll({ create: () => create$1 });
795
+ /**
796
+ * Creates a chain registry from a list of chains.
797
+ * @param chains - Array of chain objects to register.
798
+ * @returns A registry for looking up chains by ID. {@link ChainRegistry}
799
+ */
800
+ function create$1(chains) {
747
801
  const byId = /* @__PURE__ */ new Map();
748
- for (const chain of chains$2) byId.set(chain.id, chain);
802
+ for (const chain of chains) byId.set(chain.id, chain);
749
803
  return {
750
804
  getById: (chainId) => byId.get(chainId),
751
805
  list: () => Array.from(byId.values())
@@ -754,7 +808,7 @@ function create$1(chains$2) {
754
808
 
755
809
  //#endregion
756
810
  //#region src/utils/Random.ts
757
- var Random_exports = /* @__PURE__ */ __export({
811
+ var Random_exports = /* @__PURE__ */ __exportAll({
758
812
  address: () => address,
759
813
  bool: () => bool,
760
814
  bytes: () => bytes,
@@ -767,16 +821,16 @@ var Random_exports = /* @__PURE__ */ __export({
767
821
  let currentRng = Math.random;
768
822
  const FNV_OFFSET_BASIS = 2166136261;
769
823
  const FNV_PRIME = 16777619;
770
- const hashSeed = (seed$1) => {
771
- let hash$1 = FNV_OFFSET_BASIS;
772
- for (let i = 0; i < seed$1.length; i += 1) {
773
- hash$1 ^= seed$1.charCodeAt(i);
774
- hash$1 = Math.imul(hash$1, FNV_PRIME);
824
+ const hashSeed = (seed) => {
825
+ let hash = FNV_OFFSET_BASIS;
826
+ for (let i = 0; i < seed.length; i += 1) {
827
+ hash ^= seed.charCodeAt(i);
828
+ hash = Math.imul(hash, FNV_PRIME);
775
829
  }
776
- return hash$1 >>> 0;
830
+ return hash >>> 0;
777
831
  };
778
- const createSeededRng = (seed$1) => {
779
- let state = hashSeed(seed$1);
832
+ const createSeededRng = (seed) => {
833
+ let state = hashSeed(seed);
780
834
  return () => {
781
835
  state += 1831565813;
782
836
  let t = Math.imul(state ^ state >>> 15, state | 1);
@@ -787,9 +841,9 @@ const createSeededRng = (seed$1) => {
787
841
  /**
788
842
  * Runs a function with a deterministic RNG derived from the given seed.
789
843
  */
790
- function withSeed(seed$1, fn) {
844
+ function withSeed(seed, fn) {
791
845
  const previous = currentRng;
792
- currentRng = createSeededRng(seed$1);
846
+ currentRng = createSeededRng(seed);
793
847
  try {
794
848
  return fn();
795
849
  } finally {
@@ -799,8 +853,8 @@ function withSeed(seed$1, fn) {
799
853
  /**
800
854
  * Seeds the global RNG for deterministic test runs.
801
855
  */
802
- function seed(seed$1) {
803
- currentRng = createSeededRng(seed$1);
856
+ function seed(seed) {
857
+ currentRng = createSeededRng(seed);
804
858
  }
805
859
  /**
806
860
  * Returns a deterministic random float in [0, 1).
@@ -811,8 +865,8 @@ function float() {
811
865
  /**
812
866
  * Returns a deterministic random integer in [min, maxExclusive).
813
867
  */
814
- function int(maxExclusive, min$1 = 0) {
815
- return Math.floor(float() * (maxExclusive - min$1)) + min$1;
868
+ function int(maxExclusive, min = 0) {
869
+ return Math.floor(float() * (maxExclusive - min)) + min;
816
870
  }
817
871
  /**
818
872
  * Returns a deterministic random boolean.
@@ -925,12 +979,12 @@ const transformAddress = (val, ctx) => {
925
979
 
926
980
  //#endregion
927
981
  //#region src/core/LLTV.ts
928
- var LLTV_exports = /* @__PURE__ */ __export({
982
+ var LLTV_exports = /* @__PURE__ */ __exportAll({
929
983
  InvalidLLTVError: () => InvalidLLTVError,
930
984
  InvalidOptionError: () => InvalidOptionError$1,
931
985
  LLTVSchema: () => LLTVSchema,
932
986
  Options: () => Options,
933
- from: () => from$12
987
+ from: () => from$13
934
988
  });
935
989
  const Options = [
936
990
  .385,
@@ -949,7 +1003,7 @@ const LLTV_SCALED = Options.map((lltv) => BigInt(lltv * 10 ** 18));
949
1003
  * @param lltv - The LLTV option or the scaled LLTV.
950
1004
  * @returns The LLTV.
951
1005
  */
952
- function from$12(lltv) {
1006
+ function from$13(lltv) {
953
1007
  if (typeof lltv === "bigint" && !LLTV_SCALED.includes(lltv)) throw new InvalidLLTVError(lltv);
954
1008
  if (typeof lltv === "bigint") return lltv;
955
1009
  if (typeof lltv === "number" && !Options.includes(lltv)) throw new InvalidOptionError$1(lltv);
@@ -969,21 +1023,21 @@ var InvalidLLTVError = class extends BaseError {
969
1023
  };
970
1024
  const LLTVSchema = zod.bigint({ coerce: true }).refine((lltv) => {
971
1025
  try {
972
- from$12(lltv);
1026
+ from$13(lltv);
973
1027
  return true;
974
1028
  } catch (_) {
975
1029
  return false;
976
1030
  }
977
1031
  }, { error: () => {
978
1032
  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)";
979
- } }).transform((lltv) => from$12(lltv));
1033
+ } }).transform((lltv) => from$13(lltv));
980
1034
 
981
1035
  //#endregion
982
1036
  //#region src/core/Collateral.ts
983
- var Collateral_exports = /* @__PURE__ */ __export({
1037
+ var Collateral_exports = /* @__PURE__ */ __exportAll({
984
1038
  CollateralSchema: () => CollateralSchema,
985
1039
  CollateralsSchema: () => CollateralsSchema,
986
- from: () => from$11,
1040
+ from: () => from$12,
987
1041
  random: () => random$3
988
1042
  });
989
1043
  const CollateralSchema = zod.object({
@@ -1003,10 +1057,10 @@ const CollateralsSchema = zod.array(CollateralSchema).min(1, { message: "At leas
1003
1057
  }
1004
1058
  return true;
1005
1059
  }, { message: "Collaterals must not contain duplicate assets" });
1006
- const from$11 = (parameters) => {
1060
+ const from$12 = (parameters) => {
1007
1061
  return {
1008
1062
  asset: parameters.asset.toLowerCase(),
1009
- lltv: from$12(parameters.lltv),
1063
+ lltv: from$13(parameters.lltv),
1010
1064
  oracle: parameters.oracle.toLowerCase()
1011
1065
  };
1012
1066
  };
@@ -1020,7 +1074,7 @@ const from$11 = (parameters) => {
1020
1074
  * ```
1021
1075
  */
1022
1076
  function random$3() {
1023
- return from$11({
1077
+ return from$12({
1024
1078
  asset: address(),
1025
1079
  oracle: address(),
1026
1080
  lltv: .965
@@ -1029,7 +1083,7 @@ function random$3() {
1029
1083
 
1030
1084
  //#endregion
1031
1085
  //#region src/core/ERC4626.ts
1032
- var ERC4626_exports = /* @__PURE__ */ __export({
1086
+ var ERC4626_exports = /* @__PURE__ */ __exportAll({
1033
1087
  DenominatorIsZeroError: () => DenominatorIsZeroError,
1034
1088
  convertToAssets: () => convertToAssets,
1035
1089
  convertToShares: () => convertToShares,
@@ -1092,7 +1146,7 @@ var DenominatorIsZeroError = class extends BaseError {
1092
1146
 
1093
1147
  //#endregion
1094
1148
  //#region src/core/Liquidity.ts
1095
- var Liquidity_exports = /* @__PURE__ */ __export({
1149
+ var Liquidity_exports = /* @__PURE__ */ __exportAll({
1096
1150
  calculateMaxDebt: () => calculateMaxDebt,
1097
1151
  generateAllowancePoolId: () => generateAllowancePoolId,
1098
1152
  generateBalancePoolId: () => generateBalancePoolId,
@@ -1118,23 +1172,23 @@ function calculateMaxDebt(amount, oraclePrice, lltv) {
1118
1172
  * Generate pool ID for balance pools.
1119
1173
  */
1120
1174
  function generateBalancePoolId(parameters) {
1121
- const { user, chainId, token: token$1 } = parameters;
1122
- return `${user}-${chainId.toString()}-${token$1}-balance`.toLowerCase();
1175
+ const { user, chainId, token } = parameters;
1176
+ return `${user}-${chainId.toString()}-${token}-balance`.toLowerCase();
1123
1177
  }
1124
1178
  /**
1125
1179
  * Generate pool ID for allowance pools.
1126
1180
  */
1127
1181
  function generateAllowancePoolId(parameters) {
1128
- const { user, chainId, token: token$1 } = parameters;
1129
- return `${user}-${chainId.toString()}-${token$1}-allowance`.toLowerCase();
1182
+ const { user, chainId, token } = parameters;
1183
+ return `${user}-${chainId.toString()}-${token}-allowance`.toLowerCase();
1130
1184
  }
1131
1185
  /**
1132
1186
  * Generate pool ID for sell ERC20 callback pools.
1133
1187
  * Each offer has its own callback pool to prevent liquidity conflicts.
1134
1188
  */
1135
1189
  function generateSellERC20CallbackPoolId(parameters) {
1136
- const { user, chainId, obligationId: obligationId$1, token: token$1, offerHash } = parameters;
1137
- return `${user}-${chainId.toString()}-${obligationId$1}-${token$1}-${offerHash}-sell_erc20_callback`.toLowerCase();
1190
+ const { user, chainId, obligationId, token, offerHash } = parameters;
1191
+ return `${user}-${chainId.toString()}-${obligationId}-${token}-${offerHash}-sell_erc20_callback`.toLowerCase();
1138
1192
  }
1139
1193
  /**
1140
1194
  * Generate pool ID for obligation collateral pools.
@@ -1142,22 +1196,22 @@ function generateSellERC20CallbackPoolId(parameters) {
1142
1196
  * These pools are shared across all offers with the same obligation.
1143
1197
  */
1144
1198
  function generateObligationCollateralPoolId(parameters) {
1145
- const { user, chainId, obligationId: obligationId$1, token: token$1 } = parameters;
1146
- return `${user}-${chainId.toString()}-${obligationId$1}-${token$1}-obligation-collateral`.toLowerCase();
1199
+ const { user, chainId, obligationId, token } = parameters;
1200
+ return `${user}-${chainId.toString()}-${obligationId}-${token}-obligation-collateral`.toLowerCase();
1147
1201
  }
1148
1202
  /**
1149
1203
  * Generate pool ID for buy vault callback pools.
1150
1204
  */
1151
1205
  function generateBuyVaultCallbackPoolId(parameters) {
1152
1206
  const { user, chainId, vault, offerHash } = parameters;
1153
- return `${user}-${chainId.toString()}-${vault}-${offerHash}-${CallbackType.BuyVaultV1Callback}`.toLowerCase();
1207
+ return `${user}-${chainId.toString()}-${vault}-${offerHash}-${Type$1.BuyVaultV1Callback}`.toLowerCase();
1154
1208
  }
1155
1209
  /**
1156
1210
  * Generate pool ID for debt pools.
1157
1211
  */
1158
1212
  function generateDebtPoolId(parameters) {
1159
- const { user, chainId, obligationId: obligationId$1 } = parameters;
1160
- return `${user}-${chainId.toString()}-${obligationId$1}-debt`.toLowerCase();
1213
+ const { user, chainId, obligationId } = parameters;
1214
+ return `${user}-${chainId.toString()}-${obligationId}-debt`.toLowerCase();
1161
1215
  }
1162
1216
  /**
1163
1217
  * Generate pool ID for user position in a vault.
@@ -1183,17 +1237,17 @@ function generateMarketLiquidityPoolId(parameters) {
1183
1237
 
1184
1238
  //#endregion
1185
1239
  //#region src/core/Maturity.ts
1186
- var Maturity_exports = /* @__PURE__ */ __export({
1240
+ var Maturity_exports = /* @__PURE__ */ __exportAll({
1187
1241
  InvalidDateError: () => InvalidDateError,
1188
1242
  InvalidFormatError: () => InvalidFormatError,
1189
1243
  InvalidOptionError: () => InvalidOptionError,
1190
1244
  MaturitySchema: () => MaturitySchema,
1191
1245
  MaturityType: () => MaturityType,
1192
- from: () => from$10
1246
+ from: () => from$11
1193
1247
  });
1194
- const MaturitySchema = zod.number().int().refine((maturity$1) => {
1248
+ const MaturitySchema = zod.number().int().refine((maturity) => {
1195
1249
  try {
1196
- from$10(maturity$1);
1250
+ from$11(maturity);
1197
1251
  return true;
1198
1252
  } catch (_e) {
1199
1253
  return false;
@@ -1204,15 +1258,15 @@ const MaturitySchema = zod.number().int().refine((maturity$1) => {
1204
1258
  } catch (_) {
1205
1259
  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).`;
1206
1260
  }
1207
- } }).transform((maturity$1) => maturity$1);
1208
- let MaturityType = /* @__PURE__ */ function(MaturityType$1) {
1209
- MaturityType$1["EndOfWeek"] = "end_of_week";
1210
- MaturityType$1["EndOfNextWeek"] = "end_of_next_week";
1211
- MaturityType$1["EndOfMonth"] = "end_of_month";
1212
- MaturityType$1["EndOfNextMonth"] = "end_of_next_month";
1213
- MaturityType$1["EndOfQuarter"] = "end_of_quarter";
1214
- MaturityType$1["EndOfNextQuarter"] = "end_of_next_quarter";
1215
- return MaturityType$1;
1261
+ } }).transform((maturity) => maturity);
1262
+ let MaturityType = /* @__PURE__ */ function(MaturityType) {
1263
+ MaturityType["EndOfWeek"] = "end_of_week";
1264
+ MaturityType["EndOfNextWeek"] = "end_of_next_week";
1265
+ MaturityType["EndOfMonth"] = "end_of_month";
1266
+ MaturityType["EndOfNextMonth"] = "end_of_next_month";
1267
+ MaturityType["EndOfQuarter"] = "end_of_quarter";
1268
+ MaturityType["EndOfNextQuarter"] = "end_of_next_quarter";
1269
+ return MaturityType;
1216
1270
  }({});
1217
1271
  const MaturityOptions = {
1218
1272
  end_of_week: () => endOfWeek(),
@@ -1228,7 +1282,7 @@ const MaturityOptions = {
1228
1282
  * @throws {InvalidDateError} If the maturity is in seconds but not a valid date.
1229
1283
  * @throws {InvalidOptionError} If the maturity is not a valid option.
1230
1284
  */
1231
- function from$10(ts) {
1285
+ function from$11(ts) {
1232
1286
  if (typeof ts === "string") {
1233
1287
  if (ts in MaturityOptions) return MaturityOptions[ts]();
1234
1288
  throw new InvalidOptionError(ts);
@@ -1246,23 +1300,23 @@ const endOfNextWeek = () => fridayOfWeek(1);
1246
1300
  * on that Friday), roll to the next month's last Friday.
1247
1301
  */
1248
1302
  const endOfMonth = () => {
1249
- const now$1 = /* @__PURE__ */ new Date();
1250
- const year = now$1.getUTCFullYear();
1251
- const month = now$1.getUTCMonth();
1252
- const endOfMonth$1 = lastFridayOfMonth(year, month);
1253
- if (now$1.getTime() > endOfMonth$1 * 1e3) return lastFridayOfMonth(year, month + 1);
1254
- return endOfMonth$1;
1303
+ const now = /* @__PURE__ */ new Date();
1304
+ const year = now.getUTCFullYear();
1305
+ const month = now.getUTCMonth();
1306
+ const endOfMonth = lastFridayOfMonth(year, month);
1307
+ if (now.getTime() > endOfMonth * 1e3) return lastFridayOfMonth(year, month + 1);
1308
+ return endOfMonth;
1255
1309
  };
1256
1310
  /** Returns the end of the next month (last friday of the next month at 15:00:00 UTC)
1257
1311
  * Business rule: if we are after the last Friday of the current month (strictly after 15:00 UTC
1258
1312
  * on that Friday), we consider being in the next month already, so "next month" becomes month+2.
1259
1313
  */
1260
1314
  const endOfNextMonth = () => {
1261
- const now$1 = /* @__PURE__ */ new Date();
1262
- const year = now$1.getUTCFullYear();
1263
- const month = now$1.getUTCMonth();
1264
- const endOfMonth$1 = lastFridayOfMonth(year, month);
1265
- if (now$1.getTime() > endOfMonth$1 * 1e3) return lastFridayOfMonth(year, month + 2);
1315
+ const now = /* @__PURE__ */ new Date();
1316
+ const year = now.getUTCFullYear();
1317
+ const month = now.getUTCMonth();
1318
+ const endOfMonth = lastFridayOfMonth(year, month);
1319
+ if (now.getTime() > endOfMonth * 1e3) return lastFridayOfMonth(year, month + 2);
1266
1320
  return lastFridayOfMonth(year, month + 1);
1267
1321
  };
1268
1322
  /** Returns the end of the current quarter (last friday of the quarter at 15:00:00 UTC) */
@@ -1270,10 +1324,10 @@ const endOfQuarter = () => lastFridayOfQuarter(0);
1270
1324
  /** Returns the end of the next quarter (last friday of the next quarter at 15:00:00 UTC) */
1271
1325
  const endOfNextQuarter = () => lastFridayOfQuarter(1);
1272
1326
  const fridayOfWeek = (weeksAhead = 0) => {
1273
- const now$1 = /* @__PURE__ */ new Date();
1274
- const today15H = new Date(Date.UTC(now$1.getUTCFullYear(), now$1.getUTCMonth(), now$1.getUTCDate(), 15));
1327
+ const now = /* @__PURE__ */ new Date();
1328
+ const today15H = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), 15));
1275
1329
  let daysUntilFriday = (5 - today15H.getUTCDay() + 7) % 7;
1276
- if (daysUntilFriday === 0 && now$1.getTime() >= today15H.getTime()) daysUntilFriday = 7;
1330
+ if (daysUntilFriday === 0 && now.getTime() >= today15H.getTime()) daysUntilFriday = 7;
1277
1331
  const friday = new Date(today15H);
1278
1332
  friday.setUTCDate(friday.getUTCDate() + daysUntilFriday + weeksAhead * 7);
1279
1333
  return friday.getTime() / 1e3;
@@ -1284,9 +1338,9 @@ const lastFridayOfMonth = (year, month) => {
1284
1338
  return lastDayOfMonth15H.setUTCDate(lastDayOfMonth15H.getUTCDate()) / 1e3;
1285
1339
  };
1286
1340
  const lastFridayOfQuarter = (quartersAhead = 0) => {
1287
- const now$1 = /* @__PURE__ */ new Date();
1288
- const quarterIndex = Math.floor(now$1.getUTCMonth() / 3) + quartersAhead;
1289
- return lastFridayOfMonth(now$1.getUTCFullYear() + Math.floor(quarterIndex / 4), quarterIndex % 4 * 3 + 2);
1341
+ const now = /* @__PURE__ */ new Date();
1342
+ const quarterIndex = Math.floor(now.getUTCMonth() / 3) + quartersAhead;
1343
+ return lastFridayOfMonth(now.getUTCFullYear() + Math.floor(quarterIndex / 4), quarterIndex % 4 * 3 + 2);
1290
1344
  };
1291
1345
  var InvalidFormatError = class extends BaseError {
1292
1346
  constructor() {
@@ -1309,7 +1363,7 @@ var InvalidOptionError = class extends BaseError {
1309
1363
 
1310
1364
  //#endregion
1311
1365
  //#region src/utils/Format.ts
1312
- var Format_exports = /* @__PURE__ */ __export({
1366
+ var Format_exports = /* @__PURE__ */ __exportAll({
1313
1367
  fromSnakeCase: () => fromSnakeCase$3,
1314
1368
  stringifyBigint: () => stringifyBigint,
1315
1369
  toSnakeCase: () => toSnakeCase$1
@@ -1354,11 +1408,11 @@ function stringifyBigint(value) {
1354
1408
 
1355
1409
  //#endregion
1356
1410
  //#region src/core/Obligation.ts
1357
- var Obligation_exports = /* @__PURE__ */ __export({
1411
+ var Obligation_exports = /* @__PURE__ */ __exportAll({
1358
1412
  CollateralsAreNotSortedError: () => CollateralsAreNotSortedError,
1359
1413
  InvalidObligationError: () => InvalidObligationError,
1360
1414
  ObligationSchema: () => ObligationSchema,
1361
- from: () => from$9,
1415
+ from: () => from$10,
1362
1416
  fromSnakeCase: () => fromSnakeCase$2,
1363
1417
  id: () => id,
1364
1418
  random: () => random$2
@@ -1392,11 +1446,11 @@ const ObligationSchema = zod.object({
1392
1446
  * });
1393
1447
  * ```
1394
1448
  */
1395
- function from$9(parameters) {
1449
+ function from$10(parameters) {
1396
1450
  try {
1397
1451
  const parsedObligation = ObligationSchema.parse({
1398
1452
  ...parameters,
1399
- maturity: from$10(parameters.maturity)
1453
+ maturity: from$11(parameters.maturity)
1400
1454
  });
1401
1455
  return {
1402
1456
  chainId: parsedObligation.chainId,
@@ -1415,7 +1469,7 @@ function from$9(parameters) {
1415
1469
  * @returns The created obligation. {@link fromSnakeCase.ReturnType}
1416
1470
  */
1417
1471
  function fromSnakeCase$2(input) {
1418
- return from$9(fromSnakeCase$3(input));
1472
+ return from$10(fromSnakeCase$3(input));
1419
1473
  }
1420
1474
  /**
1421
1475
  * Calculates the obligation id based on the smart contract's Obligation struct.
@@ -1480,11 +1534,11 @@ function id(parameters) {
1480
1534
  * ```
1481
1535
  */
1482
1536
  function random$2() {
1483
- return from$9({
1537
+ return from$10({
1484
1538
  chainId: 1,
1485
1539
  loanToken: address(),
1486
1540
  collaterals: [random$3()],
1487
- maturity: from$10("end_of_next_quarter")
1541
+ maturity: from$11("end_of_next_quarter")
1488
1542
  });
1489
1543
  }
1490
1544
  var InvalidObligationError = class extends BaseError {
@@ -1502,7 +1556,7 @@ var CollateralsAreNotSortedError = class extends BaseError {
1502
1556
 
1503
1557
  //#endregion
1504
1558
  //#region src/core/Tree.ts
1505
- var Tree_exports = /* @__PURE__ */ __export({
1559
+ var Tree_exports = /* @__PURE__ */ __exportAll({
1506
1560
  DecodeError: () => DecodeError,
1507
1561
  EncodeError: () => EncodeError,
1508
1562
  TreeError: () => TreeError,
@@ -1510,11 +1564,11 @@ var Tree_exports = /* @__PURE__ */ __export({
1510
1564
  decode: () => decode$1,
1511
1565
  encode: () => encode$1,
1512
1566
  encodeUnsigned: () => encodeUnsigned,
1513
- from: () => from$8,
1567
+ from: () => from$9,
1514
1568
  proofs: () => proofs
1515
1569
  });
1516
1570
  const VERSION = 1;
1517
- const normalizeHash = (hash$1) => hash$1.toLowerCase();
1571
+ const normalizeHash = (hash) => hash.toLowerCase();
1518
1572
  /**
1519
1573
  * Builds a Merkle tree from a list of offers.
1520
1574
  *
@@ -1526,9 +1580,9 @@ const normalizeHash = (hash$1) => hash$1.toLowerCase();
1526
1580
  * @returns A `StandardMerkleTree` of `bytes32` leaves representing the offers.
1527
1581
  * @throws {TreeError} If tree building fails due to offer inconsistencies.
1528
1582
  */
1529
- const from$8 = (offers) => {
1583
+ const from$9 = (offers) => {
1530
1584
  const leaves = offers.map((offer) => [hash(offer)]);
1531
- const tree = __openzeppelin_merkle_tree.StandardMerkleTree.of(leaves, ["bytes32"]);
1585
+ const tree = _openzeppelin_merkle_tree.StandardMerkleTree.of(leaves, ["bytes32"]);
1532
1586
  const orderedOffers = orderOffers(tree, offers);
1533
1587
  return Object.assign(tree, { offers: orderedOffers });
1534
1588
  };
@@ -1536,9 +1590,9 @@ const orderOffers = (tree, offers) => {
1536
1590
  const offerByHash = /* @__PURE__ */ new Map();
1537
1591
  for (const offer of offers) offerByHash.set(normalizeHash(hash(offer)), offer);
1538
1592
  const entries = tree.dump().values.map((value) => {
1539
- const hash$1 = normalizeHash(value.value[0]);
1540
- const offer = offerByHash.get(hash$1);
1541
- if (!offer) throw new TreeError(`missing offer for leaf ${hash$1}`);
1593
+ const hash = normalizeHash(value.value[0]);
1594
+ const offer = offerByHash.get(hash);
1595
+ if (!offer) throw new TreeError(`missing offer for leaf ${hash}`);
1542
1596
  return {
1543
1597
  offer,
1544
1598
  treeIndex: value.treeIndex
@@ -1571,10 +1625,10 @@ const assertHex = (value, expectedBytes, name) => {
1571
1625
  const verifySignatureAndRecoverAddress = async (params) => {
1572
1626
  const { root, signature } = params;
1573
1627
  assertHex(signature, 65, "signature");
1574
- const hash$1 = (0, viem.hashMessage)({ raw: root });
1628
+ const hash = (0, viem.hashMessage)({ raw: root });
1575
1629
  try {
1576
1630
  return await (0, viem.recoverAddress)({
1577
- hash: hash$1,
1631
+ hash,
1578
1632
  signature
1579
1633
  });
1580
1634
  } catch {
@@ -1648,7 +1702,7 @@ const encodeUnsigned = (tree) => {
1648
1702
  };
1649
1703
  const validateTreeForEncoding = (tree) => {
1650
1704
  if (VERSION > 255) throw new EncodeError(`version overflow: ${VERSION} exceeds 255`);
1651
- const computed = from$8(tree.offers);
1705
+ const computed = from$9(tree.offers);
1652
1706
  if (tree.root !== computed.root) throw new EncodeError(`root mismatch: expected ${computed.root}, got ${tree.root}`);
1653
1707
  };
1654
1708
  const encodeUnsignedBytes = (tree) => {
@@ -1684,19 +1738,19 @@ const encodeUnsignedBytes = (tree) => {
1684
1738
  * @throws {DecodeError} If version invalid, signature invalid, or root mismatch
1685
1739
  */
1686
1740
  const decode$1 = async (encoded) => {
1687
- const bytes$1 = (0, viem.hexToBytes)(encoded);
1688
- if (bytes$1.length < 98) throw new DecodeError("payload too short");
1689
- const version = bytes$1[0];
1741
+ const bytes = (0, viem.hexToBytes)(encoded);
1742
+ if (bytes.length < 98) throw new DecodeError("payload too short");
1743
+ const version = bytes[0];
1690
1744
  if (version !== (VERSION & 255)) throw new DecodeError(`invalid version: expected ${VERSION}, got ${version ?? 0}`);
1691
- const signature = (0, viem.bytesToHex)(bytes$1.slice(-65));
1692
- const root = (0, viem.bytesToHex)(bytes$1.slice(-97, -65));
1745
+ const signature = (0, viem.bytesToHex)(bytes.slice(-65));
1746
+ const root = (0, viem.bytesToHex)(bytes.slice(-97, -65));
1693
1747
  assertHex(root, 32, "root");
1694
1748
  assertHex(signature, 65, "signature");
1695
1749
  const signer = await verifySignatureAndRecoverAddress({
1696
1750
  root,
1697
1751
  signature
1698
1752
  });
1699
- const compressed = bytes$1.slice(1, -97);
1753
+ const compressed = bytes.slice(1, -97);
1700
1754
  let decoded;
1701
1755
  try {
1702
1756
  decoded = (0, pako.ungzip)(compressed, { to: "string" });
@@ -1709,7 +1763,7 @@ const decode$1 = async (encoded) => {
1709
1763
  } catch {
1710
1764
  throw new DecodeError("JSON parse failed");
1711
1765
  }
1712
- const tree = from$8(rawOffers.map((o) => OfferSchema().parse(o)));
1766
+ const tree = from$9(rawOffers.map((o) => OfferSchema().parse(o)));
1713
1767
  if (root !== tree.root) throw new DecodeError(`root mismatch: expected ${tree.root}, got ${root}`);
1714
1768
  return {
1715
1769
  tree,
@@ -1750,7 +1804,7 @@ var DecodeError = class extends BaseError {
1750
1804
 
1751
1805
  //#endregion
1752
1806
  //#region src/core/Offer.ts
1753
- var Offer_exports = /* @__PURE__ */ __export({
1807
+ var Offer_exports = /* @__PURE__ */ __exportAll({
1754
1808
  AccountNotSetError: () => AccountNotSetError,
1755
1809
  InvalidOfferError: () => InvalidOfferError,
1756
1810
  OfferSchema: () => OfferSchema,
@@ -1759,7 +1813,7 @@ var Offer_exports = /* @__PURE__ */ __export({
1759
1813
  decode: () => decode,
1760
1814
  domain: () => domain,
1761
1815
  encode: () => encode,
1762
- from: () => from$7,
1816
+ from: () => from$8,
1763
1817
  fromSnakeCase: () => fromSnakeCase$1,
1764
1818
  hash: () => hash,
1765
1819
  obligationId: () => obligationId,
@@ -1772,10 +1826,10 @@ var Offer_exports = /* @__PURE__ */ __export({
1772
1826
  });
1773
1827
  /** Internal symbol for caching the computed hash. */
1774
1828
  const HASH_CACHE = Symbol("offer.hash");
1775
- let Status = /* @__PURE__ */ function(Status$1) {
1776
- Status$1["VALID"] = "VALID";
1777
- Status$1["SIMULATION_ERROR"] = "SIMULATION_ERROR";
1778
- return Status$1;
1829
+ let Status = /* @__PURE__ */ function(Status) {
1830
+ Status["VALID"] = "VALID";
1831
+ Status["SIMULATION_ERROR"] = "SIMULATION_ERROR";
1832
+ return Status;
1779
1833
  }({});
1780
1834
  const OfferSchema = () => {
1781
1835
  return zod.object({
@@ -1819,7 +1873,7 @@ const OfferSchema = () => {
1819
1873
  * @param input - The offer to create.
1820
1874
  * @returns The created offer.
1821
1875
  */
1822
- function from$7(input) {
1876
+ function from$8(input) {
1823
1877
  try {
1824
1878
  return OfferSchema().parse(input);
1825
1879
  } catch (error) {
@@ -1833,7 +1887,7 @@ function from$7(input) {
1833
1887
  * @returns The created offer.
1834
1888
  */
1835
1889
  function fromSnakeCase$1(input) {
1836
- return from$7(fromSnakeCase$3(input));
1890
+ return from$8(fromSnakeCase$3(input));
1837
1891
  }
1838
1892
  /**
1839
1893
  * Converts an offer to a snake case object.
@@ -1887,8 +1941,8 @@ function random$1(config) {
1887
1941
  const collateralCandidates = config?.collateralTokens ? config.collateralTokens.filter((a) => a !== loanToken) : [address()];
1888
1942
  const collateralAsset = collateralCandidates[int(collateralCandidates.length)];
1889
1943
  const maturityOption = weightedChoice([["end_of_month", 1], ["end_of_next_month", 1]]);
1890
- const maturity$1 = config?.maturity ?? from$10(maturityOption);
1891
- const lltv = from$12(weightedChoice([
1944
+ const maturity = config?.maturity ?? from$11(maturityOption);
1945
+ const lltv = from$13(weightedChoice([
1892
1946
  [.385, 1],
1893
1947
  [.5, 1],
1894
1948
  [.625, 2],
@@ -1927,15 +1981,15 @@ function random$1(config) {
1927
1981
  })
1928
1982
  };
1929
1983
  })();
1930
- return from$7({
1984
+ return from$8({
1931
1985
  maker: config?.maker ?? address(),
1932
1986
  assets: assetsScaled,
1933
1987
  obligationUnits: config?.obligationUnits ?? 0n,
1934
1988
  obligationShares: config?.obligationShares ?? 0n,
1935
1989
  price,
1936
- maturity: maturity$1,
1937
- expiry: config?.expiry ?? maturity$1 - 1,
1938
- start: config?.start ?? maturity$1 - 10,
1990
+ maturity,
1991
+ expiry: config?.expiry ?? maturity - 1,
1992
+ start: config?.start ?? maturity - 10,
1939
1993
  group: config?.group ?? hex(32),
1940
1994
  session: config?.session ?? hex(32),
1941
1995
  buy,
@@ -2070,7 +2124,7 @@ async function sign(offers, wallet) {
2070
2124
  });
2071
2125
  }
2072
2126
  function signatureMsg(offers) {
2073
- return from$8(offers).root;
2127
+ return from$9(offers).root;
2074
2128
  }
2075
2129
  function hash(offer) {
2076
2130
  const cached = offer[HASH_CACHE];
@@ -2108,7 +2162,7 @@ function hash(offer) {
2108
2162
  * @returns The obligation id as a 32-byte hex string.
2109
2163
  */
2110
2164
  function obligationId(offer) {
2111
- return id(from$9({
2165
+ return id(from$10({
2112
2166
  chainId: offer.chainId,
2113
2167
  loanToken: offer.loanToken,
2114
2168
  collaterals: offer.collaterals,
@@ -2224,13 +2278,13 @@ function decode(data) {
2224
2278
  } catch (error) {
2225
2279
  throw new InvalidOfferError(error);
2226
2280
  }
2227
- return from$7({
2281
+ return from$8({
2228
2282
  maker: decoded[0],
2229
2283
  assets: decoded[1],
2230
2284
  obligationUnits: decoded[2],
2231
2285
  obligationShares: decoded[3],
2232
2286
  price: decoded[4],
2233
- maturity: from$10(Number(decoded[5])),
2287
+ maturity: from$11(Number(decoded[5])),
2234
2288
  expiry: Number(decoded[6]),
2235
2289
  group: decoded[7],
2236
2290
  session: decoded[8],
@@ -2239,7 +2293,7 @@ function decode(data) {
2239
2293
  loanToken: decoded[11],
2240
2294
  start: Number(decoded[12]),
2241
2295
  collaterals: decoded[13].map((c) => {
2242
- return from$11({
2296
+ return from$12({
2243
2297
  asset: c.asset,
2244
2298
  oracle: c.oracle,
2245
2299
  lltv: c.lltv
@@ -2312,16 +2366,16 @@ var AccountNotSetError = class extends BaseError {
2312
2366
 
2313
2367
  //#endregion
2314
2368
  //#region src/core/Oracle.ts
2315
- var Oracle_exports = /* @__PURE__ */ __export({
2369
+ var Oracle_exports = /* @__PURE__ */ __exportAll({
2316
2370
  Conversion: () => Conversion,
2317
- from: () => from$6
2371
+ from: () => from$7
2318
2372
  });
2319
2373
  /**
2320
2374
  * Create an Oracle from a plain object.
2321
2375
  * @param data - The data to create the oracle from.
2322
2376
  * @returns The created oracle.
2323
2377
  */
2324
- function from$6(data) {
2378
+ function from$7(data) {
2325
2379
  return {
2326
2380
  chainId: data.chainId,
2327
2381
  address: data.address.toLowerCase(),
@@ -2344,14 +2398,14 @@ let Conversion;
2344
2398
 
2345
2399
  //#endregion
2346
2400
  //#region src/core/Position.ts
2347
- var Position_exports = /* @__PURE__ */ __export({
2401
+ var Position_exports = /* @__PURE__ */ __exportAll({
2348
2402
  Type: () => Type,
2349
- from: () => from$5
2403
+ from: () => from$6
2350
2404
  });
2351
- let Type = /* @__PURE__ */ function(Type$1) {
2352
- Type$1["ERC20"] = "erc20";
2353
- Type$1["VAULT_V1"] = "vault_v1";
2354
- return Type$1;
2405
+ let Type = /* @__PURE__ */ function(Type) {
2406
+ Type["ERC20"] = "erc20";
2407
+ Type["VAULT_V1"] = "vault_v1";
2408
+ return Type;
2355
2409
  }({});
2356
2410
  /**
2357
2411
  * @constructor
@@ -2359,7 +2413,7 @@ let Type = /* @__PURE__ */ function(Type$1) {
2359
2413
  * @param parameters - {@link from.Parameters}
2360
2414
  * @returns The created Position. {@link from.ReturnType}
2361
2415
  */
2362
- function from$5(parameters) {
2416
+ function from$6(parameters) {
2363
2417
  return {
2364
2418
  chainId: parameters.chainId,
2365
2419
  contract: parameters.contract.toLowerCase(),
@@ -2373,10 +2427,10 @@ function from$5(parameters) {
2373
2427
 
2374
2428
  //#endregion
2375
2429
  //#region src/core/Quote.ts
2376
- var Quote_exports = /* @__PURE__ */ __export({
2430
+ var Quote_exports = /* @__PURE__ */ __exportAll({
2377
2431
  InvalidQuoteError: () => InvalidQuoteError,
2378
2432
  QuoteSchema: () => QuoteSchema,
2379
- from: () => from$4,
2433
+ from: () => from$5,
2380
2434
  fromSnakeCase: () => fromSnakeCase,
2381
2435
  random: () => random
2382
2436
  });
@@ -2397,7 +2451,7 @@ const QuoteSchema = zod.object({
2397
2451
  * const quote = Quote.from({ obligationId: "0x123", ask: { price: 100n }, bid: { price: 100n } });
2398
2452
  * ```
2399
2453
  */
2400
- function from$4(parameters) {
2454
+ function from$5(parameters) {
2401
2455
  try {
2402
2456
  const parsedQuote = QuoteSchema.parse(parameters);
2403
2457
  return {
@@ -2416,7 +2470,7 @@ function from$4(parameters) {
2416
2470
  * @returns The created quote. {@link fromSnakeCase.ReturnType}
2417
2471
  */
2418
2472
  function fromSnakeCase(snake) {
2419
- return from$4(fromSnakeCase$3(snake));
2473
+ return from$5(fromSnakeCase$3(snake));
2420
2474
  }
2421
2475
  /**
2422
2476
  * Generates a random quote.
@@ -2428,7 +2482,7 @@ function fromSnakeCase(snake) {
2428
2482
  * ```
2429
2483
  */
2430
2484
  function random() {
2431
- return from$4({
2485
+ return from$5({
2432
2486
  obligationId: id(random$2()),
2433
2487
  ask: { price: BigInt(int(1e6)) },
2434
2488
  bid: { price: BigInt(int(1e6)) }
@@ -2441,9 +2495,158 @@ var InvalidQuoteError = class extends BaseError {
2441
2495
  }
2442
2496
  };
2443
2497
 
2498
+ //#endregion
2499
+ //#region src/core/TradingFee.ts
2500
+ var TradingFee_exports = /* @__PURE__ */ __exportAll({
2501
+ BREAKPOINTS: () => BREAKPOINTS,
2502
+ InvalidFeeError: () => InvalidFeeError,
2503
+ InvalidFeesLengthError: () => InvalidFeesLengthError,
2504
+ WAD: () => WAD,
2505
+ activate: () => activate,
2506
+ compute: () => compute,
2507
+ deactivate: () => deactivate,
2508
+ from: () => from$4,
2509
+ getFees: () => getFees,
2510
+ isActivated: () => isActivated
2511
+ });
2512
+ /**
2513
+ * Time breakpoints in seconds for piecewise linear fee interpolation.
2514
+ * Matches on-chain constants: 0d, 1d, 7d, 30d, 90d, 180d.
2515
+ */
2516
+ const BREAKPOINTS = [
2517
+ 0n,
2518
+ 86400n,
2519
+ 604800n,
2520
+ 2592000n,
2521
+ 7776000n,
2522
+ 15552000n
2523
+ ];
2524
+ /** WAD constant (1e18) for fee scaling. */
2525
+ const WAD = 10n ** 18n;
2526
+ /**
2527
+ * Create a TradingFee from an activation flag and 6 fee values.
2528
+ * @param activated - Whether the fee is active.
2529
+ * @param fees - Tuple of 6 fee values in WAD (one per breakpoint: 0d, 1d, 7d, 30d, 90d, 180d).
2530
+ * @returns A new TradingFee instance.
2531
+ * @throws {@link InvalidFeeError} if any fee exceeds WAD (100%).
2532
+ * @throws {@link InvalidFeesLengthError} if fees array doesn't have exactly 6 elements.
2533
+ */
2534
+ function from$4(activated, fees) {
2535
+ if (fees.length !== 6) throw new InvalidFeesLengthError(fees.length);
2536
+ for (let i = 0; i < 6; i++) {
2537
+ const fee = fees[i];
2538
+ if (fee < 0n || fee > WAD) throw new InvalidFeeError(fee, i);
2539
+ }
2540
+ const frozenFees = Object.freeze([...fees]);
2541
+ return Object.freeze({
2542
+ _activated: activated,
2543
+ _fees: frozenFees
2544
+ });
2545
+ }
2546
+ /**
2547
+ * Compute the trading fee for a given time to maturity using piecewise linear interpolation.
2548
+ * @param tradingFee - The TradingFee instance.
2549
+ * @param timeToMaturity - Time to maturity in seconds.
2550
+ * @returns The interpolated fee in WAD. Returns 0n if not activated.
2551
+ */
2552
+ function compute(tradingFee, timeToMaturity) {
2553
+ if (!tradingFee._activated) return 0n;
2554
+ const time = BigInt(Math.max(0, Math.floor(timeToMaturity)));
2555
+ if (time >= BREAKPOINTS[5]) return tradingFee._fees[5];
2556
+ const { index, start, end } = getSegment(time);
2557
+ const feeLower = tradingFee._fees[index];
2558
+ const feeUpper = tradingFee._fees[index + 1];
2559
+ const segmentLength = end - start;
2560
+ return (feeLower * (end - time) + feeUpper * (time - start)) / segmentLength;
2561
+ }
2562
+ /**
2563
+ * Check if the trading fee is activated.
2564
+ * @param tradingFee - The TradingFee instance.
2565
+ * @returns True if activated, false otherwise.
2566
+ */
2567
+ function isActivated(tradingFee) {
2568
+ return tradingFee._activated;
2569
+ }
2570
+ /**
2571
+ * Create a new TradingFee with activation enabled.
2572
+ * @param tradingFee - The TradingFee instance.
2573
+ * @returns A new TradingFee with activated set to true.
2574
+ */
2575
+ function activate(tradingFee) {
2576
+ return Object.freeze({
2577
+ _activated: true,
2578
+ _fees: tradingFee._fees
2579
+ });
2580
+ }
2581
+ /**
2582
+ * Create a new TradingFee with activation disabled.
2583
+ * @param tradingFee - The TradingFee instance.
2584
+ * @returns A new TradingFee with activated set to false.
2585
+ */
2586
+ function deactivate(tradingFee) {
2587
+ return Object.freeze({
2588
+ _activated: false,
2589
+ _fees: tradingFee._fees
2590
+ });
2591
+ }
2592
+ /**
2593
+ * Get the fee values at each breakpoint.
2594
+ * @param tradingFee - The TradingFee instance.
2595
+ * @returns The tuple of 6 fee values.
2596
+ */
2597
+ function getFees(tradingFee) {
2598
+ return tradingFee._fees;
2599
+ }
2600
+ /**
2601
+ * Determine which segment a timeToMaturity falls into for interpolation.
2602
+ * @param timeToMaturity - Time to maturity in seconds.
2603
+ * @returns Object with index, start, and end of the segment.
2604
+ */
2605
+ function getSegment(timeToMaturity) {
2606
+ if (timeToMaturity < BREAKPOINTS[1]) return {
2607
+ index: 0,
2608
+ start: BREAKPOINTS[0],
2609
+ end: BREAKPOINTS[1]
2610
+ };
2611
+ if (timeToMaturity < BREAKPOINTS[2]) return {
2612
+ index: 1,
2613
+ start: BREAKPOINTS[1],
2614
+ end: BREAKPOINTS[2]
2615
+ };
2616
+ if (timeToMaturity < BREAKPOINTS[3]) return {
2617
+ index: 2,
2618
+ start: BREAKPOINTS[2],
2619
+ end: BREAKPOINTS[3]
2620
+ };
2621
+ if (timeToMaturity < BREAKPOINTS[4]) return {
2622
+ index: 3,
2623
+ start: BREAKPOINTS[3],
2624
+ end: BREAKPOINTS[4]
2625
+ };
2626
+ return {
2627
+ index: 4,
2628
+ start: BREAKPOINTS[4],
2629
+ end: BREAKPOINTS[5]
2630
+ };
2631
+ }
2632
+ /** Error thrown when a fee value is invalid (negative or exceeds WAD). */
2633
+ var InvalidFeeError = class extends BaseError {
2634
+ constructor(fee, index) {
2635
+ super(`Invalid fee at index ${index}: ${fee}. Fee must be between 0 and ${WAD} (WAD).`);
2636
+ _defineProperty(this, "name", "TradingFee.InvalidFeeError");
2637
+ }
2638
+ };
2639
+ /** Error thrown when fees array doesn't have exactly 6 elements. */
2640
+ var InvalidFeesLengthError = class extends BaseError {
2641
+ constructor(length) {
2642
+ super(`Invalid fees length: ${length}. Expected exactly 6 fee values.`);
2643
+ _defineProperty(this, "name", "TradingFee.InvalidFeesLengthError");
2644
+ }
2645
+ };
2646
+
2444
2647
  //#endregion
2445
2648
  //#region src/core/Transfer.ts
2446
- var Transfer_exports = /* @__PURE__ */ __export({ from: () => from$3 });
2649
+ var Transfer_exports = /* @__PURE__ */ __exportAll({ from: () => from$3 });
2447
2650
  /**
2448
2651
  * @constructor
2449
2652
  *
@@ -2474,7 +2677,7 @@ const BrandTypeId = Symbol.for("mempool/Brand");
2474
2677
 
2475
2678
  //#endregion
2476
2679
  //#region src/api/Schema/OfferResponse.ts
2477
- var OfferResponse_exports = /* @__PURE__ */ __export({ from: () => from$2 });
2680
+ var OfferResponse_exports = /* @__PURE__ */ __exportAll({ from: () => from$2 });
2478
2681
  /**
2479
2682
  * Creates an `OfferResponse` matching the Solidity Offer struct layout.
2480
2683
  * @constructor
@@ -2542,7 +2745,7 @@ const API_ERROR_CODES = [
2542
2745
  ];
2543
2746
 
2544
2747
  //#endregion
2545
- //#region \0@oxc-project+runtime@0.97.0/helpers/decorate.js
2748
+ //#region \0@oxc-project+runtime@0.110.0/helpers/decorate.js
2546
2749
  function __decorate(decorators, target, key, desc) {
2547
2750
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2548
2751
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -3163,7 +3366,7 @@ __decorate([(0, openapi_metadata_decorators.ApiProperty)({
3163
3366
  type: () => [BookLevelResponse],
3164
3367
  description: "Aggregated book levels grouped by computed price."
3165
3368
  })], BookListResponse.prototype, "data", void 0);
3166
- let BooksController = class BooksController$1 {
3369
+ let BooksController = class BooksController {
3167
3370
  async getBook() {}
3168
3371
  };
3169
3372
  __decorate([
@@ -3209,7 +3412,7 @@ BooksController = __decorate([(0, openapi_metadata_decorators.ApiTags)("Markets"
3209
3412
  description: "Bad Request",
3210
3413
  type: BadRequestResponse
3211
3414
  })], BooksController);
3212
- let ValidateController = class ValidateController$1 {
3415
+ let ValidateController = class ValidateController {
3213
3416
  async validateOffers() {}
3214
3417
  };
3215
3418
  __decorate([
@@ -3236,7 +3439,7 @@ ValidateController = __decorate([(0, openapi_metadata_decorators.ApiTags)("Make"
3236
3439
  description: "Bad Request",
3237
3440
  type: BadRequestResponse
3238
3441
  })], ValidateController);
3239
- let OffersController = class OffersController$1 {
3442
+ let OffersController = class OffersController {
3240
3443
  async getOffers() {}
3241
3444
  };
3242
3445
  __decorate([
@@ -3291,7 +3494,7 @@ OffersController = __decorate([(0, openapi_metadata_decorators.ApiTags)("Markets
3291
3494
  description: "Bad Request",
3292
3495
  type: BadRequestResponse
3293
3496
  })], OffersController);
3294
- let HealthController = class HealthController$1 {
3497
+ let HealthController = class HealthController {
3295
3498
  async getRouterStatus() {}
3296
3499
  async getCollectorsHealth() {}
3297
3500
  async getChainsHealth() {}
@@ -3357,31 +3560,17 @@ __decorate([
3357
3560
  })
3358
3561
  ], HealthController.prototype, "getChainsHealth", null);
3359
3562
  HealthController = __decorate([(0, openapi_metadata_decorators.ApiTags)("System")], HealthController);
3360
- const maturitiesExample = {
3361
- end_of_month: 1738335600,
3362
- end_of_next_month: 1740754800
3363
- };
3563
+ const callbacksExample = [Type$1.BuyWithEmptyCallback];
3364
3564
  const chainConfigExample = {
3365
3565
  chain_id: 505050505,
3366
3566
  contracts: { mempool: "0xD946246695A9259F3B33a78629026F61B3Ab40aF" },
3367
- maturities: maturitiesExample
3567
+ callbacks: callbacksExample
3368
3568
  };
3369
3569
  var ConfigContractsResponse = class {};
3370
3570
  __decorate([(0, openapi_metadata_decorators.ApiProperty)({
3371
3571
  type: "string",
3372
3572
  example: chainConfigExample.contracts.mempool
3373
3573
  })], ConfigContractsResponse.prototype, "mempool", void 0);
3374
- var MaturitiesResponse = class {};
3375
- __decorate([(0, openapi_metadata_decorators.ApiProperty)({
3376
- type: "number",
3377
- description: "Unix timestamp for end of current month maturity (last Friday 15:00 UTC).",
3378
- example: maturitiesExample.end_of_month
3379
- })], MaturitiesResponse.prototype, "end_of_month", void 0);
3380
- __decorate([(0, openapi_metadata_decorators.ApiProperty)({
3381
- type: "number",
3382
- description: "Unix timestamp for end of next month maturity (last Friday 15:00 UTC).",
3383
- example: maturitiesExample.end_of_next_month
3384
- })], MaturitiesResponse.prototype, "end_of_next_month", void 0);
3385
3574
  var ConfigDataResponse = class {};
3386
3575
  __decorate([(0, openapi_metadata_decorators.ApiProperty)({
3387
3576
  type: "number",
@@ -3389,10 +3578,11 @@ __decorate([(0, openapi_metadata_decorators.ApiProperty)({
3389
3578
  })], ConfigDataResponse.prototype, "chain_id", void 0);
3390
3579
  __decorate([(0, openapi_metadata_decorators.ApiProperty)({ type: () => ConfigContractsResponse })], ConfigDataResponse.prototype, "contracts", void 0);
3391
3580
  __decorate([(0, openapi_metadata_decorators.ApiProperty)({
3392
- type: () => MaturitiesResponse,
3393
- description: "Supported maturity timestamps. Offers must use one of these values.",
3394
- example: chainConfigExample.maturities
3395
- })], ConfigDataResponse.prototype, "maturities", void 0);
3581
+ type: () => [String],
3582
+ enum: Object.values(Type$1),
3583
+ description: "Supported callback types for this chain.",
3584
+ example: callbacksExample
3585
+ })], ConfigDataResponse.prototype, "callbacks", void 0);
3396
3586
  var ConfigSuccessResponse = class extends SuccessResponse {};
3397
3587
  __decorate([(0, openapi_metadata_decorators.ApiProperty)({
3398
3588
  type: "string",
@@ -3404,21 +3594,21 @@ __decorate([(0, openapi_metadata_decorators.ApiProperty)({
3404
3594
  description: "Array of chain configurations for all indexed chains.",
3405
3595
  example: [chainConfigExample]
3406
3596
  })], ConfigSuccessResponse.prototype, "data", void 0);
3407
- let ConfigController = class ConfigController$1 {
3597
+ let ConfigController = class ConfigController {
3408
3598
  async getConfig() {}
3409
3599
  };
3410
3600
  __decorate([(0, openapi_metadata_decorators.ApiOperation)({
3411
3601
  methods: ["get"],
3412
3602
  path: "/v1/config",
3413
3603
  summary: "Get router configuration",
3414
- description: "Returns chain configurations including contract addresses and supported maturity timestamps."
3604
+ description: "Returns chain configurations including contract addresses and supported callback types."
3415
3605
  }), (0, openapi_metadata_decorators.ApiResponse)({
3416
3606
  status: 200,
3417
3607
  description: "Success",
3418
3608
  type: ConfigSuccessResponse
3419
3609
  })], ConfigController.prototype, "getConfig", null);
3420
3610
  ConfigController = __decorate([(0, openapi_metadata_decorators.ApiTags)("System")], ConfigController);
3421
- let ObligationsController = class ObligationsController$1 {
3611
+ let ObligationsController = class ObligationsController {
3422
3612
  async getObligations() {}
3423
3613
  async getObligation() {}
3424
3614
  };
@@ -3442,32 +3632,40 @@ __decorate([
3442
3632
  description: "Maximum number of obligations to return."
3443
3633
  }),
3444
3634
  (0, openapi_metadata_decorators.ApiQuery)({
3445
- name: "chain",
3446
- type: "number",
3635
+ name: "chains",
3636
+ type: ["number"],
3447
3637
  required: false,
3448
- example: 1,
3449
- description: "Filter by chain ID."
3638
+ example: "1,8453",
3639
+ description: "Filter by chain IDs (comma-separated).",
3640
+ style: "form",
3641
+ explode: false
3450
3642
  }),
3451
3643
  (0, openapi_metadata_decorators.ApiQuery)({
3452
- name: "loan_token",
3453
- type: "string",
3644
+ name: "loan_tokens",
3645
+ type: ["string"],
3454
3646
  required: false,
3455
- example: "0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078",
3456
- description: "Filter by loan token address."
3647
+ example: "0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078,0x34Cf890dB685FC536E05652FB41f02090c3fb751",
3648
+ description: "Filter by loan token addresses (comma-separated).",
3649
+ style: "form",
3650
+ explode: false
3457
3651
  }),
3458
3652
  (0, openapi_metadata_decorators.ApiQuery)({
3459
- name: "collateral_token",
3460
- type: "string",
3653
+ name: "collateral_tokens",
3654
+ type: ["string"],
3461
3655
  required: false,
3462
- example: "0x34Cf890dB685FC536E05652FB41f02090c3fb751",
3463
- description: "Filter by collateral token (matches any collateral in the obligation)."
3656
+ example: "0x34Cf890dB685FC536E05652FB41f02090c3fb751,0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078",
3657
+ description: "Filter by collateral tokens (comma-separated, matches any collateral).",
3658
+ style: "form",
3659
+ explode: false
3464
3660
  }),
3465
3661
  (0, openapi_metadata_decorators.ApiQuery)({
3466
- name: "maturity",
3467
- type: "number",
3662
+ name: "maturities",
3663
+ type: ["number"],
3468
3664
  required: false,
3469
- example: 1761922800,
3470
- description: "Filter by exact maturity timestamp (unix seconds)."
3665
+ example: "1761922800,1764524800",
3666
+ description: "Filter by exact maturity timestamps (comma-separated, unix seconds).",
3667
+ style: "form",
3668
+ explode: false
3471
3669
  }),
3472
3670
  (0, openapi_metadata_decorators.ApiResponse)({
3473
3671
  status: 200,
@@ -3499,7 +3697,7 @@ ObligationsController = __decorate([(0, openapi_metadata_decorators.ApiTags)("Ma
3499
3697
  description: "Bad Request",
3500
3698
  type: BadRequestResponse
3501
3699
  })], ObligationsController);
3502
- let UsersController = class UsersController$1 {
3700
+ let UsersController = class UsersController {
3503
3701
  async getUserPositions() {}
3504
3702
  };
3505
3703
  __decorate([
@@ -3589,7 +3787,7 @@ const OpenApi = async (options = {}) => {
3589
3787
 
3590
3788
  //#endregion
3591
3789
  //#region src/api/Schema/PositionResponse.ts
3592
- var PositionResponse_exports = /* @__PURE__ */ __export({ from: () => from$1 });
3790
+ var PositionResponse_exports = /* @__PURE__ */ __exportAll({ from: () => from$1 });
3593
3791
  /**
3594
3792
  * Creates a `PositionResponse` from a `PositionWithReserved`.
3595
3793
  * @param position - {@link PositionWithReserved}
@@ -3620,6 +3818,15 @@ function isValidBase64urlJson(val) {
3620
3818
  return false;
3621
3819
  }
3622
3820
  }
3821
+ const csvArray = (schema) => zod.preprocess((value) => {
3822
+ if (value === void 0) return void 0;
3823
+ if (Array.isArray(value)) {
3824
+ if (value.some((item) => typeof item !== "string")) return value;
3825
+ return value.flatMap((item) => item.split(",")).map((item) => item.trim()).filter((item) => item.length > 0);
3826
+ }
3827
+ if (typeof value === "string") return value.split(",").map((item) => item.trim()).filter((item) => item.length > 0);
3828
+ return value;
3829
+ }, zod.array(schema)).optional();
3623
3830
  const PaginationQueryParams = zod.object({
3624
3831
  cursor: zod.string().optional().refine((val) => {
3625
3832
  if (!val) return true;
@@ -3670,21 +3877,21 @@ const GetObligationsQueryParams = zod.object({
3670
3877
  description: "Obligation id cursor",
3671
3878
  example: "0x1234567890123456789012345678901234567890123456789012345678901234"
3672
3879
  }),
3673
- chain: zod.string().regex(/^[1-9]\d*$/, { message: "Chain must be a positive integer" }).transform((val) => Number.parseInt(val, 10)).optional().meta({
3674
- description: "Filter by chain ID",
3675
- example: "1"
3880
+ chains: csvArray(zod.string().regex(/^[1-9]\d*$/, { message: "Chain must be a positive integer" }).transform((val) => Number.parseInt(val, 10))).meta({
3881
+ description: "Filter by chain IDs (comma-separated).",
3882
+ example: "1,8453"
3676
3883
  }),
3677
- loan_token: zod.string().regex(/^0x[a-fA-F0-9]{40}$/, { error: "Loan token must be a valid 20-byte address" }).transform((val) => val.toLowerCase()).optional().meta({
3678
- description: "Filter by loan token address",
3679
- example: "0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078"
3884
+ loan_tokens: csvArray(zod.string().regex(/^0x[a-fA-F0-9]{40}$/, { error: "Loan token must be a valid 20-byte address" }).transform((val) => val.toLowerCase())).meta({
3885
+ description: "Filter by loan token addresses (comma-separated).",
3886
+ example: "0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078,0x34Cf890dB685FC536E05652FB41f02090c3fb751"
3680
3887
  }),
3681
- collateral_token: zod.string().regex(/^0x[a-fA-F0-9]{40}$/, { error: "Collateral token must be a valid 20-byte address" }).transform((val) => val.toLowerCase()).optional().meta({
3682
- description: "Filter by collateral token (matches any collateral in the obligation)",
3683
- example: "0x34Cf890dB685FC536E05652FB41f02090c3fb751"
3888
+ collateral_tokens: csvArray(zod.string().regex(/^0x[a-fA-F0-9]{40}$/, { error: "Collateral token must be a valid 20-byte address" }).transform((val) => val.toLowerCase())).meta({
3889
+ description: "Filter by collateral tokens (comma-separated, matches any collateral).",
3890
+ example: "0x34Cf890dB685FC536E05652FB41f02090c3fb751,0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078"
3684
3891
  }),
3685
- maturity: zod.string().regex(/^[1-9]\d*$/, { message: "Maturity must be a positive integer" }).transform((val) => Number.parseInt(val, 10)).optional().meta({
3686
- description: "Filter by exact maturity timestamp (unix seconds)",
3687
- example: "1761922800"
3892
+ maturities: csvArray(zod.string().regex(/^[1-9]\d*$/, { message: "Maturity must be a positive integer" }).transform((val) => Number.parseInt(val, 10))).meta({
3893
+ description: "Filter by exact maturity timestamps (comma-separated, unix seconds).",
3894
+ example: "1761922800,1764524800"
3688
3895
  })
3689
3896
  });
3690
3897
  const GetObligationParams = zod.object({ obligation_id: zod.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({
@@ -3762,7 +3969,7 @@ function safeParse(action, query, error) {
3762
3969
 
3763
3970
  //#endregion
3764
3971
  //#region src/api/Schema/index.ts
3765
- var Schema_exports = /* @__PURE__ */ __export({
3972
+ var Schema_exports = /* @__PURE__ */ __exportAll({
3766
3973
  BookResponse: () => BookResponse_exports,
3767
3974
  BooksController: () => BooksController,
3768
3975
  ChainHealth: () => ChainHealth,
@@ -3786,7 +3993,7 @@ var Schema_exports = /* @__PURE__ */ __export({
3786
3993
 
3787
3994
  //#endregion
3788
3995
  //#region src/client/Client.ts
3789
- var Client_exports = /* @__PURE__ */ __export({
3996
+ var Client_exports$1 = /* @__PURE__ */ __exportAll({
3790
3997
  HttpForbiddenError: () => HttpForbiddenError,
3791
3998
  HttpGetApiFailedError: () => HttpGetApiFailedError,
3792
3999
  HttpRateLimitError: () => HttpRateLimitError,
@@ -3819,12 +4026,16 @@ function connect$1(parameters) {
3819
4026
  };
3820
4027
  const apiClient = (0, openapi_fetch.default)({
3821
4028
  baseUrl: config.url.toString(),
3822
- headers: config.headers
4029
+ headers: config.headers,
4030
+ querySerializer: { array: {
4031
+ style: "form",
4032
+ explode: false
4033
+ } }
3823
4034
  });
3824
4035
  return {
3825
4036
  ...config,
3826
- getOffers: (parameters$1) => getOffers(apiClient, parameters$1),
3827
- getObligations: (parameters$1) => getObligations(apiClient, parameters$1)
4037
+ getOffers: (parameters) => getOffers(apiClient, parameters),
4038
+ getObligations: (parameters) => getObligations(apiClient, parameters)
3828
4039
  };
3829
4040
  }
3830
4041
  async function getOffers(apiClient, parameters) {
@@ -3851,7 +4062,7 @@ async function getOffers(apiClient, parameters) {
3851
4062
  obligation_units: offerData.obligation_units,
3852
4063
  obligation_shares: offerData.obligation_shares,
3853
4064
  price: offerData.price,
3854
- maturity: from$10(offerData.obligation.maturity),
4065
+ maturity: from$11(offerData.obligation.maturity),
3855
4066
  expiry: offerData.expiry,
3856
4067
  start: offerData.start,
3857
4068
  group: offerData.group,
@@ -3887,10 +4098,10 @@ async function getObligations(apiClient, parameters) {
3887
4098
  const { data, error, response } = await apiClient.GET("/v1/obligations", { params: { query: {
3888
4099
  cursor: parameters?.cursor,
3889
4100
  limit: parameters?.limit,
3890
- chain: parameters?.chainId,
3891
- loan_token: parameters?.loanToken,
3892
- collateral_token: parameters?.collateralToken,
3893
- maturity: parameters?.maturity
4101
+ chains: parameters?.chainIds,
4102
+ loan_tokens: parameters?.loanTokens,
4103
+ collateral_tokens: parameters?.collateralTokens,
4104
+ maturities: parameters?.maturities
3894
4105
  } } });
3895
4106
  if (error !== void 0) {
3896
4107
  switch (response.status) {
@@ -3909,7 +4120,7 @@ async function getObligations(apiClient, parameters) {
3909
4120
  oracle: collateral.oracle,
3910
4121
  lltv: collateral.lltv
3911
4122
  })),
3912
- maturity: from$10(item.maturity)
4123
+ maturity: from$11(item.maturity)
3913
4124
  });
3914
4125
  const { obligationId: _, ...returned } = {
3915
4126
  id: () => id(obligation),
@@ -3958,10 +4169,97 @@ var HttpGetApiFailedError = class extends BaseError {
3958
4169
  }
3959
4170
  };
3960
4171
 
4172
+ //#endregion
4173
+ //#region src/gatekeeper/Client.ts
4174
+ var Client_exports = /* @__PURE__ */ __exportAll({ createHttpClient: () => createHttpClient });
4175
+ const DEFAULT_TIMEOUT_MS = 1e4;
4176
+ /**
4177
+ * Create an HTTP client for a gatekeeper service.
4178
+ * @param config - Gatekeeper client configuration. {@link ClientConfig}
4179
+ * @returns An HTTP-backed gatekeeper client. {@link GatekeeperClient}
4180
+ */
4181
+ function createHttpClient(config) {
4182
+ const fetchFn = config.fetchFn ?? fetch;
4183
+ const timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
4184
+ const baseUrl = normalizeBaseUrl(config.baseUrl);
4185
+ const request = async (path, init) => {
4186
+ const controller = new AbortController();
4187
+ const timeout = setTimeout(() => controller.abort(), timeoutMs);
4188
+ try {
4189
+ return await fetchFn(`${baseUrl}${path}`, {
4190
+ ...init,
4191
+ signal: controller.signal
4192
+ });
4193
+ } finally {
4194
+ clearTimeout(timeout);
4195
+ }
4196
+ };
4197
+ const validate = async (body) => {
4198
+ const response = await request("/v1/validate", {
4199
+ method: "POST",
4200
+ headers: { "content-type": "application/json" },
4201
+ body: JSON.stringify(body)
4202
+ });
4203
+ const json = await response.json();
4204
+ return {
4205
+ statusCode: response.status,
4206
+ body: json
4207
+ };
4208
+ };
4209
+ const getRules = async () => {
4210
+ const response = await request("/v1/rules", { method: "GET" });
4211
+ const json = await response.json();
4212
+ if (!response.ok) throw new Error(`Gatekeeper rules request failed: ${extractErrorMessage(json) ?? response.statusText}`);
4213
+ if (!("data" in json) || !Array.isArray(json.data)) throw new Error("Gatekeeper rules response is invalid.");
4214
+ return json.data;
4215
+ };
4216
+ const isAllowed = async (offers) => {
4217
+ const { statusCode, body } = await validate({ offers: offers.map((offer) => toSnakeCase(offer)) });
4218
+ if (statusCode !== 200) {
4219
+ const errorMessage = extractErrorMessage(body);
4220
+ throw new Error(`Gatekeeper validation failed: ${errorMessage ?? `status ${statusCode}`}`);
4221
+ }
4222
+ const data = body.data;
4223
+ if (!data || typeof data !== "object") throw new Error("Gatekeeper validation response is invalid.");
4224
+ if ("issues" in data) {
4225
+ const issues = data.issues.map((issue) => ({
4226
+ ruleName: issue.rule,
4227
+ message: issue.message,
4228
+ item: offers[issue.index]
4229
+ }));
4230
+ const invalidIndices = new Set(data.issues.map((issue) => issue.index));
4231
+ return {
4232
+ valid: offers.filter((_, index) => !invalidIndices.has(index)),
4233
+ issues
4234
+ };
4235
+ }
4236
+ if (!("payload" in data) || !("root" in data)) throw new Error("Gatekeeper validation response is missing payload data.");
4237
+ return {
4238
+ valid: offers.slice(),
4239
+ issues: []
4240
+ };
4241
+ };
4242
+ return {
4243
+ baseUrl,
4244
+ validate,
4245
+ isAllowed,
4246
+ getRules
4247
+ };
4248
+ }
4249
+ function normalizeBaseUrl(url) {
4250
+ return url.trim().replace(/\/+$/, "");
4251
+ }
4252
+ function extractErrorMessage(payload) {
4253
+ if (!payload || typeof payload !== "object") return void 0;
4254
+ const error = payload.error;
4255
+ if (!error || typeof error !== "object") return void 0;
4256
+ return typeof error.message === "string" ? error.message : void 0;
4257
+ }
4258
+
3961
4259
  //#endregion
3962
4260
  //#region src/gatekeeper/Gate.ts
3963
- var Gate_exports = /* @__PURE__ */ __export({
3964
- batch: () => batch$1,
4261
+ var Gate_exports = /* @__PURE__ */ __exportAll({
4262
+ batch: () => batch,
3965
4263
  run: () => run,
3966
4264
  single: () => single
3967
4265
  });
@@ -3972,12 +4270,12 @@ var Gate_exports = /* @__PURE__ */ __export({
3972
4270
  * @param run - The function that validates the rule.
3973
4271
  * @returns The created rule.
3974
4272
  */
3975
- function single(name, description, run$1) {
4273
+ function single(name, description, run) {
3976
4274
  return {
3977
4275
  kind: "single",
3978
4276
  name,
3979
4277
  description,
3980
- run: run$1
4278
+ run
3981
4279
  };
3982
4280
  }
3983
4281
  /**
@@ -3987,12 +4285,12 @@ function single(name, description, run$1) {
3987
4285
  * @param run - The function that validates the rule.
3988
4286
  * @returns The created rule.
3989
4287
  */
3990
- function batch$1(name, description, run$1) {
4288
+ function batch(name, description, run) {
3991
4289
  return {
3992
4290
  kind: "batch",
3993
4291
  name,
3994
4292
  description,
3995
- run: run$1
4293
+ run
3996
4294
  };
3997
4295
  }
3998
4296
  async function run(parameters) {
@@ -4045,7 +4343,7 @@ async function run(parameters) {
4045
4343
 
4046
4344
  //#endregion
4047
4345
  //#region src/gatekeeper/GateConfig.ts
4048
- var GateConfig_exports = /* @__PURE__ */ __export({
4346
+ var GateConfig_exports = /* @__PURE__ */ __exportAll({
4049
4347
  assets: () => assets,
4050
4348
  configs: () => configs,
4051
4349
  getCallback: () => getCallback,
@@ -4071,8 +4369,8 @@ function getCallback(chain, type) {
4071
4369
  * @param address - Callback contract address
4072
4370
  * @returns The callback type when found, otherwise undefined
4073
4371
  */
4074
- function getCallbackType(chain, address$1) {
4075
- return configs[chain].callbacks?.find((c) => c.type !== CallbackType.BuyWithEmptyCallback && c.addresses.includes(address$1?.toLowerCase()))?.type;
4372
+ function getCallbackType(chain, address) {
4373
+ return configs[chain].callbacks?.find((c) => c.type !== Type$1.BuyWithEmptyCallback && c.addresses.includes(address?.toLowerCase()))?.type;
4076
4374
  }
4077
4375
  /**
4078
4376
  * Returns the callback addresses for a given chain and callback type, if it exists.
@@ -4081,7 +4379,7 @@ function getCallbackType(chain, address$1) {
4081
4379
  * @returns The matching callback addresses or an empty array if not configured
4082
4380
  */
4083
4381
  function getCallbackTypeAddresses(chain, type) {
4084
- if (type === CallbackType.BuyWithEmptyCallback) return [];
4382
+ if (type === Type$1.BuyWithEmptyCallback) return [];
4085
4383
  const match = configs[chain].callbacks?.find((c) => c.type === type);
4086
4384
  return match && "addresses" in match ? match.addresses : [];
4087
4385
  }
@@ -4092,7 +4390,7 @@ function getCallbackTypeAddresses(chain, type) {
4092
4390
  * @returns Array of allowed callback addresses (lowercased). Empty when none configured
4093
4391
  */
4094
4392
  const getCallbackAddresses = (chain) => {
4095
- return configs[chain].callbacks?.filter((c) => c.type !== CallbackType.BuyWithEmptyCallback).flatMap((c) => c.addresses) ?? [];
4393
+ return configs[chain].callbacks?.filter((c) => c.type !== Type$1.BuyWithEmptyCallback).flatMap((c) => c.addresses) ?? [];
4096
4394
  };
4097
4395
  const assets = {
4098
4396
  [ChainId.ETHEREUM.toString()]: [
@@ -4125,60 +4423,60 @@ const configs = {
4125
4423
  ethereum: {
4126
4424
  callbacks: [
4127
4425
  {
4128
- type: CallbackType.BuyVaultV1Callback,
4426
+ type: Type$1.BuyVaultV1Callback,
4129
4427
  addresses: ["0x3333333333333333333333333333333333333333", "0x4444444444444444444444444444444444444444"],
4130
4428
  vaultFactories: ["0xA9c3D3a366466Fa809d1Ae982Fb2c46E5fC41101", "0x1897A8997241C1cD4bD0698647e4EB7213535c24"]
4131
4429
  },
4132
4430
  {
4133
- type: CallbackType.SellERC20Callback,
4431
+ type: Type$1.SellERC20Callback,
4134
4432
  addresses: ["0x1111111111111111111111111111111111111111", "0x2222222222222222222222222222222222222222"]
4135
4433
  },
4136
- { type: CallbackType.BuyWithEmptyCallback }
4434
+ { type: Type$1.BuyWithEmptyCallback }
4137
4435
  ],
4138
4436
  maturities: [MaturityType.EndOfMonth, MaturityType.EndOfNextMonth]
4139
4437
  },
4140
4438
  base: {
4141
4439
  callbacks: [
4142
4440
  {
4143
- type: CallbackType.BuyVaultV1Callback,
4441
+ type: Type$1.BuyVaultV1Callback,
4144
4442
  addresses: ["0x3333333333333333333333333333333333333333", "0x4444444444444444444444444444444444444444"],
4145
4443
  vaultFactories: ["0xA9c3D3a366466Fa809d1Ae982Fb2c46E5fC41101", "0xFf62A7c278C62eD665133147129245053Bbf5918"]
4146
4444
  },
4147
4445
  {
4148
- type: CallbackType.SellERC20Callback,
4446
+ type: Type$1.SellERC20Callback,
4149
4447
  addresses: ["0x1111111111111111111111111111111111111111", "0x2222222222222222222222222222222222222222"]
4150
4448
  },
4151
- { type: CallbackType.BuyWithEmptyCallback }
4449
+ { type: Type$1.BuyWithEmptyCallback }
4152
4450
  ],
4153
4451
  maturities: [MaturityType.EndOfMonth, MaturityType.EndOfNextMonth]
4154
4452
  },
4155
4453
  "ethereum-virtual-testnet": {
4156
4454
  callbacks: [
4157
4455
  {
4158
- type: CallbackType.BuyVaultV1Callback,
4456
+ type: Type$1.BuyVaultV1Callback,
4159
4457
  addresses: ["0x3333333333333333333333333333333333333333", "0x4444444444444444444444444444444444444444"],
4160
4458
  vaultFactories: ["0xA9c3D3a366466Fa809d1Ae982Fb2c46E5fC41101", "0x1897A8997241C1cD4bD0698647e4EB7213535c24"]
4161
4459
  },
4162
4460
  {
4163
- type: CallbackType.SellERC20Callback,
4461
+ type: Type$1.SellERC20Callback,
4164
4462
  addresses: ["0x1111111111111111111111111111111111111111", "0x2222222222222222222222222222222222222222"]
4165
4463
  },
4166
- { type: CallbackType.BuyWithEmptyCallback }
4464
+ { type: Type$1.BuyWithEmptyCallback }
4167
4465
  ],
4168
4466
  maturities: [MaturityType.EndOfMonth, MaturityType.EndOfNextMonth]
4169
4467
  },
4170
4468
  anvil: {
4171
4469
  callbacks: [
4172
4470
  {
4173
- type: CallbackType.BuyVaultV1Callback,
4471
+ type: Type$1.BuyVaultV1Callback,
4174
4472
  addresses: ["0x3333333333333333333333333333333333333333", "0x4444444444444444444444444444444444444444"],
4175
4473
  vaultFactories: ["0xA9c3D3a366466Fa809d1Ae982Fb2c46E5fC41101", "0x1897A8997241C1cD4bD0698647e4EB7213535c24"]
4176
4474
  },
4177
4475
  {
4178
- type: CallbackType.SellERC20Callback,
4476
+ type: Type$1.SellERC20Callback,
4179
4477
  addresses: ["0x1111111111111111111111111111111111111111", "0x2222222222222222222222222222222222222222"]
4180
4478
  },
4181
- { type: CallbackType.BuyWithEmptyCallback }
4479
+ { type: Type$1.BuyWithEmptyCallback }
4182
4480
  ],
4183
4481
  maturities: [MaturityType.EndOfMonth, MaturityType.EndOfNextMonth]
4184
4482
  }
@@ -4186,22 +4484,31 @@ const configs = {
4186
4484
 
4187
4485
  //#endregion
4188
4486
  //#region src/gatekeeper/Gatekeeper.ts
4189
- var Gatekeeper_exports = /* @__PURE__ */ __export({ create: () => create });
4487
+ var Gatekeeper_exports = /* @__PURE__ */ __exportAll({ create: () => create });
4488
+ /**
4489
+ * Create a gatekeeper instance with the provided rules.
4490
+ * @param parameters - Gatekeeper parameters. {@link GatekeeperParameters}
4491
+ * @returns Gatekeeper instance. {@link Gatekeeper}
4492
+ */
4190
4493
  function create(parameters) {
4494
+ const { rules } = parameters;
4191
4495
  return {
4192
- rules: parameters.rules,
4193
4496
  isAllowed: async (offers) => {
4194
4497
  return await run({
4195
4498
  items: offers,
4196
- rules: parameters.rules
4499
+ rules
4197
4500
  });
4198
- }
4501
+ },
4502
+ getRules: async () => rules.map((rule) => ({
4503
+ name: rule.name,
4504
+ description: rule.description
4505
+ }))
4199
4506
  };
4200
4507
  }
4201
4508
 
4202
4509
  //#endregion
4203
4510
  //#region src/gatekeeper/Rules.ts
4204
- var Rules_exports = /* @__PURE__ */ __export({
4511
+ var Rules_exports = /* @__PURE__ */ __exportAll({
4205
4512
  amountMutualExclusivity: () => amountMutualExclusivity,
4206
4513
  callback: () => callback,
4207
4514
  chains: () => chains,
@@ -4220,21 +4527,21 @@ function validity(parameters) {
4220
4527
  const { client } = parameters;
4221
4528
  const sellErc20CallbackInvalid = single("sell_erc20_callback_invalid", "Validates that sell offers have valid ERC20 callback data matching offer collaterals", (offer) => {
4222
4529
  const callbackType = getCallbackType(client.chain.name, offer.callback.address);
4223
- if (callbackType !== CallbackType.SellERC20Callback) return;
4530
+ if (callbackType !== Type$1.SellERC20Callback) return;
4224
4531
  const decoded = decode$2(callbackType, offer.callback.data);
4225
4532
  if (decoded.length === 0) return { message: "Callback data cannot be decoded or is empty." };
4226
- if (callbackType === CallbackType.SellERC20Callback) {
4533
+ if (callbackType === Type$1.SellERC20Callback) {
4227
4534
  const offerCollaterals = new Set(offer.collaterals.map((c) => c.asset.toLowerCase()));
4228
4535
  if (decoded.length !== offer.collaterals.length) return { message: `Sell callback collateral length mismatch. Expected ${offer.collaterals.length}, got ${decoded.length}.` };
4229
4536
  for (const { contract } of decoded) if (!offerCollaterals.has(contract.toLowerCase())) return { message: "Sell callback collateral is not part of offer collaterals." };
4230
4537
  }
4231
4538
  });
4232
- 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) => {
4539
+ 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) => {
4233
4540
  const validationIssues = /* @__PURE__ */ new Map();
4234
4541
  const offersByVaultAddress = /* @__PURE__ */ new Map();
4235
4542
  for (let i = 0; i < offers.length; i++) {
4236
4543
  const offer = offers[i];
4237
- if (getCallbackType(client.chain.name, offer.callback.address) !== CallbackType.BuyVaultV1Callback) continue;
4544
+ if (getCallbackType(client.chain.name, offer.callback.address) !== Type$1.BuyVaultV1Callback) continue;
4238
4545
  try {
4239
4546
  const callbackVaults = decodeBuyVaultV1Callback(offer.callback.data);
4240
4547
  for (const { contract } of callbackVaults) {
@@ -4249,7 +4556,7 @@ function validity(parameters) {
4249
4556
  }
4250
4557
  const uniqueVaultAddresses = Array.from(offersByVaultAddress.keys());
4251
4558
  if (uniqueVaultAddresses.length === 0) return validationIssues;
4252
- const allowedFactories = getCallback(client.chain.name, CallbackType.BuyVaultV1Callback)?.vaultFactories.map((f) => f.toLowerCase());
4559
+ const allowedFactories = getCallback(client.chain.name, Type$1.BuyVaultV1Callback)?.vaultFactories.map((f) => f.toLowerCase());
4253
4560
  if (!allowedFactories) return validationIssues;
4254
4561
  const multicallContracts = [];
4255
4562
  for (const vaultAddress of uniqueVaultAddresses) {
@@ -4317,16 +4624,16 @@ function validity(parameters) {
4317
4624
  buyCallbackVaultInvalid
4318
4625
  ];
4319
4626
  }
4320
- const chains = ({ chains: chains$2 }) => single("chain_ids", `Validates that offer chain is one of: [${chains$2.map((c) => c.id).join(", ")}]`, (offer) => {
4321
- const allowedChainIds = chains$2.map((c) => c.id);
4322
- if (!allowedChainIds.some((id$1) => id$1 === offer.chainId)) return { message: `Chain ID ${offer.chainId} is not in the allowed chains (${allowedChainIds.join(", ")})` };
4627
+ const chains = ({ chains }) => single("chain_ids", `Validates that offer chain is one of: [${chains.map((c) => c.id).join(", ")}]`, (offer) => {
4628
+ const allowedChainIds = chains.map((c) => c.id);
4629
+ if (!allowedChainIds.some((id) => id === offer.chainId)) return { message: `Chain ID ${offer.chainId} is not in the allowed chains (${allowedChainIds.join(", ")})` };
4323
4630
  });
4324
4631
  const maturity = ({ maturities }) => single("maturity", `Validates that offer maturity is one of: [${maturities.join(", ")}]`, (offer) => {
4325
- const allowedMaturities = maturities.map((m) => from$10(m));
4632
+ const allowedMaturities = maturities.map((m) => from$11(m));
4326
4633
  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}` };
4327
4634
  });
4328
- 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) => {
4329
- if (isEmptyCallback(offer) && offer.buy && !callbacks?.find((c) => c === CallbackType.BuyWithEmptyCallback)) return { message: "Buy offers with empty callback not allowed." };
4635
+ 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) => {
4636
+ if (isEmptyCallback(offer) && offer.buy && !callbacks?.find((c) => c === Type$1.BuyWithEmptyCallback)) return { message: "Buy offers with empty callback not allowed." };
4330
4637
  if (isEmptyCallback(offer) && !offer.buy) return { message: "Sell offers require a non-empty callback." };
4331
4638
  if (!isEmptyCallback(offer)) {
4332
4639
  if (!allowedAddresses.includes(offer.callback.address?.toLowerCase())) return { message: `Callback address ${offer.callback.address} is not allowed.` };
@@ -4348,7 +4655,7 @@ const token = ({ assetsByChainId }) => single("token", "Validates that offer loa
4348
4655
  * Returns an issue only for the first non-conforming offer.
4349
4656
  * This rule is signing-agnostic; signer verification is handled at the collector level.
4350
4657
  */
4351
- const sameMaker = () => batch$1("mixed_maker", "Validates that all offers in a batch have the same maker address", (offers) => {
4658
+ const sameMaker = () => batch("mixed_maker", "Validates that all offers in a batch have the same maker address", (offers) => {
4352
4659
  const issues = /* @__PURE__ */ new Map();
4353
4660
  if (offers.length === 0) return issues;
4354
4661
  const firstMaker = offers[0].maker.toLowerCase();
@@ -4382,9 +4689,9 @@ const morphoRules = (chains$2) => {
4382
4689
  maturity({ maturities: [MaturityType.EndOfMonth, MaturityType.EndOfNextMonth] }),
4383
4690
  callback({
4384
4691
  callbacks: [
4385
- CallbackType.BuyWithEmptyCallback,
4386
- CallbackType.BuyVaultV1Callback,
4387
- CallbackType.SellERC20Callback
4692
+ Type$1.BuyWithEmptyCallback,
4693
+ Type$1.BuyVaultV1Callback,
4694
+ Type$1.SellERC20Callback
4388
4695
  ],
4389
4696
  allowedAddresses: chains$2.flatMap((c) => getCallbackAddresses(c.name))
4390
4697
  }),
@@ -4402,9 +4709,9 @@ function from(parameters) {
4402
4709
  blockWindow: parameters.blockWindow
4403
4710
  };
4404
4711
  return {
4405
- add: (parameters$1) => add(config, parameters$1),
4406
- get: (parameters$1) => get(config, parameters$1),
4407
- stream: (parameters$1) => streamOffers(config, parameters$1)
4712
+ add: (parameters) => add(config, parameters),
4713
+ get: (parameters) => get(config, parameters),
4714
+ stream: (parameters) => streamOffers(config, parameters)
4408
4715
  };
4409
4716
  }
4410
4717
  /**
@@ -4416,7 +4723,7 @@ function from(parameters) {
4416
4723
  */
4417
4724
  async function add(config, offers) {
4418
4725
  if (!config.client.account) throw new WalletAccountNotSetError();
4419
- const tree = from$8(offers.map((o) => from$7(o)));
4726
+ const tree = from$9(offers.map((o) => from$8(o)));
4420
4727
  const chainId = await getChainId(config.client);
4421
4728
  for (const offer of tree.offers) if (chainId !== offer.chainId) throw new ChainIdMismatchError(offer.chainId, chainId);
4422
4729
  const signature = await sign(tree.offers, config.client);
@@ -4528,7 +4835,7 @@ var ChainIdMismatchError = class extends BaseError {
4528
4835
 
4529
4836
  //#endregion
4530
4837
  //#region src/mempool/MempoolClient.ts
4531
- var MempoolClient_exports = /* @__PURE__ */ __export({ connect: () => connect });
4838
+ var MempoolClient_exports = /* @__PURE__ */ __exportAll({ connect: () => connect });
4532
4839
  /**
4533
4840
  * Client to interact with the Mempool contract on a specific chain.
4534
4841
  */
@@ -4561,7 +4868,7 @@ const retry = async (fn, attempts = 3, delayMs = 50) => {
4561
4868
  async function batchMulticall(parameters) {
4562
4869
  const { client, calls, batchSize, retryAttempts, retryDelayMs, blockNumber } = parameters;
4563
4870
  const results = [];
4564
- for (const callsBatch of batch(calls, batchSize)) {
4871
+ for (const callsBatch of batch$1(calls, batchSize)) {
4565
4872
  const batchResults = await retry(() => (0, viem_actions.multicall)(client, {
4566
4873
  allowFailure: false,
4567
4874
  contracts: callsBatch,
@@ -4574,7 +4881,7 @@ async function batchMulticall(parameters) {
4574
4881
 
4575
4882
  //#endregion
4576
4883
  //#region src/utils/Group.ts
4577
- var Group_exports = /* @__PURE__ */ __export({ fromNumber: () => fromNumber });
4884
+ var Group_exports = /* @__PURE__ */ __exportAll({ fromNumber: () => fromNumber });
4578
4885
  /**
4579
4886
  * Creates a bytes32 group identifier from a number.
4580
4887
  * @param n - A non-negative integer.
@@ -4598,7 +4905,7 @@ function lazy(pollFn) {
4598
4905
  let active = true;
4599
4906
  let resolveNext = null;
4600
4907
  const queue = [];
4601
- const wait$1 = () => new Promise((resolve) => {
4908
+ const wait = () => new Promise((resolve) => {
4602
4909
  resolveNext = resolve;
4603
4910
  });
4604
4911
  const emit = (item) => {
@@ -4616,7 +4923,7 @@ function lazy(pollFn) {
4616
4923
  unpoll = pollFn(emit, { stop });
4617
4924
  try {
4618
4925
  while (active) {
4619
- if (queue.length === 0) await wait$1();
4926
+ if (queue.length === 0) await wait();
4620
4927
  while (queue.length > 0 && active) yield queue.shift();
4621
4928
  }
4622
4929
  } finally {
@@ -4655,7 +4962,7 @@ function poll(fn, { interval }) {
4655
4962
 
4656
4963
  //#endregion
4657
4964
  //#region src/utils/time.ts
4658
- var time_exports = /* @__PURE__ */ __export({
4965
+ var time_exports = /* @__PURE__ */ __exportAll({
4659
4966
  max: () => max,
4660
4967
  now: () => now
4661
4968
  });
@@ -4668,14 +4975,14 @@ function max() {
4668
4975
 
4669
4976
  //#endregion
4670
4977
  //#region src/utils/index.ts
4671
- var utils_exports = /* @__PURE__ */ __export({
4978
+ var utils_exports = /* @__PURE__ */ __exportAll({
4672
4979
  BaseError: () => BaseError,
4673
4980
  Group: () => Group_exports,
4674
4981
  Random: () => Random_exports,
4675
4982
  ReorgError: () => ReorgError,
4676
4983
  Time: () => time_exports,
4677
4984
  atMostOneNonZero: () => atMostOneNonZero,
4678
- batch: () => batch,
4985
+ batch: () => batch$1,
4679
4986
  batchMulticall: () => batchMulticall,
4680
4987
  fromSnakeCase: () => fromSnakeCase$3,
4681
4988
  lazy: () => lazy,
@@ -4750,6 +5057,12 @@ Object.defineProperty(exports, 'Gatekeeper', {
4750
5057
  return Gatekeeper_exports;
4751
5058
  }
4752
5059
  });
5060
+ Object.defineProperty(exports, 'GatekeeperClient', {
5061
+ enumerable: true,
5062
+ get: function () {
5063
+ return Client_exports;
5064
+ }
5065
+ });
4753
5066
  Object.defineProperty(exports, 'LLTV', {
4754
5067
  enumerable: true,
4755
5068
  get: function () {
@@ -4813,7 +5126,7 @@ Object.defineProperty(exports, 'RouterApi', {
4813
5126
  Object.defineProperty(exports, 'RouterClient', {
4814
5127
  enumerable: true,
4815
5128
  get: function () {
4816
- return Client_exports;
5129
+ return Client_exports$1;
4817
5130
  }
4818
5131
  });
4819
5132
  Object.defineProperty(exports, 'Rules', {
@@ -4828,6 +5141,12 @@ Object.defineProperty(exports, 'Time', {
4828
5141
  return time_exports;
4829
5142
  }
4830
5143
  });
5144
+ Object.defineProperty(exports, 'TradingFee', {
5145
+ enumerable: true,
5146
+ get: function () {
5147
+ return TradingFee_exports;
5148
+ }
5149
+ });
4831
5150
  Object.defineProperty(exports, 'Transfer', {
4832
5151
  enumerable: true,
4833
5152
  get: function () {