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
| Instruction | Category | Notes |
|---|
Initialize | Lifecycle | Create pool (requires pre-allocated model-data account). |
PreInitialize | Lifecycle | Legacy pre-allocation helper. |
InitModelData | Model setup | Create and initialize the lookup table. |
UpdateModelData | Model setup | Populate up to 5 table elements per call. |
Deposit | Liquidity | Add liquidity, receive LP. |
Withdraw | Liquidity | Burn LP, receive both sides. |
SwapBaseIn | Swap | Exact-input swap. |
SwapBaseOut | Swap | Exact-output swap. |
MonitorStep | Crank | Settle OpenBook, update orders. |
SetParams | Admin | Change pool parameters. |
WithdrawPnl | Admin | Sweep accrued protocol fees. |
WithdrawSrm | Legacy | Sweep SRM rebates (legacy). |
SimulateInfo | Diagnostic | Read-only quote helper. |
Initialize
Bootstrap a new Stable AMM pool bound to an existing OpenBook market and a pre-created ModelDataInfo account.
Arguments
Accounts (writable W, signer S)
| # | Name | W | S | Notes |
|---|
| 1 | token_program | | | SPL Token. |
| 2 | system_program | | | |
| 3 | rent | | | |
| 4 | amm | W | | Pool’s AmmInfo account. |
| 5 | amm_authority | | | Program-wide PDA. |
| 6 | amm_open_orders | W | | OpenBook OpenOrders. |
| 7 | lp_mint | W | | Fungible LP token mint. |
| 8 | coin_mint | | | |
| 9 | pc_mint | | | |
| 10 | pool_coin_token_account | W | | Pool’s coin vault. |
| 11 | pool_pc_token_account | W | | Pool’s pc vault. |
| 12 | amm_target_orders | W | | Grid for OpenBook orders. |
| 13 | model_data_account | | | The lookup table account. |
| 14 | serum_program | | | OpenBook program. |
| 15 | serum_market | | | OpenBook market. |
| 16 | user_dest_lp_token | W | | Creator’s LP ATA (receives initial LP). |
| 17 | user_wallet | W | S | Creator; pays rent, funds initial deposit. |
| (opt) | srm_token | W | | SRM 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)
| # | Name | W | S | Notes |
|---|
| 1 | model_data_account | W | | The 50k-element table account. |
| 2 | amm_admin | | S | Pool 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)
| # | Name | W | S | Notes |
|---|
| 1 | amm_admin | | S | Signer (must be the pool admin). |
| 2 | model_data_account | W | | The 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)
| # | Name | W | S | Notes |
|---|
| 1 | token_program | | | |
| 2 | amm | W | | |
| 3 | amm_authority | | | |
| 4 | amm_open_orders | W | | |
| 5 | amm_target_orders | W | | |
| 6 | pool_coin_token_account | W | | |
| 7 | pool_pc_token_account | W | | |
| 8 | model_data_account | | | Read-only lookup table. |
| 9 | serum_program | | | |
| 10 | serum_market | W | | |
| 11 | serum_bids | W | | |
| 12 | serum_asks | W | | |
| 13 | serum_event_queue | W | | |
| 14 | serum_coin_vault | W | | |
| 15 | serum_pc_vault | W | | |
| 16 | serum_vault_signer | | | |
| 17 | user_source_token | W | | User’s input token account. |
| 18 | user_dest_token | W | | User’s output token account. |
| 19 | user_owner | | S | User (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)
| # | Name | W | S | Notes |
|---|
| 1 | token_program | | | |
| 2 | amm | W | | |
| 3 | amm_authority | | | |
| 4 | amm_open_orders | W | | |
| 5 | pool_coin_token_account | W | | |
| 6 | pool_pc_token_account | W | | |
| 7 | coin_pnl_dest | W | | Admin’s coin account (receives fee). |
| 8 | pc_pnl_dest | W | | Admin’s pc account (receives fee). |
| 9 | pnl_admin | | S | Signer (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
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)