From 06cae8c933d9adf7c84a08b2a56b09ce43511bb3 Mon Sep 17 00:00:00 2001 From: William Date: Thu, 9 Jan 2025 16:59:05 +0800 Subject: [PATCH] add default PriorityFee --- crates/pumpfun/src/lib.rs | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/crates/pumpfun/src/lib.rs b/crates/pumpfun/src/lib.rs index 57339f1..3c408e1 100755 --- a/crates/pumpfun/src/lib.rs +++ b/crates/pumpfun/src/lib.rs @@ -39,8 +39,8 @@ use crate::error::ClientError; // Constants const DEFAULT_SLIPPAGE: u64 = 500; // 10% -const DEFAULT_COMPUTE_UNIT_LIMIT: u32 = 68_000; -const DEFAULT_COMPUTE_UNIT_PRICE: u64 = 400_000; +const DEFAULT_COMPUTE_UNIT_LIMIT: u32 = 100_000; +const DEFAULT_COMPUTE_UNIT_PRICE: u64 = 100_000_000; /// Priority fee configuration #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -49,6 +49,12 @@ pub struct PriorityFee { pub price: Option, } +impl Default for PriorityFee { + fn default() -> Self { + Self { limit: Some(DEFAULT_COMPUTE_UNIT_LIMIT), price: Some(DEFAULT_COMPUTE_UNIT_PRICE) } + } +} + pub struct PumpFun { pub rpc: RpcClient, pub payer: Arc, @@ -468,24 +474,21 @@ impl PumpFun { // Helper methods fn create_priority_fee_instructions(&self, priority_fee: Option) -> Vec { let mut instructions = Vec::new(); - if let Some(fee) = priority_fee { - if let Some(limit) = fee.limit { - instructions.push(ComputeBudgetInstruction::set_compute_unit_limit(limit)); - } - if let Some(price) = fee.price { - instructions.push(ComputeBudgetInstruction::set_compute_unit_price(price)); - } + let fee = priority_fee.unwrap_or(PriorityFee::default()); + if let Some(limit) = fee.limit { + instructions.push(ComputeBudgetInstruction::set_compute_unit_limit(limit)); } + if let Some(price) = fee.price { + instructions.push(ComputeBudgetInstruction::set_compute_unit_price(price)); + } + instructions } fn get_compute_units(&self, priority_fee: Option) -> (u32, u64) { - let unit_limit = priority_fee - .and_then(|fee| fee.limit) - .unwrap_or(DEFAULT_COMPUTE_UNIT_LIMIT); - let unit_price = priority_fee - .and_then(|fee| fee.price) - .unwrap_or(DEFAULT_COMPUTE_UNIT_PRICE); + let fee = priority_fee.unwrap_or(PriorityFee::default()); + let unit_limit = fee.limit.unwrap_or(DEFAULT_COMPUTE_UNIT_LIMIT); + let unit_price = fee.price.unwrap_or(DEFAULT_COMPUTE_UNIT_PRICE); (unit_limit, unit_price) }