@1delta/margin-fetcher 0.0.338 → 0.0.339

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
@@ -22206,6 +22206,15 @@ function liquityKeyParts(key) {
22206
22206
  return { lender: base, chainId: m[1], collIndex: Number(m[2]) };
22207
22207
  }
22208
22208
  var WAD6 = 1e18;
22209
+ var MAX_PLAUSIBLE_UNIT_USD = 1e7;
22210
+ function liquityCollateralPrice(raw, collDecimals, priceDecimals) {
22211
+ if (raw == null || raw <= 0n) return 0;
22212
+ if (priceDecimals != null) return Number(raw) / 10 ** priceDecimals;
22213
+ const plain = Number(raw) / WAD6;
22214
+ if (collDecimals >= 18 || plain <= MAX_PLAUSIBLE_UNIT_USD) return plain;
22215
+ const adjusted = Number(raw) / 10 ** (36 - collDecimals);
22216
+ return adjusted <= MAX_PLAUSIBLE_UNIT_USD ? adjusted : 0;
22217
+ }
22209
22218
  function toHuman2(raw, decimals) {
22210
22219
  return Number(raw) / 10 ** decimals;
22211
22220
  }
@@ -22237,7 +22246,7 @@ function convertLiquityMarketsToResponse(raw, chainId, prices = {}, _additionalY
22237
22246
  const collSymbol = collToken?.symbol ?? branch.name?.split(" / ").pop() ?? "COLL";
22238
22247
  const marketName = branch.name ?? `${stableSymbol} / ${collSymbol}`;
22239
22248
  const collPriceKey = toOracleKey(collToken?.assetGroup) || toGenericPriceKey(collAddr, chainId);
22240
- const collPrice = (b.collPrice !== null ? Number(b.collPrice) / WAD6 : 0) || (prices[collPriceKey] ?? 0);
22249
+ const collPrice = liquityCollateralPrice(b.collPrice, collDecimals, branch.priceDecimals) || (prices[collPriceKey] ?? 0);
22241
22250
  const entireDebt = b.entireDebt !== null ? toHuman2(b.entireDebt, stableDecimals) : 0;
22242
22251
  const entireColl = b.entireColl !== null ? toHuman2(b.entireColl, collDecimals) : 0;
22243
22252
  const spDeposits = b.spDeposits !== null ? toHuman2(b.spDeposits, stableDecimals) : 0;
@@ -39787,7 +39796,6 @@ var termFetcher = {
39787
39796
  parse: parseTermResults,
39788
39797
  getAbi: getTermAbi
39789
39798
  };
39790
- var SANITY_MAX_USD = 1e9;
39791
39799
  function getLiquityCalls(chainId) {
39792
39800
  const results = [];
39793
39801
  for (const lender of LIQUITY_FAMILY_LENDERS) {
@@ -39806,6 +39814,8 @@ function getLiquityCalls(chainId) {
39806
39814
  chainId,
39807
39815
  collIndex: b.collIndex,
39808
39816
  collToken: b.collToken.toLowerCase(),
39817
+ collDecimals: b.collDecimals,
39818
+ priceDecimals: b.priceDecimals,
39809
39819
  debtToken: debtToken?.toLowerCase()
39810
39820
  },
39811
39821
  lender: liquityLenderKey(lender, chainId, b.collIndex)
@@ -39820,8 +39830,12 @@ function parseLiquityResults(data, meta, context) {
39820
39830
  const entries = [];
39821
39831
  const raw = data?.[0];
39822
39832
  const price2 = typeof raw === "bigint" ? raw : raw != null && raw !== "0x" ? BigInt(raw) : 0n;
39823
- const collUSD = Number(price2) / 1e18;
39824
- if (collUSD > 0 && collUSD < SANITY_MAX_USD) {
39833
+ const collUSD = liquityCollateralPrice(
39834
+ price2,
39835
+ meta.collDecimals,
39836
+ meta.priceDecimals
39837
+ );
39838
+ if (collUSD > 0) {
39825
39839
  entries.push({
39826
39840
  asset: meta.collToken,
39827
39841
  price: collUSD,