@1delta/margin-fetcher 0.0.197 → 0.0.199

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
@@ -30526,7 +30526,8 @@ async function fetchMorphoGraphQLPrices(chainId) {
30526
30526
  if (allMarkets.length === 0) return null;
30527
30527
  const entries = [];
30528
30528
  for (const market of allMarkets) {
30529
- if (!market.collateralAsset) continue;
30529
+ if (!market.collateralAsset?.address || !market.loanAsset?.address)
30530
+ continue;
30530
30531
  const oracle = market.oracleAddress;
30531
30532
  const loanAsset = market.loanAsset.address.toLowerCase();
30532
30533
  const collateralAsset = market.collateralAsset.address.toLowerCase();
@@ -30540,19 +30541,45 @@ async function fetchMorphoGraphQLPrices(chainId) {
30540
30541
  market.loanAsset.decimals,
30541
30542
  market.collateralAsset.decimals
30542
30543
  ) : 0;
30543
- if (collateralPriceUSD != null && collateralPriceUSD > 0) {
30544
+ if (loanPriceUSD != null && loanPriceUSD > 0) {
30545
+ const collateralUSD = oracleRatio > 0 ? oracleRatio * loanPriceUSD : collateralPriceUSD ?? 0;
30546
+ if (collateralUSD > 0) {
30547
+ entries.push({
30548
+ asset: collateralAsset,
30549
+ price: oracleRatio,
30550
+ // Raw: collateral price in loan asset terms
30551
+ priceUSD: collateralUSD,
30552
+ marketUid: createMarketUid(chainId, lenderKey, collateralAsset),
30553
+ targetLender: lenderKey
30554
+ });
30555
+ }
30556
+ } else if (collateralPriceUSD != null && collateralPriceUSD > 0) {
30544
30557
  entries.push({
30545
30558
  asset: collateralAsset,
30546
- price: oracleRatio || collateralPriceUSD,
30559
+ price: oracleRatio,
30560
+ // Raw oracle ratio
30547
30561
  priceUSD: collateralPriceUSD,
30548
30562
  marketUid: createMarketUid(chainId, lenderKey, collateralAsset),
30549
30563
  targetLender: lenderKey
30550
30564
  });
30551
30565
  }
30552
- if (loanPriceUSD != null && loanPriceUSD > 0) {
30566
+ if (collateralPriceUSD != null && collateralPriceUSD > 0) {
30567
+ const loanUSD = oracleRatio > 0 ? collateralPriceUSD / oracleRatio : loanPriceUSD ?? 0;
30568
+ if (loanUSD > 0) {
30569
+ entries.push({
30570
+ asset: loanAsset,
30571
+ price: oracleRatio > 0 ? 1 / oracleRatio : 0,
30572
+ // Raw: loan price in collateral terms
30573
+ priceUSD: loanUSD,
30574
+ marketUid: createMarketUid(chainId, lenderKey, loanAsset),
30575
+ targetLender: lenderKey
30576
+ });
30577
+ }
30578
+ } else if (loanPriceUSD != null && loanPriceUSD > 0) {
30553
30579
  entries.push({
30554
30580
  asset: loanAsset,
30555
- price: oracleRatio > 0 ? 1 / oracleRatio : loanPriceUSD,
30581
+ price: oracleRatio > 0 ? 1 / oracleRatio : 0,
30582
+ // Raw oracle ratio
30556
30583
  priceUSD: loanPriceUSD,
30557
30584
  marketUid: createMarketUid(chainId, lenderKey, loanAsset),
30558
30585
  targetLender: lenderKey
@@ -31408,11 +31435,12 @@ function selectAssetGroupPrices(structuredPrices, lists = {}, tvlMap = {}, prior
31408
31435
  for (const [chainId, lenders] of Object.entries(structuredPrices)) {
31409
31436
  const tokenList = lists[chainId] ?? {};
31410
31437
  for (const [lender, entries] of Object.entries(lenders)) {
31438
+ if (!Array.isArray(entries)) continue;
31411
31439
  const prio = computePriority(lender, chainId, priorityCfg);
31412
31440
  if (prio < 0) continue;
31413
31441
  const tvl = tvlMap[lender] ?? 0;
31414
31442
  for (const entry of entries) {
31415
- if (entry.priceUSD <= 0) continue;
31443
+ if (!entry?.asset || entry.priceUSD <= 0) continue;
31416
31444
  const oracleKey = tokenList[entry.asset]?.assetGroup ?? `${chainId}-${entry.asset.toLowerCase()}`;
31417
31445
  candidates.push({
31418
31446
  oracleKey,