rename protocol to dex_type
This commit is contained in:
@@ -255,6 +255,7 @@ async fn test_pumpfun() -> AnyResult<()> {
|
|||||||
// buy
|
// buy
|
||||||
solana_trade_client
|
solana_trade_client
|
||||||
.buy(
|
.buy(
|
||||||
|
DexType::PumpFun,
|
||||||
mint_pubkey,
|
mint_pubkey,
|
||||||
Some(creator),
|
Some(creator),
|
||||||
buy_sol_cost,
|
buy_sol_cost,
|
||||||
@@ -262,7 +263,6 @@ async fn test_pumpfun() -> AnyResult<()> {
|
|||||||
recent_blockhash,
|
recent_blockhash,
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
TradingProtocol::PumpFun,
|
|
||||||
Some(Box::new(PumpFunParams {
|
Some(Box::new(PumpFunParams {
|
||||||
bonding_curve: Some(Arc::new(bonding_curve.clone())),
|
bonding_curve: Some(Arc::new(bonding_curve.clone())),
|
||||||
})),
|
})),
|
||||||
@@ -274,6 +274,7 @@ async fn test_pumpfun() -> AnyResult<()> {
|
|||||||
let amount_token = 0; // Enter the actual amount_token
|
let amount_token = 0; // Enter the actual amount_token
|
||||||
solana_trade_client
|
solana_trade_client
|
||||||
.sell(
|
.sell(
|
||||||
|
DexType::PumpFun,
|
||||||
mint_pubkey,
|
mint_pubkey,
|
||||||
Some(creator),
|
Some(creator),
|
||||||
amount_token,
|
amount_token,
|
||||||
@@ -281,7 +282,6 @@ async fn test_pumpfun() -> AnyResult<()> {
|
|||||||
recent_blockhash,
|
recent_blockhash,
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
TradingProtocol::PumpFun,
|
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -306,6 +306,7 @@ async fn test_pumpswap() -> AnyResult<()> {
|
|||||||
// buy
|
// buy
|
||||||
solana_trade_client
|
solana_trade_client
|
||||||
.buy(
|
.buy(
|
||||||
|
DexType::PumpSwap,
|
||||||
mint_pubkey,
|
mint_pubkey,
|
||||||
Some(creator),
|
Some(creator),
|
||||||
buy_sol_cost,
|
buy_sol_cost,
|
||||||
@@ -313,7 +314,6 @@ async fn test_pumpswap() -> AnyResult<()> {
|
|||||||
recent_blockhash,
|
recent_blockhash,
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
TradingProtocol::PumpSwap,
|
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -323,6 +323,7 @@ async fn test_pumpswap() -> AnyResult<()> {
|
|||||||
let amount_token = 0; // Enter the actual amount_token
|
let amount_token = 0; // Enter the actual amount_token
|
||||||
solana_trade_client
|
solana_trade_client
|
||||||
.sell(
|
.sell(
|
||||||
|
DexType::PumpSwap,
|
||||||
mint_pubkey,
|
mint_pubkey,
|
||||||
Some(creator),
|
Some(creator),
|
||||||
amount_token,
|
amount_token,
|
||||||
@@ -330,7 +331,6 @@ async fn test_pumpswap() -> AnyResult<()> {
|
|||||||
recent_blockhash,
|
recent_blockhash,
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
TradingProtocol::PumpSwap,
|
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -354,6 +354,7 @@ async fn test_bonk() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
// buy
|
// buy
|
||||||
solana_trade_client
|
solana_trade_client
|
||||||
.buy(
|
.buy(
|
||||||
|
DexType::Bonk,
|
||||||
mint_pubkey,
|
mint_pubkey,
|
||||||
None,
|
None,
|
||||||
buy_sol_cost,
|
buy_sol_cost,
|
||||||
@@ -361,7 +362,6 @@ async fn test_bonk() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
recent_blockhash,
|
recent_blockhash,
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
TradingProtocol::Bonk,
|
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -371,6 +371,7 @@ async fn test_bonk() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let amount_token = 0; // Enter the actual amount_token
|
let amount_token = 0; // Enter the actual amount_token
|
||||||
solana_trade_client
|
solana_trade_client
|
||||||
.sell(
|
.sell(
|
||||||
|
DexType::Bonk,
|
||||||
mint_pubkey,
|
mint_pubkey,
|
||||||
None,
|
None,
|
||||||
amount_token,
|
amount_token,
|
||||||
@@ -378,7 +379,6 @@ async fn test_bonk() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
recent_blockhash,
|
recent_blockhash,
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
TradingProtocol::Bonk,
|
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|||||||
+6
-6
@@ -255,6 +255,7 @@ async fn test_pumpfun() -> AnyResult<()> {
|
|||||||
// buy
|
// buy
|
||||||
solana_trade_client
|
solana_trade_client
|
||||||
.buy(
|
.buy(
|
||||||
|
DexType::PumpFun,
|
||||||
mint_pubkey,
|
mint_pubkey,
|
||||||
Some(creator),
|
Some(creator),
|
||||||
buy_sol_cost,
|
buy_sol_cost,
|
||||||
@@ -262,7 +263,6 @@ async fn test_pumpfun() -> AnyResult<()> {
|
|||||||
recent_blockhash,
|
recent_blockhash,
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
TradingProtocol::PumpFun,
|
|
||||||
Some(Box::new(PumpFunParams {
|
Some(Box::new(PumpFunParams {
|
||||||
bonding_curve: Some(Arc::new(bonding_curve.clone())),
|
bonding_curve: Some(Arc::new(bonding_curve.clone())),
|
||||||
})),
|
})),
|
||||||
@@ -274,6 +274,7 @@ async fn test_pumpfun() -> AnyResult<()> {
|
|||||||
let amount_token = 0; // 写上真实的amount_token
|
let amount_token = 0; // 写上真实的amount_token
|
||||||
solana_trade_client
|
solana_trade_client
|
||||||
.sell(
|
.sell(
|
||||||
|
DexType::PumpFun,
|
||||||
mint_pubkey,
|
mint_pubkey,
|
||||||
Some(creator),
|
Some(creator),
|
||||||
amount_token,
|
amount_token,
|
||||||
@@ -281,7 +282,6 @@ async fn test_pumpfun() -> AnyResult<()> {
|
|||||||
recent_blockhash,
|
recent_blockhash,
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
TradingProtocol::PumpFun,
|
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -306,6 +306,7 @@ async fn test_pumpswap() -> AnyResult<()> {
|
|||||||
// buy
|
// buy
|
||||||
solana_trade_client
|
solana_trade_client
|
||||||
.buy(
|
.buy(
|
||||||
|
DexType::PumpSwap,
|
||||||
mint_pubkey,
|
mint_pubkey,
|
||||||
Some(creator),
|
Some(creator),
|
||||||
buy_sol_cost,
|
buy_sol_cost,
|
||||||
@@ -313,7 +314,6 @@ async fn test_pumpswap() -> AnyResult<()> {
|
|||||||
recent_blockhash,
|
recent_blockhash,
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
TradingProtocol::PumpSwap,
|
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -323,6 +323,7 @@ async fn test_pumpswap() -> AnyResult<()> {
|
|||||||
let amount_token = 0; // 写上真实的amount_token
|
let amount_token = 0; // 写上真实的amount_token
|
||||||
solana_trade_client
|
solana_trade_client
|
||||||
.sell(
|
.sell(
|
||||||
|
DexType::PumpSwap,
|
||||||
mint_pubkey,
|
mint_pubkey,
|
||||||
Some(creator),
|
Some(creator),
|
||||||
amount_token,
|
amount_token,
|
||||||
@@ -330,7 +331,6 @@ async fn test_pumpswap() -> AnyResult<()> {
|
|||||||
recent_blockhash,
|
recent_blockhash,
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
TradingProtocol::PumpSwap,
|
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -354,6 +354,7 @@ async fn test_bonk() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
// buy
|
// buy
|
||||||
solana_trade_client
|
solana_trade_client
|
||||||
.buy(
|
.buy(
|
||||||
|
DexType::Bonk,
|
||||||
mint_pubkey,
|
mint_pubkey,
|
||||||
None,
|
None,
|
||||||
buy_sol_cost,
|
buy_sol_cost,
|
||||||
@@ -361,7 +362,6 @@ async fn test_bonk() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
recent_blockhash,
|
recent_blockhash,
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
TradingProtocol::Bonk,
|
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -371,6 +371,7 @@ async fn test_bonk() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let amount_token = 0; // 写上真实的amount_token
|
let amount_token = 0; // 写上真实的amount_token
|
||||||
solana_trade_client
|
solana_trade_client
|
||||||
.sell(
|
.sell(
|
||||||
|
DexType::Bonk,
|
||||||
mint_pubkey,
|
mint_pubkey,
|
||||||
None,
|
None,
|
||||||
amount_token,
|
amount_token,
|
||||||
@@ -378,7 +379,6 @@ async fn test_bonk() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
recent_blockhash,
|
recent_blockhash,
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
TradingProtocol::Bonk,
|
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|||||||
+32
-32
@@ -12,7 +12,7 @@ use crate::trading::core::params::BonkParams;
|
|||||||
use crate::trading::core::params::PumpFunParams;
|
use crate::trading::core::params::PumpFunParams;
|
||||||
use crate::trading::core::params::PumpSwapParams;
|
use crate::trading::core::params::PumpSwapParams;
|
||||||
use crate::trading::core::traits::ProtocolParams;
|
use crate::trading::core::traits::ProtocolParams;
|
||||||
use crate::trading::factory::TradingProtocol;
|
use crate::trading::factory::DexType;
|
||||||
use crate::trading::BuyParams;
|
use crate::trading::BuyParams;
|
||||||
use crate::trading::SellParams;
|
use crate::trading::SellParams;
|
||||||
use crate::trading::TradeFactory;
|
use crate::trading::TradeFactory;
|
||||||
@@ -153,6 +153,7 @@ impl SolanaTrade {
|
|||||||
/// ```
|
/// ```
|
||||||
pub async fn buy(
|
pub async fn buy(
|
||||||
&self,
|
&self,
|
||||||
|
dex_type: DexType,
|
||||||
mint: Pubkey,
|
mint: Pubkey,
|
||||||
creator: Option<Pubkey>,
|
creator: Option<Pubkey>,
|
||||||
amount_sol: u64,
|
amount_sol: u64,
|
||||||
@@ -160,21 +161,20 @@ impl SolanaTrade {
|
|||||||
recent_blockhash: Hash,
|
recent_blockhash: Hash,
|
||||||
custom_buy_tip_fee: Option<f64>,
|
custom_buy_tip_fee: Option<f64>,
|
||||||
with_tip: bool,
|
with_tip: bool,
|
||||||
protocol: TradingProtocol,
|
extension_params: Option<Box<dyn ProtocolParams>>,
|
||||||
protocol_params: Option<Box<dyn ProtocolParams>>,
|
|
||||||
) -> Result<(), anyhow::Error> {
|
) -> Result<(), anyhow::Error> {
|
||||||
let executor = TradeFactory::create_executor(protocol.clone());
|
let executor = TradeFactory::create_executor(dex_type.clone());
|
||||||
let protocol_params = if let Some(params) = protocol_params {
|
let protocol_params = if let Some(params) = extension_params {
|
||||||
params
|
params
|
||||||
} else {
|
} else {
|
||||||
match protocol {
|
match dex_type {
|
||||||
TradingProtocol::PumpFun => {
|
DexType::PumpFun => {
|
||||||
Box::new(PumpFunParams::default()) as Box<dyn ProtocolParams>
|
Box::new(PumpFunParams::default()) as Box<dyn ProtocolParams>
|
||||||
}
|
}
|
||||||
TradingProtocol::PumpSwap => {
|
DexType::PumpSwap => {
|
||||||
Box::new(PumpSwapParams::default()) as Box<dyn ProtocolParams>
|
Box::new(PumpSwapParams::default()) as Box<dyn ProtocolParams>
|
||||||
}
|
}
|
||||||
TradingProtocol::Bonk => Box::new(BonkParams::default()) as Box<dyn ProtocolParams>,
|
DexType::Bonk => Box::new(BonkParams::default()) as Box<dyn ProtocolParams>,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let buy_params = BuyParams {
|
let buy_params = BuyParams {
|
||||||
@@ -203,16 +203,16 @@ impl SolanaTrade {
|
|||||||
let buy_with_tip_params = buy_params.clone().with_tip(self.swqos_clients.clone());
|
let buy_with_tip_params = buy_params.clone().with_tip(self.swqos_clients.clone());
|
||||||
|
|
||||||
// Validate protocol params
|
// Validate protocol params
|
||||||
let is_valid_params = match protocol {
|
let is_valid_params = match dex_type {
|
||||||
TradingProtocol::PumpFun => protocol_params
|
DexType::PumpFun => protocol_params
|
||||||
.as_any()
|
.as_any()
|
||||||
.downcast_ref::<PumpFunParams>()
|
.downcast_ref::<PumpFunParams>()
|
||||||
.is_some(),
|
.is_some(),
|
||||||
TradingProtocol::PumpSwap => protocol_params
|
DexType::PumpSwap => protocol_params
|
||||||
.as_any()
|
.as_any()
|
||||||
.downcast_ref::<PumpSwapParams>()
|
.downcast_ref::<PumpSwapParams>()
|
||||||
.is_some(),
|
.is_some(),
|
||||||
TradingProtocol::Bonk => protocol_params
|
DexType::Bonk => protocol_params
|
||||||
.as_any()
|
.as_any()
|
||||||
.downcast_ref::<BonkParams>()
|
.downcast_ref::<BonkParams>()
|
||||||
.is_some(),
|
.is_some(),
|
||||||
@@ -262,7 +262,7 @@ impl SolanaTrade {
|
|||||||
/// ```rust
|
/// ```rust
|
||||||
/// use solana_sdk::pubkey::Pubkey;
|
/// use solana_sdk::pubkey::Pubkey;
|
||||||
/// use solana_sdk::hash::Hash;
|
/// use solana_sdk::hash::Hash;
|
||||||
/// use crate::trading::factory::TradingProtocol;
|
/// use crate::trading::factory::DexType;
|
||||||
///
|
///
|
||||||
/// let mint = Pubkey::new_unique();
|
/// let mint = Pubkey::new_unique();
|
||||||
/// let amount_token = 1_000_000; // Amount of tokens to sell
|
/// let amount_token = 1_000_000; // Amount of tokens to sell
|
||||||
@@ -277,12 +277,13 @@ impl SolanaTrade {
|
|||||||
/// recent_blockhash,
|
/// recent_blockhash,
|
||||||
/// None,
|
/// None,
|
||||||
/// true,
|
/// true,
|
||||||
/// TradingProtocol::PumpFun,
|
/// DexType::PumpFun,
|
||||||
/// None,
|
/// None,
|
||||||
/// ).await?;
|
/// ).await?;
|
||||||
/// ```
|
/// ```
|
||||||
pub async fn sell(
|
pub async fn sell(
|
||||||
&self,
|
&self,
|
||||||
|
dex_type: DexType,
|
||||||
mint: Pubkey,
|
mint: Pubkey,
|
||||||
creator: Option<Pubkey>,
|
creator: Option<Pubkey>,
|
||||||
amount_token: u64,
|
amount_token: u64,
|
||||||
@@ -290,21 +291,20 @@ impl SolanaTrade {
|
|||||||
recent_blockhash: Hash,
|
recent_blockhash: Hash,
|
||||||
custom_buy_tip_fee: Option<f64>,
|
custom_buy_tip_fee: Option<f64>,
|
||||||
with_tip: bool,
|
with_tip: bool,
|
||||||
protocol: TradingProtocol,
|
extension_params: Option<Box<dyn ProtocolParams>>,
|
||||||
protocol_params: Option<Box<dyn ProtocolParams>>,
|
|
||||||
) -> Result<(), anyhow::Error> {
|
) -> Result<(), anyhow::Error> {
|
||||||
let executor = TradeFactory::create_executor(protocol.clone());
|
let executor = TradeFactory::create_executor(dex_type.clone());
|
||||||
let protocol_params = if let Some(params) = protocol_params {
|
let protocol_params = if let Some(params) = extension_params {
|
||||||
params
|
params
|
||||||
} else {
|
} else {
|
||||||
match protocol {
|
match dex_type {
|
||||||
TradingProtocol::PumpFun => {
|
DexType::PumpFun => {
|
||||||
Box::new(PumpFunParams::default()) as Box<dyn ProtocolParams>
|
Box::new(PumpFunParams::default()) as Box<dyn ProtocolParams>
|
||||||
}
|
}
|
||||||
TradingProtocol::PumpSwap => {
|
DexType::PumpSwap => {
|
||||||
Box::new(PumpSwapParams::default()) as Box<dyn ProtocolParams>
|
Box::new(PumpSwapParams::default()) as Box<dyn ProtocolParams>
|
||||||
}
|
}
|
||||||
TradingProtocol::Bonk => Box::new(BonkParams::default()) as Box<dyn ProtocolParams>,
|
DexType::Bonk => Box::new(BonkParams::default()) as Box<dyn ProtocolParams>,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let sell_params = SellParams {
|
let sell_params = SellParams {
|
||||||
@@ -332,16 +332,16 @@ impl SolanaTrade {
|
|||||||
let sell_with_tip_params = sell_params.clone().with_tip(self.swqos_clients.clone());
|
let sell_with_tip_params = sell_params.clone().with_tip(self.swqos_clients.clone());
|
||||||
|
|
||||||
// Validate protocol params
|
// Validate protocol params
|
||||||
let is_valid_params = match protocol {
|
let is_valid_params = match dex_type {
|
||||||
TradingProtocol::PumpFun => protocol_params
|
DexType::PumpFun => protocol_params
|
||||||
.as_any()
|
.as_any()
|
||||||
.downcast_ref::<PumpFunParams>()
|
.downcast_ref::<PumpFunParams>()
|
||||||
.is_some(),
|
.is_some(),
|
||||||
TradingProtocol::PumpSwap => protocol_params
|
DexType::PumpSwap => protocol_params
|
||||||
.as_any()
|
.as_any()
|
||||||
.downcast_ref::<PumpSwapParams>()
|
.downcast_ref::<PumpSwapParams>()
|
||||||
.is_some(),
|
.is_some(),
|
||||||
TradingProtocol::Bonk => protocol_params
|
DexType::Bonk => protocol_params
|
||||||
.as_any()
|
.as_any()
|
||||||
.downcast_ref::<BonkParams>()
|
.downcast_ref::<BonkParams>()
|
||||||
.is_some(),
|
.is_some(),
|
||||||
@@ -414,12 +414,13 @@ impl SolanaTrade {
|
|||||||
/// recent_blockhash,
|
/// recent_blockhash,
|
||||||
/// None,
|
/// None,
|
||||||
/// true,
|
/// true,
|
||||||
/// TradingProtocol::PumpFun,
|
/// DexType::PumpFun,
|
||||||
/// None,
|
/// None,
|
||||||
/// ).await?;
|
/// ).await?;
|
||||||
/// ```
|
/// ```
|
||||||
pub async fn sell_by_percent(
|
pub async fn sell_by_percent(
|
||||||
&self,
|
&self,
|
||||||
|
dex_type: DexType,
|
||||||
mint: Pubkey,
|
mint: Pubkey,
|
||||||
creator: Option<Pubkey>,
|
creator: Option<Pubkey>,
|
||||||
amount_token: u64,
|
amount_token: u64,
|
||||||
@@ -428,14 +429,14 @@ impl SolanaTrade {
|
|||||||
recent_blockhash: Hash,
|
recent_blockhash: Hash,
|
||||||
custom_buy_tip_fee: Option<f64>,
|
custom_buy_tip_fee: Option<f64>,
|
||||||
with_tip: bool,
|
with_tip: bool,
|
||||||
protocol: TradingProtocol,
|
extension_params: Option<Box<dyn ProtocolParams>>,
|
||||||
protocol_params: Option<Box<dyn ProtocolParams>>,
|
|
||||||
) -> Result<(), anyhow::Error> {
|
) -> Result<(), anyhow::Error> {
|
||||||
if percent == 0 || percent > 100 {
|
if percent == 0 || percent > 100 {
|
||||||
return Err(anyhow::anyhow!("Percentage must be between 1 and 100"));
|
return Err(anyhow::anyhow!("Percentage must be between 1 and 100"));
|
||||||
}
|
}
|
||||||
let amount = amount_token * percent / 100;
|
let amount = amount_token * percent / 100;
|
||||||
self.sell(
|
self.sell(
|
||||||
|
dex_type,
|
||||||
mint,
|
mint,
|
||||||
creator,
|
creator,
|
||||||
amount,
|
amount,
|
||||||
@@ -443,8 +444,7 @@ impl SolanaTrade {
|
|||||||
recent_blockhash,
|
recent_blockhash,
|
||||||
custom_buy_tip_fee,
|
custom_buy_tip_fee,
|
||||||
with_tip,
|
with_tip,
|
||||||
protocol,
|
extension_params,
|
||||||
protocol_params,
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-7
@@ -20,7 +20,7 @@ use sol_trade_sdk::{
|
|||||||
},
|
},
|
||||||
swqos::{SwqosConfig, SwqosRegion},
|
swqos::{SwqosConfig, SwqosRegion},
|
||||||
trading::{
|
trading::{
|
||||||
core::params::PumpFunParams, factory::TradingProtocol,
|
core::params::PumpFunParams, factory::DexType,
|
||||||
pumpfun::common::get_bonding_curve_account_v2,
|
pumpfun::common::get_bonding_curve_account_v2,
|
||||||
},
|
},
|
||||||
SolanaTrade,
|
SolanaTrade,
|
||||||
@@ -105,6 +105,7 @@ async fn test_pumpfun() -> AnyResult<()> {
|
|||||||
// buy
|
// buy
|
||||||
solana_trade_client
|
solana_trade_client
|
||||||
.buy(
|
.buy(
|
||||||
|
DexType::PumpFun,
|
||||||
mint_pubkey,
|
mint_pubkey,
|
||||||
Some(creator),
|
Some(creator),
|
||||||
buy_sol_cost,
|
buy_sol_cost,
|
||||||
@@ -112,7 +113,6 @@ async fn test_pumpfun() -> AnyResult<()> {
|
|||||||
recent_blockhash,
|
recent_blockhash,
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
TradingProtocol::PumpFun,
|
|
||||||
Some(Box::new(PumpFunParams {
|
Some(Box::new(PumpFunParams {
|
||||||
bonding_curve: Some(Arc::new(bonding_curve.clone())),
|
bonding_curve: Some(Arc::new(bonding_curve.clone())),
|
||||||
})),
|
})),
|
||||||
@@ -123,6 +123,7 @@ async fn test_pumpfun() -> AnyResult<()> {
|
|||||||
let amount_token = 0; // 写上真实的amount_token
|
let amount_token = 0; // 写上真实的amount_token
|
||||||
solana_trade_client
|
solana_trade_client
|
||||||
.sell(
|
.sell(
|
||||||
|
DexType::PumpFun,
|
||||||
mint_pubkey,
|
mint_pubkey,
|
||||||
Some(creator),
|
Some(creator),
|
||||||
amount_token,
|
amount_token,
|
||||||
@@ -130,7 +131,6 @@ async fn test_pumpfun() -> AnyResult<()> {
|
|||||||
recent_blockhash,
|
recent_blockhash,
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
TradingProtocol::PumpFun,
|
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -151,6 +151,7 @@ async fn test_pumpswap() -> AnyResult<()> {
|
|||||||
// buy
|
// buy
|
||||||
solana_trade_client
|
solana_trade_client
|
||||||
.buy(
|
.buy(
|
||||||
|
DexType::PumpFun,
|
||||||
mint_pubkey,
|
mint_pubkey,
|
||||||
Some(creator),
|
Some(creator),
|
||||||
buy_sol_cost,
|
buy_sol_cost,
|
||||||
@@ -158,7 +159,6 @@ async fn test_pumpswap() -> AnyResult<()> {
|
|||||||
recent_blockhash,
|
recent_blockhash,
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
TradingProtocol::PumpSwap,
|
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -167,6 +167,7 @@ async fn test_pumpswap() -> AnyResult<()> {
|
|||||||
let amount_token = 0; // 写上真实的amount_token
|
let amount_token = 0; // 写上真实的amount_token
|
||||||
solana_trade_client
|
solana_trade_client
|
||||||
.sell(
|
.sell(
|
||||||
|
DexType::PumpSwap,
|
||||||
mint_pubkey,
|
mint_pubkey,
|
||||||
Some(creator),
|
Some(creator),
|
||||||
amount_token,
|
amount_token,
|
||||||
@@ -174,7 +175,6 @@ async fn test_pumpswap() -> AnyResult<()> {
|
|||||||
recent_blockhash,
|
recent_blockhash,
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
TradingProtocol::PumpSwap,
|
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -194,6 +194,7 @@ async fn test_bonk() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
// buy
|
// buy
|
||||||
solana_trade_client
|
solana_trade_client
|
||||||
.buy(
|
.buy(
|
||||||
|
DexType::Bonk,
|
||||||
mint_pubkey,
|
mint_pubkey,
|
||||||
None,
|
None,
|
||||||
buy_sol_cost,
|
buy_sol_cost,
|
||||||
@@ -201,7 +202,6 @@ async fn test_bonk() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
recent_blockhash,
|
recent_blockhash,
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
TradingProtocol::Bonk,
|
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -210,6 +210,7 @@ async fn test_bonk() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let amount_token = 0; // 写上真实的amount_token
|
let amount_token = 0; // 写上真实的amount_token
|
||||||
solana_trade_client
|
solana_trade_client
|
||||||
.sell(
|
.sell(
|
||||||
|
DexType::Bonk,
|
||||||
mint_pubkey,
|
mint_pubkey,
|
||||||
None,
|
None,
|
||||||
amount_token,
|
amount_token,
|
||||||
@@ -217,7 +218,6 @@ async fn test_bonk() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
recent_blockhash,
|
recent_blockhash,
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
TradingProtocol::Bonk,
|
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|||||||
+16
-20
@@ -9,30 +9,30 @@ use super::{
|
|||||||
|
|
||||||
/// 支持的交易协议
|
/// 支持的交易协议
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub enum TradingProtocol {
|
pub enum DexType {
|
||||||
PumpFun,
|
PumpFun,
|
||||||
PumpSwap,
|
PumpSwap,
|
||||||
Bonk,
|
Bonk,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for TradingProtocol {
|
impl std::fmt::Display for DexType {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
TradingProtocol::PumpFun => write!(f, "PumpFun"),
|
DexType::PumpFun => write!(f, "PumpFun"),
|
||||||
TradingProtocol::PumpSwap => write!(f, "PumpSwap"),
|
DexType::PumpSwap => write!(f, "PumpSwap"),
|
||||||
TradingProtocol::Bonk => write!(f, "Bonk"),
|
DexType::Bonk => write!(f, "Bonk"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::str::FromStr for TradingProtocol {
|
impl std::str::FromStr for DexType {
|
||||||
type Err = anyhow::Error;
|
type Err = anyhow::Error;
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
match s.to_lowercase().as_str() {
|
match s.to_lowercase().as_str() {
|
||||||
"pumpfun" => Ok(TradingProtocol::PumpFun),
|
"pumpfun" => Ok(DexType::PumpFun),
|
||||||
"pumpswap" => Ok(TradingProtocol::PumpSwap),
|
"pumpswap" => Ok(DexType::PumpSwap),
|
||||||
"bonk" => Ok(TradingProtocol::Bonk),
|
"bonk" => Ok(DexType::Bonk),
|
||||||
_ => Err(anyhow!("Unsupported protocol: {}", s)),
|
_ => Err(anyhow!("Unsupported protocol: {}", s)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -43,17 +43,17 @@ pub struct TradeFactory;
|
|||||||
|
|
||||||
impl TradeFactory {
|
impl TradeFactory {
|
||||||
/// 创建指定协议的交易执行器
|
/// 创建指定协议的交易执行器
|
||||||
pub fn create_executor(protocol: TradingProtocol) -> Arc<dyn TradeExecutor> {
|
pub fn create_executor(protocol: DexType) -> Arc<dyn TradeExecutor> {
|
||||||
match protocol {
|
match protocol {
|
||||||
TradingProtocol::PumpFun => {
|
DexType::PumpFun => {
|
||||||
let instruction_builder = Arc::new(PumpFunInstructionBuilder);
|
let instruction_builder = Arc::new(PumpFunInstructionBuilder);
|
||||||
Arc::new(GenericTradeExecutor::new(instruction_builder, "PumpFun"))
|
Arc::new(GenericTradeExecutor::new(instruction_builder, "PumpFun"))
|
||||||
}
|
}
|
||||||
TradingProtocol::PumpSwap => {
|
DexType::PumpSwap => {
|
||||||
let instruction_builder = Arc::new(PumpSwapInstructionBuilder);
|
let instruction_builder = Arc::new(PumpSwapInstructionBuilder);
|
||||||
Arc::new(GenericTradeExecutor::new(instruction_builder, "PumpSwap"))
|
Arc::new(GenericTradeExecutor::new(instruction_builder, "PumpSwap"))
|
||||||
}
|
}
|
||||||
TradingProtocol::Bonk => {
|
DexType::Bonk => {
|
||||||
let instruction_builder = Arc::new(BonkInstructionBuilder);
|
let instruction_builder = Arc::new(BonkInstructionBuilder);
|
||||||
Arc::new(GenericTradeExecutor::new(
|
Arc::new(GenericTradeExecutor::new(
|
||||||
instruction_builder,
|
instruction_builder,
|
||||||
@@ -64,16 +64,12 @@ impl TradeFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// 获取所有支持的协议
|
/// 获取所有支持的协议
|
||||||
pub fn supported_protocols() -> Vec<TradingProtocol> {
|
pub fn supported_protocols() -> Vec<DexType> {
|
||||||
vec![
|
vec![DexType::PumpFun, DexType::PumpSwap, DexType::Bonk]
|
||||||
TradingProtocol::PumpFun,
|
|
||||||
TradingProtocol::PumpSwap,
|
|
||||||
TradingProtocol::Bonk,
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 检查协议是否支持
|
/// 检查协议是否支持
|
||||||
pub fn is_supported(protocol: &TradingProtocol) -> bool {
|
pub fn is_supported(protocol: &DexType) -> bool {
|
||||||
Self::supported_protocols().contains(protocol)
|
Self::supported_protocols().contains(protocol)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user