Updated 2024-02-17
    with boundaries as
    (select
    ethereum.public.udf_hex_to_int(regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}')[0])::integer as season,
    block_timestamp,
    COALESCE(LEAD(block_timestamp) OVER (ORDER BY block_timestamp),to_timestamp(100000000000)) as next_timestamp
    from polygon.core.fact_event_logs
    where block_timestamp::date BETWEEN '2022-03-13' and '2024-01-07'
    and contract_address = '0x70c575588b98c1f46b1382c706adaf398a874e3e'
    and topics[0]::string = '0x9b492ca62dd845faf66276dbd14ed82e0d819d8b172cb51433ffe4268ab3dd9e')

    SELECT boundaries.season,
    ethereum.public.udf_hex_to_int(regexp_substr_all(SUBSTR(INPUT, 11, len(INPUT)), '.{64}')[1]) as fuelrod,
    count(case when SUBSTR(INPUT, 1, 10) = lower('0x11237ba0') then TX_HASH end) as stx,
    count(case when SUBSTR(INPUT, 1, 10) = lower('0x11237ba0') then TX_HASH end) as srun,
    count(case when SUBSTR(INPUT, 1, 10) = lower('0xd422b242') then TX_HASH end) as btx,
    coalesce(sum(case when SUBSTR(INPUT, 1, 10) = lower('0xd422b242') then ethereum.public.udf_hex_to_int(regexp_substr_all(SUBSTR(INPUT, 11, len(INPUT)), '.{64}')[2]) end),0) as brun,
    coalesce(srun,0)+coalesce(brun,0) as tot_run
    FROM polygon.core.fact_traces ftt
    LEFT OUTER JOIN boundaries ON
    ftt.block_timestamp >= boundaries.block_timestamp AND
    ftt.block_timestamp < boundaries.next_timestamp
    WHERE ftt.block_timestamp::date BETWEEN '2022-03-13' and '2024-01-07'
    and tx_status = 'SUCCESS'
    and to_address = lower('0x70c575588b98c1f46b1382c706adaf398a874e3e')
    and SUBSTR(INPUT, 1, 10) in (lower('0x11237ba0'),lower('0xd422b242'))
    group by 1,2
    order by 1 desc , 2 desc
    Last run: about 1 year ago
    SEASON
    FUELROD
    STX
    SRUN
    BTX
    BRUN
    TOT_RUN
    1
    65119519560430625
    2
    6507723454465453
    3
    64111641164937980210966
    4
    64043434381005110094
    5
    63110641064906937510439
    6
    63042426861580415846
    7
    62110301030859904410074
    8
    62059596111408114140
    9
    61110671067863915810225
    10
    61038384821095210990
    11
    60196896873079148882
    12
    60046465141196612012
    13
    5911058105882185249582
    14
    59050506221430214352
    15
    5811022102272977168738
    16
    58064647851876518829
    17
    5711023102368969167939
    18
    57074744501008210156
    19
    5611044104470674578501
    20
    560646442796629726
    ...
    130
    4KB
    546s