@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.
package/dist/index.cjs CHANGED
@@ -1477,44 +1477,64 @@ function swappableCurveGraphNodeKeys(adj) {
1477
1477
  }
1478
1478
 
1479
1479
  // src/protocols/evm/curve-dao/apiSession.ts
1480
+ var CURVE_SESSION_CACHE_TTL_MS = 5 * 60 * 1e3;
1481
+ var curveSessionCache = /* @__PURE__ */ new Map();
1480
1482
  async function fetchAllCurvePools(curve) {
1481
1483
  const run = (p) => p.catch(() => void 0);
1482
- await Promise.all([
1483
- run(curve.factory.fetchPools()),
1484
- run(curve.crvUSDFactory.fetchPools()),
1485
- run(curve.EYWAFactory.fetchPools()),
1486
- run(curve.cryptoFactory.fetchPools()),
1487
- run(curve.twocryptoFactory.fetchPools()),
1488
- run(curve.tricryptoFactory.fetchPools()),
1489
- run(curve.stableNgFactory.fetchPools())
1490
- ]);
1484
+ const tasks = [];
1485
+ for (const key of [
1486
+ "factory",
1487
+ "crvUSDFactory",
1488
+ "EYWAFactory",
1489
+ "cryptoFactory",
1490
+ "twocryptoFactory",
1491
+ "tricryptoFactory",
1492
+ "stableNgFactory"
1493
+ ]) {
1494
+ const f = curve[key];
1495
+ if (f?.fetchPools) {
1496
+ tasks.push(run(f.fetchPools()));
1497
+ }
1498
+ }
1499
+ await Promise.all(tasks);
1491
1500
  }
1492
1501
  async function loadFullCurveSessionForRpc(rpcUrl) {
1493
1502
  const url = (rpcUrl ?? "").trim();
1494
- if (!url) return null;
1503
+ if (!url) {
1504
+ throw new Error("rpcUrl is required.");
1505
+ }
1506
+ const cached = curveSessionCache.get(url);
1507
+ if (cached && cached.expiresAt > Date.now()) {
1508
+ return cached.session;
1509
+ }
1495
1510
  try {
1496
1511
  const { default: curve } = await import('@curvefi/api');
1497
1512
  await curve.init("JsonRpc", { url }, {});
1498
1513
  const wrapped = curve.getNetworkConstants().NATIVE_COIN?.wrappedAddress;
1499
1514
  if (!curve.hasRouter || !curve.hasRouter()) {
1500
- return {
1515
+ const session2 = {
1501
1516
  curve,
1502
1517
  adj: /* @__PURE__ */ new Map(),
1503
1518
  swappableNodeKeys: /* @__PURE__ */ new Set(),
1504
1519
  wrappedNative: wrapped
1505
1520
  };
1521
+ curveSessionCache.set(url, { session: session2, expiresAt: Date.now() + CURVE_SESSION_CACHE_TTL_MS });
1522
+ return session2;
1506
1523
  }
1507
1524
  await fetchAllCurvePools(curve);
1508
1525
  const adj = buildCurveLiquidityGraphFromApi(curve);
1509
1526
  addNativeWethBridge(adj, wrapped);
1510
- return {
1527
+ const session = {
1511
1528
  curve,
1512
1529
  adj,
1513
1530
  swappableNodeKeys: swappableCurveGraphNodeKeys(adj),
1514
1531
  wrappedNative: wrapped
1515
1532
  };
1516
- } catch {
1517
- return null;
1533
+ curveSessionCache.set(url, { session, expiresAt: Date.now() + CURVE_SESSION_CACHE_TTL_MS });
1534
+ return session;
1535
+ } catch (e) {
1536
+ const msg = e instanceof Error ? e.message : String(e);
1537
+ throw new Error(`Curve session init failed for RPC: ${msg}`);
1518
1538
  }
1519
1539
  }
1520
1540