select
date_trunc('week', block_timestamp) as date,
case when amount < 10 then 'Less Than 10'
when amount >= 10 and amount < 100 then '10 - 100'
when amount >= 100 and amount < 1000 then '100 - 1000'
when amount >= 1000 and amount < 10000 then '1000 - 10000'
else 'More Than 10000' end as dist,
count(distinct tx_id) as tx_count,
count(distinct delegator) as wallets,
count(distinct node_id) as nodes,
sum(amount) as vol,
avg(amount) as avg_vol,
sum(tx_count) over(partition by dist order by date) as cumu_tx_count,
sum(vol) over(partition by dist order by date) as cumu_vol
from flow.core.ez_staking_actions
where tx_succeeded = 'TRUE'
and action in ('DelegatorTokensCommitted', 'TokensCommitted')
group by date, dist