Updated 2025-02-14
    with tab1 as (
    SELECT
    tx_hash as tx,
    case when ORIGIN_FUNCTION_SIGNATURE like '0x6945b123' then 'Buy'
    when ORIGIN_FUNCTION_SIGNATURE like '0xb51d0534' then 'Sell'
    end AS tx_type
    from base.core.fact_event_logs
    WHERE ORIGIN_TO_ADDRESS like lower('0x428aeF7fB31E4E86162D62d4530a4dd7232D953D')
    and ORIGIN_FUNCTION_SIGNATURE in ('0x6945b123', '0xb51d0534')
    )

    SELECT
    date_trunc('week', block_timestamp) as week,
    tx_type,
    count(DISTINCT tx_hash) as events,
    count(DISTINCT user) as users,
    sum(amount_usd) as volume_usd

    FROM (
    select
    tx_hash,
    'Buy' as tx_type,
    block_timestamp,
    ORIGIN_FROM_ADDRESS as user,
    amount_usd

    from base.core.ez_native_transfers as a
    left outer join tab1
    on tx = tx_hash
    where a.tx_hash in (SELECT tx from tab1)
    --and tx_hash like '0x2abc25318056095fb0843cb4b7945c7f2bfb5f5b364bd597d504e88d78423688'
    AND tx_type like 'Buy'
    and ORIGIN_FROM_ADDRESS = from_address

    UNION all
    Last run: about 2 months ago
    WEEK
    TX_TYPE
    EVENTS
    USERS
    VOLUME_USD
    1
    2024-07-08 00:00:00.000Buy166319.45
    2
    2024-10-14 00:00:00.000Sell187409856.4
    3
    2025-02-10 00:00:00.000Sell5544885.05
    4
    2024-12-30 00:00:00.000Sell4211.01
    5
    2024-06-24 00:00:00.000Buy98473345.57
    6
    2025-01-20 00:00:00.000Buy3349.75
    7
    2024-09-23 00:00:00.000Buy62141769.36
    8
    2024-10-07 00:00:00.000Sell40154790.5
    9
    2024-11-18 00:00:00.000Buy2712193.29
    10
    2025-01-20 00:00:00.000Sell105449.94
    11
    2024-10-28 00:00:00.000Buy106922125364.74
    12
    2024-10-21 00:00:00.000Buy6951039551.01
    13
    2024-11-04 00:00:00.000Sell197443145.57
    14
    2025-01-06 00:00:00.000Sell478247424.91
    15
    2024-09-09 00:00:00.000Buy120234742.74
    16
    2024-12-23 00:00:00.000Sell126108.88
    17
    2024-06-17 00:00:00.000Sell4399705802841.26
    18
    2024-10-07 00:00:00.000Buy97265572.43
    19
    2024-07-15 00:00:00.000Sell38147352.46
    20
    2025-01-27 00:00:00.000Buy8376.7
    69
    3KB
    113s