What you can do
| swap | Swap one token for another in a Raydium AMM v4 pool | GET the pool from /pools/info/mint (or /pools/info/ids), build SwapBaseInV2(amount_in, minimum_amount_out) with the pool's accounts (amm, vaults, authority, user token accounts), sign and send. Compute minimum_amount_out from the pool reserves and your slippage. |
| add-liquidity | Deposit two tokens into a pool and receive LP tokens | Deposit(max_coin_amount, max_pc_amount, base_side, other_amount_min) at the current ratio; check the pool's LP mint and ratio first |
| remove-liquidity | Burn LP tokens for the two underlying tokens | Withdraw(amount, min_coin_amount, min_pc_amount) |
| create-pool | Create a new AMM v4 pool for a market | Initialize2 with the market id and the starting amounts. The pool needs an existing OpenBook market and a pool creation fee. |
Constant-product pools lose value to arbitrage when prices move, which is impermanent loss for liquidity providers.
Low-liquidity pools have high price impact. Set minimum_amount_out on every swap.
Anyone can create a pool for any token pair, including fake or scam tokens. Check the mint before swapping or providing liquidity.
AMM v4 is the older Raydium program. Newer Raydium pool types (CPMM, CLMM) are separate programs and are not covered here.
Contracts
Read any function, or build a write and sign it. Amounts are in base units (1 USDC = 1000000).Raydium AMM v4 programexchange on solana675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8
write SwapBaseInV2(amount_in: u64, minimum_amount_out: u64)
Swap an exact amount of the input token for at least minimum_amount_out of the output token. Uses the AMM only (order book disabled). Amounts are in token base units.
write SwapBaseOutV2(max_amount_in: u64, amount_out: u64)
Receive an exact amount_out of the output token, spending at most max_amount_in of the input token. AMM only.
write SwapBaseIn(amount_in: u64, minimum_amount_out: u64)
Original exact-input swap, which can also match the OpenBook order book. Prefer the V2 variant for new integrations.
write SwapBaseOut(max_amount_in: u64, amount_out: u64)
Original exact-output swap, which can also use the order book. Prefer the V2 variant.
write Deposit(max_coin_amount: u64, max_pc_amount: u64, base_side: u64, other_amount_min: Option<u64>)
Add liquidity to a pool. Deposits at the current pool ratio, up to max_coin_amount of the coin token and max_pc_amount of the PC token. base_side selects which side the ratio is taken from. Receives LP tokens.
write Withdraw(amount: u64, min_coin_amount: Option<u64>, min_pc_amount: Option<u64>)
Burn amount LP tokens and receive pool tokens at the current ratio, failing if below the optional minimums.
write Initialize2(nonce: u8, open_time: u64, init_pc_amount: u64, init_coin_amount: u64)
Create a new AMM pool for a market, with the initial PC and coin amounts that set the starting price. Pool creation fee applies.
write SetParams(param: u8, value: Option<u64>, fees: Option<Fees>)
Admin only: change pool parameters or fees.
write UpdateConfigAccount(config_args: ConfigArgs)
Admin only: update the AMM config account (for example the owner or the pool creation fee).
write WithdrawPnl()
Admin only: withdraw accumulated profit from the pool to the protocol.