shenronWhales
    Updated 2021-11-11
    with balances as (select

    origin_address as token_owner,
    symbol,
    sum(case
    when origin_function_name = 'deposit' and amount is not null then amount
    when origin_function_name = 'removeLiquidity' and amount is not null then -1*amount
    end ) as balance

    from ethereum.udm_events
    where
    symbol in ('ALCX', 'alUSD', 'alUSD3CRV', 'ALCX-ETH SLP')

    and to_address = '0xab8e74017a8cc7c15ffccd726603790d26d7deca'
    group by 1,2

    union all

    select
    user_address as token_owner,
    symbol,
    balance
    from ethereum.erc20_balances
    where balance_date = current_date()
    and symbol in ('ALCX', 'alUSD', 'alUSD3CRV', 'ALCX-ETH SLP')
    and user_address != '0xab8e74017a8cc7c15ffccd726603790d26d7deca'
    and balance > 0
    ),

    cumulative_balance as (select token_owner, symbol, balance,
    sum(balance) over (partition by symbol order by balance desc rows between unbounded preceding and current row) / sum(balance) over(partition by symbol) as cumulative_pct
    from balances
    where balance is not null
    --order by balance desc, symbol
    )

    Run a query to Download Data