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§
- Archive
Tx - 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.
- Json
RpcTx - Transaction wrapper for JSON RPC transactions. Contains a reference to the transaction and its metadata from JSON RPC responses.
Enums§
- Instruction
Type - 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
TxFormatenum and normalizes them into a common format before processing, writing stadardized output to channelsswap_tx_senderandtoken_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 dummySwapDirectionvalue is used. TheInstructionTypewill always be correct orNone. - 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_loopdoes. - 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_loopto process the inner instructions that belong to each top level instruction.