change priority_fee

This commit is contained in:
William
2025-02-21 22:32:43 +08:00
parent 8df2841b17
commit ecb2ffa747
6 changed files with 87 additions and 95 deletions
+9 -13
View File
@@ -3,7 +3,7 @@ use tokio::sync::RwLock;
use std::{collections::HashMap, sync::Arc};
use solana_client::rpc_client::RpcClient;
use solana_sdk::{
compute_budget::ComputeBudgetInstruction, instruction::Instruction, pubkey::Pubkey, signature::Keypair, signer::Signer, system_instruction, transaction::Transaction
compute_budget::ComputeBudgetInstruction, instruction::Instruction, native_token::sol_to_lamports, pubkey::Pubkey, signature::Keypair, signer::Signer, system_instruction, transaction::Transaction
};
use spl_associated_token_account::get_associated_token_address;
use crate::{accounts, common::logs_data::TradeInfo, constants::{self, trade::{DEFAULT_COMPUTE_UNIT_LIMIT, DEFAULT_COMPUTE_UNIT_PRICE, DEFAULT_SLIPPAGE}}};
@@ -13,15 +13,16 @@ lazy_static::lazy_static! {
static ref ACCOUNT_CACHE: RwLock<HashMap<Pubkey, Arc<accounts::GlobalAccount>>> = RwLock::new(HashMap::new());
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct PriorityFee {
pub limit: Option<u32>,
pub price: Option<u64>,
pub limit: f64,
pub price: f64,
pub jito_fee: Option<f64>,
}
impl Default for PriorityFee {
fn default() -> Self {
Self { limit: Some(DEFAULT_COMPUTE_UNIT_LIMIT), price: Some(DEFAULT_COMPUTE_UNIT_PRICE) }
Self { limit: DEFAULT_COMPUTE_UNIT_LIMIT, price: DEFAULT_COMPUTE_UNIT_PRICE, jito_fee: None }
}
}
@@ -56,15 +57,10 @@ pub async fn transfer_sol(rpc: &RpcClient, payer: &Keypair, receive_wallet: &Pub
}
#[inline]
pub fn create_priority_fee_instructions(priority_fee: Option<PriorityFee>) -> Vec<Instruction> {
pub fn create_priority_fee_instructions(priority_fee: PriorityFee) -> Vec<Instruction> {
let mut instructions = Vec::with_capacity(2);
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.push(ComputeBudgetInstruction::set_compute_unit_limit(sol_to_lamports(priority_fee.limit) as u32));
instructions.push(ComputeBudgetInstruction::set_compute_unit_price(sol_to_lamports(priority_fee.price)));
instructions
}