@1delta/margin-fetcher 0.0.405 → 0.0.406

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
@@ -3183,6 +3183,14 @@ interface TermMaxMarketConfig {
3183
3183
  debtDecimals: number;
3184
3184
  collateral: string;
3185
3185
  collateralDecimals: number;
3186
+ /**
3187
+ * False when decimals could not be resolved from the payload and the 18-dec
3188
+ * default was used. Exists because reading the wrong `assetConfigs` field
3189
+ * names once made EVERY 6-dec stablecoin market silently 10^12 out; a
3190
+ * consumer that cares about exactness should treat `false` as suspect.
3191
+ */
3192
+ debtDecimalsResolved?: boolean;
3193
+ collateralDecimalsResolved?: boolean;
3186
3194
  /** Display symbol, e.g. `USDC/PT-sUSDE-13AUG2026@16AUG2026`. */
3187
3195
  symbol?: string;
3188
3196
  /** Unix seconds. */
package/dist/index.js CHANGED
@@ -23068,9 +23068,13 @@ function parseMarket(raw, assetDecimals) {
23068
23068
  xt: lower(c.xtAddr),
23069
23069
  gt: lower(c.gtAddr),
23070
23070
  debtToken,
23071
+ // A missing entry means the payload changed shape — fall back to 18 so the
23072
+ // row still renders, but flag it so it is visible rather than silent.
23071
23073
  debtDecimals: assetDecimals.get(debtToken) ?? 18,
23074
+ debtDecimalsResolved: assetDecimals.has(debtToken),
23072
23075
  collateral,
23073
23076
  collateralDecimals: assetDecimals.get(collateral) ?? 18,
23077
+ collateralDecimalsResolved: assetDecimals.has(collateral),
23074
23078
  symbol: raw.symbol,
23075
23079
  maturity: toUnix(raw.maturity),
23076
23080
  maxLtv: String(raw.maxLtv ?? "0"),
@@ -23170,8 +23174,8 @@ var TermMaxApiSource = class {
23170
23174
  if (!data) return null;
23171
23175
  const assetDecimals = /* @__PURE__ */ new Map();
23172
23176
  for (const a of Array.isArray(data.assetConfigs) ? data.assetConfigs : []) {
23173
- const addr2 = lower(a?.assetAddress);
23174
- const dec = Number(a?.assetDecimals);
23177
+ const addr2 = lower(a?.contractAddress ?? a?.assetAddress);
23178
+ const dec = Number(a?.decimals ?? a?.assetDecimals);
23175
23179
  if (addr2 && Number.isFinite(dec)) assetDecimals.set(addr2, dec);
23176
23180
  }
23177
23181
  const markets = [];
@@ -43370,6 +43374,76 @@ var riverFetcher = {
43370
43374
  parse: parseRiverResults,
43371
43375
  getAbi: getRiverAbi
43372
43376
  };
43377
+ function getInverseCalls(chainId) {
43378
+ const results = [];
43379
+ for (const lender of inverseLendersByChain(chainId)) {
43380
+ const config = inverseConfigFor(lender, chainId);
43381
+ const markets = inverseChainData(lender, chainId)?.markets ?? [];
43382
+ if (!config?.oracle || markets.length === 0) continue;
43383
+ for (const m of markets) {
43384
+ if (!m.address || !m.collToken) continue;
43385
+ const calls = [
43386
+ {
43387
+ address: config.oracle,
43388
+ name: "viewPrice",
43389
+ params: [m.collToken, BigInt(m.collateralFactorBps)]
43390
+ }
43391
+ ];
43392
+ results.push({
43393
+ calls,
43394
+ meta: {
43395
+ lender,
43396
+ chainId,
43397
+ market: m.address.toLowerCase(),
43398
+ collToken: m.collToken.toLowerCase(),
43399
+ collDecimals: m.collDecimals,
43400
+ dola: config.dola?.toLowerCase()
43401
+ },
43402
+ lender: inverseLenderKey(lender, m.address)
43403
+ });
43404
+ }
43405
+ }
43406
+ return results;
43407
+ }
43408
+ function parseInverseResults(data, meta, context) {
43409
+ const { chainId } = context;
43410
+ const key = inverseLenderKey(meta.lender, meta.market);
43411
+ const entries = [];
43412
+ const raw = data?.[0];
43413
+ const price2 = typeof raw === "bigint" ? raw : raw != null && raw !== "0x" ? BigInt(raw) : 0n;
43414
+ const collUSD = Number(price2) / 10 ** (36 - meta.collDecimals);
43415
+ if (collUSD > 0 && collUSD < 1e9) {
43416
+ entries.push({
43417
+ asset: meta.collToken,
43418
+ price: collUSD,
43419
+ priceUSD: collUSD,
43420
+ marketUid: createMarketUid(chainId, key, meta.collToken),
43421
+ targetLender: key,
43422
+ description: "Inverse FiRM pessimistic oracle (USD, ~2-day low)"
43423
+ });
43424
+ }
43425
+ if (meta.dola) {
43426
+ entries.push({
43427
+ asset: meta.dola,
43428
+ price: 1,
43429
+ priceUSD: 1,
43430
+ marketUid: createMarketUid(chainId, key, meta.dola),
43431
+ targetLender: key,
43432
+ description: "Inverse DOLA (par)",
43433
+ staticBase: true,
43434
+ baseAsset: meta.dola
43435
+ });
43436
+ }
43437
+ return entries;
43438
+ }
43439
+ function getInverseAbi() {
43440
+ return InverseOracleAbi;
43441
+ }
43442
+ var inverseFetcher = {
43443
+ getCalls: getInverseCalls,
43444
+ parse: parseInverseResults,
43445
+ getAbi: getInverseAbi
43446
+ };
43373
43447
  function getTellerCalls(chainId) {
43374
43448
  const pools = tellerPoolsByChain(chainId);
43375
43449
  if (pools.length === 0) return [];
@@ -45108,8 +45182,6 @@ function resolveDerivation(entry, groupDefault) {
45108
45182
  if (entry.baseAsset && !entry.staticBase) return "quoted";
45109
45183
  return groupDefault ?? "direct";
45110
45184
  }
45111
-
45112
- // src/prices/oracle-prices/fetchOraclePrices.ts
45113
45185
  function countFailures(data, offset, count) {
45114
45186
  let failures = 0;
45115
45187
  for (let i = offset; i < offset + count; i++) {
@@ -45221,6 +45293,9 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
45221
45293
  const multicallErrors = [];
45222
45294
  const active = onlyFetchers ? new Set(onlyFetchers.map((f) => f.toLowerCase())) : null;
45223
45295
  const isActive = (name) => !active || active.has(name);
45296
+ if (isActive("termmax") && termMaxConfigByChain(chainId)) {
45297
+ await fetchTermMaxMarkets(chainId).catch(() => []);
45298
+ }
45224
45299
  const aaveResults = isActive("aave") ? safeGetCalls(
45225
45300
  "aave",
45226
45301
  () => aaveFetcher.getCalls(chainId),
@@ -45290,6 +45365,11 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
45290
45365
  () => riverFetcher.getCalls(chainId),
45291
45366
  getCallsErrors
45292
45367
  ) : [];
45368
+ const inverseResults = isActive("inverse") ? safeGetCalls(
45369
+ "inverse",
45370
+ () => inverseFetcher.getCalls(chainId),
45371
+ getCallsErrors
45372
+ ) : [];
45293
45373
  const tellerResults = isActive("teller") ? safeGetCalls(
45294
45374
  "teller",
45295
45375
  () => tellerFetcher.getCalls(chainId),
@@ -45409,6 +45489,13 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
45409
45489
  getRiverAbi(),
45410
45490
  "direct"
45411
45491
  );
45492
+ const inverseGroup = buildGroup(
45493
+ "inverse",
45494
+ inverseResults,
45495
+ inverseFetcher.parse,
45496
+ getInverseAbi(),
45497
+ "direct"
45498
+ );
45412
45499
  const tellerGroup = buildGroup(
45413
45500
  "teller",
45414
45501
  tellerResults,
@@ -45473,6 +45560,7 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
45473
45560
  termGroup,
45474
45561
  liquityGroup,
45475
45562
  riverGroup,
45563
+ inverseGroup,
45476
45564
  tellerGroup,
45477
45565
  termMaxGroup,
45478
45566
  siloV2Group,
@@ -45520,6 +45608,7 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
45520
45608
  termData,
45521
45609
  liquityData,
45522
45610
  riverData,
45611
+ inverseData,
45523
45612
  tellerData,
45524
45613
  termMaxData,
45525
45614
  morphoGqlEntries,
@@ -45638,6 +45727,14 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
45638
45727
  allowFailure,
45639
45728
  rpcOverrides
45640
45729
  ),
45730
+ executeGroup(
45731
+ inverseGroup,
45732
+ chainId,
45733
+ chainBatchSize,
45734
+ retries,
45735
+ allowFailure,
45736
+ rpcOverrides
45737
+ ),
45641
45738
  executeGroup(
45642
45739
  tellerGroup,
45643
45740
  chainId,
@@ -45780,6 +45877,7 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
45780
45877
  parseTrackers(termGroup, termData.results);
45781
45878
  parseTrackers(liquityGroup, liquityData.results);
45782
45879
  parseTrackers(riverGroup, riverData.results);
45880
+ parseTrackers(inverseGroup, inverseData.results);
45783
45881
  if (siloV2GqlEntries != null) {
45784
45882
  const diag2 = {
45785
45883
  lender: "SILO_V2 (GraphQL)",