Files
sol-trade-sdk/src/trading/middleware/builtin.rs
T
Wood 9f79e865ab perf: P0/P1/P2 low-latency and maintainability improvements
P0:
- blockhash/nonce: get_transaction_blockhash returns Result; buy/sell entry validation
- Bonk sell: remove RPC get_token_balance from build path; require caller to pass input_amount
- Hot path: drop redundant dex_type/protocol_params clone; tip via sol_f64_to_lamports (no String)
- compute_budget cache uses Arc; extend_compute_budget_instructions avoids SmallVec clone

P1:
- middleware protocol_name takes &str; executor destructures result once to avoid signatures/submit_timings clone
- Error messages include dex context; params use Copy for Pubkey; pumpswap utils clone only Pool for pools[0]

P2:
- transaction_pool capacity constants; TIP_ACCOUNT_CACHE marked allow(dead_code)
- Fix error copy in raydium_amm_v4 / meteora_damm_v2 to correct protocol names

Made-with: Cursor
2026-03-08 01:05:27 +08:00

54 lines
1.9 KiB
Rust

use crate::trading::middleware::traits::InstructionMiddleware;
use anyhow::Result;
use solana_sdk::instruction::Instruction;
/// Logging middleware - Records instruction information
#[derive(Clone)]
pub struct LoggingMiddleware;
impl InstructionMiddleware for LoggingMiddleware {
fn name(&self) -> &'static str {
"LoggingMiddleware"
}
fn process_protocol_instructions(
&self,
protocol_instructions: Vec<Instruction>,
protocol_name: &str,
is_buy: bool,
) -> Result<Vec<Instruction>> {
println!("-------------------[{}]-------------------", self.name());
println!("process_protocol_instructions");
println!("[{}] Instruction count: {}", self.name(), protocol_instructions.len());
println!("[{}] Protocol name: {}\n", self.name(), protocol_name);
println!("[{}] Is buy: {}", self.name(), is_buy);
for (i, instruction) in protocol_instructions.iter().enumerate() {
println!("Instruction {}:", i + 1);
println!("{:?}\n", instruction);
}
Ok(protocol_instructions)
}
fn process_full_instructions(
&self,
full_instructions: Vec<Instruction>,
protocol_name: &str,
is_buy: bool,
) -> Result<Vec<Instruction>> {
println!("-------------------[{}]-------------------", self.name());
println!("process_full_instructions");
println!("[{}] Instruction count: {}", self.name(), full_instructions.len());
println!("[{}] Protocol name: {}\n", self.name(), protocol_name);
println!("[{}] Is buy: {}", self.name(), is_buy);
for (i, instruction) in full_instructions.iter().enumerate() {
println!("Instruction {}:", i + 1);
println!("{:?}\n", instruction);
}
Ok(full_instructions)
}
fn clone_box(&self) -> Box<dyn InstructionMiddleware> {
Box::new(self.clone())
}
}