@continuumdao/ctm-mpc-defi 0.2.62 → 0.2.63

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.
@@ -1097,10 +1097,24 @@ var REGISTRIES = [
1097
1097
  "factory-twocrypto",
1098
1098
  "factory-tricrypto"
1099
1099
  ];
1100
+ function apyNumbers(n) {
1101
+ const ok = (x) => typeof x === "number" && Number.isFinite(x) && x >= 0 && x < 1e5;
1102
+ if (ok(n)) return [n];
1103
+ if (Array.isArray(n)) return n.filter(ok);
1104
+ return [];
1105
+ }
1106
+ function formatApyNumber(n) {
1107
+ if (n > 0 && n < 1e-4) return n.toFixed(6);
1108
+ if (n > 0 && n < 0.01) return n.toFixed(4);
1109
+ return n.toFixed(2);
1110
+ }
1100
1111
  function formatApy(n) {
1101
- if (typeof n === "number" && Number.isFinite(n) && n >= 0) return `${n.toFixed(2)}%`;
1102
- if (Array.isArray(n) && typeof n[0] === "number" && Number.isFinite(n[0])) return `${n[0].toFixed(2)}%`;
1103
- return null;
1112
+ const nums = apyNumbers(n);
1113
+ if (!nums.length) return null;
1114
+ const lo = Math.min(...nums);
1115
+ const hi = Math.max(...nums);
1116
+ if (Math.abs(lo - hi) < 1e-9) return `${formatApyNumber(lo)}%`;
1117
+ return `${formatApyNumber(lo)}\u2013${formatApyNumber(hi)}%`;
1104
1118
  }
1105
1119
  function pickApy(pool, keys) {
1106
1120
  for (const k of keys) {
@@ -1174,11 +1188,45 @@ async function curveDaoFetchImportantPools(args) {
1174
1188
  notes: `Official api.curve.fi catalog, TVL-ranked, hard cap ${CURVE_IMPORTANT_POOL_CAP}. Dead/zero-TVL dropped. Do not call fetchAllCurvePools or invent a list-all-pools tool. gauge_crv_apy requires staking LP in the gauge.`
1175
1189
  };
1176
1190
  }
1191
+ async function fetchCurveSubgraphApyByPool(slug) {
1192
+ const out = /* @__PURE__ */ new Map();
1193
+ try {
1194
+ const res = await fetch(`https://api.curve.finance/api/getSubgraphData/${slug}`, { cache: "no-store" });
1195
+ if (!res.ok) return out;
1196
+ const j = await res.json();
1197
+ for (const row of j.data?.poolList ?? []) {
1198
+ const addr = String(row.address ?? "").trim().toLowerCase();
1199
+ if (!addr) continue;
1200
+ const daily = typeof row.latestDailyApy === "number" && Number.isFinite(row.latestDailyApy) ? row.latestDailyApy : null;
1201
+ const weekly = typeof row.latestWeeklyApy === "number" && Number.isFinite(row.latestWeeklyApy) ? row.latestWeeklyApy : null;
1202
+ out.set(addr, { daily, weekly });
1203
+ }
1204
+ } catch {
1205
+ return out;
1206
+ }
1207
+ return out;
1208
+ }
1209
+ function withSubgraphBaseApy(pool, apy) {
1210
+ if (pool.baseApy) return pool;
1211
+ const hit = apy.get(pool.address.toLowerCase());
1212
+ if (!hit) return pool;
1213
+ const label = formatApy(hit.daily) ?? formatApy(hit.weekly);
1214
+ if (!label) return pool;
1215
+ return { ...pool, baseApy: label };
1216
+ }
1177
1217
  async function curveDaoFetchLpYields(args) {
1178
- const { pools, notes } = await curveDaoFetchImportantPools({ chainId: args.chainId, query: args.query });
1218
+ const slug = CHAIN_SLUG[args.chainId];
1219
+ const [listed, apyByPool] = await Promise.all([
1220
+ curveDaoFetchImportantPools({ chainId: args.chainId, query: args.query }),
1221
+ slug ? fetchCurveSubgraphApyByPool(slug) : Promise.resolve(/* @__PURE__ */ new Map())
1222
+ ]);
1179
1223
  const poolFilter = (args.pool ?? "").trim().toLowerCase();
1180
- const filtered = poolFilter ? pools.filter((p) => p.address.toLowerCase() === poolFilter || p.id.toLowerCase() === poolFilter) : pools;
1181
- return { chainId: args.chainId, pools: filtered, notes };
1224
+ const filtered = (poolFilter ? listed.pools.filter((p) => p.address.toLowerCase() === poolFilter || p.id.toLowerCase() === poolFilter) : listed.pools).map((p) => withSubgraphBaseApy(p, apyByPool));
1225
+ return {
1226
+ chainId: args.chainId,
1227
+ pools: filtered,
1228
+ notes: `${listed.notes} baseApy is getSubgraphData latestDailyApy (else latestWeeklyApy), in percent. gaugeCrvApy is the unboosted\u2013boosted range from getPools; staking the LP in the gauge is required for that CRV yield.`
1229
+ };
1182
1230
  }
1183
1231
  var erc20ApproveAbi = viem.parseAbi(["function approve(address spender, uint256 amount) returns (bool)"]);
1184
1232
  var erc20AllowanceAbi = viem.parseAbi([