OKX DEX decoder

Decode OKX DEX instructions, accounts and events in Rust with carbon-okx-dex-decoder 2.0.0. Program ID 6m2CDdhRgxpH4WjvdzxAYbGxwdGUz5MziiL5jek2kBma.

On this page

carbon-okx-dex-decoder decodes the instructions, accounts and events of the OKX DEX program (6m2CDdhRgxpH4WjvdzxAYbGxwdGUz5MziiL5jek2kBma): 14 instructions, 2 events. It decodes no accounts: OkxDexAccount has no variants. It is generated with Codama from the program's IDL; see decoders for how decoders plug into a pipeline.

Cratecarbon-okx-dex-decoder 2.0.0
Installcargo add carbon-okx-dex-decoder@2.0.0
Program ID6m2CDdhRgxpH4WjvdzxAYbGxwdGUz5MziiL5jek2kBma (carbon_okx_dex_decoder::PROGRAM_ID)
CategoryAggregators & routing
Decodercarbon_okx_dex_decoder::OkxDexDecoder
Instruction enuminstructions::OkxDexInstruction
Account enumaccounts::OkxDexAccount (no variants)
Event enuminstructions::CpiEvent
Featuresserde, postgres, graphql (none enabled by default)
API docsdocs.rs/carbon-okx-dex-decoder/2.0.0
Sourcedecoders/okx-dex-decoder

Other aggregator and routing decoders: DFlow Aggregator v4, Jupiter Swap, OnChain Labs DEX v2. To decode several in one pipeline, see aggregator and routing 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 OKX DEX transactions from the public RPC and prints every decoded Swap instruction. Add the dependencies:

Terminal
cargo add carbon-core@2.0.0 carbon-okx-dex-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_okx_dex_decoder::{instructions::OkxDexInstruction, OkxDexDecoder, 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(OkxDexDecoder, InstructionLogger)
        .build()?
        .run()
        .await
}

struct InstructionLogger;

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

Each Swap instruction prints one line with the transaction signature and the decoded Swap 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.

Events published with Anchor's emit_cpi! arrive as the CpiEvent instruction. Match them with OkxDexInstruction::CpiEvent { data: CpiEvent::SwapEvent(event), .. } (import instructions::CpiEvent); see Events. If CpiEvent never arrives, the program logs its events with emit! instead: decode them with decode_log_events.

Instructions#

Variants of OkxDexInstruction. Each is OkxDexInstruction::<Variant> { program_id, data, accounts }, where data and accounts are the types listed under the variant, exported from carbon_okx_dex_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 6m2CDdhRgxpH4WjvdzxAYbGxwdGUz5MziiL5jek2kBma.
  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.

Claim#

Discriminator 3ec6d6c1d59f6cd2 · data Claim · accounts ClaimInstructionAccounts.

No data fields.

Required accounts: 8 (9 listed); extras go to remaining.

Fields of ClaimInstructionAccounts, in account order:

#FieldType
0signerPubkey
1receiverPubkey
2source_token_accountOption<Pubkey>
3destination_token_accountOption<Pubkey>
4sa_authorityPubkey
5token_mintOption<Pubkey>
6token_programOption<Pubkey>
7system_programPubkey
8associated_token_programOption<Pubkey>
9…remainingVec<AccountMeta>

ClaimCashbackPumpfun#

Discriminator 5301f57dc9cfd1f9 · data ClaimCashbackPumpfun · accounts ClaimCashbackPumpfunInstructionAccounts.

No data fields.

Required accounts: 7; extras go to remaining.

Fields of ClaimCashbackPumpfunInstructionAccounts, in account order:

#FieldType
0signerPubkey
1sa_authorityPubkey
2user_volume_accumulatorPubkey
3receiverPubkey
4event_authorityPubkey
5system_programPubkey
6pumpfun_programPubkey
7…remainingVec<AccountMeta>

ClaimCashbackPumpswap#

Discriminator fdf2b0add94e6419 · data ClaimCashbackPumpswap · accounts ClaimCashbackPumpswapInstructionAccounts.

No data fields.

Required accounts: 11; extras go to remaining.

Fields of ClaimCashbackPumpswapInstructionAccounts, in account order:

#FieldType
0signerPubkey
1sa_authorityPubkey
2user_volume_accumulatorPubkey
3wsol_mintPubkey
4spl_token_programPubkey
5uva_wsol_ataPubkey
6sa_wsol_ataPubkey
7receiver_wsol_ataPubkey
8system_programPubkey
9event_authorityPubkey
10pumpswap_programPubkey
11…remainingVec<AccountMeta>

CreateTokenAccount#

Discriminator 93f17b64f484ae76 · data CreateTokenAccount · accounts CreateTokenAccountInstructionAccounts.

FieldType
bumpu8

Required accounts: 6; extras go to remaining.

Fields of CreateTokenAccountInstructionAccounts, in account order:

#FieldType
0payerPubkey
1ownerPubkey
2token_accountPubkey
3token_mintPubkey
4token_programPubkey
5system_programPubkey
6…remainingVec<AccountMeta>

CreateTokenAccountWithSeed#

Discriminator 7dbfef8c420809e4 · data CreateTokenAccountWithSeed · accounts CreateTokenAccountWithSeedInstructionAccounts.

FieldType
bumpu8
seedu32

Required accounts: 6; extras go to remaining.

Fields of CreateTokenAccountWithSeedInstructionAccounts, in account order:

#FieldType
0payerPubkey
1ownerPubkey
2token_accountPubkey
3token_mintPubkey
4token_programPubkey
5system_programPubkey
6…remainingVec<AccountMeta>

ProxySwap#

Discriminator 132c829448382cee · data ProxySwap · accounts ProxySwapInstructionAccounts.

FieldType
dataSwapArgs
order_idu64

Required accounts: 5 (12 listed); extras go to remaining.

Fields of ProxySwapInstructionAccounts, in account order:

#FieldType
0payerPubkey
1source_token_accountPubkey
2destination_token_accountPubkey
3source_mintPubkey
4destination_mintPubkey
5sa_authorityOption<Pubkey>
6source_token_saOption<Pubkey>
7destination_token_saOption<Pubkey>
8source_token_programOption<Pubkey>
9destination_token_programOption<Pubkey>
10associated_token_programOption<Pubkey>
11system_programOption<Pubkey>
12…remainingVec<AccountMeta>

Swap#

Discriminator f8c69e91e17587c8 · data Swap · accounts SwapInstructionAccounts.

FieldType
dataSwapArgs
order_idu64

Required accounts: 5; extras go to remaining.

Fields of SwapInstructionAccounts, in account order:

#FieldType
0payerPubkey
1source_token_accountPubkey
2destination_token_accountPubkey
3source_mintPubkey
4destination_mintPubkey
5…remainingVec<AccountMeta>

SwapTobV3#

Discriminator 0ebf2cf68ee1e09d · data SwapTobV3 · accounts SwapTobV3InstructionAccounts.

FieldType
argsSwapArgs
commission_infou32
trim_rateu8
platform_fee_rateu16
order_idu64

Required accounts: 5 (14 listed); extras go to remaining.

Fields of SwapTobV3InstructionAccounts, in account order:

#FieldType
0payerPubkey
1source_token_accountPubkey
2destination_token_accountPubkey
3source_mintPubkey
4destination_mintPubkey
5commission_accountOption<Pubkey>
6platform_fee_accountOption<Pubkey>
7sa_authorityOption<Pubkey>
8source_token_saOption<Pubkey>
9destination_token_saOption<Pubkey>
10source_token_programOption<Pubkey>
11destination_token_programOption<Pubkey>
12associated_token_programOption<Pubkey>
13system_programOption<Pubkey>
14…remainingVec<AccountMeta>

SwapTobV3Enhanced#

Discriminator ec479b44c6620e76 · data SwapTobV3Enhanced · accounts SwapTobV3EnhancedInstructionAccounts.

FieldType
argsSwapArgs
commission_infou32
trim_rateu8
charge_rateu16
platform_fee_rateu16
order_idu64

Required accounts: 5 (14 listed); extras go to remaining.

Fields of SwapTobV3EnhancedInstructionAccounts, in account order:

#FieldType
0payerPubkey
1source_token_accountPubkey
2destination_token_accountPubkey
3source_mintPubkey
4destination_mintPubkey
5commission_accountOption<Pubkey>
6platform_fee_accountOption<Pubkey>
7sa_authorityOption<Pubkey>
8source_token_saOption<Pubkey>
9destination_token_saOption<Pubkey>
10source_token_programOption<Pubkey>
11destination_token_programOption<Pubkey>
12associated_token_programOption<Pubkey>
13system_programOption<Pubkey>
14…remainingVec<AccountMeta>

SwapTobV3WithReceiver#

From the program's IDL:

Swap ToB with optional specified receiver

  • For normal token swaps: sol_receiver should be None
  • For swap to SOL with custom receiver: sol_receiver should be Some and acc_close_flag must be true

Discriminator 3f72f6833302f71d · data SwapTobV3WithReceiver · accounts SwapTobV3WithReceiverInstructionAccounts.

FieldType
argsSwapArgs
commission_infou32
trim_rateu8
platform_fee_rateu16
order_idu64

Required accounts: 5 (15 listed); extras go to remaining.

Fields of SwapTobV3WithReceiverInstructionAccounts, in account order:

#FieldType
0payerPubkey
1source_token_accountPubkey
2destination_token_accountPubkey
3source_mintPubkey
4destination_mintPubkey
5commission_accountOption<Pubkey>
6platform_fee_accountOption<Pubkey>
7sa_authorityOption<Pubkey>
8source_token_saOption<Pubkey>
9destination_token_saOption<Pubkey>
10source_token_programOption<Pubkey>
11destination_token_programOption<Pubkey>
12associated_token_programOption<Pubkey>
13system_programOption<Pubkey>
14sol_receiverOption<Pubkey>
15…remainingVec<AccountMeta>

SwapV3#

Discriminator f0e02621b01ff1af · data SwapV3 · accounts SwapV3InstructionAccounts.

FieldType
argsSwapArgs
commission_infou32
platform_fee_rateu16
order_idu64

Required accounts: 5 (14 listed); extras go to remaining.

Fields of SwapV3InstructionAccounts, in account order:

#FieldType
0payerPubkey
1source_token_accountPubkey
2destination_token_accountPubkey
3source_mintPubkey
4destination_mintPubkey
5commission_accountOption<Pubkey>
6platform_fee_accountOption<Pubkey>
7sa_authorityOption<Pubkey>
8source_token_saOption<Pubkey>
9destination_token_saOption<Pubkey>
10source_token_programOption<Pubkey>
11destination_token_programOption<Pubkey>
12associated_token_programOption<Pubkey>
13system_programOption<Pubkey>
14…remainingVec<AccountMeta>

SwapV3WithCpiEvent#

Discriminator b8684f9c6bb6788a · data SwapV3WithCpiEvent · accounts SwapV3WithCpiEventInstructionAccounts.

FieldType
argsSwapArgs
commission_infou32
platform_fee_rateu16
order_idu64

Required accounts: 16; extras go to remaining.

Fields of SwapV3WithCpiEventInstructionAccounts, in account order:

#FieldType
0payerPubkey
1source_token_accountPubkey
2destination_token_accountPubkey
3source_mintPubkey
4destination_mintPubkey
5commission_accountOption<Pubkey>
6platform_fee_accountOption<Pubkey>
7sa_authorityOption<Pubkey>
8source_token_saOption<Pubkey>
9destination_token_saOption<Pubkey>
10source_token_programOption<Pubkey>
11destination_token_programOption<Pubkey>
12associated_token_programOption<Pubkey>
13system_programOption<Pubkey>
14event_authorityPubkey
15programPubkey
16…remainingVec<AccountMeta>

WrapUnwrapV3#

Discriminator b4b2bf3646080de0 · data WrapUnwrapV3 · accounts WrapUnwrapV3InstructionAccounts.

Required accounts: 10; extras go to remaining.

Fields of WrapUnwrapV3InstructionAccounts, in account order:

#FieldType
0payerPubkey
1payer_wsol_accountPubkey
2wsol_mintPubkey
3temp_wsol_accountOption<Pubkey>
4commission_accountOption<Pubkey>
5platform_fee_accountOption<Pubkey>
6authority_pdaOption<Pubkey>
7wsol_saOption<Pubkey>
8token_programPubkey
9system_programPubkey
10…remainingVec<AccountMeta>

WrapUnwrapV3WithReceiver#

From the program's IDL:

Wrap/Unwrap with optional specified receiver

  • Wrap (SOL -> WSOL): receiver is WSOL token account (ATA)
  • Unwrap (WSOL -> SOL): receiver is system account (EOA)

Transfer amount:

  • From fee: amount_in
  • To fee: amount_in - fees

Discriminator 46d3bea52f28d55f · data WrapUnwrapV3WithReceiver · accounts WrapUnwrapV3WithReceiverInstructionAccounts.

Required accounts: 11; extras go to remaining.

Fields of WrapUnwrapV3WithReceiverInstructionAccounts, in account order:

#FieldType
0payerPubkey
1payer_wsol_accountPubkey
2wsol_mintPubkey
3temp_wsol_accountOption<Pubkey>
4commission_accountOption<Pubkey>
5platform_fee_accountOption<Pubkey>
6authority_pdaOption<Pubkey>
7wsol_saOption<Pubkey>
8token_programPubkey
9system_programPubkey
10receiverPubkey
11…remainingVec<AccountMeta>

CpiEvent#

Anchor self-CPI that carries one of the program's events. data is the CpiEvent enum.

Discriminator e445a52e51cb9a1d · data CpiEvent · accounts CpiEventInstructionAccounts.

Required accounts: 2; extras go to remaining.

Fields of CpiEventInstructionAccounts, in account order:

#FieldType
0programPubkey
1event_authorityPubkey
2…remainingVec<AccountMeta>

Events#

Variants of instructions::CpiEvent, decoded from the CpiEvent instruction. Each wraps a struct from carbon_okx_dex_decoder::events::<module>. The discriminator is the 8-byte event discriminator that follows the e445a52e51cb9a1d CPI-event tag.

SwapEvent#

Discriminator 40c6cde8260871e2 · events::swap_event::SwapEventEvent.

FieldType
dexDex
amount_inu64
amount_outu64

SwapWithFeesCpiEvent#

Discriminator bd61430c25d1f71d · events::swap_with_fees_cpi_event::SwapWithFeesCpiEventEvent.

FieldType
order_idu64
source_mintPubkey
destination_mintPubkey
source_token_account_ownerPubkey
destination_token_account_ownerPubkey
amount_inu64
source_token_changeu64
destination_token_changeu64
commission_directionbool
commission_rateu32
commission_amountu64
commission_accountPubkey
platform_fee_rateu16
platform_fee_amountu64
platform_fee_accountPubkey
trim_rateu8
trim_amountu64
trim_accountPubkey

Types#

Types used by the instructions, accounts and events above, exported from carbon_okx_dex_decoder::types.

Dex#

Enum types::Dex.

VariantFields
SplTokenSwap
StableSwap
Whirlpool
MeteoraDynamicpool
RaydiumSwap
RaydiumStableSwap
RaydiumClmmSwap
AldrinExchangeV1
AldrinExchangeV2
LifinityV1
LifinityV2
RaydiumClmmSwapV2
FluxBeam
MeteoraDlmm
RaydiumCpmmSwap
OpenBookV2
WhirlpoolV2
Phoenix
ObricV2
SanctumAddLiq
SanctumRemoveLiq
SanctumNonWsolSwap
SanctumWsolSwap
PumpfunBuy
PumpfunSell
StabbleSwap
SanctumRouter
MeteoraVaultDeposit
MeteoraVaultWithdraw
Saros
MeteoraLst
Solfi
QualiaSwap
Zerofi
PumpfunammBuy
PumpfunammSell
Virtuals
VertigoBuy
VertigoSell
PerpetualsAddLiq
PerpetualsRemoveLiq
PerpetualsSwap
RaydiumLaunchpad
LetsBonkFun
Woofi
MeteoraDbc
MeteoraDlmmSwap2
MeteoraDAMMV2
Gavel
BoopfunBuy
BoopfunSell
MeteoraDbc2
GooseFX
Dooar
Numeraire
SaberDecimalWrapperDeposit
SaberDecimalWrapperWithdraw
SarosDlmm
OneDexSwap
Manifest
ByrealClmm
PancakeSwapV3Swap
PancakeSwapV3SwapV2
Tessera
SolRfqrfq_id: u64, expected_maker_amount: u64, expected_taker_amount: u64, maker_send_amount: u64, taker_send_amount: u64, expiry: u64, maker_use_native_sol: bool, taker_use_native_sol: bool
PumpfunBuy2
PumpfunammBuy2
Humidifi
HeavenBuy
HeavenSell
SolfiV2
PumpfunBuy3
PumpfunSell3
PumpfunammBuy3
PumpfunammSell3
Goonfi
MoonitBuy
MoonitSell
RaydiumSwapV2
Whalestreet
SugarMoneyBuybonding_curve_bump: u8, bonding_curve_sol_associated_account_bump: u8
SugarMoneySellbonding_curve_bump: u8, bonding_curve_sol_associated_account_bump: u8
MeteoraDAMMV2Swap2
AlphaQ
FutarchyAmm
PumpfunSell2
HumidifiSwap2swap_id: u64
Scorchid: u128
JupiterLendDeposit
JupiterLendRedeem
TaurusFi
BisonFi
GoonfiV2
Quantum
BoopfunBuy2
BoopfunSell2
ByrealClmm2
Dooar2
HeavenBuy2
HeavenSell2
MoonitBuy2
MoonitSell2
SaberDecimalWrapperDeposit2
SaberDecimalWrapperWithdraw2
ByrealPropAmm
SanctumPrefundSwapViaStakeswap_id: u64
AbyssAmm
Aquifer
WhalestreetV2auth_amount_in: u64, auth: u64
SolfiV2WithSigunix_timestamp: u64, msg_amount_in: u64, expect_amount_out: u64, slippage: u16, user_request_slot: u64, signature: [u8; 64], recovery_id: u8

PlatformFeeWrapUnwrapArgs#

Struct types::PlatformFeeWrapUnwrapArgs.

FieldType
order_idu64
amount_inu64
commission_infou32
platform_fee_rateu16
tobbool

Route#

Struct types::Route.

FieldType
dexesVec<Dex>
weightsVec<u8>

SwapArgs#

Struct types::SwapArgs.

FieldType
amount_inu64
expect_amount_outu64
min_returnu64
amountsVec<u64>
routesVec<Vec<Route>>

SwapEvent#

Struct types::SwapEvent. Same fields as the SwapEvent event.

SwapWithFeesCpiEvent#

Struct types::SwapWithFeesCpiEvent. Same fields as the SwapWithFeesCpiEvent event.

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.