Query editor
-- We will be finding the most profitable and user-preferred trading pairsWITH pair_analysis AS (SELECTCASEWHEN token_bought_symbol < token_sold_symbolTHEN token_bought_symbol || '/' || token_sold_symbol -- keeping the format in this representation USDT/WETHELSE token_sold_symbol || '/' || token_bought_symbolEND as trading_pair,COUNT(DISTINCT tx_from) as unique_traders,COUNT(*) as total_trades,SUM(amount_usd) as total_volume,AVG(amount_usd) as avg_trade_size,COUNT(DISTINCT DATE_TRUNC('day', block_time)) as active_days,COUNT(*) * 1.0 / COUNT(DISTINCT tx_from) as trades_per_trader,COUNT(DISTINCT tx_from) * 1.0 / COUNT(DISTINCT DATE_TRUNC('day', block_time)) as daily_traders_avg,SUM(CASE WHEN block_time >= NOW() - INTERVAL '7' day THEN amount_usd ELSE 0 END) as volume_last_7d,SUM(CASE WHEN block_time >= NOW() - INTERVAL '14' day AND block_time < NOW() - INTERVAL '7' dayTHEN amount_usd ELSE 0 END) as volume_prev_7dFROM dex.tradesWHERE blockchain = 'ethereum'AND project = 'uniswap'AND block_time >= NOW() - INTERVAL '30' dayAND token_bought_symbol IS NOT NULLAND token_sold_symbol IS NOT NULLGROUP BY 1)SELECTtrading_pair,unique_traders,total_volume,volume_last_7d,CASEWHEN volume_prev_7d > 0THEN (volume_last_7d - volume_prev_7d) * 100.0 / volume_prev_7dELSE 100END as volume_growth_pct,trades_per_trader,daily_traders_avg,-- Composite score for prioritization(LN(CAST(unique_traders AS DOUBLE)) * 0.3 +LN(CAST(GREATEST(volume_last_7d, 1) AS DOUBLE)) * 0.4 +(CASE WHEN trades_per_trader > 2 THEN 1 ELSE 0.5 END) * 0.2 +(CASEWHEN volume_prev_7d > 0AND (volume_last_7d - volume_prev_7d) * 100.0 / volume_prev_7d > 20THEN 1ELSE 0.5END) * 0.1) AS priority_scoreFROM pair_analysisWHERE total_volume > 100000 -- Minimum volume thresholdAND unique_traders > 10 -- Minimum user baseORDER BY priority_score DESCLIMIT 20;