Updated 2023-01-10
    with tab1 as (
    select
    date_trunc('day', block_timestamp) as date1 ,
    sum(ATTRIBUTES:coin_received:amount) / power(10, 6) as Reward_volume

    from terra.core.ez_messages
    where message_type like '%MsgWithdrawDelegatorReward%'
    group by 1
    )

    , tab2 as (
    select
    date_trunc('day', block_timestamp) as date2,
    avg(to_amount/from_amount) as price_of_Luna


    from terra.core.ez_swaps
    where from_currency like 'uluna'
    and to_currency like '%B3504E092456BA618CC28AC671A71FB08C6CA0FD0BE7C8A5B5A3E2DD933CC9E4%'
    and to_amount < 10000000
    and from_amount < 10000000
    group by 1
    having price_of_Luna < 50)

    , tab3 as (
    select
    date1,
    price_of_luna * reward_volume as Staking_Rewards_USD

    from tab1 left outer join tab2 on
    date1 = date2
    where staking_rewards_usd is not null
    and date1 >= '2023-01-01'
    order by 1 )

    select
    Run a query to Download Data