SpecterArbitrum
    Updated 2024-12-16
    WITH lockup AS (
    SELECT
    TRUNC(block_timestamp, 'day') AS day, -- Truncate to match `meprice`
    block_timestamp,
    tx_id,
    signers[0] AS owner,
    -- Extract amount staked, dividing by 10^6 to account for decimal places
    utils.udf_hex_to_int(
    TO_CHAR(REVERSE(TO_BINARY(SUBSTR(utils.udf_base58_to_hex(instruction:data), 19, 16))))
    ) / POW(10, 6) AS amount,
    -- Extract lockup period and convert to a readable timestamp
    TO_TIMESTAMP(
    utils.udf_hex_to_int(
    TO_CHAR(REVERSE(TO_BINARY(SUBSTR(utils.udf_base58_to_hex(instruction:data), 35, 8))))
    )
    ) AS lockup_end_timestamp,
    -- Calculate lockup length in days using DATEDIFF with 'day' as the unit
    DATEDIFF(
    'day',
    block_timestamp,
    TO_TIMESTAMP(
    utils.udf_hex_to_int(
    TO_CHAR(REVERSE(TO_BINARY(SUBSTR(utils.udf_base58_to_hex(instruction:data), 35, 8))))
    )
    )
    ) AS lockup_length_days,
    -- Calculate staking power as amount * lockup length (in days)
    (
    utils.udf_hex_to_int(
    TO_CHAR(REVERSE(TO_BINARY(SUBSTR(utils.udf_base58_to_hex(instruction:data), 19, 16))))
    ) / POW(10, 6)
    ) * DATEDIFF(
    'day',
    block_timestamp,
    TO_TIMESTAMP(
    utils.udf_hex_to_int(
    QueryRunArchived: QueryRun has been archived