Skip to main content
Version banner. All demos target @raydium-io/raydium-sdk-v2@0.2.64-alpha against Solana mainnet-beta, verified 2026-09-09 — every builder name, parameter name and parameter type below was checked against that release’s source and against raydium-sdk-V2-demo/src/amm. Program ID: 675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8 (see reference/program-addresses).Two traps that bite most first integrations: computeAmountOut’s slippage is a plain number (0.005 = 0.5%), not a Percent; and liquidity.swap requires inputMint as a base58 string.
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 account in the order the program expects, plus the legacy market fields that the current program accepts positionally but no longer reads.

Swap (base-in)

The SDK routes AMM v4 swaps through the V2 entrypoints, which do not carry the OpenBook accounts. (After the 2026-07 upgrade, the market accounts are no longer validated even on the legacy v1 path.)

Swap (base-out)

Add liquidity

fixedSide: "a" tells the SDK you supplied the exact amountInA and that amountInB should be at most maxAnotherAmount. The pro-rata math runs off the vault balances minus accrued PnL — there is no longer any on-book component to settle first.

Remove liquidity

Slippage mins protect against the pool’s state shifting between your pre-quote and the land time.

Compute-unit / priority fee tuning

Since the OpenBook removal an AMM v4 swap no longer validates any market state, so a V1 SwapBaseIn is markedly cheaper than it used to be — and SwapBaseInV2 (8 accounts, no market placeholders) is cheaper still. Measure your own path rather than budgeting off historical figures, and always pass an explicit compute-unit limit:
If you omit computeBudgetConfig, the SDK may still use its own default; inspect the returned transaction 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 model SwapBaseIn’s account list verbatim. A minimal sketch:
AMM v4 does not ship an Anchor crate for CPI. The sketch above uses a manually-constructed Instruction.
The CPI sketch above uses the legacy v1 SwapBaseIn layout (tag 9, 17 accounts) for reading/reproducing existing transactions. Since the 2026-07 upgrade the market accounts are accepted but ignored. For new code, prefer SwapBaseInV2 / SwapBaseOutV2 (tags 16 / 17), which drop the market accounts (and amm_open_orders) entirely — pass only 8 accounts: token_program, amm, amm_authority, the two pool vaults, the two user token accounts, and user_owner.

Pitfalls

  • Wrong account count on v1 swaps. The legacy SwapBaseIn / SwapBaseOut still require the full 17-account (or 18-account) list — a mismatched count reverts with WrongAccountsNumber. The market accounts’ contents are no longer validated, but you must still occupy their slots. Prefer the V2 entrypoints to avoid this.
  • Reading raw vault balances. Reserves are now vault-only; subtract accrued PnL (need_take_pnl_*). The SDK quote or api-v3.raydium.io/pools/info/ids handles this for you.
  • Calling removed instructions. MonitorStep, MigrateToOpenBook, WithdrawSrm, SimulateInfo, AdminCancelOrders, and legacy Initialize / PreInitialize now revert. Use Initialize2 for pool creation; there is no crank to call.
  • 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

Sources: