Crate solana_tx_decoding

Source
Expand description

§Solana Transaction Decoding

Library for decoding raw Solana transactions from various sources into standardized formats.

This library provides:

  • Multi-format transaction parsing (Archive, gRPC, JSON RPC)
  • Instruction classification and decoding
  • Parallel processing ability with Tokio broadcast channels
  • Standardized output types (SwapTx, TokenCreation)
  • Protocol-specific instruction processors (Raydium, Pumpswap, Pumpfun)

§Usage

The main entry point is analyze_tx, which takes a TxFormat enum (containing any transaction format) and writes decoded swap transactions and token creations to broadcast channels.

Structs§

ArchiveTx
Transaction wrapper for Archive format transactions. Contains a reference to the transaction and its metadata from Old Faithful CAR format archive block storage.
GrpcTx
Transaction wrapper for Yellowstone gRPC stream transactions. Contains a reference to the transaction and its metadata from Yellowstone gRPC streams.
JsonRpcTx
Transaction wrapper for JSON RPC transactions. Contains a reference to the transaction and its metadata from JSON RPC responses.

Enums§

InstructionType
Enumeration of all supported instruction types. Represents the different types of instructions that can be classified and processed. Includes swaps from various protocols, token creations, and liquidity operations.
TxFormat
Enum representing different transaction source formats. Allows the decoding system to handle transactions from multiple sources (Archive blocks of Triton One Old Faithful CAR format used in solana_car, gRPC streams, JSON RPC) in a unified way.

Functions§

analyze_tx
Analyze raw Solana transactions and extract swaps and token creations. This is the main entry point for transaction decoding. It accepts transactions from multiple sources (Archive, gRPC, JSON RPC) using the TxFormat enum and normalizes them into a common format before processing, writing stadardized output to channels swap_tx_sender and token_create_sender. Failed transactions are skipped and not analyzed. TODO support can be added for add/remove liquidity and bubblemapping with links.
classify_instruction
Classify an instruction to determine its type and swap direction. Returns a tuple of (InstructionType, SwapDirection). For instructions that don’t have a swap direction, a dummy SwapDirection value is used. The InstructionType will always be correct or None.
fetch_token_metadata_from_uri
Fetch additional token metadata from off-chain URI. Token metadata URIs point to JSON APIs that return additional metadata. This function extracts description, twitter, and website fields from the JSON response, returning empty strings if fields are missing or not strings.
inner_instructions_loop
Handles inner instructions that result from program invocations. Processes swap instructions and token creation events from various protocols, sending results to broadcast channels just like top_level_instructions_loop does.
is_pf_bonding_curve_create_instruction
Determine if a Solana instruction is a Pumpfun bonding curve creation instruction. Checks data length, account count, discriminator, and program ID to identify Pumpfun bonding curve creation instructions.
is_pumpfun_event_instruction
Determine if a Solana instruction is a Pumpfun bonding curve event instruction. Checks data length, discriminator, program ID, and event authority account to identify Pumpfun event instructions that contain swap data.
is_pumpswap_swap_instruction
Determine if a Solana instruction is a Pumpswap swap instruction. Checks program ID, data length, and identifies swap direction by checking instruction discriminator.
is_raydium_ammv4_swap_instruction
Determine if a Solana instruction is a Raydium AMMv4 swap instruction. Checks program ID, data length, account count, and instruction discriminator to identify Raydium AMMv4 swap instructions.
is_raydium_cpmm_swap_instruction
Determine if a Solana instruction is a Raydium Cpmm/AmmV5 swap instruction. Checks program ID, data length, account count, and instruction discriminator to identify Raydium CPMM swap instructions.
is_raydium_launchpad_swap_instruction
Determine if a Solana instruction is a Raydium launchpad swap instruction. Checks program ID, data length, account count, and instruction discriminator to identify Raydium launchpad swap instructions. Returns the swap direction identified by the discriminator.
process_pf_bonding_curve_create_instruction
Process a Pumpfun bonding curve creation instruction and create a TokenCreation. Extracts token creation information from the bonding curve create instruction data, including name, symbol, URI, and metadata fields.
process_pumpfun_event_instruction
Process a Pumpfun bonding curve event instruction and create a SwapTx. Pumpfun bonding curve events contain all information needed to build the SwapTx type. Assumes the instruction has already been validated as a valid Pumpfun event instruction.
process_pumpswap_swap_instruction
Process a Pumpswap swap instruction and create a SwapTx. Assumes the instruction has been validated as a valid Pumpswap swap. Needs the event instruction that follows the swap instruction to extract swap details.
process_raydium_ammv4_swap_instruction
Process a Raydium AMMv4 swap instruction and create a SwapTx. Assumes the instruction has been validated as a valid Raydium AMMv4 swap. Uses token transfer instructions that follow the swap to determine swap amounts.
process_raydium_cpmm_swap_instruction
Process a Raydium Cpmm swap instruction and create a SwapTx. Assumes the instruction has been validated as a valid Raydium Cpmm swap. Uses token transfer instructions that follow the swap to determine swap amounts.
process_raydium_launchpad_swap_instruction
Process a Raydium launchpad swap instruction and create a SwapTx. Assumes the instruction has been validated as a valid Raydium launchpad swap. Requires both the swap instruction and its corresponding event instruction because the platform config cannot be derived from the event data alone.
top_level_instructions_loop
Process top-level instructions in a transaction. Iterates through top-level instructions, classifies them, and processes swap/creation instructions. Also calls inner_instructions_loop to process the inner instructions that belong to each top level instruction.