nsa2000Weekly variation of the Osmosis Nakamoto Coefficient
    Updated 2022-11-10
    with tab1 as (
    SELECT
    date_trunc('week', block_timestamp) as day,
    validator_address,
    sum(CASE WHEN action LIKE 'undelegate' THEN (amount / power(10,6)) * -1
    else (amount / power(10,6)) end) as token_flow
    FROM osmosis.core.fact_staking
    --WHERE action LIKE 'undelegate'
    where currency LIKE 'uosmo'
    AND REDELEGATE_SOURCE_VALIDATOR_ADDRESS is NULL
    GROUP BY 1,2
    ), tab2 as (
    SELECT
    date_trunc('week', block_timestamp) as day,
    REDELEGATE_SOURCE_VALIDATOR_ADDRESS as validator_address,
    sum((amount / power(10,6)) * -1 ) as token_flow
    FROM osmosis.core.fact_staking
    --WHERE action LIKE 'undelegate'
    where currency LIKE 'uosmo'
    AND NOT REDELEGATE_SOURCE_VALIDATOR_ADDRESS is NULL
    GROUP BY 1,2
    ), tab3 AS (
    SELECT *
    FROM TAB1

    UNION

    SELECT *
    FROM TAB2
    ), tab4 as (
    SELECT
    DAY,
    validator_address,
    SUM(token_flow) AS TOKEN_FLOW_TOTAL
    Run a query to Download Data