From 7cf908ae5deee62451c22c8185d46788384233b4 Mon Sep 17 00:00:00 2001 From: William Date: Fri, 14 Feb 2025 18:53:00 +0800 Subject: [PATCH] fix --- src/lib.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 7a0c5a2..607751d 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -96,6 +96,10 @@ impl PumpFun { } } + pub fn get_rpc(&self) -> &RpcClient { + &self.rpc + } + /// Create a new token pub async fn create( &self, @@ -648,6 +652,29 @@ impl PumpFun { subscription_handle.shutdown().await; } + pub async fn transfer_sol(&self, recieve_wallet: &Pubkey, amount: u64) -> Result<(), anyhow::Error> { + let mut instructions = vec![]; + let transfer_instruction = system_instruction::transfer( + &self.payer.pubkey(), // 付款方地址 + recieve_wallet, // 收款方地址 + amount, // 转账金额 + ); + instructions.push(transfer_instruction); + + let recent_blockhash = self.rpc.get_latest_blockhash()?; + + let transaction = Transaction::new_signed_with_payer( + &instructions, + Some(&self.payer.pubkey()), + &[&self.payer.clone()], + recent_blockhash, + ); + + self.rpc.send_and_confirm_transaction(&transaction)?; + + Ok(()) + } + pub fn get_buy_amount_with_slippage(&self, amount_sol: u64, slippage_basis_points: Option) -> u64 { utils::calculate_with_slippage_buy(amount_sol, slippage_basis_points.unwrap_or(DEFAULT_SLIPPAGE)) }