select
date_trunc(month,block_timestamp)::date as date
,case
when action in('DelegatorTokensCommitted','TokensCommitted') then 'Stake'
when action in ('DelegatorUnstakedTokensWithdrawn','UnstakedTokensWithdrawn') then 'Unstake'
else null
end as type
,count(tx_id) as tx_count
,count(DISTINCT DELEGATOR) as delegators
,count(DISTINCT node_id) as nodes
,sum(amount) as volume
,avg(amount) as avg_volume
,sum(tx_count) over(partition by type order by date) as growth_tx_count
,sum(delegators) over(partition by type order by date) as growth_delegators
,sum(volume) over(partition by type order by date) as growth_volume
from flow.core.ez_staking_actions
where TX_SUCCEEDED=true
and type is not null
group by 1,2
order by 1