nitsStaking Distribution
    Updated 2022-05-25
    WITH a AS (
    SELECT DISTINCT tx_id
    FROM ethereum.events_emitted
    WHERE contract_address = LOWER('0xa5f2211B9b8170F694421f2046281775E8468044')
    ), b AS (
    SELECT *
    FROM ethereum.events_emitted e
    JOIN a ON a.tx_id = e.tx_id
    WHERE tx_to_address = LOWER('0x815c23eca83261b6ec689b60cc4a58b54bc24d8d')
    AND event_name = 'Deposit'
    ),
    a_ AS (
    SELECT DISTINCT tx_id
    FROM ethereum.events_emitted
    WHERE contract_address = LOWER('0xa5f2211B9b8170F694421f2046281775E8468044')
    ), b_ AS (
    SELECT *
    FROM ethereum.events_emitted e
    JOIN a_ ON a_.tx_id = e.tx_id
    WHERE tx_to_address = LOWER('0x815c23eca83261b6ec689b60cc4a58b54bc24d8d')
    AND event_name = 'Withdraw'
    ),
    staked_data as
    (SELECT tx_from_address, sum(event_inputs:value)/pow(10,18) as amt, count(*) as total_txs from b
    GROUP by 1 ),
    unstaked_amt as
    (SELECT tx_from_address, sum(event_inputs:amount)*(-1)/pow(10,18) as amt, count(*) as total_txs from b_
    GROUP by 1)

    SELECT CASE WHEN net_thor< pow(10,2) and net_thor> '0' then '0-100'
    WHEN NET_THOR> pow(10,2) and net_thor< pow(10,3) then '100-1k'
    WHEN NET_THOR> pow(10,3) and net_thor< pow(10,4) then '1k-10k'
    WHEN NET_THOR> pow(10,4) and net_thor< pow(10,5) then '10k-100k'
    WHEN NET_THOR> pow(10,5) and net_thor< pow(10,6) then '100k-1M'
    WHEN NET_THOR> pow(10,6) then '1M+' end as distribution, sum(net_thor) as total_amt_staked, count(DISTINCT tx_from_address) as total_users from
    (SELECT tx_from_address, sum(amt) as net_thor, sum(total_txs) as total_tx
    Run a query to Download Data