Query editor
with sig as (select sid, mint, slot, txi from dune.swaps_io.dataset_pf_sig_nov where chunk = 0),ev as (select token_mint_address mint, block_slot slot, tx_index txi, coalesce(outer_instruction_index,0)*1000+coalesce(inner_instruction_index,0) ii, to_owner owner, cast(amount as double) dfrom tokens_solana.transfers t where block_date >= date '2026-09-20' and token_mint_address in (select distinct mint from dune.swaps_io.dataset_pf_sig_nov where chunk = 0) and to_owner is not null and action in ('transfer','mint')union allselect token_mint_address, block_slot, tx_index, coalesce(outer_instruction_index,0)*1000+coalesce(inner_instruction_index,0), from_owner, -cast(amount as double)from tokens_solana.transfers t where block_date >= date '2026-09-20' and token_mint_address in (select distinct mint from dune.swaps_io.dataset_pf_sig_nov where chunk = 0) and from_owner is not null and action in ('transfer','burn')),bal as (select mint, slot, txi, ii, owner,sum(d) over (partition by mint, owner order by slot, txi, ii rows unbounded preceding) bfrom ev),cr as (select mint, slot, txi, ii,case when b > 0 and coalesce(lag(b) over (partition by mint, owner order by slot, txi, ii), 0) <= 0 then 1when b <= 0 and coalesce(lag(b) over (partition by mint, owner order by slot, txi, ii), 0) > 0 then -1 else 0 end cfrom bal),stream as (select mint, slot, txi, ii, c, cast(null as bigint) sid from cr where c <> 0union allselect mint, slot, txi, 1000000000, 0, sid from sig)select sid, h from (select sid, sum(c) over (partition by mint order by slot, txi, ii, sid nulls first rows unbounded preceding) h from stream) where sid is not null