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