Version banner. All TypeScript demos target
@raydium-io/raydium-sdk-v2@0.2.42-alpha against Solana mainnet-beta, verified 2026-04. The Rust CPI skeleton targets raydium-cp-swap on the master branch, Anchor 0.30.x. Program IDs are pulled via constants from reference/program-addresses.Prerequisites
raydium-sdk-V2-demo/src/cpmm; the GitHub link sits next to each section. Bootstrap follows the demo repo’s config.ts.template (source):
Raydium instance is the SDK’s facade — every demo below uses it. It lazily fetches token lists and fee configs from api-v3.raydium.io; you can seed it with your own data in offline environments.
Create a CPMM pool
Source:src/cpmm/createCpmmPool.ts
- Sorting the mints into token0/token1 order before deriving the PDA.
- Paying the one-time
create_pool_feetopoolFeeAccount. - Creating the caller’s associated token accounts if missing.
- Choosing the right token program (SPL Token vs Token-2022) per side.
Swap (base-input)
Source:src/cpmm/swap.ts
getPoolInfoFromRpc. Do not quote off api-v3.raydium.io for a transaction you are about to sign — a quote that is one block stale can slip into ExceededSlippage at land time.
Swap (base-output)
Source:src/cpmm/swapBaseOut.ts
Deposit liquidity
Source:src/cpmm/deposit.ts
lpAmount into needed_token_0 and needed_token_1 using the pool’s current reserves, inflates each by 1 + slippage for the instruction’s maximum_* arguments, and builds the ATA creations if necessary.
Withdraw liquidity
Source:src/cpmm/withdraw.ts
Collect protocol/fund/creator fees
Source:src/cpmm/collectCreatorFee.ts, src/cpmm/collectAllCreatorFee.ts
These instructions are admin- or creator-gated and typically invoked from a signer held by the Raydium multisig or the pool creator. The SDK surfaces them as raw builders:
PoolState:
Rust CPI skeleton
If you want to invoke CPMM from your own Anchor program — for example, a vault that swaps on behalf of its depositors — the CPI context looks like this. Account ordering followsproducts/cpmm/instructions.
CpiContext::new for CpiContext::new_with_signer and pass your seeds.
Common pitfalls
A short checklist before opening a support ticket:- Sorted mints. If your derived
poolStatePDA does not match the on-chain pool, you probably forgot to sort the mints. - Stale API quote. Never pass a reserve value from
api-v3.raydium.iointoCurveCalculator.swap. Fetch from an RPC. - Wrong token program. A Token-2022 mint’s vault is owned by the Token-2022 program, not by SPL Token. Always use the pool’s
token_0_program/token_1_programfields. - Slippage under-denominated for transfer-fee mints. If either side of the pool is a Token-2022 transfer-fee mint, your
minimum_amount_outmust be denominated in what the user actually receives, not in what the vault sends. NotApprovedon a swap. CheckPoolState.status— the admin may have paused swaps on that pool. Seeproducts/cpmm/instructionsfor the status bitmask.
Where to go next
sdk-api/typescript-sdk— full SDK reference.sdk-api/rest-api— quote and pool-metadata endpoints.user-flows/create-cpmm-pool— the non-code walkthrough of the same flow.integration-guides/aggregator— if you are routing CPMM as part of a multi-hop path.

