# Detect New Pools on Raydium AMM

In the fast-moving world of decentralized finance, being among the first to identify new liquidity pools can offer significant advantages. Raydium AMM frequently sees the creation of new pools, and quickly detecting these allows traders and analysts to capitalize on early opportunities. In this document, we will illustrate how we can detect new Pools on Raydium AMM

{% hint style="success" %}
The complete source code for this project is available on GitHub.&#x20;

* [<mark style="color:yellow;">TypeScript</mark>](https://github.com/Shyft-to/solana-defi/tree/main/Raydium/Typescript/streaming_newly_added_pool_accounts)

Please feel free to clone the repository and try it out. Additionally, you will find other relevant and useful code examples related to gRPC and streaming [<mark style="color:yellow;">here</mark>](https://github.com/Shyft-to/solana-defi).
{% endhint %}

## Step-by-Step Breakdown

This project consists of two key components:

1. Create a Yellowstone gRPC `SubscribeRequest` with Raydium AMM Filters
2. Parse the Incoming Account Data

### 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](https://docs.shyft.to/docs#authentication) for more details.&#x20;

#### Initializing the Client

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

{% tabs %}
{% tab title="TypeScript" %}

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

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

{% endtab %}

{% tab title="Rust" %}

```rust
use yellowstone_grpc_client::{GeyserGrpcClient, Interceptor}

async fn connect(&self) -> anyhow::Result<GeyserGrpcClient<impl Interceptor>> {
     GeyserGrpcClient::build_from_shared(self.endpoint.clone())? //grpc url
            .x_token(Some(self.x_token.clone()))? //grpc auth token
            .connect_timeout(Duration::from_secs(10))
            .timeout(Duration::from_secs(10))
            .tls_config(ClientTlsConfig::new().with_native_roots())?
            .max_decoding_message_size(1024 * 1024 * 1024)
            .connect()
            .await
            .map_err(Into::into)
}
```

{% endtab %}
{% endtabs %}

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](https://docs.shyft.to/docs#what-are-subscribe-requests) here.&#x20;

We first construct a `SubscribeRequest` targeting the Raydium AMM program (`675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8`) with specific **account-level memcmp filters**:

* **Filter 1**: Matches liquidity pools where the `quoteMint` is SOL (`So1111...`), identifying pools paired with SOL.
* **Filter 2**: Verifies that the `marketProgramId` is set to Raydium Serum Market (`srmqPvym...`).
* **Filters 3 & 4**: Ensure both `swapQuoteInAmount` and `swapBaseOutAmount` are initially zero—indicating the pool has just been created and no swaps have occurred yet.

This setup streams **only newly initialized Raydium AMM liquidity pool accounts** that meet these conditions.

{% tabs %}
{% tab title="TypeScript" %}
{% code overflow="wrap" %}

```typescript
const request: SubscribeRequest = {
  "slots": {},
  "accounts": {
    "raydium": {
      "account": [],
      "filters": [
        {
          "memcmp": {
            "offset": LIQUIDITY_STATE_LAYOUT_V4.offsetOf('quoteMint').toString(), // Filter for only tokens paired with SOL
            "base58": "So11111111111111111111111111111111111111112"
          }
        },
        {
          "memcmp": {
            "offset": LIQUIDITY_STATE_LAYOUT_V4.offsetOf('marketProgramId').toString(), 
            "base58": "srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX"
          }
        },
        {
          "memcmp": {
            "offset": LIQUIDITY_STATE_LAYOUT_V4.offsetOf('swapQuoteInAmount').toString(), 
            "bytes": Uint8Array.from([0])
          }
         },
        {
          "memcmp": {
            "offset": LIQUIDITY_STATE_LAYOUT_V4.offsetOf('swapBaseOutAmount').toString(), 
            "bytes": Uint8Array.from([0])
          }
        }
      ],
      "owner": ["675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"] 
    }
  },
  "transactions": {},
  "blocks": {},
  "blocksMeta": {
    "block": []
  },
  "accountsDataSlice": [],
  "commitment": CommitmentLevel.PROCESSED, // Subscribe to processed blocks for the fastest updates
  entry: {},
  transactionsStatus: {}
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

Once established, the stream will begin sending data directly to your application. You have the flexibility to [**modify your subscription**](https://docs.shyft.to/solana-yellowstone-grpc/docs/getting-started/modify-grpc-subscribe-request) **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**](https://docs.shyft.to/solana-yellowstone-grpc/docs/getting-started/replaying-slots-with-grpc)**, or** [**closing your gRPC connection**](https://docs.shyft.to/solana-yellowstone-grpc/docs/getting-started/gracefully-closing-a-grpc-connection), you can find additional information in our [documentation](https://docs.shyft.to/solana-yellowstone-grpc/docs).

### Handling the incoming data

Once the subscription is active, your gRPC client starts receiving account updates in real-time. You check for the presence of an `account` field in the stream. The `tOutPut()` function decodes and extracts critical on-chain metadata about the Raydium pool:

{% tabs %}
{% tab title="TypeScript" %}

```typescript
export function tOutPut(data){
    const dataTx = data?.account?.account;
    const signature = decodeTransact(dataTx?.txnSignature); // Transaction signature
    const pubKey = decodeTransact(dataTx?.pubkey);          // Account public key
    const owner = decodeTransact(dataTx?.owner);            // Program owner
    const poolstate = LIQUIDITY_STATE_LAYOUT_V4.decode(dataTx.data); // Pool state decoded using Raydium SDK
    const slot = data?.account.slot;                        // Slot number of update

    return {
        signature,
        pubKey,
        owner,
        poolstate,
        slot
    }
}
```

{% endtab %}
{% endtabs %}

**This function extracts:**

* `signature`: The transaction signature associated with the account creation.
* `pubKey`: The public key of the new Raydium pool account.
* `owner`: Should match the Raydium AMM program ID.
* `poolstate`: Decoded struct holding all AMM pool configuration details (mints, reserves, fee structure, etc.).
* `slot`: Solana slot number when the update occurred.

### Important Links

* [**Solana gRPC Documentation**](https://docs.shyft.to/solana-yellowstone-grpc/docs) – In-depth technical docs for implementing real-time streaming with **Yellowstone gRPC** and **Geyser plugin** on Solana.
* [**Blogs on Solana gRPC Streaming**](https://blogs.shyft.to/) – Guides, use cases, and performance benchmarks for building **low-latency Solana applications** using **gRPC-based infrastructure**.
* [**Solana DeFi Code Snippets & Examples**](https://github.com/Shyft-to/solana-defi/) – Ready-to-use code snippets and integrations for common **DeFi protocols**, **transaction parsers**, and **real-time Solana data streaming** use cases.
