--credit : 0xHaM-d
with pricet as (
select
timestamp::date as day,
token_contract,
symbol,
avg (price_usd) as USDPrice
from flow.core.fact_prices
group by 1,2,3
)
select
date_trunc('month',block_timestamp) as date,
sum(amount*usdprice) as Volume,
avg(amount*usdprice) as Average_Volume
from flow.core.ez_token_transfers t1 join pricet t2 on t1.block_Timestamp::Date = t2.day and t1.token_contract = t2.token_contract
where tx_succeeded = 'TRUE'
and block_Timestamp >= '2022-01-01'
group by 1
order by 1