Skip to content
Dune Analytics

@kroeger0x / Top DEX Pairs (by token address), Trailing 7 days

Top DEX Pairs (by token address), Trailing 7 days

Loading
 

About queries and results

Dune Analytics lets you explore, create, and share Ethereum analytics. You can find an endless amount of great queries and dashboards on Dune.

We have decoded Ethereum smart contract data so you can do powerful analysis with simple SQL queries and visualise the query results into beautiful graphs.

Dune Analytics is free for everyone forever. If you want extra features like private queries, export your results and more check out our Pro plan.

SQL query

1WITH
2prices AS (                                                                                       
3    SELECT minute,                                                         
4        contract_address,                                                                              
5        price
6    FROM prices.usd                                                                                    
7    WHERE minute > now() - interval '7 days'
8)
9, pair_volume AS (
10    select
11        CASE
12            WHEN (t.token_a_address)::VARCHAR > (t.token_b_address::VARCHAR)
13                THEN (t.token_a_address::VARCHAR)  || '-' || (t.token_b_address::VARCHAR)
14                ELSE (t.token_b_address::VARCHAR)  || '-' || (t.token_a_address::VARCHAR)
15        END AS pair
16        , (
17            CASE WHEN token_a_address = a.contract_address THEN token_a_amount * a.price -- Use token A when there's USD price for it                    
18            ELSE token_b_amount * b.price -- Else use token b                             
19            END   
20            ) AS usd_volume
21    FROM dex.trades t
22    LEFT JOIN prices a ON date_trunc('minute', block_time) = a.minute AND token_a_address = a.contract_address 
23    LEFT JOIN prices b ON date_trunc('minute', block_time) = b.minute AND token_b_address = b.contract_address 
24    WHERE
25        block_time > (now() - interval '7 days')...

SQL query results

Loading
 

Result visualizations

Top DEX Pairs (by token address), Trailing 7 days

Loading