nsa2000GMX Protocol
    Updated 2022-11-16
    with table_1 as (select block_timestamp::date as day,
    case
    when contract_address = '0xda10009cbd5d07dd0cecc66161fc93d7c9000da1' then 'DAI'
    when contract_address = '0x17fc002b466eec40dae837fc4be5c67993ddbd6f' then 'FRAX'
    when contract_address = '0xf97f4df75117a78c1a5a0dbb814af92458539fb4' then 'LINK'
    when contract_address = '0xfa7f8980b0f1e64a2062791cc3b0871572f1f7f0' then 'UNI'
    when contract_address = '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8' then 'USDC'
    when contract_address = '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9' then 'USDT'
    when contract_address = '0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f' then 'WBTC'
    when contract_address = '0x82af49447d8a07e3bd95bd0d56f35241523fbab1' then 'WETH'
    end as asset_name,
    *
    from arbitrum.core.fact_event_logs --GMX
    where tx_status = 'SUCCESS'
    and event_name = 'Transfer'
    and event_inputs:value is not null
    and origin_to_address in ('0x3d6ba331e3d9702c5e8a8d254e5d8a285f223aba','0xb87a436b93ffe9d75c5cfa7bacfff96430b09868')),

    table_2 as (select hour::date as day,
    symbol,
    decimals,
    avg(price) as asset_price
    from ethereum.core.fact_hourly_token_prices
    where token_address in ('0x6b175474e89094c44da98b954eedeac495271d0f', --DAI
    '0x853d955acef822db058eb8505911ed77f175b99e', --FRAX
    '0x514910771af9ca656af840dff83e8264ecf986ca', --LINK
    '0x1f9840a85d5af5bf1d1762f925bdaddc4201f984', --UNI
    '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', --USDC
    '0xdac17f958d2ee523a2206206994597c13d831ec7', --USDT
    '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599', --WBTC
    '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2') --WETH
    group by 1,2,3),

    table_3 as (select date_trunc('day', block_timestamp) as date,
    sum((event_inputs:value/pow(10,decimals))*asset_price) as usd_volume,
    sum(usd_volume) over (order by date) as cumu_usd_volume,