@morpho-dev/router 0.1.0 → 0.1.2

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.
@@ -1,6 +1,5 @@
1
- import { Errors, LLTV, Offer, Format, Time, Maturity } from '@morpho-dev/mempool';
1
+ import { Errors, LLTV, Offer, Format, Time, Maturity, Chain } from '@morpho-dev/mempool';
2
2
  export * from '@morpho-dev/mempool';
3
- import { base, mainnet } from 'viem/chains';
4
3
  import { z } from 'zod/v4';
5
4
  import { createDocument } from 'zod-openapi';
6
5
  import { parseUnits, maxUint256, formatUnits, parseAbi } from 'viem';
@@ -15,85 +14,6 @@ var __export = (target, all) => {
15
14
  __defProp(target, name, { get: all[name], enumerable: true });
16
15
  };
17
16
 
18
- // src/Chain.ts
19
- var Chain_exports = {};
20
- __export(Chain_exports, {
21
- ChainId: () => ChainId,
22
- chainIds: () => chainIds,
23
- chainNames: () => chainNames,
24
- chains: () => chains,
25
- getChain: () => getChain,
26
- getWhitelistedChains: () => getWhitelistedChains
27
- });
28
- var chainNames = ["ethereum", "base", "ethereum-virtual-testnet"];
29
- var ChainId = {
30
- ETHEREUM: BigInt(mainnet.id),
31
- BASE: BigInt(base.id),
32
- "ETHEREUM-VIRTUAL-TESTNET": 109111114n
33
- };
34
- var chainIds = new Set(Object.values(ChainId));
35
- var chainNameLookup = new Map(Object.entries(ChainId).map(([key, value]) => [value, key]));
36
- function getChain(chainId) {
37
- const chainName = chainNameLookup.get(chainId)?.toLowerCase();
38
- if (!chainName) {
39
- return void 0;
40
- }
41
- return chains[chainName];
42
- }
43
- var getWhitelistedChains = () => {
44
- return [chains.ethereum, chains.base, chains["ethereum-virtual-testnet"]];
45
- };
46
- var chains = {
47
- ethereum: {
48
- ...mainnet,
49
- id: ChainId.ETHEREUM,
50
- name: "ethereum",
51
- whitelistedAssets: new Set(
52
- [
53
- "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
54
- // USDC
55
- "0x6B175474E89094C44Da98b954EedeAC495271d0F"
56
- // DAI
57
- ].map((address) => address.toLowerCase())
58
- ),
59
- morpho: "0x0000000000000000000000000000000000000000"
60
- },
61
- base: {
62
- ...base,
63
- id: ChainId.BASE,
64
- name: "base",
65
- whitelistedAssets: new Set(
66
- [
67
- "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
68
- // USDC
69
- "0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb"
70
- // DAI
71
- ].map((address) => address.toLowerCase())
72
- ),
73
- morpho: "0x0000000000000000000000000000000000000000"
74
- },
75
- "ethereum-virtual-testnet": {
76
- ...mainnet,
77
- id: 109111114n,
78
- name: "ethereum-virtual-testnet",
79
- whitelistedAssets: new Set(
80
- [
81
- "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
82
- // USDC
83
- "0x6B175474E89094C44Da98b954EedeAC495271d0F"
84
- // DAI
85
- ].map((address) => address.toLowerCase())
86
- ),
87
- morpho: "0x11a002d45db720ed47a80d2f3489cba5b833eaf5",
88
- // @TODO: This is mock Consumed contract, update with Terms once stable
89
- mempool: {
90
- address: "0x7be3164eeee8b35092f6128ec32c2e6ff8f6c890",
91
- deploymentBlock: 23223727,
92
- reindexBuffer: 10
93
- }
94
- }
95
- };
96
-
97
17
  // src/core/apiSchema/index.ts
98
18
  var apiSchema_exports = {};
99
19
  __export(apiSchema_exports, {
@@ -417,12 +337,15 @@ var GetOffersQueryParams = z.object({
417
337
  description: "Filter by multiple rate oracles (comma-separated)",
418
338
  example: "0x1234567890123456789012345678901234567890,0xabcdefabcdefabcdefabcdefabcdefabcdefabcd"
419
339
  }),
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)."
340
+ collateral_tuple: z.string().transform((val, ctx) => {
341
+ 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]+)?)?)*$/;
342
+ if (!pattern.test(val)) {
343
+ ctx.addIssue({
344
+ code: "custom",
345
+ message: "collateral_tuple has an invalid format",
346
+ input: val
347
+ });
424
348
  }
425
- ).transform((val, ctx) => {
426
349
  return val.split("#").map((tuple) => {
427
350
  const parts = tuple.split(":");
428
351
  if (parts.length === 0 || !parts[0]) {
@@ -552,9 +475,23 @@ var MatchOffersQueryParams = z.object({
552
475
  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
476
  example: "buy"
554
477
  }),
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({
478
+ chain_id: z.string().transform((val, ctx) => {
479
+ const numericLike = /^-?\d+$/.test(val);
480
+ if (!numericLike) {
481
+ ctx.addIssue({
482
+ code: "custom",
483
+ message: "chain_id has an invalid format",
484
+ input: val
485
+ });
486
+ ctx.addIssue({
487
+ code: "custom",
488
+ message: "Invalid input: expected number, received NaN",
489
+ input: val
490
+ });
491
+ return z.NEVER;
492
+ }
493
+ return Number.parseInt(val, 10);
494
+ }).pipe(z.number().positive()).meta({
558
495
  description: "The blockchain network chain ID",
559
496
  example: "1"
560
497
  }),
@@ -566,12 +503,15 @@ var MatchOffersQueryParams = z.object({
566
503
  example: "1000000000000000000"
567
504
  }),
568
505
  // 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."
506
+ collaterals: z.string().transform((val, ctx) => {
507
+ 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]+)?)*$/;
508
+ if (!pattern.test(val)) {
509
+ ctx.addIssue({
510
+ code: "custom",
511
+ message: "Collaterals must be in format: asset:oracle:lltv#asset2:oracle2:lltv2. All fields are required for each collateral.",
512
+ input: val
513
+ });
573
514
  }
574
- ).transform((val, ctx) => {
575
515
  return val.split("#").map((collateral) => {
576
516
  const parts = collateral.split(":");
577
517
  if (parts.length !== 3) {
@@ -1081,7 +1021,6 @@ function memory(parameters) {
1081
1021
  const map = parameters.offers;
1082
1022
  const filled = parameters.filled;
1083
1023
  const consumedIds = /* @__PURE__ */ new Set();
1084
- const indexingProgress = /* @__PURE__ */ new Map();
1085
1024
  const create = async (parameters2) => {
1086
1025
  if (map.has(parameters2.offer.hash.toLowerCase())) return parameters2.offer.hash;
1087
1026
  map.set(parameters2.offer.hash.toLowerCase(), {
@@ -1152,7 +1091,7 @@ function memory(parameters) {
1152
1091
  let {
1153
1092
  creators,
1154
1093
  side,
1155
- chains: chains2,
1094
+ chains,
1156
1095
  loanTokens,
1157
1096
  status = ["valid"],
1158
1097
  callbackAddresses,
@@ -1223,7 +1162,7 @@ function memory(parameters) {
1223
1162
  offers = offers.filter((o) => o.expiry >= now);
1224
1163
  creators && (offers = offers.filter((o) => creators.includes(o.offering.toLowerCase())));
1225
1164
  side && (offers = offers.filter((o) => o.buy === buy));
1226
- chains2 && (offers = offers.filter((o) => chains2.includes(Number(o.chainId))));
1165
+ chains && (offers = offers.filter((o) => chains.includes(Number(o.chainId))));
1227
1166
  loanTokens && (offers = offers.filter((o) => loanTokens.includes(o.loanToken.toLowerCase())));
1228
1167
  status && (offers = offers.filter((o) => status.includes(o.status)));
1229
1168
  callbackAddresses && (offers = offers.filter(
@@ -1429,15 +1368,6 @@ function memory(parameters) {
1429
1368
  filledForOffering.set(nonce, current + parameters2.consumed);
1430
1369
  filledForChain.set(address, filledForOffering);
1431
1370
  filled.set(chainId, filledForChain);
1432
- },
1433
- saveLatestBlockNumberProcessed: async (parameters2) => {
1434
- const key = `${parameters2.chainId.toString()}:${parameters2.eventType}`;
1435
- indexingProgress.set(key, parameters2.latestBlockNumber);
1436
- },
1437
- getLatestBlockNumberProcessed: async (parameters2) => {
1438
- const key = `${parameters2.chainId.toString()}:${parameters2.eventType}`;
1439
- const value = indexingProgress.get(key);
1440
- return value === void 0 ? null : { latestBlockNumber: value };
1441
1371
  }
1442
1372
  };
1443
1373
  }
@@ -1825,7 +1755,7 @@ function morpho(parameters) {
1825
1755
  );
1826
1756
  const buyOffersPerLoanAsset = /* @__PURE__ */ new Map();
1827
1757
  for (const offer of buyOffers) {
1828
- const chainName = getChain(offer.chainId)?.name;
1758
+ const chainName = Chain.getChain(offer.chainId)?.name;
1829
1759
  const loanTokens = buyOffersPerLoanAsset.get(chainName) ?? /* @__PURE__ */ new Map();
1830
1760
  const offers2 = loanTokens.get(offer.loanToken.toLowerCase()) ?? [];
1831
1761
  offers2.push(offer);
@@ -1836,7 +1766,7 @@ function morpho(parameters) {
1836
1766
  Array.from(buyOffersPerLoanAsset.entries()).map(async ([name, loanTokens]) => {
1837
1767
  const chainName = name;
1838
1768
  const publicClient = publicClients[chainName];
1839
- const morpho2 = morphoPerChain.get(chains[chainName].id);
1769
+ const morpho2 = morphoPerChain.get(Chain.chains[chainName].id);
1840
1770
  if (!publicClient) {
1841
1771
  const offers2 = Array.from(loanTokens.values()).flat();
1842
1772
  for (const offer of offers2) {
@@ -1916,6 +1846,6 @@ function morpho(parameters) {
1916
1846
  ];
1917
1847
  }
1918
1848
 
1919
- export { apiSchema_exports as ApiSchema, Chain_exports as Chain, Logger_exports as Logger, OfferStore_exports as OfferStore, router_exports as Router, RouterEvent_exports as RouterEvent, RouterOffer_exports as RouterOffer, utils_exports as Utils, Validation_exports as Validation, ValidationRule_exports as ValidationRule };
1849
+ export { apiSchema_exports as ApiSchema, Logger_exports as Logger, OfferStore_exports as OfferStore, router_exports as Router, RouterEvent_exports as RouterEvent, RouterOffer_exports as RouterOffer, utils_exports as Utils, Validation_exports as Validation, ValidationRule_exports as ValidationRule };
1920
1850
  //# sourceMappingURL=index.node.mjs.map
1921
1851
  //# sourceMappingURL=index.node.mjs.map