bachiflowusers3
    Updated 2022-11-28
    with balance_dtls as (
    select
    date(block_timestamp) as day,
    event_data:to as address,
    sum(event_data:amount) as volume
    from flow.core.fact_events
    where
    event_contract = 'A.1654653399040a61.FlowToken' and
    event_type = 'TokensDeposited' and
    tx_succeeded = 'TRUE' and
    event_data:to != 'null' and
    event_data:amount is not null
    group by 1, 2

    union all
    select
    date(block_timestamp) as day,
    event_data:from as address,
    -sum(event_data:amount) as volume
    from flow.core.fact_events
    where
    event_contract = 'A.1654653399040a61.FlowToken' and
    event_type = 'TokensWithdrawn' and
    tx_succeeded = 'TRUE' and
    event_data:from != 'null' and
    event_data:amount is not null
    group by 1, 2
    )
    select
    --date(day),
    count(distinct address) as no_of_users,
    round(sum(volume),2) as balance_tokens
    from balance_dtls
    where volume > 0
    Run a query to Download Data