DeFi Intel

Build Dune Dashboards for DeFi Metrics: Step by Step

Quick answerTo build a Dune dashboard for DeFi metrics, start by mastering Dune's schema for top protocols. Write SQL to extract key data (e.g., daily volume, TVL). Use Dune's chart wizard to create visualizations and assemble them into a dashboard. Add parameters for interactivity. Optimize queries for speed. Share and schedule refreshes to keep data fresh.

Building a Dune dashboard for DeFi metrics is one of the most effective ways to monitor and communicate blockchain data. Whether you are tracking Uniswap liquidity, Compound borrow rates, or aggregate TVL, Dune Analytics provides a powerful platform to turn raw on-chain data into actionable visualizations. Dune combines a community-curated database of decoded blockchain data with a flexible SQL query engine and a rich dashboard builder, making it the go-to tool for DeFi analysts, researchers, and investors.

In this step-by-step guide, you will learn how to go from writing your first SQL query to publishing a polished, interactive dashboard that the whole DeFi community can benefit from. We will cover real examples using protocols like Uniswap V3, Compound, and Aave, and explain best practices for query optimization, visualization selection, and dashboard layout. By the end, you will be able to create your own Dune dashboard for DeFi metrics that stands out in the Dune ecosystem.

Key takeaways
  • Master Dune's schema — understand table naming conventions (evt_, view_) for each protocol.
  • Use CTEs and early filtering to write efficient, readable queries that save credits.
  • Choose chart types that match the metric (line for time-series, counter for snapshots).
  • Parameters turn a static dashboard into an interactive tool for exploratory analysis.
  • Optimize queries with limits, index-friendly filters, and scheduled refreshes for performance.
  • Share and maintain your dashboard — keep it public, update for protocol changes, and add a changelog.

Why a Dune Dashboard for DeFi? Understanding the Value

Dune dashboards are the standard for transparent, real-time DeFi analytics. Unlike centralized platforms that may obfuscate data sources, Dune queries are publicly auditable, and every chart is backed by a verifiable SQL query. For intermediate DeFi analysts, building your own dashboard allows you to track exactly the metrics that matter to your strategy, whether that is Uniswap V3 fee generation over time or the debt ratio distribution in Maker Vaults.

A well-designed Dune dashboard for DeFi metrics can serve as a decision-support tool for liquidity provision, lending, or portfolio management. It also helps you communicate findings to a broader audience — many popular dashboards on Dune have thousands of daily views. The key is to move beyond simply copying others and instead learn the underlying query logic so you can adapt and extend dashboards to new protocols or custom analytic needs.

Setting Up Your Dune Workspace: From Account to First Query

To start building your Dune dashboard for DeFi, go to dune.com and create a free account. The free tier includes enough query execution credits for most intermediate use cases. Once logged in, explore the Datasets tab to see the available blockchains (Ethereum, Polygon, Solana, etc.) and decoded protocols. For this guide, we will focus on Ethereum mainnet data.

Before writing a query, it is helpful to look at existing dashboards for inspiration. Search for “Uniswap volume” or “Aave TVL” and examine the queries behind the charts. Dune’s query engine, DuneSQL, is based on Trino (a Presto-derived SQL dialect). You can fork any public query or start from scratch in the New Query window. Familiarize yourself with the Query Tabs for saved queries, and the Visualization tab where you will turn query results into charts.

Pro Tip: Use the EXPLAIN ANALYZE feature to understand query performance early. A minor optimization can reduce execution time from minutes to seconds, saving your daily query limit.

Decoding Dune's Data Schema: Understanding Tables and Columns

Dune organizes data into tables for each protocol and event type. For example, Uniswap V3 swap events live in uniswap_v3_evt_swap. Each row contains columns like evt_tx_hash, evt_block_time, amount0, amount1, liquidity, and more. To build a Dune dashboard for DeFi metrics, you must understand the schema of the protocols you track.

Below is a typical structure for a lending protocol like Compound:

Table NameKey ColumnsMetric Use
compound_v2_evt_borrowborrower, amount, evt_block_timeBorrow volume over time
compound_v2_view_marketunderlying_symbol, total_borrows, total_reservesMarket-level TVL and supply
compound_v2_evt_redeemredeemer, amountWithdraw events

To explore the schema, use the Dataset Browser in Dune or run SELECT * FROM information_schema.columns … for any table. Most DeFi protocol tables follow a similar pattern with evt_ for events and view_ for aggregated state.

Writing Your First DeFi Metric: Daily DEX Volume for Uniswap

A classic Dune dashboard for DeFi metrics starts with daily DEX volume. Let’s write a query to get daily USD volume on Uniswap V3 Ethereum. We’ll use the uniswap_v3_evt_swap table and join with token prices from the prices.usd table. Here’s a step-by-step example:

First, define a CTE that extracts swap events and computes a raw volume in ETH-like terms:

WITH swap_events AS (
SELECT
DATE_TRUNC('day', evt_block_time) AS day,
amount0 / 1e18 AS amount0_adj,
amount1 / 1e18 AS amount1_adj,
contract_address
FROM uniswap_v3_evt_swap
WHERE evt_block_time >= '2023-01-01'
),

Then, join with a token price feed to convert to USD. For simplicity, we can use the median of amount0 and amount1 assuming one side is a stablecoin. A more robust approach uses the prices.usd table:

price_feed AS (
SELECT * FROM prices.usd
WHERE symbol = 'WETH' AND contract_address = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'
)
SELECT
day,
SUM(ABS(amount0_adj) * price) AS volume_usd
FROM swap_events s
JOIN price_feed p ON DATE_TRUNC('day', s.evt_block_time) = p.minute
GROUP BY day
ORDER BY day;

Run this query in Dune, and you’ll get a daily volume series. Save it as a query named “Uniswap V3 Daily Volume”.

Advanced Query Techniques: Calculating TVL for Lending Protocols

To build a more advanced Dune dashboard for DeFi metrics, you need to calculate Total Value Locked (TVL) for lending protocols like Compound or Aave. TVL is the sum of supplied assets in USD across all markets. Dune provides a view table for each protocol that snapshots the state periodically. For Compound V2, use compound_v2_view_market.

Here is a query to get TVL in ETH (or USD) by aggregating each market’s total supply:

WITH markets AS (
SELECT
underlying_symbol,
total_supply / 1e18 AS supply,
block_time
FROM compound_v2_view_market
WHERE underlying_symbol IN ('ETH', 'DAI', 'USDC')
)
SELECT
DATE_TRUNC('day', block_time) AS day,
SUM(supply) AS tvl_eth
FROM markets
GROUP BY day
ORDER BY day;

For USD value, join with a price oracle table. Dune’s prices.usd covers most ERC20 tokens. Use LATEST ON or a subquery to get the nearest price for each market. A common technique is to create a CTE for the latest price per token per hour and then join on hour truncated.

Performance tip: Instead of joining on every row, materialize the price feed into a separate query that returns hourly prices, then cross-join with market snapshots. This reduces data shuffling and speeds up execution on Dune’s cluster.

Choosing the Right Visualization for Your Metric

Dune’s visualization tool supports line, bar, area, pie, table, counter, and more. The best choice depends on the metric. For time series like daily volume or TVL, a line chart is most informative. For comparing multiple protocols (e.g., Aave vs. Compound supply rate), a grouped bar chart works well. Use a counter for a current TVL snapshot or total users.

Metric TypeRecommended ChartExample Use
Time-series (single)LineDaily Uniswap volume
Time-series (multiple)Multi-lineTVL of top 5 lending protocols
Composition over timeStacked areaDominance of stablecoins
DistributionHistogramLoan size distribution
Single valueCounterCurrent total value locked
Grid of tokensTableToken balances for a wallet

To create a visualization, go to the Visualization tab after running a query, choose the chart type, then configure axes, labels, and colors. Dune automatically suggests a chart based on your columns, but you can override.

A well-chosen chart makes your Dune dashboard for DeFi metrics immediately understandable. Avoid pie charts for time-series or for many categories; they become unreadable with more than 5 slices.

Assembling Your Dashboard: Layout and Best Practices

Once you have several queries with visualizations, you can combine them into a dashboard. In Dune, click New Dashboard, give it a name like “DeFi Market Monitor”, and start adding visualizations by searching for your saved queries. Arrange them by dragging and dropping. A good layout follows a narrative: start with a broad overview (e.g., total market TVL counter), then drill down into specific protocols, and finally show transaction activity or fee generation.

Best practices for a Dune dashboard for DeFi metrics:

Remember that dashboards are public by default. Before publishing, test all interactions and ensure queries run within the free tier limits.

Adding Interactivity with Parameters and Filters

Parameters are one of the most powerful features in Dune. They allow dashboard viewers to dynamically change the query without rewriting SQL. For example, you can add a date_from parameter to your volume query:

SELECT * FROM uniswap_v3_evt_swap
WHERE evt_block_time >= '{{date_from}}';

In the query editor, wrap the variable in double curly braces. Then, in the dashboard, Dune automatically creates a date picker widget. You can also use parameters for token addresses:

WHERE token_address = '{{token_address}}'

This makes your Dune dashboard for DeFi metrics highly reusable. For instance, a “Token Explorer” dashboard could accept any ERC20 address and show its transfers, holders, and price.

Parameters can be of type: text, number, date, list, or link. Use the list type with a predefined set of values (e.g., protocol names) for cleaner input. You can also set default values.

Another interactivity trick: use chart cross-filtering (available in Dune’s embedding mode) to let clicking on a chart segment filter other charts on the same dashboard. This is advanced but makes your dashboard truly dynamic.

Optimizing Your Dune Queries for Speed and Cost

Every query on Dune consumes credits. To keep your Dune dashboard for DeFi metrics cost-effective and fast, follow these optimization principles:

For heavy dashboards, consider using Dune’s Materialized Views (available on premium plans) to precompute daily aggregations. Or, create a separate query that runs once a day and store results in a static table using Dune’s Export to Google Sheets feature.

Sharing and Maintaining Your Dune Dashboard for DeFi Metrics

Once your dashboard is polished, share it with the community. Dune allows you to make a dashboard public, and it will appear in search results. You can also embed public dashboards on your own website using an iframe. The URL format is: https://dune.com/your-username/dashboard-title.

Maintenance is crucial. DeFi protocols upgrade, and Dune may deprecate or rename tables. Subscribe to Dune’s changelog or follow Dune’s official account on X for updates. Periodically check that your queries still run. Use the Refresh button manually after network upgrades.

For a long-lived Dune dashboard for DeFi metrics, adopt version control: keep a private fork of your dashboard for testing, and only update the public version after verifying new queries. Add a changelog in a text widget so users know when data was last updated.

Finally, consider monetization: while Dune dashboards are free to build, you can offer custom dashboards to protocols or DAOs in exchange for tokens. Many analysts now earn a living by maintaining high-quality dashboards for DeFi teams.

Step-by-step

  1. Sign up for Dune Analytics and explore the dataset browser to understand the schema for protocols like Uniswap V3 and Compound.
  2. Write a basic SQL query to extract daily DEX volume from uniswap_v3_evt_swap, joining with prices.usd for USD conversion.
  3. Create a CTE-based query to calculate TVL for a lending protocol using compound_v2_view_market and aggregate daily supplies.
  4. Test and optimize your queries: add time filters, use limits, and avoid unnecessary joins. Use EXPLAIN ANALYZE to check performance.
  5. Turn each query into a visualization by selecting chart type (line, bar, counter) and configuring axes, labels, and colors in the Visualization tab.
  6. Create a new dashboard, add your saved visualizations, and arrange them in a logical layout with consistent time ranges.
  7. Add parameters (e.g., date range, token address) to make your dashboard interactive. Set default values and test user inputs.
  8. Publish your dashboard publicly, share the URL, and schedule regular refreshes (daily or hourly) to keep data current.
  9. Monitor your queries for schema changes and update CTEs or table names as protocols upgrade. Maintain a change log for transparency.

Common mistakes to avoid

Frequently asked questions

How long does it take to learn Dune for DeFi analytics?

If you have basic SQL knowledge, you can build your first Dune dashboard for DeFi metrics within a week. Mastering advanced techniques like parameters and materialized views may take 2–3 weeks of practice.

Can I use Dune for blockchains other than Ethereum?

Yes, Dune now supports Polygon, Solana, BNB Chain, Arbitrum, Optimism, Avalanche, and more. Each blockchain has separate datasets, but the SQL logic is largely transferable.

What SQL dialect does Dune use?

Dune uses DuneSQL, a query engine based on Trino. Common functions like DATE_TRUNC, SUM, and JOIN work as expected. Window functions and CTEs are fully supported.

How often should I refresh my Dune dashboard?

For most DeFi metrics (volume, TVL, rates), refreshing once per day is sufficient. For high-frequency trading metrics, refresh more often. Note that automatic scheduled refreshes are a paid-plan feature on Dune; free accounts refresh manually.

Track the entities behind the concepts

DeFi Intel maps 11,000+ protocols, tokens and companies to a typed knowledge graph — with live data, incidents and regulation.

Entities mentioned