refactor: update API with DexParamEnum and simplify TradeConfig

- Introduce DexParamEnum to replace Dex enum for protocol parameters
- Simplify TradeConfig::new() to accept only 3 essential parameters
- Update all examples to use new DexParamEnum API
- Optimize executor and params modules
- Remove deprecated wsol_use_seed and mint_use_seed parameters
- Fix fast_fn module exports
This commit is contained in:
Wood
2025-12-08 01:35:40 +08:00
parent de8c55e599
commit 80ad2e052e
24 changed files with 240 additions and 226 deletions
+5 -16
View File
@@ -5,7 +5,11 @@ use solana_sdk::{instruction::Instruction, signature::Signature};
/// 交易执行器trait - 定义了所有交易协议都需要实现的核心方法
#[async_trait::async_trait]
pub trait TradeExecutor: Send + Sync {
async fn swap(&self, params: SwapParams) -> Result<(bool, Signature, Option<anyhow::Error>)>;
/// 🔧 修复:返回Vec<Signature>支持多SWQOS并发交易
/// - bool: 是否至少有一个交易成功
/// - Vec<Signature>: 所有提交的交易签名(按SWQOS顺序)
/// - Option<anyhow::Error>: 最后一个错误(如果全部失败)
async fn swap(&self, params: SwapParams) -> Result<(bool, Vec<Signature>, Option<anyhow::Error>)>;
/// 获取协议名称
fn protocol_name(&self) -> &'static str;
}
@@ -19,18 +23,3 @@ pub trait InstructionBuilder: Send + Sync {
/// 构建卖出指令
async fn build_sell_instructions(&self, params: &SwapParams) -> Result<Vec<Instruction>>;
}
/// 协议特定参数trait - 允许每个协议定义自己的参数
pub trait ProtocolParams: Send + Sync {
/// 将参数转换为Any以便向下转型
fn as_any(&self) -> &dyn std::any::Any;
/// 克隆参数
fn clone_box(&self) -> Box<dyn ProtocolParams>;
}
impl Clone for Box<dyn ProtocolParams> {
fn clone(&self) -> Self {
self.clone_box()
}
}