mariya Total Circulating LUNA Delegation rate
    Updated 2022-05-18
    with a as (select date_trunc('day', block_timestamp) as day, sum (event_amount) as amount_delegated
    from terra.staking
    where action like '%delegate%'
    group by 1),

    b as(
    select date_trunc('day', block_timestamp) as daya, sum (event_amount) as amount_undelegated
    from terra.staking
    where action like '%undelegate%'
    group by 1
    ),

    c as (
    select date_trunc('day', date) as dayb, sum (balance) as CS
    from terra.daily_balances
    where currency like '%LUNA%'
    group by 1
    )

    select a.day, (sum((amount_delegated-amount_undelegated)/cs)*100) as Delegation_Percent
    from a
    inner join b ON
    b.daya=a.day
    inner join c
    on c.dayb=b.daya
    group by 1
    Run a query to Download Data