Sub topic 13
Cross-checking Dune against DefiLlama
This chapter assumes you can write DuneSQL queries against dex.trades and decoded event tables. It also assumes you know what DefiLlama's TVL, volume and fees pages show, and that you have seen the pitfalls chapter on decimals, double counting and prices. Here you combine those skills to compare one metric across both tools and explain any gap.
Why cross-check at all
Dune and DefiLlama both read the same blockchains, but their numbers rarely match exactly. A match within a few percent is normal. A gap of 30% or more means the two sides are measuring different things, or one side has a bug.
Cross-checking gives you three things:
- It catches mistakes in your own query, such as a wrong decimal or a missing filter.
- It shows which definition each source uses.
- It gives readers a reason to trust your dashboard, because you can state how closely it agrees with an independent source.
Treat neither source as ground truth. Dune gives you transparent logic, because you can read every line of SQL. DefiLlama gives you curated coverage, because its adapters are maintained per protocol. Agreement between the two is evidence that both are reasonable. Disagreement is a prompt to investigate.
Choose a metric that can be compared
Start with a metric both tools define in a similar way. Some are easier to compare than others.
| Metric | Dune source | DefiLlama source | Comparability |
|---|---|---|---|
| DEX volume per chain | `dex.trades` | DEX volume dashboard | Good, with scope differences |
| Stablecoin transferred | `erc20_ethereum.evt_Transfer` | Stablecoins dashboard | Poor. Transfers are not supply |
| Protocol TVL | Custom balance queries | Protocol TVL page | Hard. You must replicate the adapter |
| Fees and revenue | Custom per protocol | Fees dashboard | Hard. Definitions vary |
DEX volume is the best starting point. It is a flow (an amount per day), it has a clear unit (USD), and Dune provides a curated table for it. TVL is a stock (a balance at a point in time), so a comparison needs historical balances and prices for every tracked asset. Do that only for a single protocol you understand well.
Align the definitions first
Before running anything, write down what each side counts. Most disagreement comes from mismatched scope, not from wrong data.
- Chain. Dune's
blockchaincolumn is lowercase ('ethereum'). DefiLlama uses display names such asEthereum. Confirm that you are comparing the same chain. - Protocols included.
dex.tradescovers the projects that Dune's maintainers have added. DefiLlama tracks its own list of adapters. Neither list is a superset of the other. - Trade type. Aggregators and routers can produce several underlying swaps for one user trade. One source may count the aggregator volume and the underlying pool volume, while the other counts only one of them.
- Time window. Dune's
block_dateis in UTC. DefiLlama's daily values are also UTC-based, but its latest day may be incomplete while data is still being collected. Compare only completed days. - Volume definition. Dune's
amount_usdis a price-valued figure for the trade. DefiLlama may use the protocol's own accounting or a different price source.
Build the Dune side
Use a query with the same shape as the one from the efficiency chapter, grouped by day and, when you need to debug, by project.
SELECT
block_date,
SUM(amount_usd) AS volume_usd
FROM dex.trades
WHERE blockchain = 'ethereum'
AND block_date >= current_date - INTERVAL '30' DAY
AND block_date < current_date
GROUP BY 1
ORDER BY 1The extra block_date < current_date filter excludes today's partial day. Without it, your last data point is almost always low and looks like a crash.
When the totals disagree, rerun the query with project in the SELECT and GROUP BY. Then compare the project list against DefiLlama's breakdown for the same chain. A project that appears on one side only usually explains a large part of the gap.
Be aware that amount_usd can be NULL when Dune has no price for a token in the trade. SUM skips NULL values silently, so trades in obscure tokens vanish from your total. Check how many rows are affected:
SELECT
COUNT(*) AS trades,
COUNT(amount_usd) AS priced_trades,
COUNT(*) - COUNT(amount_usd) AS unpriced_trades
FROM dex.trades
WHERE blockchain = 'ethereum'
AND block_date >= current_date - INTERVAL '7' DAYBuild the DefiLlama side
You can read DefiLlama's numbers from the website's chart download, or fetch them with the public API as in the earlier chapter. Either way, put both series into the same shape: one USD value per UTC date. Export your Dune result as CSV, or read it through Dune's API, and load the DefiLlama series the same way.
Compare the two series
Compare day by day, not only in total. A total can hide offsetting errors, while a daily series shows whether the gap is constant, growing, or limited to a few days.
The script below takes two dictionaries of daily USD values, computes the relative difference for each shared day, and flags days outside a tolerance. The numbers are illustrative. Replace them with your own exports.
from statistics import median
dune = {
"2026-11-20": 1_210_000_000,
"2026-11-21": 980_000_000,
"2026-11-22": 1_050_000_000,
"2026-11-23": 1_400_000_000,
}
llama = {
"2026-11-20": 1_180_000_000,
"2026-11-21": 1_010_000_000,
"2026-11-22": 1_020_000_000,
"2026-11-23": 1_020_000_000,
}
def compare(a, b, tolerance=0.05):
"""Return (day, a, b, relative_diff, flagged) for each shared day."""
rows = []
for day in sorted(set(a) & set(b)):
if b[day] == 0:
continue
diff = (a[day] - b[day]) / b[day]
rows.append((day, a[day], b[day], diff, abs(diff) > tolerance))
return rows
rows = compare(dune, llama)
for day, a, b, diff, flagged in rows:
mark = "CHECK" if flagged else "ok"
print(f"{day} dune={a / 1e6:>8,.0f}M llama={b / 1e6:>8,.0f}M {diff:+7.1%} {mark}")
print(f"median difference: {median(r[3] for r in rows):+.1%}")The median difference tells you about the systematic offset, for example "Dune runs about 3% higher". The flagged days tell you about outliers. A steady offset points to a definition difference. A single outlier day points to a data event, such as a missing adapter, a delayed update, or an unusual trade.
Diagnose a gap
Work through the likely causes from cheapest to check to most expensive.
The same checks as a list:
- Filters. Confirm the chain, the UTC date range and that you excluded the current partial day.
- Project coverage. Group Dune by
project, list DefiLlama's protocols for the chain, and restrict both to the projects they share. - Unpriced trades. Run the
NULLcount query. If a few percent of trades lack prices, your Dune total is a lower bound. - Double counting. Look for aggregator or router projects in your Dune breakdown. If both the aggregator and the underlying pools appear, volume is counted twice.
- Price source. If the gap is small (1% to 4%) and steady, different price feeds are the likely cause. You can rarely eliminate this.
- Decimals. A gap near a power of ten (10x, 1,000,000x) is almost always a decimals mistake in a custom query, not a data difference.
Interpret the result
After you have restricted both sides to shared scope, you should be within a few percent. Record what you found. A useful note has three parts:
- The scope you compared, such as "Ethereum, 30 completed UTC days, 12 shared projects".
- The size of the gap, for example "median +2.8%, largest day +9.1%".
- The explanation, or the statement that the cause is unknown.
An unexplained gap is acceptable as long as you say so. Explaining it falsely is worse than leaving it open, because readers then trust a claim you did not verify.
Cross-checking also has limits. If both tools use the same upstream price source, or both miss the same new protocol, they will agree and both be wrong. Agreement raises confidence but does not prove correctness. For a high-stakes number, spot-check a few individual transactions on a block explorer and confirm that the amounts match your table rows.
Make it repeatable
Cross-checks decay as protocols launch, adapters change and tables are updated. To keep yours useful:
- Save the Dune query with a parameter for the chain, as in the parameters chapter, so you can rerun it for another chain.
- Keep the comparison script next to the exported data, with the tolerance written as a named argument.
- Rerun the check when you add a protocol or change a filter, and when a number on your dashboard looks surprising.
Exercise
Your Dune query for Ethereum DEX volume over the last 30 days is 18% higher than DefiLlama's total, and the difference is steady across days. List three checks you would run, in order, and say what result of each would explain the gap.
Show answer
First, group the Dune result by project and compare it with DefiLlama's protocol list for Ethereum. If Dune includes projects DefiLlama does not track, restrict both sides to the shared projects. Second, look for aggregator or router entries in the breakdown. If both the aggregator and the underlying pools are counted, volume is double counted and removing the aggregator rows should reduce the gap. Third, confirm the date window is complete UTC days and that the chain filter matches. A steady 18% offset suggests scope or double counting rather than a one-off data event. A power-of-ten difference would instead point to decimals, which does not fit 18%.
Exercise
Why can a Dune total built with SUM(amount_usd) understate real volume even when the query has no bugs, and how would you measure the effect?
Show answer
amountusd is NULL for trades where Dune has no price for a token, and SUM ignores NULL values, so those trades add nothing to the total. Measure it by counting rows with COUNT(*) and COUNT(amountusd) over the same filter. The difference is the number of unpriced trades. If it is a meaningful share, report the Dune total as a lower bound.