Skip to content

stablecoins: apply the chain-total exclusions to chain dominance#875

Open
tarun-khatri wants to merge 1 commit into
DefiLlama:masterfrom
tarun-khatri:fix-chain-dominance-filters
Open

stablecoins: apply the chain-total exclusions to chain dominance#875
tarun-khatri wants to merge 1 commit into
DefiLlama:masterfrom
tarun-khatri:fix-chain-dominance-filters

Conversation

@tarun-khatri

@tarun-khatri tarun-khatri commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

craftStablecoinChainsResponse and craftChainDominanceResponse both report stablecoin totals per chain, but they don't apply the same exclusions. The chains path starts with

if (pegged.doublecounted) return;

while the dominance path maps over every asset with no filter at all. The two endpoints therefore disagree for the same chain on the same day:

chain /stablecoindominance/<chain> /stablecoinchains delta
BSC $18,092,455,236 $14,037,328,950 +$4,055,126,286 (28.89%)
Polygon $3,840,314,992 $3,279,981,142 +$560,333,851 (17.08%)
Arbitrum $3,928,564,483 $3,727,018,994 +$201,545,489 (5.41%)
Solana $15,748,298,354 $15,134,554,698 +$613,743,655 (4.06%)
Ethereum $151,082,124,253 $149,752,674,683 +$1,329,449,570 (0.89%)
Base $4,807,555,565 $4,795,890,921 +$11,664,644 (0.24%)

What makes up the gap

66 assets carry doublecounted: true, and 17 carry deadFrom. Summing what each group contributes per chain from the published chainCirculating:

chain doublecounted deadFrom
BSC $4,432,492,928 $530,707,071
Ethereum $1,340,409,502 $310,777,247
Solana $613,670,251
Polygon $560,323,832 $101,148,56
Arbitrum $201,509,986 $121,971,085

The doublecounted column matches the observed endpoint delta, which is what you'd expect given the chains endpoint already filters it.

deadFrom is the second half. It is honoured in storePegged.ts, storeNewPeggedBalances.ts, storeAllPeggedAssets.ts and storeCharts.ts, but in none of the serving paths — so a dead asset's lastBalance stays frozen at its final day, and since coins.llama.fi returns no price for these collapsed tokens the pegType === "peggedUSD" ? 1 : 0 fallback values every unit at exactly $1.00.

Fix

Adds both exclusions so the dominance figures agree with the chain totals they sit alongside.

I could not run the api2 cache locally, so this is verified against the published endpoints and by summing the two flagged groups from chainCirculating rather than by executing the cron task. tsc --noEmit gives the same 50 pre-existing errors before and after, none in this file.

Related: I have #874 open adding the deadFrom exclusion to getStablecoinChains.ts. Different file and different function; this one needs both flags because it currently has neither. getStableCoins.ts has the same omission, but dropping an asset there would also drop its detail page, so that one looks like a deliberate call rather than an oversight.

Summary by CodeRabbit

  • Bug Fixes
    • Improved chain dominance calculations by excluding pegged assets that are double-counted or no longer active.
    • Prevented excluded assets from affecting dominance totals and the selection of the highest market capitalization.

craftStablecoinChainsResponse skips doublecounted assets; craftChainDominance
Response skips nothing, so the two endpoints report different totals for the
same chain on the same day - BSC differs by 28.9%.

Excludes doublecounted assets, whose collateral is already counted, and dead
assets, whose lastBalance is frozen at their final day and has no price so the
peggedUSD fallback values it at par.
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f30b8d0b-15a9-4549-93cd-58a076352cda

📥 Commits

Reviewing files that changed from the base of the PR and between adf9680 and 265b8e1.

📒 Files selected for processing (1)
  • api2/routes/getChainDominance.ts

📝 Walkthrough

Walkthrough

The chain dominance response now excludes pegged assets marked as doublecounted or having deadFrom from dominance totals and greatest market-cap selection.

Changes

Chain dominance calculation

Layer / File(s) Summary
Filter invalid pegged assets
api2/routes/getChainDominance.ts
The pegged-asset mapping skips assets with doublecounted or deadFrom values by returning undefined.

Estimated code review effort: 1 (Trivial) | ~3 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is off-template and does not include the required listing fields or sections from this repository's PR template. Rewrite the PR description to follow the repository template, including the required headings and filled-in fields, or note that it is not a new listing if applicable.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: applying exclusions when computing chain dominance totals.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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.

1 participant