siwakon-ethbgt-reward
    Updated 2024-10-08
    -- forked from bgt-reward @ https://flipsidecrypto.xyz/studio/queries/926a4bc1-2f08-4dc4-86e5-7763a70b56e8

    -- forked from bgt-reward @ https://flipsidecrypto.xyz/studio/queries/e92ea497-1c9c-4e3d-b45f-cef1381d4910

    WITH daily_totals AS (
    SELECT
    date_trunc('day', block_timestamp) as date,
    sum(bgt_value) as total_bgt_value
    FROM
    (
    SELECT
    block_timestamp,
    utils.udf_hex_to_int('s2c', regexp_substr_all(SUBSTR(output, 3, len(output)), '.{64}')[0] :: string) :: bigint / pow(10, 18) as bgt_value
    FROM
    berachain.testnet.fact_traces
    WHERE
    from_address = '{{contract_address}}'
    AND left(input, 10) = '0xc00007b0'
    AND tx_succeeded = true
    AND block_timestamp > '2024-06-12'
    ) subquery
    GROUP BY
    date_trunc('day', block_timestamp)
    )
    SELECT
    date,
    total_bgt_value,
    SUM(total_bgt_value) OVER (ORDER BY date) as cumulative_bgt_value
    FROM
    daily_totals
    ORDER BY
    date DESC;



    QueryRunArchived: QueryRun has been archived