rahocosmo fee 4 copy
    -- forked from Moe / cosmo fee 4 @ https://flipsidecrypto.xyz/Moe/q/untitled-query-6T7-KP



    with tb3 as (select
    date_trunc('day',RECORDED_HOUR) as day,
    avg(CLOSE) as price_token
    from crosschain.core.fact_hourly_prices
    where ID = 'terra-luna-2'
    group by 1)



    select
    date_trunc('week',block_timestamp) as date,
    'Terra' as chain,
    sum(FEE) as amount,
    sum((price_token)*FEE) as amount_usd,
    avg(price_token*FEE) as avg_usd,
    avg(avg_usd) OVER (ORDER BY date ROWS BETWEEN 7 PRECEDING AND CURRENT ROW) as MA_7_Days,
    sum(amount_usd) over (order by date) as cum_volume
    from terra.core.fact_transactions s left join tb3 b on s.BLOCK_TIMESTAMP::date=b.day
    where FEE_DENOM ilike '%uluna%' and block_timestamp>=current_date - {{days_back}}
    group by 1,2


    Run a query to Download Data