Updated 2023-07-03
    WITH flow_out as (
    SELECT sender,
    sum(AMOUNT) as amnt
    FROM terra.core.ez_transfers
    WHERE CURRENCY='uluna'
    AND tx_succeeded = true
    AND amount is not NULL
    GROUP by sender),
    flow_in as (
    SELECT receiver,
    sum(AMOUNT) as amnt
    FROM terra.core.ez_transfers
    WHERE CURRENCY='uluna'
    AND tx_succeeded = true
    AND amount is not NULL
    GROUP BY receiver
    )

    SELECT sum(balance) as circulating_supply
    FROM(
    SELECT sender as "Wallet Address", (zeroifnull(b.amnt)-zeroifnull(a.amnt))/pow(10,6) AS balance
    FROM flow_out a
    LEFT JOIN flow_in b
    ON a.sender=b.receiver
    )
    WHERE balance > 0
    Run a query to Download Data