feat: major refactor with calculation utilities and instruction optimization

- Add comprehensive calculation utilities for all protocols (bonk, pumpfun, pumpswap, raydium)
- Refactor instruction modules to reduce code complexity and improve maintainability
- Optimize trading parameters structure and enhance common utilities
- Separate calculation logic from trading modules for better code organization
- Update dependencies and module exports
This commit is contained in:
ysq
2025-08-18 18:00:14 +08:00
parent 350e34e0a0
commit 57474bfa6e
21 changed files with 1513 additions and 1107 deletions
+5 -27
View File
@@ -175,22 +175,11 @@ impl SolanaTrade {
slippage_basis_points: Option<u64>,
recent_blockhash: Hash,
custom_buy_tip_fee: Option<f64>,
extension_params: Option<Box<dyn ProtocolParams>>,
extension_params: Box<dyn ProtocolParams>,
lookup_table_key: Option<Pubkey>,
) -> Result<(), anyhow::Error> {
let executor = TradeFactory::create_executor(dex_type.clone());
let protocol_params = if let Some(params) = extension_params {
params
} else {
match dex_type {
DexType::PumpFun => Box::new(PumpFunParams::default()) as Box<dyn ProtocolParams>,
DexType::PumpSwap => Box::new(PumpSwapParams::default()) as Box<dyn ProtocolParams>,
DexType::Bonk => Box::new(BonkParams::default()) as Box<dyn ProtocolParams>,
DexType::RaydiumCpmm => {
Box::new(RaydiumCpmmParams::default()) as Box<dyn ProtocolParams>
}
}
};
let protocol_params = extension_params;
let final_lookup_table_key = lookup_table_key.or(self.trade_config.lookup_table_key);
@@ -308,22 +297,11 @@ impl SolanaTrade {
recent_blockhash: Hash,
custom_buy_tip_fee: Option<f64>,
with_tip: bool,
extension_params: Option<Box<dyn ProtocolParams>>,
extension_params: Box<dyn ProtocolParams>,
lookup_table_key: Option<Pubkey>,
) -> Result<(), anyhow::Error> {
let executor = TradeFactory::create_executor(dex_type.clone());
let protocol_params = if let Some(params) = extension_params {
params
} else {
match dex_type {
DexType::PumpFun => Box::new(PumpFunParams::default()) as Box<dyn ProtocolParams>,
DexType::PumpSwap => Box::new(PumpSwapParams::default()) as Box<dyn ProtocolParams>,
DexType::Bonk => Box::new(BonkParams::default()) as Box<dyn ProtocolParams>,
DexType::RaydiumCpmm => {
Box::new(RaydiumCpmmParams::default()) as Box<dyn ProtocolParams>
}
}
};
let protocol_params = extension_params;
let final_lookup_table_key = lookup_table_key.or(self.trade_config.lookup_table_key);
@@ -454,7 +432,7 @@ impl SolanaTrade {
recent_blockhash: Hash,
custom_buy_tip_fee: Option<f64>,
with_tip: bool,
extension_params: Option<Box<dyn ProtocolParams>>,
extension_params: Box<dyn ProtocolParams>,
lookup_table_key: Option<Pubkey>,
) -> Result<(), anyhow::Error> {
if percent == 0 || percent > 100 {