Query editor
WITH filtered AS (-- Combine filtering and extraction in one pass to reduce I/O-- Extract only what we need, when we need itSELECTblock_time,tx_id,-- Extract token immediately during scanCASEWHEN varbinary_length(data) = 406 THEN to_base58(varbinary_substring(data, 279, 32))WHEN varbinary_length(data) = 670 THEN to_base58(varbinary_substring(data, 543, 32))END AS token,-- Extract swap_type onceCASE varbinary_substring(data, 105, 1)WHEN 0x00 THEN 'buy'WHEN 0x01 THEN 'sell'END AS swap_type,-- Pre-calculate amounts (divide by 1e6 once)varbinary_to_bigint(varbinary_reverse(varbinary_substring(data, 106, 8))) / 1e6 AS input_amount,varbinary_to_bigint(varbinary_reverse(varbinary_substring(data, 114, 8))) / 1e6 AS output_amountFROM solana.instruction_callsWHERE-- partition pruning (huge)block_date >= DATE '{{start_date}}'AND block_date <= CURRENT_DATEAND tx_success = trueAND is_inner = trueAND executing_account = 'FUTARELBfJfQ8RDGhg1wdhddq1odMAJUePHFuBYfUxKq'AND inner_executing_account = 'FUTARELBfJfQ8RDGhg1wdhddq1odMAJUePHFuBYfUxKq'AND account_arguments[1] = 'DGEympSS4qLvdr9r3uGHTfACdN8snShk4iGdJtZPxuBC'AND cardinality(account_arguments) = 1-- cheap + selective varbinary checksAND varbinary_starts_with(data, 0xe445a52e51cb9a1d)AND varbinary_length(data) IN (406, 670)-- avoid array_joinAND any_match(log_messages, x -> strpos(x, 'SpotSwap') > 0)),clean AS (SELECTtoken,date_trunc('day', block_time) AS trading_date,swap_type,input_amount,output_amount,CASEWHEN swap_type = 'buy' THEN input_amount / NULLIF(output_amount, 0)WHEN swap_type = 'sell' THEN output_amount / NULLIF(input_amount, 0)END AS priceFROM filteredWHERE('__ALL__' IN ({{token_list}}) OR token IN ({{token_list}}))AND input_amount > 0AND output_amount > 0AND token IS NOT NULL),daily AS (SELECTtoken,