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 (-- Find only transactions that start and end on the same symbol (true loops)SELECTtx_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))-- SELECT *-- FROM trade_directions,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 the first outbound transfer per symbolSELECTtx_id,