Afonso_DiazTop token pairs copy
    Updated 2024-09-18
    -- forked from Top token pairs @ https://flipsidecrypto.xyz/studio/queries/62ae63d3-9ff8-43be-988f-de92c42a886e

    with

    pricet as (
    select
    hour::date as date,
    symbol,
    token_address,
    avg(price) as price_usd
    from arbitrum.price.ez_prices_hourly
    group by 1, 2, 3
    ),

    main as (
    select
    tx_hash,
    block_timestamp,
    origin_from_address as user,
    case
    when amount_in_usd is not null then amount_in_usd
    when token_in in ('0xcb59a0a753fdb7491d5f3d794316f1ade197b21e', '0xda10009cbd5d07dd0cecc66161fc93d7c9000da1', '0x94b008aa00579c1307b0ef2c499ad98a8ce58e58', '0x73cb180bf0521828d8849bc8cf2b920918e23032', '0x0b2c639c533813f4aa9d7837caf62653d097ff85', '0x7f5c764cbc14f9669b88837ca1490cca17c31607', '0xb0b195aefa3650a6908f15cdac7d92f8a5791b0b', '0x8c6f28f2f1a3c87f0f938b96d27520d9751ec8d9', '0x2e3d870790dc77a83dd1d18184acc7439a53f475', '0x8ae125e8653821e851f12a49f7765db9a9ce7384') then amount_in
    when s1.price_usd is not null then amount_in * s1.price_usd
    end as amount_in_usdd,

    case
    when amount_out_usd is not null then amount_out_usd
    when token_out in ('0xcb59a0a753fdb7491d5f3d794316f1ade197b21e', '0xda10009cbd5d07dd0cecc66161fc93d7c9000da1', '0x94b008aa00579c1307b0ef2c499ad98a8ce58e58', '0x73cb180bf0521828d8849bc8cf2b920918e23032', '0x0b2c639c533813f4aa9d7837caf62653d097ff85', '0x7f5c764cbc14f9669b88837ca1490cca17c31607', '0xb0b195aefa3650a6908f15cdac7d92f8a5791b0b', '0x8c6f28f2f1a3c87f0f938b96d27520d9751ec8d9', '0x2e3d870790dc77a83dd1d18184acc7439a53f475', '0x8ae125e8653821e851f12a49f7765db9a9ce7384') then amount_out
    when s2.price_usd is not null then amount_out * s2.price_usd
    end as amount_out_usdd,
    case
    when amount_in_usdd < 1e6 then amount_in_usdd
    when amount_out_usdd < 1e6 then amount_out_usdd
    end as amount_usd,
    symbol_in,
    symbol_out,
    QueryRunArchived: QueryRun has been archived