Detecting Buy/Sell Transactions on Raydium AMM

Ultra-Low Latency Monitoring: Capturing Buy and Sell Pump.fun Events with Solana Yellowstone gRPC

In the rapid Solana memecoin market, instantly knowing about buy and sell events on Pump AMM offers a crucial edge for traders and analysts. This guide explains how to leverage Solana's Yellowstone gRPC stream to capture and parse live transaction data, ensuring you detect token swaps the moment they happen.

Step-by-Step Breakdown

This project consists of two key components:

  1. Streaming Raydium AMM Transactions via Yellowstone gRPC

  2. Parsing the Received transactions along with events

  3. Identifying Buy / Sell transactions based on the Pump Events

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.

Subscribe Requests specify what data to stream by the means of filters. When you want to stream transactions, you use a transaction filter. Inside this filter, you tell it which program's transactions you're interested in by providing its "program ID" in the "account" field. 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: {
    pumpFun: {
      vote: false,
      failed: false,
      signature: undefined,
      accountInclude: ["pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA"],
      //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. However, in cases where an IDL is not readily available, manual parsers may be used to interpret the raw transaction data. This is one such case.

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

import { SolanaParser } from "@shyft-to/solana-transaction-parser";

const RAYDIUM_IX_PARSER = new SolanaParser([]);
//initializing the parser

RAYDIUM_IX_PARSER.addParser(
  "675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8",
  raydiumAmmParser.parseInstruction.bind(raydiumAmmParser),
);

function decodeRaydiumTxn(tx: VersionedTransactionResponse) {
  if (tx.meta?.err) return;

  const parsedIxs = IX_PARSER.parseTransactionWithInnerInstructions(tx);

  const programIxs = parsedIxs.filter((ix) =>
    ix.programId.equals(RAYDIUM_PUBLIC_KEY),
  );

  if (programIxs.length === 0) return;
  const LogsEvent = LOGS_PARSER.parse(parsedIxs, tx.meta.logMessages);
  const result = { instructions: parsedIxs, events: LogsEvent };
  bnLayoutFormatter(result);
  return result;
}

Detecting Buy/Sell Events

Once a valid Raydium AMM swap transaction is streamed and decoded, the transactionOutput(parsedTxn) function extracts critical real-time swap data for indexing or alerting. It processes the parsed transaction to retrieve:

  • Event Name: Indicates whether the user performed a "swapBaseIn" (buy) or "swapBaseOut" (sell) operation on Raydium.

  • SIGNER: The wallet address initiating the swap, determined by identifying the userSourceOwner or fallback signer from the instruction accounts.

  • MINT: The token address involved in the AMM swap (usually a pump.fun token).

  • AMOUNT IN: The input amount of SOL or token provided by the user for the swap.

  • AMOUNT OUT: The output amount of the token or SOL the user receives after the swap.

  • TYPE: An optional field used to tag the transaction with contextual metadata (e.g., trade intent or source).

These details are then formatted and returned in a structured object, making it easy to log or feed into real-time DeFi dashboards, trading bots, or alert systems. By parsing Raydium AMM swaps on Solana using Yellowstone gRPC and program-specific event decoding, developers can monitor liquidity flows, token activity, and user behavior with low-latency precision.

  • 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?