Query editor
-- This query used incompatible data types from Dune SQL alpha and may need to be updated.-- More details can be found on https://dune.com/docs/query/dunesql-changes/withswaps as (selectdate_trunc('minute', call_block_time) as time, t2."from" as raw_source, t1."from" as direct_source, row_number() over (partition by t2.tx_hash, s.call_trace_address order by cardinality(t2.trace_address) desc) as rn-- for frequency later, s.call_tx_hash as tx_hash-- for volume, case when cast(s.amount0Out as double) = 0 then cast(s.amount1Out as double)else cast(s.amount0Out as double)end as raw_amount, case when cast(s.amount0Out as double) = 0 then token1else token0end as token_addressfrom uniswap_v2_ethereum.Pair_call_swap sleft join uniswap_v2_ethereum.Factory_evt_PairCreated pcon pc.pair = s.contract_address/**- find caller of the caller of the swap- from (caller of the caller) -> to (caller) [traces2] [0, 0, 5, 1]- from (caller) -> to (pair contract for swapping) [traces1] [0, 0, 5, 1, 5]--> traces1.trace_address = s.call_trace_address--> traces1.from = traces2.to--> cardinality(traces2.trace_address) <= cardinality(traces1.trace_address)*/left join ethereum.traces t1on t1.tx_hash = s.call_tx_hashand t1.block_time = s.call_block_timeand t1.trace_address = s.call_trace_addressleft join ethereum.traces t2on t1.tx_hash = t2.tx_hashand t1.block_time = t2.block_timeand t1."from" = t2.to and t1."from" != t2."from"and COALESCE(cardinality(t2.trace_address), 0) <= COALESCE(cardinality(t1.trace_address), 0)where 1=1and s.call_block_time >= now() - interval '8' monthand s.contract_address = {{Pair Address}} -- USDC/WETH by defaultand t1.success and t2.successand t1.call_type = 'call' and t2.call_type = 'call'), inter_swaps as (select * from swapswhere rn = 1 -- taking the closest caller of the caller (from from)), labeled_swaps as (