bera-terminaltotal bgt delegate
    Updated 2024-10-11
    with undelegation_database as (
    with database AS (
    WITH tbl AS (
    SELECT
    *
    FROM
    berachain.testnet.fact_event_logs
    where
    ORIGIN_TO_ADDRESS = '0xbda130737bdd9618301681329bf2e46a016ff9ad'
    and CONTRACT_ADDRESS = '0xbda130737bdd9618301681329bf2e46a016ff9ad'
    and ORIGIN_FUNCTION_SIGNATURE = '0xe1f63d2e'
    and TX_SUCCEEDED = 'TRUE'
    )
    SELECT
    block_timestamp,
    tx_hash,
    '0x' || SUBSTR(PARSE_JSON(TOPICS) [1] :: string, -40) AS user_wallet,
    '0x' || SUBSTR(PARSE_JSON(TOPICS) [2] :: string, -40) AS validator_address,
    utils.udf_hex_to_int(DATA) / pow (10, 18) AS undelegated_amount
    FROM
    tbl
    )
    SELECT
    validator_address,
    sum (undelegated_amount) as "total undelegation"
    from
    database
    GROUP by
    1
    order by
    2 desc
    ),
    delegation_database AS (
    with database AS (
    WITH tbl AS (
    SELECT
    QueryRunArchived: QueryRun has been archived