Query editor
WITH-- Find tokens launched recentlyrecent_launches AS (SELECTtoken_bought_address AS token_address,MIN(block_time) AS launch_timeFROM dex.tradesWHERE blockchain = 'base'GROUP BY token_bought_addressHAVING MIN(block_time) > CURRENT_DATE - INTERVAL '1' month),-- Track all buys of these tokenstoken_buys AS (SELECTt.tx_from AS trader,t.token_bought_address AS token_address,t.block_time AS tx_time,t.tx_hash,'buy' AS tx_type,t.token_bought_amount AS token_amount,t.amount_usd AS usd_value,rl.launch_time,-- Flag whether this is within first minute (potential insider)CASE WHEN t.block_time < rl.launch_time + INTERVAL '1' minute THEN 1 ELSE 0 END AS is_first_minute,-- Rank buys chronologically for each trader/token pairROW_NUMBER() OVER (PARTITION BY t.tx_from, t.token_bought_address ORDER BY t.block_time) AS buy_seqFROM dex.trades tJOIN recent_launches rl ON t.token_bought_address = rl.token_addressWHEREt.blockchain = 'base'AND t.block_time > CURRENT_DATE - INTERVAL '1' monthAND t.token_sold_address IN (0x4200000000000000000000000000000000000006, 0x833589fcd6edb6e08f4c7c32d4f71b54bda02913)AND token_bought_amount is not Null),-- Track all sells of these tokenstoken_sells AS (SELECTt.tx_from AS trader,t.token_sold_address AS token_address,t.block_time AS tx_time,t.tx_hash,'sell' AS tx_type,t.token_sold_amount AS token_amount,t.amount_usd AS usd_value,b.launch_time,-- Rank sells chronologically for each trader/token pairROW_NUMBER() OVER (PARTITION BY t.tx_from, t.token_sold_address ORDER BY t.block_time) AS sell_seqFROM dex.trades tJOIN (SELECT DISTINCT trader, token_address, launch_time FROM token_buys) bON t.tx_from = b.trader AND t.token_sold_address = b.token_addressWHEREt.blockchain = 'base'AND t.block_time > CURRENT_DATE - INTERVAL '1' monthAND t.token_bought_address IN (0x4200000000000000000000000000000000000006, 0x833589fcd6edb6e08f4c7c32d4f71b54bda02913)AND token_sold_amount is not Null),-- Combine buys and sells into a single timeline