mlhUntitled Query
    Updated 2022-09-19
    --credit to cryptoicicle
    with price as (select hour::date as date,
    token_address,
    symbol,
    avg(price) as price
    from ethereum.token_prices_hourly
    where hour::date >= CURRENT_DATE - 90
    group by 1, 2, 3
    )
    select date_trunc('day',block_timestamp) as date,
    type,
    symbol,
    count(distinct tx_hash) as count_positions,
    count(distinct origin_from_address) as count_wallets,
    sum(iff(from_address = '0x0000000000000000000000000000000000000000', 0, amount_usd)) as position_volume,
    sum(iff(from_address = '0x0000000000000000000000000000000000000000', amount_usd, 0)) as fee
    from ( select t.*,
    t.amount * p.price as amount_usd
    from (select l.address_name as token,
    case when contract_address='0xff970a61a04b1ca14834a43f5de4533ebddb5cc8' then 'USDC'
    when contract_address='0x82af49447d8a07e3bd95bd0d56f35241523fbab1' then 'WETH'
    when contract_address= '0xda10009cbd5d07dd0cecc66161fc93d7c9000da1' then 'DAI'
    when contract_address= '0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f' then 'WBTC'
    when contract_address= '0x17fc002b466eec40dae837fc4be5c67993ddbd6f' then 'FRAX'
    when contract_address= '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9' then 'USDT'
    when contract_address='0xfa7f8980b0f1e64a2062791cc3b0871572f1f7f0' then 'UNI'
    when contract_address='0xf97f4df75117a78c1a5a0dbb814af92458539fb4' then 'LINK'
    end as symbol,
    case when contract_address = '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8' then raw_amount/10e5
    when contract_address = '0x82af49447d8a07e3bd95bd0d56f35241523fbab1' then raw_amount/10e17
    when contract_address = '0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f' then raw_amount/10e17
    when contract_address = '0xda10009cbd5d07dd0cecc66161fc93d7c9000da1' then raw_amount/10e17
    when contract_address = '0x17fc002b466eec40dae837fc4be5c67993ddbd6f' then raw_amount/10e17
    when contract_address = '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9' then raw_amount/10e5
    when contract_address = '0xf97f4df75117a78c1a5a0dbb814af92458539fb4' then raw_amount/10e17
    when contract_address='0xfa7f8980b0f1e64a2062791cc3b0871572f1f7f0' then raw_amount/10e17
    Run a query to Download Data