@morpho-dev/router 0.0.27 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -41,7 +41,7 @@ function getChain(chainId) {
41
41
  return chains[chainName];
42
42
  }
43
43
  var getWhitelistedChains = () => {
44
- return [chains.ethereum, chains["ethereum-virtual-testnet"]];
44
+ return [chains.ethereum, chains.base, chains["ethereum-virtual-testnet"]];
45
45
  };
46
46
  var chains = {
47
47
  ethereum: {
@@ -417,12 +417,15 @@ var GetOffersQueryParams = z.object({
417
417
  description: "Filter by multiple rate oracles (comma-separated)",
418
418
  example: "0x1234567890123456789012345678901234567890,0xabcdefabcdefabcdefabcdefabcdefabcdefabcd"
419
419
  }),
420
- collateral_tuple: z.string().regex(
421
- /^(0x[a-fA-F0-9]{40}(:0x[a-fA-F0-9]{40})?(:[0-9]+(\.[0-9]+)?)?)(#0x[a-fA-F0-9]{40}(:0x[a-fA-F0-9]{40})?(:[0-9]+(\.[0-9]+)?)?)*$/,
422
- {
423
- message: "Collateral tuple must be in format: asset:oracle:lltv#asset2:oracle2:lltv2. Oracle and lltv are optional. Asset must be 0x + 40 hex chars, oracle must be 0x + 40 hex chars, lltv must be a number (e.g., 80.5)."
420
+ collateral_tuple: z.string().transform((val, ctx) => {
421
+ const pattern = /^(0x[a-fA-F0-9]{40}(:0x[a-fA-F0-9]{40})?(:[0-9]+(\.[0-9]+)?)?)(#0x[a-fA-F0-9]{40}(:0x[a-fA-F0-9]{40})?(:[0-9]+(\.[0-9]+)?)?)*$/;
422
+ if (!pattern.test(val)) {
423
+ ctx.addIssue({
424
+ code: "custom",
425
+ message: "collateral_tuple has an invalid format",
426
+ input: val
427
+ });
424
428
  }
425
- ).transform((val, ctx) => {
426
429
  return val.split("#").map((tuple) => {
427
430
  const parts = tuple.split(":");
428
431
  if (parts.length === 0 || !parts[0]) {
@@ -552,9 +555,23 @@ var MatchOffersQueryParams = z.object({
552
555
  description: "The desired side of the match: 'buy' if you want to buy, 'sell' if you want to sell. If your intent is to sell, buy offers will be returned, and vice versa.",
553
556
  example: "buy"
554
557
  }),
555
- chain_id: z.string().regex(/^\d+$/, {
556
- message: "Chain ID must be a positive integer"
557
- }).transform((val) => Number.parseInt(val, 10)).pipe(z.number().positive()).meta({
558
+ chain_id: z.string().transform((val, ctx) => {
559
+ const numericLike = /^-?\d+$/.test(val);
560
+ if (!numericLike) {
561
+ ctx.addIssue({
562
+ code: "custom",
563
+ message: "chain_id has an invalid format",
564
+ input: val
565
+ });
566
+ ctx.addIssue({
567
+ code: "custom",
568
+ message: "Invalid input: expected number, received NaN",
569
+ input: val
570
+ });
571
+ return z.NEVER;
572
+ }
573
+ return Number.parseInt(val, 10);
574
+ }).pipe(z.number().positive()).meta({
558
575
  description: "The blockchain network chain ID",
559
576
  example: "1"
560
577
  }),
@@ -566,12 +583,15 @@ var MatchOffersQueryParams = z.object({
566
583
  example: "1000000000000000000"
567
584
  }),
568
585
  // Collateral filtering
569
- collaterals: z.string().regex(
570
- /^(0x[a-fA-F0-9]{40}:0x[a-fA-F0-9]{40}:[0-9]+(\.[0-9]+)?)(#0x[a-fA-F0-9]{40}:0x[a-fA-F0-9]{40}:[0-9]+(\.[0-9]+)?)*$/,
571
- {
572
- message: "Collaterals must be in format: asset:oracle:lltv#asset2:oracle2:lltv2. All fields are required for each collateral."
586
+ collaterals: z.string().transform((val, ctx) => {
587
+ const pattern = /^(0x[a-fA-F0-9]{40}:0x[a-fA-F0-9]{40}:[0-9]+(\.[0-9]+)?)(#0x[a-fA-F0-9]{40}:0x[a-fA-F0-9]{40}:[0-9]+(\.[0-9]+)?)*$/;
588
+ if (!pattern.test(val)) {
589
+ ctx.addIssue({
590
+ code: "custom",
591
+ message: "Collaterals must be in format: asset:oracle:lltv#asset2:oracle2:lltv2. All fields are required for each collateral.",
592
+ input: val
593
+ });
573
594
  }
574
- ).transform((val, ctx) => {
575
595
  return val.split("#").map((collateral) => {
576
596
  const parts = collateral.split(":");
577
597
  if (parts.length !== 3) {
@@ -848,7 +868,7 @@ function connect(opts) {
848
868
  if (u.protocol !== "http:" && u.protocol !== "https:") {
849
869
  throw new InvalidUrlError(u.toString());
850
870
  }
851
- const headers = new Headers();
871
+ const headers = opts?.headers ?? new Headers();
852
872
  headers.set("Content-Type", "application/json");
853
873
  opts?.apiKey !== void 0 ? headers.set("X-API-Key", opts.apiKey) : null;
854
874
  const config = {
@@ -1625,7 +1645,8 @@ __export(Logger_exports, {
1625
1645
  LogLevelValues: () => LogLevelValues,
1626
1646
  defaultLogger: () => defaultLogger,
1627
1647
  getLogger: () => getLogger,
1628
- runWithLogger: () => runWithLogger
1648
+ runWithLogger: () => runWithLogger,
1649
+ silentLogger: () => silentLogger
1629
1650
  });
1630
1651
  var LogLevelValues = [
1631
1652
  "silent",
@@ -1636,20 +1657,50 @@ var LogLevelValues = [
1636
1657
  "error",
1637
1658
  "fatal"
1638
1659
  ];
1639
- function defaultLogger() {
1660
+ function defaultLogger(minLevel) {
1661
+ const threshold = minLevel ?? "trace";
1662
+ const levelIndexByName = LogLevelValues.reduce(
1663
+ (acc, lvl, idx) => {
1664
+ acc[lvl] = idx;
1665
+ return acc;
1666
+ },
1667
+ {}
1668
+ );
1669
+ const isEnabled = (methodLevel) => levelIndexByName[methodLevel] >= levelIndexByName[threshold];
1640
1670
  return {
1641
1671
  // biome-ignore lint/suspicious/noConsole: console is used for logging
1642
- trace: console.trace.bind(console),
1672
+ trace: isEnabled("trace") ? console.trace.bind(console) : () => {
1673
+ },
1643
1674
  // biome-ignore lint/suspicious/noConsole: console is used for logging
1644
- debug: console.debug.bind(console),
1675
+ debug: isEnabled("debug") ? console.debug.bind(console) : () => {
1676
+ },
1645
1677
  // biome-ignore lint/suspicious/noConsole: console is used for logging
1646
- info: console.info.bind(console),
1678
+ info: isEnabled("info") ? console.info.bind(console) : () => {
1679
+ },
1647
1680
  // biome-ignore lint/suspicious/noConsole: console is used for logging
1648
- warn: console.warn.bind(console),
1681
+ warn: isEnabled("warn") ? console.warn.bind(console) : () => {
1682
+ },
1649
1683
  // biome-ignore lint/suspicious/noConsole: console is used for logging
1650
- error: console.error.bind(console),
1651
- // biome-ignore lint/suspicious/noConsole: console.fatal does not exist
1652
- fatal: (...args) => console.error("[fatal]", ...args)
1684
+ error: isEnabled("error") ? console.error.bind(console) : () => {
1685
+ },
1686
+ fatal: isEnabled("fatal") ? (...args) => console.error("[fatal]", ...args) : () => {
1687
+ }
1688
+ };
1689
+ }
1690
+ function silentLogger() {
1691
+ return {
1692
+ trace: () => {
1693
+ },
1694
+ debug: () => {
1695
+ },
1696
+ info: () => {
1697
+ },
1698
+ warn: () => {
1699
+ },
1700
+ error: () => {
1701
+ },
1702
+ fatal: () => {
1703
+ }
1653
1704
  };
1654
1705
  }
1655
1706
  var loggerContext = new AsyncLocalStorage();