HosseinUntitled Query
    Updated 2022-12-31
    with t1 as (
    select
    date_trunc('day', recorded_hour)::date as day,
    (avg(open) + avg(close)) / 2 as price
    from crosschain.core.fact_hourly_prices
    where id = 'terra-luna-2'
    group by day
    )

    select
    date_trunc('week', block_timestamp)::date as week,
    sum(amount::number / pow(10, 6)) as staking_rewards_luna,
    sum((amount::number / pow(10, 6)) * price) as staking_rewards_usd
    from terra.core.ez_transfers t2
    join t1
    on block_timestamp::date = day
    where
    currency = 'uluna'
    and tx_succeeded = 1
    and message_type = '/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward'
    group by week
    order by week asc
    Run a query to Download Data