Ready to Build Your Analytics Dashboard?
Get expert guidance on on-chain analytics and Dune dashboard setup.
Tool Workspace
Use, understand, and apply the results
Tool Overview
Every production blockchain protocol needs on-chain analytics for transparency and decision-making. Here are the SQL query templates for Dune Analytics.
Key Result
Dune Analytics SQL query templates for blockchain protocols: Protocol TVL Dashboard (daily TVL tracking with USDC pricing), Unique Users Query (weekly depositor count and cumulative users), Protocol Revenue Query (daily fee revenue, annualized run rate). Shareable Dune Dashboard template with 6 panels: TVL (line chart), Daily Volume (bar chart), Unique Depositors (counter + line), Protocol Revenue (bar + cumulative), Top Depositors Table (whale concentration), Oracle Health (price feed staleness and divergence).
Protocol TVL Dashboard Query (Dune Analytics)
-- Dune SQL: Track protocol TVL over time
-- Replace contract_address with your vault/pool address
WITH daily_balances AS (
SELECT
DATE_TRUNC('day', block_time) AS day,
SUM(CASE WHEN to = 0xYOUR_CONTRACT_ADDRESS
THEN value ELSE -value END)
/ 1e6 AS usdc_delta -- USDC has 6 decimals
FROM erc20_ethereum.evt_Transfer
WHERE (to = 0xYOUR_CONTRACT_ADDRESS
OR "from" = 0xYOUR_CONTRACT_ADDRESS)
AND contract_address = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 -- USDC
AND block_time >= DATE '2024-01-01'
GROUP BY 1
),
cumulative AS (
SELECT
day,
SUM(usdc_delta) OVER (ORDER BY day) AS tvl_usdc
FROM daily_balances
)
SELECT
day,
tvl_usdc,
tvl_usdc * eth_price.price AS tvl_usd
FROM cumulative
LEFT JOIN prices.usd eth_price
ON eth_price.symbol = 'USDC'
AND eth_price.minute = DATE_TRUNC('minute', cumulative.day)
ORDER BY day DESCUnique Users Query
-- Count unique depositors per week
SELECT
DATE_TRUNC('week', block_time) AS week,
COUNT(DISTINCT "from") AS new_depositors,
COUNT(DISTINCT "from") OVER (ORDER BY DATE_TRUNC('week', block_time)) AS cumulative_users
FROM erc20_ethereum.evt_Transfer
WHERE to = 0xYOUR_CONTRACT_ADDRESS
AND contract_address = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
AND block_time >= DATE '2024-01-01'
GROUP BY 1
ORDER BY 1 DESCProtocol Revenue Query
-- Track fee revenue collected by protocol treasury
WITH fee_events AS (
SELECT
DATE_TRUNC('day', block_time) AS day,
SUM(CAST(data AS DOUBLE) / 1e6) AS daily_fees_usdc
FROM ethereum.logs
WHERE contract_address = 0xYOUR_CONTRACT
AND topic0 = 0xFEE_COLLECTED_EVENT_SIGNATURE
AND block_time >= DATE '2024-01-01'
GROUP BY 1
)
SELECT
day,
daily_fees_usdc,
SUM(daily_fees_usdc) OVER (ORDER BY day) AS cumulative_fees_usdc,
daily_fees_usdc * 365 AS annualized_revenue_rate
FROM fee_events
ORDER BY day DESCShareable Dune Dashboard Template
PROTOCOL NAME — Analytics Dashboard
PANEL 1: TVL (Line Chart) — X-axis: Date | Y-axis: TVL in USD
PANEL 2: Daily Volume (Bar Chart) — X-axis: Date | Y-axis: Volume USD
PANEL 3: Unique Depositors (Counter + Line) — Total unique depositors + New depositors per week
PANEL 4: Protocol Revenue (Bar + Cumulative Line) — Daily fee revenue + Cumulative + Annualized run rate
PANEL 5: Top Depositors Table — Address | Balance | % of TVL | First Deposit Date
PANEL 6: Oracle Health — Price feed last updated (must be < 1 hour ago), Divergence between Chainlink and TWAP (must be < 1%)