freemartianvote power test
    Updated 2022-11-22
    with delegations as (
    select
    date_trunc('hour', block_timestamp) as TIME,
    delegator_address,
    sum(amount)/pow(10,6) as delegation_amount
    from osmosis.core.fact_staking
    where action = 'delegate'
    and TX_STATUS = 'SUCCEEDED'
    group by TIME, delegator_address),

    undelegations as (
    select
    date_trunc('hour', block_timestamp) as TIME,
    delegator_address,
    sum(amount)/pow(10,6) as undelegation_amount
    from osmosis.core.fact_staking
    where action = 'undelegate'
    and TX_STATUS = 'SUCCEEDED'
    group by TIME, delegator_address
    )
    select
    d.TIME,
    d.delegator_address as delegator,
    delegation_amount,
    case
    when undelegation_amount is null then 0
    when undelegation_amount is not null then undelegation_amount
    end as undelegation_amount,
    case when delegation_amount - undelegation_amount is null then delegation_amount
    when delegation_amount - undelegation_amount is not null then delegation_amount - undelegation_amount
    end as staked_amount
    from delegations d left join undelegations u on d.delegator_address = u.delegator_address

    -- final as (
    -- select
    -- max(block_timestamp),
    Run a query to Download Data