@1delta/margin-fetcher 0.0.334 → 0.0.335

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
@@ -21300,20 +21300,25 @@ function convertMidnightMarketsToResponse(raw, chainId, prices = {}, _additional
21300
21300
  const cursor = toBigIntOr0(c.liquidationCursor);
21301
21301
  const liquidationPenalty = cursor > 0n ? midnightLiquidationPenaltyNumber(toBigIntOr0(c.lltv), cursor) : liquidationPenaltyFromLltv(ltv);
21302
21302
  const collUid = createMarketUid(chainId, m, collAddr);
21303
+ const collAsset = tokens[collAddr];
21304
+ const collKey = toOracleKey(collAsset?.assetGroup) || toGenericPriceKey(collAddr, chainId);
21305
+ const collPrice = prices[collKey] ?? 0;
21306
+ const collCapacityUSD = ltv > 0 ? borrowLiquidity * loanPrice / ltv : borrowLiquidity * loanPrice;
21307
+ const collCapacity = collPrice > 0 ? collCapacityUSD / collPrice : 0;
21303
21308
  entry.data[collUid] = {
21304
21309
  marketUid: collUid,
21305
21310
  name: "Collateral " + (tokens[collAddr]?.symbol ?? ""),
21306
21311
  poolId: collAddr,
21307
21312
  underlying: collAddr,
21308
21313
  asset: currencyFor(collAddr, c.decimals, tokens),
21309
- totalDeposits: 0,
21314
+ totalDeposits: collCapacity,
21310
21315
  totalDebtStable: 0,
21311
21316
  totalDebt: 0,
21312
- totalLiquidity: 0,
21317
+ totalLiquidity: collCapacity,
21313
21318
  borrowLiquidity: 0,
21314
- totalLiquidityUSD: 0,
21319
+ totalLiquidityUSD: collCapacityUSD,
21315
21320
  borrowLiquidityUSD: 0,
21316
- totalDepositsUSD: 0,
21321
+ totalDepositsUSD: collCapacityUSD,
21317
21322
  totalDebtStableUSD: 0,
21318
21323
  totalDebtUSD: 0,
21319
21324
  utilization: 0,
@@ -22661,7 +22666,7 @@ function convertRiverMarketsToResponse(raw, chainId, prices = {}, _additionalYie
22661
22666
  }
22662
22667
  return out;
22663
22668
  }
22664
- var READS_PER_POOL = 6;
22669
+ var READS_PER_POOL = 7;
22665
22670
  var READS_PER_MARKET = 2;
22666
22671
  async function fetchTellerMarkets(chainId) {
22667
22672
  const pools = tellerPoolsByChain(chainId);
@@ -22679,7 +22684,12 @@ async function fetchTellerMarkets(chainId) {
22679
22684
  params: [onePrincipal]
22680
22685
  },
22681
22686
  { address: p.pool, name: "getMaxLoanDuration", params: [] },
22682
- { address: p.pool, name: "getMarketId", params: [] }
22687
+ { address: p.pool, name: "getMarketId", params: [] },
22688
+ // ERC-4626 CURRENT principal TVL (V2/V3). `totalPrincipalTokensCommitted`
22689
+ // is a CUMULATIVE lifetime counter, NOT the current balance — using it
22690
+ // overstates deposits by orders of magnitude. `totalAssets` reverts on V1
22691
+ // Smart pools (→ null), where we fall back to the committed counter.
22692
+ { address: p.pool, name: "totalAssets", params: [] }
22683
22693
  ];
22684
22694
  });
22685
22695
  let results = [];
@@ -22719,7 +22729,8 @@ async function fetchTellerMarkets(chainId) {
22719
22729
  minRateBps: num6(base + 2),
22720
22730
  collateralPerPrincipal: big4(base + 3),
22721
22731
  maxLoanDuration: num6(base + 4),
22722
- marketId: big4(base + 5)
22732
+ marketId: big4(base + 5),
22733
+ totalAssets: big4(base + 6)
22723
22734
  };
22724
22735
  });
22725
22736
  const attByMarket = /* @__PURE__ */ new Map();
@@ -22822,7 +22833,10 @@ function convertTellerMarketsToResponse(raw, chainId, prices = {}, _additionalYi
22822
22833
  const principalPrice = priceFor(principalAddr, chainId, tokens, prices);
22823
22834
  const collateralPrice = priceFor(collateralAddr, chainId, tokens, prices);
22824
22835
  const borrowLiquidity = tellerToHuman(p.available, cfg.principalDecimals);
22825
- const totalDeposits = tellerToHuman(p.committed, cfg.principalDecimals);
22836
+ const totalDeposits = tellerToHuman(
22837
+ p.totalAssets ?? p.committed,
22838
+ cfg.principalDecimals
22839
+ );
22826
22840
  const totalDebt = Math.max(0, totalDeposits - borrowLiquidity);
22827
22841
  const utilization = totalDeposits > 0 ? totalDebt / totalDeposits : 0;
22828
22842
  const borrowApr = tellerBpsToPercent(p.minRateBps);
@@ -39711,19 +39725,12 @@ function parseTellerResults(data, meta, context) {
39711
39725
  const principal = meta.principal;
39712
39726
  const collateral = meta.collateral;
39713
39727
  const lenderKey = tellerLenderKey(meta.pool);
39714
- const principalOracleKey = tokenList?.[principal]?.assetGroup ?? `${chainId}-${principal}`;
39715
- const principalUSD = usdPrices[principalOracleKey] ?? usdPrices[principal];
39716
- if (!principalUSD) return entries;
39717
- entries.push({
39718
- asset: principal,
39719
- price: 1,
39720
- priceUSD: principalUSD,
39721
- marketUid: createMarketUid(chainId, lenderKey, principal),
39722
- targetLender: lenderKey,
39723
- description: "Teller principal asset",
39724
- staticBase: true,
39725
- baseAsset: principal
39726
- });
39728
+ const usdOf = (addr) => {
39729
+ const key = tokenList?.[addr]?.assetGroup ?? `${chainId}-${addr}`;
39730
+ return usdPrices[key] ?? usdPrices[addr];
39731
+ };
39732
+ const principalUSD = usdOf(principal);
39733
+ const collateralUSD = usdOf(collateral);
39727
39734
  const rawCollateral = data?.[0];
39728
39735
  if (rawCollateral == null || rawCollateral === "0x") return entries;
39729
39736
  let equivalent;
@@ -39734,17 +39741,48 @@ function parseTellerResults(data, meta, context) {
39734
39741
  }
39735
39742
  if (equivalent <= 0n) return entries;
39736
39743
  const collateralDecimals = meta.collateralDecimals ?? tokenList?.[collateral]?.decimals ?? 18;
39737
- const priceCollateralInPrincipal = 10 ** collateralDecimals / Number(equivalent);
39738
- if (!(priceCollateralInPrincipal > 0)) return entries;
39739
- entries.push({
39740
- asset: collateral,
39741
- price: priceCollateralInPrincipal,
39742
- // raw: collateral price in principal terms
39743
- priceUSD: priceCollateralInPrincipal * principalUSD,
39744
- marketUid: createMarketUid(chainId, lenderKey, collateral),
39745
- targetLender: lenderKey,
39746
- baseAsset: principal
39747
- });
39744
+ const collPerPrincipal = Number(equivalent) / 10 ** collateralDecimals;
39745
+ if (!(collPerPrincipal > 0)) return entries;
39746
+ if (principalUSD) {
39747
+ const collateralPriceInPrincipal = 1 / collPerPrincipal;
39748
+ entries.push({
39749
+ asset: principal,
39750
+ price: 1,
39751
+ priceUSD: principalUSD,
39752
+ marketUid: createMarketUid(chainId, lenderKey, principal),
39753
+ targetLender: lenderKey,
39754
+ description: "Teller principal asset",
39755
+ staticBase: true,
39756
+ baseAsset: principal
39757
+ });
39758
+ entries.push({
39759
+ asset: collateral,
39760
+ price: collateralPriceInPrincipal,
39761
+ priceUSD: collateralPriceInPrincipal * principalUSD,
39762
+ marketUid: createMarketUid(chainId, lenderKey, collateral),
39763
+ targetLender: lenderKey,
39764
+ baseAsset: principal
39765
+ });
39766
+ } else if (collateralUSD) {
39767
+ entries.push({
39768
+ asset: collateral,
39769
+ price: 1,
39770
+ priceUSD: collateralUSD,
39771
+ marketUid: createMarketUid(chainId, lenderKey, collateral),
39772
+ targetLender: lenderKey,
39773
+ description: "Teller collateral asset",
39774
+ staticBase: true,
39775
+ baseAsset: collateral
39776
+ });
39777
+ entries.push({
39778
+ asset: principal,
39779
+ price: collPerPrincipal,
39780
+ priceUSD: collPerPrincipal * collateralUSD,
39781
+ marketUid: createMarketUid(chainId, lenderKey, principal),
39782
+ targetLender: lenderKey,
39783
+ baseAsset: collateral
39784
+ });
39785
+ }
39748
39786
  return entries;
39749
39787
  }
39750
39788
  function getTellerAbi() {