winnie-fsTerra Tax Rate Calculations
    Updated 2022-02-20
    with tax_rate as (
    select
    date_trunc('day', block_timestamp) as date,
    block_timestamp,
    case when block_timestamp > '2020-10-03T14:56:11Z' then block_id + 3820000 else block_id end as new_block_id,
    floor(new_block_id/(10*60*24*7), 0) as epoch, --epoch is one week, based on 10 blocks/min target block time. actual epoch time is different due to non-constant block times.
    event,
    transition_type,
    event_attributes:tax_rate as tax_rate,
    event_attributes:reward_weight as reward_weight
    from terra.transitions
    where event in ('policy_update')
    and block_timestamp > '2020-04-01'
    order by 1
    ),


    rewards as (
    select
    floor(case when block_timestamp > '2020-10-03T14:56:11Z' then block_id + 3820000 else block_id end/(10*60*24*7), 0) as epoch,
    date_trunc('day', max(block_timestamp)) as date,
    sum(event_amount_usd) as reward_usd
    from terra.reward
    where date_trunc('day', block_timestamp) > '2020-04-01'
    group by 1
    order by 1
    ),

    staked_luna as (
    SELECT
    date,
    sum(balance_usd) as staked_luna_usd,
    sum(balance) as staked_luna
    from terra.daily_balances
    where currency = 'LUNA'
    and balance_type = 'staked'
    Run a query to Download Data