@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.
@@ -40,7 +40,7 @@ function getChain(chainId) {
40
40
  return chains[chainName];
41
41
  }
42
42
  var getWhitelistedChains = () => {
43
- return [chains.ethereum, chains["ethereum-virtual-testnet"]];
43
+ return [chains.ethereum, chains.base, chains["ethereum-virtual-testnet"]];
44
44
  };
45
45
  var chains = {
46
46
  ethereum: {
@@ -419,12 +419,15 @@ var GetOffersQueryParams = z.object({
419
419
  description: "Filter by multiple rate oracles (comma-separated)",
420
420
  example: "0x1234567890123456789012345678901234567890,0xabcdefabcdefabcdefabcdefabcdefabcdefabcd"
421
421
  }),
422
- collateral_tuple: z.string().regex(
423
- /^(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]+)?)?)*$/,
424
- {
425
- 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)."
422
+ collateral_tuple: z.string().transform((val, ctx) => {
423
+ 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]+)?)?)*$/;
424
+ if (!pattern.test(val)) {
425
+ ctx.addIssue({
426
+ code: "custom",
427
+ message: "collateral_tuple has an invalid format",
428
+ input: val
429
+ });
426
430
  }
427
- ).transform((val, ctx) => {
428
431
  return val.split("#").map((tuple) => {
429
432
  const parts = tuple.split(":");
430
433
  if (parts.length === 0 || !parts[0]) {
@@ -554,9 +557,23 @@ var MatchOffersQueryParams = z.object({
554
557
  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.",
555
558
  example: "buy"
556
559
  }),
557
- chain_id: z.string().regex(/^\d+$/, {
558
- message: "Chain ID must be a positive integer"
559
- }).transform((val) => Number.parseInt(val, 10)).pipe(z.number().positive()).meta({
560
+ chain_id: z.string().transform((val, ctx) => {
561
+ const numericLike = /^-?\d+$/.test(val);
562
+ if (!numericLike) {
563
+ ctx.addIssue({
564
+ code: "custom",
565
+ message: "chain_id has an invalid format",
566
+ input: val
567
+ });
568
+ ctx.addIssue({
569
+ code: "custom",
570
+ message: "Invalid input: expected number, received NaN",
571
+ input: val
572
+ });
573
+ return z.NEVER;
574
+ }
575
+ return Number.parseInt(val, 10);
576
+ }).pipe(z.number().positive()).meta({
560
577
  description: "The blockchain network chain ID",
561
578
  example: "1"
562
579
  }),
@@ -568,12 +585,15 @@ var MatchOffersQueryParams = z.object({
568
585
  example: "1000000000000000000"
569
586
  }),
570
587
  // Collateral filtering
571
- collaterals: z.string().regex(
572
- /^(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]+)?)*$/,
573
- {
574
- message: "Collaterals must be in format: asset:oracle:lltv#asset2:oracle2:lltv2. All fields are required for each collateral."
588
+ collaterals: z.string().transform((val, ctx) => {
589
+ 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]+)?)*$/;
590
+ if (!pattern.test(val)) {
591
+ ctx.addIssue({
592
+ code: "custom",
593
+ message: "Collaterals must be in format: asset:oracle:lltv#asset2:oracle2:lltv2. All fields are required for each collateral.",
594
+ input: val
595
+ });
575
596
  }
576
- ).transform((val, ctx) => {
577
597
  return val.split("#").map((collateral) => {
578
598
  const parts = collateral.split(":");
579
599
  if (parts.length !== 3) {
@@ -827,7 +847,7 @@ function connect(opts) {
827
847
  if (u.protocol !== "http:" && u.protocol !== "https:") {
828
848
  throw new InvalidUrlError(u.toString());
829
849
  }
830
- const headers = new Headers();
850
+ const headers = opts?.headers ?? new Headers();
831
851
  headers.set("Content-Type", "application/json");
832
852
  opts?.apiKey !== void 0 ? headers.set("X-API-Key", opts.apiKey) : null;
833
853
  const config = {