@continuumdao/ctm-mpc-defi 0.2.2 → 0.2.3

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.
@@ -212,44 +212,64 @@ function swappableCurveGraphNodeKeys(adj) {
212
212
  }
213
213
 
214
214
  // src/protocols/evm/curve-dao/apiSession.ts
215
+ var CURVE_SESSION_CACHE_TTL_MS = 5 * 60 * 1e3;
216
+ var curveSessionCache = /* @__PURE__ */ new Map();
215
217
  async function fetchAllCurvePools(curve) {
216
218
  const run = (p) => p.catch(() => void 0);
217
- await Promise.all([
218
- run(curve.factory.fetchPools()),
219
- run(curve.crvUSDFactory.fetchPools()),
220
- run(curve.EYWAFactory.fetchPools()),
221
- run(curve.cryptoFactory.fetchPools()),
222
- run(curve.twocryptoFactory.fetchPools()),
223
- run(curve.tricryptoFactory.fetchPools()),
224
- run(curve.stableNgFactory.fetchPools())
225
- ]);
219
+ const tasks = [];
220
+ for (const key of [
221
+ "factory",
222
+ "crvUSDFactory",
223
+ "EYWAFactory",
224
+ "cryptoFactory",
225
+ "twocryptoFactory",
226
+ "tricryptoFactory",
227
+ "stableNgFactory"
228
+ ]) {
229
+ const f = curve[key];
230
+ if (f?.fetchPools) {
231
+ tasks.push(run(f.fetchPools()));
232
+ }
233
+ }
234
+ await Promise.all(tasks);
226
235
  }
227
236
  async function loadFullCurveSessionForRpc(rpcUrl) {
228
237
  const url = (rpcUrl ?? "").trim();
229
- if (!url) return null;
238
+ if (!url) {
239
+ throw new Error("rpcUrl is required.");
240
+ }
241
+ const cached = curveSessionCache.get(url);
242
+ if (cached && cached.expiresAt > Date.now()) {
243
+ return cached.session;
244
+ }
230
245
  try {
231
246
  const { default: curve } = await import('@curvefi/api');
232
247
  await curve.init("JsonRpc", { url }, {});
233
248
  const wrapped = curve.getNetworkConstants().NATIVE_COIN?.wrappedAddress;
234
249
  if (!curve.hasRouter || !curve.hasRouter()) {
235
- return {
250
+ const session2 = {
236
251
  curve,
237
252
  adj: /* @__PURE__ */ new Map(),
238
253
  swappableNodeKeys: /* @__PURE__ */ new Set(),
239
254
  wrappedNative: wrapped
240
255
  };
256
+ curveSessionCache.set(url, { session: session2, expiresAt: Date.now() + CURVE_SESSION_CACHE_TTL_MS });
257
+ return session2;
241
258
  }
242
259
  await fetchAllCurvePools(curve);
243
260
  const adj = buildCurveLiquidityGraphFromApi(curve);
244
261
  addNativeWethBridge(adj, wrapped);
245
- return {
262
+ const session = {
246
263
  curve,
247
264
  adj,
248
265
  swappableNodeKeys: swappableCurveGraphNodeKeys(adj),
249
266
  wrappedNative: wrapped
250
267
  };
251
- } catch {
252
- return null;
268
+ curveSessionCache.set(url, { session, expiresAt: Date.now() + CURVE_SESSION_CACHE_TTL_MS });
269
+ return session;
270
+ } catch (e) {
271
+ const msg = e instanceof Error ? e.message : String(e);
272
+ throw new Error(`Curve session init failed for RPC: ${msg}`);
253
273
  }
254
274
  }
255
275