Raydium AMM v4 decoder
Decode Raydium AMM v4 instructions and accounts in Rust with carbon-raydium-amm-v4-decoder 2.0.0. Program ID 675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8.
On this page
carbon-raydium-amm-v4-decoder decodes the instructions and accounts of the Raydium AMM v4 program (675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8): 18 instructions, 3 account types. It is generated with Codama from the program's IDL; see decoders for how decoders plug into a pipeline.
| Crate | carbon-raydium-amm-v4-decoder 2.0.0 |
| Install | cargo add carbon-raydium-amm-v4-decoder@2. |
| Program ID | 675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8 (carbon_) |
| Category | DEX & AMM |
| Decoder | carbon_ |
| Instruction enum | instructions:: |
| Account enum | accounts:: |
| Features | serde, postgres, graphql (none enabled by default) |
| API docs | docs.rs/carbon-raydium-amm-v4-decoder/2.0.0 |
| Source | decoders/raydium-amm-v4-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 CLMM, Raydium CPMM, Raydium Stable Swap, 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 AMM v4 transactions from the public RPC and prints every decoded SwapBaseIn instruction. Add the dependencies:
cargo add carbon-core@2.0.0 carbon-raydium-amm-v4-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_amm_v4_decoder::{
instructions::RaydiumAmmV4Instruction, RaydiumAmmV4Decoder, 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(RaydiumAmmV4Decoder, InstructionLogger)
.build()?
.run()
.await
}
struct InstructionLogger;
impl Processor<InstructionProcessorInputType<'_, RaydiumAmmV4Instruction>> for InstructionLogger {
async fn process(
&mut self,
input: &InstructionProcessorInputType<'_, RaydiumAmmV4Instruction>,
) -> CarbonResult<()> {
let signature = input.metadata.transaction_metadata.signature;
if let RaydiumAmmV4Instruction::SwapBaseIn { data, accounts, .. } = input.decoded_instruction {
println!("swap_base_in {signature}: {data:?} token_program={}", accounts.token_program);
}
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.
Decode accounts#
The transaction crawler emits transactions only. To decode accounts, use a datasource that emits account updates. This program subscribes to the program's accounts with programSubscribe on the public WebSocket endpoint and prints every decoded AmmInfo account as it changes. Add the datasource and the Solana RPC types it takes:
cargo add carbon-rpc-program-subscribe-datasource@2.0.0 solana-client@4.2.2use {
carbon_core::{
account::AccountProcessorInputType, error::CarbonResult, pipeline::Pipeline,
processor::Processor,
},
carbon_log_metrics::LogMetrics,
carbon_raydium_amm_v4_decoder::{accounts::RaydiumAmmV4Account, RaydiumAmmV4Decoder, PROGRAM_ID},
carbon_rpc_program_subscribe_datasource::{Filters, RpcProgramSubscribe},
solana_client::rpc_config::{RpcAccountInfoConfig, RpcProgramAccountsConfig, UiAccountEncoding},
std::sync::Arc,
};
#[tokio::main]
async fn main() -> CarbonResult<()> {
env_logger::init();
// Streams every change to an account owned by the program (programSubscribe).
let config = RpcProgramAccountsConfig {
account_config: RpcAccountInfoConfig {
encoding: Some(UiAccountEncoding::Base64),
..Default::default()
},
..Default::default()
};
let datasource = RpcProgramSubscribe::new(
"wss://api.mainnet-beta.solana.com".to_string(),
Filters::new(PROGRAM_ID, Some(config)),
);
Pipeline::builder()
.datasource(datasource)
.metrics(Arc::new(LogMetrics::new()))
.account(RaydiumAmmV4Decoder, AccountLogger)
.build()?
.run()
.await
}
struct AccountLogger;
impl Processor<AccountProcessorInputType<'_, RaydiumAmmV4Account>> for AccountLogger {
async fn process(
&mut self,
input: &AccountProcessorInputType<'_, RaydiumAmmV4Account>,
) -> CarbonResult<()> {
if let RaydiumAmmV4Account::AmmInfo(amm_info) = &input.decoded_account.data {
println!("amm_info {}: {amm_info:?}", input.metadata.pubkey);
}
Ok(())
}
}RUST_LOG=info cargo runEach update to a AmmInfo account prints its address and decoded fields; the program runs until you stop it. Cargo resolves solana-client to 4.2.2, the exact version the datasource pins, so both use the same RpcProgramAccountsConfig type. To load every existing account once instead of streaming changes, see load account state.
Instructions#
Variants of RaydiumAmmV4Instruction. Each is RaydiumAmmV4Instruction::, 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
675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8. - 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.
AdminCancelOrders#
From the program's IDL:
Admin: cancel up to
limitof the pool's open orders.
Discriminator 0d · data AdminCancelOrders · accounts AdminCancelOrdersInstructionAccounts.
| Field | Type |
|---|---|
limit | u16 |
Required accounts: 17 (18 listed); extras go to remaining.
Fields of AdminCancelOrdersInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | token_ | Pubkey |
| 1 | amm | Pubkey |
| 2 | amm_ | Pubkey |
| 3 | amm_ | Pubkey |
| 4 | amm_ | Pubkey |
| 5 | amm_ | Pubkey |
| 6 | amm_ | Pubkey |
| 7 | amm_config | Pubkey |
| 8 | admin | Pubkey |
| 9 | market_ | Pubkey |
| 10 | market | Pubkey |
| 11 | market_ | Pubkey |
| 12 | market_ | Pubkey |
| 13 | market_ | Pubkey |
| 14 | market_ | Pubkey |
| 15 | market_bids | Pubkey |
| 16 | market_asks | Pubkey |
| 17 | referrer_ | Option< |
| 18… | remaining | Vec< |
CreateConfigAccount#
From the program's IDL:
Admin: create the singleton AmmConfig account.
Discriminator 0e · data CreateConfigAccount · accounts CreateConfigAccountInstructionAccounts.
No data fields.
Required accounts: 5; extras go to remaining.
Fields of CreateConfigAccountInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | admin | Pubkey |
| 1 | amm_config | Pubkey |
| 2 | owner | Pubkey |
| 3 | system_ | Pubkey |
| 4 | rent | Pubkey |
| 5… | remaining | Vec< |
Deposit#
From the program's IDL:
Deposit tokens into the pool. Mints LP tokens to the user.
Discriminator 03 · data Deposit · accounts DepositInstructionAccounts.
| Field | Type | Description |
|---|---|---|
max_ | u64 | |
max_ | u64 | |
base_side | u64 | |
other_ | Option<u64> | Optional trailing slippage bound; absent in legacy txs. |
Required accounts: 14; extras go to remaining.
Fields of DepositInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | token_ | Pubkey |
| 1 | amm | Pubkey |
| 2 | amm_ | Pubkey |
| 3 | amm_ | Pubkey |
| 4 | amm_ | Pubkey |
| 5 | amm_lp_mint | Pubkey |
| 6 | amm_ | Pubkey |
| 7 | amm_ | Pubkey |
| 8 | market | Pubkey |
| 9 | user_ | Pubkey |
| 10 | user_ | Pubkey |
| 11 | user_ | Pubkey |
| 12 | user_owner | Pubkey |
| 13 | market_ | Pubkey |
| 14… | remaining | Vec< |
Initialize#
From the program's IDL:
Deprecated. Use
initialize2.
Discriminator 00 · data Initialize · accounts InitializeInstructionAccounts.
| Field | Type |
|---|---|
nonce | u8 |
open_time | u64 |
Required accounts: 16; extras go to remaining.
Fields of InitializeInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | token_ | Pubkey |
| 1 | system_ | Pubkey |
| 2 | rent | Pubkey |
| 3 | amm | Pubkey |
| 4 | amm_ | Pubkey |
| 5 | amm_ | Pubkey |
| 6 | amm_lp_mint | Pubkey |
| 7 | amm_ | Pubkey |
| 8 | amm_pc_mint | Pubkey |
| 9 | amm_ | Pubkey |
| 10 | amm_ | Pubkey |
| 11 | amm_ | Pubkey |
| 12 | pool_ | Pubkey |
| 13 | market_ | Pubkey |
| 14 | market | Pubkey |
| 15 | user_wallet | Pubkey |
| 16… | remaining | Vec< |
Initialize2#
From the program's IDL:
Initializes a new AMM pool.
Discriminator 01 · data Initialize2 · accounts Initialize2InstructionAccounts.
| Field | Type |
|---|---|
nonce | u8 |
open_time | u64 |
init_ | u64 |
init_ | u64 |
Required accounts: 21; extras go to remaining.
Fields of Initialize2InstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | token_ | Pubkey |
| 1 | associated_ | Pubkey |
| 2 | system_ | Pubkey |
| 3 | rent | Pubkey |
| 4 | amm | Pubkey |
| 5 | amm_ | Pubkey |
| 6 | amm_ | Pubkey |
| 7 | amm_lp_mint | Pubkey |
| 8 | amm_ | Pubkey |
| 9 | amm_pc_mint | Pubkey |
| 10 | amm_ | Pubkey |
| 11 | amm_ | Pubkey |
| 12 | amm_ | Pubkey |
| 13 | amm_config | Pubkey |
| 14 | create_ | Pubkey |
| 15 | market_ | Pubkey |
| 16 | market | Pubkey |
| 17 | user_wallet | Pubkey |
| 18 | user_ | Pubkey |
| 19 | user_ | Pubkey |
| 20 | user_ | Pubkey |
| 21… | remaining | Vec< |
MigrateToOpenBook#
From the program's IDL:
Migrate the associated market from Serum to OpenBook.
Discriminator 05 · data MigrateToOpenBook · accounts MigrateToOpenBookInstructionAccounts.
No data fields.
Required accounts: 21; extras go to remaining.
Fields of MigrateToOpenBookInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | token_ | Pubkey |
| 1 | system_ | Pubkey |
| 2 | rent | Pubkey |
| 3 | amm | Pubkey |
| 4 | amm_ | Pubkey |
| 5 | amm_ | Pubkey |
| 6 | amm_ | Pubkey |
| 7 | amm_ | Pubkey |
| 8 | amm_ | Pubkey |
| 9 | market_ | Pubkey |
| 10 | market | Pubkey |
| 11 | market_bids | Pubkey |
| 12 | market_asks | Pubkey |
| 13 | market_ | Pubkey |
| 14 | market_ | Pubkey |
| 15 | market_ | Pubkey |
| 16 | market_ | Pubkey |
| 17 | new_ | Pubkey |
| 18 | new_ | Pubkey |
| 19 | new_market | Pubkey |
| 20 | admin | Pubkey |
| 21… | remaining | Vec< |
MonitorStep#
From the program's IDL:
Step the AMM order-book state machine.
Discriminator 02 · data MonitorStep · accounts MonitorStepInstructionAccounts.
| Field | Type |
|---|---|
plan_ | u16 |
place_ | u16 |
cancel_ | u16 |
Required accounts: 18 (20 listed); extras go to remaining.
Fields of MonitorStepInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | token_ | Pubkey |
| 1 | rent | Pubkey |
| 2 | clock | Pubkey |
| 3 | amm | Pubkey |
| 4 | amm_ | Pubkey |
| 5 | amm_ | Pubkey |
| 6 | amm_ | Pubkey |
| 7 | amm_ | Pubkey |
| 8 | amm_ | Pubkey |
| 9 | market_ | Pubkey |
| 10 | market | Pubkey |
| 11 | market_ | Pubkey |
| 12 | market_ | Pubkey |
| 13 | market_ | Pubkey |
| 14 | market_ | Pubkey |
| 15 | market_ | Pubkey |
| 16 | market_bids | Pubkey |
| 17 | market_asks | Pubkey |
| 18 | srm_account | Option< |
| 19 | referrer_ | Option< |
| 20… | remaining | Vec< |
PreInitialize#
From the program's IDL:
Deprecated. Use
initialize2.
Discriminator 0a · data PreInitialize · accounts PreInitializeInstructionAccounts.
| Field | Type |
|---|---|
nonce | u8 |
Required accounts: 14; extras go to remaining.
Fields of PreInitializeInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | token_ | Pubkey |
| 1 | system_ | Pubkey |
| 2 | rent | Pubkey |
| 3 | amm_ | Pubkey |
| 4 | pool_ | Pubkey |
| 5 | amm_ | Pubkey |
| 6 | lp_ | Pubkey |
| 7 | coin_ | Pubkey |
| 8 | pc_ | Pubkey |
| 9 | pool_ | Pubkey |
| 10 | pool_ | Pubkey |
| 11 | pool_ | Pubkey |
| 12 | serum_ | Pubkey |
| 13 | user_wallet | Pubkey |
| 14… | remaining | Vec< |
SetParams#
From the program's IDL:
Admin: set an AMM parameter. The payload after
paramdepends on the variant:
- ammOwner: 32-byte Pubkey
- fees: 64-byte Fees struct
- lastOrderDistance: numerator(u64) + denominator(u64)
- all other variants: value(u64)
Only
value,newPubkey,fees, orlastOrderDistanceis populated based onparam.
Discriminator 06 · data SetParams · accounts SetParamsInstructionAccounts.
| Field | Type |
|---|---|
param | AmmParams |
value | Option<u64> |
new_pubkey | Option< |
fees | Option< |
last_ | Option< |
Required accounts: 16 (17 listed); extras go to remaining.
Fields of SetParamsInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | token_ | Pubkey |
| 1 | amm | Pubkey |
| 2 | amm_ | Pubkey |
| 3 | amm_ | Pubkey |
| 4 | amm_ | Pubkey |
| 5 | amm_ | Pubkey |
| 6 | amm_ | Pubkey |
| 7 | market_ | Pubkey |
| 8 | market | Pubkey |
| 9 | market_ | Pubkey |
| 10 | market_ | Pubkey |
| 11 | market_ | Pubkey |
| 12 | market_ | Pubkey |
| 13 | market_bids | Pubkey |
| 14 | market_asks | Pubkey |
| 15 | admin | Pubkey |
| 16 | new_ | Option< |
| 17… | remaining | Vec< |
SimulateInfo#
From the program's IDL:
Simulation-only instruction (used via simulateTransaction).
Payload afterparamdepends on the variant:
- poolInfo / runCrankInfo: no extra payload
- swapBaseInInfo: amountIn(u64) + minimumAmountOut(u64)
- swapBaseOutInfo: maxAmountIn(u64) + amountOut(u64)
Discriminator 0c · data SimulateInfo · accounts SimulateInfoInstructionAccounts.
| Field | Type |
|---|---|
param | SimulateParams |
swap_ | Option< |
swap_ | Option< |
Required accounts: 8; extras go to remaining.
Fields of SimulateInfoInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | amm | Pubkey |
| 1 | amm_ | Pubkey |
| 2 | amm_ | Pubkey |
| 3 | amm_ | Pubkey |
| 4 | amm_ | Pubkey |
| 5 | amm_lp_mint | Pubkey |
| 6 | market | Pubkey |
| 7 | market_ | Pubkey |
| 8… | remaining | Vec< |
SwapBaseIn#
From the program's IDL:
Swap a fixed input amount with a slippage-bounded output.
Discriminator 09 · 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 | token_ | Pubkey |
| 1 | amm | Pubkey |
| 2 | amm_ | Pubkey |
| 3 | amm_ | Pubkey |
| 4 | amm_ | Option< |
| 5 | amm_ | Pubkey |
| 6 | amm_ | Pubkey |
| 7 | market_ | Pubkey |
| 8 | market | Pubkey |
| 9 | market_bids | Pubkey |
| 10 | market_asks | Pubkey |
| 11 | market_ | Pubkey |
| 12 | market_ | Pubkey |
| 13 | market_ | Pubkey |
| 14 | market_ | Pubkey |
| 15 | user_ | Pubkey |
| 16 | user_ | Pubkey |
| 17 | user_ | Pubkey |
| 18… | remaining | Vec< |
SwapBaseInV2#
From the program's IDL:
Order-book-disabled swap with fixed input amount.
Discriminator 10 · data SwapBaseInV2 · accounts SwapBaseInV2InstructionAccounts.
| Field | Type |
|---|---|
amount_in | u64 |
minimum_ | u64 |
Required accounts: 8; extras go to remaining.
Fields of SwapBaseInV2InstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | token_ | Pubkey |
| 1 | amm | Pubkey |
| 2 | amm_ | Pubkey |
| 3 | amm_ | Pubkey |
| 4 | amm_ | Pubkey |
| 5 | user_ | Pubkey |
| 6 | user_ | Pubkey |
| 7 | user_ | Pubkey |
| 8… | remaining | Vec< |
SwapBaseOut#
From the program's IDL:
Swap to receive a fixed output amount with a slippage-bounded input.
Discriminator 0b · 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 | token_ | Pubkey |
| 1 | amm | Pubkey |
| 2 | amm_ | Pubkey |
| 3 | amm_ | Pubkey |
| 4 | amm_ | Option< |
| 5 | amm_ | Pubkey |
| 6 | amm_ | Pubkey |
| 7 | market_ | Pubkey |
| 8 | market | Pubkey |
| 9 | market_bids | Pubkey |
| 10 | market_asks | Pubkey |
| 11 | market_ | Pubkey |
| 12 | market_ | Pubkey |
| 13 | market_ | Pubkey |
| 14 | market_ | Pubkey |
| 15 | user_ | Pubkey |
| 16 | user_ | Pubkey |
| 17 | user_ | Pubkey |
| 18… | remaining | Vec< |
SwapBaseOutV2#
From the program's IDL:
Order-book-disabled swap with fixed output amount.
Discriminator 11 · data SwapBaseOutV2 · accounts SwapBaseOutV2InstructionAccounts.
| Field | Type |
|---|---|
max_ | u64 |
amount_out | u64 |
Required accounts: 8; extras go to remaining.
Fields of SwapBaseOutV2InstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | token_ | Pubkey |
| 1 | amm | Pubkey |
| 2 | amm_ | Pubkey |
| 3 | amm_ | Pubkey |
| 4 | amm_ | Pubkey |
| 5 | user_ | Pubkey |
| 6 | user_ | Pubkey |
| 7 | user_ | Pubkey |
| 8… | remaining | Vec< |
UpdateConfigAccount#
From the program's IDL:
Admin: update the AmmConfig. Payload after
paramdepends on the variant:
- pnlOwner / cancelOrderOwner: 32-byte Pubkey
- createPoolFee: u64
Discriminator 0f · data UpdateConfigAccount · accounts UpdateConfigAccountInstructionAccounts.
| Field | Type |
|---|---|
param | ConfigParam |
owner | Option< |
create_ | Option<u64> |
Required accounts: 2; extras go to remaining.
Fields of UpdateConfigAccountInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | admin | Pubkey |
| 1 | amm_config | Pubkey |
| 2… | remaining | Vec< |
Withdraw#
From the program's IDL:
Burn LP tokens and withdraw the underlying assets.
Discriminator 04 · data Withdraw · accounts WithdrawInstructionAccounts.
| Field | Type | Description |
|---|---|---|
amount | u64 | |
min_ | Option<u64> | Optional trailing slippage bound; both min fields are present or both absent. |
min_ | Option<u64> |
Required accounts: 20; extras go to remaining.
Fields of WithdrawInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | token_ | Pubkey |
| 1 | amm | Pubkey |
| 2 | amm_ | Pubkey |
| 3 | amm_ | Pubkey |
| 4 | amm_ | Pubkey |
| 5 | amm_lp_mint | Pubkey |
| 6 | amm_ | Pubkey |
| 7 | amm_ | Pubkey |
| 8 | market_ | Pubkey |
| 9 | market | Pubkey |
| 10 | market_ | Pubkey |
| 11 | market_ | Pubkey |
| 12 | market_ | Pubkey |
| 13 | user_ | Pubkey |
| 14 | user_ | Pubkey |
| 15 | user_ | Pubkey |
| 16 | user_owner | Pubkey |
| 17 | market_ | Pubkey |
| 18 | market_bids | Pubkey |
| 19 | market_asks | Pubkey |
| 20… | remaining | Vec< |
WithdrawPnl#
From the program's IDL:
Protocol: withdraw accrued PnL from the pool.
Discriminator 07 · data WithdrawPnl · accounts WithdrawPnlInstructionAccounts.
No data fields.
Required accounts: 17 (18 listed); extras go to remaining.
Fields of WithdrawPnlInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | token_ | Pubkey |
| 1 | amm | Pubkey |
| 2 | amm_config | Pubkey |
| 3 | amm_ | Pubkey |
| 4 | amm_ | Pubkey |
| 5 | amm_ | Pubkey |
| 6 | amm_ | Pubkey |
| 7 | user_ | Pubkey |
| 8 | user_ | Pubkey |
| 9 | user_owner | Pubkey |
| 10 | amm_ | Pubkey |
| 11 | market_ | Pubkey |
| 12 | market | Pubkey |
| 13 | market_ | Pubkey |
| 14 | market_ | Pubkey |
| 15 | market_ | Pubkey |
| 16 | market_ | Pubkey |
| 17 | referrer_ | Option< |
| 18… | remaining | Vec< |
WithdrawSrm#
From the program's IDL:
Admin: withdraw (M)SRM held for fee discounts.
Discriminator 08 · data WithdrawSrm · accounts WithdrawSrmInstructionAccounts.
| Field | Type |
|---|---|
amount | u64 |
Required accounts: 6; extras go to remaining.
Fields of WithdrawSrmInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | token_ | Pubkey |
| 1 | amm | Pubkey |
| 2 | admin | Pubkey |
| 3 | amm_ | Pubkey |
| 4 | srm_from | Pubkey |
| 5 | srm_to | Pubkey |
| 6… | remaining | Vec< |
Accounts#
Variants of RaydiumAmmV4Account. Each wraps a boxed struct from carbon_. decode_ only considers accounts owned by PROGRAM_ID and returns the first variant that matches.
AmmConfig#
From the program's IDL:
Global program config account.
Matched by data length (544 bytes) · accounts::.
| Field | Type |
|---|---|
pnl_owner | Pubkey |
cancel_ | Pubkey |
pending1 | [u64; 28] |
pending2 | [u64; 31] |
create_ | u64 |
AmmInfo#
From the program's IDL:
On-chain state of a single AMM pool.
Matched by data length (752 bytes) · accounts::.
| Field | Type |
|---|---|
status | u64 |
nonce | u64 |
order_num | u64 |
depth | u64 |
coin_ | u64 |
pc_decimals | u64 |
state | u64 |
reset_flag | u64 |
min_size | u64 |
vol_ | u64 |
amount_wave | u64 |
coin_ | u64 |
pc_lot_size | u64 |
min_ | u64 |
max_ | u64 |
sys_ | u64 |
fees | Fees |
state_data | StateData |
coin_vault | Pubkey |
pc_vault | Pubkey |
coin_ | Pubkey |
pc_ | Pubkey |
lp_mint | Pubkey |
open_orders | Pubkey |
market | Pubkey |
market_ | Pubkey |
target_ | Pubkey |
padding1 | [u64; 8] |
amm_owner | Pubkey |
lp_amount | u64 |
client_ | u64 |
recent_ | u64 |
padding2 | u64 |
TargetOrders#
From the program's IDL:
Per-pool target orders book.
No discriminator (matched by Borsh layout) · accounts::.
| Field | Type |
|---|---|
owner | [u64; 4] |
buy_orders | [TargetOrder; 50] |
padding1 | [u64; 8] |
target_x | u128 |
target_y | u128 |
plan_x_buy | u128 |
plan_y_buy | u128 |
plan_x_sell | u128 |
plan_y_sell | u128 |
placed_x | u128 |
placed_y | u128 |
calc_pnl_x | u128 |
calc_pnl_y | u128 |
sell_orders | [TargetOrder; 50] |
padding2 | [u64; 6] |
replace_ | [u64; 10] |
replace_ | [u64; 10] |
last_ | u64 |
last_ | u64 |
plan_ | u64 |
place_ | u64 |
valid_ | u64 |
valid_ | u64 |
padding3 | [u64; 10] |
free_ | u128 |
Types#
Types used by the instructions, accounts and events above, exported from carbon_.
AmmParams#
From the program's IDL:
SetParams.param values.
Enum types::.
| Variant |
|---|
Status |
State |
OrderNum |
Depth |
AmountWave |
MinPriceMultiplier |
MaxPriceMultiplier |
MinSize |
VolMaxCutRatio |
Fees |
AmmOwner |
SetOpenTime |
LastOrderDistance |
InitOrderDepth |
SetSwitchTime |
ClearOpenTime |
Seek |
EnableOrderBook |
DisableOrderBook |
AmmResetFlag#
Enum types::.
| Variant |
|---|
ResetYes |
ResetNo |
AmmState#
From the program's IDL:
AmmInfo.state machine (stored as u64).
Enum types::.
| Variant |
|---|
IdleState |
CancelAllOrdersState |
PlanOrdersState |
CancelOrderState |
PlaceOrdersState |
PurgeOrderState |
AmmStatus#
From the program's IDL:
AmmInfo.status discriminator (stored as u64).
Enum types::.
| Variant |
|---|
Uninitialized |
Initialized |
Disabled |
WithdrawOnly |
LiquidityOnly |
OrderBookOnly |
SwapOnly |
WaitingTrade |
ConfigParam#
From the program's IDL:
UpdateConfigAccount.param values.
Enum types::.
| Variant |
|---|
PnlOwner |
CancelOrderOwner |
CreatePoolFee |
Fees#
From the program's IDL:
Fee parameters for a pool.
Struct types::Fees.
| Field | Type |
|---|---|
min_ | u64 |
min_ | u64 |
trade_ | u64 |
trade_ | u64 |
pnl_ | u64 |
pnl_ | u64 |
swap_ | u64 |
swap_ | u64 |
LastOrderDistance#
Struct types::.
| Field | Type |
|---|---|
last_ | u64 |
last_ | u64 |
SimulateParams#
From the program's IDL:
SimulateInfo.param values.
Enum types::.
| Variant |
|---|
PoolInfo |
SwapBaseInInfo |
SwapBaseOutInfo |
RunCrankInfo |
StateData#
From the program's IDL:
Mutable pool statistics embedded in AmmInfo.
Struct types::.
| Field | Type |
|---|---|
need_ | u64 |
need_ | u64 |
total_ | u64 |
total_ | u64 |
pool_ | u64 |
padding | [u64; 2] |
orderbook_ | u64 |
swap_ | u128 |
swap_ | u128 |
swap_ | u64 |
swap_ | u128 |
swap_ | u128 |
swap_ | u64 |
SwapInstructionBaseIn#
Struct types::.
| Field | Type |
|---|---|
amount_in | u64 |
minimum_ | u64 |
SwapInstructionBaseOut#
Struct types::.
| Field | Type |
|---|---|
max_ | u64 |
amount_out | u64 |
TargetOrder#
Struct types::.
| Field | Type |
|---|---|
price | u64 |
vol | u64 |