Query editor
WITHtrades AS (SELECTtx_id,COUNT(*) AS tx_hops,COUNT(DISTINCT project) AS protocols_routed_throughFROM dex_solana.tradesWHEREblock_date = DATE '2025-11-06'GROUP BY tx_idHAVINGCOUNT(*) BETWEEN 2 AND 3AND COUNT(DISTINCT project) BETWEEN 2 AND 3),trade_directions AS (-- Retain transactions whose symbol flow closes a full loopSELECTtx_id,MIN(CASE WHEN rn = 1 THEN token_sold_symbol END) AS first_sold,MAX(CASE WHEN rn = max_rn THEN token_bought_symbol END) AS last_boughtFROM (SELECTtx_id,token_sold_symbol,token_bought_symbol,ROW_NUMBER() OVER (PARTITION BY tx_id ORDER BY outer_instruction_index, inner_instruction_index) AS rn,COUNT(*) OVER (PARTITION BY tx_id) AS max_rnFROM dex_solana.tradesWHERE block_date = DATE '2025-11-06') rankedGROUP BY tx_idHAVING MIN(CASE WHEN rn = 1 THEN token_sold_symbol END) =MAX(CASE WHEN rn = max_rn THEN token_bought_symbol END)),ranked_transfers AS (SELECT*,ROW_NUMBER() OVER (PARTITION BY tx_id, outer_instruction_index, symbolORDER BY inner_instruction_index) AS symbol_occurrenceFROM tokens_solana.transfersWHEREdate_trunc('day', block_time) = DATE '2025-11-06'AND tx_id IN (SELECT tx_id FROM trade_directions)AND from_owner != to_owner),first_transfers AS (-- Identify *every outbound send* of each symbol by the wallet/router.-- We keep symbol_occurrence = 1 to indicate the first appearance within that outer index.SELECTtx_id,symbol,outer_instruction_index,inner_instruction_index AS start_inner_index,amount_usd AS entry_amount_usd,from_owner AS entry_from_owner,