@morpho-dev/router 0.0.26 → 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,
@@ -51,8 +55,7 @@ var chains = {
51
55
  // DAI
52
56
  ].map((address) => address.toLowerCase())
53
57
  ),
54
- morpho: "0x0000000000000000000000000000000000000000",
55
- termsContract: "0x0000000000000000000000000000000000000000"
58
+ morpho: "0x0000000000000000000000000000000000000000"
56
59
  },
57
60
  base: {
58
61
  ...base,
@@ -66,8 +69,7 @@ var chains = {
66
69
  // DAI
67
70
  ].map((address) => address.toLowerCase())
68
71
  ),
69
- morpho: "0x0000000000000000000000000000000000000000",
70
- termsContract: "0x0000000000000000000000000000000000000000"
72
+ morpho: "0x0000000000000000000000000000000000000000"
71
73
  },
72
74
  "ethereum-virtual-testnet": {
73
75
  ...mainnet,
@@ -81,8 +83,8 @@ var chains = {
81
83
  // DAI
82
84
  ].map((address) => address.toLowerCase())
83
85
  ),
84
- morpho: "0x0000000000000000000000000000000000000000",
85
- termsContract: "0xa85d462ceb11d6f91f003072fdc701b0a1bbd8bd",
86
+ morpho: "0x11a002d45db720ed47a80d2f3489cba5b833eaf5",
87
+ // @TODO: This is mock Consumed contract, update with Terms once stable
86
88
  mempool: {
87
89
  address: "0x7be3164eeee8b35092f6128ec32c2e6ff8f6c890",
88
90
  deploymentBlock: 23223727,
@@ -388,28 +390,14 @@ var GetOffersQueryParams = z.object({
388
390
  example: "1500000000000000000"
389
391
  }),
390
392
  // Time range
391
- min_maturity: z.coerce.number().int().positive().transform((maturity, ctx) => {
392
- try {
393
- return Maturity.from(maturity);
394
- } catch (e) {
395
- ctx.addIssue({
396
- code: "custom",
397
- message: e.message
398
- });
399
- return z.NEVER;
400
- }
401
- }).optional(),
402
- max_maturity: z.coerce.number().int().positive().transform((maturity, ctx) => {
403
- try {
404
- return Maturity.from(maturity);
405
- } catch (e) {
406
- ctx.addIssue({
407
- code: "custom",
408
- message: e.message
409
- });
410
- return z.NEVER;
411
- }
412
- }).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
+ }),
413
401
  min_expiry: z.coerce.number().int().optional().meta({
414
402
  description: "Minimum expiry timestamp (Unix timestamp in seconds)",
415
403
  example: "1700000000"
@@ -484,33 +472,11 @@ var GetOffersQueryParams = z.object({
484
472
  description: "Filter by collateral combinations in format: asset:oracle:lltv#asset2:oracle2:lltv2. Oracle and lltv are optional. Use # to separate multiple combinations.",
485
473
  example: "0x1234567890123456789012345678901234567890:0xabcdefabcdefabcdefabcdefabcdefabcdefabcd:86#0x9876543210987654321098765432109876543210:94.5"
486
474
  }),
487
- min_lltv: z.coerce.number().min(0, { message: "LLTV must be above 0" }).max(100, { message: "LLTV must be below 100" }).transform((lltv, ctx) => {
488
- try {
489
- return LLTV.from(parseUnits(lltv.toString(), 16));
490
- } catch (e) {
491
- ctx.addIssue({
492
- code: "custom",
493
- message: e.message,
494
- input: lltv
495
- });
496
- return z.NEVER;
497
- }
498
- }).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({
499
476
  description: "Minimum Loan-to-Value ratio (LLTV) for collateral (percentage as decimal, e.g., 80.5 = 80.5%)",
500
477
  example: "80.5"
501
478
  }),
502
- max_lltv: z.coerce.number().min(0, { message: "LLTV must be above 0" }).max(100, { message: "LLTV must be below 100" }).transform((lltv, ctx) => {
503
- try {
504
- return LLTV.from(parseUnits(lltv.toString(), 16));
505
- } catch (e) {
506
- ctx.addIssue({
507
- code: "custom",
508
- message: e.message,
509
- input: lltv
510
- });
511
- return z.NEVER;
512
- }
513
- }).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({
514
480
  description: "Maximum Loan-to-Value ratio (LLTV) for collateral (percentage as decimal, e.g., 95.5 = 95.5%)",
515
481
  example: "95.5"
516
482
  }),
@@ -653,39 +619,18 @@ var MatchOffersQueryParams = z.object({
653
619
  example: "0x1234567890123456789012345678901234567890:0xabcdefabcdefabcdefabcdefabcdefabcdefabcd:86#0x9876543210987654321098765432109876543210:0xfedcbafedcbafedcbafedcbafedcbafedcbafedc:94.5"
654
620
  }),
655
621
  // Maturity filtering
656
- maturity: z.coerce.number().int().positive().transform((maturity, ctx) => {
657
- try {
658
- return Maturity.from(maturity);
659
- } catch (e) {
660
- ctx.addIssue({
661
- code: "custom",
662
- message: e.message
663
- });
664
- return z.NEVER;
665
- }
666
- }).optional(),
667
- min_maturity: z.coerce.number().int().positive().transform((maturity, ctx) => {
668
- try {
669
- return Maturity.from(maturity);
670
- } catch (e) {
671
- ctx.addIssue({
672
- code: "custom",
673
- message: e.message
674
- });
675
- return z.NEVER;
676
- }
677
- }).optional(),
678
- max_maturity: z.coerce.number().int().positive().transform((maturity, ctx) => {
679
- try {
680
- return Maturity.from(maturity);
681
- } catch (e) {
682
- ctx.addIssue({
683
- code: "custom",
684
- message: e.message
685
- });
686
- return z.NEVER;
687
- }
688
- }).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
+ }),
689
634
  // Asset and creator filtering
690
635
  loan_token: z.string().regex(/^0x[a-fA-F0-9]{40}$/, {
691
636
  message: "Loan asset must be a valid Ethereum address"
@@ -1284,8 +1229,12 @@ function memory(parameters) {
1284
1229
  )
1285
1230
  )
1286
1231
  ));
1287
- minLltv && (offers = offers.filter((o) => o.collaterals.every((c) => c.lltv >= minLltv)));
1288
- 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
+ ));
1289
1238
  offers = offers.sort((a, b) => sort(sortBy, sortOrder, a, b));
1290
1239
  let nextCursor = null;
1291
1240
  if (offers.length > limit) {