0x000eth-sW-WATReferral II (2024-10-21 03AM - 2024-10-28 03AM UTC) copy
    Updated 2024-10-25
    -- forked from sssstatistic / Referral II (2024-10-21 03AM - 2024-10-28 03AM UTC) @ https://flipsidecrypto.xyz/sssstatistic/q/MYTIBJl7WQAD/referral-ii-2024-10-21-03am---2024-10-28-03am-utc

    -- forked from TOP Referrers Event Blast Gold W1 @ https://flipsidecrypto.xyz/studio/queries/dccfb12c-f9bf-42f2-bb7d-4963fc7c9773

    -- forked from TOP Referrers (On-chain) @ https://flipsidecrypto.xyz/studio/queries/50138a96-6dc5-4abf-aa54-7ea8ff4e8160

    With reset_time as (
    select
    origin_from_address,
    max(block_timestamp) AS block_timestamp
    from blast.core.ez_decoded_event_logs
    where contract_address = '0xc48f6213a1a4d3ead79db812c2b91817980532c3'
    and event_name IN ('WithdrawRewardFromPool')
    group by origin_from_address
    ),
    timeline as (
    select
    origin_from_address,
    event_name,
    max(block_timestamp) AS block_timestamp
    from blast.core.ez_decoded_event_logs el
    where contract_address = '0xc48f6213a1a4d3ead79db812c2b91817980532c3'
    and event_name IN ('LevelUpSamurai', 'LevelUpPet')
    and not exists (
    select 1
    from reset_time rt
    where rt.origin_from_address = el.origin_from_address
    and rt.block_timestamp > el.block_timestamp
    )
    group by origin_from_address, event_name
    ),
    samurai_level as (
    select
    el.origin_from_address,
    max(
    CASE
    QueryRunArchived: QueryRun has been archived