purifYeet testnet v2 - Staking over time
    Updated 2025-01-08
    with staking as (
    select date_trunc('day',block_timestamp) as day, sum(amount) as staked from (
    select block_timestamp, (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')
    group by 1),
    unstaking as (
    select date_trunc('day',block_timestamp) as day, sum(amount) as unstaked from (
    select block_timestamp, (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'
    )
    group by 1
    )

    select day, staked, unstaked, sum(staked+unstaked) over (order by day) as cumulative_stake from (
    select coalesce(s.day, u.day) as day, coalesce(staked,0) as staked, coalesce(unstaked,0)*-1.0 as unstaked
    from staking s
    left join unstaking u on s.day=u.day)
    order by day desc

    QueryRunArchived: QueryRun has been archived