@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 { parseUnits, maxUint256, formatUnits, parseAbi } from 'viem';
5
4
  import { z } from 'zod/v4';
6
5
  import { createDocument } from 'zod-openapi';
@@ -14,85 +13,6 @@ var __export = (target, all) => {
14
13
  };
15
14
  var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
16
15
 
17
- // src/Chain.ts
18
- var Chain_exports = {};
19
- __export(Chain_exports, {
20
- ChainId: () => ChainId,
21
- chainIds: () => chainIds,
22
- chainNames: () => chainNames,
23
- chains: () => chains,
24
- getChain: () => getChain,
25
- getWhitelistedChains: () => getWhitelistedChains
26
- });
27
- var chainNames = ["ethereum", "base", "ethereum-virtual-testnet"];
28
- var ChainId = {
29
- ETHEREUM: BigInt(mainnet.id),
30
- BASE: BigInt(base.id),
31
- "ETHEREUM-VIRTUAL-TESTNET": 109111114n
32
- };
33
- var chainIds = new Set(Object.values(ChainId));
34
- var chainNameLookup = new Map(Object.entries(ChainId).map(([key, value]) => [value, key]));
35
- function getChain(chainId) {
36
- const chainName = chainNameLookup.get(chainId)?.toLowerCase();
37
- if (!chainName) {
38
- return void 0;
39
- }
40
- return chains[chainName];
41
- }
42
- var getWhitelistedChains = () => {
43
- return [chains.ethereum, chains.base, chains["ethereum-virtual-testnet"]];
44
- };
45
- var chains = {
46
- ethereum: {
47
- ...mainnet,
48
- id: ChainId.ETHEREUM,
49
- name: "ethereum",
50
- whitelistedAssets: new Set(
51
- [
52
- "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
53
- // USDC
54
- "0x6B175474E89094C44Da98b954EedeAC495271d0F"
55
- // DAI
56
- ].map((address) => address.toLowerCase())
57
- ),
58
- morpho: "0x0000000000000000000000000000000000000000"
59
- },
60
- base: {
61
- ...base,
62
- id: ChainId.BASE,
63
- name: "base",
64
- whitelistedAssets: new Set(
65
- [
66
- "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
67
- // USDC
68
- "0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb"
69
- // DAI
70
- ].map((address) => address.toLowerCase())
71
- ),
72
- morpho: "0x0000000000000000000000000000000000000000"
73
- },
74
- "ethereum-virtual-testnet": {
75
- ...mainnet,
76
- id: 109111114n,
77
- name: "ethereum-virtual-testnet",
78
- whitelistedAssets: new Set(
79
- [
80
- "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
81
- // USDC
82
- "0x6B175474E89094C44Da98b954EedeAC495271d0F"
83
- // DAI
84
- ].map((address) => address.toLowerCase())
85
- ),
86
- morpho: "0x11a002d45db720ed47a80d2f3489cba5b833eaf5",
87
- // @TODO: This is mock Consumed contract, update with Terms once stable
88
- mempool: {
89
- address: "0x7be3164eeee8b35092f6128ec32c2e6ff8f6c890",
90
- deploymentBlock: 23223727,
91
- reindexBuffer: 10
92
- }
93
- }
94
- };
95
-
96
16
  // src/core/router/Client.ts
97
17
  var Client_exports = {};
98
18
  __export(Client_exports, {
@@ -419,12 +339,15 @@ var GetOffersQueryParams = z.object({
419
339
  description: "Filter by multiple rate oracles (comma-separated)",
420
340
  example: "0x1234567890123456789012345678901234567890,0xabcdefabcdefabcdefabcdefabcdefabcdefabcd"
421
341
  }),
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)."
342
+ collateral_tuple: z.string().transform((val, ctx) => {
343
+ 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]+)?)?)*$/;
344
+ if (!pattern.test(val)) {
345
+ ctx.addIssue({
346
+ code: "custom",
347
+ message: "collateral_tuple has an invalid format",
348
+ input: val
349
+ });
426
350
  }
427
- ).transform((val, ctx) => {
428
351
  return val.split("#").map((tuple) => {
429
352
  const parts = tuple.split(":");
430
353
  if (parts.length === 0 || !parts[0]) {
@@ -554,9 +477,23 @@ var MatchOffersQueryParams = z.object({
554
477
  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
478
  example: "buy"
556
479
  }),
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({
480
+ chain_id: z.string().transform((val, ctx) => {
481
+ const numericLike = /^-?\d+$/.test(val);
482
+ if (!numericLike) {
483
+ ctx.addIssue({
484
+ code: "custom",
485
+ message: "chain_id has an invalid format",
486
+ input: val
487
+ });
488
+ ctx.addIssue({
489
+ code: "custom",
490
+ message: "Invalid input: expected number, received NaN",
491
+ input: val
492
+ });
493
+ return z.NEVER;
494
+ }
495
+ return Number.parseInt(val, 10);
496
+ }).pipe(z.number().positive()).meta({
560
497
  description: "The blockchain network chain ID",
561
498
  example: "1"
562
499
  }),
@@ -568,12 +505,15 @@ var MatchOffersQueryParams = z.object({
568
505
  example: "1000000000000000000"
569
506
  }),
570
507
  // 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."
508
+ collaterals: z.string().transform((val, ctx) => {
509
+ 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]+)?)*$/;
510
+ if (!pattern.test(val)) {
511
+ ctx.addIssue({
512
+ code: "custom",
513
+ message: "Collaterals must be in format: asset:oracle:lltv#asset2:oracle2:lltv2. All fields are required for each collateral.",
514
+ input: val
515
+ });
575
516
  }
576
- ).transform((val, ctx) => {
577
517
  return val.split("#").map((collateral) => {
578
518
  const parts = collateral.split(":");
579
519
  if (parts.length !== 3) {
@@ -1060,7 +1000,6 @@ function memory(parameters) {
1060
1000
  const map = parameters.offers;
1061
1001
  const filled = parameters.filled;
1062
1002
  const consumedIds = /* @__PURE__ */ new Set();
1063
- const indexingProgress = /* @__PURE__ */ new Map();
1064
1003
  const create = async (parameters2) => {
1065
1004
  if (map.has(parameters2.offer.hash.toLowerCase())) return parameters2.offer.hash;
1066
1005
  map.set(parameters2.offer.hash.toLowerCase(), {
@@ -1131,7 +1070,7 @@ function memory(parameters) {
1131
1070
  let {
1132
1071
  creators,
1133
1072
  side,
1134
- chains: chains2,
1073
+ chains,
1135
1074
  loanTokens,
1136
1075
  status = ["valid"],
1137
1076
  callbackAddresses,
@@ -1202,7 +1141,7 @@ function memory(parameters) {
1202
1141
  offers = offers.filter((o) => o.expiry >= now);
1203
1142
  creators && (offers = offers.filter((o) => creators.includes(o.offering.toLowerCase())));
1204
1143
  side && (offers = offers.filter((o) => o.buy === buy));
1205
- chains2 && (offers = offers.filter((o) => chains2.includes(Number(o.chainId))));
1144
+ chains && (offers = offers.filter((o) => chains.includes(Number(o.chainId))));
1206
1145
  loanTokens && (offers = offers.filter((o) => loanTokens.includes(o.loanToken.toLowerCase())));
1207
1146
  status && (offers = offers.filter((o) => status.includes(o.status)));
1208
1147
  callbackAddresses && (offers = offers.filter(
@@ -1408,15 +1347,6 @@ function memory(parameters) {
1408
1347
  filledForOffering.set(nonce, current + parameters2.consumed);
1409
1348
  filledForChain.set(address, filledForOffering);
1410
1349
  filled.set(chainId, filledForChain);
1411
- },
1412
- saveLatestBlockNumberProcessed: async (parameters2) => {
1413
- const key = `${parameters2.chainId.toString()}:${parameters2.eventType}`;
1414
- indexingProgress.set(key, parameters2.latestBlockNumber);
1415
- },
1416
- getLatestBlockNumberProcessed: async (parameters2) => {
1417
- const key = `${parameters2.chainId.toString()}:${parameters2.eventType}`;
1418
- const value = indexingProgress.get(key);
1419
- return value === void 0 ? null : { latestBlockNumber: value };
1420
1350
  }
1421
1351
  };
1422
1352
  }
@@ -1555,7 +1485,7 @@ function morpho(parameters) {
1555
1485
  );
1556
1486
  const buyOffersPerLoanAsset = /* @__PURE__ */ new Map();
1557
1487
  for (const offer of buyOffers) {
1558
- const chainName = getChain(offer.chainId)?.name;
1488
+ const chainName = Chain.getChain(offer.chainId)?.name;
1559
1489
  const loanTokens = buyOffersPerLoanAsset.get(chainName) ?? /* @__PURE__ */ new Map();
1560
1490
  const offers2 = loanTokens.get(offer.loanToken.toLowerCase()) ?? [];
1561
1491
  offers2.push(offer);
@@ -1566,7 +1496,7 @@ function morpho(parameters) {
1566
1496
  Array.from(buyOffersPerLoanAsset.entries()).map(async ([name, loanTokens]) => {
1567
1497
  const chainName = name;
1568
1498
  const publicClient = publicClients[chainName];
1569
- const morpho2 = morphoPerChain.get(chains[chainName].id);
1499
+ const morpho2 = morphoPerChain.get(Chain.chains[chainName].id);
1570
1500
  if (!publicClient) {
1571
1501
  const offers2 = Array.from(loanTokens.values()).flat();
1572
1502
  for (const offer of offers2) {
@@ -1646,6 +1576,6 @@ function morpho(parameters) {
1646
1576
  ];
1647
1577
  }
1648
1578
 
1649
- export { Chain_exports as Chain, OfferStore_exports as OfferStore, Client_exports as Router, RouterEvent_exports as RouterEvent, RouterOffer_exports as RouterOffer, utils_exports as Utils, Validation_exports as Validation, ValidationRule_exports as ValidationRule };
1579
+ export { OfferStore_exports as OfferStore, Client_exports as Router, RouterEvent_exports as RouterEvent, RouterOffer_exports as RouterOffer, utils_exports as Utils, Validation_exports as Validation, ValidationRule_exports as ValidationRule };
1650
1580
  //# sourceMappingURL=index.browser.mjs.map
1651
1581
  //# sourceMappingURL=index.browser.mjs.map