Documentation Index
Fetch the complete documentation index at: https://docs.raydium.io/llms.txt
Use this file to discover all available pages before exploring further.
Version banner. All demos target
@raydium-io/raydium-sdk-v2@0.2.42-alpha against Solana mainnet-beta, verified 2026-04. Program ID: 675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8 (see reference/program-addresses).New-pool creation is not shown here. The Raydium UI no longer offers AMM v4 pool creation — new pairs default to CPMM. The AMM v4 program itself still accepts
Initialize2 on-chain; it just isn’t the recommended path. The demos below cover the live-pool operations every integrator still needs: swap, deposit, withdraw.Setup
Fetch a pool by id
poolKeys is the struct the instruction builders consume. It carries every AMM v4 and OpenBook account in the order the program expects.
Swap (base-in)
Swap (base-out)
Add liquidity
fixedSide: "a" tells the SDK you supplied the exact amountInA and that amountInB should be at-most maxAnotherAmount. The pool’s on-book liquidity is settled before the pro-rata math so the deposit ratio matches the freshest reserves.
Remove liquidity
Compute-unit / priority fee tuning
AMM v4 swaps are heavy on compute because every instruction validates the full OpenBook state. A typical swap uses 180k–250k CU depending on how many open orders need settling on the way through. Always pass a compute-unit limit:computeBudgetConfig, the SDK may still use its own default; inspect innerTransactions to confirm. See integration-guides/priority-fee-tuning.
Direct Rust CPI
If you must CPI into AMM v4 from your own Anchor program, you will need to modelSwapBaseIn’s account list verbatim. A minimal sketch:
Instruction.
Pitfalls
- Missing an OpenBook account. All 8 OpenBook-side accounts are required on every swap, deposit, and withdraw; the SDK handles this, hand-built instructions often do not.
- Reading raw vault balances. Does not reflect on-book-escrowed amounts or accrued PnL. Use the SDK’s quote or
api-v3.raydium.io/pools/info/ids. - OpenBook event queue full. A pool may revert swaps with
SerumOrderErrorwhen its market’s event queue needs cranking. Cranking is permissionless (MonitorStepon the market’s OpenBook accounts). - Token-2022 mints. Not supported. An AMM v4 pool cannot be created against a Token-2022 mint; any Token-2022 pair should be on CPMM or CLMM.
Where to go next
products/amm-v4/instructions— the instruction-level surface behind these demos.user-flows/migrate-amm-v4-to-cpmm— if you are an LP considering migration.integration-guides/priority-fee-tuning— priority-fee sizing for heavy AMM v4 swaps.


