@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 { parseUnits, maxUint256, formatUnits, parseAbi } from 'viem';
@@ -21,7 +21,8 @@ __export(Chain_exports, {
21
21
  chainIds: () => chainIds,
22
22
  chainNames: () => chainNames,
23
23
  chains: () => chains,
24
- getChain: () => getChain
24
+ getChain: () => getChain,
25
+ getWhitelistedChains: () => getWhitelistedChains
25
26
  });
26
27
  var chainNames = ["ethereum", "base", "ethereum-virtual-testnet"];
27
28
  var ChainId = {
@@ -38,6 +39,9 @@ function getChain(chainId) {
38
39
  }
39
40
  return chains[chainName];
40
41
  }
42
+ var getWhitelistedChains = () => {
43
+ return [chains.ethereum, chains["ethereum-virtual-testnet"]];
44
+ };
41
45
  var chains = {
42
46
  ethereum: {
43
47
  ...mainnet,
@@ -79,7 +83,8 @@ var chains = {
79
83
  // DAI
80
84
  ].map((address) => address.toLowerCase())
81
85
  ),
82
- morpho: "0x0000000000000000000000000000000000000000",
86
+ morpho: "0x11a002d45db720ed47a80d2f3489cba5b833eaf5",
87
+ // @TODO: This is mock Consumed contract, update with Terms once stable
83
88
  mempool: {
84
89
  address: "0x7be3164eeee8b35092f6128ec32c2e6ff8f6c890",
85
90
  deploymentBlock: 23223727,
@@ -107,7 +112,9 @@ __export(RouterOffer_exports, {
107
112
  InvalidRouterOfferError: () => InvalidRouterOfferError,
108
113
  OfferStatusValues: () => OfferStatusValues,
109
114
  RouterOfferSchema: () => RouterOfferSchema,
115
+ consumedEvent: () => consumedEvent,
110
116
  from: () => from,
117
+ fromConsumedLog: () => fromConsumedLog,
111
118
  fromSnakeCase: () => fromSnakeCase,
112
119
  random: () => random,
113
120
  toSnakeCase: () => toSnakeCase
@@ -125,6 +132,16 @@ var RouterOfferSchema = (parameters) => Offer.OfferSchema(parameters).extend({
125
132
  issue: z.string()
126
133
  }).optional()
127
134
  });
135
+ var consumedEvent = {
136
+ type: "event",
137
+ name: "Consumed",
138
+ inputs: [
139
+ { name: "user", type: "address", indexed: true, internalType: "address" },
140
+ { name: "nonce", type: "uint256", indexed: true, internalType: "uint256" },
141
+ { name: "amount", type: "uint256", indexed: false, internalType: "uint256" }
142
+ ],
143
+ anonymous: false
144
+ };
128
145
  function from(input) {
129
146
  try {
130
147
  const parsedOffer = RouterOfferSchema({ omitHash: true }).parse(input);
@@ -152,6 +169,16 @@ function random() {
152
169
  consumed: 0n
153
170
  });
154
171
  }
172
+ function fromConsumedLog(parameters) {
173
+ const { blockNumber, logIndex, chainId, transactionHash, user, nonce, amount } = parameters;
174
+ return {
175
+ id: `${blockNumber.toString()}-${logIndex.toString()}-${chainId}-${transactionHash}`,
176
+ chainId: BigInt(chainId),
177
+ offering: user,
178
+ nonce,
179
+ amount
180
+ };
181
+ }
155
182
  var InvalidRouterOfferError = class extends Errors.BaseError {
156
183
  constructor(error) {
157
184
  super("Invalid router offer.", { cause: error });
@@ -363,28 +390,14 @@ var GetOffersQueryParams = z.object({
363
390
  example: "1500000000000000000"
364
391
  }),
365
392
  // Time range
366
- min_maturity: z.coerce.number().int().positive().transform((maturity, ctx) => {
367
- try {
368
- return Maturity.from(maturity);
369
- } catch (e) {
370
- ctx.addIssue({
371
- code: "custom",
372
- message: e.message
373
- });
374
- return z.NEVER;
375
- }
376
- }).optional(),
377
- max_maturity: z.coerce.number().int().positive().transform((maturity, ctx) => {
378
- try {
379
- return Maturity.from(maturity);
380
- } catch (e) {
381
- ctx.addIssue({
382
- code: "custom",
383
- message: e.message
384
- });
385
- return z.NEVER;
386
- }
387
- }).optional(),
393
+ min_maturity: z.coerce.number().int().min(0).optional().meta({
394
+ description: "Minimum maturity timestamp (Unix timestamp in seconds)",
395
+ example: "1700000000"
396
+ }),
397
+ max_maturity: z.coerce.number().int().min(0).optional().meta({
398
+ description: "Maximum maturity timestamp (Unix timestamp in seconds)",
399
+ example: "1800000000"
400
+ }),
388
401
  min_expiry: z.coerce.number().int().optional().meta({
389
402
  description: "Minimum expiry timestamp (Unix timestamp in seconds)",
390
403
  example: "1700000000"
@@ -459,33 +472,11 @@ var GetOffersQueryParams = z.object({
459
472
  description: "Filter by collateral combinations in format: asset:oracle:lltv#asset2:oracle2:lltv2. Oracle and lltv are optional. Use # to separate multiple combinations.",
460
473
  example: "0x1234567890123456789012345678901234567890:0xabcdefabcdefabcdefabcdefabcdefabcdefabcd:86#0x9876543210987654321098765432109876543210:94.5"
461
474
  }),
462
- min_lltv: z.coerce.number().min(0, { message: "LLTV must be above 0" }).max(100, { message: "LLTV must be below 100" }).transform((lltv, ctx) => {
463
- try {
464
- return LLTV.from(parseUnits(lltv.toString(), 16));
465
- } catch (e) {
466
- ctx.addIssue({
467
- code: "custom",
468
- message: e.message,
469
- input: lltv
470
- });
471
- return z.NEVER;
472
- }
473
- }).optional().meta({
475
+ min_lltv: z.coerce.number().min(0, { message: "LLTV must be above 0" }).max(100, { message: "LLTV must be below 100" }).optional().meta({
474
476
  description: "Minimum Loan-to-Value ratio (LLTV) for collateral (percentage as decimal, e.g., 80.5 = 80.5%)",
475
477
  example: "80.5"
476
478
  }),
477
- max_lltv: z.coerce.number().min(0, { message: "LLTV must be above 0" }).max(100, { message: "LLTV must be below 100" }).transform((lltv, ctx) => {
478
- try {
479
- return LLTV.from(parseUnits(lltv.toString(), 16));
480
- } catch (e) {
481
- ctx.addIssue({
482
- code: "custom",
483
- message: e.message,
484
- input: lltv
485
- });
486
- return z.NEVER;
487
- }
488
- }).optional().meta({
479
+ max_lltv: z.coerce.number().min(0, { message: "LLTV must be above 0" }).max(100, { message: "LLTV must be below 100" }).optional().meta({
489
480
  description: "Maximum Loan-to-Value ratio (LLTV) for collateral (percentage as decimal, e.g., 95.5 = 95.5%)",
490
481
  example: "95.5"
491
482
  }),
@@ -628,39 +619,18 @@ var MatchOffersQueryParams = z.object({
628
619
  example: "0x1234567890123456789012345678901234567890:0xabcdefabcdefabcdefabcdefabcdefabcdefabcd:86#0x9876543210987654321098765432109876543210:0xfedcbafedcbafedcbafedcbafedcbafedcbafedc:94.5"
629
620
  }),
630
621
  // Maturity filtering
631
- maturity: z.coerce.number().int().positive().transform((maturity, ctx) => {
632
- try {
633
- return Maturity.from(maturity);
634
- } catch (e) {
635
- ctx.addIssue({
636
- code: "custom",
637
- message: e.message
638
- });
639
- return z.NEVER;
640
- }
641
- }).optional(),
642
- min_maturity: z.coerce.number().int().positive().transform((maturity, ctx) => {
643
- try {
644
- return Maturity.from(maturity);
645
- } catch (e) {
646
- ctx.addIssue({
647
- code: "custom",
648
- message: e.message
649
- });
650
- return z.NEVER;
651
- }
652
- }).optional(),
653
- max_maturity: z.coerce.number().int().positive().transform((maturity, ctx) => {
654
- try {
655
- return Maturity.from(maturity);
656
- } catch (e) {
657
- ctx.addIssue({
658
- code: "custom",
659
- message: e.message
660
- });
661
- return z.NEVER;
662
- }
663
- }).optional(),
622
+ maturity: z.coerce.number().int().min(0).optional().meta({
623
+ description: "Maturity timestamp (Unix timestamp in seconds)",
624
+ example: "1700000000"
625
+ }),
626
+ min_maturity: z.coerce.number().int().min(0).optional().meta({
627
+ description: "Minimum maturity timestamp (Unix timestamp in seconds)",
628
+ example: "1700000000"
629
+ }),
630
+ max_maturity: z.coerce.number().int().min(0).optional().meta({
631
+ description: "Maximum maturity timestamp (Unix timestamp in seconds)",
632
+ example: "1800000000"
633
+ }),
664
634
  // Asset and creator filtering
665
635
  loan_token: z.string().regex(/^0x[a-fA-F0-9]{40}$/, {
666
636
  message: "Loan asset must be a valid Ethereum address"
@@ -1089,6 +1059,7 @@ __export(OfferStore_exports, {
1089
1059
  function memory(parameters) {
1090
1060
  const map = parameters.offers;
1091
1061
  const filled = parameters.filled;
1062
+ const consumedIds = /* @__PURE__ */ new Set();
1092
1063
  const indexingProgress = /* @__PURE__ */ new Map();
1093
1064
  const create = async (parameters2) => {
1094
1065
  if (map.has(parameters2.offer.hash.toLowerCase())) return parameters2.offer.hash;
@@ -1258,8 +1229,12 @@ function memory(parameters) {
1258
1229
  )
1259
1230
  )
1260
1231
  ));
1261
- minLltv && (offers = offers.filter((o) => o.collaterals.every((c) => c.lltv >= minLltv)));
1262
- maxLltv && (offers = offers.filter((o) => o.collaterals.every((c) => c.lltv <= maxLltv)));
1232
+ minLltv && (offers = offers.filter(
1233
+ (o) => o.collaterals.every((c) => c.lltv >= parseUnits(minLltv.toString(), 16))
1234
+ ));
1235
+ maxLltv && (offers = offers.filter(
1236
+ (o) => o.collaterals.every((c) => c.lltv <= parseUnits(maxLltv.toString(), 16))
1237
+ ));
1263
1238
  offers = offers.sort((a, b) => sort(sortBy, sortOrder, a, b));
1264
1239
  let nextCursor = null;
1265
1240
  if (offers.length > limit) {
@@ -1422,12 +1397,15 @@ function memory(parameters) {
1422
1397
  });
1423
1398
  },
1424
1399
  updateConsumedAmount: async (parameters2) => {
1400
+ if (consumedIds.has(parameters2.id)) return;
1401
+ consumedIds.add(parameters2.id);
1425
1402
  const chainId = parameters2.chainId;
1426
1403
  const address = parameters2.offering.toLowerCase();
1427
1404
  const nonce = parameters2.nonce;
1428
1405
  const filledForChain = filled.get(chainId) || /* @__PURE__ */ new Map();
1429
1406
  const filledForOffering = filledForChain.get(address) || /* @__PURE__ */ new Map();
1430
- filledForOffering.set(nonce, parameters2.consumed);
1407
+ const current = filledForOffering.get(nonce) || 0n;
1408
+ filledForOffering.set(nonce, current + parameters2.consumed);
1431
1409
  filledForChain.set(address, filledForOffering);
1432
1410
  filled.set(chainId, filledForChain);
1433
1411
  },
@@ -1449,9 +1427,9 @@ __export(RouterEvent_exports, {
1449
1427
  from: () => from2,
1450
1428
  types: () => types
1451
1429
  });
1452
- var types = ["offer_created", "offer_matched", "offer_validation"];
1430
+ var types = ["offer_created", "offer_consumed", "offer_validation"];
1453
1431
  function from2(base) {
1454
- const id = `${base.type}:${base.offer.hash.toLowerCase()}`;
1432
+ const id = base.type === "offer_consumed" ? `${base.type}:${base.offerConsumed.id}` : `${base.type}:${base.offer.hash.toLowerCase()}`;
1455
1433
  return { id, ...base };
1456
1434
  }
1457
1435