MahrooUntitled Query
    Updated 2022-11-08
    with DelegateTable as (
    select date_trunc (week,block_timestamp) as date,
    validator_address,
    sum (amount/pow(10,decimal)) as delegate_amount
    from osmosis.core.fact_staking
    where action in ('delegate')
    and tx_status = 'SUCCEEDED'
    group by 1,2),

    UndelegateTable as (
    select date_trunc (week,block_timestamp) as date,
    validator_address,
    sum (amount/pow(10,decimal)) as undelegate_amount
    from osmosis.core.fact_staking
    where action in ('undelegate')
    and tx_status = 'SUCCEEDED'
    group by 1,2),

    RedelegateTable as (
    select date_trunc (week,block_timestamp) as date,
    redelegate_source_validator_address,
    sum (amount/pow(10,decimal)) as redelegate_amount
    from osmosis.core.fact_staking
    where action in ('redelegate')
    and tx_status = 'SUCCEEDED'
    group by 1,2),

    topvalidators as (
    select t1.validator_address,
    sum ((delegate_amount + redelegate_amount) - undelegate_amount)::numeric as Net_Delegate_Amount
    from DelegateTable t1 join UndelegateTable t2 on t1.validator_address = t2.validator_address
    join RedelegateTable t3 on t1.validator_address = t3.redelegate_source_validator_address
    group by 1
    order by 2 DESC
    limit 150),

    Run a query to Download Data