with pricet as (
select block_timestamp::date as day,
swap_from_mint as token,
avg (swap_to_amount/swap_from_amount) as USDPrice
from solana.fact_swaps
where swap_to_mint in ('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v','Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB') --USDC,USDT
and swap_to_amount > 0
and swap_from_amount > 0
and block_timestamp >= CURRENT_DATE - 7
and succeeded = 'TRUE'
group by 1,2)
select block_timestamp::date as date,
count (distinct tx_id) as Swaps_Count,
count (distinct swapper) as Swappers_Count,
sum (swap_from_amount*usdprice) as USD_Volume,
avg (swap_from_amount*usdprice) as Average_USD_Volume
from solana.core.fact_swaps t1 join pricet t2 on t1.block_timestamp::Date = t2.day and t1.swap_from_mint = t2.token
where succeeded = 'TRUE'
and block_timestamp >= CURRENT_DATE - 30
group by 1
order by 1