Afonso_DiazGrouping swaps
    Updated 2025-01-07
    with

    pricet as (
    select
    hour::date as date,
    token_address,
    avg(price) as token_price_usd
    from
    mantle.price.ez_prices_hourly
    group by 1, 2
    ),

    main as (
    select
    tx_hash,
    block_timestamp,
    origin_from_address as trader,
    a.contract_address as token_in_address,
    b.contract_address as token_out_address,
    a.decoded_log:value as amount_in_unadj,
    b.decoded_log:value as amount_out_unadj
    from
    mantle.core.ez_decoded_event_logs a
    join
    mantle.core.ez_decoded_event_logs b using (tx_hash, block_timestamp, origin_to_address, tx_succeeded, event_name)
    where
    origin_to_address = '0xce16f69375520ab01377ce7b88f5ba8c48f8d666'
    and (
    (a.decoded_log:from::string in (b.decoded_log:to::string, '0x0000000000000000000000000000000000000000') and b.decoded_log:to::string = trader) or
    (b.decoded_log:to::string in (a.decoded_log:from::string, '0x0000000000000000000000000000000000000000') and a.decoded_log:from::string = trader)
    )
    and event_name = 'Transfer'
    and token_in_address != token_out_address
    and tx_succeeded
    and origin_function_signature = '0x58181a80'
    ),
    QueryRunArchived: QueryRun has been archived