@continuumdao/ctm-mpc-defi 0.2.31 → 0.2.33
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/agent/catalog.cjs +233 -33
- package/dist/agent/catalog.cjs.map +1 -1
- package/dist/agent/catalog.js +233 -33
- package/dist/agent/catalog.js.map +1 -1
- package/dist/agent/skills/euler-v2/SKILL.md +1 -1
- package/dist/core/index.cjs +9 -0
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.ts +3 -1
- package/dist/core/index.js +8 -1
- package/dist/core/index.js.map +1 -1
- package/dist/index.cjs +9 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/protocols/evm/aave-v4/index.cjs.map +1 -1
- package/dist/protocols/evm/aave-v4/index.js.map +1 -1
- package/dist/protocols/evm/euler-v2/index.cjs +298 -290
- package/dist/protocols/evm/euler-v2/index.cjs.map +1 -1
- package/dist/protocols/evm/euler-v2/index.d.ts +37 -4
- package/dist/protocols/evm/euler-v2/index.js +296 -292
- package/dist/protocols/evm/euler-v2/index.js.map +1 -1
- package/dist/protocols/evm/maple/index.cjs.map +1 -1
- package/dist/protocols/evm/maple/index.js.map +1 -1
- package/dist/protocols/evm/morpho/index.cjs.map +1 -1
- package/dist/protocols/evm/morpho/index.js.map +1 -1
- package/dist/protocols/evm/sky/index.cjs.map +1 -1
- package/dist/protocols/evm/sky/index.js.map +1 -1
- package/dist/protocols/evm/uniswap-v4/index.cjs.map +1 -1
- package/dist/protocols/evm/uniswap-v4/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1579,6 +1579,15 @@ async function postJsonViaOptionalProxy(args) {
|
|
|
1579
1579
|
}
|
|
1580
1580
|
return await r.json();
|
|
1581
1581
|
}
|
|
1582
|
+
async function getJsonViaOptionalProxy(args) {
|
|
1583
|
+
const url = args.directUrl;
|
|
1584
|
+
const r = await fetch(url, { method: "GET", headers: { accept: "application/json" } });
|
|
1585
|
+
if (!r.ok) {
|
|
1586
|
+
const t = await r.text().catch(() => "");
|
|
1587
|
+
throw new Error(t ? `HTTP ${r.status}: ${t.slice(0, 200)}` : `HTTP ${r.status}`);
|
|
1588
|
+
}
|
|
1589
|
+
return await r.json();
|
|
1590
|
+
}
|
|
1582
1591
|
|
|
1583
1592
|
// src/protocols/evm/aave-v4/api.ts
|
|
1584
1593
|
var AAVE_V4_GRAPHQL_URL = "https://api.v4.aave.com/graphql";
|
|
@@ -1612,177 +1621,79 @@ async function fetchAaveV4NativeWrappedToken(chainId) {
|
|
|
1612
1621
|
if (t && viem.isAddress(t)) return viem.getAddress(t);
|
|
1613
1622
|
return null;
|
|
1614
1623
|
}
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
var
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
const
|
|
1629
|
-
const
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
}
|
|
1651
|
-
try {
|
|
1652
|
-
rawBorrowCap16 = Number(BigInt((args.borrowCapRaw ?? "").trim() || "0") & 0xffffn);
|
|
1653
|
-
} catch {
|
|
1654
|
-
rawBorrowCap16 = 0;
|
|
1655
|
-
}
|
|
1656
|
-
return {
|
|
1657
|
-
rawSupplyCap16,
|
|
1658
|
-
rawBorrowCap16,
|
|
1659
|
-
supplyCapWei: eulerSubgraphVaultCapToUnderlyingWei(args.supplyCapRaw),
|
|
1660
|
-
borrowCapWei: eulerSubgraphVaultCapToUnderlyingWei(args.borrowCapRaw),
|
|
1661
|
-
cashWei: args.cashWei,
|
|
1662
|
-
totalBorrowsWei: args.totalBorrowsWei,
|
|
1663
|
-
totalAssetsWei: args.totalAssetsWei
|
|
1664
|
-
};
|
|
1665
|
-
}
|
|
1666
|
-
function formatEulerResolvedCapOrCashForUi(wei, decimals, symbolSuffix) {
|
|
1667
|
-
if (wei >= EULER_EVAULT_CAP_UNLIMITED_WEI - 3n) return "Unlimited";
|
|
1668
|
-
if (wei === 0n) return symbolSuffix ? `0 ${symbolSuffix}` : "0";
|
|
1669
|
-
try {
|
|
1670
|
-
const s = viem.formatUnits(wei, decimals);
|
|
1671
|
-
const n = Number(s);
|
|
1672
|
-
if (Number.isFinite(n) && Math.abs(n) >= 1e9) return `${n.toExponential(2)}${symbolSuffix ? ` ${symbolSuffix}` : ""}`;
|
|
1673
|
-
return symbolSuffix ? `${s} ${symbolSuffix}` : s;
|
|
1674
|
-
} catch {
|
|
1675
|
-
return wei.toString();
|
|
1624
|
+
|
|
1625
|
+
// src/protocols/evm/euler-v2/eulerV3Api.ts
|
|
1626
|
+
var EULER_V3_API_BASE = "https://v3.euler.finance";
|
|
1627
|
+
function qs(params) {
|
|
1628
|
+
const u = new URLSearchParams();
|
|
1629
|
+
for (const [k, v] of Object.entries(params)) {
|
|
1630
|
+
if (v == null) continue;
|
|
1631
|
+
u.set(k, String(v));
|
|
1632
|
+
}
|
|
1633
|
+
const s = u.toString();
|
|
1634
|
+
return s ? `?${s}` : "";
|
|
1635
|
+
}
|
|
1636
|
+
async function eulerV3Get(path, params = {}) {
|
|
1637
|
+
const rel = path.startsWith("/") ? path : `/${path}`;
|
|
1638
|
+
const query = qs(params);
|
|
1639
|
+
const directUrl = `${EULER_V3_API_BASE}${rel}${query}`;
|
|
1640
|
+
rel.replace(/^\/v3\/?/, "");
|
|
1641
|
+
return getJsonViaOptionalProxy({ directUrl});
|
|
1642
|
+
}
|
|
1643
|
+
async function paginateV3Vaults(path, chainId, extra = {}) {
|
|
1644
|
+
const out = [];
|
|
1645
|
+
let offset = 0;
|
|
1646
|
+
const limit = 100;
|
|
1647
|
+
while (true) {
|
|
1648
|
+
const page = await eulerV3Get(path, {
|
|
1649
|
+
chainId,
|
|
1650
|
+
limit,
|
|
1651
|
+
offset,
|
|
1652
|
+
...extra
|
|
1653
|
+
});
|
|
1654
|
+
const rows = page.data ?? [];
|
|
1655
|
+
out.push(...rows);
|
|
1656
|
+
const total = typeof page.meta?.total === "number" ? page.meta.total : out.length;
|
|
1657
|
+
offset += rows.length;
|
|
1658
|
+
if (!rows.length || offset >= total) break;
|
|
1676
1659
|
}
|
|
1660
|
+
return out;
|
|
1677
1661
|
}
|
|
1678
|
-
function
|
|
1679
|
-
|
|
1680
|
-
if (supplyCapWei === 0n) return 0n;
|
|
1681
|
-
if (supplyCapWei >= EULER_EVAULT_CAP_UNLIMITED_WEI - 3n) return EULER_EVAULT_CAP_UNLIMITED_WEI;
|
|
1682
|
-
if (totalAssetsWei >= supplyCapWei) return 0n;
|
|
1683
|
-
return supplyCapWei - totalAssetsWei;
|
|
1662
|
+
async function fetchEulerV3EvkVaults(args) {
|
|
1663
|
+
return paginateV3Vaults("/v3/evk/vaults", args.chainId, args.asset ? { asset: args.asset } : {});
|
|
1684
1664
|
}
|
|
1685
|
-
function
|
|
1686
|
-
|
|
1687
|
-
if (borrowCapWei === 0n) return 0n;
|
|
1688
|
-
if (borrowCapWei >= EULER_EVAULT_CAP_UNLIMITED_WEI - 3n) return cashWei;
|
|
1689
|
-
const capLeft = borrowCapWei > totalBorrowsWei ? borrowCapWei - totalBorrowsWei : 0n;
|
|
1690
|
-
return cashWei < capLeft ? cashWei : capLeft;
|
|
1665
|
+
async function fetchEulerV3EarnVaults(args) {
|
|
1666
|
+
return paginateV3Vaults("/v3/earn/vaults", args.chainId, args.asset ? { asset: args.asset } : {});
|
|
1691
1667
|
}
|
|
1692
|
-
async function
|
|
1693
|
-
const
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
const client = viem.createPublicClient({ chain: ch, transport: viem.http(args.rpcUrl) });
|
|
1700
|
-
const addr = viem.getAddress(args.evault);
|
|
1701
|
-
const [[supplyRaw, borrowRaw], cashWei, totalBorrowsWei, totalAssetsWei] = await Promise.all([
|
|
1702
|
-
client.readContract({
|
|
1703
|
-
address: addr,
|
|
1704
|
-
abi: eulerVaultLendAbi,
|
|
1705
|
-
functionName: "caps"
|
|
1706
|
-
}),
|
|
1707
|
-
client.readContract({
|
|
1708
|
-
address: addr,
|
|
1709
|
-
abi: eulerVaultLendAbi,
|
|
1710
|
-
functionName: "cash"
|
|
1711
|
-
}),
|
|
1712
|
-
client.readContract({
|
|
1713
|
-
address: addr,
|
|
1714
|
-
abi: eulerVaultLendAbi,
|
|
1715
|
-
functionName: "totalBorrows"
|
|
1716
|
-
}),
|
|
1717
|
-
client.readContract({
|
|
1718
|
-
address: addr,
|
|
1719
|
-
abi: eulerVaultLendAbi,
|
|
1720
|
-
functionName: "totalAssets"
|
|
1721
|
-
})
|
|
1722
|
-
]);
|
|
1723
|
-
const rs = Number(supplyRaw);
|
|
1724
|
-
const rb = Number(borrowRaw);
|
|
1725
|
-
return {
|
|
1726
|
-
rawSupplyCap16: rs,
|
|
1727
|
-
rawBorrowCap16: rb,
|
|
1728
|
-
supplyCapWei: resolveEulerAmountCapToWei(rs),
|
|
1729
|
-
borrowCapWei: resolveEulerAmountCapToWei(rb),
|
|
1730
|
-
cashWei,
|
|
1731
|
-
totalBorrowsWei,
|
|
1732
|
-
totalAssetsWei
|
|
1733
|
-
};
|
|
1734
|
-
}
|
|
1735
|
-
async function fetchEulerVaultOnChainLendMetricsForVaults(args) {
|
|
1736
|
-
const rpc = (args.rpcUrl ?? "").trim();
|
|
1737
|
-
const out = /* @__PURE__ */ new Map();
|
|
1738
|
-
if (!rpc || !args.vaults.length) return out;
|
|
1739
|
-
const concurrency = 8;
|
|
1740
|
-
let idx = 0;
|
|
1741
|
-
const list = [...args.vaults];
|
|
1742
|
-
async function worker() {
|
|
1743
|
-
while (idx < list.length) {
|
|
1744
|
-
const i = idx++;
|
|
1745
|
-
const row = list[i];
|
|
1746
|
-
try {
|
|
1747
|
-
const ev = viem.getAddress(row.evault.trim());
|
|
1748
|
-
const data = await fetchEulerVaultOnChainLendMetrics({
|
|
1749
|
-
rpcUrl: rpc,
|
|
1750
|
-
chainId: args.chainId,
|
|
1751
|
-
evault: ev
|
|
1752
|
-
});
|
|
1753
|
-
out.set(row.key, { ok: true, data });
|
|
1754
|
-
} catch (e) {
|
|
1755
|
-
out.set(row.key, {
|
|
1756
|
-
ok: false,
|
|
1757
|
-
message: e instanceof Error ? e.message : "On-chain read failed"
|
|
1758
|
-
});
|
|
1759
|
-
}
|
|
1760
|
-
}
|
|
1668
|
+
async function fetchEulerV3ActiveChainIds() {
|
|
1669
|
+
const page = await eulerV3Get("/v3/chains");
|
|
1670
|
+
const ids = [];
|
|
1671
|
+
for (const row of page.data ?? []) {
|
|
1672
|
+
if (typeof row.id !== "number" || !Number.isFinite(row.id)) continue;
|
|
1673
|
+
if ((row.status ?? "active") !== "active") continue;
|
|
1674
|
+
ids.push(row.id);
|
|
1761
1675
|
}
|
|
1762
|
-
|
|
1763
|
-
return out;
|
|
1676
|
+
return ids.sort((a, b) => a - b);
|
|
1764
1677
|
}
|
|
1765
1678
|
|
|
1766
1679
|
// src/protocols/evm/euler-v2/eulerV2Subgraph.ts
|
|
1767
1680
|
var EULER_V2_GOLDSKY_SUBGRAPH_URL_BY_CHAIN_ID = {
|
|
1768
|
-
1: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-
|
|
1769
|
-
8453: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-
|
|
1770
|
-
1923: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-
|
|
1771
|
-
146: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-
|
|
1772
|
-
60808: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-
|
|
1773
|
-
80094: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-
|
|
1774
|
-
43114: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-
|
|
1775
|
-
42161: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-
|
|
1776
|
-
130: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
9745: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-v2-plasma/latest/gn",
|
|
1785
|
-
5e3: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-v2-mantle/latest/gn"
|
|
1681
|
+
1: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-simple-mainnet/latest/gn",
|
|
1682
|
+
8453: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-simple-base/latest/gn",
|
|
1683
|
+
1923: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-simple-swell/latest/gn",
|
|
1684
|
+
146: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-simple-sonic/latest/gn",
|
|
1685
|
+
60808: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-simple-bob/latest/gn",
|
|
1686
|
+
80094: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-simple-berachain/latest/gn",
|
|
1687
|
+
43114: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-simple-avalanche/latest/gn",
|
|
1688
|
+
42161: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-simple-arbitrum/latest/gn",
|
|
1689
|
+
130: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-simple-unichain/latest/gn",
|
|
1690
|
+
56: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-simple-bsc/latest/gn",
|
|
1691
|
+
999: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-simple-hyperevm/latest/gn",
|
|
1692
|
+
239: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-simple-tac/latest/gn",
|
|
1693
|
+
9745: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-simple-plasma/latest/gn",
|
|
1694
|
+
137: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-simple-polygon/latest/gn",
|
|
1695
|
+
59144: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-simple-linea/latest/gn",
|
|
1696
|
+
143: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-simple-monad/latest/gn"
|
|
1786
1697
|
};
|
|
1787
1698
|
var WRAPPED_NATIVE_FALLBACK = {
|
|
1788
1699
|
1: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
|
@@ -1790,6 +1701,10 @@ var WRAPPED_NATIVE_FALLBACK = {
|
|
|
1790
1701
|
56: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
|
|
1791
1702
|
100: "0xe91d153e0b41518a2ce8dd3d7944fa863463a97d",
|
|
1792
1703
|
130: "0x4200000000000000000000000000000000000006",
|
|
1704
|
+
137: "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",
|
|
1705
|
+
// Polygon: WPOL
|
|
1706
|
+
143: "0x3bd359C1119dA7Da1D913D1C4D2B7c461115433A",
|
|
1707
|
+
// Monad: WMON
|
|
1793
1708
|
146: "0x03980325872071166574bcd94670450917897468",
|
|
1794
1709
|
239: "0xB63B9f0eb4A6E6f191529D71d4D88cc8900Df2C9",
|
|
1795
1710
|
// TAC: WTAC (https://docs.tac.build/ecosystem/token-list)
|
|
@@ -1801,6 +1716,8 @@ var WRAPPED_NATIVE_FALLBACK = {
|
|
|
1801
1716
|
43114: "0xB31f66AA3C1e785363F0875A1B74D27b85FE0459",
|
|
1802
1717
|
5e3: "0x78c1b0C915c4FAA5FffA6CAbf0219DA63d7f4cb8",
|
|
1803
1718
|
// Mantle: WMNT
|
|
1719
|
+
59144: "0xe5D7C2a44FfDDf6b295A15c148167daaAf5Cf34f",
|
|
1720
|
+
// Linea: WETH
|
|
1804
1721
|
57073: "0x4200000000000000000000000000000000000006",
|
|
1805
1722
|
60808: "0x4200000000000000000000000000000000000006",
|
|
1806
1723
|
80094: "0x6969696969696969696969696969696969696969",
|
|
@@ -1899,81 +1816,20 @@ function normAssetAddr(raw) {
|
|
|
1899
1816
|
if (!s || !viem.isAddress(s)) return null;
|
|
1900
1817
|
return viem.getAddress(s).toLowerCase();
|
|
1901
1818
|
}
|
|
1902
|
-
function
|
|
1903
|
-
|
|
1819
|
+
function v3VaultShowsBorrow(totalBorrows, explorableBorrow) {
|
|
1820
|
+
if (explorableBorrow === true) return true;
|
|
1904
1821
|
try {
|
|
1905
|
-
|
|
1822
|
+
return BigInt((totalBorrows ?? "0").trim() || "0") > 0n;
|
|
1906
1823
|
} catch {
|
|
1907
|
-
|
|
1908
|
-
}
|
|
1909
|
-
if (borrows > 0n) return true;
|
|
1910
|
-
const w = eulerSubgraphVaultCapToUnderlyingWei(borrowCap);
|
|
1911
|
-
if (w >= EULER_EVAULT_CAP_UNLIMITED_WEI - 3n) return true;
|
|
1912
|
-
return w > 0n;
|
|
1913
|
-
}
|
|
1914
|
-
var VAULT_PAGE = `
|
|
1915
|
-
query V($first: Int!, $skip: Int!) {
|
|
1916
|
-
eulerVaults(first: $first, skip: $skip) {
|
|
1917
|
-
asset
|
|
1918
|
-
borrowCap
|
|
1919
|
-
state { totalBorrows }
|
|
1920
|
-
}
|
|
1921
|
-
}
|
|
1922
|
-
`;
|
|
1923
|
-
var EARN_PAGE = `
|
|
1924
|
-
query E($first: Int!, $skip: Int!) {
|
|
1925
|
-
eulerEarnVaults(first: $first, skip: $skip) {
|
|
1926
|
-
asset
|
|
1927
|
-
}
|
|
1928
|
-
}
|
|
1929
|
-
`;
|
|
1930
|
-
async function paginateEulerVaultRows(endpoint) {
|
|
1931
|
-
const out = [];
|
|
1932
|
-
let skip = 0;
|
|
1933
|
-
const first = 1e3;
|
|
1934
|
-
while (true) {
|
|
1935
|
-
const d = await eulerSubgraphGql(endpoint, VAULT_PAGE, { first, skip });
|
|
1936
|
-
const rows = d.eulerVaults ?? [];
|
|
1937
|
-
if (!rows.length) break;
|
|
1938
|
-
for (const r of rows) {
|
|
1939
|
-
const tb = (r.state?.totalBorrows ?? "0").toString();
|
|
1940
|
-
out.push({ asset: r.asset ?? null, borrowCap: r.borrowCap, totalBorrows: tb });
|
|
1941
|
-
}
|
|
1942
|
-
if (rows.length < first) break;
|
|
1943
|
-
skip += first;
|
|
1944
|
-
}
|
|
1945
|
-
return out;
|
|
1946
|
-
}
|
|
1947
|
-
async function paginateEulerEarnAssets(endpoint) {
|
|
1948
|
-
const assets = [];
|
|
1949
|
-
let skip = 0;
|
|
1950
|
-
const first = 1e3;
|
|
1951
|
-
while (true) {
|
|
1952
|
-
const d = await eulerSubgraphGql(endpoint, EARN_PAGE, {
|
|
1953
|
-
first,
|
|
1954
|
-
skip
|
|
1955
|
-
});
|
|
1956
|
-
const rows = d.eulerEarnVaults ?? [];
|
|
1957
|
-
if (!rows.length) break;
|
|
1958
|
-
for (const r of rows) {
|
|
1959
|
-
const a = normAssetAddr(r.asset ?? void 0);
|
|
1960
|
-
if (a) assets.push(a);
|
|
1961
|
-
}
|
|
1962
|
-
if (rows.length < first) break;
|
|
1963
|
-
skip += first;
|
|
1824
|
+
return false;
|
|
1964
1825
|
}
|
|
1965
|
-
return assets;
|
|
1966
1826
|
}
|
|
1967
1827
|
var eulerV2ChainAssetCache = /* @__PURE__ */ new Map();
|
|
1968
1828
|
async function fetchEulerV2ChainAssetCache(chainId) {
|
|
1969
|
-
const
|
|
1970
|
-
if (!endpoint) {
|
|
1971
|
-
return { nativeWrapped: null, modesByUnderlying: /* @__PURE__ */ new Map() };
|
|
1972
|
-
}
|
|
1973
|
-
const [nativeWrapped, vaultRows, earnAssets] = await Promise.all([
|
|
1829
|
+
const [nativeWrapped, evkVaults, earnVaults] = await Promise.all([
|
|
1974
1830
|
resolveEulerWrappedNativeToken(chainId),
|
|
1975
|
-
|
|
1976
|
-
|
|
1831
|
+
fetchEulerV3EvkVaults({ chainId }),
|
|
1832
|
+
fetchEulerV3EarnVaults({ chainId }).catch(() => [])
|
|
1977
1833
|
]);
|
|
1978
1834
|
const modes = /* @__PURE__ */ new Map();
|
|
1979
1835
|
const bump = (addr, patch) => {
|
|
@@ -1984,13 +1840,17 @@ async function fetchEulerV2ChainAssetCache(chainId) {
|
|
|
1984
1840
|
earn: cur.earn || !!patch.earn
|
|
1985
1841
|
});
|
|
1986
1842
|
};
|
|
1987
|
-
for (const
|
|
1988
|
-
|
|
1989
|
-
|
|
1843
|
+
for (const v of earnVaults) {
|
|
1844
|
+
const a = normAssetAddr(v.asset?.address ?? void 0);
|
|
1845
|
+
if (a) bump(a, { earn: true });
|
|
1846
|
+
}
|
|
1847
|
+
for (const v of evkVaults) {
|
|
1848
|
+
const a = normAssetAddr(v.asset?.address ?? void 0);
|
|
1990
1849
|
if (!a) continue;
|
|
1850
|
+
const vis = v.visibility;
|
|
1991
1851
|
bump(a, {
|
|
1992
|
-
lend:
|
|
1993
|
-
borrow:
|
|
1852
|
+
lend: vis?.explorableLend !== false,
|
|
1853
|
+
borrow: v3VaultShowsBorrow(v.totalBorrows, vis?.explorableBorrow)
|
|
1994
1854
|
});
|
|
1995
1855
|
}
|
|
1996
1856
|
return { nativeWrapped, modesByUnderlying: modes };
|
|
@@ -1998,7 +1858,10 @@ async function fetchEulerV2ChainAssetCache(chainId) {
|
|
|
1998
1858
|
function ensureEulerV2ChainAssetCache(chainId) {
|
|
1999
1859
|
const hit = eulerV2ChainAssetCache.get(chainId);
|
|
2000
1860
|
if (hit) return hit;
|
|
2001
|
-
const p = fetchEulerV2ChainAssetCache(chainId)
|
|
1861
|
+
const p = fetchEulerV2ChainAssetCache(chainId).catch((e) => {
|
|
1862
|
+
eulerV2ChainAssetCache.delete(chainId);
|
|
1863
|
+
throw e;
|
|
1864
|
+
});
|
|
2002
1865
|
eulerV2ChainAssetCache.set(chainId, p);
|
|
2003
1866
|
return p;
|
|
2004
1867
|
}
|
|
@@ -2064,47 +1927,162 @@ function eulerLabelsLookupLabelForVault(labelMap, evaultAddress) {
|
|
|
2064
1927
|
const v = labelMap.get(k);
|
|
2065
1928
|
return typeof v === "string" && v.trim() ? v.trim() : void 0;
|
|
2066
1929
|
}
|
|
1930
|
+
var EULER_EVAULT_CAP_UNLIMITED_WEI = (1n << 256n) - 1n;
|
|
1931
|
+
var UINT256_MAX = EULER_EVAULT_CAP_UNLIMITED_WEI;
|
|
1932
|
+
var EULER_EVAULT_SUPPLY_CAP_UNLIMITED_WEI = EULER_EVAULT_CAP_UNLIMITED_WEI;
|
|
1933
|
+
var EULER_V2_PREFER_ON_CHAIN_LEND_METRICS = false;
|
|
1934
|
+
var eulerVaultLendAbi = viem.parseAbi([
|
|
1935
|
+
"function caps() view returns (uint16 supplyCap, uint16 borrowCap)",
|
|
1936
|
+
"function cash() view returns (uint256)",
|
|
1937
|
+
"function totalBorrows() view returns (uint256)",
|
|
1938
|
+
"function totalAssets() view returns (uint256)"
|
|
1939
|
+
]);
|
|
1940
|
+
function resolveEulerAmountCapToWei(rawCap16) {
|
|
1941
|
+
const amountCap = BigInt(rawCap16) & 0xffffn;
|
|
1942
|
+
if (amountCap === 0n) return UINT256_MAX;
|
|
1943
|
+
const exp = amountCap & 63n;
|
|
1944
|
+
const mantissa = amountCap >> 6n;
|
|
1945
|
+
return 10n ** exp * mantissa / 100n;
|
|
1946
|
+
}
|
|
1947
|
+
var resolveEulerAmountCapToSupplyWei = resolveEulerAmountCapToWei;
|
|
1948
|
+
function eulerSubgraphVaultCapToUnderlyingWei(raw) {
|
|
1949
|
+
try {
|
|
1950
|
+
const v = BigInt((raw ?? "").trim() || "0");
|
|
1951
|
+
if (v >= UINT256_MAX - 3n) return v;
|
|
1952
|
+
if (v <= 0xffffn) return resolveEulerAmountCapToWei(v);
|
|
1953
|
+
return v;
|
|
1954
|
+
} catch {
|
|
1955
|
+
return 0n;
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
function eulerVaultLendMetricsFromIndexerVaultState(args) {
|
|
1959
|
+
let rawSupplyCap16 = 0;
|
|
1960
|
+
let rawBorrowCap16 = 0;
|
|
1961
|
+
try {
|
|
1962
|
+
rawSupplyCap16 = Number(BigInt((args.supplyCapRaw ?? "").trim() || "0") & 0xffffn);
|
|
1963
|
+
} catch {
|
|
1964
|
+
rawSupplyCap16 = 0;
|
|
1965
|
+
}
|
|
1966
|
+
try {
|
|
1967
|
+
rawBorrowCap16 = Number(BigInt((args.borrowCapRaw ?? "").trim() || "0") & 0xffffn);
|
|
1968
|
+
} catch {
|
|
1969
|
+
rawBorrowCap16 = 0;
|
|
1970
|
+
}
|
|
1971
|
+
return {
|
|
1972
|
+
rawSupplyCap16,
|
|
1973
|
+
rawBorrowCap16,
|
|
1974
|
+
supplyCapWei: eulerSubgraphVaultCapToUnderlyingWei(args.supplyCapRaw),
|
|
1975
|
+
borrowCapWei: eulerSubgraphVaultCapToUnderlyingWei(args.borrowCapRaw),
|
|
1976
|
+
cashWei: args.cashWei,
|
|
1977
|
+
totalBorrowsWei: args.totalBorrowsWei,
|
|
1978
|
+
totalAssetsWei: args.totalAssetsWei
|
|
1979
|
+
};
|
|
1980
|
+
}
|
|
1981
|
+
function formatEulerResolvedCapOrCashForUi(wei, decimals, symbolSuffix) {
|
|
1982
|
+
if (wei >= EULER_EVAULT_CAP_UNLIMITED_WEI - 3n) return "Unlimited";
|
|
1983
|
+
if (wei === 0n) return symbolSuffix ? `0 ${symbolSuffix}` : "0";
|
|
1984
|
+
try {
|
|
1985
|
+
const s = viem.formatUnits(wei, decimals);
|
|
1986
|
+
const n = Number(s);
|
|
1987
|
+
if (Number.isFinite(n) && Math.abs(n) >= 1e9) return `${n.toExponential(2)}${symbolSuffix ? ` ${symbolSuffix}` : ""}`;
|
|
1988
|
+
return symbolSuffix ? `${s} ${symbolSuffix}` : s;
|
|
1989
|
+
} catch {
|
|
1990
|
+
return wei.toString();
|
|
1991
|
+
}
|
|
1992
|
+
}
|
|
1993
|
+
function eulerVaultMaxNewSupplyWei(metrics) {
|
|
1994
|
+
const { supplyCapWei, totalAssetsWei } = metrics;
|
|
1995
|
+
if (supplyCapWei === 0n) return 0n;
|
|
1996
|
+
if (supplyCapWei >= EULER_EVAULT_CAP_UNLIMITED_WEI - 3n) return EULER_EVAULT_CAP_UNLIMITED_WEI;
|
|
1997
|
+
if (totalAssetsWei >= supplyCapWei) return 0n;
|
|
1998
|
+
return supplyCapWei - totalAssetsWei;
|
|
1999
|
+
}
|
|
2000
|
+
function eulerVaultMaxNewBorrowWei(metrics) {
|
|
2001
|
+
const { cashWei, borrowCapWei, totalBorrowsWei } = metrics;
|
|
2002
|
+
if (borrowCapWei === 0n) return 0n;
|
|
2003
|
+
if (borrowCapWei >= EULER_EVAULT_CAP_UNLIMITED_WEI - 3n) return cashWei;
|
|
2004
|
+
const capLeft = borrowCapWei > totalBorrowsWei ? borrowCapWei - totalBorrowsWei : 0n;
|
|
2005
|
+
return cashWei < capLeft ? cashWei : capLeft;
|
|
2006
|
+
}
|
|
2007
|
+
async function fetchEulerVaultOnChainLendMetrics(args) {
|
|
2008
|
+
const ch = viem.defineChain({
|
|
2009
|
+
id: args.chainId,
|
|
2010
|
+
name: "EulerVaultRead",
|
|
2011
|
+
nativeCurrency: { decimals: 18, name: "x", symbol: "x" },
|
|
2012
|
+
rpcUrls: { default: { http: [args.rpcUrl] } }
|
|
2013
|
+
});
|
|
2014
|
+
const client = viem.createPublicClient({ chain: ch, transport: viem.http(args.rpcUrl) });
|
|
2015
|
+
const addr = viem.getAddress(args.evault);
|
|
2016
|
+
const [[supplyRaw, borrowRaw], cashWei, totalBorrowsWei, totalAssetsWei] = await Promise.all([
|
|
2017
|
+
client.readContract({
|
|
2018
|
+
address: addr,
|
|
2019
|
+
abi: eulerVaultLendAbi,
|
|
2020
|
+
functionName: "caps"
|
|
2021
|
+
}),
|
|
2022
|
+
client.readContract({
|
|
2023
|
+
address: addr,
|
|
2024
|
+
abi: eulerVaultLendAbi,
|
|
2025
|
+
functionName: "cash"
|
|
2026
|
+
}),
|
|
2027
|
+
client.readContract({
|
|
2028
|
+
address: addr,
|
|
2029
|
+
abi: eulerVaultLendAbi,
|
|
2030
|
+
functionName: "totalBorrows"
|
|
2031
|
+
}),
|
|
2032
|
+
client.readContract({
|
|
2033
|
+
address: addr,
|
|
2034
|
+
abi: eulerVaultLendAbi,
|
|
2035
|
+
functionName: "totalAssets"
|
|
2036
|
+
})
|
|
2037
|
+
]);
|
|
2038
|
+
const rs = Number(supplyRaw);
|
|
2039
|
+
const rb = Number(borrowRaw);
|
|
2040
|
+
return {
|
|
2041
|
+
rawSupplyCap16: rs,
|
|
2042
|
+
rawBorrowCap16: rb,
|
|
2043
|
+
supplyCapWei: resolveEulerAmountCapToWei(rs),
|
|
2044
|
+
borrowCapWei: resolveEulerAmountCapToWei(rb),
|
|
2045
|
+
cashWei,
|
|
2046
|
+
totalBorrowsWei,
|
|
2047
|
+
totalAssetsWei
|
|
2048
|
+
};
|
|
2049
|
+
}
|
|
2050
|
+
async function fetchEulerVaultOnChainLendMetricsForVaults(args) {
|
|
2051
|
+
const rpc = (args.rpcUrl ?? "").trim();
|
|
2052
|
+
const out = /* @__PURE__ */ new Map();
|
|
2053
|
+
if (!rpc || !args.vaults.length) return out;
|
|
2054
|
+
const concurrency = 8;
|
|
2055
|
+
let idx = 0;
|
|
2056
|
+
const list = [...args.vaults];
|
|
2057
|
+
async function worker() {
|
|
2058
|
+
while (idx < list.length) {
|
|
2059
|
+
const i = idx++;
|
|
2060
|
+
const row = list[i];
|
|
2061
|
+
try {
|
|
2062
|
+
const ev = viem.getAddress(row.evault.trim());
|
|
2063
|
+
const data = await fetchEulerVaultOnChainLendMetrics({
|
|
2064
|
+
rpcUrl: rpc,
|
|
2065
|
+
chainId: args.chainId,
|
|
2066
|
+
evault: ev
|
|
2067
|
+
});
|
|
2068
|
+
out.set(row.key, { ok: true, data });
|
|
2069
|
+
} catch (e) {
|
|
2070
|
+
out.set(row.key, {
|
|
2071
|
+
ok: false,
|
|
2072
|
+
message: e instanceof Error ? e.message : "On-chain read failed"
|
|
2073
|
+
});
|
|
2074
|
+
}
|
|
2075
|
+
}
|
|
2076
|
+
}
|
|
2077
|
+
await Promise.all(Array.from({ length: Math.min(concurrency, list.length) }, () => worker()));
|
|
2078
|
+
return out;
|
|
2079
|
+
}
|
|
2067
2080
|
|
|
2068
2081
|
// src/protocols/evm/euler-v2/eulerV2LendMarkets.ts
|
|
2069
2082
|
var erc20StringMetaAbi = viem.parseAbi([
|
|
2070
2083
|
"function name() view returns (string)",
|
|
2071
2084
|
"function symbol() view returns (string)"
|
|
2072
2085
|
]);
|
|
2073
|
-
var LEND_VAULT_PAGE = `
|
|
2074
|
-
query EulerLendVaults($first: Int!, $skip: Int!, $asset: Bytes!) {
|
|
2075
|
-
eulerVaults(
|
|
2076
|
-
first: $first
|
|
2077
|
-
skip: $skip
|
|
2078
|
-
where: { asset: $asset }
|
|
2079
|
-
orderBy: state__supplyApy
|
|
2080
|
-
orderDirection: desc
|
|
2081
|
-
) {
|
|
2082
|
-
id
|
|
2083
|
-
evc
|
|
2084
|
-
evault
|
|
2085
|
-
name
|
|
2086
|
-
symbol
|
|
2087
|
-
asset
|
|
2088
|
-
decimals
|
|
2089
|
-
supplyCap
|
|
2090
|
-
borrowCap
|
|
2091
|
-
interestFee
|
|
2092
|
-
perspectives
|
|
2093
|
-
collaterals
|
|
2094
|
-
oracle
|
|
2095
|
-
unitOfAccount
|
|
2096
|
-
governonAdmin
|
|
2097
|
-
state {
|
|
2098
|
-
cash
|
|
2099
|
-
totalBorrows
|
|
2100
|
-
totalShares
|
|
2101
|
-
supplyApy
|
|
2102
|
-
borrowApy
|
|
2103
|
-
timestamp
|
|
2104
|
-
}
|
|
2105
|
-
}
|
|
2106
|
-
}
|
|
2107
|
-
`;
|
|
2108
2086
|
var COLLATERAL_META = `
|
|
2109
2087
|
query EulerCollateralVaults($first: Int!, $ids: [Bytes!]!) {
|
|
2110
2088
|
eulerVaults(first: $first, where: { id_in: $ids }) {
|
|
@@ -2310,23 +2288,41 @@ function vaultCashAndBorrows(r) {
|
|
|
2310
2288
|
}
|
|
2311
2289
|
return { cash, borrows };
|
|
2312
2290
|
}
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2291
|
+
function v3ApyDecimalToRayString(apy) {
|
|
2292
|
+
if (apy == null || !Number.isFinite(apy) || apy <= 0) return "0";
|
|
2293
|
+
const ray = BigInt(Math.round(apy * 1e9)) * 10n ** 18n;
|
|
2294
|
+
return ray.toString();
|
|
2295
|
+
}
|
|
2296
|
+
function v3VaultToGqlRow(v) {
|
|
2297
|
+
let cash = 0n;
|
|
2298
|
+
let borrows = 0n;
|
|
2299
|
+
try {
|
|
2300
|
+
const assets = BigInt((v.totalAssets ?? "0").trim() || "0");
|
|
2301
|
+
borrows = BigInt((v.totalBorrows ?? "0").trim() || "0");
|
|
2302
|
+
cash = assets > borrows ? assets - borrows : 0n;
|
|
2303
|
+
} catch {
|
|
2304
|
+
cash = 0n;
|
|
2305
|
+
borrows = 0n;
|
|
2328
2306
|
}
|
|
2329
|
-
|
|
2307
|
+
const addr = (v.address ?? "").trim();
|
|
2308
|
+
return {
|
|
2309
|
+
id: addr || null,
|
|
2310
|
+
evault: addr || null,
|
|
2311
|
+
name: v.name ?? null,
|
|
2312
|
+
symbol: v.symbol ?? null,
|
|
2313
|
+
asset: v.asset?.address ?? null,
|
|
2314
|
+
decimals: v.decimals != null ? String(v.decimals) : "18",
|
|
2315
|
+
state: {
|
|
2316
|
+
cash: cash.toString(),
|
|
2317
|
+
totalBorrows: borrows.toString(),
|
|
2318
|
+
supplyApy: v3ApyDecimalToRayString(v.supplyApy),
|
|
2319
|
+
borrowApy: v3ApyDecimalToRayString(v.borrowApy)
|
|
2320
|
+
}
|
|
2321
|
+
};
|
|
2322
|
+
}
|
|
2323
|
+
async function paginateLendVaultRows(chainId, assetLower) {
|
|
2324
|
+
const rows = await fetchEulerV3EvkVaults({ chainId, asset: assetLower });
|
|
2325
|
+
return rows.map(v3VaultToGqlRow);
|
|
2330
2326
|
}
|
|
2331
2327
|
async function fetchCollateralVaultMeta(chainId, collateralIds) {
|
|
2332
2328
|
const map = /* @__PURE__ */ new Map();
|
|
@@ -3806,10 +3802,18 @@ async function loadEulerV2PortfolioUsdSnapshot(args) {
|
|
|
3806
3802
|
|
|
3807
3803
|
// src/protocols/evm/euler-v2/loadEulerV2SupportedChainIds.ts
|
|
3808
3804
|
var cached = null;
|
|
3809
|
-
function loadEulerV2SupportedChainIds() {
|
|
3810
|
-
if (cached) return
|
|
3805
|
+
async function loadEulerV2SupportedChainIds() {
|
|
3806
|
+
if (cached) return cached;
|
|
3807
|
+
try {
|
|
3808
|
+
const ids = await fetchEulerV3ActiveChainIds();
|
|
3809
|
+
if (ids.length) {
|
|
3810
|
+
cached = new Set(ids);
|
|
3811
|
+
return cached;
|
|
3812
|
+
}
|
|
3813
|
+
} catch {
|
|
3814
|
+
}
|
|
3811
3815
|
cached = new Set(Object.keys(EULER_V2_GOLDSKY_SUBGRAPH_URL_BY_CHAIN_ID).map((k) => Number(k)));
|
|
3812
|
-
return
|
|
3816
|
+
return cached;
|
|
3813
3817
|
}
|
|
3814
3818
|
|
|
3815
3819
|
// src/protocols/evm/euler-v2/index.ts
|
|
@@ -3846,6 +3850,7 @@ exports.EULER_V2_ISOLATED_VAULT_DEPOSIT_FALLBACK_GAS = EULER_V2_ISOLATED_VAULT_D
|
|
|
3846
3850
|
exports.EULER_V2_PREFER_ON_CHAIN_LEND_METRICS = EULER_V2_PREFER_ON_CHAIN_LEND_METRICS;
|
|
3847
3851
|
exports.EULER_V2_PROTOCOL_ID = EULER_V2_PROTOCOL_ID;
|
|
3848
3852
|
exports.EULER_V2_VAULT_WITHDRAW_FALLBACK_GAS = EULER_V2_VAULT_WITHDRAW_FALLBACK_GAS;
|
|
3853
|
+
exports.EULER_V3_API_BASE = EULER_V3_API_BASE;
|
|
3849
3854
|
exports.REUL_FULL_VEST_SEC = REUL_FULL_VEST_SEC;
|
|
3850
3855
|
exports.REUL_LOCK_DAY_SEC = REUL_LOCK_DAY_SEC;
|
|
3851
3856
|
exports.buildEvmMultisignBodyEulerV2BorrowCollateralDepositBatch = buildEvmMultisignBodyEulerV2BorrowCollateralDepositBatch;
|
|
@@ -3889,6 +3894,9 @@ exports.fetchEulerV2EarnOfferingsForRowAsset = fetchEulerV2EarnOfferingsForRowAs
|
|
|
3889
3894
|
exports.fetchEulerV2IsolatedLendMarketsForRowAsset = fetchEulerV2IsolatedLendMarketsForRowAsset;
|
|
3890
3895
|
exports.fetchEulerV2TrackingBorrowEntries = fetchEulerV2TrackingBorrowEntries;
|
|
3891
3896
|
exports.fetchEulerV2TrackingDepositEntries = fetchEulerV2TrackingDepositEntries;
|
|
3897
|
+
exports.fetchEulerV3ActiveChainIds = fetchEulerV3ActiveChainIds;
|
|
3898
|
+
exports.fetchEulerV3EarnVaults = fetchEulerV3EarnVaults;
|
|
3899
|
+
exports.fetchEulerV3EvkVaults = fetchEulerV3EvkVaults;
|
|
3892
3900
|
exports.fetchEulerVaultAssetDecimals = fetchEulerVaultAssetDecimals;
|
|
3893
3901
|
exports.fetchEulerVaultMaxWithdrawWei = fetchEulerVaultMaxWithdrawWei;
|
|
3894
3902
|
exports.fetchEulerVaultOnChainLendMetrics = fetchEulerVaultOnChainLendMetrics;
|