Merge branch 'main' of github.com:0xfnzero/sol-trade-sdk

This commit is contained in:
Wood
2025-11-12 22:00:53 +08:00
25 changed files with 211 additions and 94 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "sol-trade-sdk" name = "sol-trade-sdk"
version = "3.2.1" version = "3.3.0"
edition = "2021" edition = "2021"
authors = [ authors = [
"William <byteblock6@gmail.com>", "William <byteblock6@gmail.com>",
+3 -3
View File
@@ -87,14 +87,14 @@ Add the dependency to your `Cargo.toml`:
```toml ```toml
# Add to your Cargo.toml # Add to your Cargo.toml
sol-trade-sdk = { path = "./sol-trade-sdk", version = "3.2.1" } sol-trade-sdk = { path = "./sol-trade-sdk", version = "3.3.0" }
``` ```
### Use crates.io ### Use crates.io
```toml ```toml
# Add to your Cargo.toml # Add to your Cargo.toml
sol-trade-sdk = "3.2.1" sol-trade-sdk = "3.3.0"
``` ```
## 🛠️ Usage Examples ## 🛠️ Usage Examples
@@ -146,7 +146,7 @@ For detailed information about Gas Fee Strategy, see the [Gas Fee Strategy Refer
// Create GasFeeStrategy instance // Create GasFeeStrategy instance
let gas_fee_strategy = GasFeeStrategy::new(); let gas_fee_strategy = GasFeeStrategy::new();
// Set global strategy // Set global strategy
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001); gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
``` ```
#### 3. Build Trading Parameters #### 3. Build Trading Parameters
+3 -3
View File
@@ -87,14 +87,14 @@ git clone https://github.com/0xfnzero/sol-trade-sdk
```toml ```toml
# 添加到您的 Cargo.toml # 添加到您的 Cargo.toml
sol-trade-sdk = { path = "./sol-trade-sdk", version = "3.2.1" } sol-trade-sdk = { path = "./sol-trade-sdk", version = "3.3.0" }
``` ```
### 使用 crates.io ### 使用 crates.io
```toml ```toml
# 添加到您的 Cargo.toml # 添加到您的 Cargo.toml
sol-trade-sdk = "3.2.1" sol-trade-sdk = "3.3.0"
``` ```
## 🛠️ 使用示例 ## 🛠️ 使用示例
@@ -146,7 +146,7 @@ let client = SolanaTrade::new(Arc::new(payer), trade_config).await;
// 创建 GasFeeStrategy 实例 // 创建 GasFeeStrategy 实例
let gas_fee_strategy = GasFeeStrategy::new(); let gas_fee_strategy = GasFeeStrategy::new();
// 设置全局策略 // 设置全局策略
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001); gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
``` ```
#### 3. 构建交易参数 #### 3. 构建交易参数
+2 -1
View File
@@ -125,7 +125,7 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
fetch_address_lookup_table_account(&client.rpc, &lookup_table_key).await.ok(); fetch_address_lookup_table_account(&client.rpc, &lookup_table_key).await.ok();
let gas_fee_strategy = GasFeeStrategy::new(); let gas_fee_strategy = GasFeeStrategy::new();
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001); gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
// Buy tokens // Buy tokens
println!("Buying tokens from PumpFun..."); println!("Buying tokens from PumpFun...");
@@ -148,6 +148,7 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
trade_info.real_token_reserves, trade_info.real_token_reserves,
trade_info.real_sol_reserves, trade_info.real_sol_reserves,
None, None,
trade_info.fee_recipient,
)), )),
address_lookup_table_account: address_lookup_table_account, address_lookup_table_account: address_lookup_table_account,
wait_transaction_confirmed: true, wait_transaction_confirmed: true,
+1 -1
View File
@@ -125,7 +125,7 @@ async fn bonk_copy_trade_with_grpc(trade_info: BonkTradeEvent) -> AnyResult<()>
let recent_blockhash = client.rpc.get_latest_blockhash().await?; let recent_blockhash = client.rpc.get_latest_blockhash().await?;
let gas_fee_strategy = GasFeeStrategy::new(); let gas_fee_strategy = GasFeeStrategy::new();
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001); gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
// Buy tokens // Buy tokens
println!("Buying tokens from Bonk..."); println!("Buying tokens from Bonk...");
+1 -1
View File
@@ -95,7 +95,7 @@ async fn bonk_sniper_trade_with_shreds(trade_info: BonkTradeEvent) -> AnyResult<
let recent_blockhash = client.rpc.get_latest_blockhash().await?; let recent_blockhash = client.rpc.get_latest_blockhash().await?;
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001); gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
let token_type = if trade_info.quote_token_mint == sol_trade_sdk::constants::USD1_TOKEN_ACCOUNT let token_type = if trade_info.quote_token_mint == sol_trade_sdk::constants::USD1_TOKEN_ACCOUNT
{ {
+10 -10
View File
@@ -615,7 +615,7 @@ async fn handle_buy_pumpfun(
let sol_lamports = sol_str_to_lamports(sol_amount.to_string().as_str()).unwrap(); let sol_lamports = sol_str_to_lamports(sol_amount.to_string().as_str()).unwrap();
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001); gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
let buy_params = TradeBuyParams { let buy_params = TradeBuyParams {
dex_type: DexType::PumpFun, dex_type: DexType::PumpFun,
@@ -669,7 +669,7 @@ async fn handle_buy_pumpswap(
let sol_lamports = sol_str_to_lamports(sol_amount.to_string().as_str()).unwrap(); let sol_lamports = sol_str_to_lamports(sol_amount.to_string().as_str()).unwrap();
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001); gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
let buy_params = TradeBuyParams { let buy_params = TradeBuyParams {
dex_type: DexType::PumpSwap, dex_type: DexType::PumpSwap,
@@ -722,7 +722,7 @@ async fn handle_buy_bonk(
let sol_lamports = sol_str_to_lamports(sol_amount.to_string().as_str()).unwrap(); let sol_lamports = sol_str_to_lamports(sol_amount.to_string().as_str()).unwrap();
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001); gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
let buy_params = TradeBuyParams { let buy_params = TradeBuyParams {
dex_type: DexType::Bonk, dex_type: DexType::Bonk,
@@ -779,7 +779,7 @@ async fn handle_buy_raydium_v4(
let sol_lamports = sol_str_to_lamports(sol_amount.to_string().as_str()).unwrap(); let sol_lamports = sol_str_to_lamports(sol_amount.to_string().as_str()).unwrap();
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001); gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
let buy_params = TradeBuyParams { let buy_params = TradeBuyParams {
dex_type: DexType::RaydiumAmmV4, dex_type: DexType::RaydiumAmmV4,
@@ -836,7 +836,7 @@ async fn handle_buy_raydium_cpmm(
let sol_lamports = sol_str_to_lamports(sol_amount.to_string().as_str()).unwrap(); let sol_lamports = sol_str_to_lamports(sol_amount.to_string().as_str()).unwrap();
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001); gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
let buy_params = TradeBuyParams { let buy_params = TradeBuyParams {
dex_type: DexType::RaydiumCpmm, dex_type: DexType::RaydiumCpmm,
@@ -1003,7 +1003,7 @@ async fn handle_sell_pumpfun(
let recent_blockhash = client.rpc.get_latest_blockhash().await?; let recent_blockhash = client.rpc.get_latest_blockhash().await?;
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001); gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
let sell_params = TradeSellParams { let sell_params = TradeSellParams {
dex_type: DexType::PumpFun, dex_type: DexType::PumpFun,
@@ -1061,7 +1061,7 @@ async fn handle_sell_pumpswap(
let recent_blockhash = client.rpc.get_latest_blockhash().await?; let recent_blockhash = client.rpc.get_latest_blockhash().await?;
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001); gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
let sell_params = TradeSellParams { let sell_params = TradeSellParams {
dex_type: DexType::PumpSwap, dex_type: DexType::PumpSwap,
@@ -1118,7 +1118,7 @@ async fn handle_sell_bonk(
let recent_blockhash = client.rpc.get_latest_blockhash().await?; let recent_blockhash = client.rpc.get_latest_blockhash().await?;
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001); gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
let sell_params = TradeSellParams { let sell_params = TradeSellParams {
dex_type: DexType::Bonk, dex_type: DexType::Bonk,
@@ -1178,7 +1178,7 @@ async fn handle_sell_raydium_v4(
let recent_blockhash = client.rpc.get_latest_blockhash().await?; let recent_blockhash = client.rpc.get_latest_blockhash().await?;
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001); gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
let sell_params = TradeSellParams { let sell_params = TradeSellParams {
dex_type: DexType::RaydiumAmmV4, dex_type: DexType::RaydiumAmmV4,
@@ -1238,7 +1238,7 @@ async fn handle_sell_raydium_cpmm(
let recent_blockhash = client.rpc.get_latest_blockhash().await?; let recent_blockhash = client.rpc.get_latest_blockhash().await?;
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001); gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
let sell_params = TradeSellParams { let sell_params = TradeSellParams {
dex_type: DexType::RaydiumCpmm, dex_type: DexType::RaydiumCpmm,
+6 -1
View File
@@ -12,7 +12,7 @@ async fn main() {
// Set global strategy // Set global strategy
println!("1. Set global strategy"); println!("1. Set global strategy");
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001); gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
// Print all strategies // Print all strategies
println!("\n2. Print all strategies"); println!("\n2. Print all strategies");
@@ -30,6 +30,8 @@ async fn main() {
500000, // cu_price 500000, // cu_price
0.0, // buy_tip 0.0, // buy_tip
0.0, // sell_tip 0.0, // sell_tip
256 * 1024,
0,
); );
// Add high-low fee strategy for SwqosType::Jito on Buy // Add high-low fee strategy for SwqosType::Jito on Buy
@@ -42,6 +44,7 @@ async fn main() {
10 * 1_000_000, // high cu_price 10 * 1_000_000, // high cu_price
0.001, // low tip 0.001, // low tip
0.1, // high tip 0.1, // high tip
0,
); );
// Print all strategies // Print all strategies
@@ -56,6 +59,8 @@ async fn main() {
500000, // cu_price 500000, // cu_price
0.0001, // buy_tip 0.0001, // buy_tip
0.0001, // sell_tip 0.0001, // sell_tip
256 * 1024,
0,
); );
// Print all strategies // Print all strategies
@@ -23,7 +23,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mint_pubkey = Pubkey::from_str("PRVT6TB7uss3FrUd2D9xs2zqDBsa3GbMJMwCQsgmeta").unwrap(); let mint_pubkey = Pubkey::from_str("PRVT6TB7uss3FrUd2D9xs2zqDBsa3GbMJMwCQsgmeta").unwrap();
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001); gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
// Buy tokens // Buy tokens
println!("Buying tokens from Metaora Damm V2..."); println!("Buying tokens from Metaora Damm V2...");
+1 -1
View File
@@ -81,7 +81,7 @@ async fn test_middleware() -> AnyResult<()> {
let pool_address = Pubkey::from_str("539m4mVWt6iduB6W8rDGPMarzNCMesuqY5eUTiiYHAgR")?; let pool_address = Pubkey::from_str("539m4mVWt6iduB6W8rDGPMarzNCMesuqY5eUTiiYHAgR")?;
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001); gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
let buy_params = sol_trade_sdk::TradeBuyParams { let buy_params = sol_trade_sdk::TradeBuyParams {
dex_type: DexType::PumpSwap, dex_type: DexType::PumpSwap,
+2 -1
View File
@@ -125,7 +125,7 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
let durable_nonce = fetch_nonce_info(&client.rpc, nonce_account_str).await; let durable_nonce = fetch_nonce_info(&client.rpc, nonce_account_str).await;
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001); gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
// Buy tokens // Buy tokens
println!("Buying tokens from PumpFun..."); println!("Buying tokens from PumpFun...");
@@ -148,6 +148,7 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
trade_info.real_token_reserves, trade_info.real_token_reserves,
trade_info.real_sol_reserves, trade_info.real_sol_reserves,
None, None,
trade_info.fee_recipient,
)), )),
address_lookup_table_account: None, address_lookup_table_account: None,
wait_transaction_confirmed: true, wait_transaction_confirmed: true,
+3 -1
View File
@@ -121,7 +121,7 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
let recent_blockhash = client.rpc.get_latest_blockhash().await?; let recent_blockhash = client.rpc.get_latest_blockhash().await?;
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001); gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
// Buy tokens // Buy tokens
println!("Buying tokens from PumpFun..."); println!("Buying tokens from PumpFun...");
@@ -144,6 +144,7 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
trade_info.real_token_reserves, trade_info.real_token_reserves,
trade_info.real_sol_reserves, trade_info.real_sol_reserves,
None, None,
trade_info.fee_recipient,
)), )),
address_lookup_table_account: None, address_lookup_table_account: None,
wait_transaction_confirmed: true, wait_transaction_confirmed: true,
@@ -187,6 +188,7 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
trade_info.real_token_reserves, trade_info.real_token_reserves,
trade_info.real_sol_reserves, trade_info.real_sol_reserves,
Some(true), Some(true),
trade_info.fee_recipient,
)), )),
address_lookup_table_account: None, address_lookup_table_account: None,
wait_transaction_confirmed: true, wait_transaction_confirmed: true,
+2 -1
View File
@@ -89,7 +89,7 @@ async fn pumpfun_sniper_trade_with_shreds(trade_info: PumpFunTradeEvent) -> AnyR
let recent_blockhash = client.rpc.get_latest_blockhash().await?; let recent_blockhash = client.rpc.get_latest_blockhash().await?;
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001); gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
// Buy tokens // Buy tokens
println!("Buying tokens from PumpFun..."); println!("Buying tokens from PumpFun...");
@@ -110,6 +110,7 @@ async fn pumpfun_sniper_trade_with_shreds(trade_info: PumpFunTradeEvent) -> AnyR
trade_info.associated_bonding_curve, trade_info.associated_bonding_curve,
trade_info.creator_vault, trade_info.creator_vault,
None, None,
trade_info.fee_recipient,
)), )),
address_lookup_table_account: None, address_lookup_table_account: None,
wait_transaction_confirmed: true, wait_transaction_confirmed: true,
+1 -1
View File
@@ -23,7 +23,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mint_pubkey = Pubkey::from_str("pumpCmXqMfrsAkQ5r49WcJnRayYRqmXz6ae8H7H9Dfn").unwrap(); let mint_pubkey = Pubkey::from_str("pumpCmXqMfrsAkQ5r49WcJnRayYRqmXz6ae8H7H9Dfn").unwrap();
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001); gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
// Buy tokens // Buy tokens
println!("Buying tokens from PumpSwap..."); println!("Buying tokens from PumpSwap...");
+7 -3
View File
@@ -148,9 +148,11 @@ async fn pumpswap_trade_with_grpc_buy_event(trade_info: PumpSwapBuyEvent) -> Any
trade_info.coin_creator_vault_authority, trade_info.coin_creator_vault_authority,
trade_info.base_token_program, trade_info.base_token_program,
trade_info.quote_token_program, trade_info.quote_token_program,
trade_info.protocol_fee_recipient,
); );
let mint = if trade_info.base_mint == sol_trade_sdk::constants::USDC_TOKEN_ACCOUNT let mint = if trade_info.base_mint == sol_trade_sdk::constants::USDC_TOKEN_ACCOUNT
|| trade_info.base_mint == sol_trade_sdk::constants::WSOL_TOKEN_ACCOUNT { || trade_info.base_mint == sol_trade_sdk::constants::WSOL_TOKEN_ACCOUNT
{
trade_info.quote_mint trade_info.quote_mint
} else { } else {
trade_info.base_mint trade_info.base_mint
@@ -172,9 +174,11 @@ async fn pumpswap_trade_with_grpc_sell_event(trade_info: PumpSwapSellEvent) -> A
trade_info.coin_creator_vault_authority, trade_info.coin_creator_vault_authority,
trade_info.base_token_program, trade_info.base_token_program,
trade_info.quote_token_program, trade_info.quote_token_program,
trade_info.protocol_fee_recipient,
); );
let mint = if trade_info.base_mint == sol_trade_sdk::constants::USDC_TOKEN_ACCOUNT let mint = if trade_info.base_mint == sol_trade_sdk::constants::USDC_TOKEN_ACCOUNT
|| trade_info.base_mint == sol_trade_sdk::constants::WSOL_TOKEN_ACCOUNT { || trade_info.base_mint == sol_trade_sdk::constants::WSOL_TOKEN_ACCOUNT
{
trade_info.quote_mint trade_info.quote_mint
} else { } else {
trade_info.base_mint trade_info.base_mint
@@ -191,7 +195,7 @@ async fn pumpswap_trade_with_grpc(mint_pubkey: Pubkey, params: PumpSwapParams) -
let recent_blockhash = client.rpc.get_latest_blockhash().await?; let recent_blockhash = client.rpc.get_latest_blockhash().await?;
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001); gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
let is_sol = params.base_mint == sol_trade_sdk::constants::WSOL_TOKEN_ACCOUNT let is_sol = params.base_mint == sol_trade_sdk::constants::WSOL_TOKEN_ACCOUNT
|| params.quote_mint == sol_trade_sdk::constants::WSOL_TOKEN_ACCOUNT; || params.quote_mint == sol_trade_sdk::constants::WSOL_TOKEN_ACCOUNT;
+1 -1
View File
@@ -140,7 +140,7 @@ async fn raydium_amm_v4_copy_trade_with_grpc(trade_info: RaydiumAmmV4SwapEvent)
); );
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001); gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
// Buy tokens // Buy tokens
println!("Buying tokens from Raydium_amm_v4..."); println!("Buying tokens from Raydium_amm_v4...");
+1 -1
View File
@@ -130,7 +130,7 @@ async fn raydium_cpmm_copy_trade_with_grpc(trade_info: RaydiumCpmmSwapEvent) ->
let recent_blockhash = client.rpc.get_latest_blockhash().await?; let recent_blockhash = client.rpc.get_latest_blockhash().await?;
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001); gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
let buy_params = let buy_params =
RaydiumCpmmParams::from_pool_address_by_rpc(&client.rpc, &trade_info.pool_state).await?; RaydiumCpmmParams::from_pool_address_by_rpc(&client.rpc, &trade_info.pool_state).await?;
+1 -1
View File
@@ -22,7 +22,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mint_pubkey = Pubkey::from_str("2zMMhcVQEXDtdE6vsFS7S7D5oUodfJHE8vd1gnBouauv").unwrap(); let mint_pubkey = Pubkey::from_str("2zMMhcVQEXDtdE6vsFS7S7D5oUodfJHE8vd1gnBouauv").unwrap();
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001); gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
// Buy tokens // Buy tokens
println!("Buying tokens from PumpSwap..."); println!("Buying tokens from PumpSwap...");
+6
View File
@@ -58,6 +58,8 @@ pub struct BondingCurveAccount {
pub complete: bool, pub complete: bool,
/// Creator of the bonding curve /// Creator of the bonding curve
pub creator: Pubkey, pub creator: Pubkey,
/// Whether this is a mayhem mode token (Token2022)
pub is_mayhem_mode: bool,
} }
impl BondingCurveAccount { impl BondingCurveAccount {
@@ -67,6 +69,7 @@ impl BondingCurveAccount {
dev_token_amount: u64, dev_token_amount: u64,
dev_sol_amount: u64, dev_sol_amount: u64,
creator: Pubkey, creator: Pubkey,
is_mayhem_mode: bool,
) -> Self { ) -> Self {
let account = if bonding_curve != Pubkey::default() { let account = if bonding_curve != Pubkey::default() {
bonding_curve bonding_curve
@@ -83,6 +86,7 @@ impl BondingCurveAccount {
token_total_supply: TOKEN_TOTAL_SUPPLY, token_total_supply: TOKEN_TOTAL_SUPPLY,
complete: false, complete: false,
creator: creator, creator: creator,
is_mayhem_mode: is_mayhem_mode,
} }
} }
@@ -94,6 +98,7 @@ impl BondingCurveAccount {
virtual_sol_reserves: u64, virtual_sol_reserves: u64,
real_token_reserves: u64, real_token_reserves: u64,
real_sol_reserves: u64, real_sol_reserves: u64,
is_mayhem_mode: bool,
) -> Self { ) -> Self {
let account = if bonding_curve != Pubkey::default() { let account = if bonding_curve != Pubkey::default() {
bonding_curve bonding_curve
@@ -110,6 +115,7 @@ impl BondingCurveAccount {
token_total_supply: TOKEN_TOTAL_SUPPLY, token_total_supply: TOKEN_TOTAL_SUPPLY,
complete: false, complete: false,
creator: creator, creator: creator,
is_mayhem_mode: is_mayhem_mode,
} }
} }
+53 -11
View File
@@ -68,12 +68,25 @@ impl InstructionBuilder for PumpFunInstructionBuilder {
bonding_curve.account bonding_curve.account
}; };
// Determine token program based on mayhem mode
let is_mayhem_mode = bonding_curve.is_mayhem_mode;
let token_program = if is_mayhem_mode {
crate::constants::TOKEN_PROGRAM_2022
} else {
crate::constants::TOKEN_PROGRAM
};
let token_program_meta = if is_mayhem_mode {
crate::constants::TOKEN_PROGRAM_2022_META
} else {
crate::constants::TOKEN_PROGRAM_META
};
let associated_bonding_curve = let associated_bonding_curve =
if protocol_params.associated_bonding_curve == Pubkey::default() { if protocol_params.associated_bonding_curve == Pubkey::default() {
crate::common::fast_fn::get_associated_token_address_with_program_id_fast( crate::common::fast_fn::get_associated_token_address_with_program_id_fast(
&bonding_curve_addr, &bonding_curve_addr,
&params.output_mint, &params.output_mint,
&crate::constants::TOKEN_PROGRAM, &token_program,
) )
} else { } else {
protocol_params.associated_bonding_curve protocol_params.associated_bonding_curve
@@ -83,7 +96,7 @@ impl InstructionBuilder for PumpFunInstructionBuilder {
crate::common::fast_fn::get_associated_token_address_with_program_id_fast_use_seed( crate::common::fast_fn::get_associated_token_address_with_program_id_fast_use_seed(
&params.payer.pubkey(), &params.payer.pubkey(),
&params.output_mint, &params.output_mint,
&crate::constants::TOKEN_PROGRAM, &token_program,
params.open_seed_optimize, params.open_seed_optimize,
); );
@@ -102,7 +115,7 @@ impl InstructionBuilder for PumpFunInstructionBuilder {
&params.payer.pubkey(), &params.payer.pubkey(),
&params.payer.pubkey(), &params.payer.pubkey(),
&params.output_mint, &params.output_mint,
&crate::constants::TOKEN_PROGRAM, &token_program,
params.open_seed_optimize, params.open_seed_optimize,
), ),
); );
@@ -113,16 +126,23 @@ impl InstructionBuilder for PumpFunInstructionBuilder {
buy_data[8..16].copy_from_slice(&buy_token_amount.to_le_bytes()); buy_data[8..16].copy_from_slice(&buy_token_amount.to_le_bytes());
buy_data[16..24].copy_from_slice(&max_sol_cost.to_le_bytes()); buy_data[16..24].copy_from_slice(&max_sol_cost.to_le_bytes());
// Determine fee recipient based on mayhem mode
let fee_recipient_meta = if is_mayhem_mode {
global_constants::MAYHEM_FEE_RECIPIENT_META
} else {
global_constants::FEE_RECIPIENT_META
};
let accounts: [AccountMeta; 16] = [ let accounts: [AccountMeta; 16] = [
global_constants::GLOBAL_ACCOUNT_META, global_constants::GLOBAL_ACCOUNT_META,
global_constants::FEE_RECIPIENT_META, fee_recipient_meta,
AccountMeta::new_readonly(params.output_mint, false), AccountMeta::new_readonly(params.output_mint, false),
AccountMeta::new(bonding_curve_addr, false), AccountMeta::new(bonding_curve_addr, false),
AccountMeta::new(associated_bonding_curve, false), AccountMeta::new(associated_bonding_curve, false),
AccountMeta::new(user_token_account, false), AccountMeta::new(user_token_account, false),
AccountMeta::new(params.payer.pubkey(), true), AccountMeta::new(params.payer.pubkey(), true),
crate::constants::SYSTEM_PROGRAM_META, crate::constants::SYSTEM_PROGRAM_META,
crate::constants::TOKEN_PROGRAM_META, token_program_meta,
AccountMeta::new(creator_vault_pda, false), AccountMeta::new(creator_vault_pda, false),
accounts::EVENT_AUTHORITY_META, accounts::EVENT_AUTHORITY_META,
accounts::PUMPFUN_META, accounts::PUMPFUN_META,
@@ -188,12 +208,25 @@ impl InstructionBuilder for PumpFunInstructionBuilder {
bonding_curve.account bonding_curve.account
}; };
// Determine token program based on mayhem mode
let is_mayhem_mode = bonding_curve.is_mayhem_mode;
let token_program = if is_mayhem_mode {
crate::constants::TOKEN_PROGRAM_2022
} else {
crate::constants::TOKEN_PROGRAM
};
let token_program_meta = if is_mayhem_mode {
crate::constants::TOKEN_PROGRAM_2022_META
} else {
crate::constants::TOKEN_PROGRAM_META
};
let associated_bonding_curve = let associated_bonding_curve =
if protocol_params.associated_bonding_curve == Pubkey::default() { if protocol_params.associated_bonding_curve == Pubkey::default() {
crate::common::fast_fn::get_associated_token_address_with_program_id_fast( crate::common::fast_fn::get_associated_token_address_with_program_id_fast(
&bonding_curve_addr, &bonding_curve_addr,
&params.input_mint, &params.input_mint,
&crate::constants::TOKEN_PROGRAM, &token_program,
) )
} else { } else {
protocol_params.associated_bonding_curve protocol_params.associated_bonding_curve
@@ -203,7 +236,7 @@ impl InstructionBuilder for PumpFunInstructionBuilder {
crate::common::fast_fn::get_associated_token_address_with_program_id_fast_use_seed( crate::common::fast_fn::get_associated_token_address_with_program_id_fast_use_seed(
&params.payer.pubkey(), &params.payer.pubkey(),
&params.input_mint, &params.input_mint,
&crate::constants::TOKEN_PROGRAM, &token_program,
params.open_seed_optimize, params.open_seed_optimize,
); );
@@ -217,9 +250,16 @@ impl InstructionBuilder for PumpFunInstructionBuilder {
sell_data[8..16].copy_from_slice(&token_amount.to_le_bytes()); sell_data[8..16].copy_from_slice(&token_amount.to_le_bytes());
sell_data[16..24].copy_from_slice(&min_sol_output.to_le_bytes()); sell_data[16..24].copy_from_slice(&min_sol_output.to_le_bytes());
// Determine fee recipient based on mayhem mode
let fee_recipient_meta = if is_mayhem_mode {
global_constants::MAYHEM_FEE_RECIPIENT_META
} else {
global_constants::FEE_RECIPIENT_META
};
let accounts: [AccountMeta; 14] = [ let accounts: [AccountMeta; 14] = [
global_constants::GLOBAL_ACCOUNT_META, global_constants::GLOBAL_ACCOUNT_META,
global_constants::FEE_RECIPIENT_META, fee_recipient_meta,
AccountMeta::new_readonly(params.input_mint, false), AccountMeta::new_readonly(params.input_mint, false),
AccountMeta::new(bonding_curve_addr, false), AccountMeta::new(bonding_curve_addr, false),
AccountMeta::new(associated_bonding_curve, false), AccountMeta::new(associated_bonding_curve, false),
@@ -227,7 +267,7 @@ impl InstructionBuilder for PumpFunInstructionBuilder {
AccountMeta::new(params.payer.pubkey(), true), AccountMeta::new(params.payer.pubkey(), true),
crate::constants::SYSTEM_PROGRAM_META, crate::constants::SYSTEM_PROGRAM_META,
AccountMeta::new(creator_vault_pda, false), AccountMeta::new(creator_vault_pda, false),
crate::constants::TOKEN_PROGRAM_META, token_program_meta,
accounts::EVENT_AUTHORITY_META, accounts::EVENT_AUTHORITY_META,
accounts::PUMPFUN_META, accounts::PUMPFUN_META,
accounts::FEE_CONFIG_META, accounts::FEE_CONFIG_META,
@@ -241,9 +281,11 @@ impl InstructionBuilder for PumpFunInstructionBuilder {
)); ));
// Optional: Close token account // Optional: Close token account
if protocol_params.close_token_account_when_sell.unwrap_or(false) || params.close_input_mint_ata { if protocol_params.close_token_account_when_sell.unwrap_or(false)
|| params.close_input_mint_ata
{
instructions.push(close_account( instructions.push(close_account(
&crate::constants::TOKEN_PROGRAM, &token_program,
&user_token_account, &user_token_account,
&params.payer.pubkey(), &params.payer.pubkey(),
&params.payer.pubkey(), &params.payer.pubkey(),
+63 -39
View File
@@ -53,10 +53,14 @@ impl InstructionBuilder for PumpSwapInstructionBuilder {
let pool_base_token_account = protocol_params.pool_base_token_account; let pool_base_token_account = protocol_params.pool_base_token_account;
let pool_quote_token_account = protocol_params.pool_quote_token_account; let pool_quote_token_account = protocol_params.pool_quote_token_account;
let is_wsol = (base_mint == crate::constants::WSOL_TOKEN_ACCOUNT && quote_mint != crate::constants::USDC_TOKEN_ACCOUNT) let is_wsol = (base_mint == crate::constants::WSOL_TOKEN_ACCOUNT
|| (quote_mint == crate::constants::WSOL_TOKEN_ACCOUNT && base_mint != crate::constants::USDC_TOKEN_ACCOUNT); && quote_mint != crate::constants::USDC_TOKEN_ACCOUNT)
let is_usdc = (base_mint == crate::constants::USDC_TOKEN_ACCOUNT && quote_mint != crate::constants::WSOL_TOKEN_ACCOUNT) || (quote_mint == crate::constants::WSOL_TOKEN_ACCOUNT
|| (quote_mint == crate::constants::USDC_TOKEN_ACCOUNT && base_mint != crate::constants::WSOL_TOKEN_ACCOUNT); && base_mint != crate::constants::USDC_TOKEN_ACCOUNT);
let is_usdc = (base_mint == crate::constants::USDC_TOKEN_ACCOUNT
&& quote_mint != crate::constants::WSOL_TOKEN_ACCOUNT)
|| (quote_mint == crate::constants::USDC_TOKEN_ACCOUNT
&& base_mint != crate::constants::WSOL_TOKEN_ACCOUNT);
if !is_wsol && !is_usdc { if !is_wsol && !is_usdc {
return Err(anyhow!("Pool must contain WSOL or USDC")); return Err(anyhow!("Pool must contain WSOL or USDC"));
} }
@@ -113,7 +117,17 @@ impl InstructionBuilder for PumpSwapInstructionBuilder {
&quote_token_program, &quote_token_program,
params.open_seed_optimize, params.open_seed_optimize,
); );
let fee_recipient_ata = fee_recipient_ata(accounts::FEE_RECIPIENT, quote_mint);
// Determine fee recipient based on mayhem mode
let is_mayhem_mode = protocol_params.is_mayhem_mode;
let fee_recipient =
if is_mayhem_mode { accounts::MAYHEM_FEE_RECIPIENT } else { accounts::FEE_RECIPIENT };
let fee_recipient_meta = if is_mayhem_mode {
accounts::MAYHEM_FEE_RECIPIENT_META
} else {
accounts::FEE_RECIPIENT_META
};
let fee_recipient_ata = fee_recipient_ata(fee_recipient, quote_mint);
// ======================================== // ========================================
// Build instructions // Build instructions
@@ -140,18 +154,18 @@ impl InstructionBuilder for PumpSwapInstructionBuilder {
// Create buy instruction // Create buy instruction
let mut accounts = Vec::with_capacity(23); let mut accounts = Vec::with_capacity(23);
accounts.extend([ accounts.extend([
AccountMeta::new(pool, false), // pool_id AccountMeta::new(pool, false), // pool_id
AccountMeta::new(params.payer.pubkey(), true), // user (signer) AccountMeta::new(params.payer.pubkey(), true), // user (signer)
accounts::GLOBAL_ACCOUNT_META, // global (readonly) accounts::GLOBAL_ACCOUNT_META, // global (readonly)
AccountMeta::new_readonly(base_mint, false), // base_mint (readonly) AccountMeta::new_readonly(base_mint, false), // base_mint (readonly)
AccountMeta::new_readonly(quote_mint, false), // quote_mint (readonly) AccountMeta::new_readonly(quote_mint, false), // quote_mint (readonly)
AccountMeta::new(user_base_token_account, false), // user_base_token_account AccountMeta::new(user_base_token_account, false), // user_base_token_account
AccountMeta::new(user_quote_token_account, false), // user_quote_token_account AccountMeta::new(user_quote_token_account, false), // user_quote_token_account
AccountMeta::new(pool_base_token_account, false), // pool_base_token_account AccountMeta::new(pool_base_token_account, false), // pool_base_token_account
AccountMeta::new(pool_quote_token_account, false), // pool_quote_token_account AccountMeta::new(pool_quote_token_account, false), // pool_quote_token_account
accounts::FEE_RECIPIENT_META, // fee_recipient (readonly) fee_recipient_meta, // fee_recipient (readonly)
AccountMeta::new(fee_recipient_ata, false), // fee_recipient_ata AccountMeta::new(fee_recipient_ata, false), // fee_recipient_ata
AccountMeta::new_readonly(base_token_program, false), // TOKEN_PROGRAM_ID (readonly) AccountMeta::new_readonly(base_token_program, false), // TOKEN_PROGRAM_ID (readonly)
AccountMeta::new_readonly(quote_token_program, false), // TOKEN_PROGRAM_ID (readonly, duplicated as in JS) AccountMeta::new_readonly(quote_token_program, false), // TOKEN_PROGRAM_ID (readonly, duplicated as in JS)
crate::constants::SYSTEM_PROGRAM_META, // System Program (readonly) crate::constants::SYSTEM_PROGRAM_META, // System Program (readonly)
accounts::ASSOCIATED_TOKEN_PROGRAM_META, // ASSOCIATED_TOKEN_PROGRAM_ID (readonly) accounts::ASSOCIATED_TOKEN_PROGRAM_META, // ASSOCIATED_TOKEN_PROGRAM_ID (readonly)
@@ -222,10 +236,14 @@ impl InstructionBuilder for PumpSwapInstructionBuilder {
let base_token_program = protocol_params.base_token_program; let base_token_program = protocol_params.base_token_program;
let quote_token_program = protocol_params.quote_token_program; let quote_token_program = protocol_params.quote_token_program;
let is_wsol = (base_mint == crate::constants::WSOL_TOKEN_ACCOUNT && quote_mint != crate::constants::USDC_TOKEN_ACCOUNT) let is_wsol = (base_mint == crate::constants::WSOL_TOKEN_ACCOUNT
|| (quote_mint == crate::constants::WSOL_TOKEN_ACCOUNT && base_mint != crate::constants::USDC_TOKEN_ACCOUNT); && quote_mint != crate::constants::USDC_TOKEN_ACCOUNT)
let is_usdc = (base_mint == crate::constants::USDC_TOKEN_ACCOUNT && quote_mint != crate::constants::WSOL_TOKEN_ACCOUNT) || (quote_mint == crate::constants::WSOL_TOKEN_ACCOUNT
|| (quote_mint == crate::constants::USDC_TOKEN_ACCOUNT && base_mint != crate::constants::WSOL_TOKEN_ACCOUNT); && base_mint != crate::constants::USDC_TOKEN_ACCOUNT);
let is_usdc = (base_mint == crate::constants::USDC_TOKEN_ACCOUNT
&& quote_mint != crate::constants::WSOL_TOKEN_ACCOUNT)
|| (quote_mint == crate::constants::USDC_TOKEN_ACCOUNT
&& base_mint != crate::constants::WSOL_TOKEN_ACCOUNT);
if !is_wsol && !is_usdc { if !is_wsol && !is_usdc {
return Err(anyhow!("Pool must contain WSOL or USDC")); return Err(anyhow!("Pool must contain WSOL or USDC"));
} }
@@ -272,7 +290,17 @@ impl InstructionBuilder for PumpSwapInstructionBuilder {
sol_amount = params.fixed_output_amount.unwrap(); sol_amount = params.fixed_output_amount.unwrap();
} }
let fee_recipient_ata = fee_recipient_ata(accounts::FEE_RECIPIENT, quote_mint); // Determine fee recipient based on mayhem mode
let is_mayhem_mode = protocol_params.is_mayhem_mode;
let fee_recipient =
if is_mayhem_mode { accounts::MAYHEM_FEE_RECIPIENT } else { accounts::FEE_RECIPIENT };
let fee_recipient_meta = if is_mayhem_mode {
accounts::MAYHEM_FEE_RECIPIENT_META
} else {
accounts::FEE_RECIPIENT_META
};
let fee_recipient_ata = fee_recipient_ata(fee_recipient, quote_mint);
let user_base_token_account = let user_base_token_account =
crate::common::fast_fn::get_associated_token_address_with_program_id_fast_use_seed( crate::common::fast_fn::get_associated_token_address_with_program_id_fast_use_seed(
&params.payer.pubkey(), &params.payer.pubkey(),
@@ -300,18 +328,18 @@ impl InstructionBuilder for PumpSwapInstructionBuilder {
// Create sell instruction // Create sell instruction
let mut accounts = Vec::with_capacity(23); let mut accounts = Vec::with_capacity(23);
accounts.extend([ accounts.extend([
AccountMeta::new(pool, false), // pool_id AccountMeta::new(pool, false), // pool_id
AccountMeta::new(params.payer.pubkey(), true), // user (signer) AccountMeta::new(params.payer.pubkey(), true), // user (signer)
accounts::GLOBAL_ACCOUNT_META, // global (readonly) accounts::GLOBAL_ACCOUNT_META, // global (readonly)
AccountMeta::new_readonly(base_mint, false), // mint (readonly) AccountMeta::new_readonly(base_mint, false), // mint (readonly)
AccountMeta::new_readonly(quote_mint, false), // WSOL_TOKEN_ACCOUNT (readonly) AccountMeta::new_readonly(quote_mint, false), // WSOL_TOKEN_ACCOUNT (readonly)
AccountMeta::new(user_base_token_account, false), // user_base_token_account AccountMeta::new(user_base_token_account, false), // user_base_token_account
AccountMeta::new(user_quote_token_account, false), // user_quote_token_account AccountMeta::new(user_quote_token_account, false), // user_quote_token_account
AccountMeta::new(pool_base_token_account, false), // pool_base_token_account AccountMeta::new(pool_base_token_account, false), // pool_base_token_account
AccountMeta::new(pool_quote_token_account, false), // pool_quote_token_account AccountMeta::new(pool_quote_token_account, false), // pool_quote_token_account
accounts::FEE_RECIPIENT_META, // fee_recipient (readonly) fee_recipient_meta, // fee_recipient (readonly)
AccountMeta::new(fee_recipient_ata, false), // fee_recipient_ata AccountMeta::new(fee_recipient_ata, false), // fee_recipient_ata
AccountMeta::new_readonly(base_token_program, false), // TOKEN_PROGRAM_ID (readonly) AccountMeta::new_readonly(base_token_program, false), // TOKEN_PROGRAM_ID (readonly)
AccountMeta::new_readonly(quote_token_program, false), // TOKEN_PROGRAM_ID (readonly, duplicated as in JS) AccountMeta::new_readonly(quote_token_program, false), // TOKEN_PROGRAM_ID (readonly, duplicated as in JS)
crate::constants::SYSTEM_PROGRAM_META, // System Program (readonly) crate::constants::SYSTEM_PROGRAM_META, // System Program (readonly)
accounts::ASSOCIATED_TOKEN_PROGRAM_META, // ASSOCIATED_TOKEN_PROGRAM_ID (readonly) accounts::ASSOCIATED_TOKEN_PROGRAM_META, // ASSOCIATED_TOKEN_PROGRAM_ID (readonly)
@@ -358,11 +386,7 @@ impl InstructionBuilder for PumpSwapInstructionBuilder {
} }
if params.close_input_mint_ata { if params.close_input_mint_ata {
instructions.push(crate::common::spl_token::close_account( instructions.push(crate::common::spl_token::close_account(
if quote_is_wsol_or_usdc { if quote_is_wsol_or_usdc { &base_token_program } else { &quote_token_program },
&base_token_program
} else {
&quote_token_program
},
if quote_is_wsol_or_usdc { if quote_is_wsol_or_usdc {
&user_base_token_account &user_base_token_account
} else { } else {
+11 -7
View File
@@ -1,8 +1,7 @@
use crate::common::{bonding_curve::BondingCurveAccount, global::GlobalAccount, SolanaRpcClient}; use crate::common::{bonding_curve::BondingCurveAccount, SolanaRpcClient};
use anyhow::anyhow; use anyhow::anyhow;
use solana_sdk::pubkey::Pubkey; use solana_sdk::pubkey::Pubkey;
use std::{collections::HashMap, sync::Arc}; use std::sync::Arc;
use tokio::sync::RwLock;
/// Constants used as seeds for deriving PDAs (Program Derived Addresses) /// Constants used as seeds for deriving PDAs (Program Derived Addresses)
pub mod seeds { pub mod seeds {
@@ -58,6 +57,15 @@ pub mod global_constants {
is_writable: true, is_writable: true,
}; };
pub const MAYHEM_FEE_RECIPIENT: Pubkey =
pubkey!("GesfTA3X2arioaHp8bbKdjG9vJtskViWACZoYvxp4twS");
pub const MAYHEM_FEE_RECIPIENT_META: solana_sdk::instruction::AccountMeta =
solana_sdk::instruction::AccountMeta {
pubkey: FEE_RECIPIENT,
is_signer: false,
is_writable: true,
};
/// Public key for the global PDA /// Public key for the global PDA
pub const GLOBAL_ACCOUNT: Pubkey = pubkey!("4wTV1YmiEkRvAtNtsSGPtUrqRYQMe5SKy2uB4Jjaxnjf"); pub const GLOBAL_ACCOUNT: Pubkey = pubkey!("4wTV1YmiEkRvAtNtsSGPtUrqRYQMe5SKy2uB4Jjaxnjf");
pub const GLOBAL_ACCOUNT_META: solana_sdk::instruction::AccountMeta = pub const GLOBAL_ACCOUNT_META: solana_sdk::instruction::AccountMeta =
@@ -152,10 +160,6 @@ impl Symbol {
pub const SOLANA: &'static str = "solana"; pub const SOLANA: &'static str = "solana";
} }
lazy_static::lazy_static! {
static ref ACCOUNT_CACHE: RwLock<HashMap<Pubkey, Arc<GlobalAccount>>> = RwLock::new(HashMap::new());
}
#[inline] #[inline]
pub fn get_bonding_curve_pda(mint: &Pubkey) -> Option<Pubkey> { pub fn get_bonding_curve_pda(mint: &Pubkey) -> Option<Pubkey> {
crate::common::fast_fn::get_cached_pda( crate::common::fast_fn::get_cached_pda(
+11
View File
@@ -65,6 +65,10 @@ pub mod accounts {
pub const DEFAULT_COIN_CREATOR_VAULT_AUTHORITY: Pubkey = pub const DEFAULT_COIN_CREATOR_VAULT_AUTHORITY: Pubkey =
pubkey!("8N3GDaZ2iwN65oxVatKTLPNooAVUJTbfiVJ1ahyqwjSk"); pubkey!("8N3GDaZ2iwN65oxVatKTLPNooAVUJTbfiVJ1ahyqwjSk");
/// Mayhem fee recipient (for mayhem mode coins)
pub const MAYHEM_FEE_RECIPIENT: Pubkey =
pubkey!("GesfTA3X2arioaHp8bbKdjG9vJtskViWACZoYvxp4twS");
// META // META
pub const GLOBAL_ACCOUNT_META: solana_sdk::instruction::AccountMeta = pub const GLOBAL_ACCOUNT_META: solana_sdk::instruction::AccountMeta =
@@ -81,6 +85,13 @@ pub mod accounts {
is_writable: false, is_writable: false,
}; };
pub const MAYHEM_FEE_RECIPIENT_META: solana_sdk::instruction::AccountMeta =
solana_sdk::instruction::AccountMeta {
pubkey: MAYHEM_FEE_RECIPIENT,
is_signer: false,
is_writable: false,
};
pub const ASSOCIATED_TOKEN_PROGRAM_META: solana_sdk::instruction::AccountMeta = pub const ASSOCIATED_TOKEN_PROGRAM_META: solana_sdk::instruction::AccountMeta =
solana_sdk::instruction::AccountMeta { solana_sdk::instruction::AccountMeta {
pubkey: ASSOCIATED_TOKEN_PROGRAM, pubkey: ASSOCIATED_TOKEN_PROGRAM,
+2 -1
View File
@@ -14,9 +14,10 @@ pub struct Pool {
pub pool_quote_token_account: Pubkey, pub pool_quote_token_account: Pubkey,
pub lp_supply: u64, pub lp_supply: u64,
pub coin_creator: Pubkey, pub coin_creator: Pubkey,
pub is_mayhem_mode: bool,
} }
pub const POOL_SIZE: usize = 1 + 2 + 32 * 6 + 8 + 32; pub const POOL_SIZE: usize = 1 + 2 + 32 * 6 + 8 + 32 + 1;
pub fn pool_decode(data: &[u8]) -> Option<Pool> { pub fn pool_decode(data: &[u8]) -> Option<Pool> {
if data.len() < POOL_SIZE { if data.len() < POOL_SIZE {
+15
View File
@@ -4,6 +4,8 @@ use crate::common::nonce_cache::DurableNonceInfo;
use crate::common::spl_associated_token_account::get_associated_token_address_with_program_id; use crate::common::spl_associated_token_account::get_associated_token_address_with_program_id;
use crate::common::{GasFeeStrategy, SolanaRpcClient}; use crate::common::{GasFeeStrategy, SolanaRpcClient};
use crate::constants::TOKEN_PROGRAM; use crate::constants::TOKEN_PROGRAM;
use crate::instruction::utils::pumpfun::global_constants::MAYHEM_FEE_RECIPIENT;
use crate::instruction::utils::pumpswap::accounts::MAYHEM_FEE_RECIPIENT as MAYHEM_FEE_RECIPIENT_SWAP;
use crate::swqos::{SwqosClient, TradeType}; use crate::swqos::{SwqosClient, TradeType};
use crate::trading::common::get_multi_token_balances; use crate::trading::common::get_multi_token_balances;
use crate::trading::MiddlewareManager; use crate::trading::MiddlewareManager;
@@ -79,13 +81,16 @@ impl PumpFunParams {
associated_bonding_curve: Pubkey, associated_bonding_curve: Pubkey,
creator_vault: Pubkey, creator_vault: Pubkey,
close_token_account_when_sell: Option<bool>, close_token_account_when_sell: Option<bool>,
fee_recipient: Pubkey,
) -> Self { ) -> Self {
let is_mayhem_mode = fee_recipient == MAYHEM_FEE_RECIPIENT;
let bonding_curve_account = BondingCurveAccount::from_dev_trade( let bonding_curve_account = BondingCurveAccount::from_dev_trade(
bonding_curve, bonding_curve,
&mint, &mint,
token_amount, token_amount,
max_sol_cost, max_sol_cost,
creator, creator,
is_mayhem_mode,
); );
Self { Self {
bonding_curve: Arc::new(bonding_curve_account), bonding_curve: Arc::new(bonding_curve_account),
@@ -106,7 +111,9 @@ impl PumpFunParams {
real_token_reserves: u64, real_token_reserves: u64,
real_sol_reserves: u64, real_sol_reserves: u64,
close_token_account_when_sell: Option<bool>, close_token_account_when_sell: Option<bool>,
fee_recipient: Pubkey,
) -> Self { ) -> Self {
let is_mayhem_mode = fee_recipient == MAYHEM_FEE_RECIPIENT;
let bonding_curve = BondingCurveAccount::from_trade( let bonding_curve = BondingCurveAccount::from_trade(
bonding_curve, bonding_curve,
mint, mint,
@@ -115,6 +122,7 @@ impl PumpFunParams {
virtual_sol_reserves, virtual_sol_reserves,
real_token_reserves, real_token_reserves,
real_sol_reserves, real_sol_reserves,
is_mayhem_mode,
); );
Self { Self {
bonding_curve: Arc::new(bonding_curve), bonding_curve: Arc::new(bonding_curve),
@@ -140,6 +148,7 @@ impl PumpFunParams {
token_total_supply: account.0.token_total_supply, token_total_supply: account.0.token_total_supply,
complete: account.0.complete, complete: account.0.complete,
creator: account.0.creator, creator: account.0.creator,
is_mayhem_mode: account.0.is_mayhem_mode,
}; };
let associated_bonding_curve = get_associated_token_address_with_program_id( let associated_bonding_curve = get_associated_token_address_with_program_id(
&bonding_curve.account, &bonding_curve.account,
@@ -201,6 +210,8 @@ pub struct PumpSwapParams {
pub base_token_program: Pubkey, pub base_token_program: Pubkey,
/// Quote token program ID /// Quote token program ID
pub quote_token_program: Pubkey, pub quote_token_program: Pubkey,
/// Whether the pool is in mayhem mode
pub is_mayhem_mode: bool,
} }
impl PumpSwapParams { impl PumpSwapParams {
@@ -216,7 +227,9 @@ impl PumpSwapParams {
coin_creator_vault_authority: Pubkey, coin_creator_vault_authority: Pubkey,
base_token_program: Pubkey, base_token_program: Pubkey,
quote_token_program: Pubkey, quote_token_program: Pubkey,
fee_recipient: Pubkey,
) -> Self { ) -> Self {
let is_mayhem_mode = fee_recipient == MAYHEM_FEE_RECIPIENT_SWAP;
Self { Self {
pool, pool,
base_mint, base_mint,
@@ -229,6 +242,7 @@ impl PumpSwapParams {
coin_creator_vault_authority, coin_creator_vault_authority,
base_token_program, base_token_program,
quote_token_program, quote_token_program,
is_mayhem_mode,
} }
} }
@@ -295,6 +309,7 @@ impl PumpSwapParams {
} else { } else {
crate::constants::TOKEN_PROGRAM_2022 crate::constants::TOKEN_PROGRAM_2022
}, },
is_mayhem_mode: pool_data.is_mayhem_mode,
}) })
} }
} }