Skip to main content

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.

AMM v4 instructions uniformly expect both a pool side (AMM v4 program accounts) and a market side (OpenBook accounts for the bound market). Omitting or mismatching either set reverts. The account lists below use the field names from the Raydium SDK for clarity; the underlying IDL sometimes uses serum_* prefixes.

Instruction inventory

GroupInstructionNotes
Pool lifecycleInitialize2Current pool-creation instruction (still functional; UI defaults to CPMM for new pools).
LiquidityDepositAdd liquidity, receive LP.
LiquidityWithdrawBurn LP, receive both sides pro-rata.
SwapSwapBaseInExact-input swap (full path: vaults + OpenBook).
SwapSwapBaseOutExact-output swap (full path).
SwapSwapBaseInV2Exact-input swap that bypasses OpenBook — vaults only, fewer accounts.
SwapSwapBaseOutV2Exact-output swap that bypasses OpenBook.
UpkeepSetParamsAdmin: change pool parameters.
UpkeepWithdrawPnlSweep accrued protocol PnL into the PnL-owner accounts.
UpkeepCreateConfigAccountAdmin: initialize the program-level AmmConfig PDA.
UpkeepUpdateConfigAccountAdmin: change program-level config params.
The SDK exposes builders for the user-facing instructions only. Upkeep instructions are typically invoked by the Raydium keeper.

Initialize2

Bootstrap a new AMM v4 pool bound to an existing OpenBook market. Arguments
nonce:        u8
open_time:    u64
init_pc_amount:   u64
init_coin_amount: u64
Accounts (writable W, signer S)
#NameWSNotes
1token_programSPL Token.
2system_program
3rent
4ammWAmmInfo account (seeded key).
5amm_authorityProgram PDA.
6amm_open_ordersWOpenBook OpenOrders (seeded).
7lp_mintW
8coin_mint
9pc_mint
10pool_coin_token_accountW
11pool_pc_token_accountW
12pool_withdraw_queueW
13pool_target_orders_accountW
14pool_lp_token_accountWCreator’s LP ATA.
15pool_temp_lp_token_accountWScratch account.
16market_programOpenBook program.
17marketOpenBook market.
18user_walletWSCreator. Pays rent and funds initial deposit.
19user_token_coinW
20user_token_pcW
Postconditions
  • lp_supply = sqrt(init_coin_amount × init_pc_amount) − INIT_BURN, where INIT_BURN ≈ 100 LP units are kept out of circulation.
  • OpenBook orders have not yet been posted; the first MonitorStep posts the initial grid.
Common errorsInvalidInput (mismatched decimals, non-sorted), NotApproved, OpenBook-side InvalidMarketState.

Deposit

Add liquidity. Arguments
max_coin_amount: u64
max_pc_amount:   u64
base_side:       u64    // 0 = base on coin, 1 = base on pc
// (some SDK variants also accept other_amount_min)
Accounts (abridged)
#NameWS
1token_program
2ammW
3amm_authority
4amm_open_orders
5amm_target_ordersW
6lp_mintW
7pool_coin_token_accountW
8pool_pc_token_accountW
9market
10user_coin_token_accountW
11user_pc_token_accountW
12user_lp_token_accountW
13user_ownerS
Math — standard pro-rata. Using the pool’s effective reserves (vaults + on-book), the SDK computes the coin/pc pair that yields the given LP amount and checks it against max_*. Reverts with ExceededSlippage if either side exceeds the cap.

Withdraw

Burn LP, receive both sides. Arguments
amount: u64    // LP to burn
Accounts — like Deposit with the direction reversed; lp_mint is writable for burn, the user ATAs are receivers. A MonitorStep-like settle-from-OpenBook step happens internally before the pro-rata math so the redemption uses fresh reserves.

SwapBaseIn

Exact-input swap. Always an AMM-path swap (does not route through OpenBook matching).
Use the V2 variants for new code. Since AMM v4 no longer shares liquidity to OpenBook, the V1 entrypoints (SwapBaseIn, SwapBaseOut) — which still require the full set of OpenBook accounts for validation — are functionally redundant. New integrations should use SwapBaseInV2 / SwapBaseOutV2, which take a much smaller account list and represent the canonical execution path today. The V1 forms are documented here for completeness and for reading existing on-chain transactions.
Arguments
amount_in:            u64
minimum_amount_out:   u64
Accounts (abridged)
#NameWS
1token_program
2ammW
3amm_authority
4amm_open_ordersW
5amm_target_ordersW
6pool_coin_token_accountW
7pool_pc_token_accountW
8market_program
9marketW
10market_bidsW
11market_asksW
12market_event_queueW
13market_coin_vaultW
14market_pc_vaultW
15market_vault_signer
16user_source_token_accountW
17user_dest_token_accountW
18user_ownerS
Math — see products/amm-v4/math. Preconditions
  • amm.status allows swap (bit 0 of the status bitmask not set).
  • amm.state_data.pool_open_time <= now.
  • amount_in > 0.
  • user_source_token_account holds at least amount_in.
Postconditions
  • User loses amount_in of source token, gains amount_out ≥ minimum_amount_out of dest token.
  • state_data.swap_*_in_amount and swap_*_out_amount incremented (for analytics).
  • need_take_pnl_* incremented by the protocol fee share.
Common errorsExceededSlippage, InvalidInput, InvalidStatus, InvalidMarket.

SwapBaseOut

Exact-output, inverse of SwapBaseIn. Same accounts. Arguments
max_amount_in: u64
amount_out:    u64

SwapBaseInV2 / SwapBaseOutV2

Variant swap entrypoints that skip the OpenBook accounts entirely. The math is identical to the V1 path, but the account list shrinks to the AMM side only:
#NameWS
1token_program
2ammW
3amm_authority
4amm_open_orders
5pool_coin_token_accountW
6pool_pc_token_accountW
7user_source_token_accountW
8user_dest_token_accountW
9user_ownerS
The pool’s effective reserves still account for tokens posted on OpenBook, so quote math is unchanged. Use V2 to save compute and avoid passing the market accounts when you don’t need an OpenBook crank in the same transaction. The Raydium router always uses the V2 form when routing through AMM v4. Arguments are the same as the V1 forms (amount_in / minimum_amount_out for SwapBaseInV2; max_amount_in / amount_out for SwapBaseOutV2).

MonitorStep (legacy / inert)

No longer cranked. AMM v4 no longer shares liquidity to OpenBook, so MonitorStep has nothing to do — the pool has no orders posted to settle, cancel, or replace. The instruction remains in the on-chain program for backwards compatibility but the Raydium keeper no longer calls it. Calling it manually is effectively a no-op (other than refreshing zeroed-out state) and should not be needed by integrators.
Originally this instruction cranked the pool’s OpenBook interaction. Arguments
plan_order_limit:   u16
place_order_limit:  u16
cancel_order_limit: u16
Accounts — everything above for a swap, plus administrative OpenBook accounts. Original effect (no longer relevant in practice):
  • Settled any filled orders (their proceeds moved from market_coin_vault/market_pc_vault into the pool’s vaults via OpenBook CPI).
  • Cancelled stale orders whose prices or sizes no longer matched target_orders.
  • Posted new orders to close the gap between target_orders and amm_open_orders.
Permissionless. Any account could call it; historically the Raydium keeper did so routinely.

WithdrawPnl / TakePnl

Admin sweep of accrued protocol fees. Arguments
  • WithdrawPnl takes no args; it reads need_take_pnl_* and moves those exact amounts.
Accounts (abridged)
#NameWS
1token_program
2ammW
3amm_authority
4amm_config
5amm_open_ordersW
6pool_coin_token_accountW
7pool_pc_token_accountW
8pnl_coin_token_accountWRecipient, stored on AmmConfig.
9pnl_pc_token_accountW
10pnl_ownerSAdmin multisig.
11market_program
12marketW
13market_event_queueW
14market_coin_vaultW
15market_pc_vaultW
16market_vault_signer
Effect
  • Transfers need_take_pnl_coin from pool_coin_token_account to pnl_coin_token_account.
  • Same for pc.
  • Zeros need_take_pnl_coin and need_take_pnl_pc.
No change to reserves since accrued PnL was already excluded from the invariant.

SetParams

Admin param changes: status bitmask, ordering-grid depth, amount waves, fees (rarely), etc. Called by the Raydium multisig. Arguments are a param: u8 tag + payload, analogous to CPMM’s UpdateAmmConfig.

State-change matrix

Instructionlp_mint supplyVaultsPnL countersOpenBook
Initialize2init supply minted to creator+ init_coin_amount, + init_pc_amount0OpenOrders created
Deposit++ bothsettle fills
Withdraw− bothsettle fills
SwapBaseIn+ in, − out+ pnl sharemaybe re-post grid
SwapBaseOut+ in, − out+ pnl sharemaybe re-post grid
MonitorStepsettle fillscancel / post
WithdrawPnl− (pnl swept)0
SetParams

Where to go next

Sources: