maybeyonassushi_10_loser_liq
    Updated 2022-11-28
    with
    pools as (
    select * from (
    select
    pool_name,
    pool_address
    from ethereum.dex_swaps
    where platform = 'sushiswap'
    and direction = 'IN'
    )
    ),
    pool_bals as (
    select
    address_name,
    user_address,
    sum(
    case when balance_date< current_date then amount_usd else 0 end
    ) as tvl,
    sum(
    case when balance_date< current_date then amount_usd else -amount_usd end
    ) as delta_tvl
    from ethereum.erc20_balances
    where user_address in (select pool_address from pools)
    and balance_date in (current_date, current_date-1)
    and amount_usd is not null
    and address_name is not null
    group by 1,2
    ),
    losers as (
    select * from pool_bals
    order by delta_tvl
    limit 10
    ),
    gainers as (
    select * from pool_bals
    order by delta_tvl desc
    Run a query to Download Data