Raydium Stable Swap decoder

Decode Raydium Stable Swap instructions in Rust with carbon-raydium-stable-swap-decoder 2.0.0. Program ID 5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h.

On this page

carbon-raydium-stable-swap-decoder decodes the instructions of the Raydium Stable Swap program (5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h): 6 instructions. It decodes no accounts: RaydiumStableSwapAccount has no variants. It is generated with Codama from the program's IDL; see decoders for how decoders plug into a pipeline.

Cratecarbon-raydium-stable-swap-decoder 2.0.0
Installcargo add carbon-raydium-stable-swap-decoder@2.0.0
Program ID5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h (carbon_raydium_stable_swap_decoder::PROGRAM_ID)
CategoryDEX & AMM
Decodercarbon_raydium_stable_swap_decoder::RaydiumStableSwapDecoder
Instruction enuminstructions::RaydiumStableSwapInstruction
Account enumaccounts::RaydiumStableSwapAccount (no variants)
Featuresserde, postgres, graphql (none enabled by default)
API docsdocs.rs/carbon-raydium-stable-swap-decoder/2.0.0
Sourcedecoders/raydium-stable-swap-decoder

Other DEX and AMM decoders: BonkSwap, FluxBeam, Gavel, Heaven, Jupiter Limit Order, Jupiter Limit Order v2, Kamino Limit Order, Lifinity AMM v2, Meteora DAMM v2, Meteora DLMM, Meteora Pools, OpenBook v2, Orca Whirlpools, PancakeSwap, Phoenix v1, PumpSwap, Raydium AMM v4, Raydium CLMM, Raydium CPMM, Stabble Stable Swap, Stabble Weighted Swap. To decode several in one pipeline, see dEX and AMM decoders.

The serde feature derives Serialize/Deserialize on every type, postgres adds tables and processors for Postgres, and graphql adds a schema for the GraphQL server.

Usage#

This program crawls recent Raydium Stable Swap transactions from the public RPC and prints every decoded SwapBaseIn instruction. Add the dependencies:

Terminal
cargo add carbon-core@2.0.0 carbon-raydium-stable-swap-decoder@2.0.0 carbon-rpc-transaction-crawler-datasource@2.0.0 carbon-log-metrics@2.0.0 env_logger tokio --features tokio/full
src/main.rs
use {
    carbon_core::{
        error::CarbonResult, instruction::InstructionProcessorInputType, pipeline::Pipeline,
        processor::Processor,
    },
    carbon_log_metrics::LogMetrics,
    carbon_raydium_stable_swap_decoder::{
        instructions::RaydiumStableSwapInstruction, RaydiumStableSwapDecoder, PROGRAM_ID,
    },
    carbon_rpc_transaction_crawler_datasource::{ConnectionConfig, Filters, RpcTransactionCrawler},
    std::sync::Arc,
};

#[tokio::main]
async fn main() -> CarbonResult<()> {
    env_logger::init();

    // Fetches the program's recent transactions over JSON-RPC, newest first.
    let datasource = RpcTransactionCrawler::new(
        "https://api.mainnet-beta.solana.com".to_string(),
        PROGRAM_ID,
        ConnectionConfig::default(),
        Filters::new(None, None, None),
        None,
    );

    Pipeline::builder()
        .datasource(datasource)
        .metrics(Arc::new(LogMetrics::new()))
        .instruction(RaydiumStableSwapDecoder, InstructionLogger)
        .build()?
        .run()
        .await
}

struct InstructionLogger;

impl Processor<InstructionProcessorInputType<'_, RaydiumStableSwapInstruction>> for InstructionLogger {
    async fn process(
        &mut self,
        input: &InstructionProcessorInputType<'_, RaydiumStableSwapInstruction>,
    ) -> CarbonResult<()> {
        let signature = input.metadata.transaction_metadata.signature;
        if let RaydiumStableSwapInstruction::SwapBaseIn { data, accounts, .. } = input.decoded_instruction {
            println!("swap_base_in {signature}: {data:?} amm={}", accounts.amm);
        }
        Ok(())
    }
}
Terminal
RUST_LOG=info cargo run

Each SwapBaseIn instruction prints one line with the transaction signature and the decoded SwapBaseIn data. The public endpoint rate-limits requests, so the first lines can take a while; use your own RPC URL for anything beyond a test. See stream with RPC for the crawler options.

Instructions#

Variants of RaydiumStableSwapInstruction. Each is RaydiumStableSwapInstruction::<Variant> { program_id, data, accounts }, where data and accounts are the types listed under the variant, exported from carbon_raydium_stable_swap_decoder::instructions. Discriminators are the leading bytes of the instruction data, in hex.

How an instruction decodes. The decoder returns a variant only when all of these hold; otherwise the instruction is skipped and no processor is called:

  1. The instruction's program ID is 5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h.
  2. The data starts with the variant's discriminator, and the rest deserializes into its data type.
  3. The instruction has at least as many accounts as the variant requires (the "Required accounts" count under each variant).

Accounts. They are matched by position, in the order listed. An account marked optional is None only when the instruction ends before it; Anchor programs pass the program ID as a placeholder for an omitted optional account, so check for Some(PROGRAM_ID) too. Accounts after the listed ones are in accounts.remaining as AccountMetas. The decoder doesn't record whether an account signed or was writable: read that from input.raw_instruction.accounts[i].is_signer and .is_writable, which follow the same order. It doesn't check signer, writable, owner or PDA constraints either; the program enforced those when the transaction executed, so a decoded instruction from a successful transaction already satisfied them.

Deposit#

From the program's IDL:

Deposit liquidity into the stable AMM pool

Discriminator f223c68952e1f2b6 · data Deposit · accounts DepositInstructionAccounts.

FieldType
max_coin_amountu64
max_pc_amountu64
base_sideu64

Required accounts: 14; extras go to remaining.

Fields of DepositInstructionAccounts, in account order:

#FieldType
0ammPubkey
1amm_authorityPubkey
2amm_open_ordersPubkey
3amm_target_ordersPubkey
4amm_lp_mintPubkey
5amm_coin_vaultPubkey
6amm_pc_vaultPubkey
7model_data_accountPubkey
8serum_marketPubkey
9user_source_coin_tokenPubkey
10user_source_pc_tokenPubkey
11user_dest_lp_tokenPubkey
12user_ownerPubkey
13spl_token_programPubkey
14…remainingVec<AccountMeta>

Initialize#

From the program's IDL:

Initialize a stable AMM pool

Discriminator afaf6d1f0d989bed · data Initialize · accounts InitializeInstructionAccounts.

FieldType
nonceu8
open_timeu64

Required accounts: 17; extras go to remaining.

Fields of InitializeInstructionAccounts, in account order:

#FieldType
0ammPubkey
1amm_authorityPubkey
2amm_open_ordersPubkey
3amm_lp_mintPubkey
4coin_mintPubkey
5pc_mintPubkey
6amm_coin_vaultPubkey
7amm_pc_vaultPubkey
8amm_target_ordersPubkey
9model_data_accountPubkey
10serum_programPubkey
11serum_marketPubkey
12user_dest_lp_tokenPubkey
13user_walletPubkey
14spl_token_programPubkey
15system_programPubkey
16rentPubkey
17…remainingVec<AccountMeta>

PreInitialize#

From the program's IDL:

Pre-initialize a stable AMM pool

Discriminator ff5c572dc6acec02 · data PreInitialize · accounts PreInitializeInstructionAccounts.

FieldType
nonceu8

Required accounts: 12; extras go to remaining.

Fields of PreInitializeInstructionAccounts, in account order:

#FieldType
0amm_target_ordersPubkey
1amm_authorityPubkey
2amm_lp_mintPubkey
3coin_mintPubkey
4pc_mintPubkey
5amm_coin_vaultPubkey
6amm_pc_vaultPubkey
7serum_marketPubkey
8user_walletPubkey
9spl_token_programPubkey
10system_programPubkey
11rentPubkey
12…remainingVec<AccountMeta>

SwapBaseIn#

From the program's IDL:

Swap with exact input amount

Discriminator 2aec48a2f2182754 · data SwapBaseIn · accounts SwapBaseInInstructionAccounts.

FieldType
amount_inu64
minimum_amount_outu64

Required accounts: 18; extras go to remaining.

Fields of SwapBaseInInstructionAccounts, in account order:

#FieldType
0ammPubkey
1amm_authorityPubkey
2amm_open_ordersPubkey
3amm_coin_vaultPubkey
4amm_pc_vaultPubkey
5model_data_accountPubkey
6serum_programPubkey
7serum_marketPubkey
8serum_bidsPubkey
9serum_asksPubkey
10serum_event_queuePubkey
11serum_coin_vaultPubkey
12serum_pc_vaultPubkey
13serum_vault_signerPubkey
14user_source_tokenPubkey
15user_destination_tokenPubkey
16user_source_ownerPubkey
17spl_token_programPubkey
18…remainingVec<AccountMeta>

SwapBaseOut#

From the program's IDL:

Swap with exact output amount

Discriminator a3d29bd0af92d596 · data SwapBaseOut · accounts SwapBaseOutInstructionAccounts.

FieldType
max_amount_inu64
amount_outu64

Required accounts: 18; extras go to remaining.

Fields of SwapBaseOutInstructionAccounts, in account order:

#FieldType
0ammPubkey
1amm_authorityPubkey
2amm_open_ordersPubkey
3amm_coin_vaultPubkey
4amm_pc_vaultPubkey
5model_data_accountPubkey
6serum_programPubkey
7serum_marketPubkey
8serum_bidsPubkey
9serum_asksPubkey
10serum_event_queuePubkey
11serum_coin_vaultPubkey
12serum_pc_vaultPubkey
13serum_vault_signerPubkey
14user_source_tokenPubkey
15user_destination_tokenPubkey
16user_source_ownerPubkey
17spl_token_programPubkey
18…remainingVec<AccountMeta>

Withdraw#

From the program's IDL:

Withdraw liquidity from the stable AMM pool

Discriminator b712469c946da122 · data Withdraw · accounts WithdrawInstructionAccounts.

FieldType
amountu64

Required accounts: 18; extras go to remaining.

Fields of WithdrawInstructionAccounts, in account order:

#FieldType
0ammPubkey
1amm_authorityPubkey
2amm_open_ordersPubkey
3amm_target_ordersPubkey
4amm_lp_mintPubkey
5amm_coin_vaultPubkey
6amm_pc_vaultPubkey
7model_data_accountPubkey
8serum_programPubkey
9serum_marketPubkey
10serum_coin_vaultPubkey
11serum_pc_vaultPubkey
12serum_vault_signerPubkey
13user_source_lp_tokenPubkey
14user_dest_coin_tokenPubkey
15user_dest_pc_tokenPubkey
16user_ownerPubkey
17spl_token_programPubkey
18…remainingVec<AccountMeta>

Generated from the crate’s source at Carbon v2.0.0, so it always matches the published code. Spotted a problem? Report it; edits to this page itself are overwritten on the next release.

Your endpoints

Code samples use these instead of the placeholders, so you can copy and run them as they are. They’re stored only in this browser and never sent anywhere.