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