Abbas_ra21Untitled Query
    Updated 2022-07-05
    with pools AS (
    select POOL_ADDRESS,token0,token1
    from ethereum.core.dim_dex_liquidity_pools
    where PLATFORM !='curve'),
    token0_amount AS (select
    user_address,
    token0,
    symbol_token0,
    case when DECIMALS is not null and balance is null then (NON_ADJUSTED_BALANCE/power(10,DECIMALS))
    when DECIMALS is null and balance is null then NON_ADJUSTED_BALANCE
    when DECIMALS is NULL and balance is not null then balance
    else balance
    end as token0_amount
    from flipside_prod_db.ethereum.erc20_balances
    inner join pools on user_address=pool_address and token0=CONTRACT_ADDRESS
    where BALANCE_DATE=CURRENT_DATE),
    tokne1 amount AS (
    select
    user_address,
    token1,
    symbol_token1,
    case when DECIMALS is not null and balance is null then (NON_ADJUSTED_BALANCE/power(10,DECIMALS))
    when DECIMALS is null and balance is null then NON_ADJUSTED_BALANCE
    when DECIMALS is NULL and balance is not null then balance
    else balance
    end as token1_amount
    from flipside_prod_db.ethereum.erc20_balances
    inner join pools on user_address=pool_address and token1=CONTRACT_ADDRESS
    where BALANCE_DATE=CURRENT_DATE
    ),
    prices AS (
    select date_trunc('day', HOUR) as date,
    TOKEN_ADDRESS,
    max(PRICE) as price
    from ethereum.core.fact_hourly_token_prices
    where date=CURRENT_DATE
    Run a query to Download Data