@1delta/margin-fetcher 5.0.97 → 5.0.99

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.d.ts CHANGED
@@ -11829,6 +11829,18 @@ interface GetVaultPublicDataAllOptions {
11829
11829
  interface VaultPublicDataResult {
11830
11830
  data: VaultPublicDataAll;
11831
11831
  lookup: Map<string, VaultLookupEntry>;
11832
+ /**
11833
+ * Providers whose fetch threw (and whose rows are therefore absent from
11834
+ * `data`). A provider returning zero rows without throwing is NOT listed —
11835
+ * absence here plus absence in `data` means "nothing deployed", while
11836
+ * presence here means "the source broke". Callers that log "providers ok"
11837
+ * must check this, or an upstream API change reads as a healthy sweep
11838
+ * (the Morpho rewards→allRewards rename served exactly that lie).
11839
+ */
11840
+ failed: Array<{
11841
+ provider: VaultProvider;
11842
+ error: string;
11843
+ }>;
11832
11844
  }
11833
11845
  /**
11834
11846
  * Universal vault fetcher — the vaults-side analogue of
package/dist/index.js CHANGED
@@ -50498,8 +50498,7 @@ var readVaults = async () => {
50498
50498
  (Date.now() / 1e3 - VAULT_EPOCH_ANCHOR.startTime) / NOMINAL_EPOCH_SECONDS
50499
50499
  );
50500
50500
  const probe = [];
50501
- for (let e = estimate - 6; e <= estimate + 6; e++) {
50502
- if (e - WINDOW >= 0) probe.push(e - WINDOW);
50501
+ for (let e = estimate - 34; e <= estimate + 6; e++) {
50503
50502
  if (e >= 0) probe.push(e);
50504
50503
  }
50505
50504
  const epochs = [...new Set(probe)].sort((a, b) => a - b);
@@ -50516,7 +50515,6 @@ var readVaults = async () => {
50516
50515
  allowFailure: true
50517
50516
  });
50518
50517
  const aprs = {};
50519
- const cadences = [];
50520
50518
  BFUSD_VAULTS.forEach(({ address }, vi) => {
50521
50519
  const rows = /* @__PURE__ */ new Map();
50522
50520
  epochs.forEach((e, i) => {
@@ -50530,18 +50528,28 @@ var readVaults = async () => {
50530
50528
  if (!now || !then) return;
50531
50529
  const elapsed = Number(now.startTime - then.startTime);
50532
50530
  if (elapsed <= 0) return;
50533
- cadences.push(elapsed / WINDOW);
50534
50531
  const growth = Number(now.startRatio) / Number(then.startRatio) - 1;
50535
50532
  const apr = 100 * SECONDS_PER_YEAR13 * growth / elapsed;
50536
50533
  if (plausible(apr)) {
50537
50534
  aprs[bitfiYieldKey(Chain.ETHEREUM_MAINNET, address)] = apr;
50538
50535
  }
50539
50536
  });
50540
- const secondsPerEpoch = cadences.length ? cadences.reduce((a, b) => a + b, 0) / cadences.length : void 0;
50541
- const usable = secondsPerEpoch !== void 0 && secondsPerEpoch > 43200 && secondsPerEpoch < 259200;
50542
- return { aprs, secondsPerEpoch: usable ? secondsPerEpoch : void 0 };
50537
+ return { aprs };
50543
50538
  };
50544
- var readBfbtc = async (chain, address, secondsPerEpoch) => {
50539
+ var BITFI_APR_URL = "https://api-ext.bitfi.one/api/v1/external/apr";
50540
+ var fetchBitfiApiApr = async () => {
50541
+ try {
50542
+ const res = await fetch(BITFI_APR_URL, {
50543
+ headers: { accept: "application/json" }
50544
+ }).then((r) => r.json());
50545
+ const frac = Number(res?.data?.["7e"]?.apr);
50546
+ const apr = frac * 100;
50547
+ return plausible(apr) && apr > 0 ? apr : void 0;
50548
+ } catch {
50549
+ return void 0;
50550
+ }
50551
+ };
50552
+ var readBfbtc = async (chain, address, secondsPerEpoch, frozenFallbackApr) => {
50545
50553
  const [epochRaw] = await multicallRetryUniversal({
50546
50554
  chain,
50547
50555
  abi: RATIO_ABI,
@@ -50562,6 +50570,10 @@ var readBfbtc = async (chain, address, secondsPerEpoch) => {
50562
50570
  });
50563
50571
  if (typeof nowRaw !== "bigint" || typeof thenRaw !== "bigint") return {};
50564
50572
  if (nowRaw <= 0n || thenRaw <= 0n) return {};
50573
+ if (nowRaw === thenRaw) {
50574
+ const apiApr = await frozenFallbackApr();
50575
+ return apiApr !== void 0 ? { [bitfiYieldKey(chain, address)]: apiApr } : { [bitfiYieldKey(chain, address)]: 0 };
50576
+ }
50565
50577
  const growth = Number(thenRaw) / Number(nowRaw) - 1;
50566
50578
  const apr = 100 * SECONDS_PER_YEAR13 * growth / (WINDOW * secondsPerEpoch);
50567
50579
  return plausible(apr) ? { [bitfiYieldKey(chain, address)]: apr } : {};
@@ -50569,11 +50581,13 @@ var readBfbtc = async (chain, address, secondsPerEpoch) => {
50569
50581
  var bitfiFetcher = {
50570
50582
  label: "BITFI",
50571
50583
  fetch: async () => {
50572
- const { aprs, secondsPerEpoch } = await readVaults();
50573
- const clock = secondsPerEpoch ?? NOMINAL_EPOCH_SECONDS;
50584
+ const { aprs } = await readVaults();
50585
+ const clock = NOMINAL_EPOCH_SECONDS;
50586
+ let apiApr;
50587
+ const frozenFallbackApr = () => apiApr ??= fetchBitfiApiApr();
50574
50588
  const perChain = await Promise.all(
50575
50589
  BFBTC_DEPLOYMENTS.map(
50576
- ({ chain, address }) => readBfbtc(chain, address, clock).catch(() => ({}))
50590
+ ({ chain, address }) => readBfbtc(chain, address, clock, frozenFallbackApr).catch(() => ({}))
50577
50591
  )
50578
50592
  );
50579
50593
  const out = { ...aprs };
@@ -62694,7 +62708,7 @@ var MORPHO_SHARE_DECIMALS = 18;
62694
62708
  var MORPHO_API_URL = "https://blue-api.morpho.org/graphql";
62695
62709
  var PAGE_SIZE2 = 200;
62696
62710
  var MIN_TOTAL_ASSETS_USD = 100;
62697
- var vaultsQuery = (first, skip, chainId) => `
62711
+ var vaultsQuery = (first, skip, chainId, tier = "decorated") => `
62698
62712
  query GetVaults {
62699
62713
  vaults(
62700
62714
  first: ${first},
@@ -62706,8 +62720,7 @@ query GetVaults {
62706
62720
  items {
62707
62721
  address
62708
62722
  symbol
62709
- name
62710
- whitelisted: listed
62723
+ name${tier === "decorated" ? "\n whitelisted: listed" : ""}
62711
62724
  asset {
62712
62725
  address
62713
62726
  name
@@ -62729,29 +62742,31 @@ query GetVaults {
62729
62742
  timelock
62730
62743
  owner
62731
62744
  curator
62732
- guardian
62745
+ guardian${tier === "decorated" ? `
62733
62746
  curators {
62734
62747
  id
62735
62748
  name
62736
62749
  image
62737
62750
  verified
62738
62751
  }
62739
- rewards {
62752
+ rewards: allRewards {
62740
62753
  supplyApr
62741
62754
  asset {
62742
62755
  address
62743
62756
  }
62744
- }
62757
+ }` : ""}
62745
62758
  }
62746
62759
  }
62747
62760
  }
62748
62761
  }
62749
62762
  `;
62750
- async function fetchPage(chainId, first, skip) {
62763
+ var isSchemaFieldError = (errors) => errors.some((e) => /cannot query field/i.test(e?.message ?? ""));
62764
+ var decoratedTierBroken = false;
62765
+ async function runQuery(chainId, first, skip, tier) {
62751
62766
  const response = await fetch(MORPHO_API_URL, {
62752
62767
  method: "POST",
62753
62768
  headers: { "Content-Type": "application/json" },
62754
- body: JSON.stringify({ query: vaultsQuery(first, skip, chainId) })
62769
+ body: JSON.stringify({ query: vaultsQuery(first, skip, chainId, tier) })
62755
62770
  });
62756
62771
  if (!response.ok) {
62757
62772
  throw new Error(
@@ -62760,11 +62775,31 @@ async function fetchPage(chainId, first, skip) {
62760
62775
  }
62761
62776
  const json = await response.json();
62762
62777
  if (json?.errors?.length) {
62778
+ return { items: [], errors: json.errors };
62779
+ }
62780
+ return { items: json?.data?.vaults?.items ?? [] };
62781
+ }
62782
+ async function fetchPage(chainId, first, skip) {
62783
+ if (!decoratedTierBroken) {
62784
+ const full = await runQuery(chainId, first, skip, "decorated");
62785
+ if (!full.errors) return full.items;
62786
+ if (!isSchemaFieldError(full.errors)) {
62787
+ throw new Error(
62788
+ `Morpho vaults API GraphQL error: ${full.errors.map((e) => e?.message).join("; ")}`
62789
+ );
62790
+ }
62791
+ decoratedTierBroken = true;
62792
+ console.error(
62793
+ `[morpho-vaults] API schema drift \u2014 decorated query rejected, serving core fields only (rewardsRate=0, curators dropped) until the query is updated: ${full.errors.map((e) => e?.message).join("; ")}`
62794
+ );
62795
+ }
62796
+ const core = await runQuery(chainId, first, skip, "core");
62797
+ if (core.errors) {
62763
62798
  throw new Error(
62764
- `Morpho vaults API GraphQL error: ${json.errors.map((e) => e?.message).join("; ")}`
62799
+ `Morpho vaults API GraphQL error (core query): ${core.errors.map((e) => e?.message).join("; ")}`
62765
62800
  );
62766
62801
  }
62767
- return json?.data?.vaults?.items ?? [];
62802
+ return core.items;
62768
62803
  }
62769
62804
  var parseCurators = (curators) => {
62770
62805
  if (!curators?.length) return void 0;
@@ -79441,7 +79476,10 @@ function stampVaultTermSheets(data, chainId) {
79441
79476
  stampBag(data.hypercore, "hypercore");
79442
79477
  stampBag(data.gmx, "gmx");
79443
79478
  }
79479
+
79480
+ // src/vaults/fetchVaultsAll.ts
79444
79481
  var warn8 = (...args) => {
79482
+ console.error(...args);
79445
79483
  };
79446
79484
  var VAULT_PROVIDERS = [
79447
79485
  "fluid",
@@ -79465,18 +79503,23 @@ var VAULT_PROVIDERS = [
79465
79503
  var HYPERCORE_PROVIDER_CHAIN = "999";
79466
79504
  var getVaultPublicDataAll = async (chainId, providers, multicallRetry, prices = {}, tokenList = {}, options) => {
79467
79505
  const requested = new Set(providers);
79468
- if (requested.size === 0) return { data: {}, lookup: /* @__PURE__ */ new Map() };
79506
+ if (requested.size === 0) return { data: {}, lookup: /* @__PURE__ */ new Map(), failed: [] };
79469
79507
  const tasks = [];
79470
79508
  const out = {};
79509
+ const failed = [];
79510
+ const fail = (provider, e) => {
79511
+ failed.push({ provider, error: String(e?.message ?? e) });
79512
+ warn8(
79513
+ `[vaults] ${provider} fetch failed for chain ${chainId}:`,
79514
+ e?.message ?? e
79515
+ );
79516
+ };
79471
79517
  if (requested.has("fluid")) {
79472
79518
  tasks.push(
79473
79519
  fetchFluidFTokens(chainId, multicallRetry, prices, tokenList).then((res) => {
79474
79520
  out.fluid = res;
79475
79521
  }).catch((e) => {
79476
- warn8(
79477
- `[vaults] fluid fetch failed for chain ${chainId}:`,
79478
- e?.message ?? e
79479
- );
79522
+ fail("fluid", e);
79480
79523
  })
79481
79524
  );
79482
79525
  }
@@ -79485,10 +79528,7 @@ var getVaultPublicDataAll = async (chainId, providers, multicallRetry, prices =
79485
79528
  fetchGearboxV3Pools(chainId, multicallRetry, prices, tokenList).then((res) => {
79486
79529
  out.gearbox = res;
79487
79530
  }).catch((e) => {
79488
- warn8(
79489
- `[vaults] gearbox fetch failed for chain ${chainId}:`,
79490
- e?.message ?? e
79491
- );
79531
+ fail("gearbox", e);
79492
79532
  })
79493
79533
  );
79494
79534
  }
@@ -79497,10 +79537,7 @@ var getVaultPublicDataAll = async (chainId, providers, multicallRetry, prices =
79497
79537
  fetchMorphoVaults(chainId, multicallRetry, prices, tokenList).then((res) => {
79498
79538
  out.morpho = res;
79499
79539
  }).catch((e) => {
79500
- warn8(
79501
- `[vaults] morpho fetch failed for chain ${chainId}:`,
79502
- e?.message ?? e
79503
- );
79540
+ fail("morpho", e);
79504
79541
  })
79505
79542
  );
79506
79543
  }
@@ -79509,10 +79546,7 @@ var getVaultPublicDataAll = async (chainId, providers, multicallRetry, prices =
79509
79546
  fetchListaVaultsFromChain(chainId, multicallRetry, prices, tokenList).then((res) => {
79510
79547
  out.lista = res;
79511
79548
  }).catch((e) => {
79512
- warn8(
79513
- `[vaults] lista fetch failed for chain ${chainId}:`,
79514
- e?.message ?? e
79515
- );
79549
+ fail("lista", e);
79516
79550
  })
79517
79551
  );
79518
79552
  }
@@ -79524,10 +79558,7 @@ var getVaultPublicDataAll = async (chainId, providers, multicallRetry, prices =
79524
79558
  }).then((res) => {
79525
79559
  out.silo = res;
79526
79560
  }).catch((e) => {
79527
- warn8(
79528
- `[vaults] silo fetch failed for chain ${chainId}:`,
79529
- e?.message ?? e
79530
- );
79561
+ fail("silo", e);
79531
79562
  })
79532
79563
  );
79533
79564
  }
@@ -79536,10 +79567,7 @@ var getVaultPublicDataAll = async (chainId, providers, multicallRetry, prices =
79536
79567
  fetchEulerEarnVaults(chainId, prices, tokenList, multicallRetry).then((res) => {
79537
79568
  out["euler-earn"] = res;
79538
79569
  }).catch((e) => {
79539
- warn8(
79540
- `[vaults] euler-earn fetch failed for chain ${chainId}:`,
79541
- e?.message ?? e
79542
- );
79570
+ fail("euler-earn", e);
79543
79571
  })
79544
79572
  );
79545
79573
  }
@@ -79548,10 +79576,7 @@ var getVaultPublicDataAll = async (chainId, providers, multicallRetry, prices =
79548
79576
  fetchTermMaxVaults(chainId, multicallRetry, prices, tokenList).then((res) => {
79549
79577
  out.termmax = res;
79550
79578
  }).catch((e) => {
79551
- warn8(
79552
- `[vaults] termmax fetch failed for chain ${chainId}:`,
79553
- e?.message ?? e
79554
- );
79579
+ fail("termmax", e);
79555
79580
  })
79556
79581
  );
79557
79582
  }
@@ -79560,10 +79585,7 @@ var getVaultPublicDataAll = async (chainId, providers, multicallRetry, prices =
79560
79585
  fetchLstShareTokens(chainId, multicallRetry, prices, tokenList).then((res) => {
79561
79586
  out.lst = res;
79562
79587
  }).catch((e) => {
79563
- warn8(
79564
- `[vaults] lst fetch failed for chain ${chainId}:`,
79565
- e?.message ?? e
79566
- );
79588
+ fail("lst", e);
79567
79589
  })
79568
79590
  );
79569
79591
  }
@@ -79572,10 +79594,7 @@ var getVaultPublicDataAll = async (chainId, providers, multicallRetry, prices =
79572
79594
  fetchSavingsVaults(chainId, multicallRetry, prices, tokenList).then((res) => {
79573
79595
  out.savings = res;
79574
79596
  }).catch((e) => {
79575
- warn8(
79576
- `[vaults] savings fetch failed for chain ${chainId}:`,
79577
- e?.message ?? e
79578
- );
79597
+ fail("savings", e);
79579
79598
  })
79580
79599
  );
79581
79600
  }
@@ -79584,10 +79603,7 @@ var getVaultPublicDataAll = async (chainId, providers, multicallRetry, prices =
79584
79603
  fetchLagoonVaults(chainId, prices, tokenList).then((res) => {
79585
79604
  out.lagoon = res;
79586
79605
  }).catch((e) => {
79587
- warn8(
79588
- `[vaults] lagoon fetch failed for chain ${chainId}:`,
79589
- e?.message ?? e
79590
- );
79606
+ fail("lagoon", e);
79591
79607
  })
79592
79608
  );
79593
79609
  }
@@ -79596,10 +79612,7 @@ var getVaultPublicDataAll = async (chainId, providers, multicallRetry, prices =
79596
79612
  fetchAaveEarnVaults(chainId, multicallRetry, prices, tokenList).then((res) => {
79597
79613
  out["aave-earn"] = res;
79598
79614
  }).catch((e) => {
79599
- warn8(
79600
- `[vaults] aave-earn fetch failed for chain ${chainId}:`,
79601
- e?.message ?? e
79602
- );
79615
+ fail("aave-earn", e);
79603
79616
  })
79604
79617
  );
79605
79618
  }
@@ -79608,10 +79621,7 @@ var getVaultPublicDataAll = async (chainId, providers, multicallRetry, prices =
79608
79621
  fetchUpshiftVaults(chainId, prices, tokenList).then((res) => {
79609
79622
  out.upshift = res;
79610
79623
  }).catch((e) => {
79611
- warn8(
79612
- `[vaults] upshift fetch failed for chain ${chainId}:`,
79613
- e?.message ?? e
79614
- );
79624
+ fail("upshift", e);
79615
79625
  })
79616
79626
  );
79617
79627
  }
@@ -79620,10 +79630,7 @@ var getVaultPublicDataAll = async (chainId, providers, multicallRetry, prices =
79620
79630
  fetchYearnVaults(chainId, multicallRetry, prices, tokenList).then((res) => {
79621
79631
  out.yearn = res;
79622
79632
  }).catch((e) => {
79623
- warn8(
79624
- `[vaults] yearn fetch failed for chain ${chainId}:`,
79625
- e?.message ?? e
79626
- );
79633
+ fail("yearn", e);
79627
79634
  })
79628
79635
  );
79629
79636
  }
@@ -79632,10 +79639,7 @@ var getVaultPublicDataAll = async (chainId, providers, multicallRetry, prices =
79632
79639
  fetchHypercoreVaults().then((res) => {
79633
79640
  out.hypercore = res;
79634
79641
  }).catch((e) => {
79635
- warn8(
79636
- `[vaults] hypercore fetch failed for chain ${chainId}:`,
79637
- e?.message ?? e
79638
- );
79642
+ fail("hypercore", e);
79639
79643
  })
79640
79644
  );
79641
79645
  }
@@ -79646,10 +79650,7 @@ var getVaultPublicDataAll = async (chainId, providers, multicallRetry, prices =
79646
79650
  }).then((res) => {
79647
79651
  out.pendle = res;
79648
79652
  }).catch((e) => {
79649
- warn8(
79650
- `[vaults] pendle fetch failed for chain ${chainId}:`,
79651
- e?.message ?? e
79652
- );
79653
+ fail("pendle", e);
79653
79654
  })
79654
79655
  );
79655
79656
  }
@@ -79660,10 +79661,7 @@ var getVaultPublicDataAll = async (chainId, providers, multicallRetry, prices =
79660
79661
  }).then((res) => {
79661
79662
  out.spectra = res;
79662
79663
  }).catch((e) => {
79663
- warn8(
79664
- `[vaults] spectra fetch failed for chain ${chainId}:`,
79665
- e?.message ?? e
79666
- );
79664
+ fail("spectra", e);
79667
79665
  })
79668
79666
  );
79669
79667
  }
@@ -79672,10 +79670,7 @@ var getVaultPublicDataAll = async (chainId, providers, multicallRetry, prices =
79672
79670
  fetchGmxVaults(chainId, multicallRetry).then((res) => {
79673
79671
  out.gmx = res;
79674
79672
  }).catch((e) => {
79675
- warn8(
79676
- `[vaults] gmx fetch failed for chain ${chainId}:`,
79677
- e?.message ?? e
79678
- );
79673
+ fail("gmx", e);
79679
79674
  })
79680
79675
  );
79681
79676
  tasks.push(
@@ -79698,7 +79693,7 @@ var getVaultPublicDataAll = async (chainId, providers, multicallRetry, prices =
79698
79693
  await Promise.all(tasks);
79699
79694
  stampVaultClassification(out, chainId, tokenList);
79700
79695
  stampVaultTermSheets(out, chainId);
79701
- return { data: out, lookup: buildVaultLookup(out) };
79696
+ return { data: out, lookup: buildVaultLookup(out), failed };
79702
79697
  };
79703
79698
 
79704
79699
  // src/vaults/interfaceKind.ts