@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/agent/catalog.cjs +34 -14
- package/dist/agent/catalog.cjs.map +1 -1
- package/dist/agent/catalog.js +34 -14
- package/dist/agent/catalog.js.map +1 -1
- package/dist/index.cjs +34 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +34 -14
- package/dist/index.js.map +1 -1
- package/dist/protocols/evm/curve-dao/index.cjs +38 -17
- package/dist/protocols/evm/curve-dao/index.cjs.map +1 -1
- package/dist/protocols/evm/curve-dao/index.d.ts +9 -9
- package/dist/protocols/evm/curve-dao/index.js +38 -17
- package/dist/protocols/evm/curve-dao/index.js.map +1 -1
- package/package.json +3 -3
package/dist/agent/catalog.js
CHANGED
|
@@ -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
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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)
|
|
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
|
-
|
|
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
|
-
|
|
262
|
+
const session = {
|
|
246
263
|
curve,
|
|
247
264
|
adj,
|
|
248
265
|
swappableNodeKeys: swappableCurveGraphNodeKeys(adj),
|
|
249
266
|
wrappedNative: wrapped
|
|
250
267
|
};
|
|
251
|
-
|
|
252
|
-
return
|
|
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
|
|