LittlerDataFlow holding
    Updated 2022-11-29

    with receiving as (
    select
    event_data:to as receiver
    ,sum(event_data:amount) as deposits
    from flow.core.fact_events
    where event_contract = 'A.1654653399040a61.FlowToken'
    and event_type = 'TokensDeposited'
    and tx_succeeded = 'TRUE'
    and receiver != 'null'
    group by 1
    ),

    sending_out as (
    select
    event_data:from as sender
    ,sum(event_data:amount) as withdrawns
    from flow.core.fact_events
    where event_contract = 'A.1654653399040a61.FlowToken'
    and event_type = 'TokensWithdrawn'
    and tx_succeeded = 'TRUE'
    and sender != 'null'
    group by 1
    ),

    joining as (
    select
    receiver as wallet
    ,sum (deposits - withdrawns) as current_balance
    from receiving
    join sending_out on receiving.receiver = sending_out.sender
    full outer join flow.core.dim_contract_labels labels on receiving.receiver = labels.account_address
    where wallet != 'null'
    group by 1
    ),