purifYeet testnet v2 - YEET stakers
    Updated 2025-01-08
    with staking as (select block_timestamp, concat('0x',substr(TOPICS[1], 27,64)) as address,
    (utils.udf_hex_to_int(substr(data,3,66))::int)/1e18 as amount
    from berachain.testnet.fact_event_logs
    where ORIGIN_TO_ADDRESS=LOWER('0xd98c56EBbb46aA3a85Cc488c6b24E0d486624D9F')
    and ORIGIN_FUNCTION_SIGNATURE='0xa694fc3a'
    and topics[0]='0xebedb8b3c678666e7f36970bc8f57abf6d8fa2e828c0da91ea5b75bf68ed101a'),
    unstaking as (
    select tx_hash,block_timestamp, concat('0x',substr(TOPICS[1], 27,64)) as address,
    (utils.udf_hex_to_int(substr(data,3,64))::int)/1e18 as amount,
    from berachain.testnet.fact_event_logs
    where ORIGIN_TO_ADDRESS=LOWER('0xd98c56EBbb46aA3a85Cc488c6b24E0d486624D9F')
    and ORIGIN_FUNCTION_SIGNATURE='0x2e17de78'
    and topics[0]='0xf960dbf9e5d0682f7a298ed974e33a28b4464914b7a2bfac12ae419a9afeb280'
    ),
    stake_sum as (
    select address, sum(amount) as stake from
    (select address, sum(amount) as amount from staking
    group by 1
    UNION ALL
    select address, sum(amount)*-1.0 as amount from unstaking
    group by 1
    )
    group by 1 having stake>=1
    )

    select address, stake, sum(stake) over (order by stake) as cumulative, count(address) over (order by stake) as stakers_count from stake_sum
    order by stake desc
    QueryRunArchived: QueryRun has been archived