Skip to content

fix: FX fallback price broken for peggedREAL (BRTH shows mcap 0)#856

Open
0xshubhs wants to merge 1 commit into
DefiLlama:masterfrom
0xshubhs:fix/brth-price
Open

fix: FX fallback price broken for peggedREAL (BRTH shows mcap 0)#856
0xshubhs wants to merge 1 commit into
DefiLlama:masterfrom
0xshubhs:fix/brth-price

Conversation

@0xshubhs

@0xshubhs 0xshubhs commented Jul 7, 2026

Copy link
Copy Markdown

Fixes #743.

Root cause

BRTH (id 352, peggedREAL, Polygon) has no market price: it isn't on CoinGecko and coins.llama.fi returns {"coins":{}} for it. That part is upstream. But the repo already has an FX-rate fallback for fiat-pegged assets without a market price, and it's broken for BRL pegs in two ways:

  1. storeCharts.ts and getChainDominance.ts derive the FX ticker with pegType.slice(-3). For peggedREAL that yields "EAL", but the FX feed (rates/full) keys by ISO code (BRL), so the lookup always misses and the fallback price becomes 0. Every 3-letter pegType (EUR, GBP, JPY, ...) happens to work by accident; peggedREAL is the only 4-letter one and there are 5 such assets.
  2. getStableCoins.ts and getStablecoinChains.ts don't use the FX fallback at all — they hardcode pegType === "peggedUSD" ? 1 : 0, so any non-USD asset without a market price gets mcap 0 in the /stablecoins and /stablecoinchains responses even when the chart code path would have priced it.

(BRZ and cREAL never surfaced this because they have CoinGecko prices.)

Change

  • src/utils/fxRates.ts: add pegTypeFxTicker() (strips the pegged prefix, with an explicit peggedREAL -> BRL override) and fxFallbackPrice() (1 for USD pegs, 1/fxRate for fiat pegs, 0 for peggedVAR/unknown).
  • storeCharts.ts, getChainDominance.ts: use pegTypeFxTicker instead of slice(-3). Also fixed the dominance guard: typeof (1/undefined) === "number" is true for NaN, so the old check never caught a missing rate — now isFinite.
  • getStableCoins.ts, getStablecoinChains.ts: replace the hardcoded 0 with fxFallbackPrice fed from the same cron FX cache, so these responses price fiat pegs consistently with the chart/dominance paths.

Test

npm test brth passes (supply adapter reads 2.97k BRTH live from Polygon).

Fallback exercised against the live FX feed:

pegTypeFxTicker(peggedREAL) = BRL
OLD chart lookup (EAL): null
NEW chart lookup (BRL): 5.1451
fxFallbackPrice peggedREAL = 0.1943...   (1/5.1451)
fxFallbackPrice peggedUSD  = 1
fxFallbackPrice peggedVAR  = 0
fxFallbackPrice peggedEUR  = 1.1441...
BRTH mcap with fix ~= $578.61

No new type errors in the touched files (the two pre-existing TS2322s in storeCharts/getChainDominance are unchanged on master).

Copilot AI review requested due to automatic review settings July 7, 2026 21:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@0xshubhs, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 53 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4479d6c5-191d-4298-917b-57c38e5c6c52

📥 Commits

Reviewing files that changed from the base of the PR and between 3803bad and 51bae20.

📒 Files selected for processing (5)
  • api2/cron-task/getStableCoins.ts
  • api2/cron-task/getStablecoinChains.ts
  • api2/cron-task/storeCharts.ts
  • api2/routes/getChainDominance.ts
  • src/utils/fxRates.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BRTH: coins.llama.fi price API returns empty despite active Uniswap V3 pool

2 participants