Sub topic 3
Volume, fees, yields and stablecoin dashboards
This chapter assumes you know basic SQL (SELECT, WHERE, GROUP BY, JOIN), what transactions and smart contracts are, and how ERC-20 tokens work. The Python example needs Python 3 and the requests package.
Reading DefiLlama's core dashboards
DefiLlama publishes four metric families:
- Volume: trading volume on decentralized exchanges (DEXs), summed per day.
- Fees: fees users pay to protocols, and the share protocols keep as revenue.
- Yields: annual percentage yields (APY) for lending markets and liquidity pools.
- Stablecoins: circulating supply of tokens pegged to a currency, broken down by chain.
Read each dashboard's methodology note before comparing numbers. Protocols define fees and revenue differently.
Pulling DefiLlama data with the public API
The public API needs no key. This script lists the ten protocols with the highest total value locked (TVL):
import requests
resp = requests.get("https://api.llama.fi/protocols", timeout=30)
resp.raise_for_status()
protocols = resp.json()
top = sorted(
(p for p in protocols if p.get("tvl")),
key=lambda p: p["tvl"],
reverse=True,
)[:10]
for p in top:
category = p.get("category") or "n/a"
print(f"{p['name']:<25} {category:<20} ${p['tvl'] / 1e9:,.2f}B")Common pitfalls
- Decimals: token amounts are stored as integers. USDC uses 6 decimals, so divide the raw value by 10^6.
- Double counting: a swap routed through two pools can appear twice in volume. Check which level the source counts.
- Prices: USD values depend on the token price at trade time. A token without a price feed shows as zero or missing.
Cross-checking Dune against DefiLlama
Pick one metric, such as daily DEX volume on Ethereum over 30 days. Run the Dune query over dex.trades, then compare the result with DefiLlama's DEX volume chart for the same days. Expect gaps. Typical causes are different DEX coverage, different price sources, and different day boundaries. Record each gap and its likely cause.
Designing a dashboard people can trust
- State the definition and data source on every chart.
- Show the date range and time zone.
- Keep one metric per chart.
- Place the cross-check result beside the chart it verifies.
Exercise
Exercise
Why must you divide a raw USDC transfer amount by 10^6 before reporting it?
Show answer
USDC has 6 decimals, so the stored integer is one million times the token amount. Dividing by 10^6 converts it to whole USDC.