djebril2023-08-25 07:10 PM
    Updated 2023-08-25
    with

    pricet as (
    select
    hour::date as date,
    token_address,
    avg(price) as usdprice
    from ethereum.core.fact_hourly_token_prices
    group by 1,2
    )
    ,

    deposits as (
    select
    tx_hash,
    block_timestamp,
    amount_deposited*usdprice as amount_usd,
    symbol,
    'Deposit' as type,
    depositor as user
    from ethereum.maker.ez_deposits a
    join pricet on pricet.token_address = token_deposited and date = date_trunc('day', block_timestamp)
    where TX_STATUS = 'SUCCESS'
    )
    ,

    withdrawals as (
    select
    tx_hash,
    block_timestamp,
    amount_withdrawn*usdprice as amount_usd,
    symbol,
    'Withdrawal' as type,
    withdrawer as user
    from ethereum.maker.ez_withdrawals a
    join pricet on pricet.token_address = token_withdrawn and date = date_trunc('day', block_timestamp)
    Run a query to Download Data