@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.
@@ -5,9 +5,7 @@ import * as viem from 'viem';
5
5
  import { Address, Hex, PublicClient } from 'viem';
6
6
  import { Chain as Chain$2 } from 'viem/chains';
7
7
  import * as node_modules_zod_openapi_dist_components_DkyUTLcs_js from 'node_modules/zod-openapi/dist/components-DkyUTLcs.js';
8
- import * as zod_v4 from 'zod/v4';
9
8
  import { z, ZodError } from 'zod/v4';
10
- import * as zod_v4_core from 'zod/v4/core';
11
9
  import * as hono_utils_types from 'hono/utils/types';
12
10
  import * as hono from 'hono';
13
11
  import { Context } from 'hono';
@@ -137,29 +135,29 @@ type OfferConsumed = {
137
135
  };
138
136
  declare const RouterOfferSchema: (parameters?: {
139
137
  omitHash?: boolean;
140
- }) => zod_v4.ZodObject<{
141
- offering: zod_v4.ZodPipe<zod_v4.ZodString, zod_v4.ZodTransform<`0x${string}`, string>>;
142
- assets: zod_v4.ZodBigInt;
143
- rate: zod_v4.ZodBigInt;
144
- maturity: zod_v4.ZodPipe<zod_v4.ZodNumber, zod_v4.ZodTransform<number & _morpho_dev_mempool.Brand<"Maturity">, number>>;
145
- expiry: zod_v4.ZodNumber;
146
- start: zod_v4.ZodNumber;
147
- nonce: zod_v4.ZodBigInt;
148
- buy: zod_v4.ZodBoolean;
149
- chainId: zod_v4.ZodBigInt;
150
- loanToken: zod_v4.ZodPipe<zod_v4.ZodString, zod_v4.ZodTransform<`0x${string}`, string>>;
151
- collaterals: zod_v4.ZodArray<zod_v4.ZodObject<{
152
- asset: zod_v4.ZodPipe<zod_v4.ZodString, zod_v4.ZodTransform<`0x${string}`, string>>;
153
- oracle: zod_v4.ZodPipe<zod_v4.ZodString, zod_v4.ZodTransform<`0x${string}`, string>>;
154
- lltv: zod_v4.ZodPipe<zod_v4.ZodBigInt, zod_v4.ZodTransform<bigint & _morpho_dev_mempool.Brand<"LLTV">, bigint>>;
155
- }, zod_v4_core.$strip>>;
156
- callback: zod_v4.ZodObject<{
157
- address: zod_v4.ZodPipe<zod_v4.ZodString, zod_v4.ZodTransform<`0x${string}`, string>>;
158
- data: zod_v4.ZodPipe<zod_v4.ZodString, zod_v4.ZodTransform<`0x${string}`, string>>;
159
- gasLimit: zod_v4.ZodBigInt;
160
- }, zod_v4_core.$strip>;
161
- signature: zod_v4.ZodOptional<zod_v4.ZodPipe<zod_v4.ZodString, zod_v4.ZodTransform<`0x${string}`, string>>>;
162
- createdAt: zod_v4.ZodOptional<zod_v4.ZodNumber>;
138
+ }) => z.ZodObject<{
139
+ offering: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
140
+ assets: z.ZodBigInt;
141
+ rate: z.ZodBigInt;
142
+ maturity: z.ZodPipe<z.ZodNumber, z.ZodTransform<number & _morpho_dev_mempool.Brand<"Maturity">, number>>;
143
+ expiry: z.ZodNumber;
144
+ start: z.ZodNumber;
145
+ nonce: z.ZodBigInt;
146
+ buy: z.ZodBoolean;
147
+ chainId: z.ZodBigInt;
148
+ loanToken: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
149
+ collaterals: z.ZodArray<z.ZodObject<{
150
+ asset: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
151
+ oracle: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
152
+ lltv: z.ZodPipe<z.ZodBigInt, z.ZodTransform<bigint & _morpho_dev_mempool.Brand<"LLTV">, bigint>>;
153
+ }, z.core.$strip>>;
154
+ callback: z.ZodObject<{
155
+ address: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
156
+ data: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
157
+ gasLimit: z.ZodBigInt;
158
+ }, z.core.$strip>;
159
+ signature: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>>;
160
+ createdAt: z.ZodOptional<z.ZodNumber>;
163
161
  consumed: z.ZodBigInt;
164
162
  status: z.ZodEnum<{
165
163
  valid: "valid";
@@ -170,7 +168,7 @@ declare const RouterOfferSchema: (parameters?: {
170
168
  metadata: z.ZodOptional<z.ZodObject<{
171
169
  issue: z.ZodString;
172
170
  }, z.core.$strip>>;
173
- }, zod_v4_core.$strip>;
171
+ }, z.core.$strip>;
174
172
  /**
175
173
  * ABI for the Consumed event emitted by the terms contract.
176
174
  */
@@ -381,6 +379,7 @@ type Client = Compute<RouterClientConfig & {
381
379
  declare function connect(opts?: {
382
380
  url?: string;
383
381
  apiKey?: string;
382
+ headers?: Headers;
384
383
  }): Client;
385
384
  declare namespace connect {
386
385
  type ErrorType = InvalidUrlError;
@@ -705,7 +704,8 @@ type Logger = {
705
704
  error: LogFn;
706
705
  fatal: LogFn;
707
706
  };
708
- declare function defaultLogger(): Logger;
707
+ declare function defaultLogger(minLevel?: LogLevel): Logger;
708
+ declare function silentLogger(): Logger;
709
709
  declare function runWithLogger<T>(logger: Logger, fn: () => Promise<T>): Promise<T>;
710
710
  declare function getLogger(): Logger;
711
711
 
@@ -716,8 +716,9 @@ type Logger$1_Logger = Logger;
716
716
  declare const Logger$1_defaultLogger: typeof defaultLogger;
717
717
  declare const Logger$1_getLogger: typeof getLogger;
718
718
  declare const Logger$1_runWithLogger: typeof runWithLogger;
719
+ declare const Logger$1_silentLogger: typeof silentLogger;
719
720
  declare namespace Logger$1 {
720
- export { type Logger$1_LogFn as LogFn, type Logger$1_LogLevel as LogLevel, Logger$1_LogLevelValues as LogLevelValues, type Logger$1_Logger as Logger, Logger$1_defaultLogger as defaultLogger, Logger$1_getLogger as getLogger, Logger$1_runWithLogger as runWithLogger };
721
+ export { type Logger$1_LogFn as LogFn, type Logger$1_LogLevel as LogLevel, Logger$1_LogLevelValues as LogLevelValues, type Logger$1_Logger as Logger, Logger$1_defaultLogger as defaultLogger, Logger$1_getLogger as getLogger, Logger$1_runWithLogger as runWithLogger, Logger$1_silentLogger as silentLogger };
721
722
  }
722
723
 
723
724
  declare const types: readonly ["offer_created", "offer_consumed", "offer_validation"];
@@ -5,9 +5,7 @@ import * as viem from 'viem';
5
5
  import { Address, Hex, PublicClient } from 'viem';
6
6
  import { Chain as Chain$2 } from 'viem/chains';
7
7
  import * as node_modules_zod_openapi_dist_components_DkyUTLcs_js from 'node_modules/zod-openapi/dist/components-DkyUTLcs.js';
8
- import * as zod_v4 from 'zod/v4';
9
8
  import { z, ZodError } from 'zod/v4';
10
- import * as zod_v4_core from 'zod/v4/core';
11
9
  import * as hono_utils_types from 'hono/utils/types';
12
10
  import * as hono from 'hono';
13
11
  import { Context } from 'hono';
@@ -137,29 +135,29 @@ type OfferConsumed = {
137
135
  };
138
136
  declare const RouterOfferSchema: (parameters?: {
139
137
  omitHash?: boolean;
140
- }) => zod_v4.ZodObject<{
141
- offering: zod_v4.ZodPipe<zod_v4.ZodString, zod_v4.ZodTransform<`0x${string}`, string>>;
142
- assets: zod_v4.ZodBigInt;
143
- rate: zod_v4.ZodBigInt;
144
- maturity: zod_v4.ZodPipe<zod_v4.ZodNumber, zod_v4.ZodTransform<number & _morpho_dev_mempool.Brand<"Maturity">, number>>;
145
- expiry: zod_v4.ZodNumber;
146
- start: zod_v4.ZodNumber;
147
- nonce: zod_v4.ZodBigInt;
148
- buy: zod_v4.ZodBoolean;
149
- chainId: zod_v4.ZodBigInt;
150
- loanToken: zod_v4.ZodPipe<zod_v4.ZodString, zod_v4.ZodTransform<`0x${string}`, string>>;
151
- collaterals: zod_v4.ZodArray<zod_v4.ZodObject<{
152
- asset: zod_v4.ZodPipe<zod_v4.ZodString, zod_v4.ZodTransform<`0x${string}`, string>>;
153
- oracle: zod_v4.ZodPipe<zod_v4.ZodString, zod_v4.ZodTransform<`0x${string}`, string>>;
154
- lltv: zod_v4.ZodPipe<zod_v4.ZodBigInt, zod_v4.ZodTransform<bigint & _morpho_dev_mempool.Brand<"LLTV">, bigint>>;
155
- }, zod_v4_core.$strip>>;
156
- callback: zod_v4.ZodObject<{
157
- address: zod_v4.ZodPipe<zod_v4.ZodString, zod_v4.ZodTransform<`0x${string}`, string>>;
158
- data: zod_v4.ZodPipe<zod_v4.ZodString, zod_v4.ZodTransform<`0x${string}`, string>>;
159
- gasLimit: zod_v4.ZodBigInt;
160
- }, zod_v4_core.$strip>;
161
- signature: zod_v4.ZodOptional<zod_v4.ZodPipe<zod_v4.ZodString, zod_v4.ZodTransform<`0x${string}`, string>>>;
162
- createdAt: zod_v4.ZodOptional<zod_v4.ZodNumber>;
138
+ }) => z.ZodObject<{
139
+ offering: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
140
+ assets: z.ZodBigInt;
141
+ rate: z.ZodBigInt;
142
+ maturity: z.ZodPipe<z.ZodNumber, z.ZodTransform<number & _morpho_dev_mempool.Brand<"Maturity">, number>>;
143
+ expiry: z.ZodNumber;
144
+ start: z.ZodNumber;
145
+ nonce: z.ZodBigInt;
146
+ buy: z.ZodBoolean;
147
+ chainId: z.ZodBigInt;
148
+ loanToken: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
149
+ collaterals: z.ZodArray<z.ZodObject<{
150
+ asset: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
151
+ oracle: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
152
+ lltv: z.ZodPipe<z.ZodBigInt, z.ZodTransform<bigint & _morpho_dev_mempool.Brand<"LLTV">, bigint>>;
153
+ }, z.core.$strip>>;
154
+ callback: z.ZodObject<{
155
+ address: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
156
+ data: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
157
+ gasLimit: z.ZodBigInt;
158
+ }, z.core.$strip>;
159
+ signature: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>>;
160
+ createdAt: z.ZodOptional<z.ZodNumber>;
163
161
  consumed: z.ZodBigInt;
164
162
  status: z.ZodEnum<{
165
163
  valid: "valid";
@@ -170,7 +168,7 @@ declare const RouterOfferSchema: (parameters?: {
170
168
  metadata: z.ZodOptional<z.ZodObject<{
171
169
  issue: z.ZodString;
172
170
  }, z.core.$strip>>;
173
- }, zod_v4_core.$strip>;
171
+ }, z.core.$strip>;
174
172
  /**
175
173
  * ABI for the Consumed event emitted by the terms contract.
176
174
  */
@@ -381,6 +379,7 @@ type Client = Compute<RouterClientConfig & {
381
379
  declare function connect(opts?: {
382
380
  url?: string;
383
381
  apiKey?: string;
382
+ headers?: Headers;
384
383
  }): Client;
385
384
  declare namespace connect {
386
385
  type ErrorType = InvalidUrlError;
@@ -705,7 +704,8 @@ type Logger = {
705
704
  error: LogFn;
706
705
  fatal: LogFn;
707
706
  };
708
- declare function defaultLogger(): Logger;
707
+ declare function defaultLogger(minLevel?: LogLevel): Logger;
708
+ declare function silentLogger(): Logger;
709
709
  declare function runWithLogger<T>(logger: Logger, fn: () => Promise<T>): Promise<T>;
710
710
  declare function getLogger(): Logger;
711
711
 
@@ -716,8 +716,9 @@ type Logger$1_Logger = Logger;
716
716
  declare const Logger$1_defaultLogger: typeof defaultLogger;
717
717
  declare const Logger$1_getLogger: typeof getLogger;
718
718
  declare const Logger$1_runWithLogger: typeof runWithLogger;
719
+ declare const Logger$1_silentLogger: typeof silentLogger;
719
720
  declare namespace Logger$1 {
720
- export { type Logger$1_LogFn as LogFn, type Logger$1_LogLevel as LogLevel, Logger$1_LogLevelValues as LogLevelValues, type Logger$1_Logger as Logger, Logger$1_defaultLogger as defaultLogger, Logger$1_getLogger as getLogger, Logger$1_runWithLogger as runWithLogger };
721
+ export { type Logger$1_LogFn as LogFn, type Logger$1_LogLevel as LogLevel, Logger$1_LogLevelValues as LogLevelValues, type Logger$1_Logger as Logger, Logger$1_defaultLogger as defaultLogger, Logger$1_getLogger as getLogger, Logger$1_runWithLogger as runWithLogger, Logger$1_silentLogger as silentLogger };
721
722
  }
722
723
 
723
724
  declare const types: readonly ["offer_created", "offer_consumed", "offer_validation"];
@@ -42,7 +42,7 @@ function getChain(chainId) {
42
42
  return chains[chainName];
43
43
  }
44
44
  var getWhitelistedChains = () => {
45
- return [chains.ethereum, chains["ethereum-virtual-testnet"]];
45
+ return [chains.ethereum, chains.base, chains["ethereum-virtual-testnet"]];
46
46
  };
47
47
  var chains = {
48
48
  ethereum: {
@@ -418,12 +418,15 @@ var GetOffersQueryParams = v4.z.object({
418
418
  description: "Filter by multiple rate oracles (comma-separated)",
419
419
  example: "0x1234567890123456789012345678901234567890,0xabcdefabcdefabcdefabcdefabcdefabcdefabcd"
420
420
  }),
421
- collateral_tuple: v4.z.string().regex(
422
- /^(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]+)?)?)*$/,
423
- {
424
- 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)."
421
+ collateral_tuple: v4.z.string().transform((val, ctx) => {
422
+ 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]+)?)?)*$/;
423
+ if (!pattern.test(val)) {
424
+ ctx.addIssue({
425
+ code: "custom",
426
+ message: "collateral_tuple has an invalid format",
427
+ input: val
428
+ });
425
429
  }
426
- ).transform((val, ctx) => {
427
430
  return val.split("#").map((tuple) => {
428
431
  const parts = tuple.split(":");
429
432
  if (parts.length === 0 || !parts[0]) {
@@ -553,9 +556,23 @@ var MatchOffersQueryParams = v4.z.object({
553
556
  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.",
554
557
  example: "buy"
555
558
  }),
556
- chain_id: v4.z.string().regex(/^\d+$/, {
557
- message: "Chain ID must be a positive integer"
558
- }).transform((val) => Number.parseInt(val, 10)).pipe(v4.z.number().positive()).meta({
559
+ chain_id: v4.z.string().transform((val, ctx) => {
560
+ const numericLike = /^-?\d+$/.test(val);
561
+ if (!numericLike) {
562
+ ctx.addIssue({
563
+ code: "custom",
564
+ message: "chain_id has an invalid format",
565
+ input: val
566
+ });
567
+ ctx.addIssue({
568
+ code: "custom",
569
+ message: "Invalid input: expected number, received NaN",
570
+ input: val
571
+ });
572
+ return v4.z.NEVER;
573
+ }
574
+ return Number.parseInt(val, 10);
575
+ }).pipe(v4.z.number().positive()).meta({
559
576
  description: "The blockchain network chain ID",
560
577
  example: "1"
561
578
  }),
@@ -567,12 +584,15 @@ var MatchOffersQueryParams = v4.z.object({
567
584
  example: "1000000000000000000"
568
585
  }),
569
586
  // Collateral filtering
570
- collaterals: v4.z.string().regex(
571
- /^(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]+)?)*$/,
572
- {
573
- message: "Collaterals must be in format: asset:oracle:lltv#asset2:oracle2:lltv2. All fields are required for each collateral."
587
+ collaterals: v4.z.string().transform((val, ctx) => {
588
+ 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]+)?)*$/;
589
+ if (!pattern.test(val)) {
590
+ ctx.addIssue({
591
+ code: "custom",
592
+ message: "Collaterals must be in format: asset:oracle:lltv#asset2:oracle2:lltv2. All fields are required for each collateral.",
593
+ input: val
594
+ });
574
595
  }
575
- ).transform((val, ctx) => {
576
596
  return val.split("#").map((collateral) => {
577
597
  const parts = collateral.split(":");
578
598
  if (parts.length !== 3) {
@@ -849,7 +869,7 @@ function connect(opts) {
849
869
  if (u.protocol !== "http:" && u.protocol !== "https:") {
850
870
  throw new InvalidUrlError(u.toString());
851
871
  }
852
- const headers = new Headers();
872
+ const headers = opts?.headers ?? new Headers();
853
873
  headers.set("Content-Type", "application/json");
854
874
  opts?.apiKey !== void 0 ? headers.set("X-API-Key", opts.apiKey) : null;
855
875
  const config = {
@@ -1626,7 +1646,8 @@ __export(Logger_exports, {
1626
1646
  LogLevelValues: () => LogLevelValues,
1627
1647
  defaultLogger: () => defaultLogger,
1628
1648
  getLogger: () => getLogger,
1629
- runWithLogger: () => runWithLogger
1649
+ runWithLogger: () => runWithLogger,
1650
+ silentLogger: () => silentLogger
1630
1651
  });
1631
1652
  var LogLevelValues = [
1632
1653
  "silent",
@@ -1637,20 +1658,50 @@ var LogLevelValues = [
1637
1658
  "error",
1638
1659
  "fatal"
1639
1660
  ];
1640
- function defaultLogger() {
1661
+ function defaultLogger(minLevel) {
1662
+ const threshold = minLevel ?? "trace";
1663
+ const levelIndexByName = LogLevelValues.reduce(
1664
+ (acc, lvl, idx) => {
1665
+ acc[lvl] = idx;
1666
+ return acc;
1667
+ },
1668
+ {}
1669
+ );
1670
+ const isEnabled = (methodLevel) => levelIndexByName[methodLevel] >= levelIndexByName[threshold];
1641
1671
  return {
1642
1672
  // biome-ignore lint/suspicious/noConsole: console is used for logging
1643
- trace: console.trace.bind(console),
1673
+ trace: isEnabled("trace") ? console.trace.bind(console) : () => {
1674
+ },
1644
1675
  // biome-ignore lint/suspicious/noConsole: console is used for logging
1645
- debug: console.debug.bind(console),
1676
+ debug: isEnabled("debug") ? console.debug.bind(console) : () => {
1677
+ },
1646
1678
  // biome-ignore lint/suspicious/noConsole: console is used for logging
1647
- info: console.info.bind(console),
1679
+ info: isEnabled("info") ? console.info.bind(console) : () => {
1680
+ },
1648
1681
  // biome-ignore lint/suspicious/noConsole: console is used for logging
1649
- warn: console.warn.bind(console),
1682
+ warn: isEnabled("warn") ? console.warn.bind(console) : () => {
1683
+ },
1650
1684
  // biome-ignore lint/suspicious/noConsole: console is used for logging
1651
- error: console.error.bind(console),
1652
- // biome-ignore lint/suspicious/noConsole: console.fatal does not exist
1653
- fatal: (...args) => console.error("[fatal]", ...args)
1685
+ error: isEnabled("error") ? console.error.bind(console) : () => {
1686
+ },
1687
+ fatal: isEnabled("fatal") ? (...args) => console.error("[fatal]", ...args) : () => {
1688
+ }
1689
+ };
1690
+ }
1691
+ function silentLogger() {
1692
+ return {
1693
+ trace: () => {
1694
+ },
1695
+ debug: () => {
1696
+ },
1697
+ info: () => {
1698
+ },
1699
+ warn: () => {
1700
+ },
1701
+ error: () => {
1702
+ },
1703
+ fatal: () => {
1704
+ }
1654
1705
  };
1655
1706
  }
1656
1707
  var loggerContext = new async_hooks.AsyncLocalStorage();