Pmisha-bmlMdxtvl.uniswap
    Updated 2022-06-09
    with st as (select
    SYMBOL,
    abs(max(price-1)) as deviation
    from ethereum.core.fact_hourly_token_prices
    where SYMBOL in (select SYMBOL_IN from ethereum.sushi.ez_swaps )
    and HOUR>=CURRENT_DATE-60
    group by 1 having deviation < 0.05),

    pl as (
    select * from (
    select
    pool_name,
    pool_address
    from flipside_prod_db.ethereum_core.dim_dex_liquidity_pools
    where platform ilike '%uniswap%'
    )
    ),
    blnc as (
    select
    balance_date,
    SYMBOL,
    sum(amount_usd) as tvl
    from ethereum.erc20_balances
    where user_address in (select pool_address from pl)
    and balance_date >= '2022-01-01'
    and amount_usd is not null
    and amount_usd < 1000000000
    and address_name is not null
    and SYMBOL in (select SYMBOL from st)
    group by 1,2
    )

    select * from blnc
    Run a query to Download Data