cypherTerra2 dash - supply - staking rewards
    Updated 2023-03-15
    with price as (
    select
    date_trunc('day', recorded_hour) as date,
    (avg(open) + avg(close)) / 2 as price
    from crosschain.core.fact_hourly_prices
    where id = 'terra-luna-2'
    group by 1
    ),

    rewards as (select
    date_trunc('day', block_timestamp) as date,
    sum(amount::number/1e6) as total_reward

    from terra.core.ez_transfers
    where
    tx_succeeded = 'TRUE' and
    currency = 'uluna' and
    message_type = '/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward'
    group by date),

    final as (select * from rewards
    left join price using (date))

    select *, total_reward*price as reward_usd
    from final

    Run a query to Download Data