with
swap_to_cte as (
select
BLOCK_TIMESTAMP::date date
, ORIGIN_FROM_ADDRESS
, amount_out amount
, tx_hash
from ethereum.core.ez_dex_swaps
where 1=1
and token_out = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
)
, swap_from_cte as (
select
BLOCK_TIMESTAMP::date date
, ORIGIN_FROM_ADDRESS
, amount_in amount
, tx_hash
from ethereum.core.ez_dex_swaps
where 1=1
and token_in = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
)
, union_cte as (
select
date
, swap_type
, sum(amount) amount
from (
select 'Swap to' swap_type, * from swap_to_cte
union all
select 'Swap from', * from swap_from_cte
)
group by 1,2
)
select
date
, swap_type