From af2afcbb60b628db9604896a82a07c937ff35d40 Mon Sep 17 00:00:00 2001 From: wei <1415121722@qq.com> Date: Sat, 14 Jun 2025 18:52:46 +0800 Subject: [PATCH 1/5] fix --- Cargo.toml | 2 +- src/common/types.rs | 6 +++--- src/constants/pumpfun/mod.rs | 2 ++ src/lib.rs | 9 +++++++++ src/swqos/mod.rs | 1 + 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c4f0871..9dc1f64 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -87,7 +87,7 @@ tokio-tungstenite = { version = "0.26.1", features = ["native-tls"] } indicatif = "0.17.11" toml = "0.8.20" -pumpfun_program = { version = "4.2.0", package = "pumpfun" } +pumpfun_program = { version = "4.3.0", package = "pumpfun" } diff --git a/src/common/types.rs b/src/common/types.rs index 47095a4..94daec8 100755 --- a/src/common/types.rs +++ b/src/common/types.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use solana_client::rpc_client::RpcClient; use solana_sdk::{commitment_config::CommitmentConfig, pubkey::Pubkey, signature::Keypair}; use serde::Deserialize; -use crate::{constants::pumpfun::trade::{DEFAULT_BUY_TIP_FEE, DEFAULT_COMPUTE_UNIT_LIMIT, DEFAULT_COMPUTE_UNIT_PRICE, DEFAULT_SELL_TIP_FEE}, swqos::FeeClient}; +use crate::{constants::pumpfun::trade::{DEFAULT_BUY_TIP_FEE, DEFAULT_COMPUTE_UNIT_LIMIT, DEFAULT_COMPUTE_UNIT_PRICE, DEFAULT_RPC_UNIT_LIMIT, DEFAULT_RPC_UNIT_PRICE, DEFAULT_SELL_TIP_FEE}, swqos::FeeClient}; #[derive(Debug, Clone, PartialEq)] pub enum FeeType { @@ -87,8 +87,8 @@ impl Default for PriorityFee { Self { unit_limit: DEFAULT_COMPUTE_UNIT_LIMIT, unit_price: DEFAULT_COMPUTE_UNIT_PRICE, - rpc_unit_limit: 0, - rpc_unit_price: 0, + rpc_unit_limit: DEFAULT_RPC_UNIT_LIMIT, + rpc_unit_price: DEFAULT_RPC_UNIT_PRICE, buy_tip_fee: DEFAULT_BUY_TIP_FEE, buy_tip_fees: vec![], sell_tip_fee: DEFAULT_SELL_TIP_FEE diff --git a/src/constants/pumpfun/mod.rs b/src/constants/pumpfun/mod.rs index c59a2c9..38969cf 100755 --- a/src/constants/pumpfun/mod.rs +++ b/src/constants/pumpfun/mod.rs @@ -165,6 +165,8 @@ pub mod trade { pub const DEFAULT_COMPUTE_UNIT_PRICE: u64 = 500000; pub const DEFAULT_BUY_TIP_FEE: f64 = 0.0006; pub const DEFAULT_SELL_TIP_FEE: f64 = 0.0001; + pub const DEFAULT_RPC_UNIT_LIMIT: u32 = 1000000; + pub const DEFAULT_RPC_UNIT_PRICE: u64 = 500000; } pub struct Symbol; diff --git a/src/lib.rs b/src/lib.rs index 47823af..0ee710e 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -640,6 +640,15 @@ impl PumpFun { Ok(actual_sol_reserves) } + #[inline] + pub async fn get_creator(&self, mint: &Pubkey) -> Result { + let (bonding_curve, _) = pumpfun::common::get_bonding_curve_account_v2(&self.rpc, mint).await?; + + let creator = bonding_curve.creator; + + Ok(creator) + } + #[inline] pub async fn get_current_price_with_pumpswap(&self, pool_address: &Pubkey) -> Result { let pool = pumpswap::pool::Pool::fetch(&self.rpc, pool_address).await?; diff --git a/src/swqos/mod.rs b/src/swqos/mod.rs index 8a92dab..1e9ad67 100755 --- a/src/swqos/mod.rs +++ b/src/swqos/mod.rs @@ -95,6 +95,7 @@ impl FeeClientTrait for SolRpcClient { Ok(_) => (), Err(_) => (), } + println!(" signature: {:?}", signature); println!(" rpc{}确认: {:?}", trade_type, start_time.elapsed()); Ok(signature) From 1b2d79d5fec982321736dbcc0c742ba4f65163d0 Mon Sep 17 00:00:00 2001 From: wei <1415121722@qq.com> Date: Sat, 14 Jun 2025 20:16:50 +0800 Subject: [PATCH 2/5] fix --- src/pumpfun/sell.rs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/pumpfun/sell.rs b/src/pumpfun/sell.rs index 15334e4..24522f6 100755 --- a/src/pumpfun/sell.rs +++ b/src/pumpfun/sell.rs @@ -7,7 +7,7 @@ use spl_associated_token_account::get_associated_token_address; use spl_token::instruction::close_account; use tokio::task::JoinHandle; use std::{str::FromStr, sync::Arc, time::Instant}; - +use crate::PumpFun; use crate::{common::{address_lookup_cache::get_address_lookup_table_account, PriorityFee, SolanaRpcClient}, constants::pumpfun::{global_constants::FEE_RECIPIENT}, instruction, swqos::{FeeClient, TradeType, ClientType}}; use super::common::get_creator_vault_pda; @@ -270,7 +270,10 @@ pub async fn build_sell_instructions( let creator_vault_pda = get_creator_vault_pda(&creator).unwrap(); let ata = get_associated_token_address(&payer.pubkey(), &mint); - let instructions = vec![ + // Get token balance using get_payer_token_balance + let balance_u64 = PumpFun::get_instance().get_payer_token_balance(&mint).await?; + + let mut instructions = vec![ instruction::sell( payer.as_ref(), &mint, @@ -281,15 +284,20 @@ pub async fn build_sell_instructions( _min_sol_output: 1, }, ), - - close_account( - &spl_token::ID, - &ata, - &payer.pubkey(), - &payer.pubkey(), - &[&payer.pubkey()], - )? ]; + // Only add close account instruction if amount is less than balance + if amount_token >= balance_u64 { + instructions.push( + close_account( + &spl_token::ID, + &ata, + &payer.pubkey(), + &payer.pubkey(), + &[&payer.pubkey()], + )? + ); + } + Ok(instructions) } From 5cbbfb400db665e1f5b318a5232f9d8c26f4bd78 Mon Sep 17 00:00:00 2001 From: wei <1415121722@qq.com> Date: Sat, 14 Jun 2025 21:18:48 +0800 Subject: [PATCH 3/5] fix --- src/pumpfun/sell.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/pumpfun/sell.rs b/src/pumpfun/sell.rs index 24522f6..6dd5818 100755 --- a/src/pumpfun/sell.rs +++ b/src/pumpfun/sell.rs @@ -273,6 +273,11 @@ pub async fn build_sell_instructions( // Get token balance using get_payer_token_balance let balance_u64 = PumpFun::get_instance().get_payer_token_balance(&mint).await?; + let mut amount_token = amount_token; + if amount_token > balance_u64 { + amount_token = balance_u64; + } + let mut instructions = vec![ instruction::sell( payer.as_ref(), From f38fb91076761ac6282cd15429d90a4536bde371 Mon Sep 17 00:00:00 2001 From: wei <1415121722@qq.com> Date: Sun, 15 Jun 2025 20:50:51 +0800 Subject: [PATCH 4/5] Add a method to obtain pumpswap token balance --- src/lib.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 0ee710e..03f21ae 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -674,4 +674,13 @@ impl PumpFun { Ok(quote_amount) } + + #[inline] + pub async fn get_payer_token_balance_with_pumpswap(&self, pool_address: &Pubkey) -> Result { + let pool = pumpswap::pool::Pool::fetch(&self.rpc, pool_address).await?; + + let (base_amount, _) = pool.get_token_balances(&self.rpc).await?; + + Ok(base_amount) + } } From 5468b6258e2b0404250deafe8d85d43534ec9729 Mon Sep 17 00:00:00 2001 From: wei <1415121722@qq.com> Date: Sun, 15 Jun 2025 21:42:59 +0800 Subject: [PATCH 5/5] fix --- src/pumpfun/sell.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/pumpfun/sell.rs b/src/pumpfun/sell.rs index 6dd5818..29a18b2 100755 --- a/src/pumpfun/sell.rs +++ b/src/pumpfun/sell.rs @@ -270,8 +270,11 @@ pub async fn build_sell_instructions( let creator_vault_pda = get_creator_vault_pda(&creator).unwrap(); let ata = get_associated_token_address(&payer.pubkey(), &mint); - // Get token balance using get_payer_token_balance - let balance_u64 = PumpFun::get_instance().get_payer_token_balance(&mint).await?; + // Get token balance + let rpc = PumpFun::get_instance().get_rpc().clone(); + let balance = rpc.get_token_account_balance(&ata).await?; + let balance_u64 = balance.amount.parse::() + .map_err(|_| anyhow!("Failed to parse token balance"))?; let mut amount_token = amount_token; if amount_token > balance_u64 {