misaghlbTerradash Part 2: Staking and Supply
    Updated 2022-12-08
    -- select *
    -- from terra.classic.ez_staking
    -- where 1=1
    -- -- and tx_succeeded = 'TRUE'
    -- -- and action in ('Redelegate')
    -- -- and tx_id = '390033BAF5D3A91D1A3BC4B19E0DF9448C9EF1F23F2427E21B6B39A2ECE588F5'
    -- and DELEGATOR_ADDRESS = 'terra12079m57cew2v02zs624zvyed5479an9wxcrveh'
    -- order by BLOCK_ID DESC
    -- limit 19
    with raw as (
    select DELEGATOR_ADDRESS,
    sum(case when action in ('Delegate') then amount end) as staked_amount,
    sum(case when action in ('Undelegate') then amount end) as unstaked_amount,
    sum(case when action in ('Redelegate') then amount end) as restaked_amount,
    staked_amount + (restaked_amount - staked_amount) - unstaked_amount as allvol,
    sum(case when action in ('Delegate') then amount when action in ('Undelegate') then amount * -1 end) as net_staked
    -- 127475474 as circulating_supply,
    -- (net_staked / circulating_supply * 100) as circulating_supply_to_staked
    from terra.core.ez_staking
    where tx_succeeded = 'TRUE'
    GROUP by DELEGATOR_ADDRESS
    -- limit 3
    )
    SELECT sum(allvol) as staked,
    127475474 as circulating_supply,
    (staked / circulating_supply * 100) as circulating_supply_to_staked
    from raw
    Run a query to Download Data