2025-06-17 23:32:20 +08:00
|
|
|
use solana_hash::Hash;
|
|
|
|
|
use solana_sdk::{pubkey::Pubkey, signature::Keypair};
|
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
|
|
use super::traits::ProtocolParams;
|
|
|
|
|
use crate::common::{PriorityFee, SolanaRpcClient};
|
2025-07-06 22:06:44 +08:00
|
|
|
use crate::swqos::SwqosClient;
|
2025-07-10 02:53:01 +08:00
|
|
|
use crate::common::bonding_curve::BondingCurveAccount;
|
2025-06-17 23:32:20 +08:00
|
|
|
|
|
|
|
|
/// 通用买入参数
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
|
pub struct BuyParams {
|
|
|
|
|
pub rpc: Option<Arc<SolanaRpcClient>>,
|
|
|
|
|
pub payer: Arc<Keypair>,
|
|
|
|
|
pub mint: Pubkey,
|
|
|
|
|
pub creator: Pubkey,
|
|
|
|
|
pub amount_sol: u64,
|
|
|
|
|
pub slippage_basis_points: Option<u64>,
|
|
|
|
|
pub priority_fee: PriorityFee,
|
|
|
|
|
pub lookup_table_key: Option<Pubkey>,
|
|
|
|
|
pub recent_blockhash: Hash,
|
|
|
|
|
pub data_size_limit: u32,
|
|
|
|
|
pub protocol_params: Box<dyn ProtocolParams>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// 带MEV服务的买入参数
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
|
pub struct BuyWithTipParams {
|
|
|
|
|
pub rpc: Option<Arc<SolanaRpcClient>>,
|
2025-07-06 22:06:44 +08:00
|
|
|
pub swqos_clients: Vec<Arc<SwqosClient>>,
|
2025-06-17 23:32:20 +08:00
|
|
|
pub payer: Arc<Keypair>,
|
|
|
|
|
pub mint: Pubkey,
|
|
|
|
|
pub creator: Pubkey,
|
|
|
|
|
pub amount_sol: u64,
|
|
|
|
|
pub slippage_basis_points: Option<u64>,
|
|
|
|
|
pub priority_fee: PriorityFee,
|
|
|
|
|
pub lookup_table_key: Option<Pubkey>,
|
|
|
|
|
pub recent_blockhash: Hash,
|
|
|
|
|
pub data_size_limit: u32,
|
|
|
|
|
pub protocol_params: Box<dyn ProtocolParams>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// 通用卖出参数
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
|
pub struct SellParams {
|
|
|
|
|
pub rpc: Option<Arc<SolanaRpcClient>>,
|
|
|
|
|
pub payer: Arc<Keypair>,
|
|
|
|
|
pub mint: Pubkey,
|
|
|
|
|
pub creator: Pubkey,
|
|
|
|
|
pub amount_token: Option<u64>,
|
|
|
|
|
pub slippage_basis_points: Option<u64>,
|
|
|
|
|
pub priority_fee: PriorityFee,
|
|
|
|
|
pub lookup_table_key: Option<Pubkey>,
|
|
|
|
|
pub recent_blockhash: Hash,
|
|
|
|
|
pub protocol_params: Box<dyn ProtocolParams>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// 带MEV服务的卖出参数
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
|
pub struct SellWithTipParams {
|
|
|
|
|
pub rpc: Option<Arc<SolanaRpcClient>>,
|
2025-07-06 22:06:44 +08:00
|
|
|
pub swqos_clients: Vec<Arc<SwqosClient>>,
|
2025-06-17 23:32:20 +08:00
|
|
|
pub payer: Arc<Keypair>,
|
|
|
|
|
pub mint: Pubkey,
|
|
|
|
|
pub creator: Pubkey,
|
|
|
|
|
pub amount_token: Option<u64>,
|
|
|
|
|
pub slippage_basis_points: Option<u64>,
|
|
|
|
|
pub priority_fee: PriorityFee,
|
|
|
|
|
pub lookup_table_key: Option<Pubkey>,
|
|
|
|
|
pub recent_blockhash: Hash,
|
|
|
|
|
pub protocol_params: Box<dyn ProtocolParams>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// PumpFun协议特定参数
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
|
pub struct PumpFunParams {
|
|
|
|
|
pub trade_type: String,
|
2025-06-18 17:39:20 +08:00
|
|
|
pub bonding_curve: Option<Arc<BondingCurveAccount>>,
|
2025-06-17 23:32:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl ProtocolParams for PumpFunParams {
|
|
|
|
|
fn as_any(&self) -> &dyn std::any::Any {
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn clone_box(&self) -> Box<dyn ProtocolParams> {
|
|
|
|
|
Box::new(self.clone())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
|
pub struct PumpFunSellParams {}
|
|
|
|
|
|
|
|
|
|
impl ProtocolParams for PumpFunSellParams {
|
|
|
|
|
fn as_any(&self) -> &dyn std::any::Any {
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn clone_box(&self) -> Box<dyn ProtocolParams> {
|
|
|
|
|
Box::new(self.clone())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// PumpSwap协议特定参数
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
|
pub struct PumpSwapParams {
|
|
|
|
|
pub pool: Option<Pubkey>,
|
|
|
|
|
pub pool_base_token_account: Option<Pubkey>,
|
|
|
|
|
pub pool_quote_token_account: Option<Pubkey>,
|
|
|
|
|
pub user_base_token_account: Option<Pubkey>,
|
|
|
|
|
pub user_quote_token_account: Option<Pubkey>,
|
2025-06-23 00:50:51 +08:00
|
|
|
pub auto_handle_wsol: bool,
|
2025-06-17 23:32:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl ProtocolParams for PumpSwapParams {
|
|
|
|
|
fn as_any(&self) -> &dyn std::any::Any {
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn clone_box(&self) -> Box<dyn ProtocolParams> {
|
|
|
|
|
Box::new(self.clone())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-10 00:23:29 +08:00
|
|
|
/// Bonk协议特定参数
|
2025-07-09 22:29:29 +08:00
|
|
|
#[derive(Clone)]
|
2025-07-10 00:23:29 +08:00
|
|
|
pub struct BonkParams {
|
2025-07-09 22:29:29 +08:00
|
|
|
pub virtual_base: Option<u128>,
|
|
|
|
|
pub virtual_quote: Option<u128>,
|
|
|
|
|
pub real_base_before: Option<u128>,
|
|
|
|
|
pub real_quote_before: Option<u128>,
|
|
|
|
|
pub auto_handle_wsol: bool,
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-10 00:23:29 +08:00
|
|
|
impl ProtocolParams for BonkParams {
|
2025-07-09 22:29:29 +08:00
|
|
|
fn as_any(&self) -> &dyn std::any::Any {
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn clone_box(&self) -> Box<dyn ProtocolParams> {
|
|
|
|
|
Box::new(self.clone())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-17 23:32:20 +08:00
|
|
|
impl BuyParams {
|
|
|
|
|
/// 转换为BuyWithTipParams
|
2025-07-06 22:06:44 +08:00
|
|
|
pub fn with_tip(self, swqos_clients: Vec<Arc<SwqosClient>>) -> BuyWithTipParams {
|
2025-06-17 23:32:20 +08:00
|
|
|
BuyWithTipParams {
|
|
|
|
|
rpc: self.rpc,
|
2025-07-06 22:06:44 +08:00
|
|
|
swqos_clients,
|
2025-06-17 23:32:20 +08:00
|
|
|
payer: self.payer,
|
|
|
|
|
mint: self.mint,
|
|
|
|
|
creator: self.creator,
|
|
|
|
|
amount_sol: self.amount_sol,
|
|
|
|
|
slippage_basis_points: self.slippage_basis_points,
|
|
|
|
|
priority_fee: self.priority_fee,
|
|
|
|
|
lookup_table_key: self.lookup_table_key,
|
|
|
|
|
recent_blockhash: self.recent_blockhash,
|
|
|
|
|
data_size_limit: self.data_size_limit,
|
|
|
|
|
protocol_params: self.protocol_params,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl SellParams {
|
|
|
|
|
/// 转换为SellWithTipParams
|
2025-07-06 22:06:44 +08:00
|
|
|
pub fn with_tip(self, swqos_clients: Vec<Arc<SwqosClient>>) -> SellWithTipParams {
|
2025-06-17 23:32:20 +08:00
|
|
|
SellWithTipParams {
|
|
|
|
|
rpc: self.rpc,
|
2025-07-06 22:06:44 +08:00
|
|
|
swqos_clients,
|
2025-06-17 23:32:20 +08:00
|
|
|
payer: self.payer,
|
|
|
|
|
mint: self.mint,
|
|
|
|
|
creator: self.creator,
|
|
|
|
|
amount_token: self.amount_token,
|
|
|
|
|
slippage_basis_points: self.slippage_basis_points,
|
|
|
|
|
priority_fee: self.priority_fee,
|
|
|
|
|
lookup_table_key: self.lookup_table_key,
|
|
|
|
|
recent_blockhash: self.recent_blockhash,
|
|
|
|
|
protocol_params: self.protocol_params,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|