Cipher009-CpUJ5kTransaction Value in USD Post Date | Grouped by Token
    -- forked from mehrancrypto-dxoepq / Untitled Query @ https://flipsidecrypto.xyz/mehrancrypto-dxoepq/q/E8pzMlHkMJZ7/untitled-query

    with tx1 as (select address , ADDRESS_NAME
    from ethereum.core.dim_labels
    where label = 'tornado cash'
    ) , tx2 as (
    SELECT ETH_VALUE, ADDRESS_NAME , B.tx_hash , C.amount , D.amount As tokens , CONTRACT_ADDRESS , date_trunc('hour' , B.block_timestamp) as daily ,
    case
    when D.origin_function_signature = '0xb438689f' then 'Withdraw'
    when D.origin_function_signature = '0x13d98d13' then 'Deposit' end as types
    from tx1 A , ethereum.core.fact_transactions B
    left outer JOIN ethereum.core.ez_eth_transfers C on B.tx_hash = C.tx_hash
    left outer JOIN ethereum.core.ez_token_transfers D on B.tx_hash = D.tx_hash
    where address = B.TO_ADDRESS
    and B.block_timestamp >='2023-06-10') ,
    tx3 as (
    SELECT tx_hash , avg(price) as price , symbol
    from ethereum.core.fact_hourly_token_prices A , tx2 B
    where CONTRACT_ADDRESS = TOKEN_ADDRESS
    and date_trunc('hour' , hour) = daily
    GROUP by 1 , 3
    )
    , tx4 as (
    SELECT A.tx_hash , daily as date , symbol ,tokens as volume , price*tokens as usd_value , types
    from tx2 A, tx3 B
    where A.tx_hash = B.tx_hash
    )
    SELECT symbol , date::date as daily , types , sum(usd_value) , count(tx_hash)
    from tx4
    where types is not null
    group by 1,2,3




    Run a query to Download Data