@continuumdao/ctm-mpc-defi 0.2.32 → 0.2.34
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 +117 -163
- package/dist/agent/catalog.cjs.map +1 -1
- package/dist/agent/catalog.js +117 -163
- 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 +301 -294
- 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 +299 -296
- 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;
|
|
1691
|
-
}
|
|
1692
|
-
async function fetchEulerVaultOnChainLendMetrics(args) {
|
|
1693
|
-
const ch = viem.defineChain({
|
|
1694
|
-
id: args.chainId,
|
|
1695
|
-
name: "EulerVaultRead",
|
|
1696
|
-
nativeCurrency: { decimals: 18, name: "x", symbol: "x" },
|
|
1697
|
-
rpcUrls: { default: { http: [args.rpcUrl] } }
|
|
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
|
-
};
|
|
1665
|
+
async function fetchEulerV3EarnVaults(args) {
|
|
1666
|
+
return paginateV3Vaults("/v3/earn/vaults", args.chainId, args.asset ? { asset: args.asset } : {});
|
|
1734
1667
|
}
|
|
1735
|
-
async function
|
|
1736
|
-
const
|
|
1737
|
-
const
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
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,85 +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(chainId) {
|
|
1931
|
-
const out = [];
|
|
1932
|
-
let skip = 0;
|
|
1933
|
-
const first = 1e3;
|
|
1934
|
-
while (true) {
|
|
1935
|
-
const d = await eulerV2QueryGraphQl(chainId, 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(chainId) {
|
|
1948
|
-
const assets = [];
|
|
1949
|
-
let skip = 0;
|
|
1950
|
-
const first = 1e3;
|
|
1951
|
-
while (true) {
|
|
1952
|
-
const d = await eulerV2QueryGraphQl(
|
|
1953
|
-
chainId,
|
|
1954
|
-
EARN_PAGE,
|
|
1955
|
-
{
|
|
1956
|
-
first,
|
|
1957
|
-
skip
|
|
1958
|
-
}
|
|
1959
|
-
);
|
|
1960
|
-
const rows = d.eulerEarnVaults ?? [];
|
|
1961
|
-
if (!rows.length) break;
|
|
1962
|
-
for (const r of rows) {
|
|
1963
|
-
const a = normAssetAddr(r.asset ?? void 0);
|
|
1964
|
-
if (a) assets.push(a);
|
|
1965
|
-
}
|
|
1966
|
-
if (rows.length < first) break;
|
|
1967
|
-
skip += first;
|
|
1824
|
+
return false;
|
|
1968
1825
|
}
|
|
1969
|
-
return assets;
|
|
1970
1826
|
}
|
|
1971
1827
|
var eulerV2ChainAssetCache = /* @__PURE__ */ new Map();
|
|
1972
1828
|
async function fetchEulerV2ChainAssetCache(chainId) {
|
|
1973
|
-
const
|
|
1974
|
-
if (!endpoint) {
|
|
1975
|
-
return { nativeWrapped: null, modesByUnderlying: /* @__PURE__ */ new Map() };
|
|
1976
|
-
}
|
|
1977
|
-
const [nativeWrapped, vaultRows, earnAssets] = await Promise.all([
|
|
1829
|
+
const [nativeWrapped, evkVaults, earnVaults] = await Promise.all([
|
|
1978
1830
|
resolveEulerWrappedNativeToken(chainId),
|
|
1979
|
-
|
|
1980
|
-
|
|
1831
|
+
fetchEulerV3EvkVaults({ chainId }),
|
|
1832
|
+
fetchEulerV3EarnVaults({ chainId }).catch(() => [])
|
|
1981
1833
|
]);
|
|
1982
1834
|
const modes = /* @__PURE__ */ new Map();
|
|
1983
1835
|
const bump = (addr, patch) => {
|
|
@@ -1988,13 +1840,17 @@ async function fetchEulerV2ChainAssetCache(chainId) {
|
|
|
1988
1840
|
earn: cur.earn || !!patch.earn
|
|
1989
1841
|
});
|
|
1990
1842
|
};
|
|
1991
|
-
for (const
|
|
1992
|
-
|
|
1993
|
-
|
|
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);
|
|
1994
1849
|
if (!a) continue;
|
|
1850
|
+
const vis = v.visibility;
|
|
1995
1851
|
bump(a, {
|
|
1996
|
-
lend:
|
|
1997
|
-
borrow:
|
|
1852
|
+
lend: vis?.explorableLend !== false,
|
|
1853
|
+
borrow: v3VaultShowsBorrow(v.totalBorrows, vis?.explorableBorrow)
|
|
1998
1854
|
});
|
|
1999
1855
|
}
|
|
2000
1856
|
return { nativeWrapped, modesByUnderlying: modes };
|
|
@@ -2071,47 +1927,162 @@ function eulerLabelsLookupLabelForVault(labelMap, evaultAddress) {
|
|
|
2071
1927
|
const v = labelMap.get(k);
|
|
2072
1928
|
return typeof v === "string" && v.trim() ? v.trim() : void 0;
|
|
2073
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
|
+
}
|
|
2074
2080
|
|
|
2075
2081
|
// src/protocols/evm/euler-v2/eulerV2LendMarkets.ts
|
|
2076
2082
|
var erc20StringMetaAbi = viem.parseAbi([
|
|
2077
2083
|
"function name() view returns (string)",
|
|
2078
2084
|
"function symbol() view returns (string)"
|
|
2079
2085
|
]);
|
|
2080
|
-
var LEND_VAULT_PAGE = `
|
|
2081
|
-
query EulerLendVaults($first: Int!, $skip: Int!, $asset: Bytes!) {
|
|
2082
|
-
eulerVaults(
|
|
2083
|
-
first: $first
|
|
2084
|
-
skip: $skip
|
|
2085
|
-
where: { asset: $asset }
|
|
2086
|
-
orderBy: state__supplyApy
|
|
2087
|
-
orderDirection: desc
|
|
2088
|
-
) {
|
|
2089
|
-
id
|
|
2090
|
-
evc
|
|
2091
|
-
evault
|
|
2092
|
-
name
|
|
2093
|
-
symbol
|
|
2094
|
-
asset
|
|
2095
|
-
decimals
|
|
2096
|
-
supplyCap
|
|
2097
|
-
borrowCap
|
|
2098
|
-
interestFee
|
|
2099
|
-
perspectives
|
|
2100
|
-
collaterals
|
|
2101
|
-
oracle
|
|
2102
|
-
unitOfAccount
|
|
2103
|
-
governonAdmin
|
|
2104
|
-
state {
|
|
2105
|
-
cash
|
|
2106
|
-
totalBorrows
|
|
2107
|
-
totalShares
|
|
2108
|
-
supplyApy
|
|
2109
|
-
borrowApy
|
|
2110
|
-
timestamp
|
|
2111
|
-
}
|
|
2112
|
-
}
|
|
2113
|
-
}
|
|
2114
|
-
`;
|
|
2115
2086
|
var COLLATERAL_META = `
|
|
2116
2087
|
query EulerCollateralVaults($first: Int!, $ids: [Bytes!]!) {
|
|
2117
2088
|
eulerVaults(first: $first, where: { id_in: $ids }) {
|
|
@@ -2317,23 +2288,42 @@ function vaultCashAndBorrows(r) {
|
|
|
2317
2288
|
}
|
|
2318
2289
|
return { cash, borrows };
|
|
2319
2290
|
}
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
const
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
const
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2291
|
+
function v3ApyPercentToRayString(apyPercent) {
|
|
2292
|
+
if (apyPercent == null || !Number.isFinite(apyPercent) || apyPercent <= 0) return "0";
|
|
2293
|
+
const fraction = apyPercent / 100;
|
|
2294
|
+
const ray = BigInt(Math.round(fraction * 1e9)) * 10n ** 18n;
|
|
2295
|
+
return ray.toString();
|
|
2296
|
+
}
|
|
2297
|
+
function v3VaultToGqlRow(v) {
|
|
2298
|
+
let cash = 0n;
|
|
2299
|
+
let borrows = 0n;
|
|
2300
|
+
try {
|
|
2301
|
+
const assets = BigInt((v.totalAssets ?? "0").trim() || "0");
|
|
2302
|
+
borrows = BigInt((v.totalBorrows ?? "0").trim() || "0");
|
|
2303
|
+
cash = assets > borrows ? assets - borrows : 0n;
|
|
2304
|
+
} catch {
|
|
2305
|
+
cash = 0n;
|
|
2306
|
+
borrows = 0n;
|
|
2335
2307
|
}
|
|
2336
|
-
|
|
2308
|
+
const addr = (v.address ?? "").trim();
|
|
2309
|
+
return {
|
|
2310
|
+
id: addr || null,
|
|
2311
|
+
evault: addr || null,
|
|
2312
|
+
name: v.name ?? null,
|
|
2313
|
+
symbol: v.symbol ?? null,
|
|
2314
|
+
asset: v.asset?.address ?? null,
|
|
2315
|
+
decimals: v.decimals != null ? String(v.decimals) : "18",
|
|
2316
|
+
state: {
|
|
2317
|
+
cash: cash.toString(),
|
|
2318
|
+
totalBorrows: borrows.toString(),
|
|
2319
|
+
supplyApy: v3ApyPercentToRayString(v.supplyApy),
|
|
2320
|
+
borrowApy: v3ApyPercentToRayString(v.borrowApy)
|
|
2321
|
+
}
|
|
2322
|
+
};
|
|
2323
|
+
}
|
|
2324
|
+
async function paginateLendVaultRows(chainId, assetLower) {
|
|
2325
|
+
const rows = await fetchEulerV3EvkVaults({ chainId, asset: assetLower });
|
|
2326
|
+
return rows.map(v3VaultToGqlRow);
|
|
2337
2327
|
}
|
|
2338
2328
|
async function fetchCollateralVaultMeta(chainId, collateralIds) {
|
|
2339
2329
|
const map = /* @__PURE__ */ new Map();
|
|
@@ -2341,7 +2331,12 @@ async function fetchCollateralVaultMeta(chainId, collateralIds) {
|
|
|
2341
2331
|
const chunkSize = 400;
|
|
2342
2332
|
for (let i = 0; i < uniq.length; i += chunkSize) {
|
|
2343
2333
|
const chunk = uniq.slice(i, i + chunkSize);
|
|
2344
|
-
|
|
2334
|
+
let d;
|
|
2335
|
+
try {
|
|
2336
|
+
d = await eulerV2QueryGraphQl(chainId, COLLATERAL_META, { first: chunk.length, ids: chunk });
|
|
2337
|
+
} catch {
|
|
2338
|
+
continue;
|
|
2339
|
+
}
|
|
2345
2340
|
for (const r of d.eulerVaults ?? []) {
|
|
2346
2341
|
const id = normId(r.id ?? void 0);
|
|
2347
2342
|
if (!id) continue;
|
|
@@ -3813,10 +3808,18 @@ async function loadEulerV2PortfolioUsdSnapshot(args) {
|
|
|
3813
3808
|
|
|
3814
3809
|
// src/protocols/evm/euler-v2/loadEulerV2SupportedChainIds.ts
|
|
3815
3810
|
var cached = null;
|
|
3816
|
-
function loadEulerV2SupportedChainIds() {
|
|
3817
|
-
if (cached) return
|
|
3811
|
+
async function loadEulerV2SupportedChainIds() {
|
|
3812
|
+
if (cached) return cached;
|
|
3813
|
+
try {
|
|
3814
|
+
const ids = await fetchEulerV3ActiveChainIds();
|
|
3815
|
+
if (ids.length) {
|
|
3816
|
+
cached = new Set(ids);
|
|
3817
|
+
return cached;
|
|
3818
|
+
}
|
|
3819
|
+
} catch {
|
|
3820
|
+
}
|
|
3818
3821
|
cached = new Set(Object.keys(EULER_V2_GOLDSKY_SUBGRAPH_URL_BY_CHAIN_ID).map((k) => Number(k)));
|
|
3819
|
-
return
|
|
3822
|
+
return cached;
|
|
3820
3823
|
}
|
|
3821
3824
|
|
|
3822
3825
|
// src/protocols/evm/euler-v2/index.ts
|
|
@@ -3853,6 +3856,7 @@ exports.EULER_V2_ISOLATED_VAULT_DEPOSIT_FALLBACK_GAS = EULER_V2_ISOLATED_VAULT_D
|
|
|
3853
3856
|
exports.EULER_V2_PREFER_ON_CHAIN_LEND_METRICS = EULER_V2_PREFER_ON_CHAIN_LEND_METRICS;
|
|
3854
3857
|
exports.EULER_V2_PROTOCOL_ID = EULER_V2_PROTOCOL_ID;
|
|
3855
3858
|
exports.EULER_V2_VAULT_WITHDRAW_FALLBACK_GAS = EULER_V2_VAULT_WITHDRAW_FALLBACK_GAS;
|
|
3859
|
+
exports.EULER_V3_API_BASE = EULER_V3_API_BASE;
|
|
3856
3860
|
exports.REUL_FULL_VEST_SEC = REUL_FULL_VEST_SEC;
|
|
3857
3861
|
exports.REUL_LOCK_DAY_SEC = REUL_LOCK_DAY_SEC;
|
|
3858
3862
|
exports.buildEvmMultisignBodyEulerV2BorrowCollateralDepositBatch = buildEvmMultisignBodyEulerV2BorrowCollateralDepositBatch;
|
|
@@ -3896,6 +3900,9 @@ exports.fetchEulerV2EarnOfferingsForRowAsset = fetchEulerV2EarnOfferingsForRowAs
|
|
|
3896
3900
|
exports.fetchEulerV2IsolatedLendMarketsForRowAsset = fetchEulerV2IsolatedLendMarketsForRowAsset;
|
|
3897
3901
|
exports.fetchEulerV2TrackingBorrowEntries = fetchEulerV2TrackingBorrowEntries;
|
|
3898
3902
|
exports.fetchEulerV2TrackingDepositEntries = fetchEulerV2TrackingDepositEntries;
|
|
3903
|
+
exports.fetchEulerV3ActiveChainIds = fetchEulerV3ActiveChainIds;
|
|
3904
|
+
exports.fetchEulerV3EarnVaults = fetchEulerV3EarnVaults;
|
|
3905
|
+
exports.fetchEulerV3EvkVaults = fetchEulerV3EvkVaults;
|
|
3899
3906
|
exports.fetchEulerVaultAssetDecimals = fetchEulerVaultAssetDecimals;
|
|
3900
3907
|
exports.fetchEulerVaultMaxWithdrawWei = fetchEulerVaultMaxWithdrawWei;
|
|
3901
3908
|
exports.fetchEulerVaultOnChainLendMetrics = fetchEulerVaultOnChainLendMetrics;
|