Yakuzaevm2
    Updated 2023-02-07
    --made by : https://app.flipsidecrypto.com/velocity/queries/8c79c7a3-10e6-4d2c-9dde-4982dd6d65a3 **ali3n**
    with aaa as ( select hour::date as day, symbol, decimals, avg (price) as usdprice
    from ethereum.core.fact_hourly_token_prices
    where (symbol in ('USDC','USDT','WETH','WBTC','DAI'))
    group by 1,2,3),

    gmxtable as (select block_timestamp, tx_hash, origin_from_address, RAW_AMOUNT as volume,
    case when contract_address = '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8' then 'USDC'
    when contract_address = '0x82af49447d8a07e3bd95bd0d56f35241523fbab1' then 'WETH'
    when contract_address = '0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f' then 'WBTC'
    when contract_address = '0xda10009cbd5d07dd0cecc66161fc93d7c9000da1' then 'DAI'
    when contract_address = '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9' then 'USDT'
    else contract_address end as Token_Symbol
    from arbitrum.core.fact_token_transfers
    where origin_to_address in ('0x3d6ba331e3d9702c5e8a8d254e5d8a285f223aba','0xb87a436b93ffe9d75c5cfa7bacfff96430b09868')
    and RAW_AMOUNT is not null ),


    maintable as (select t1.*, (t1.volume / pow (10,t2.decimals)) * t2.usdprice as Volume1
    from gmxtable t1 join aaa t2 on t1.block_timestamp::date = t2.day and t1.Token_Symbol = t2.symbol
    where Volume1 > 1 )


    select block_timestamp::date as day, count (distinct tx_hash) as TX_Count, count (distinct origin_from_address) as Users_Count,
    sum (Volume1) as Total_Volume, avg (Volume1) as Average_Volume, sum (TX_Count) over (order by day) as Cumulative_TX_Count, Total_Volume * 0.001 as Total_Fee,
    sum (Total_Volume) over (order by day) as Cumulative_Volume, avg (Total_Volume) over (order by day rows between 1 PRECEDING and current row) as Moving_Average_7_USD,
    Cumulative_Volume * 0.001 as Cumulative_Fee, sum (Users_Count) over (order by day) as Cumulative_Users_Count
    from maintable
    where day >= CURRENT_DATE - 100
    group by 1


    Run a query to Download Data