Raydium SDK Liquidity Withdrawal Guide

To withdraw your liquidity without using the Novadex Frontend, follow the Raydium SDK guidelines:

Step 1: Clone the Repository

  1. Clone the Raydium SDK V2 demo repository:

  2. After cloning, navigate into the new directory and install dependencies:

    • cd raydium-sdk-V2-demo

    • yarn install


Step 2: Update Addresses

  1. Search for the address CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK in the directory and replace all instances with cLmhcuG6pHbGHLzEKphgq6DBJvSiiY4h8D4kAppw7jd. Be thorough, as this address will appear in multiple files.

  2. Ensure this replacement is done especially in the node_modules file at:

    • raydium-sdk-V2-demo/node_modules/@raydium-io/raydium-sdk-v2/src/common/programId.ts


Step 3: Configure Settings

  1. Update the config.ts.template file to match your configuration, then rename it to config.ts.

  2. Replace the following placeholders:

    • <YOUR_WALLET_SECRET_KEY> with your own wallet secret key.

    • <YOUR_RPC_URL> with your preferred RPC URL.

    • <API_HOST> : usually, the Raydium API host isn’t needed unless you’re testing on devnet.


Step 4: Set Up Liquidity Withdrawal

  1. Replace the poolId with the ID of the pool you wish to withdraw from. For example:

    • const poolId = '6UmmUiYoBjSrhakAobJw8BvkmJtDVxaeBtbt7rxWo1mg'; (for the RAY-USDC pool)

  2. Update the following part of the script:

/
  if (raydium.cluster === 'mainnet') {
    // note: api doesn't support get devnet pool info, so in devnet else we go rpc method
    // if you wish to get pool info from rpc, also can modify logic to go rpc method directly
    const data = await raydium.api.fetchPoolById({ ids: poolId })
    poolInfo = data[0] as ApiV3PoolInfoConcentratedItem
    if (!isValidClmm(poolInfo.programId)) throw new Error('target pool is not CLMM pool')
  } else {
    const data = await raydium.clmm.getPoolInfoFromRpc(poolId)
    poolInfo = data.poolInfo
    poolKeys = data.poolKeys
  }

to:
 // Fetch pool info directly from RPC method regardless of the cluster
  const data = await raydium.clmm.getPoolInfoFromRpc(poolId)
  poolInfo = data.poolInfo
  poolKeys = data.poolKeys


  if (!isValidClmm(poolInfo.programId)) throw new Error('target pool is not CLMM pool')
  1. This enables the use of RPC instead of the Raydium API. If errors occur, consider switching to a different RPC or even a paid RPC.


Step 5: Run the Withdrawal Script Execute the following command to withdraw your liquidity:

  • yarn dev src/amm/decreaseLiquidity.ts

If your transaction is not successful, try switching RPC providers. If it is still not successful, it might be due to Solana network congestion. You can try adjusting the gas price or wait for an interval where network demand is lower.

Last updated