Quantcast
Channel: Recent Questions - Solana Stack Exchange
Viewing all articles
Browse latest Browse all 9228

How can I retrieve Raydium Swap instruction account keys using a mint address in Rust, without making an API call?

$
0
0

I'm working on creating a Raydium swap instruction for the Solana blockchain using Rust and need to construct it solely with Pubkeys, without making any external API calls. Specifically, I'm looking to build an instruction similar to the "Raydium Liquidity Pool V4: raydium" which can be seen in this transaction example on Solscan.

https://solscan.io/tx/5GwrTekdKgUReKpHjEr1m6LkpyX3RgzA2g4tQRJ3NQ45zBxaxdoYrpMyJyoMwcEL46NjUNzSry2Crqsz61rjbB7x

Below is the code I’ve started with:

async fn make_raydium_swap_instruction(    from_mint: Pubkey,    to_mint: Pubkey,    amount_in: u64,    min_amount_out: u64) -> Result<Instruction, Box<dyn std::error::Error>> {    let instruction_data_struct = RaydiumSwapInstructionData {        opcode: 9,        amount_in,        min_amount_out,    };    let instruction_data = bincode::serialize(&instruction_data_struct)?;    // Token program is hardcoded as an example, need similar logic for other keys    let token_program_pubkey = pubkey_from_base58(TOKEN_PROGRAM)?;    let amm_pubkey = // Logic needed to derive this account    let amm_authority_pubkey = pubkey_from_base58(RAYDIUM_AUTHORITY_V4)?;    // Additional required accounts also need to be derived}

My Goals:

Populate account Pubkeys like amm_pubkey, amm_authority_pubkey, and other required accounts for Raydium swap.Construct the instruction without relying on API calls—ideally, using deterministic Pubkey derivation or similar methods if applicable.

Challenges: I'm unsure how to programmatically determine account Pubkeys like amm_pubkey and others involved in the swap. Are there Rust utilities or specific derivation patterns in Solana that can help fetch these account addresses based on token mint addresses alone? Or are there any recommended approaches to handle this scenario efficiently?

Any guidance on constructing this swap instruction fully in Rust would be greatly appreciated. Thanks in advance!


Viewing all articles
Browse latest Browse all 9228

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>