Afonso_DiazGrouping stakers
    Updated 2024-09-06
    with

    pricet as (
    select
    hour::date as date,
    avg(price) as price_usd
    from flow.price.ez_prices_hourly
    where symbol = 'FLOW'
    group by 1
    ),

    main as (
    select
    tx_id,
    block_timestamp,
    delegator as user,
    amount,
    amount * price_usd as amount_usd,
    iff(action in ('DelegatorTokensCommitted', 'TokensCommitted'), 'Stake', 'Unstake') as action,
    node_id
    from flow.gov.ez_staking_actions
    left join pricet on block_timestamp::date = date
    where tx_succeeded = 1
    and block_timestamp::date >= '{{ date }}'
    ),

    users as (
    select
    user,
    count(distinct tx_id) as transactions
    from main
    where action = 'Stake'
    group by 1
    )

    select