HDKL4
    Updated 2023-06-12
    select
    count(distinct Merchant) as Shareholders
    from
    (
    SELECT
    case
    when Merchant = '0x53f389d96fb4ce5e' then 'Donation purse'
    when Merchant = '0xbfb26bb8adf90399' then 'SLOPPY-FLOW Pool'
    when Merchant = '0xc6cfb151ff031094' then 'SLOPPY-USDC Pool'
    else Merchant
    end as Merchant,
    volume_deposited,
    volume_withdrawn,
    volume_deposited - volume_withdrawn as holdings
    from
    (
    SELECT
    ifnull(x.purse, y.purse) as Merchant,
    ifnull(volume_in, 0) as volume_deposited,
    ifnull(volume_out, 0) as volume_withdrawn
    from
    (
    select
    event_data:to as purse,
    sum(event_data:amount) as volume_in
    from
    flow.core.fact_events
    where
    event_contract = 'A.53f389d96fb4ce5e.SloppyStakes'
    and event_type = 'TokensDeposited'
    group by
    1
    ) x
    left join (
    select
    event_data:
    Run a query to Download Data