Ali3NTotal FLOW Holders And Average Balance of Users
    Updated 2022-11-25
    with depositt as (
    select event_data:to as flowuser,
    sum (event_data:amount) as Deposit_Volume
    from flow.core.fact_events
    where event_contract = 'A.1654653399040a61.FlowToken'
    and event_type = 'TokensDeposited'
    and tx_succeeded = 'TRUE'
    group by 1),

    withdrawt as (
    select event_data:from as flowuser,
    sum (event_data:amount) as Withdraw_Volume
    from flow.core.fact_events
    where event_contract = 'A.1654653399040a61.FlowToken'
    and event_type = 'TokensWithdrawn'
    and tx_succeeded = 'TRUE'
    group by 1),

    maintable as (
    select t1.flowuser,
    contract_name,
    sum (deposit_volume - withdraw_volume) as Balance
    from depositt t1 join withdrawt t2 on t1.flowuser = t2.flowuser
    full outer join flow.core.dim_contract_labels t3 on t1.flowuser = t3.account_address
    where t1.flowuser != 'null'
    group by 1,2)

    select count (distinct flowuser) as Total_Holders,
    avg (balance) as Average_Flow_Balance
    from maintable




    Run a query to Download Data