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.

What an IDL is

Anchor programs on Solana publish an IDL (Interface Definition Language) file describing their instructions, account layouts, error enum, and struct schemas. The IDL is the source of truth for client code generation — the TS SDK, Rust CPI crate, and third-party clients are all generated from (or hand-written against) it. Raydium publishes IDLs for CPMM, CLMM, and LaunchLab. AMM v4, Stable AMM, and Farm (v3 / v5 / v6) predate Anchor or are otherwise not Anchor-distributed — their account structures are hand-maintained in the SDK.

Where to find them

IDLs live in a dedicated repository:
https://github.com/raydium-io/raydium-idl
The exact files:
ProgramIDL file
CPMMraydium_cpmm/raydium_cp_swap.json
CLMMraydium_clmm/raydium_clmm.json
LaunchLabraydium_launchpad/raydium_launchpad.json
AMM v4no official IDL — see raydium-sdk-V2/src/raydium/liquidity/layout.ts for hand-written layouts
Stable AMMno official IDL — layouts in the SDK
Farmno official IDL — layouts in the SDK
The IDL files are versioned in the repo’s git history; pin to a specific commit if you need byte-for-byte reproducibility. IDLs can also be pulled directly from the deployed programs via Anchor’s on-chain IDL feature (if the program publisher opted in):
anchor idl fetch <PROGRAM_ID> --provider.cluster mainnet
CPMM, CLMM, and LaunchLab all have on-chain IDLs. AMM v4, Stable AMM, and Farm do not (pre-Anchor programs).

Regenerating a TypeScript client

Anchor’s codegen produces a typed client from the IDL:
# Using the anchor CLI
anchor build
anchor idl parse \
  --file target/idl/cpmm.json \
  --out target/types/cpmm.ts

# Or with the `@coral-xyz/anchor` TS helpers at runtime:
import { Program, AnchorProvider } from "@coral-xyz/anchor";
// Pull the IDL directly from the raydium-idl repo (or vendor it into your project).
import cpmmIdl from "./idls/raydium_cp_swap.json";

const provider = new AnchorProvider(connection, wallet, {});
const program  = new Program(cpmmIdl as any, CPMM_PROGRAM_ID, provider);

// Typed method builders auto-generated:
await program.methods
  .swapBaseInput(new BN(amountIn), new BN(minAmountOut))
  .accounts({ ... })
  .rpc();
Most integrators do not do this — they use the higher-level raydium.cpmm.swap(...) helper which wraps the Anchor methods plus all the bookkeeping (ATA creation, transfer-fee adjustment, compute budget, Token-2022 program routing). Regenerate only when you need a layer below the SDK.

Regenerating a Rust client (CPI crate)

Raydium publishes Anchor crates for the programs that have IDLs:
# Cargo.toml
[dependencies]
raydium_cp_swap = { git = "https://github.com/raydium-io/raydium-cp-swap", branch = "master", features = ["cpi"] }
raydium_amm_v3 = { git = "https://github.com/raydium-io/raydium-clmm",    branch = "master", features = ["cpi"] }
The cpi feature exposes cpi::accounts::<Ix> account structs and cpi::<ix>() invokers — ready-to-use CPI wrappers. See sdk-api/rust-cpi for usage patterns. If you prefer to generate fresh bindings:
# From the IDL, using anchor-client
anchor idl parse \
  --file raydium_cpmm/raydium_cp_swap.json \
  --out src/generated/cpmm_bindings.rs

Regenerating a Python client

There is no official Raydium Python SDK. Third-party generators include:
  • anchorpy — Python port of @coral-xyz/anchor. Generates typed method builders from IDLs.
  • solders — low-level Solana primitives (transactions, keypairs, pubkeys) in Rust bindings; used underneath anchorpy.
pip install anchorpy solders solana
from anchorpy import Program, Provider
from solana.rpc.async_api import AsyncClient
from pathlib import Path
import json

idl = json.loads(Path("cpmm.json").read_text())
provider = Provider(AsyncClient("https://api.mainnet-beta.solana.com"), wallet)
program  = Program(idl, CPMM_PROGRAM_ID, provider)

await program.rpc["swap_base_input"](amount_in, min_amount_out, ctx=Context(accounts={...}))
See sdk-api/python-integration for a fuller walk-through.

IDL change policy

Raydium follows these rules for IDL stability:
  1. Instruction discriminators never change. Adding new instructions extends the enum at the end; existing discriminators remain stable.
  2. Account struct layouts evolve only additively. New fields go at the end, preceded by a size bump in the on-chain schema. Existing fields keep their offsets.
  3. Error enum codes are append-only. An existing error code always means the same thing.
  4. Breaking changes ship in new programs. When a redesign is needed, the team deploys a new program ID (e.g. CPMM as a fresh program rather than upgrading AMM v4). Old pools continue to run on the old program; new pools go to the new one.
This policy makes regenerated clients backward-compatible: a client generated against a two-version-old IDL will still decode current state correctly (it sees extra trailing bytes as padding).

What to do when the IDL changes

  1. Update the SDK. npm update @raydium-io/raydium-sdk-v2.
  2. Regenerate your client code if you use Anchor codegen directly.
  3. Diff the account layout. The new layout’s trailing fields are the only thing your code hasn’t seen; confirm whether you need them.
  4. Don’t assume old instruction discriminators are invalid. Per rule 1, they still work.
  5. Re-run integration tests against devnet before rolling to mainnet.

IDL troubleshooting

”Invalid discriminator” errors

Usually means a client built against version N of the IDL is trying to invoke an instruction that existed only in a pre-deploy version of the program. Re-pull the IDL from the live program:
anchor idl fetch <PROGRAM_ID>

Account decode failures

If program.account.<Name>.fetch(pubkey) throws with “Invalid account discriminator”, the account was created by a previous program version and Anchor is rejecting its 8-byte discriminator. The fix is to use the raw layout parser from the SDK (PoolInfoLayout.decode(accountData)) which does not enforce Anchor discriminators.

Missing instructions in the generated client

Anchor’s TS codegen only generates methods for instructions whose IDL entry has a name that parses as a valid identifier. Raydium’s instructions all satisfy this, but if you see a mismatch, check whether the IDL file is from the current SDK release.

Pointers

Sources: