please fix this use solanaclient::rpcclient::RpcClient; use solanasdk::{…
- User
please fix this use solana_client::rpc_client::RpcClient; use solana_sdk::{ commitment_config::CommitmentConfig, pubkey::Pubkey, signature::{Keypair, Signer}, transaction::Transaction, instruction::{Instruction, AccountMeta}, message::Message, }; use spl_associated_token_account::get_associated_token_address; use std::{str::FromStr, fs, time::Duration}; use serde::Deserialize; use log::{info, error};
const RAYDIUM_SWAP_V2: &str = "675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8";
#[derive(Deserialize)] struct Config { rpc_url: String, keypair_64: String, amount_to_trade: f64, priority_fee: u64, }
fn main() -> Result<(), Box> { // Initialize logging env_logger::init();
// Load configuration let config: Config = toml::from_str(&fs::read_to_string("config.toml")?)?; let client = RpcClient::new_with_commitment(&config.rpc_url, CommitmentConfig::confirmed()); // Load keypair directly from the 64-byte key let keypair_bytes: Vec<u8> = config.keypair_64.split(',') .map(|s| s.trim().parse::<u8>().unwrap()) .collect(); let keypair = Keypair::from_bytes(&keypair_bytes)?; // SOL and USDC mint addresses let sol_mint = Pubkey::from_str("So11111111111111111111111111111111111111112")?; let usdc_mint = Pubkey::from_str("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v")?; // Raydium SOL/USDC pool address let pool_address = Pubkey::from_str("58oQChx4yWmvKdwLLZzBi4ChoCc2fqCUWBkwMihLYQo2")?; // Check SOL balance let sol_balance = client.get_balance(&keypair.pubkey())?; info!("SOL balance: {} SOL", sol_balance as f64 / 1e9); // Perform buy (SOL to USDC) info!("Performing buy (SOL to USDC)..."); let sol_amount_in = (config.amount_to_trade * 1e9) as u64; // Convert SOL to lamports if sol_amount_in + 5000 > sol_balance { // 5000 lamports for fee error!("Insufficient SOL balance for trade and fee"); return Err("Insufficient balance".into()); } match swap(&client, &keypair, &pool_address, &sol_mint, &usdc_mint, sol_amount_in, config.priority_fee) { Ok(signature) => info!("Buy transaction signature: {}", signature), Err(e) => { error!("Buy transaction failed: {}", e); return Err(e); } } // Wait a bit before selling std::thread::sleep(Duration::from_secs(5)); // Check USDC balance let usdc_account = get_associated_token_address(&keypair.pubkey(), &usdc_mint); let usdc_balance = client.get_token_account_balance(&usdc_account)?; info!("USDC balance: {} USDC", usdc_balance.amount.parse::<f64>()? / 1e6); // Perform sell (USDC to SOL) info!("Performing sell (USDC to SOL)..."); let usdc_amount_in = (usdc_balance.amount.parse::<f64>()? * 0.99 * 1e6) as u64; // Sell 99% of USDC balance if usdc_amount_in == 0 { error!("Insufficient USDC balance for trade"); return Err("Insufficient USDC balance".into()); } match swap(&client, &keypair, &pool_address, &usdc_mint, &sol_mint, usdc_amount_in, config.priority_fee) { Ok(signature) => info!("Sell transaction signature: {}", signature), Err(e) => { error!("Sell transaction failed: {}", e); return Err(e); } } Ok(()) - Assistant
- User
can u rewrite the full script correctly
- Assistant
- User
Compiling solana-sniper-bot v0.1.0 (C:\solana_rust_bot) warning: unused import: --> src/main.rs:9:5 | 9 | system_instruction, | ^^^^^^^^^^^^^^^^^^ | = note: on by default
- Assistant
- User
S C:\solana_rust_bot> cargo run --release --jobs 7
Finishedreleaseprofile [optimized] target(s) in 0.29s Runningtarget\release\solana-sniper-bot.exeError: Error { request: Some(SendTransaction), kind: RpcError(RpcResponseError { code: -32002, message: "Transaction simulation failed: Error processing Instruction 1: custom program error: 0x18", data: SendTransactionPreflightFailure(RpcSimulateTransactionResult { err: Some(InstructionError(1, Custom(24))), logs: Some(["Program ComputeBudget111111111111111111111111111111 invoke [1]", "Program ComputeBudget111111111111111111111111111111 success", "Program 675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8 invoke [1]", "Program log: Error: WrongAccountsNumber", "Program 675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8 consumed 1900 of 199850 compute units", "Program 675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8 failed: custom program error: 0x18"]), accounts: None, units_consumed: Some(2050), return_data: None, inner_instructions: None }) }) } error: process didn't exit successfully:target\release\solana-sniper-bot.exe(exit code: 1) PS C:\solana_rust_bot> - Assistant
- User
continue
- Assistant
- Assistant
It seems like you were about to add something or ask a question. Feel free to provide more details or ask any additional questions you have about developing with Solana, Rust, or any other related topics. I'm here to help!
- User
- Assistant
- User
write fulll script please really dig deep here
- Assistant
- User
- Assistant
- User
- Assistant
- User
full script please
- Assistant
- User
Compiling solana-sniper-bot v0.1.0 (C:\solana_rust_bot) Finished
releaseprofile [optimized] target(s) in 2.01s PS C:\solana_rust_bot> cargo run --release --jobs 7
Finishedreleaseprofile [optimized] target(s) in 0.29s Runningtarget\release\solana-sniper-bot.exeError: Error { request: Some(SendTransaction), kind: RpcError(RpcResponseError { code: -32002, message: "Transaction simulation failed: Error processing Instruction 1: invalid instruction data", data: SendTransactionPreflightFailure(RpcSimulateTransactionResult { err: Some(InstructionError(1, InvalidInstructionData)), logs: Some(["Program ComputeBudget111111111111111111111111111111 invoke [1]", "Program ComputeBudget111111111111111111111111111111 success", "Program 675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8 invoke [1]", "Program log: Error: InvalidInstructionData", "Program 675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8 consumed 5316 of 199850 compute units", "Program 675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8 failed: invalid instruction data"]), accounts: None, units_consumed: Some(5466), return_data: None, inner_instructions: None }) }) } error: process didn't exit successfully:target\release\solana-sniper-bot.exe(exit code: 1) PS C:\solana_rust_bot> fix please full - Assistant
- User
Compiling solana-sniper-bot v0.1.0 (C:\solana_rust_bot) Finished
releaseprofile [optimized] target(s) in 1.95s PS C:\solana_rust_bot> cargo run --release --jobs 7
Finishedreleaseprofile [optimized] target(s) in 0.28s Runningtarget\release\solana-sniper-bot.exeError: Error { request: Some(SendTransaction), kind: RpcError(RpcResponseError { code: -32002, message: "Transaction simulation failed: Error processing Instruction 1: custom program error: 0x1b", data: SendTransactionPreflightFailure(RpcSimulateTransactionResult { err: Some(InstructionError(1, Custom(27))), logs: Some(["Program ComputeBudget111111111111111111111111111111 invoke [1]", "Program ComputeBudget111111111111111111111111111111 success", "Program 675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8 invoke [1]", "Program log: Error: The amm account owner is not match with this program", "Program 675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8 consumed 5576 of 199850 compute units", "Program 675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8 failed: custom program error: 0x1b"]), accounts: None, units_consumed: Some(5726), return_data: None, inner_instructions: None }) }) } error: process didn't exit successfully:target\release\solana-sniper-bot.exe(exit code: 1) PS C:\solana_rust_bot> nope fix please - Assistant
- User
PS C:\solana_rust_bot> cargo build --release --jobs 7 Compiling solana-sniper-bot v0.1.0 (C:\solana_rust_bot) Finished
releaseprofile [optimized] target(s) in 1.96s PS C:\solana_rust_bot> cargo run --release --jobs 7
Finishedreleaseprofile [optimized] target(s) in 0.28s Runningtarget\release\solana-sniper-bot.exeError: Error { request: Some(SendTransaction), kind: RpcError(RpcResponseError { code: -32002, message: "Transaction simulation failed: Error processing Instruction 1: custom program error: 0x1b", data: SendTransactionPreflightFailure(RpcSimulateTransactionResult { err: Some(InstructionError(1, Custom(27))), logs: Some(["Program ComputeBudget111111111111111111111111111111 invoke [1]", "Program ComputeBudget111111111111111111111111111111 success", "Program 675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8 invoke [1]", "Program log: Error: The amm account owner is not match with this program", "Program 675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8 consumed 5576 of 199850 compute units", "Program 675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8 failed: custom program error: 0x1b"]), accounts: None, units_consumed: Some(5726), return_data: None, inner_instructions: None }) }) } error: process didn't exit successfully:target\release\solana-sniper-bot.exe(exit code: 1) need you to fix please make work - Assistant
- User
- Assistant
- User
- Assistant