@morpho-dev/router 0.0.26 → 0.1.0
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.
- package/dist/index.browser.d.cts +11 -9
- package/dist/index.browser.d.ts +11 -9
- package/dist/index.browser.js +38 -89
- package/dist/index.browser.js.map +1 -1
- package/dist/index.browser.mjs +39 -90
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.node.d.cts +22 -18
- package/dist/index.node.d.ts +22 -18
- package/dist/index.node.js +78 -98
- package/dist/index.node.js.map +1 -1
- package/dist/index.node.mjs +79 -99
- package/dist/index.node.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.node.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Errors, LLTV,
|
|
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.base, chains["ethereum-virtual-testnet"]];
|
|
45
|
+
};
|
|
42
46
|
var chains = {
|
|
43
47
|
ethereum: {
|
|
44
48
|
...mainnet,
|
|
@@ -52,8 +56,7 @@ var chains = {
|
|
|
52
56
|
// DAI
|
|
53
57
|
].map((address) => address.toLowerCase())
|
|
54
58
|
),
|
|
55
|
-
morpho: "0x0000000000000000000000000000000000000000"
|
|
56
|
-
termsContract: "0x0000000000000000000000000000000000000000"
|
|
59
|
+
morpho: "0x0000000000000000000000000000000000000000"
|
|
57
60
|
},
|
|
58
61
|
base: {
|
|
59
62
|
...base,
|
|
@@ -67,8 +70,7 @@ var chains = {
|
|
|
67
70
|
// DAI
|
|
68
71
|
].map((address) => address.toLowerCase())
|
|
69
72
|
),
|
|
70
|
-
morpho: "0x0000000000000000000000000000000000000000"
|
|
71
|
-
termsContract: "0x0000000000000000000000000000000000000000"
|
|
73
|
+
morpho: "0x0000000000000000000000000000000000000000"
|
|
72
74
|
},
|
|
73
75
|
"ethereum-virtual-testnet": {
|
|
74
76
|
...mainnet,
|
|
@@ -82,8 +84,8 @@ var chains = {
|
|
|
82
84
|
// DAI
|
|
83
85
|
].map((address) => address.toLowerCase())
|
|
84
86
|
),
|
|
85
|
-
morpho: "
|
|
86
|
-
|
|
87
|
+
morpho: "0x11a002d45db720ed47a80d2f3489cba5b833eaf5",
|
|
88
|
+
// @TODO: This is mock Consumed contract, update with Terms once stable
|
|
87
89
|
mempool: {
|
|
88
90
|
address: "0x7be3164eeee8b35092f6128ec32c2e6ff8f6c890",
|
|
89
91
|
deploymentBlock: 23223727,
|
|
@@ -386,28 +388,14 @@ var GetOffersQueryParams = z.object({
|
|
|
386
388
|
example: "1500000000000000000"
|
|
387
389
|
}),
|
|
388
390
|
// Time range
|
|
389
|
-
min_maturity: z.coerce.number().int().
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
return z.NEVER;
|
|
398
|
-
}
|
|
399
|
-
}).optional(),
|
|
400
|
-
max_maturity: z.coerce.number().int().positive().transform((maturity, ctx) => {
|
|
401
|
-
try {
|
|
402
|
-
return Maturity.from(maturity);
|
|
403
|
-
} catch (e) {
|
|
404
|
-
ctx.addIssue({
|
|
405
|
-
code: "custom",
|
|
406
|
-
message: e.message
|
|
407
|
-
});
|
|
408
|
-
return z.NEVER;
|
|
409
|
-
}
|
|
410
|
-
}).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
|
+
}),
|
|
411
399
|
min_expiry: z.coerce.number().int().optional().meta({
|
|
412
400
|
description: "Minimum expiry timestamp (Unix timestamp in seconds)",
|
|
413
401
|
example: "1700000000"
|
|
@@ -482,33 +470,11 @@ var GetOffersQueryParams = z.object({
|
|
|
482
470
|
description: "Filter by collateral combinations in format: asset:oracle:lltv#asset2:oracle2:lltv2. Oracle and lltv are optional. Use # to separate multiple combinations.",
|
|
483
471
|
example: "0x1234567890123456789012345678901234567890:0xabcdefabcdefabcdefabcdefabcdefabcdefabcd:86#0x9876543210987654321098765432109876543210:94.5"
|
|
484
472
|
}),
|
|
485
|
-
min_lltv: z.coerce.number().min(0, { message: "LLTV must be above 0" }).max(100, { message: "LLTV must be below 100" }).
|
|
486
|
-
try {
|
|
487
|
-
return LLTV.from(parseUnits(lltv.toString(), 16));
|
|
488
|
-
} catch (e) {
|
|
489
|
-
ctx.addIssue({
|
|
490
|
-
code: "custom",
|
|
491
|
-
message: e.message,
|
|
492
|
-
input: lltv
|
|
493
|
-
});
|
|
494
|
-
return z.NEVER;
|
|
495
|
-
}
|
|
496
|
-
}).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({
|
|
497
474
|
description: "Minimum Loan-to-Value ratio (LLTV) for collateral (percentage as decimal, e.g., 80.5 = 80.5%)",
|
|
498
475
|
example: "80.5"
|
|
499
476
|
}),
|
|
500
|
-
max_lltv: z.coerce.number().min(0, { message: "LLTV must be above 0" }).max(100, { message: "LLTV must be below 100" }).
|
|
501
|
-
try {
|
|
502
|
-
return LLTV.from(parseUnits(lltv.toString(), 16));
|
|
503
|
-
} catch (e) {
|
|
504
|
-
ctx.addIssue({
|
|
505
|
-
code: "custom",
|
|
506
|
-
message: e.message,
|
|
507
|
-
input: lltv
|
|
508
|
-
});
|
|
509
|
-
return z.NEVER;
|
|
510
|
-
}
|
|
511
|
-
}).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({
|
|
512
478
|
description: "Maximum Loan-to-Value ratio (LLTV) for collateral (percentage as decimal, e.g., 95.5 = 95.5%)",
|
|
513
479
|
example: "95.5"
|
|
514
480
|
}),
|
|
@@ -651,39 +617,18 @@ var MatchOffersQueryParams = z.object({
|
|
|
651
617
|
example: "0x1234567890123456789012345678901234567890:0xabcdefabcdefabcdefabcdefabcdefabcdefabcd:86#0x9876543210987654321098765432109876543210:0xfedcbafedcbafedcbafedcbafedcbafedcbafedc:94.5"
|
|
652
618
|
}),
|
|
653
619
|
// Maturity filtering
|
|
654
|
-
maturity: z.coerce.number().int().
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
try {
|
|
667
|
-
return Maturity.from(maturity);
|
|
668
|
-
} catch (e) {
|
|
669
|
-
ctx.addIssue({
|
|
670
|
-
code: "custom",
|
|
671
|
-
message: e.message
|
|
672
|
-
});
|
|
673
|
-
return z.NEVER;
|
|
674
|
-
}
|
|
675
|
-
}).optional(),
|
|
676
|
-
max_maturity: z.coerce.number().int().positive().transform((maturity, ctx) => {
|
|
677
|
-
try {
|
|
678
|
-
return Maturity.from(maturity);
|
|
679
|
-
} catch (e) {
|
|
680
|
-
ctx.addIssue({
|
|
681
|
-
code: "custom",
|
|
682
|
-
message: e.message
|
|
683
|
-
});
|
|
684
|
-
return z.NEVER;
|
|
685
|
-
}
|
|
686
|
-
}).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
|
+
}),
|
|
687
632
|
// Asset and creator filtering
|
|
688
633
|
loan_token: z.string().regex(/^0x[a-fA-F0-9]{40}$/, {
|
|
689
634
|
message: "Loan asset must be a valid Ethereum address"
|
|
@@ -903,7 +848,7 @@ function connect(opts) {
|
|
|
903
848
|
if (u.protocol !== "http:" && u.protocol !== "https:") {
|
|
904
849
|
throw new InvalidUrlError(u.toString());
|
|
905
850
|
}
|
|
906
|
-
const headers = new Headers();
|
|
851
|
+
const headers = opts?.headers ?? new Headers();
|
|
907
852
|
headers.set("Content-Type", "application/json");
|
|
908
853
|
opts?.apiKey !== void 0 ? headers.set("X-API-Key", opts.apiKey) : null;
|
|
909
854
|
const config = {
|
|
@@ -1305,8 +1250,12 @@ function memory(parameters) {
|
|
|
1305
1250
|
)
|
|
1306
1251
|
)
|
|
1307
1252
|
));
|
|
1308
|
-
minLltv && (offers = offers.filter(
|
|
1309
|
-
|
|
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
|
+
));
|
|
1310
1259
|
offers = offers.sort((a, b) => sort(sortBy, sortOrder, a, b));
|
|
1311
1260
|
let nextCursor = null;
|
|
1312
1261
|
if (offers.length > limit) {
|
|
@@ -1676,7 +1625,8 @@ __export(Logger_exports, {
|
|
|
1676
1625
|
LogLevelValues: () => LogLevelValues,
|
|
1677
1626
|
defaultLogger: () => defaultLogger,
|
|
1678
1627
|
getLogger: () => getLogger,
|
|
1679
|
-
runWithLogger: () => runWithLogger
|
|
1628
|
+
runWithLogger: () => runWithLogger,
|
|
1629
|
+
silentLogger: () => silentLogger
|
|
1680
1630
|
});
|
|
1681
1631
|
var LogLevelValues = [
|
|
1682
1632
|
"silent",
|
|
@@ -1687,20 +1637,50 @@ var LogLevelValues = [
|
|
|
1687
1637
|
"error",
|
|
1688
1638
|
"fatal"
|
|
1689
1639
|
];
|
|
1690
|
-
function defaultLogger() {
|
|
1640
|
+
function defaultLogger(minLevel) {
|
|
1641
|
+
const threshold = minLevel ?? "trace";
|
|
1642
|
+
const levelIndexByName = LogLevelValues.reduce(
|
|
1643
|
+
(acc, lvl, idx) => {
|
|
1644
|
+
acc[lvl] = idx;
|
|
1645
|
+
return acc;
|
|
1646
|
+
},
|
|
1647
|
+
{}
|
|
1648
|
+
);
|
|
1649
|
+
const isEnabled = (methodLevel) => levelIndexByName[methodLevel] >= levelIndexByName[threshold];
|
|
1691
1650
|
return {
|
|
1692
1651
|
// biome-ignore lint/suspicious/noConsole: console is used for logging
|
|
1693
|
-
trace: console.trace.bind(console)
|
|
1652
|
+
trace: isEnabled("trace") ? console.trace.bind(console) : () => {
|
|
1653
|
+
},
|
|
1694
1654
|
// biome-ignore lint/suspicious/noConsole: console is used for logging
|
|
1695
|
-
debug: console.debug.bind(console)
|
|
1655
|
+
debug: isEnabled("debug") ? console.debug.bind(console) : () => {
|
|
1656
|
+
},
|
|
1696
1657
|
// biome-ignore lint/suspicious/noConsole: console is used for logging
|
|
1697
|
-
info: console.info.bind(console)
|
|
1658
|
+
info: isEnabled("info") ? console.info.bind(console) : () => {
|
|
1659
|
+
},
|
|
1698
1660
|
// biome-ignore lint/suspicious/noConsole: console is used for logging
|
|
1699
|
-
warn: console.warn.bind(console)
|
|
1661
|
+
warn: isEnabled("warn") ? console.warn.bind(console) : () => {
|
|
1662
|
+
},
|
|
1700
1663
|
// biome-ignore lint/suspicious/noConsole: console is used for logging
|
|
1701
|
-
error: console.error.bind(console)
|
|
1702
|
-
|
|
1703
|
-
fatal: (...args) => console.error("[fatal]", ...args)
|
|
1664
|
+
error: isEnabled("error") ? console.error.bind(console) : () => {
|
|
1665
|
+
},
|
|
1666
|
+
fatal: isEnabled("fatal") ? (...args) => console.error("[fatal]", ...args) : () => {
|
|
1667
|
+
}
|
|
1668
|
+
};
|
|
1669
|
+
}
|
|
1670
|
+
function silentLogger() {
|
|
1671
|
+
return {
|
|
1672
|
+
trace: () => {
|
|
1673
|
+
},
|
|
1674
|
+
debug: () => {
|
|
1675
|
+
},
|
|
1676
|
+
info: () => {
|
|
1677
|
+
},
|
|
1678
|
+
warn: () => {
|
|
1679
|
+
},
|
|
1680
|
+
error: () => {
|
|
1681
|
+
},
|
|
1682
|
+
fatal: () => {
|
|
1683
|
+
}
|
|
1704
1684
|
};
|
|
1705
1685
|
}
|
|
1706
1686
|
var loggerContext = new AsyncLocalStorage();
|