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.

Stable AMM shares most of its instruction surface with AMM v4. The unique instructions are InitModelData and UpdateModelData, which populate and update the lookup table. All other operations (swap, deposit, withdraw, crank) follow the same pattern as AMM v4.

Instruction inventory

InstructionCategoryNotes
InitializeLifecycleCreate pool (requires pre-allocated model-data account).
PreInitializeLifecycleLegacy pre-allocation helper.
InitModelDataModel setupCreate and initialize the lookup table.
UpdateModelDataModel setupPopulate up to 5 table elements per call.
DepositLiquidityAdd liquidity, receive LP.
WithdrawLiquidityBurn LP, receive both sides.
SwapBaseInSwapExact-input swap.
SwapBaseOutSwapExact-output swap.
MonitorStepCrankSettle OpenBook, update orders.
SetParamsAdminChange pool parameters.
WithdrawPnlAdminSweep accrued protocol fees.
WithdrawSrmLegacySweep SRM rebates (legacy).
SimulateInfoDiagnosticRead-only quote helper.

Initialize

Bootstrap a new Stable AMM pool bound to an existing OpenBook market and a pre-created ModelDataInfo account. Arguments
nonce: u8
open_time: u64
Accounts (writable W, signer S)
#NameWSNotes
1token_programSPL Token.
2system_program
3rent
4ammWPool’s AmmInfo account.
5amm_authorityProgram-wide PDA.
6amm_open_ordersWOpenBook OpenOrders.
7lp_mintWFungible LP token mint.
8coin_mint
9pc_mint
10pool_coin_token_accountWPool’s coin vault.
11pool_pc_token_accountWPool’s pc vault.
12amm_target_ordersWGrid for OpenBook orders.
13model_data_accountThe lookup table account.
14serum_programOpenBook program.
15serum_marketOpenBook market.
16user_dest_lp_tokenWCreator’s LP ATA (receives initial LP).
17user_walletWSCreator; pays rent, funds initial deposit.
(opt)srm_tokenWSRM token account for fee discounts (legacy).
Preconditions
  • model_data_account must already be created and initialized by a prior InitModelData.
  • lp_mint must be empty (zero supply).
  • Vaults must exist and be owned by amm_authority.
Postconditions
  • AmmInfo is initialized with all references.
  • TargetOrders is zeroed and ready for the first MonitorStep.
  • Initial LP tokens are minted and sent to user_dest_lp_token.
  • OpenBook orders have not been posted yet; the first MonitorStep posts them.

InitModelData

Create and initialize the ModelDataInfo account. Must be called once before Initialize. Arguments
multiplier: u64       // scale factor (e.g., 10^6)
Accounts (writable W, signer S)
#NameWSNotes
1model_data_accountWThe 50k-element table account.
2amm_adminSPool admin (must sign to prove authority).
Preconditions
  • model_data_account must be sufficiently large (~1.2 MB for 50k × 24 bytes).
  • model_data_account must be owned by the Stable program.
Postconditions
  • status = Initialized.
  • multiplier is set.
  • valid_data_count = 0 (no elements populated yet; call UpdateModelData to add them).
  • elements array is zeroed.

UpdateModelData

Populate up to 5 table elements in a single call. Must be called after InitModelData but before swaps start using the table. Arguments
array_data: [UpdateModelData; 5]

pub struct UpdateModelData {
  pub index: u64,
  pub data: DataElement,
}
Accounts (writable W, signer S)
#NameWSNotes
1amm_adminSSigner (must be the pool admin).
2model_data_accountWThe table account.
Preconditions
  • amm_admin must match AmmInfo.amm_admin.
  • Each index in array_data must be valid (within 50,000).
  • Entries must be sorted (not validated on-chain for speed): x ascending, y descending, price ascending.
Postconditions
  • Elements are written to model_data_account.elements[index] for each input.
  • valid_data_count is updated to the max index written + 1.
Governance note: There is no on-chain enforcement of sort order or price consistency. A malicious or careless admin can corrupt the table and cause incorrect quotes. In practice, the Raydium multisig controls this address.

Deposit

Add liquidity, receive LP tokens. Arguments
max_coin_amount: u64
max_pc_amount: u64
base_side: u64          // 0 = base on coin, 1 = base on pc
Accounts — like AMM v4, ~13 accounts. Must include the model_data_account as read-only. Math — standard pro-rata using the lookup table to compute the ratio. The SDK computes coin/pc pair for the desired LP amount and checks against max caps.

Withdraw

Burn LP, receive both sides pro-rata. Arguments
amount: u64            // LP tokens to burn
Accounts — like AMM v4, with model_data_account as read-only. Preconditions
  • user_lp_token_account holds at least amount.
Postconditions
  • amount LP tokens are burned.
  • User receives coin and pc amounts according to the current pro-rata, adjusted for accrued fees.

SwapBaseIn

Exact-input swap using the lookup table for pricing. Arguments
amount_in: u64
minimum_amount_out: u64
Accounts (~17 total)
#NameWSNotes
1token_program
2ammW
3amm_authority
4amm_open_ordersW
5amm_target_ordersW
6pool_coin_token_accountW
7pool_pc_token_accountW
8model_data_accountRead-only lookup table.
9serum_program
10serum_marketW
11serum_bidsW
12serum_asksW
13serum_event_queueW
14serum_coin_vaultW
15serum_pc_vaultW
16serum_vault_signer
17user_source_tokenWUser’s input token account.
18user_dest_tokenWUser’s output token account.
19user_ownerSUser (transaction signer).
Preconditions
  • amm.status allows swap.
  • user_source_token holds ≥ amount_in.
Postconditions
  • User loses amount_in, gains amount_out ≥ minimum_amount_out.
  • Pool fees increment need_take_pnl_* counters.
  • OpenBook orders may settle if filled.
Math — Lookup-table interpolation as described in products/stable/math.

SwapBaseOut

Exact-output swap (inverse of SwapBaseIn). Same accounts, different math direction. Arguments
max_amount_in: u64
amount_out: u64

MonitorStep

Permissionless crank: settle OpenBook fills, update the limit-order grid. Arguments
plan_order_limit: u16
place_order_limit: u16
cancel_order_limit: u16
Accounts (~18 total) — same as AMM v4 MonitorStep plus the model_data_account as read-only. Preconditions
  • OpenBook account references must match the pool’s bound market.
Postconditions
  • Pending OpenBook fills are settled into the pool vaults.
  • New limit orders are posted to OpenBook based on the lookup-table curve.
  • TargetOrders is updated.

SetParams

Admin-only. Change pool parameters (status, state, fees, owner, model-data key, etc.). Arguments
param: u8              // which parameter to change (Status, State, Fees, etc.)
value: Option<u64>    // new value (if param is numeric)
new_pubkey: Option<Pubkey>  // new address (if param is an account key)
fees: Option<Fees>    // new fees (if param is Fees)
Accounts — varies by param. Always requires amm_admin as signer. Common params:
  • param = 0 (Status) — change the operation bitmask.
  • param = 9 (Fees) — change trade_fee, pnl split, etc.
  • param = 11 (ModelDataKey) — rebind the lookup table (rare, requires admin action).

WithdrawPnl

Admin-only. Sweep accrued protocol fees from need_take_pnl_* into designated PnL accounts. Arguments — none (state-driven). Accounts (~14 total)
#NameWSNotes
1token_program
2ammW
3amm_authority
4amm_open_ordersW
5pool_coin_token_accountW
6pool_pc_token_accountW
7coin_pnl_destWAdmin’s coin account (receives fee).
8pc_pnl_destWAdmin’s pc account (receives fee).
9pnl_adminSSigner (must match pool ownership).
10+OpenBook accounts (~4)Settle pending fills first.
Preconditions
  • pnl_admin must be authorized.
Postconditions
  • need_take_pnl_coin and need_take_pnl_pc are transferred to the admin’s accounts.
  • Counters are zeroed.

WithdrawSrm

Legacy (do not use on new pools). Sweeps SRM fee-discount token rebates from early Serum-era pools. Arguments
amount: u64

SimulateInfo

Read-only quote helper for clients and the SDK. Arguments
param: u8              // PoolInfo, SwapBaseInInfo, SwapBaseOutInfo, RunCrankInfo
swap_base_in_value: Option<SwapInstructionBaseIn>
swap_base_out_value: Option<SwapInstructionBaseOut>
Usage — invoked via simulateTransaction to get a quote without executing a swap.

Where to go next

  • Accounts — for account field layouts and sizes.
  • Math — for the lookup-table interpolation logic.
  • Code demos — to see how to call these from the SDK.
Sources:
  • raydium-stable/program/src/instruction.rs (enum and pack/unpack)
  • raydium-stable/program/src/processor.rs (execution logic)