solana_tx_decoding/instruction/raydium/
is_raydium_launchpad_swap_instruction.rs1use solana_central::Instruction;
2use solana_central::SwapDirection;
3use solana_central::constants::RAYDIUM_CONSTANTS;
4
5pub fn is_raydium_launchpad_swap_instruction(instruction: &Instruction) -> (bool, SwapDirection) {
9 if instruction.data.len() < 32 {
10 return (false, SwapDirection::AToB);
11 }
12 if instruction.accounts.len() < 14 {
13 return (false, SwapDirection::AToB);
14 }
15 if instruction.tx_account_keys[instruction.program_id_index as usize]
16 != RAYDIUM_CONSTANTS.launchpad_program
17 {
18 return (false, SwapDirection::AToB);
19 }
20 if instruction.data[0..8] == RAYDIUM_CONSTANTS.launchpad_swap_discriminators[0] {
22 return (true, SwapDirection::BToA);
23 } else if instruction.data[0..8] == RAYDIUM_CONSTANTS.launchpad_swap_discriminators[1] {
24 return (true, SwapDirection::AToB);
25 } else if instruction.data[0..8] == RAYDIUM_CONSTANTS.launchpad_swap_discriminators[2] {
26 return (true, SwapDirection::BToA);
27 } else if instruction.data[0..8] == RAYDIUM_CONSTANTS.launchpad_swap_discriminators[3] {
28 return (true, SwapDirection::AToB);
29 } else {
30 return (false, SwapDirection::AToB);
31 }
32}