sunslingerLUNA Circulating Supply (Ava Upgrade)
    Updated 2022-07-07
    WITH vesting AS (
    select distinct address
    from "FLIPSIDE_PROD_DB"."GOLD"."TERRA_VESTING_SCHEDULE"
    where vesting_currency = 'luna'
    ),

    vested_luna AS (
    SELECT sum(balance) AS vested_balance
    from terra.daily_balances
    WHERE date = (current_date() - interval'365 days')
    AND currency = 'LUNA'
    AND balance_type = 'staked'
    AND address in (SELECT address FROM vesting)
    ),

    other_supply AS (
    select sum(balance) as total_balance
    from terra.daily_balances
    WHERE date = (current_date() - interval'30 days')
    AND currency = 'LUNA'
    AND balance > 0
    AND address NOT IN (
    'terra1fl48vsnmsdzcv85q5d2q4z5ajdha8yu3nln0mh', -- bonded token pool
    'terra1jv65s3grqf6v6jl3dp4t6c9t9rk99cd8pm7utl', -- community pool
    'terra1dp0taj85ruc299rkdvzp4z5pfg6z6swaed74e6', -- foundation
    'terra1jgp27m8fykex4e4jtt0l7ze8q528ux2lh4zh0f', --: oracle reward
    'terra1sk06e3dyexuq4shw77y3dsv480xv42mq73anxu') -- : burn')
    )

    SELECT
    total_balance - vested_balance AS circulating_supply
    FROM other_supply, vested_luna
    Run a query to Download Data