Query editor
withprogram_logged as (SELECTouter_instruction_index, sum(inner_instruction) over (partition by outer_instruction_index, id order by log_index asc) as inner_instruction_index, invoke_tracker, success_tracker, log_index, logs, id, block_slot, block_timeFROM (SELECTsum(CASE WHEN logs LIKE 'Program %% invoke [1]%' then 1 else 0 end) over (partition by id order by log_index asc) as outer_instruction_index, CASE WHEN logs LIKE 'Program %% invoke [%]%' AND logs not like 'Program %% invoke [1]%' then 1 else 0 end as inner_instruction, CASE WHEN logs LIKE 'Program %% invoke%' then split(log_messages.logs, ' ')[2] else null end as invoke_tracker, CASE WHEN logs LIKE 'Program %% success%' then split(log_messages.logs, ' ')[2] else null end as success_tracker, log_index, log_messages.logs, id, block_slot, block_timeFROM solana.transactions txLEFT JOIN unnest(log_messages) WITH ORDINALITY as log_messages(logs, log_index) ON TrueWHERE 1=1and success = trueand contains(account_keys, 'TSWAPaqyCSx2KABk68Shruf4rp7CxcNi8hAsbdwmHbN') --check for tensor-- tensor BuySellEventand id = 'tW3expB3ozDocV84UvDodjAoBMR43RXmiASGwC4uWymyVstDqNifoF4gMXJVCjjQSmbnSYWEfAr8owZHPHv3QfE'and block_slot = 212651592)), program_end as (SELECTouter_instruction_index, inner_instruction_index, invoke_tracker, log_index, end_log_index, id, block_timeFROM (SELECTpl_start.*, pl_end.log_index as end_log_index, row_number() over (partition by pl_start.id, pl_start.invoke_tracker, pl_start.log_index order by pl_end.log_index asc) as first_endFROM program_logged pl_startLEFT JOIN program_logged pl_end ON pl_start.id = pl_end.id AND pl_start.invoke_tracker = pl_end.success_tracker AND pl_end.log_index > pl_start.log_index)WHERE first_end = 1), ordered_logs as (SELECTouter_instruction_index, inner_instruction_index, program_id, log_index