@continuumdao/ctm-mpc-defi 0.2.62 → 0.2.63

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.
@@ -1951,6 +1951,8 @@ async function fetchEulerV2ChainAssetCache(chainId) {
1951
1951
  fetchEulerV3EarnVaults({ chainId }).catch(() => [])
1952
1952
  ]);
1953
1953
  const modes = /* @__PURE__ */ new Map();
1954
+ const symbols = /* @__PURE__ */ new Map();
1955
+ const ambiguousSymbols = /* @__PURE__ */ new Set();
1954
1956
  const bump = (addr, patch) => {
1955
1957
  const cur = modes.get(addr) ?? { lend: false, borrow: false, earn: false };
1956
1958
  modes.set(addr, {
@@ -1959,9 +1961,26 @@ async function fetchEulerV2ChainAssetCache(chainId) {
1959
1961
  earn: cur.earn || !!patch.earn
1960
1962
  });
1961
1963
  };
1964
+ const noteSymbol = (symbol, addr) => {
1965
+ const sym = (symbol ?? "").trim().toLowerCase();
1966
+ if (!sym || ambiguousSymbols.has(sym) || !viem.isAddress(addr)) return;
1967
+ const checksum = viem.getAddress(addr);
1968
+ const prev = symbols.get(sym);
1969
+ if (!prev) {
1970
+ symbols.set(sym, checksum);
1971
+ return;
1972
+ }
1973
+ if (prev.toLowerCase() !== checksum.toLowerCase()) {
1974
+ symbols.delete(sym);
1975
+ ambiguousSymbols.add(sym);
1976
+ }
1977
+ };
1962
1978
  for (const v of earnVaults) {
1963
1979
  const a = normAssetAddr(v.asset?.address ?? void 0);
1964
- if (a) bump(a, { earn: true });
1980
+ if (a) {
1981
+ bump(a, { earn: true });
1982
+ noteSymbol(v.asset?.symbol, a);
1983
+ }
1965
1984
  }
1966
1985
  for (const v of evkVaults) {
1967
1986
  const a = normAssetAddr(v.asset?.address ?? void 0);
@@ -1971,8 +1990,16 @@ async function fetchEulerV2ChainAssetCache(chainId) {
1971
1990
  lend: vis?.explorableLend !== false,
1972
1991
  borrow: v3VaultShowsBorrow(v.totalBorrows, vis?.explorableBorrow)
1973
1992
  });
1993
+ noteSymbol(v.asset?.symbol, a);
1974
1994
  }
1975
- return { nativeWrapped, modesByUnderlying: modes };
1995
+ const weth = symbols.get("weth");
1996
+ if (weth && !symbols.has("eth") && !ambiguousSymbols.has("eth")) {
1997
+ symbols.set("eth", weth);
1998
+ }
1999
+ return { nativeWrapped, modesByUnderlying: modes, symbolToAddress: symbols };
2000
+ }
2001
+ function resetEulerV2ChainAssetCache() {
2002
+ eulerV2ChainAssetCache.clear();
1976
2003
  }
1977
2004
  function ensureEulerV2ChainAssetCache(chainId) {
1978
2005
  const hit = eulerV2ChainAssetCache.get(chainId);
@@ -2658,11 +2685,20 @@ async function fetchEulerV2IsolatedLendMarketsForRowAsset(args) {
2658
2685
  }
2659
2686
  return rows;
2660
2687
  }
2661
- async function eulerV2FetchLendVaultsSummary(args) {
2662
- const addr = (await canonicalizeEvmTokenInput(args.underlyingAddress)).trim();
2663
- if (!viem.isAddress(addr)) {
2664
- throw new Error("underlyingAddress must be a valid ERC-20 address.");
2688
+ async function resolveEulerUnderlyingAddress(chainId, input) {
2689
+ const canon = (await canonicalizeEvmTokenInput(input)).trim();
2690
+ if (viem.isAddress(canon)) return viem.getAddress(canon);
2691
+ const cache = await ensureEulerV2ChainAssetCache(chainId);
2692
+ const hit = cache.symbolToAddress.get(canon.toLowerCase());
2693
+ if (!hit) {
2694
+ throw new Error(
2695
+ `underlyingAddress must be a valid ERC-20 address, or a ticker from Euler vaults on chain ${chainId} (for example USDC). "${canon}" did not match one underlying.`
2696
+ );
2665
2697
  }
2698
+ return hit;
2699
+ }
2700
+ async function eulerV2FetchLendVaultsSummary(args) {
2701
+ const addr = await resolveEulerUnderlyingAddress(args.chainId, args.underlyingAddress);
2666
2702
  const limit = Math.min(Math.max(args.limit ?? 30, 1), 100);
2667
2703
  const markets = await fetchEulerV2IsolatedLendMarketsForRowAsset({
2668
2704
  chainId: args.chainId,
@@ -2955,10 +2991,7 @@ function checksumHex2(raw) {
2955
2991
 
2956
2992
  // src/protocols/evm/euler-v2/eulerV2EarnDiscovery.ts
2957
2993
  async function eulerV2FetchEarnVaultsSummary(args) {
2958
- const addr = (await canonicalizeEvmTokenInput(args.underlyingAddress)).trim();
2959
- if (!viem.isAddress(addr)) {
2960
- throw new Error("underlyingAddress must be a valid ERC-20 address.");
2961
- }
2994
+ const addr = await resolveEulerUnderlyingAddress(args.chainId, args.underlyingAddress);
2962
2995
  const limit = Math.min(Math.max(args.limit ?? 30, 1), 100);
2963
2996
  await ensureEulerV2ChainAssetCache(args.chainId);
2964
2997
  const underlying = viem.getAddress(addr);
@@ -4288,8 +4321,10 @@ exports.maxCollateralWeiCappedByBorrowLiquidity = maxCollateralWeiCappedByBorrow
4288
4321
  exports.mergeEulerV2PositionsTabRows = mergeEulerV2PositionsTabRows;
4289
4322
  exports.parseEulerTrackingBorrowEntry = parseEulerTrackingBorrowEntry;
4290
4323
  exports.planSameAssetLeveragedBorrows = planSameAssetLeveragedBorrows;
4324
+ exports.resetEulerV2ChainAssetCache = resetEulerV2ChainAssetCache;
4291
4325
  exports.resolveEulerAmountCapToSupplyWei = resolveEulerAmountCapToSupplyWei;
4292
4326
  exports.resolveEulerAmountCapToWei = resolveEulerAmountCapToWei;
4327
+ exports.resolveEulerUnderlyingAddress = resolveEulerUnderlyingAddress;
4293
4328
  exports.resolveEulerWrappedNativeToken = resolveEulerWrappedNativeToken;
4294
4329
  //# sourceMappingURL=index.cjs.map
4295
4330
  //# sourceMappingURL=index.cjs.map