MLDZMNFPD2
    Updated 2022-11-14
    select
    date_trunc('{{Time_basis}}',BLOCK_TIMESTAMP) as date,
    CASE
    when ACTION in ('TokensCommitted','DelegatorTokensCommitted') then 'Stake'
    when action in ('DelegatorUnstakedTokensWithdrawn','UnstakedTokensWithdrawn') then 'Unstake'
    when action in ('DelegatorRewardTokensWithdrawn','RewardTokensWithdrawn') then 'Claim rewards'
    end as action_type,
    count(distinct tx_id) as no_txn,
    count(distinct DELEGATOR) as no_users,
    sum(AMOUNT) as total_flow,
    avg(amount) as avg_flow,
    median(amount)as median_flow,
    avg(avg_flow) OVER (partition by action_type ORDER BY date ROWS BETWEEN 7 PRECEDING AND CURRENT ROW) as MA_7_Days,
    sum(no_users) over (partition by action_type order by date) as cum_users,
    sum(no_txn) over (partition by action_type order by date) as cum_txn,
    sum(total_flow) over (partition by action_type order by date) as cum_volume

    from flow.core.ez_staking_actions
    where TX_SUCCEEDED='TRUE'
    and BLOCK_TIMESTAMP>=CURRENT_DATE- {{Time_period}}
    group by 1,2

    Run a query to Download Data