Query editor
WITH monthly_trades AS (SELECTdt.trader_address,dt.volume_usd,t.total_fees,dt.block_date,dt.token_sold_address,dt.token_bought_addressFROM ton.dex_trades dtLEFT JOIN ton.transactions t ON dt.tx_hash = t.hashWHERE dt.project = 'dedust'AND dt.block_date >= DATE_TRUNC('month', CURRENT_DATE) - INTERVAL '1' MONTHAND dt.block_date < DATE_TRUNC('month', CURRENT_DATE)AND dt.volume_usd > 0),trader_metrics AS (SELECTtrader_address AS "Trader Address",ROUND(SUM(volume_usd), 2) AS "Total Trading Volume USD",COUNT(*) AS "Total Trades",COUNT(DISTINCT CONCAT(token_sold_address, token_bought_address)) AS "Unique Trading Pairs",ROUND(COALESCE(SUM(CAST(COALESCE(total_fees, 0) AS DOUBLE PRECISION) / 1e9), 0), 6) AS "DeDust Fees Paid TON",ROUND(SUM(volume_usd) / COUNT(*), 2) AS "Average Volume Per Trade USD",ROUND(COALESCE(SUM(CAST(COALESCE(total_fees, 0) AS DOUBLE PRECISION) / 1e9) / COUNT(*), 0), 6) AS "Average Fee Per Trade TON"FROM monthly_tradesGROUP BY trader_address),treasure_hunt AS (SELECT"Trader Address","Total Trading Volume USD","Total Trades","Unique Trading Pairs","DeDust Fees Paid TON","Average Volume Per Trade USD","Average Fee Per Trade TON",ROUND("DeDust Fees Paid TON" / NULLIF("Total Trading Volume USD", 0), 6) AS "Fee to Volume Ratio",CASEWHEN ("DeDust Fees Paid TON" / NULLIF("Total Trading Volume USD", 0)) > 0.0001 THEN 'Vault Raider'ELSE 'Market Wanderer'END AS "Treasure Hunter Status"FROM trader_metricsORDER BY "Total Trading Volume USD" DESCLIMIT 100),treasure_summary AS (SELECT"Treasure Hunter Status",COUNT(*) AS "Trader Count",ROUND(CAST(COUNT(*) AS DOUBLE) / 100 * 100, 1) AS "Percentage of Traders",AVG("Fee to Volume Ratio") AS "Average Fee to Volume Ratio"FROM treasure_huntGROUP BY "Treasure Hunter Status")SELECT"Treasure Hunter Status" AS "Label","Trader Count" AS "Value","Average Fee to Volume Ratio" AS "Description"FROM treasure_summaryORDER BY "Trader Count" DESC;