@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.
@@ -50,7 +50,7 @@ async function postJsonViaOptionalProxy(args) {
50
50
  return await r.json();
51
51
  }
52
52
  async function getJsonViaOptionalProxy(args) {
53
- const url = args.directUrl;
53
+ const url = args.proxyUrl?.trim() || args.directUrl;
54
54
  const r = await fetch(url, { method: "GET", headers: { accept: "application/json" } });
55
55
  if (!r.ok) {
56
56
  const t = await r.text().catch(() => "");
@@ -191,7 +191,8 @@ function midnightApiConfig() {
191
191
  async function midnightGetJson(pathAndQuery) {
192
192
  const path = pathAndQuery.startsWith("/") ? pathAndQuery : `/${pathAndQuery}`;
193
193
  const directUrl = `${MORPHO_MIDNIGHT_REST_BASE}${path}`;
194
- return getJsonViaOptionalProxy({ directUrl});
194
+ const proxyUrl = void 0;
195
+ return getJsonViaOptionalProxy({ directUrl, proxyUrl });
195
196
  }
196
197
  async function fetchMorphoMidnightBooks(args) {
197
198
  const limit = args.limit == null ? void 0 : Math.min(Math.max(Math.floor(args.limit), 1), MORPHO_MIDNIGHT_BOOKS_MAX_LIMIT);
@@ -291,10 +292,10 @@ function morphoMidnightBookToMarketParams(book) {
291
292
  async function fetchMorphoMidnightUserPositions(args) {
292
293
  const user = args.user.trim();
293
294
  if (!isAddress(user)) return [];
294
- const qs = new URLSearchParams();
295
- if (args.types) qs.set("types", args.types);
296
- if (args.activeOnly) qs.set("active_only", "true");
297
- const q = qs.toString();
295
+ const qs2 = new URLSearchParams();
296
+ if (args.types) qs2.set("types", args.types);
297
+ if (args.activeOnly) qs2.set("active_only", "true");
298
+ const q = qs2.toString();
298
299
  const path = `/users/${encodeURIComponent(getAddress(user))}/positions${q ? `?${q}` : ""}`;
299
300
  const j = await midnightGetJson(path);
300
301
  const rows = [];
@@ -317,10 +318,10 @@ async function fetchMorphoMidnightUserPositions(args) {
317
318
  return rows;
318
319
  }
319
320
  async function fetchMorphoMidnightMakerOffers(args) {
320
- const qs = new URLSearchParams();
321
- qs.set("maker", getAddress(args.maker));
322
- if (args.chainId != null) qs.set("chain_ids", String(args.chainId));
323
- const j = await midnightGetJson(`/takeable-offers?${qs}`);
321
+ const qs2 = new URLSearchParams();
322
+ qs2.set("maker", getAddress(args.maker));
323
+ if (args.chainId != null) qs2.set("chain_ids", String(args.chainId));
324
+ const j = await midnightGetJson(`/takeable-offers?${qs2}`);
324
325
  const out = [];
325
326
  for (const row of j.data ?? []) {
326
327
  const o = row.offer;
@@ -668,9 +669,9 @@ async function loadFullCurveSessionForRpc(rpcUrl) {
668
669
  if (!url) {
669
670
  throw new Error("rpcUrl is required.");
670
671
  }
671
- const cached = curveSessionCache.get(url);
672
- if (cached && cached.expiresAt > Date.now()) {
673
- return cached.session;
672
+ const cached2 = curveSessionCache.get(url);
673
+ if (cached2 && cached2.expiresAt > Date.now()) {
674
+ return cached2.session;
674
675
  }
675
676
  try {
676
677
  const { default: curve } = await import('@curvefi/api');
@@ -7068,6 +7069,198 @@ var aaveV4ProtocolModule = {
7068
7069
  };
7069
7070
  registerProtocolModule(aaveV4ProtocolModule);
7070
7071
 
7072
+ // src/protocols/evm/euler-v2/eulerV3Api.ts
7073
+ init_defiProxy();
7074
+ var EULER_V3_API_BASE = "https://v3.euler.finance";
7075
+ function qs(params) {
7076
+ const u = new URLSearchParams();
7077
+ for (const [k, v] of Object.entries(params)) {
7078
+ if (v == null) continue;
7079
+ u.set(k, String(v));
7080
+ }
7081
+ const s = u.toString();
7082
+ return s ? `?${s}` : "";
7083
+ }
7084
+ async function eulerV3Get(path, params = {}) {
7085
+ const rel = path.startsWith("/") ? path : `/${path}`;
7086
+ const query = qs(params);
7087
+ const directUrl = `${EULER_V3_API_BASE}${rel}${query}`;
7088
+ rel.replace(/^\/v3\/?/, "");
7089
+ const proxyUrl = void 0;
7090
+ return getJsonViaOptionalProxy({ directUrl, proxyUrl });
7091
+ }
7092
+ async function paginateV3Vaults(path, chainId, extra = {}) {
7093
+ const out = [];
7094
+ let offset = 0;
7095
+ const limit = 100;
7096
+ while (true) {
7097
+ const page = await eulerV3Get(path, {
7098
+ chainId,
7099
+ limit,
7100
+ offset,
7101
+ ...extra
7102
+ });
7103
+ const rows = page.data ?? [];
7104
+ out.push(...rows);
7105
+ const total = typeof page.meta?.total === "number" ? page.meta.total : out.length;
7106
+ offset += rows.length;
7107
+ if (!rows.length || offset >= total) break;
7108
+ }
7109
+ return out;
7110
+ }
7111
+ async function fetchEulerV3EvkVaults(args) {
7112
+ return paginateV3Vaults("/v3/evk/vaults", args.chainId, args.asset ? { asset: args.asset } : {});
7113
+ }
7114
+ async function fetchEulerV3EarnVaults(args) {
7115
+ return paginateV3Vaults("/v3/earn/vaults", args.chainId, args.asset ? { asset: args.asset } : {});
7116
+ }
7117
+ async function fetchEulerV3ActiveChainIds() {
7118
+ const page = await eulerV3Get("/v3/chains");
7119
+ const ids = [];
7120
+ for (const row of page.data ?? []) {
7121
+ if (typeof row.id !== "number" || !Number.isFinite(row.id)) continue;
7122
+ if ((row.status ?? "active") !== "active") continue;
7123
+ ids.push(row.id);
7124
+ }
7125
+ return ids.sort((a, b) => a - b);
7126
+ }
7127
+
7128
+ // src/protocols/evm/euler-v2/eulerV2Subgraph.ts
7129
+ var EULER_V2_GOLDSKY_SUBGRAPH_URL_BY_CHAIN_ID = {
7130
+ 1: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-simple-mainnet/latest/gn",
7131
+ 8453: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-simple-base/latest/gn",
7132
+ 1923: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-simple-swell/latest/gn",
7133
+ 146: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-simple-sonic/latest/gn",
7134
+ 60808: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-simple-bob/latest/gn",
7135
+ 80094: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-simple-berachain/latest/gn",
7136
+ 43114: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-simple-avalanche/latest/gn",
7137
+ 42161: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-simple-arbitrum/latest/gn",
7138
+ 130: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-simple-unichain/latest/gn",
7139
+ 56: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-simple-bsc/latest/gn",
7140
+ 999: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-simple-hyperevm/latest/gn",
7141
+ 239: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-simple-tac/latest/gn",
7142
+ 9745: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-simple-plasma/latest/gn",
7143
+ 137: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-simple-polygon/latest/gn",
7144
+ 59144: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-simple-linea/latest/gn",
7145
+ 143: "https://api.goldsky.com/api/public/project_cm4iagnemt1wp01xn4gh1agft/subgraphs/euler-simple-monad/latest/gn"
7146
+ };
7147
+ var WRAPPED_NATIVE_FALLBACK = {
7148
+ 1: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
7149
+ 10: "0x4200000000000000000000000000000000000006",
7150
+ 56: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
7151
+ 100: "0xe91d153e0b41518a2ce8dd3d7944fa863463a97d",
7152
+ 130: "0x4200000000000000000000000000000000000006",
7153
+ 137: "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",
7154
+ // Polygon: WPOL
7155
+ 143: "0x3bd359C1119dA7Da1D913D1C4D2B7c461115433A",
7156
+ // Monad: WMON
7157
+ 146: "0x03980325872071166574bcd94670450917897468",
7158
+ 239: "0xB63B9f0eb4A6E6f191529D71d4D88cc8900Df2C9",
7159
+ // TAC: WTAC (https://docs.tac.build/ecosystem/token-list)
7160
+ 480: "0x4200000000000000000000000000000000000006",
7161
+ 999: "0x5555555555555555555555555555555555555555",
7162
+ // HyperEVM: WHYPE (Hyperliquid docs)
7163
+ 1923: "0x4200000000000000000000000000000000000006",
7164
+ 42161: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
7165
+ 43114: "0xB31f66AA3C1e785363F0875A1B74D27b85FE0459",
7166
+ 5e3: "0x78c1b0C915c4FAA5FffA6CAbf0219DA63d7f4cb8",
7167
+ // Mantle: WMNT
7168
+ 59144: "0xe5D7C2a44FfDDf6b295A15c148167daaAf5Cf34f",
7169
+ // Linea: WETH
7170
+ 57073: "0x4200000000000000000000000000000000000006",
7171
+ 60808: "0x4200000000000000000000000000000000000006",
7172
+ 80094: "0x6969696969696969696969696969696969696969",
7173
+ // Berachain: WBERA (https://docs.berachain.com)
7174
+ 8453: "0x4200000000000000000000000000000000000006",
7175
+ 9745: "0x6100E367285b01F48D07953803A2d8dCA5D19873"
7176
+ // Plasma: WXPL
7177
+ };
7178
+ for (const id of Object.keys(EULER_V2_GOLDSKY_SUBGRAPH_URL_BY_CHAIN_ID).map(Number)) {
7179
+ if (WRAPPED_NATIVE_FALLBACK[id] == null) {
7180
+ throw new Error(`eulerV2Subgraph: add WRAPPED_NATIVE_FALLBACK for Euler Goldsky chain ${id}`);
7181
+ }
7182
+ }
7183
+ async function resolveEulerWrappedNativeToken(chainId) {
7184
+ try {
7185
+ const fromAave = await fetchAaveV4NativeWrappedToken(chainId);
7186
+ if (fromAave) return fromAave;
7187
+ } catch {
7188
+ }
7189
+ const fb = WRAPPED_NATIVE_FALLBACK[chainId];
7190
+ if (fb && isAddress(fb)) return getAddress(fb);
7191
+ return null;
7192
+ }
7193
+ function normAssetAddr(raw) {
7194
+ const s = (raw ?? "").trim();
7195
+ if (!s || !isAddress(s)) return null;
7196
+ return getAddress(s).toLowerCase();
7197
+ }
7198
+ function v3VaultShowsBorrow(totalBorrows, explorableBorrow) {
7199
+ if (explorableBorrow === true) return true;
7200
+ try {
7201
+ return BigInt((totalBorrows ?? "0").trim() || "0") > 0n;
7202
+ } catch {
7203
+ return false;
7204
+ }
7205
+ }
7206
+ var eulerV2ChainAssetCache = /* @__PURE__ */ new Map();
7207
+ async function fetchEulerV2ChainAssetCache(chainId) {
7208
+ const [nativeWrapped, evkVaults, earnVaults] = await Promise.all([
7209
+ resolveEulerWrappedNativeToken(chainId),
7210
+ fetchEulerV3EvkVaults({ chainId }),
7211
+ fetchEulerV3EarnVaults({ chainId }).catch(() => [])
7212
+ ]);
7213
+ const modes = /* @__PURE__ */ new Map();
7214
+ const bump = (addr, patch) => {
7215
+ const cur = modes.get(addr) ?? { lend: false, borrow: false, earn: false };
7216
+ modes.set(addr, {
7217
+ lend: cur.lend || !!patch.lend,
7218
+ borrow: cur.borrow || !!patch.borrow,
7219
+ earn: cur.earn || !!patch.earn
7220
+ });
7221
+ };
7222
+ for (const v of earnVaults) {
7223
+ const a = normAssetAddr(v.asset?.address ?? void 0);
7224
+ if (a) bump(a, { earn: true });
7225
+ }
7226
+ for (const v of evkVaults) {
7227
+ const a = normAssetAddr(v.asset?.address ?? void 0);
7228
+ if (!a) continue;
7229
+ const vis = v.visibility;
7230
+ bump(a, {
7231
+ lend: vis?.explorableLend !== false,
7232
+ borrow: v3VaultShowsBorrow(v.totalBorrows, vis?.explorableBorrow)
7233
+ });
7234
+ }
7235
+ return { nativeWrapped, modesByUnderlying: modes };
7236
+ }
7237
+ function ensureEulerV2ChainAssetCache(chainId) {
7238
+ const hit = eulerV2ChainAssetCache.get(chainId);
7239
+ if (hit) return hit;
7240
+ const p = fetchEulerV2ChainAssetCache(chainId).catch((e) => {
7241
+ eulerV2ChainAssetCache.delete(chainId);
7242
+ throw e;
7243
+ });
7244
+ eulerV2ChainAssetCache.set(chainId, p);
7245
+ return p;
7246
+ }
7247
+
7248
+ // src/protocols/evm/euler-v2/loadEulerV2SupportedChainIds.ts
7249
+ var cached = null;
7250
+ async function loadEulerV2SupportedChainIds() {
7251
+ if (cached) return cached;
7252
+ try {
7253
+ const ids = await fetchEulerV3ActiveChainIds();
7254
+ if (ids.length) {
7255
+ cached = new Set(ids);
7256
+ return cached;
7257
+ }
7258
+ } catch {
7259
+ }
7260
+ cached = new Set(Object.keys(EULER_V2_GOLDSKY_SUBGRAPH_URL_BY_CHAIN_ID).map((k) => Number(k)));
7261
+ return cached;
7262
+ }
7263
+
7071
7264
  // src/protocols/evm/euler-v2/index.ts
7072
7265
  var EULER_V2_PROTOCOL_ID = "euler-v2";
7073
7266
  var eulerV2ProtocolModule = {
@@ -7113,8 +7306,8 @@ function buildGmxUrl(baseUrl, path, query) {
7113
7306
  for (const [key, value] of Object.entries(query)) {
7114
7307
  if (value !== void 0 && value !== null) params.set(key, String(value));
7115
7308
  }
7116
- const qs = params.toString();
7117
- return qs ? `${base}${path}?${qs}` : `${base}${path}`;
7309
+ const qs2 = params.toString();
7310
+ return qs2 ? `${base}${path}?${qs2}` : `${base}${path}`;
7118
7311
  }
7119
7312
  function bigintReplacer(_key, value) {
7120
7313
  return typeof value === "bigint" ? value.toString() : value;
@@ -9043,20 +9236,6 @@ function getProtocolDiscoverySummary(protocolId) {
9043
9236
  };
9044
9237
  }
9045
9238
  init_support();
9046
- var EULER_V2_SUBGRAPH_CHAIN_IDS = [
9047
- 1,
9048
- 8453,
9049
- 42161,
9050
- 10,
9051
- 137,
9052
- 56,
9053
- 43114,
9054
- 100,
9055
- 59144,
9056
- 146,
9057
- 1923,
9058
- 130
9059
- ];
9060
9239
  function advisor(protocolId, tokenFilter, impl) {
9061
9240
  return { protocolId, tokenFilter, ...impl };
9062
9241
  }
@@ -9290,13 +9469,34 @@ var PROTOCOL_SUPPORT_ADVISORS = {
9290
9469
  }),
9291
9470
  "euler-v2": advisor("euler-v2", "subgraph_vaults", {
9292
9471
  async supportedChainIds() {
9293
- return [...EULER_V2_SUBGRAPH_CHAIN_IDS];
9472
+ const set = await loadEulerV2SupportedChainIds();
9473
+ return [...set].sort((a, b) => a - b);
9294
9474
  },
9295
- async supportedTokens() {
9475
+ async supportedTokens(chainId) {
9476
+ const cache = await ensureEulerV2ChainAssetCache(chainId);
9477
+ const tokens = [...cache.modesByUnderlying.entries()].map(([address, modes]) => ({
9478
+ address,
9479
+ roles: [
9480
+ ...modes.lend ? ["vault_underlying"] : [],
9481
+ ...modes.borrow ? ["loan"] : [],
9482
+ ...modes.earn ? ["earn"] : []
9483
+ ]
9484
+ }));
9296
9485
  return {
9297
- tokens: [],
9298
- notes: "Euler vault/collateral assets vary by chain. Pass vault and asset addresses from Euler app or subgraph."
9486
+ tokens,
9487
+ nativeWrapped: cache.nativeWrapped ?? void 0,
9488
+ notes: "Euler EVK vault underlyings and Earn vault assets from the Euler V3 API. Use address as underlyingAddress for ctm_euler_v2_fetch_lend_vaults."
9299
9489
  };
9490
+ },
9491
+ async isTokenSupported(chainId, address) {
9492
+ const cache = await ensureEulerV2ChainAssetCache(chainId);
9493
+ let normalized;
9494
+ try {
9495
+ normalized = getAddress(address).toLowerCase();
9496
+ } catch {
9497
+ return false;
9498
+ }
9499
+ return cache.modesByUnderlying.has(normalized);
9300
9500
  }
9301
9501
  }),
9302
9502
  [MAPLE_PROTOCOL_ID]: advisor(MAPLE_PROTOCOL_ID, "fixed_addresses", {