DaniLabsdecoding tx
    Updated 2025-02-10
    -- SELECT
    -- instruction:data AS encoded_data,
    -- utils.udf_base58_to_hex(encoded_data) AS hex_data, -- Decoded Data

    -- -- substr(hex_data, 3 + 16, 16): This SQL function substr is used to Start at the character position 3 + 16 (which is 19) in hex_data.
    -- -- Take the next 16 characters (which corresponds to 8 bytes in binary since each byte in hex is represented by two characters).
    -- -- to_binary: Converts the hex string back into binary.
    -- -- reverse: Reverses the byte order because, as mentioned, blockchain data often uses little-endian format, and most systems expect big-endian for numerical interpretation.
    -- -- to_char: Converts the binary back into a string or character representation, likely for consistency in further SQL operations.
    -- -- udf_hex_to_int: This user-defined function then converts this hexadecimal string into an integer, which is the numeric value of the input_amount.


    -- livequery.utils.udf_hex_to_int(to_char(reverse(to_binary(substr(hex_data, 3 + 16, 16))))) as input_amount,
    -- instruction:accounts[6] AS input_mint,
    -- livequery.utils.udf_hex_to_int(to_char(reverse(to_binary(substr(hex_data, 3 + 16 + 16, 16))))) as output_amount,
    -- instruction:accounts[8] AS output_mint
    -- FROM solana.core.fact_events e
    -- where 1 = 1
    -- AND tx_id = '4YAVquvLKfAedJHPxQfy5HruafwSXchsBoioLRMqT8G5SLtiH1G6ZSD6XMwhrL75vx6qj9CRp5J94513dQJBHxfo'
    -- AND program_id = '61DFfeTKM7trxYcPQCM78bJ794ddZprZpAwAnLiwTpYH'



    SELECT
    instruction:data AS raw_data,
    utils.udf_base58_to_hex(instruction:data) AS decoded_data,

    -- 0x a860b7a35c0a28a0 c286b04243710200 a5f1df6910010000d1fd696700000000

    livequery.utils.udf_hex_to_int(to_char(reverse(to_binary(substr(decoded_data, 3 + 16, 16))))) as input_amount,
    livequery.utils.udf_hex_to_int(to_char(reverse(to_binary(substr(decoded_data, 3 + 16 + 16, 16))))) as output_amount


    FROM solana.core.fact_events
    where tx_id = '4YAVquvLKfAedJHPxQfy5HruafwSXchsBoioLRMqT8G5SLtiH1G6ZSD6XMwhrL75vx6qj9CRp5J94513dQJBHxfo'
    AND program_id = '61DFfeTKM7trxYcPQCM78bJ794ddZprZpAwAnLiwTpYH'
    Last run: about 1 month ago
    RAW_DATA
    DECODED_DATA
    INPUT_AMOUNT
    OUTPUT_AMOUNT
    1
    CLH2mh6Bt8oRgmtxR64YJDPSXduGcQ3vwpnxKU5NosdH
    0xa860b7a35c0a28a0c286b04243710200a5f1df6910010000d1fd6967000000006874836490339221170007388581
    1
    153B
    6s