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.
This page is the authoritative instruction reference for the AMM Routing program. For code examples, see
products/routing/code-demos. For error meanings, see reference/error-codes.Instruction summary
| Tag | Discriminator | Exact | Variant |
|---|---|---|---|
| 0 | SwapBaseInWithUserAccount | Input | Legacy |
| 1 | SwapBaseOutWithUserAccount | Output | Legacy |
| 5 | CreateSyncNative | — | Utility |
| 6 | CloseTokenAccount | — | Utility |
| 8 | SwapBaseIn | Input | Current |
| 9 | SwapBaseOut | Output | Current |
- Exact: which amount is fixed by the caller (Input = exact-input
amount_in; Output = exact-outputamount_out). - Variant: Legacy instructions require a non-empty
limit_pricesdeque even if no CLMM hop is in the route. Current instructions (8 / 9) treat an emptylimit_pricesas “no checks”, which is the recommended path for new code.
SwapBaseIn) or tag 9 (SwapBaseOut) unless you have a specific reason to call a Legacy variant.
Current swap instructions (recommended)
These are the entry points new code should use. Argument structure is the same as the Legacy variants butlimit_prices may be empty.
SwapBaseIn (tag 8)
Exact-input multi-hop swap. The caller fixes amount_in; the router executes hop-by-hop and asserts that the final amount lands at or above minimum_amount_out.
Arguments
- Caller signs with
user_input_ata. user_input_ata.amount >= amount_in.- Each intermediate user ATA exists and is owned by the caller.
- If any hop is CLMM and you want price-bound enforcement, supply one
limit_pricesentry per CLMM hop.
user_input_atabalance decreased byamount_in.user_output_atabalance increased by ≥minimum_amount_out.- Each intermediate ATA is left with zero net change (the route consumes whatever it produced one hop earlier).
ExceededSlippage— final output <minimum_amount_out.InvalidInput— empty route, malformed accounts, or unsupportedpool_program.SqrtPriceX64— a CLMM hop’s price moved outside the suppliedlimit_pricesbound (only whenlimit_pricesis non-empty).
SwapBaseOut (tag 9)
Exact-output multi-hop swap. The caller fixes amount_out; the router asserts that the actual input does not exceed maximum_amount_in.
Arguments
- Caller signs with
user_input_ata; balance>= maximum_amount_in(worst case). - Each intermediate and the output ATA exist.
user_input_atadecreased by the actual amount needed (≤maximum_amount_in).user_output_ataincreased by exactlyamount_out.
ExceededSlippage— required input exceedsmaximum_amount_in.InvalidInput,SqrtPriceX64— as for tag 8.
Legacy swap instructions
These older variants are still callable on the live program and are documented here for completeness. Prefer tag 8 / tag 9 for new code; both Legacy variants below require a non-emptylimit_prices deque even when no CLMM hop is involved, which makes them awkward to use.
SwapBaseInWithUserAccount (tag 0)
Exact-input multi-hop swap, identical in shape to tag 8 but with the stricter limit_prices requirement.
Arguments
SwapBaseIn (tag 8). All intermediate slots must be ATAs owned by the caller.
Pre-conditions
- Caller signs with
user_input_ata. user_input_ata.amount >= amount_in.- All intermediate user ATAs exist and are owned by the caller.
limit_pricesis non-empty (one entry per CLMM hop; pad with placeholder values if no CLMM hop is involved).
user_input_atabalance decreased byamount_in.user_output_atabalance increased by ≥minimum_amount_out.
ExceededSlippage.InvalidInput— emptylimit_pricesis rejected on this Legacy variant.SqrtPriceX64.
SwapBaseOutWithUserAccount (tag 1)
Exact-output swap, the Legacy counterpart to SwapBaseOut (tag 9).
Arguments
- Caller signs with
user_input_ata. user_input_ata.amount >= maximum_amount_in.- All intermediate user ATAs exist and are owned by the caller.
limit_pricesis non-empty.
user_input_atadecreased by the actual amount needed (≤maximum_amount_in).user_output_ataincreased by exactlyamount_out.
ExceededSlippage.InvalidInput.SqrtPriceX64.
Utility instructions
CreateSyncNative (tag 5)
Create (if missing) and sync a wSOL ATA in one step. Convenient when wrapping SOL inline alongside a swap.
Arguments
- Creates
user_wsol_ataif it does not yet exist. - Transfers
amountlamports from the signer’s native SOL balance to the ATA. - Calls
SyncNativeon the ATA so its token balance reflects the new lamports.
InvalidOwner—user_wsol_ata’s owner is not the signer.
CloseTokenAccount (tag 6)
Close a token account and return its rent to the destination wallet. Pairs with CreateSyncNative: after a wSOL-leg swap, call CloseTokenAccount to recover the rent that backed the wSOL ATA.
Arguments — none.
Accounts
- Closes
token_account_to_close. - Transfers the rent-exempt lamport balance (~0.00203928 SOL on mainnet for a vanilla SPL Token account) to
destination_for_rent. - The token account must have zero token balance.
InvalidOwner— caller is not the ATA owner.- Token account balance is non-zero.
Where to go next
products/routing/code-demos— building each of these instructions in TypeScript.products/routing/accounts— per-AMM dispatch keys and per-hop account layout.reference/error-codes— fullRouteErrorlist.


