@morpho-dev/router 0.1.0 → 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.
@@ -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) {