All Resources
Parse Raydium AMM Swaps from Solana gRPC Streams
RaydiumTypeScriptMarch 24, 20263 min read

Parse Raydium AMM Swaps from Solana gRPC Streams

Stream Raydium AMM swaps over Yellowstone gRPC and decode pool, token amount and trade direction fields in TypeScript.

raydiumgrpctypescripttransaction-parsingamm

Raydium swap parsing starts at the transaction stream

Raydium is one of the most active automated market makers (AMMs) on Solana, processing thousands of swaps every minute. For developers building trading bots, analytics dashboards, or monitoring tools, the ability to stream and parse these transactions in real-time is essential.

The useful part is not just seeing a Raydium signature. You need to decode token amounts, pool addresses and trade direction quickly enough for bots, dashboards and alerting systems to act on it.

Why Yellowstone gRPC beats polling for Raydium swaps

Yellowstone gRPC (also known as Geyser gRPC) is a high-performance streaming interface for Solana. Unlike polling RPC endpoints, gRPC pushes data to your application the moment it's confirmed on-chain. This means:

  • Sub-second latency, you see transactions as they land
  • No rate limits from polling
  • Filtered streams, subscribe only to the programs and accounts you care about

Subscribe to the Raydium AMM program

First, you'll need a Yellowstone gRPC endpoint and token from your dashboard. Dedicated infrastructure is available on Dedicated Nodes.

import Client, { CommitmentLevel } from '@triton-one/yellowstone-grpc';

const client = new Client(process.env.YELLOWSTONE_GRPC_ENDPOINT!, process.env.YELLOWSTONE_GRPC_TOKEN!, undefined);
await client.connect();

// Subscribe to Raydium AMM program transactions
const stream = await client.subscribe();

await stream.write({
  transactions: {
    raydium: {
      accountInclude: ['675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8'],
      accountExclude: [],
      accountRequired: [],
      failed: false,
      vote: false,
    },
  },
  accounts: {},
  slots: {},
  blocks: {},
  blocksMeta: {},
  entry: {},
  accountsDataSlice: [],
  transactionsStatus: {},
  commitment: CommitmentLevel.PROCESSED,
});

Parsing Transaction Data

Raydium AMM transactions contain the swap instruction data encoded in the transaction's inner instructions. The key fields to extract are:

  • Pool address, identifies which token pair was traded
  • Amount in / Amount out, the swap amounts
  • Token mints, which tokens were swapped
  • User wallet, who performed the swap
function parseRaydiumSwap(tx: TransactionMessage) {
  const instructions = tx.transaction?.transaction?.message?.instructions || [];
  
  for (const ix of instructions) {
    // Check if this is a Raydium AMM instruction
    if (ix.programId === 'RAYDIUM_AMM_PROGRAM_ID') {
      const data = Buffer.from(ix.data);
      const discriminator = data.readUInt8(0);
      
      // Discriminator 9 = Swap instruction
      if (discriminator === 9) {
        const amountIn = data.readBigUInt64LE(1);
        const minAmountOut = data.readBigUInt64LE(9);
        
        return {
          type: 'swap',
          amountIn: amountIn.toString(),
          minAmountOut: minAmountOut.toString(),
          pool: ix.accounts[1],
          user: ix.accounts[16],
        };
      }
    }
  }
  return null;
}

Detecting Buy vs Sell Events

To determine whether a swap is a buy or sell, you need to check the direction of the swap relative to the base token (usually SOL or USDC):

function classifyTrade(swap: ParsedSwap, pool: PoolInfo) {
  const isBaseToQuote = swap.sourceToken === pool.baseMint;
  return isBaseToQuote ? 'sell' : 'buy';
}

Where Raydium parsing usually breaks

  1. IDL version mismatches, Raydium has multiple program versions (AMM v4, CLMM, CPMM). Make sure you're parsing against the correct IDL.
  2. Inner instruction parsing, Some swap data is in inner instructions, not top-level. Always check both.
  3. Connection handling, gRPC streams can disconnect. Implement automatic reconnection with exponential backoff.

What to build once swaps are decoded

With real-time Raydium transaction data flowing into your application, you can:

  • Build a trading bot that reacts to large swaps
  • Create a price feed by aggregating swap ratios
  • Monitor new pool creation events for early token discovery
  • Track whale wallets making large trades

Infrastructure

Solana Tracker's Yellowstone gRPC endpoints are optimized for low-latency DeFi streaming. Use the Data API for pre-parsed token data, or Dedicated Nodes for isolated RPC.

Download the example

Clone the full runnable project on GitHub, npm install && npm start with your keys in .env. See the tutorial for step-by-step context.

Runnable Node.js project — clone from GitHub, add keys to .env, then npm start. gRPC examples use native dependencies — run locally with Node.js.