Sbhn_NPcircul 1
    Updated 2023-01-21
    --credit : https://app.flipsidecrypto.com/velocity/queries/a84b31f9-a341-4ce0-9558-d1a832be5479
    with transfer_luna_from_user as (
    select
    sender as address,
    - (sum(amount))/1e6 as amount
    from terra.core.ez_transfers
    where currency = 'uluna'
    and tx_succeeded = true
    group by address
    ),
    transfer_luna_to_user as (
    select
    receiver as address,
    (sum(amount))/1e6 as amount
    from terra.core.ez_transfers
    where currency = 'uluna'
    and tx_succeeded = true
    group by address
    ),
    results_1 as (
    select * from transfer_luna_from_user
    union
    select * from transfer_luna_to_user
    ),
    results_2 as (
    select
    address as holder,
    sum(amount) as amount_of_hold
    from results_1
    group by holder
    having amount_of_hold > 0
    )

    select
    sum(amount_of_hold) as "Circulating Supply",
    count(holder) as "Number of Holder"
    Run a query to Download Data