mhmTotal fees paid daily
    Updated 2022-09-19
    with currencies as (
    select * from (
    values
    ('USDC', '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8', '6'),
    ('WETH', '0x82af49447d8a07e3bd95bd0d56f35241523fbab1', '18'),
    ('LINK', '0xf97f4df75117a78c1a5a0dbb814af92458539fb4', '18'),
    ('WBTC', '0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f', '18'),
    ('UNI', '0xfa7f8980b0f1e64a2062791cc3b0871572f1f7f0', '18'),
    ('DAI', '0xda10009cbd5d07dd0cecc66161fc93d7c9000da1', '18'),
    ('FRAX', '0x17fc002b466eec40dae837fc4be5c67993ddbd6f', '18'),
    ('USDT', '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9', '6')
    ) as v1 (symbol, contract, decimals)
    ), prices as (
    select hour::date as date,
    symbol,
    avg(price) as price
    from ethereum.core.fact_hourly_token_prices
    where (symbol in ('USDC','LINK','USDT','WETH','WBTC','DAI','FRAX')
    or token_address in ('0x1f9840a85d5af5bf1d1762f925bdaddc4201f984')) --UNI
    group by 1,2
    )
    , trades as (
    select
    block_timestamp::date as date,
    tx_hash,
    ORIGIN_FROM_ADDRESS as user_address,
    c1.symbol as symbol_in,
    tokenflow_eth.hextoint(substr(data,3+2*64,64))/pow(10,c1.decimals) as amount_In,
    price ,
    tokenflow_eth.hextoint(substr(data,3+3*64,64))/pow(10,30) as min_Out,
    tokenflow_eth.hextoint(substr(data,3+4*64,64))/pow(10,30) as delta,
    tokenflow_eth.hextoint(substr(data,3+5*64,64)) as is_Long,
    case when is_long = 1 then 'Long' else 'Short' end as dir,
    c2.symbol as leveraged_asset,
    tokenflow_eth.hextoint(substr(data,3+6*64,64))/pow(10,30) as acceptable_Price,
    tokenflow_eth.hextoint(substr(data,3+7*64,64))/pow(10,18) as execution_Fee,
    Run a query to Download Data