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.
| Crate | carbon-raydium-stable-swap-decoder 2.0.0 |
| Install | cargo add carbon-raydium-stable-swap-decoder@2. |
| Program ID | 5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h (carbon_) |
| Category | DEX & AMM |
| Decoder | carbon_ |
| Instruction enum | instructions:: |
| Account enum | accounts:: (no variants) |
| Features | serde, postgres, graphql (none enabled by default) |
| API docs | docs.rs/carbon-raydium-stable-swap-decoder/2.0.0 |
| Source | decoders/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:
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/fulluse {
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(())
}
}RUST_LOG=info cargo runEach 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::, where data and accounts are the types listed under the variant, exported from carbon_. 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:
- The instruction's program ID is
5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h. - The data starts with the variant's discriminator, and the rest deserializes into its data type.
- 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_ too. Accounts after the listed ones are in accounts. as AccountMetas. The decoder doesn't record whether an account signed or was writable: read that from input. and ., 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.
| Field | Type |
|---|---|
max_ | u64 |
max_ | u64 |
base_side | u64 |
Required accounts: 14; extras go to remaining.
Fields of DepositInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | amm | Pubkey |
| 1 | amm_ | Pubkey |
| 2 | amm_ | Pubkey |
| 3 | amm_ | Pubkey |
| 4 | amm_lp_mint | Pubkey |
| 5 | amm_ | Pubkey |
| 6 | amm_ | Pubkey |
| 7 | model_ | Pubkey |
| 8 | serum_ | Pubkey |
| 9 | user_ | Pubkey |
| 10 | user_ | Pubkey |
| 11 | user_ | Pubkey |
| 12 | user_owner | Pubkey |
| 13 | spl_ | Pubkey |
| 14… | remaining | Vec< |
Initialize#
From the program's IDL:
Initialize a stable AMM pool
Discriminator afaf6d1f0d989bed · data Initialize · accounts InitializeInstructionAccounts.
| Field | Type |
|---|---|
nonce | u8 |
open_time | u64 |
Required accounts: 17; extras go to remaining.
Fields of InitializeInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | amm | Pubkey |
| 1 | amm_ | Pubkey |
| 2 | amm_ | Pubkey |
| 3 | amm_lp_mint | Pubkey |
| 4 | coin_mint | Pubkey |
| 5 | pc_mint | Pubkey |
| 6 | amm_ | Pubkey |
| 7 | amm_ | Pubkey |
| 8 | amm_ | Pubkey |
| 9 | model_ | Pubkey |
| 10 | serum_ | Pubkey |
| 11 | serum_ | Pubkey |
| 12 | user_ | Pubkey |
| 13 | user_wallet | Pubkey |
| 14 | spl_ | Pubkey |
| 15 | system_ | Pubkey |
| 16 | rent | Pubkey |
| 17… | remaining | Vec< |
PreInitialize#
From the program's IDL:
Pre-initialize a stable AMM pool
Discriminator ff5c572dc6acec02 · data PreInitialize · accounts PreInitializeInstructionAccounts.
| Field | Type |
|---|---|
nonce | u8 |
Required accounts: 12; extras go to remaining.
Fields of PreInitializeInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | amm_ | Pubkey |
| 1 | amm_ | Pubkey |
| 2 | amm_lp_mint | Pubkey |
| 3 | coin_mint | Pubkey |
| 4 | pc_mint | Pubkey |
| 5 | amm_ | Pubkey |
| 6 | amm_ | Pubkey |
| 7 | serum_ | Pubkey |
| 8 | user_wallet | Pubkey |
| 9 | spl_ | Pubkey |
| 10 | system_ | Pubkey |
| 11 | rent | Pubkey |
| 12… | remaining | Vec< |
SwapBaseIn#
From the program's IDL:
Swap with exact input amount
Discriminator 2aec48a2f2182754 · data SwapBaseIn · accounts SwapBaseInInstructionAccounts.
| Field | Type |
|---|---|
amount_in | u64 |
minimum_ | u64 |
Required accounts: 18; extras go to remaining.
Fields of SwapBaseInInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | amm | Pubkey |
| 1 | amm_ | Pubkey |
| 2 | amm_ | Pubkey |
| 3 | amm_ | Pubkey |
| 4 | amm_ | Pubkey |
| 5 | model_ | Pubkey |
| 6 | serum_ | Pubkey |
| 7 | serum_ | Pubkey |
| 8 | serum_bids | Pubkey |
| 9 | serum_asks | Pubkey |
| 10 | serum_ | Pubkey |
| 11 | serum_ | Pubkey |
| 12 | serum_ | Pubkey |
| 13 | serum_ | Pubkey |
| 14 | user_ | Pubkey |
| 15 | user_ | Pubkey |
| 16 | user_ | Pubkey |
| 17 | spl_ | Pubkey |
| 18… | remaining | Vec< |
SwapBaseOut#
From the program's IDL:
Swap with exact output amount
Discriminator a3d29bd0af92d596 · data SwapBaseOut · accounts SwapBaseOutInstructionAccounts.
| Field | Type |
|---|---|
max_ | u64 |
amount_out | u64 |
Required accounts: 18; extras go to remaining.
Fields of SwapBaseOutInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | amm | Pubkey |
| 1 | amm_ | Pubkey |
| 2 | amm_ | Pubkey |
| 3 | amm_ | Pubkey |
| 4 | amm_ | Pubkey |
| 5 | model_ | Pubkey |
| 6 | serum_ | Pubkey |
| 7 | serum_ | Pubkey |
| 8 | serum_bids | Pubkey |
| 9 | serum_asks | Pubkey |
| 10 | serum_ | Pubkey |
| 11 | serum_ | Pubkey |
| 12 | serum_ | Pubkey |
| 13 | serum_ | Pubkey |
| 14 | user_ | Pubkey |
| 15 | user_ | Pubkey |
| 16 | user_ | Pubkey |
| 17 | spl_ | Pubkey |
| 18… | remaining | Vec< |
Withdraw#
From the program's IDL:
Withdraw liquidity from the stable AMM pool
Discriminator b712469c946da122 · data Withdraw · accounts WithdrawInstructionAccounts.
| Field | Type |
|---|---|
amount | u64 |
Required accounts: 18; extras go to remaining.
Fields of WithdrawInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | amm | Pubkey |
| 1 | amm_ | Pubkey |
| 2 | amm_ | Pubkey |
| 3 | amm_ | Pubkey |
| 4 | amm_lp_mint | Pubkey |
| 5 | amm_ | Pubkey |
| 6 | amm_ | Pubkey |
| 7 | model_ | Pubkey |
| 8 | serum_ | Pubkey |
| 9 | serum_ | Pubkey |
| 10 | serum_ | Pubkey |
| 11 | serum_ | Pubkey |
| 12 | serum_ | Pubkey |
| 13 | user_ | Pubkey |
| 14 | user_ | Pubkey |
| 15 | user_ | Pubkey |
| 16 | user_owner | Pubkey |
| 17 | spl_ | Pubkey |
| 18… | remaining | Vec< |