@morpho-dev/router 0.0.25 → 0.0.27

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.
@@ -23,7 +23,8 @@ __export(Chain_exports, {
23
23
  chainIds: () => chainIds,
24
24
  chainNames: () => chainNames,
25
25
  chains: () => chains,
26
- getChain: () => getChain
26
+ getChain: () => getChain,
27
+ getWhitelistedChains: () => getWhitelistedChains
27
28
  });
28
29
  var chainNames = ["ethereum", "base", "ethereum-virtual-testnet"];
29
30
  var ChainId = {
@@ -40,6 +41,9 @@ function getChain(chainId) {
40
41
  }
41
42
  return chains[chainName];
42
43
  }
44
+ var getWhitelistedChains = () => {
45
+ return [chains.ethereum, chains["ethereum-virtual-testnet"]];
46
+ };
43
47
  var chains = {
44
48
  ethereum: {
45
49
  ...chains$1.mainnet,
@@ -81,7 +85,8 @@ var chains = {
81
85
  // DAI
82
86
  ].map((address) => address.toLowerCase())
83
87
  ),
84
- morpho: "0x0000000000000000000000000000000000000000",
88
+ morpho: "0x11a002d45db720ed47a80d2f3489cba5b833eaf5",
89
+ // @TODO: This is mock Consumed contract, update with Terms once stable
85
90
  mempool: {
86
91
  address: "0x7be3164eeee8b35092f6128ec32c2e6ff8f6c890",
87
92
  deploymentBlock: 23223727,
@@ -106,7 +111,9 @@ __export(RouterOffer_exports, {
106
111
  InvalidRouterOfferError: () => InvalidRouterOfferError,
107
112
  OfferStatusValues: () => OfferStatusValues,
108
113
  RouterOfferSchema: () => RouterOfferSchema,
114
+ consumedEvent: () => consumedEvent,
109
115
  from: () => from,
116
+ fromConsumedLog: () => fromConsumedLog,
110
117
  fromSnakeCase: () => fromSnakeCase,
111
118
  random: () => random,
112
119
  toSnakeCase: () => toSnakeCase
@@ -124,6 +131,16 @@ var RouterOfferSchema = (parameters) => mempool.Offer.OfferSchema(parameters).ex
124
131
  issue: v4.z.string()
125
132
  }).optional()
126
133
  });
134
+ var consumedEvent = {
135
+ type: "event",
136
+ name: "Consumed",
137
+ inputs: [
138
+ { name: "user", type: "address", indexed: true, internalType: "address" },
139
+ { name: "nonce", type: "uint256", indexed: true, internalType: "uint256" },
140
+ { name: "amount", type: "uint256", indexed: false, internalType: "uint256" }
141
+ ],
142
+ anonymous: false
143
+ };
127
144
  function from(input) {
128
145
  try {
129
146
  const parsedOffer = RouterOfferSchema({ omitHash: true }).parse(input);
@@ -151,6 +168,16 @@ function random() {
151
168
  consumed: 0n
152
169
  });
153
170
  }
171
+ function fromConsumedLog(parameters) {
172
+ const { blockNumber, logIndex, chainId, transactionHash, user, nonce, amount } = parameters;
173
+ return {
174
+ id: `${blockNumber.toString()}-${logIndex.toString()}-${chainId}-${transactionHash}`,
175
+ chainId: BigInt(chainId),
176
+ offering: user,
177
+ nonce,
178
+ amount
179
+ };
180
+ }
154
181
  var InvalidRouterOfferError = class extends mempool.Errors.BaseError {
155
182
  name = "RouterOffer.InvalidRouterOfferError";
156
183
  constructor(error2) {
@@ -362,28 +389,14 @@ var GetOffersQueryParams = v4.z.object({
362
389
  example: "1500000000000000000"
363
390
  }),
364
391
  // Time range
365
- min_maturity: v4.z.coerce.number().int().positive().transform((maturity, ctx) => {
366
- try {
367
- return mempool.Maturity.from(maturity);
368
- } catch (e) {
369
- ctx.addIssue({
370
- code: "custom",
371
- message: e.message
372
- });
373
- return v4.z.NEVER;
374
- }
375
- }).optional(),
376
- max_maturity: v4.z.coerce.number().int().positive().transform((maturity, ctx) => {
377
- try {
378
- return mempool.Maturity.from(maturity);
379
- } catch (e) {
380
- ctx.addIssue({
381
- code: "custom",
382
- message: e.message
383
- });
384
- return v4.z.NEVER;
385
- }
386
- }).optional(),
392
+ min_maturity: v4.z.coerce.number().int().min(0).optional().meta({
393
+ description: "Minimum maturity timestamp (Unix timestamp in seconds)",
394
+ example: "1700000000"
395
+ }),
396
+ max_maturity: v4.z.coerce.number().int().min(0).optional().meta({
397
+ description: "Maximum maturity timestamp (Unix timestamp in seconds)",
398
+ example: "1800000000"
399
+ }),
387
400
  min_expiry: v4.z.coerce.number().int().optional().meta({
388
401
  description: "Minimum expiry timestamp (Unix timestamp in seconds)",
389
402
  example: "1700000000"
@@ -458,33 +471,11 @@ var GetOffersQueryParams = v4.z.object({
458
471
  description: "Filter by collateral combinations in format: asset:oracle:lltv#asset2:oracle2:lltv2. Oracle and lltv are optional. Use # to separate multiple combinations.",
459
472
  example: "0x1234567890123456789012345678901234567890:0xabcdefabcdefabcdefabcdefabcdefabcdefabcd:86#0x9876543210987654321098765432109876543210:94.5"
460
473
  }),
461
- min_lltv: v4.z.coerce.number().min(0, { message: "LLTV must be above 0" }).max(100, { message: "LLTV must be below 100" }).transform((lltv, ctx) => {
462
- try {
463
- return mempool.LLTV.from(viem.parseUnits(lltv.toString(), 16));
464
- } catch (e) {
465
- ctx.addIssue({
466
- code: "custom",
467
- message: e.message,
468
- input: lltv
469
- });
470
- return v4.z.NEVER;
471
- }
472
- }).optional().meta({
474
+ min_lltv: v4.z.coerce.number().min(0, { message: "LLTV must be above 0" }).max(100, { message: "LLTV must be below 100" }).optional().meta({
473
475
  description: "Minimum Loan-to-Value ratio (LLTV) for collateral (percentage as decimal, e.g., 80.5 = 80.5%)",
474
476
  example: "80.5"
475
477
  }),
476
- max_lltv: v4.z.coerce.number().min(0, { message: "LLTV must be above 0" }).max(100, { message: "LLTV must be below 100" }).transform((lltv, ctx) => {
477
- try {
478
- return mempool.LLTV.from(viem.parseUnits(lltv.toString(), 16));
479
- } catch (e) {
480
- ctx.addIssue({
481
- code: "custom",
482
- message: e.message,
483
- input: lltv
484
- });
485
- return v4.z.NEVER;
486
- }
487
- }).optional().meta({
478
+ max_lltv: v4.z.coerce.number().min(0, { message: "LLTV must be above 0" }).max(100, { message: "LLTV must be below 100" }).optional().meta({
488
479
  description: "Maximum Loan-to-Value ratio (LLTV) for collateral (percentage as decimal, e.g., 95.5 = 95.5%)",
489
480
  example: "95.5"
490
481
  }),
@@ -627,39 +618,18 @@ var MatchOffersQueryParams = v4.z.object({
627
618
  example: "0x1234567890123456789012345678901234567890:0xabcdefabcdefabcdefabcdefabcdefabcdefabcd:86#0x9876543210987654321098765432109876543210:0xfedcbafedcbafedcbafedcbafedcbafedcbafedc:94.5"
628
619
  }),
629
620
  // Maturity filtering
630
- maturity: v4.z.coerce.number().int().positive().transform((maturity, ctx) => {
631
- try {
632
- return mempool.Maturity.from(maturity);
633
- } catch (e) {
634
- ctx.addIssue({
635
- code: "custom",
636
- message: e.message
637
- });
638
- return v4.z.NEVER;
639
- }
640
- }).optional(),
641
- min_maturity: v4.z.coerce.number().int().positive().transform((maturity, ctx) => {
642
- try {
643
- return mempool.Maturity.from(maturity);
644
- } catch (e) {
645
- ctx.addIssue({
646
- code: "custom",
647
- message: e.message
648
- });
649
- return v4.z.NEVER;
650
- }
651
- }).optional(),
652
- max_maturity: v4.z.coerce.number().int().positive().transform((maturity, ctx) => {
653
- try {
654
- return mempool.Maturity.from(maturity);
655
- } catch (e) {
656
- ctx.addIssue({
657
- code: "custom",
658
- message: e.message
659
- });
660
- return v4.z.NEVER;
661
- }
662
- }).optional(),
621
+ maturity: v4.z.coerce.number().int().min(0).optional().meta({
622
+ description: "Maturity timestamp (Unix timestamp in seconds)",
623
+ example: "1700000000"
624
+ }),
625
+ min_maturity: v4.z.coerce.number().int().min(0).optional().meta({
626
+ description: "Minimum maturity timestamp (Unix timestamp in seconds)",
627
+ example: "1700000000"
628
+ }),
629
+ max_maturity: v4.z.coerce.number().int().min(0).optional().meta({
630
+ description: "Maximum maturity timestamp (Unix timestamp in seconds)",
631
+ example: "1800000000"
632
+ }),
663
633
  // Asset and creator filtering
664
634
  loan_token: v4.z.string().regex(/^0x[a-fA-F0-9]{40}$/, {
665
635
  message: "Loan asset must be a valid Ethereum address"
@@ -1111,6 +1081,7 @@ __export(OfferStore_exports, {
1111
1081
  function memory(parameters) {
1112
1082
  const map = parameters.offers;
1113
1083
  const filled = parameters.filled;
1084
+ const consumedIds = /* @__PURE__ */ new Set();
1114
1085
  const indexingProgress = /* @__PURE__ */ new Map();
1115
1086
  const create = async (parameters2) => {
1116
1087
  if (map.has(parameters2.offer.hash.toLowerCase())) return parameters2.offer.hash;
@@ -1280,8 +1251,12 @@ function memory(parameters) {
1280
1251
  )
1281
1252
  )
1282
1253
  ));
1283
- minLltv && (offers = offers.filter((o) => o.collaterals.every((c) => c.lltv >= minLltv)));
1284
- maxLltv && (offers = offers.filter((o) => o.collaterals.every((c) => c.lltv <= maxLltv)));
1254
+ minLltv && (offers = offers.filter(
1255
+ (o) => o.collaterals.every((c) => c.lltv >= viem.parseUnits(minLltv.toString(), 16))
1256
+ ));
1257
+ maxLltv && (offers = offers.filter(
1258
+ (o) => o.collaterals.every((c) => c.lltv <= viem.parseUnits(maxLltv.toString(), 16))
1259
+ ));
1285
1260
  offers = offers.sort((a, b) => sort(sortBy, sortOrder, a, b));
1286
1261
  let nextCursor = null;
1287
1262
  if (offers.length > limit) {
@@ -1444,12 +1419,15 @@ function memory(parameters) {
1444
1419
  });
1445
1420
  },
1446
1421
  updateConsumedAmount: async (parameters2) => {
1422
+ if (consumedIds.has(parameters2.id)) return;
1423
+ consumedIds.add(parameters2.id);
1447
1424
  const chainId = parameters2.chainId;
1448
1425
  const address = parameters2.offering.toLowerCase();
1449
1426
  const nonce = parameters2.nonce;
1450
1427
  const filledForChain = filled.get(chainId) || /* @__PURE__ */ new Map();
1451
1428
  const filledForOffering = filledForChain.get(address) || /* @__PURE__ */ new Map();
1452
- filledForOffering.set(nonce, parameters2.consumed);
1429
+ const current = filledForOffering.get(nonce) || 0n;
1430
+ filledForOffering.set(nonce, current + parameters2.consumed);
1453
1431
  filledForChain.set(address, filledForOffering);
1454
1432
  filled.set(chainId, filledForChain);
1455
1433
  },
@@ -1689,9 +1667,9 @@ __export(RouterEvent_exports, {
1689
1667
  from: () => from2,
1690
1668
  types: () => types
1691
1669
  });
1692
- var types = ["offer_created", "offer_matched", "offer_validation"];
1670
+ var types = ["offer_created", "offer_consumed", "offer_validation"];
1693
1671
  function from2(base) {
1694
- const id = `${base.type}:${base.offer.hash.toLowerCase()}`;
1672
+ const id = base.type === "offer_consumed" ? `${base.type}:${base.offerConsumed.id}` : `${base.type}:${base.offer.hash.toLowerCase()}`;
1695
1673
  return { id, ...base };
1696
1674
  }
1697
1675