The buy and sell methods support passing lookup_table_pubkey
This commit is contained in:
+20
-2
@@ -128,6 +128,7 @@ impl SolanaTrade {
|
||||
/// * `recent_blockhash` - Recent blockhash for transaction validity
|
||||
/// * `custom_buy_tip_fee` - Optional custom tip fee for priority processing (in SOL)
|
||||
/// * `extension_params` - Optional protocol-specific parameters (uses defaults if None)
|
||||
/// * `lookup_table_key` - Optional address lookup table key for transaction optimization
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
@@ -162,6 +163,7 @@ impl SolanaTrade {
|
||||
/// recent_blockhash,
|
||||
/// None,
|
||||
/// None,
|
||||
/// Some(lookup_table_pubkey),
|
||||
/// ).await?;
|
||||
/// ```
|
||||
pub async fn buy(
|
||||
@@ -174,6 +176,7 @@ impl SolanaTrade {
|
||||
recent_blockhash: Hash,
|
||||
custom_buy_tip_fee: Option<f64>,
|
||||
extension_params: Option<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 {
|
||||
@@ -188,6 +191,9 @@ impl SolanaTrade {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let final_lookup_table_key = lookup_table_key.or(self.trade_config.lookup_table_key);
|
||||
|
||||
let buy_params = BuyParams {
|
||||
rpc: Some(self.rpc.clone()),
|
||||
payer: self.payer.clone(),
|
||||
@@ -196,7 +202,7 @@ impl SolanaTrade {
|
||||
sol_amount: sol_amount,
|
||||
slippage_basis_points: slippage_basis_points,
|
||||
priority_fee: self.trade_config.priority_fee.clone(),
|
||||
lookup_table_key: self.trade_config.lookup_table_key,
|
||||
lookup_table_key: final_lookup_table_key,
|
||||
recent_blockhash,
|
||||
data_size_limit: 0,
|
||||
protocol_params: protocol_params.clone(),
|
||||
@@ -252,6 +258,7 @@ impl SolanaTrade {
|
||||
/// * `custom_buy_tip_fee` - Optional custom tip fee for priority processing (in SOL)
|
||||
/// * `with_tip` - Optional boolean to indicate if the transaction should be sent with tip
|
||||
/// * `extension_params` - Optional protocol-specific parameters (uses defaults if None)
|
||||
/// * `lookup_table_key` - Optional address lookup table key for transaction optimization
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
@@ -288,6 +295,7 @@ impl SolanaTrade {
|
||||
/// None,
|
||||
/// false,
|
||||
/// None,
|
||||
/// Some(lookup_table_pubkey),
|
||||
/// ).await?;
|
||||
/// ```
|
||||
pub async fn sell(
|
||||
@@ -301,6 +309,7 @@ impl SolanaTrade {
|
||||
custom_buy_tip_fee: Option<f64>,
|
||||
with_tip: bool,
|
||||
extension_params: Option<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 {
|
||||
@@ -315,6 +324,9 @@ impl SolanaTrade {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let final_lookup_table_key = lookup_table_key.or(self.trade_config.lookup_table_key);
|
||||
|
||||
let sell_params = SellParams {
|
||||
rpc: Some(self.rpc.clone()),
|
||||
payer: self.payer.clone(),
|
||||
@@ -323,7 +335,7 @@ impl SolanaTrade {
|
||||
token_amount: Some(token_amount),
|
||||
slippage_basis_points: slippage_basis_points,
|
||||
priority_fee: self.trade_config.priority_fee.clone(),
|
||||
lookup_table_key: self.trade_config.lookup_table_key,
|
||||
lookup_table_key: final_lookup_table_key,
|
||||
recent_blockhash,
|
||||
protocol_params: protocol_params.clone(),
|
||||
};
|
||||
@@ -385,7 +397,9 @@ impl SolanaTrade {
|
||||
/// * `slippage_basis_points` - Optional slippage tolerance in basis points (e.g., 100 = 1%)
|
||||
/// * `recent_blockhash` - Recent blockhash for transaction validity
|
||||
/// * `custom_buy_tip_fee` - Optional custom tip fee for priority processing (in SOL)
|
||||
/// * `with_tip` - Whether to use tip for priority processing
|
||||
/// * `extension_params` - Optional protocol-specific parameters (uses defaults if None)
|
||||
/// * `lookup_table_key` - Optional lookup table key for address lookup optimization
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
@@ -424,6 +438,8 @@ impl SolanaTrade {
|
||||
/// slippage,
|
||||
/// recent_blockhash,
|
||||
/// None,
|
||||
/// false,
|
||||
/// None,
|
||||
/// None,
|
||||
/// ).await?;
|
||||
/// ```
|
||||
@@ -439,6 +455,7 @@ impl SolanaTrade {
|
||||
custom_buy_tip_fee: Option<f64>,
|
||||
with_tip: bool,
|
||||
extension_params: Option<Box<dyn ProtocolParams>>,
|
||||
lookup_table_key: Option<Pubkey>,
|
||||
) -> Result<(), anyhow::Error> {
|
||||
if percent == 0 || percent > 100 {
|
||||
return Err(anyhow::anyhow!("Percentage must be between 1 and 100"));
|
||||
@@ -454,6 +471,7 @@ impl SolanaTrade {
|
||||
custom_buy_tip_fee,
|
||||
with_tip,
|
||||
extension_params,
|
||||
lookup_table_key,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
+14
@@ -98,6 +98,7 @@ async fn test_pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> Any
|
||||
Some(Box::new(PumpFunParams {
|
||||
bonding_curve: Some(Arc::new(bonding_curve.clone())),
|
||||
})),
|
||||
None,
|
||||
).await?;
|
||||
|
||||
// Sell tokens
|
||||
@@ -113,6 +114,7 @@ async fn test_pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> Any
|
||||
None,
|
||||
false,
|
||||
None,
|
||||
None,
|
||||
).await?;
|
||||
|
||||
Ok(())
|
||||
@@ -152,6 +154,7 @@ async fn test_pumpfun_sniper_trade_with_shreds(trade_info: PumpFunTradeEvent) ->
|
||||
Some(Box::new(PumpFunParams {
|
||||
bonding_curve: Some(Arc::new(bonding_curve.clone())),
|
||||
})),
|
||||
None,
|
||||
).await?;
|
||||
|
||||
// Sell tokens
|
||||
@@ -167,6 +170,7 @@ async fn test_pumpfun_sniper_trade_with_shreds(trade_info: PumpFunTradeEvent) ->
|
||||
None,
|
||||
false,
|
||||
None,
|
||||
None,
|
||||
).await?;
|
||||
|
||||
Ok(())
|
||||
@@ -205,6 +209,7 @@ async fn test_pumpswap() -> AnyResult<()> {
|
||||
pool_quote_token_reserves: Some(pool_quote_token_reserves),
|
||||
auto_handle_wsol: true,
|
||||
})),
|
||||
None,
|
||||
).await?;
|
||||
|
||||
// Sell tokens
|
||||
@@ -227,6 +232,7 @@ async fn test_pumpswap() -> AnyResult<()> {
|
||||
pool_quote_token_reserves: Some(pool_quote_token_reserves),
|
||||
auto_handle_wsol: true,
|
||||
})),
|
||||
None,
|
||||
).await?;
|
||||
|
||||
Ok(())
|
||||
@@ -254,6 +260,7 @@ async fn test_bonk_copy_trade_with_grpc(trade_info: BonkTradeEvent) -> AnyResult
|
||||
recent_blockhash,
|
||||
None,
|
||||
Some(Box::new(BonkParams::from_trade(trade_info))),
|
||||
None,
|
||||
).await?;
|
||||
|
||||
// Sell tokens
|
||||
@@ -269,6 +276,7 @@ async fn test_bonk_copy_trade_with_grpc(trade_info: BonkTradeEvent) -> AnyResult
|
||||
None,
|
||||
false,
|
||||
None,
|
||||
None,
|
||||
).await?;
|
||||
|
||||
Ok(())
|
||||
@@ -298,6 +306,7 @@ async fn test_bonk_sniper_trade_with_shreds(trade_info: BonkTradeEvent) -> AnyRe
|
||||
recent_blockhash,
|
||||
None,
|
||||
Some(Box::new(BonkParams::from_dev_trade(trade_info))),
|
||||
None,
|
||||
).await?;
|
||||
|
||||
// Sell tokens
|
||||
@@ -313,6 +322,7 @@ async fn test_bonk_sniper_trade_with_shreds(trade_info: BonkTradeEvent) -> AnyRe
|
||||
None,
|
||||
false,
|
||||
None,
|
||||
None,
|
||||
).await?;
|
||||
|
||||
Ok(())
|
||||
@@ -339,6 +349,7 @@ async fn test_bonk() -> Result<(), Box<dyn std::error::Error>> {
|
||||
recent_blockhash,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
).await?;
|
||||
|
||||
// Sell tokens
|
||||
@@ -354,6 +365,7 @@ async fn test_bonk() -> Result<(), Box<dyn std::error::Error>> {
|
||||
None,
|
||||
false,
|
||||
None,
|
||||
None,
|
||||
).await?;
|
||||
|
||||
Ok(())
|
||||
@@ -387,6 +399,7 @@ async fn test_raydium_cpmm() -> Result<(), Box<dyn std::error::Error>> {
|
||||
minimum_amount_out: Some(buy_amount_out), // 如果不传、默认为0
|
||||
auto_handle_wsol: true,
|
||||
})),
|
||||
None,
|
||||
).await?;
|
||||
|
||||
// Sell tokens
|
||||
@@ -409,6 +422,7 @@ async fn test_raydium_cpmm() -> Result<(), Box<dyn std::error::Error>> {
|
||||
minimum_amount_out: Some(sell_sol_amount), // 如果不传、默认为0
|
||||
auto_handle_wsol: true,
|
||||
})),
|
||||
None,
|
||||
).await?;
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user