@1delta/margin-fetcher 5.0.154 → 5.0.155

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.js CHANGED
@@ -93539,6 +93539,29 @@ var YearnLiquidityAbi = [
93539
93539
  outputs: [{ type: "uint256" }]
93540
93540
  }
93541
93541
  ];
93542
+ var YearnRepairAbi = [
93543
+ {
93544
+ type: "function",
93545
+ name: "asset",
93546
+ stateMutability: "view",
93547
+ inputs: [],
93548
+ outputs: [{ type: "address" }]
93549
+ },
93550
+ {
93551
+ type: "function",
93552
+ name: "pricePerShare",
93553
+ stateMutability: "view",
93554
+ inputs: [],
93555
+ outputs: [{ type: "uint256" }]
93556
+ },
93557
+ {
93558
+ type: "function",
93559
+ name: "decimals",
93560
+ stateMutability: "view",
93561
+ inputs: [],
93562
+ outputs: [{ type: "uint8" }]
93563
+ }
93564
+ ];
93542
93565
  var asBig = (v) => {
93543
93566
  try {
93544
93567
  if (typeof v === "bigint") return v;
@@ -93567,10 +93590,70 @@ var deriveTotalSupply = (totalAssetsRaw, pricePerShareRaw, decimals) => {
93567
93590
  return totalAssetsRaw || "0";
93568
93591
  }
93569
93592
  };
93593
+ var hasUnresolvedToken = (v) => {
93594
+ const a = (v.token?.address ?? "").toLowerCase();
93595
+ return !a || a === ZERO_ADDR;
93596
+ };
93597
+ var hasNoPricePerShare = (v) => (asBig(v.pricePerShare) ?? 0n) === 0n;
93598
+ var repairFromChain = async (chainId, multicallRetry, items, tokenList) => {
93599
+ const broken = items.filter(
93600
+ (v) => v.address && (hasUnresolvedToken(v) || hasNoPricePerShare(v))
93601
+ );
93602
+ if (broken.length === 0) return;
93603
+ const r1Calls = broken.flatMap((v) => [
93604
+ { address: v.address.toLowerCase(), name: "asset", params: [] },
93605
+ { address: v.address.toLowerCase(), name: "pricePerShare", params: [] }
93606
+ ]);
93607
+ const r1 = await multicallRetry({
93608
+ chain: chainId,
93609
+ calls: r1Calls,
93610
+ abi: r1Calls.map(() => YearnRepairAbi),
93611
+ maxRetries: 2,
93612
+ allowFailure: true
93613
+ });
93614
+ const needDecimals = [];
93615
+ broken.forEach((v, i) => {
93616
+ const pps = asBig(r1[i * 2 + 1]);
93617
+ if (hasNoPricePerShare(v) && pps != null && pps > 0n)
93618
+ v.pricePerShare = pps.toString();
93619
+ if (!hasUnresolvedToken(v)) return;
93620
+ const asset = typeof r1[i * 2] === "string" ? r1[i * 2].toLowerCase() : "";
93621
+ if (!asset || asset === ZERO_ADDR) {
93622
+ v.token = null;
93623
+ return;
93624
+ }
93625
+ const meta = tokenList[asset];
93626
+ v.token = {
93627
+ address: asset,
93628
+ symbol: meta?.symbol ?? null,
93629
+ name: meta?.name ?? null,
93630
+ decimals: meta?.decimals ?? null
93631
+ };
93632
+ if (meta?.decimals == null) needDecimals.push({ v, asset });
93633
+ });
93634
+ if (needDecimals.length === 0) return;
93635
+ const r2Calls = needDecimals.map(({ asset }) => ({
93636
+ address: asset,
93637
+ name: "decimals",
93638
+ params: []
93639
+ }));
93640
+ const r2 = await multicallRetry({
93641
+ chain: chainId,
93642
+ calls: r2Calls,
93643
+ abi: r2Calls.map(() => YearnRepairAbi),
93644
+ maxRetries: 2,
93645
+ allowFailure: true
93646
+ });
93647
+ needDecimals.forEach(({ v }, i) => {
93648
+ const d = Number(r2[i]);
93649
+ if (r2[i] == null || !Number.isInteger(d)) v.token = null;
93650
+ else v.token.decimals = d;
93651
+ });
93652
+ };
93570
93653
  function parseVault9(v, chainId, prices, tokenList) {
93571
93654
  const address = (v?.address ?? "").toLowerCase();
93572
93655
  const assetAddr = (v?.token?.address ?? "").toLowerCase();
93573
- if (!address || !assetAddr) return null;
93656
+ if (!address || !assetAddr || assetAddr === ZERO_ADDR) return null;
93574
93657
  const assetMeta = tokenList[assetAddr];
93575
93658
  const decimals = Number(v.decimals ?? 18);
93576
93659
  const assetDecimals = Number(v.token?.decimals ?? assetMeta?.decimals ?? 18);
@@ -93695,6 +93778,10 @@ var attachYearnLiquidity = async (chainId, multicallRetry, out) => {
93695
93778
  var fetchYearnVaults = async (chainId, multicallRetry, prices = {}, tokenList = {}) => {
93696
93779
  if (!hasYearnVaults(chainId)) return {};
93697
93780
  const items = await fetchYearnApiVaults(chainId);
93781
+ try {
93782
+ await repairFromChain(chainId, multicallRetry, items, tokenList);
93783
+ } catch {
93784
+ }
93698
93785
  const out = {};
93699
93786
  for (const item of items) {
93700
93787
  const parsed = parseVault9(item, chainId, prices, tokenList);