mirror of
https://github.com/0xfnzero/solana-streamer.git
synced 2026-08-25 14:58:05 +00:00
add default PriorityFee
This commit is contained in:
+18
-15
@@ -39,8 +39,8 @@ use crate::error::ClientError;
|
|||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
const DEFAULT_SLIPPAGE: u64 = 500; // 10%
|
const DEFAULT_SLIPPAGE: u64 = 500; // 10%
|
||||||
const DEFAULT_COMPUTE_UNIT_LIMIT: u32 = 68_000;
|
const DEFAULT_COMPUTE_UNIT_LIMIT: u32 = 100_000;
|
||||||
const DEFAULT_COMPUTE_UNIT_PRICE: u64 = 400_000;
|
const DEFAULT_COMPUTE_UNIT_PRICE: u64 = 100_000_000;
|
||||||
|
|
||||||
/// Priority fee configuration
|
/// Priority fee configuration
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
@@ -49,6 +49,12 @@ pub struct PriorityFee {
|
|||||||
pub price: Option<u64>,
|
pub price: Option<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for PriorityFee {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self { limit: Some(DEFAULT_COMPUTE_UNIT_LIMIT), price: Some(DEFAULT_COMPUTE_UNIT_PRICE) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct PumpFun {
|
pub struct PumpFun {
|
||||||
pub rpc: RpcClient,
|
pub rpc: RpcClient,
|
||||||
pub payer: Arc<Keypair>,
|
pub payer: Arc<Keypair>,
|
||||||
@@ -468,24 +474,21 @@ impl PumpFun {
|
|||||||
// Helper methods
|
// Helper methods
|
||||||
fn create_priority_fee_instructions(&self, priority_fee: Option<PriorityFee>) -> Vec<Instruction> {
|
fn create_priority_fee_instructions(&self, priority_fee: Option<PriorityFee>) -> Vec<Instruction> {
|
||||||
let mut instructions = Vec::new();
|
let mut instructions = Vec::new();
|
||||||
if let Some(fee) = priority_fee {
|
let fee = priority_fee.unwrap_or(PriorityFee::default());
|
||||||
if let Some(limit) = fee.limit {
|
if let Some(limit) = fee.limit {
|
||||||
instructions.push(ComputeBudgetInstruction::set_compute_unit_limit(limit));
|
instructions.push(ComputeBudgetInstruction::set_compute_unit_limit(limit));
|
||||||
}
|
|
||||||
if let Some(price) = fee.price {
|
|
||||||
instructions.push(ComputeBudgetInstruction::set_compute_unit_price(price));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if let Some(price) = fee.price {
|
||||||
|
instructions.push(ComputeBudgetInstruction::set_compute_unit_price(price));
|
||||||
|
}
|
||||||
|
|
||||||
instructions
|
instructions
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_compute_units(&self, priority_fee: Option<PriorityFee>) -> (u32, u64) {
|
fn get_compute_units(&self, priority_fee: Option<PriorityFee>) -> (u32, u64) {
|
||||||
let unit_limit = priority_fee
|
let fee = priority_fee.unwrap_or(PriorityFee::default());
|
||||||
.and_then(|fee| fee.limit)
|
let unit_limit = fee.limit.unwrap_or(DEFAULT_COMPUTE_UNIT_LIMIT);
|
||||||
.unwrap_or(DEFAULT_COMPUTE_UNIT_LIMIT);
|
let unit_price = fee.price.unwrap_or(DEFAULT_COMPUTE_UNIT_PRICE);
|
||||||
let unit_price = priority_fee
|
|
||||||
.and_then(|fee| fee.price)
|
|
||||||
.unwrap_or(DEFAULT_COMPUTE_UNIT_PRICE);
|
|
||||||
(unit_limit, unit_price)
|
(unit_limit, unit_price)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user