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.
| Crate | carbon-okx-dex-decoder 2.0.0 |
| Install | cargo add carbon-okx-dex-decoder@2. |
| Program ID | 6m2CDdhRgxpH4WjvdzxAYbGxwdGUz5MziiL5jek2kBma (carbon_) |
| Category | Aggregators & routing |
| Decoder | carbon_ |
| Instruction enum | instructions:: |
| Account enum | accounts:: (no variants) |
| Event enum | instructions:: |
| Features | serde, postgres, graphql (none enabled by default) |
| API docs | docs.rs/carbon-okx-dex-decoder/2.0.0 |
| Source | decoders/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:
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/fulluse {
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(())
}
}RUST_LOG=info cargo runEach 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:: (import instructions::); see Events. If CpiEvent never arrives, the program logs its events with emit! instead: decode them with decode_.
Instructions#
Variants of OkxDexInstruction. Each is OkxDexInstruction::, 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
6m2CDdhRgxpH4WjvdzxAYbGxwdGUz5MziiL5jek2kBma. - 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.
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:
| # | Field | Type |
|---|---|---|
| 0 | signer | Pubkey |
| 1 | receiver | Pubkey |
| 2 | source_ | Option< |
| 3 | destination_ | Option< |
| 4 | sa_ | Pubkey |
| 5 | token_mint | Option< |
| 6 | token_ | Option< |
| 7 | system_ | Pubkey |
| 8 | associated_ | Option< |
| 9… | remaining | Vec< |
ClaimCashbackPumpfun#
Discriminator 5301f57dc9cfd1f9 · data ClaimCashbackPumpfun · accounts ClaimCashbackPumpfunInstructionAccounts.
No data fields.
Required accounts: 7; extras go to remaining.
Fields of ClaimCashbackPumpfunInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | signer | Pubkey |
| 1 | sa_ | Pubkey |
| 2 | user_ | Pubkey |
| 3 | receiver | Pubkey |
| 4 | event_ | Pubkey |
| 5 | system_ | Pubkey |
| 6 | pumpfun_ | Pubkey |
| 7… | remaining | Vec< |
ClaimCashbackPumpswap#
Discriminator fdf2b0add94e6419 · data ClaimCashbackPumpswap · accounts ClaimCashbackPumpswapInstructionAccounts.
No data fields.
Required accounts: 11; extras go to remaining.
Fields of ClaimCashbackPumpswapInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | signer | Pubkey |
| 1 | sa_ | Pubkey |
| 2 | user_ | Pubkey |
| 3 | wsol_mint | Pubkey |
| 4 | spl_ | Pubkey |
| 5 | uva_ | Pubkey |
| 6 | sa_wsol_ata | Pubkey |
| 7 | receiver_ | Pubkey |
| 8 | system_ | Pubkey |
| 9 | event_ | Pubkey |
| 10 | pumpswap_ | Pubkey |
| 11… | remaining | Vec< |
CreateTokenAccount#
Discriminator 93f17b64f484ae76 · data CreateTokenAccount · accounts CreateTokenAccountInstructionAccounts.
| Field | Type |
|---|---|
bump | u8 |
Required accounts: 6; extras go to remaining.
Fields of CreateTokenAccountInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | payer | Pubkey |
| 1 | owner | Pubkey |
| 2 | token_ | Pubkey |
| 3 | token_mint | Pubkey |
| 4 | token_ | Pubkey |
| 5 | system_ | Pubkey |
| 6… | remaining | Vec< |
CreateTokenAccountWithSeed#
Discriminator 7dbfef8c420809e4 · data CreateTokenAccountWithSeed · accounts CreateTokenAccountWithSeedInstructionAccounts.
| Field | Type |
|---|---|
bump | u8 |
seed | u32 |
Required accounts: 6; extras go to remaining.
Fields of CreateTokenAccountWithSeedInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | payer | Pubkey |
| 1 | owner | Pubkey |
| 2 | token_ | Pubkey |
| 3 | token_mint | Pubkey |
| 4 | token_ | Pubkey |
| 5 | system_ | Pubkey |
| 6… | remaining | Vec< |
ProxySwap#
Discriminator 132c829448382cee · data ProxySwap · accounts ProxySwapInstructionAccounts.
| Field | Type |
|---|---|
data | SwapArgs |
order_id | u64 |
Required accounts: 5 (12 listed); extras go to remaining.
Fields of ProxySwapInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | payer | Pubkey |
| 1 | source_ | Pubkey |
| 2 | destination_ | Pubkey |
| 3 | source_mint | Pubkey |
| 4 | destination_ | Pubkey |
| 5 | sa_ | Option< |
| 6 | source_ | Option< |
| 7 | destination_ | Option< |
| 8 | source_ | Option< |
| 9 | destination_ | Option< |
| 10 | associated_ | Option< |
| 11 | system_ | Option< |
| 12… | remaining | Vec< |
Swap#
Discriminator f8c69e91e17587c8 · data Swap · accounts SwapInstructionAccounts.
| Field | Type |
|---|---|
data | SwapArgs |
order_id | u64 |
Required accounts: 5; extras go to remaining.
Fields of SwapInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | payer | Pubkey |
| 1 | source_ | Pubkey |
| 2 | destination_ | Pubkey |
| 3 | source_mint | Pubkey |
| 4 | destination_ | Pubkey |
| 5… | remaining | Vec< |
SwapTobV3#
Discriminator 0ebf2cf68ee1e09d · data SwapTobV3 · accounts SwapTobV3InstructionAccounts.
| Field | Type |
|---|---|
args | SwapArgs |
commission_ | u32 |
trim_rate | u8 |
platform_ | u16 |
order_id | u64 |
Required accounts: 5 (14 listed); extras go to remaining.
Fields of SwapTobV3InstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | payer | Pubkey |
| 1 | source_ | Pubkey |
| 2 | destination_ | Pubkey |
| 3 | source_mint | Pubkey |
| 4 | destination_ | Pubkey |
| 5 | commission_ | Option< |
| 6 | platform_ | Option< |
| 7 | sa_ | Option< |
| 8 | source_ | Option< |
| 9 | destination_ | Option< |
| 10 | source_ | Option< |
| 11 | destination_ | Option< |
| 12 | associated_ | Option< |
| 13 | system_ | Option< |
| 14… | remaining | Vec< |
SwapTobV3Enhanced#
Discriminator ec479b44c6620e76 · data SwapTobV3Enhanced · accounts SwapTobV3EnhancedInstructionAccounts.
| Field | Type |
|---|---|
args | SwapArgs |
commission_ | u32 |
trim_rate | u8 |
charge_rate | u16 |
platform_ | u16 |
order_id | u64 |
Required accounts: 5 (14 listed); extras go to remaining.
Fields of SwapTobV3EnhancedInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | payer | Pubkey |
| 1 | source_ | Pubkey |
| 2 | destination_ | Pubkey |
| 3 | source_mint | Pubkey |
| 4 | destination_ | Pubkey |
| 5 | commission_ | Option< |
| 6 | platform_ | Option< |
| 7 | sa_ | Option< |
| 8 | source_ | Option< |
| 9 | destination_ | Option< |
| 10 | source_ | Option< |
| 11 | destination_ | Option< |
| 12 | associated_ | Option< |
| 13 | system_ | Option< |
| 14… | remaining | Vec< |
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.
| Field | Type |
|---|---|
args | SwapArgs |
commission_ | u32 |
trim_rate | u8 |
platform_ | u16 |
order_id | u64 |
Required accounts: 5 (15 listed); extras go to remaining.
Fields of SwapTobV3WithReceiverInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | payer | Pubkey |
| 1 | source_ | Pubkey |
| 2 | destination_ | Pubkey |
| 3 | source_mint | Pubkey |
| 4 | destination_ | Pubkey |
| 5 | commission_ | Option< |
| 6 | platform_ | Option< |
| 7 | sa_ | Option< |
| 8 | source_ | Option< |
| 9 | destination_ | Option< |
| 10 | source_ | Option< |
| 11 | destination_ | Option< |
| 12 | associated_ | Option< |
| 13 | system_ | Option< |
| 14 | sol_ | Option< |
| 15… | remaining | Vec< |
SwapV3#
Discriminator f0e02621b01ff1af · data SwapV3 · accounts SwapV3InstructionAccounts.
| Field | Type |
|---|---|
args | SwapArgs |
commission_ | u32 |
platform_ | u16 |
order_id | u64 |
Required accounts: 5 (14 listed); extras go to remaining.
Fields of SwapV3InstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | payer | Pubkey |
| 1 | source_ | Pubkey |
| 2 | destination_ | Pubkey |
| 3 | source_mint | Pubkey |
| 4 | destination_ | Pubkey |
| 5 | commission_ | Option< |
| 6 | platform_ | Option< |
| 7 | sa_ | Option< |
| 8 | source_ | Option< |
| 9 | destination_ | Option< |
| 10 | source_ | Option< |
| 11 | destination_ | Option< |
| 12 | associated_ | Option< |
| 13 | system_ | Option< |
| 14… | remaining | Vec< |
SwapV3WithCpiEvent#
Discriminator b8684f9c6bb6788a · data SwapV3WithCpiEvent · accounts SwapV3WithCpiEventInstructionAccounts.
| Field | Type |
|---|---|
args | SwapArgs |
commission_ | u32 |
platform_ | u16 |
order_id | u64 |
Required accounts: 16; extras go to remaining.
Fields of SwapV3WithCpiEventInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | payer | Pubkey |
| 1 | source_ | Pubkey |
| 2 | destination_ | Pubkey |
| 3 | source_mint | Pubkey |
| 4 | destination_ | Pubkey |
| 5 | commission_ | Option< |
| 6 | platform_ | Option< |
| 7 | sa_ | Option< |
| 8 | source_ | Option< |
| 9 | destination_ | Option< |
| 10 | source_ | Option< |
| 11 | destination_ | Option< |
| 12 | associated_ | Option< |
| 13 | system_ | Option< |
| 14 | event_ | Pubkey |
| 15 | program | Pubkey |
| 16… | remaining | Vec< |
WrapUnwrapV3#
Discriminator b4b2bf3646080de0 · data WrapUnwrapV3 · accounts WrapUnwrapV3InstructionAccounts.
| Field | Type |
|---|---|
args | PlatformFeeWrapUnwrapArgs |
Required accounts: 10; extras go to remaining.
Fields of WrapUnwrapV3InstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | payer | Pubkey |
| 1 | payer_ | Pubkey |
| 2 | wsol_mint | Pubkey |
| 3 | temp_ | Option< |
| 4 | commission_ | Option< |
| 5 | platform_ | Option< |
| 6 | authority_ | Option< |
| 7 | wsol_sa | Option< |
| 8 | token_ | Pubkey |
| 9 | system_ | Pubkey |
| 10… | remaining | Vec< |
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.
| Field | Type |
|---|---|
args | PlatformFeeWrapUnwrapArgs |
Required accounts: 11; extras go to remaining.
Fields of WrapUnwrapV3WithReceiverInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | payer | Pubkey |
| 1 | payer_ | Pubkey |
| 2 | wsol_mint | Pubkey |
| 3 | temp_ | Option< |
| 4 | commission_ | Option< |
| 5 | platform_ | Option< |
| 6 | authority_ | Option< |
| 7 | wsol_sa | Option< |
| 8 | token_ | Pubkey |
| 9 | system_ | Pubkey |
| 10 | receiver | Pubkey |
| 11… | remaining | Vec< |
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:
| # | Field | Type |
|---|---|---|
| 0 | program | Pubkey |
| 1 | event_ | Pubkey |
| 2… | remaining | Vec< |
Events#
Variants of instructions::, decoded from the CpiEvent instruction. Each wraps a struct from carbon_. The discriminator is the 8-byte event discriminator that follows the e445a52e51cb9a1d CPI-event tag.
SwapEvent#
Discriminator 40c6cde8260871e2 · events::.
| Field | Type |
|---|---|
dex | Dex |
amount_in | u64 |
amount_out | u64 |
SwapWithFeesCpiEvent#
Discriminator bd61430c25d1f71d · events::.
| Field | Type |
|---|---|
order_id | u64 |
source_mint | Pubkey |
destination_ | Pubkey |
source_ | Pubkey |
destination_ | Pubkey |
amount_in | u64 |
source_ | u64 |
destination_ | u64 |
commission_ | bool |
commission_ | u32 |
commission_ | u64 |
commission_ | Pubkey |
platform_ | u16 |
platform_ | u64 |
platform_ | Pubkey |
trim_rate | u8 |
trim_amount | u64 |
trim_ | Pubkey |
Types#
Types used by the instructions, accounts and events above, exported from carbon_.
Dex#
Enum types::Dex.
| Variant | Fields |
|---|---|
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 | |
SolRfq | rfq_id: u64, expected_: u64, expected_: u64, maker_: u64, taker_: u64, expiry: u64, maker_: bool, taker_: bool |
PumpfunBuy2 | |
PumpfunammBuy2 | |
Humidifi | |
HeavenBuy | |
HeavenSell | |
SolfiV2 | |
PumpfunBuy3 | |
PumpfunSell3 | |
PumpfunammBuy3 | |
PumpfunammSell3 | |
Goonfi | |
MoonitBuy | |
MoonitSell | |
RaydiumSwapV2 | |
Whalestreet | |
SugarMoneyBuy | bonding_: u8, bonding_: u8 |
SugarMoneySell | bonding_: u8, bonding_: u8 |
MeteoraDAMMV2Swap2 | |
AlphaQ | |
FutarchyAmm | |
PumpfunSell2 | |
HumidifiSwap2 | swap_id: u64 |
Scorch | id: u128 |
JupiterLendDeposit | |
JupiterLendRedeem | |
TaurusFi | |
BisonFi | |
GoonfiV2 | |
Quantum | |
BoopfunBuy2 | |
BoopfunSell2 | |
ByrealClmm2 | |
Dooar2 | |
HeavenBuy2 | |
HeavenSell2 | |
MoonitBuy2 | |
MoonitSell2 | |
SaberDecimalWrapperDeposit2 | |
SaberDecimalWrapperWithdraw2 | |
ByrealPropAmm | |
SanctumPrefundSwapViaStake | swap_id: u64 |
AbyssAmm | |
Aquifer | |
WhalestreetV2 | auth_: u64, auth: u64 |
SolfiV2WithSig | unix_: u64, msg_: u64, expect_: u64, slippage: u16, user_: u64, signature: [u8; 64], recovery_id: u8 |
PlatformFeeWrapUnwrapArgs#
Struct types::.
| Field | Type |
|---|---|
order_id | u64 |
amount_in | u64 |
commission_ | u32 |
platform_ | u16 |
tob | bool |
Route#
Struct types::.
| Field | Type |
|---|---|
dexes | Vec<Dex> |
weights | Vec<u8> |
SwapArgs#
Struct types::.
| Field | Type |
|---|---|
amount_in | u64 |
expect_ | u64 |
min_return | u64 |
amounts | Vec<u64> |
routes | Vec< |
SwapEvent#
Struct types::. Same fields as the SwapEvent event.
SwapWithFeesCpiEvent#
Struct types::. Same fields as the SwapWithFeesCpiEvent event.