with prices as (
select block_timestamp::date as day,
swap_from_mint as mint,
median (swap_to_amount/swap_from_amount) as price_usd
from solana.fact_swaps
where swap_to_mint in ('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v','Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB')
and swap_to_amount > 0
and swap_from_amount > 0
and succeeded = 1
group by 1,2
),
wormhole as (
select distinct(tx_id) as tx_id
from solana.core.fact_events
where program_id = 'wormDTUJ6AWPNvk59vGQbDvGJmqbDTdgWgAqcLBCgUb'
)
select
label as type,
count(distinct tx_id) as txn_count,
count(distinct tx_from) as users_count,
txn_count / users_count as tx_per_user,
sum(amount * price_usd) as volume_usd,
volume_usd / users_count as volume_per_user,
avg(amount * price_usd) as volume_usd_avg,
median(amount * price_usd) as volume_usd_median
from solana.core.fact_transfers
join prices using (mint)
left outer join solana.core.dim_labels
on mint = address
where tx_id in (select tx_id from wormhole)
and block_timestamp::date = day
and day >= '2022-11-01'
and label is not null
group by label