Sbhn_NPstake terra
    Updated 2022-12-15
    --credit : https://app.flipsidecrypto.com/velocity/queries/47efda77-58e2-4ff4-9221-87240f63b51d
    with luna_price as(select
    date_trunc('day',RECORDED_HOUR) as date,
    avg(CLOSE) as price
    from crosschain.core.fact_hourly_prices
    where ID ilike 'terra-luna-2'
    group by 1
    ),
    main as(select
    date_trunc('day',BLOCK_TIMESTAMP) as date,
    action as type,
    count(TX_ID) as stake_txs,
    count(DISTINCT DELEGATOR_ADDRESS) as users,
    sum(amount) as volume
    from terra.core.ez_staking
    where TX_SUCCEEDED = TRUE
    group by 1,2
    )
    select
    a.date,
    type,
    price,
    stake_txs,
    users,
    volume,
    sum(stake_txs) over (order by a.date) as cum_txs,
    sum(users) over (order by a.date) as cum_users,
    sum(volume) over (order by a.date) as cum_volume
    from main a
    join luna_price b on a.date=b.date
    Run a query to Download Data