@1delta/margin-fetcher 0.0.255 → 0.0.257

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
@@ -20515,11 +20515,13 @@ function lenderApiOnly(lender, chainId) {
20515
20515
  if (chainId === Chain.HEMI_NETWORK) return false;
20516
20516
  if (chainId === Chain.BERACHAIN) return false;
20517
20517
  if (chainId === Chain.SEI_NETWORK) return false;
20518
+ if (chainId === Chain.BNB_SMART_CHAIN_MAINNET) return false;
20518
20519
  if (chainId === Chain.CELO_MAINNET) return false;
20519
- if (chainId === Chain.CORN) return false;
20520
- if (chainId === Chain.ABSTRACT) return false;
20521
- if (chainId === Chain.PLUME_MAINNET) return false;
20522
20520
  if (chainId === Chain.LISK) return false;
20521
+ if (chainId === Chain.TAC_MAINNET) return false;
20522
+ if (chainId === Chain.FLARE_MAINNET) return false;
20523
+ if (chainId === Chain.PLUME_MAINNET) return false;
20524
+ if (chainId === "4114") return false;
20523
20525
  return true;
20524
20526
  }
20525
20527
  return false;
@@ -31307,16 +31309,6 @@ var ProxyOracleAbi = [
31307
31309
  }
31308
31310
  ];
31309
31311
 
31310
- // src/lending/public-data/morpho/fetchMorphoGoldsky.ts
31311
- ({
31312
- [Chain.SEI_NETWORK]: "https://api.goldsky.com/api/public/project_cmiergfbv4vma01vb642yaeam/subgraphs/morphoblue-sei/1.0.1/gn",
31313
- [Chain.CELO_MAINNET]: "https://api.goldsky.com/api/public/project_cmiergfbv4vma01vb642yaeam/subgraphs/morphoblue-celo/1.0.4/gn",
31314
- [Chain.LISK]: "https://api.goldsky.com/api/public/project_cmiergfbv4vma01vb642yaeam/subgraphs/morphobluelisk/1.0.1/gn",
31315
- [Chain.SONEIUM]: "https://api.goldsky.com/api/public/project_cmiergfbv4vma01vb642yaeam/subgraphs/morphobluesoneium/1.0.2/gn",
31316
- [Chain.TAC_MAINNET]: "https://api.goldsky.com/api/public/project_cmiergfbv4vma01vb642yaeam/subgraphs/morphoblue-tac/1.0.0/gn",
31317
- [Chain.HEMI_NETWORK]: "https://feather.securesecrets.org/hemi-mopho-blue/"
31318
- });
31319
-
31320
31312
  // src/prices/oracle-prices/fetchers/morpho.ts
31321
31313
  function morphoApiAvailable(chainId) {
31322
31314
  if (chainId === Chain.SONEIUM) return false;
@@ -31331,6 +31323,17 @@ function morphoApiAvailable(chainId) {
31331
31323
  if (chainId === Chain.BNB_SMART_CHAIN_MAINNET) return false;
31332
31324
  return true;
31333
31325
  }
31326
+ var MORPHO_API_INCOMPLETE_CHAINS = /* @__PURE__ */ new Set([
31327
+ Chain.FLARE_MAINNET,
31328
+ // Mystic — no state.price
31329
+ Chain.PLUME_MAINNET,
31330
+ // Mystic — no state.price
31331
+ "4114"
31332
+ // Citrea (Mystic) — not yet in chain-registry
31333
+ ]);
31334
+ function morphoApiIncomplete(chainId) {
31335
+ return MORPHO_API_INCOMPLETE_CHAINS.has(chainId);
31336
+ }
31334
31337
  function generateMarketId(oracle, loanAsset, collateralAsset) {
31335
31338
  return `${oracle}${loanAsset}${collateralAsset}`.replace(/0x/gi, "").toUpperCase();
31336
31339
  }
@@ -32904,6 +32907,66 @@ function parseSiloV3GraphQLResults(items, context) {
32904
32907
  return out;
32905
32908
  }
32906
32909
 
32910
+ // src/prices/oracle-prices/fetchers/fetchMysticApi.ts
32911
+ var MYSTIC_CHAIN_IDS = /* @__PURE__ */ new Set([
32912
+ "14",
32913
+ // Flare
32914
+ "98866",
32915
+ // Plume
32916
+ "4114"
32917
+ // Citrea
32918
+ ]);
32919
+ function hasMysticApi(chainId) {
32920
+ return MYSTIC_CHAIN_IDS.has(chainId);
32921
+ }
32922
+
32923
+ // src/prices/oracle-prices/fetchers/fetchMorphoMysticPrices.ts
32924
+ var FULL_URL = "https://api.mysticfinance.xyz/morphoCache/";
32925
+ async function fetchMorphoMysticPrices(chainId) {
32926
+ try {
32927
+ const res = await fetch(`${FULL_URL}?chainId=${chainId}`);
32928
+ if (!res.ok) {
32929
+ console.warn(
32930
+ `[morpho-mystic] chain ${chainId}: ${res.status} ${res.statusText}`
32931
+ );
32932
+ return null;
32933
+ }
32934
+ const body = await res.json();
32935
+ const raw = body.markets ?? [];
32936
+ const allMarkets = [];
32937
+ for (const m of raw) {
32938
+ const loanAddr = (m.loanToken ?? m.asset?.asset ?? "").toLowerCase();
32939
+ const collateralAddr = (m.collateralToken ?? m.collateral?.asset ?? "").toLowerCase();
32940
+ if (!m.marketId || !m.oracle || !loanAddr || !collateralAddr) continue;
32941
+ const loanPrice = typeof m.assetPrice === "number" && Number.isFinite(m.assetPrice) ? m.assetPrice : null;
32942
+ const collateralPrice = typeof m.collateralPrice === "number" && Number.isFinite(m.collateralPrice) ? m.collateralPrice : null;
32943
+ allMarkets.push({
32944
+ uniqueKey: m.marketId,
32945
+ oracleAddress: m.oracle,
32946
+ loanAsset: {
32947
+ address: loanAddr,
32948
+ decimals: m.asset?.decimals ?? 18,
32949
+ priceUsd: loanPrice
32950
+ },
32951
+ collateralAsset: {
32952
+ address: collateralAddr,
32953
+ decimals: m.collateral?.decimals ?? 18,
32954
+ priceUsd: collateralPrice
32955
+ },
32956
+ // Mystic does not return the on-chain oracle ratio.
32957
+ state: null
32958
+ });
32959
+ }
32960
+ return processMarketsToEntries(chainId, allMarkets, "morpho-mystic");
32961
+ } catch (err) {
32962
+ console.warn(
32963
+ `[morpho-mystic] chain ${chainId}: fetch error, skipping`,
32964
+ err
32965
+ );
32966
+ return null;
32967
+ }
32968
+ }
32969
+
32907
32970
  // src/prices/oracle-prices/fetchOraclePrices.ts
32908
32971
  function countFailures(data, offset, count) {
32909
32972
  let failures = 0;
@@ -33047,8 +33110,11 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
33047
33110
  () => aaveV4Fetcher.getCalls(chainId),
33048
33111
  getCallsErrors
33049
33112
  ) : [];
33050
- const morphoUseApi = isActive("morpho") && morphoApiAvailable(chainId);
33051
- const morphoUseOnChain = isActive("morpho") && !morphoUseApi;
33113
+ const morphoUseMystic = isActive("morpho") && hasMysticApi(chainId);
33114
+ const morphoUseApi = isActive("morpho") && !morphoUseMystic && morphoApiAvailable(chainId);
33115
+ const morphoUseRemote = morphoUseMystic || morphoUseApi;
33116
+ const morphoUseHybrid = morphoUseRemote && morphoApiIncomplete(chainId);
33117
+ const morphoUseOnChain = isActive("morpho") && (!morphoUseRemote || morphoUseHybrid);
33052
33118
  const morphoResults = morphoUseOnChain ? safeGetCalls(
33053
33119
  "morpho",
33054
33120
  () => morphoFetcher.getCalls(chainId, {
@@ -33171,7 +33237,7 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
33171
33237
  return { chainId, data: chainResult, diagnostic: diag2 };
33172
33238
  }
33173
33239
  const chainBatchSize = batchSize?.[chainId];
33174
- const morphoGqlPromise = morphoUseApi ? fetchMorphoGraphQLPrices(chainId) : Promise.resolve(null);
33240
+ const morphoGqlPromise = morphoUseMystic ? fetchMorphoMysticPrices(chainId) : morphoUseApi ? fetchMorphoGraphQLPrices(chainId) : Promise.resolve(null);
33175
33241
  const siloV2GqlPromise = isActive("silov2") ? fetchSiloV2GraphQLPrices(chainId, basePrices, tokenList) : Promise.resolve(null);
33176
33242
  const siloV3GqlPromise = isActive("silov3") ? fetchSiloV3GraphQLPrices(chainId, basePrices, tokenList) : Promise.resolve(null);
33177
33243
  const [
@@ -33290,6 +33356,7 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
33290
33356
  rpcOverrides
33291
33357
  ) : { results: [], error: void 0 };
33292
33358
  const useMorphoGql = morphoGqlEntries != null;
33359
+ const useMorphoHybrid = useMorphoGql && morphoUseHybrid;
33293
33360
  const groupResults = [
33294
33361
  { group: aaveGroup, data: aaveData },
33295
33362
  { group: compoundV2Group, data: compoundV2Data },
@@ -33301,7 +33368,8 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
33301
33368
  { group: gearboxV3Group, data: gearboxV3Data },
33302
33369
  ...siloV2GqlEntries != null ? [] : [{ group: siloV2Group, data: siloV2Data }],
33303
33370
  ...siloV3GqlEntries != null ? [] : [{ group: siloV3Group, data: siloV3Data }],
33304
- ...useMorphoGql ? [] : [{ group: morphoGroup, data: morphoData }]
33371
+ // In hybrid mode the on-chain multicall ran too — surface its errors.
33372
+ ...useMorphoGql && !useMorphoHybrid ? [] : [{ group: morphoGroup, data: morphoData }]
33305
33373
  ];
33306
33374
  for (const { group, data } of groupResults) {
33307
33375
  if (data.error) {
@@ -33425,7 +33493,38 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
33425
33493
  } else {
33426
33494
  parseTrackers(siloV3Group, siloV3Data.results);
33427
33495
  }
33428
- if (useMorphoGql) {
33496
+ if (useMorphoHybrid) {
33497
+ for (const entry of morphoGqlEntries) {
33498
+ if (!(entry.priceUSD > 0)) continue;
33499
+ const oracleKey = tokenList[entry.asset]?.assetGroup ?? `${chainId}-${entry.asset}`;
33500
+ usdPrices[oracleKey] = entry.priceUSD;
33501
+ usdPrices[entry.asset] = entry.priceUSD;
33502
+ }
33503
+ parseTrackers(morphoGroup, morphoData.results, false);
33504
+ const onChainKeys = /* @__PURE__ */ new Set();
33505
+ for (const lender of Object.keys(chainResult)) {
33506
+ for (const e of chainResult[lender]) {
33507
+ if (!e.targetLender) continue;
33508
+ if (!e.targetLender.startsWith("MORPHO")) continue;
33509
+ onChainKeys.add(`${e.targetLender}|${e.marketUid}|${e.asset}`);
33510
+ }
33511
+ }
33512
+ let gqlPushed = 0;
33513
+ for (const entry of morphoGqlEntries) {
33514
+ const lender = entry.targetLender ?? "MORPHO_BLUE";
33515
+ const key = `${lender}|${entry.marketUid}|${entry.asset}`;
33516
+ if (onChainKeys.has(key)) continue;
33517
+ if (!chainResult[lender]) chainResult[lender] = [];
33518
+ chainResult[lender].push(entry);
33519
+ gqlPushed++;
33520
+ }
33521
+ trackerDiags.push({
33522
+ lender: "MORPHO_BLUE (hybrid-fill)",
33523
+ callCount: 0,
33524
+ failedCalls: 0,
33525
+ parsedEntries: gqlPushed
33526
+ });
33527
+ } else if (useMorphoGql) {
33429
33528
  const morphoGqlDiag = {
33430
33529
  lender: "MORPHO_BLUE (GraphQL)",
33431
33530
  callCount: 0,