tkvresearchisolated-red
    Updated 2025-04-27
    with buy_tab as
    (select block_timestamp,
    tx_hash,
    origin_from_address as swapper,
    'buy' as action_,
    (case when amount_in_usd is null then amount_out_usd end )/amount_out as price_buy,
    amount_out as amount_buy,
    case when amount_in_usd is null then amount_out_usd end as total_vol_usd
    from base.defi.ez_dex_swaps
    where token_out = lower('0xBAa5CC21fd487B8Fcc2F632f3F4E8D37262a0842')),

    sell_tab as
    (select block_timestamp,
    tx_hash,
    origin_from_address as swapper,
    'sell' as action_,
    (case when amount_out_usd is null then amount_in_usd end)/amount_in as price_sell,
    -amount_in as amount_sell,
    -(case when amount_out_usd is null then amount_in_usd end) as total_vol_usd
    from base.defi.ez_dex_swaps
    where token_in = lower('0xBAa5CC21fd487B8Fcc2F632f3F4E8D37262a0842')),

    price_tab as (
    select hour,
    token_address,
    price
    from base.price.ez_prices_hourly
    where token_address = lower('0xBAa5CC21fd487B8Fcc2F632f3F4E8D37262a0842')
    ),

    master_tab as
    (select date_hour,
    tx_hash,
    swapper,
    action_,
    case when price_buy is null then price end as price_buy,
    Last run: 27 days ago
    SWAPPER_CNT
    LABEL
    1
    453Profit
    2
    5133Loss
    3
    8Equal
    3
    42B
    12s