Streaming and Parsing Raydium CPMM Transactions

Real-Time Streaming and Parsing of Raydium CP Swap Transactions on Solana via Yellowstone gRPC

Raydium's Constant Product Market Maker (CPMM) pools are fundamental to its liquidity model, facilitating numerous token swaps. To effectively analyze market movements and build robust trading strategies, gaining real-time access to and understanding of these transactions is essential. This document illustrates how to stream and parse Raydium CP swap transactions, providing immediate insights into its core trading activities.

Step-by-Step Breakdown

This project consists of two key components:

  1. Streaming Raydium CLMM Transactions via Yellowstone gRPC

  2. Parsing those transactions using the program's IDL

Streaming Transactions Using gRPC

The first step involves initializing the Solana Yellowstone Client. You can get Solana Yellowstone gRPC access from the Shyft Dashboard. Please check out our gRPC Authentication Docs for more details.

Initializing the Client

Once you have the authentication details, you can initialize the client in the following manner,

import Client from "@triton-one/yellowstone-grpc";

const client = new Client(
  "YOUR-GRPC-ENDPOINT", //yellowstone grpc url
  "GRPC-ACCESS-TOKEN", //authentication token
  undefined
);

You can use any Yellowstone gRPC endpoint with this client. An access token is optional, as some gRPC services don't require authentication.

The Rust client supports several additional options, as demonstrated in the example above. Most of these options are also available for the TS client, where they are passed as the third argument to the Client constructor.

Specifying what data to stream from gRPC

To specify what on-chain data, we send a SubscribeRequest over the existing Solana Yellowstone gRPC client. These Request allows you to filter for specific accounts, transactions, slots, or other Solana on-chain events, giving you full control over the data you receive.

You can find out more about Subscribe Requests here. The example below demonstrates how to initiate a gRPC stream by sending a SubscribeRequest using a standard gRPC client:

const req: SubscribeRequest = {
  accounts: {},
  slots: {},
  transactions: {
    raydiumAmm: {
      vote: false,
      failed: false,
      signature: undefined,
      accountInclude: ["CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK"],
      //for our usecase we only need to listen to transaction belonging to one program, so we have added one address
      accountExclude: [],
      accountRequired: [],
    },
  },
  transactionsStatus: {},
  entry: {},
  blocks: {},
  blocksMeta: {},
  accountsDataSlice: [],
  ping: undefined,
  commitment: CommitmentLevel.CONFIRMED,
};

Once established, the stream will begin sending data directly to your application. You have the flexibility to modify your subscription on the fly, allowing you to change the data specifications you receive without stopping your stream. For more details on reconnecting and re-starting the stream from a specific slot, or closing your gRPC connection, you can find additional information in our documentation.

Parsing the received transaction

Once a raw Solana transaction is received via the Yellowstone gRPC stream, it must be parsed to extract meaningful, human-readable data. For JavaScript/TypeScript applications, Shyft's IDL-based transaction parser, are commonly used, as they efficiently decode transactions into structured data based on the program's IDL.

On Rust however, we use a interface generated by solores to parse the transaction instruction.

import { SolanaParser } from "@shyft-to/solana-transaction-parser";
import { RaydiumAmmParser } from "./parsers/raydium-amm-parser";

const RAYDIUM_CLMM_IX_PARSER = new SolanaParser([]);

RAYDIUM_CLMM_IX_PARSER.addParserFromIdl(
  RAYDIUM_CLMM_PROGRAM_ID.toBase58(),
  raydiumClmmIdl as Idl,
);

//adding manually written raydium Amm parser

function decodeRaydiumTxn(tx: VersionedTransactionResponse) {
  if (tx.meta?.err) return;
  try{
    const paredIxs = RAYDIUM_CLMM_IX_PARSER.parseTransactionData(
      tx.transaction.message,
      tx.meta.loadedAddresses,
    ); //parsing transaction

    const parsedInnerIxs = RAYDIUM_CLMM_IX_PARSER.parseTransactionWithInnerInstructions(tx);
    //parsing inner instructions
     
     //..code shortened
    return result;
  }catch(err){
    console.log(err);
  }
}
  • Solana gRPC Documentation – In-depth technical docs for implementing real-time streaming with Yellowstone gRPC and Geyser plugin on Solana.

  • Blogs on Solana gRPC Streaming – Guides, use cases, and performance benchmarks for building low-latency Solana applications using gRPC-based infrastructure.

  • Solana DeFi Code Snippets & Examples – Ready-to-use code snippets and integrations for common DeFi protocols, transaction parsers, and real-time Solana data streaming use cases.

Last updated

Was this helpful?