Query editor
WITH tokens_with_both_projects AS (-- Block 1: Tokens involved in both 'pumpdotfun' and 'raydium'SELECTtoken_sold_mint_address AS token_mint_addressFROM dex_solana.tradesWHEREproject IN ('pumpdotfun', 'raydium')AND block_time >= CURRENT_TIMESTAMP - INTERVAL '24' HOURAND token_sold_mint_address != 'So11111111111111111111111111111111111111112'GROUP BY token_sold_mint_addressHAVING COUNT(DISTINCT project) = 2),wallets_that_bought_tokens AS (-- Block 2: Wallets that bought tokens from Block 1SELECTtoken_bought_mint_address,trader_idFROM dex_solana.tradesWHEREtoken_bought_mint_address IN (SELECT token_mint_address FROM tokens_with_both_projects)AND project = 'pumpdotfun'AND block_time >= CURRENT_TIMESTAMP - INTERVAL '24' HOUR),grouped_wallets AS (-- Block 3: Group wallets by tokensSELECTtoken_bought_mint_address,trader_idFROM wallets_that_bought_tokensGROUP BY token_bought_mint_address, trader_id),wallets_with_multiple_tokens AS (-- Block 4: Traders with multiple tokensSELECTtrader_id,COUNT(DISTINCT token_bought_mint_address) AS token_countFROM grouped_walletsGROUP BY trader_idHAVING COUNT(DISTINCT token_bought_mint_address) > 1),token_trader_pairs AS (-- Block 5: Create pairs of traders with shared tokensSELECTtoken_bought_mint_address,ARRAY_AGG(trader_id) AS tradersFROM grouped_walletsGROUP BY token_bought_mint_address),grouped_traders AS (-- Block 5 (continued): Identify overlapping trader pairsSELECTt1.trader_id,t2.trader_id AS grouped_trader_id,COUNT(DISTINCT t1.token_bought_mint_address) AS shared_token_count,ARRAY_AGG(DISTINCT t1.token_bought_mint_address) AS shared_tokensFROM grouped_wallets t1JOIN grouped_wallets t2ON t1.token_bought_mint_address = t2.token_bought_mint_addressAND t1.trader_id != t2.trader_idGROUP BY t1.trader_id, t2.trader_id