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.

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@tarun-khatri, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 59 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

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 Plus

Run ID: 734c1271-d306-4b2f-a6df-7348d8d5c763

📥 Commits

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

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (68)
  • .gitignore
  • api2/ecosystem.config.js
  • api2/routes/getChainDominance.ts
  • package.json
  • src/adapters/peggedAssets/agant-gbp/index.ts
  • src/adapters/peggedAssets/apxusd/index.ts
  • src/adapters/peggedAssets/avant-usd/index.ts
  • src/adapters/peggedAssets/beatusd/index.ts
  • src/adapters/peggedAssets/celo-euro/index.ts
  • src/adapters/peggedAssets/cod3x-usd/index.ts
  • src/adapters/peggedAssets/decentralized-euro/index.ts
  • src/adapters/peggedAssets/defi-money/index.ts
  • src/adapters/peggedAssets/elara-usd/index.ts
  • src/adapters/peggedAssets/ethena-usde/layerzeroConfig.ts
  • src/adapters/peggedAssets/eusd-2/index.ts
  • src/adapters/peggedAssets/falcon-finance-usd/index.ts
  • src/adapters/peggedAssets/flying-tulip-usd/index.ts
  • src/adapters/peggedAssets/forte-aud/index.ts
  • src/adapters/peggedAssets/fusd-by-the-fedz/index.ts
  • src/adapters/peggedAssets/fxusd/layerzeroConfig.ts
  • src/adapters/peggedAssets/gho/index.ts
  • src/adapters/peggedAssets/global-dollar/index.ts
  • src/adapters/peggedAssets/helper/aptos.ts
  • src/adapters/peggedAssets/helper/chains.json
  • src/adapters/peggedAssets/helper/scripts/generateLzConfig.ts
  • src/adapters/peggedAssets/helper/starknet.js
  • src/adapters/peggedAssets/hyperliquid-native-stablecoin/index.ts
  • src/adapters/peggedAssets/inverse-usd/index.js
  • src/adapters/peggedAssets/kerne-usd/index.ts
  • src/adapters/peggedAssets/macropod/index.ts
  • src/adapters/peggedAssets/mento-japanese-yen/index.ts
  • src/adapters/peggedAssets/mento-swiss-franc/index.ts
  • src/adapters/peggedAssets/monerium-eur-money/index.ts
  • src/adapters/peggedAssets/monetrix-usdm/index.ts
  • src/adapters/peggedAssets/money-protocol/index.ts
  • src/adapters/peggedAssets/myr-stablecoin/index.ts
  • src/adapters/peggedAssets/ondo-u-s-dollar-token/index.ts
  • src/adapters/peggedAssets/paypal-usd/layerzeroConfig.ts
  • src/adapters/peggedAssets/peggedAsset.type.ts
  • src/adapters/peggedAssets/polymarket-usd/index.ts
  • src/adapters/peggedAssets/re-protocol-reusd/index.ts
  • src/adapters/peggedAssets/royal-dollar/index.ts
  • src/adapters/peggedAssets/royal-euro/index.ts
  • src/adapters/peggedAssets/saturn-dollar/index.ts
  • src/adapters/peggedAssets/societe-generale-forge-eurcv/config.ts
  • src/adapters/peggedAssets/societe-generale-forge-eurcv/index.ts
  • src/adapters/peggedAssets/soulpeg-usd/index.ts
  • src/adapters/peggedAssets/stable-mint-usd/index.ts
  • src/adapters/peggedAssets/stablecorp-qcad/index.ts
  • src/adapters/peggedAssets/startale-usd/index.ts
  • src/adapters/peggedAssets/tether/config.ts
  • src/adapters/peggedAssets/tether/index.ts
  • src/adapters/peggedAssets/tether/layerzeroConfig.ts
  • src/adapters/peggedAssets/tgbp/index.ts
  • src/adapters/peggedAssets/tori-usd/index.ts
  • src/adapters/peggedAssets/unity-usd/index.ts
  • src/adapters/peggedAssets/universal-usd/index.ts
  • src/adapters/peggedAssets/usd-2/index.ts
  • src/adapters/peggedAssets/usd-coin/config.ts
  • src/adapters/peggedAssets/usd-coin/index.ts
  • src/adapters/peggedAssets/usd-coin/layerzeroConfig.ts
  • src/adapters/peggedAssets/usda-3/index.ts
  • src/adapters/peggedAssets/usdead/index.ts
  • src/adapters/peggedAssets/usdkg/index.ts
  • src/adapters/peggedAssets/valtorum-usdv/index.ts
  • src/peggedData/peggedData.ts
  • src/peggedData/types.ts
  • src/utils/deadChains.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.

@tarun-khatri
tarun-khatri force-pushed the fix-chain-dominance-filters branch from 265b8e1 to 873bbd8 Compare August 14, 2026 18:37
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