To monitor new liquidity pools on Raydium in real-time and display metadata for the associated tokens, you can use and adapt the existing script subNewAmmPool.ts from the Raydium SDK V1 demo. Below is a detailed explanation of how to achieve this, along with similar functionalities and production-ready implementation suggestions.
Key Steps for Monitoring New Liquidity Pools
Use the subNewAmmPool.ts Script:
This script listens for program account changes on the Solana blockchain using the getProgramAccounts RPC call or WebSocket subscriptions. It filters events to detect new liquidity pools in real-time using the memcmp function for memory comparison.
You can find the script in the Raydium SDK V1 demo repository[[8]].
Fetch Metadata for Tokens:
Once a new pool is detected, retrieve the metadata for the tokens involved using their mint addresses. This can be done using Solana's token metadata program or APIs provided by Raydium (e.g., https://api.raydium.io/v2/sdk/token/solana.mainnet.json)[[3]][[5]].
Display Metadata:
Parse the token metadata (e.g., name, symbol, decimals) and display it in your application. You can use libraries like @raydium-io/raydium-sdk for easier integration[[3]][[7]].
Similar Functionalities and Tools
Here are some similar functionalities and tools that can be adapted for production:
QuickNode Streams and Functions:
QuickNode provides a serverless infrastructure to monitor blockchain events in real-time. You can set up a stream to detect liquidity pool creation events and use a serverless function to process and display token metadata[[2]].
Raydium SDK:
The Raydium SDK provides methods to interact with liquidity pools, fetch pool keys, and retrieve token metadata. It includes utilities for creating, initializing, and managing pools programmatically[[3]][[7]][18].
Custom GraphQL APIs:
Tools like Shyft provide GraphQL APIs to monitor liquidity pools and calculate LP token burn percentages, which can be useful for advanced analytics[[6]].
Production-Ready Implementation
To build a production-ready version of the script:
Set Up Dependencies:
Install the Raydium SDK:
bash
npm install @raydium-io/raydium-sdk
Configure your Solana RPC endpoint and wallet keys in a configuration file.
Monitor Pool Creation:
Use the subNewAmmPool.ts script as a base. Modify it to include error handling, logging, and scalability improvements for production.
Fetch and Cache Metadata:
Use ethers.js or similar libraries to fetch token metadata and cache it locally to reduce redundant blockchain calls.
Optimize Performance:
Use WebSocket subscriptions for real-time updates instead of polling.
Implement rate-limiting and batching for API calls to avoid overloading the system.
Deploy and Scale:
Deploy the application on a cloud platform like AWS or Google Cloud.
Use containerization (e.g., Docker) for easier deployment and scaling.
Example Code Snippet
Here’s a simplified example of how to monitor new pools and fetch token metadata:
typescript
import { Connection, PublicKey } from '@solana/web3.js';
import { Raydium } from '@raydium-io/raydium-sdk';
const connection = new Connection('https://api.mainnet-beta.solana.com', 'confirmed');
async function monitorNewPools() {
const raydium = await Raydium.load({ connection });
raydium.liquidity.onNewPool(async (pool) => {
console.log('New Pool Detected:', pool);
const tokenMetadata = await raydium.token.getTokenMetadata(pool.baseMint);
console.log('Token Metadata:', tokenMetadata);
});
}
monitorNewPools().catch(console.error);
This example uses the Raydium SDK to listen for new pool events and fetch token metadata. You can expand it to include additional features like UI integration or notifications.
By leveraging the Raydium SDK and related tools, you can efficiently monitor new liquidity pools and display token metadata in a production-ready application.