3

I'm trying to fetch the pool keys that are necessary to make swap a transaction using the Raydium SDK. These keys are available in the https://api.raydium.io/v2/sdk/liquidity/mainnet.json file, but this is not updated in real time and its download is heavily rate-limited. So what happens is that when I detect a new liquidity pool using dextools.io APIs I would need to wait several minutes for this information to be available.

How do websites like dextools.io get the information about the pool when it's not in the mainnet.json file yet? Based on a similar question (Faster method to retrieve pool keys [Raydium]) asked previously, I assume this can be done with the getProgramAccounts RPC call, but:

  1. This call is not available on the RPC providers I've tried, as it appears to be very expensive
  2. Discarding point 1. it seems that the call requires a marketProgramId which is itself available only through the mainnet.json file (as far as I understand things).

EDIT I might've understood that the marketProgramId refers to the Serum program (srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX) but even if this is correct the call is still blocked for the performance reasons mentioned earlier.

How to sort this out?

3 Answers 3

1

You can either use Geyser to monitor pool creation in real time https://github.com/raydium-io/raydium-sdk-V1-demo/blob/master/src/subNewAmmPool.ts

These can be used to get pool keys for previously created pools, etc CPMM https://github.com/raydium-io/raydium-sdk-V1-demo/blob/master/src/formatAmmKeys.ts CLMM https://github.com/raydium-io/raydium-sdk-V1-demo/blob/master/src/formatClmmKeys.ts

0

If you want to retrieve information about a new pool, you'll need to use Raydium WebSocket to get the pool info.

2
0

You can use following snippet to listen to pool creation events in real time

It listens for program account change logs filtered with memcmp memory compare function.

The full code can be found at Listen for pool creation events on Raydium

private async subscribeToRaydiumPools(config: { quoteToken: Token }) {
    return this.connection.onProgramAccountChange(
      MAINNET_PROGRAM_ID.AmmV4,
      async (updatedAccountInfo) => {
        this.emit('pool', updatedAccountInfo);
      },
      this.connection.commitment,
      [
        { dataSize: LIQUIDITY_STATE_LAYOUT_V4.span },
        {
          memcmp: {
            offset: LIQUIDITY_STATE_LAYOUT_V4.offsetOf('quoteMint'),
            bytes: config.quoteToken.mint.toBase58(),
          },
        },
        {
          memcmp: {
            offset: LIQUIDITY_STATE_LAYOUT_V4.offsetOf('marketProgramId'),
            bytes: MAINNET_PROGRAM_ID.OPENBOOK_MARKET.toBase58(),
          },
        },
        {
          memcmp: {
            offset: LIQUIDITY_STATE_LAYOUT_V4.offsetOf('status'),
            bytes: bs58.encode([6, 0, 0, 0, 0, 0, 0, 0]),
          },
        },
      ],
    );
  }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.