diff --git a/helium-lib/src/asset.rs b/helium-lib/src/asset.rs index e738038a..aef89a0a 100644 --- a/helium-lib/src/asset.rs +++ b/helium-lib/src/asset.rs @@ -184,12 +184,8 @@ pub async fn transfer_message + AsRef>( let ixs = &[ compute_budget_instruction(200_000), - compute_price_instruction_for_accounts( - client, - &priority_fee_accounts, - opts.min_priority_fee, - ) - .await?, + compute_price_instruction_for_accounts(client, &priority_fee_accounts, opts.fee_range()) + .await?, transfer_ix, ]; @@ -244,12 +240,8 @@ pub async fn burn_message + AsRef>( let ixs = &[ compute_budget_instruction(100_000), - compute_price_instruction_for_accounts( - client, - &priority_fee_accounts, - opts.min_priority_fee, - ) - .await?, + compute_price_instruction_for_accounts(client, &priority_fee_accounts, opts.fee_range()) + .await?, ix, ]; diff --git a/helium-lib/src/boosting.rs b/helium-lib/src/boosting.rs index ccd02e70..91f2f470 100644 --- a/helium-lib/src/boosting.rs +++ b/helium-lib/src/boosting.rs @@ -64,7 +64,7 @@ pub async fn start_boost_message>( priority_fee::compute_price_instruction_for_accounts( client, &ix_accounts, - opts.min_priority_fee, + opts.fee_range(), ) .await?, ], diff --git a/helium-lib/src/dc.rs b/helium-lib/src/dc.rs index adabd4a7..9297e748 100644 --- a/helium-lib/src/dc.rs +++ b/helium-lib/src/dc.rs @@ -81,7 +81,7 @@ pub async fn mint_message>( priority_fee::compute_price_instruction_for_accounts( client, &ix.accounts, - opts.min_priority_fee, + opts.fee_range(), ) .await?, ix, @@ -145,7 +145,7 @@ pub async fn delegate_message>( priority_fee::compute_price_instruction_for_accounts( client, &ix.accounts, - opts.min_priority_fee, + opts.fee_range(), ) .await?, ix, @@ -202,7 +202,7 @@ pub async fn burn_message>( priority_fee::compute_price_instruction_for_accounts( client, &ix.accounts, - opts.min_priority_fee, + opts.fee_range(), ) .await?, ix, @@ -283,7 +283,7 @@ pub async fn burn_delegated_message>( priority_fee::compute_price_instruction_for_accounts( client, &burn_ix.accounts, - opts.min_priority_fee, + opts.fee_range(), ) .await?, burn_ix, diff --git a/helium-lib/src/hotspot/dataonly.rs b/helium-lib/src/hotspot/dataonly.rs index bef755f2..5c92339d 100644 --- a/helium-lib/src/hotspot/dataonly.rs +++ b/helium-lib/src/hotspot/dataonly.rs @@ -99,7 +99,7 @@ mod iot { priority_fee::compute_price_instruction_for_accounts( client, &onboard_ix.accounts, - opts.min_priority_fee, + opts.fee_range(), ) .await?, onboard_ix, @@ -187,7 +187,7 @@ mod mobile { priority_fee::compute_price_instruction_for_accounts( client, &onboard_ix.accounts, - opts.min_priority_fee, + opts.fee_range(), ) .await?, onboard_ix, @@ -291,12 +291,8 @@ pub async fn issue_transaction + GetAnchorAccount>( let ixs = &[ priority_fee::compute_budget_instruction(300_000), - priority_fee::compute_price_instruction_for_accounts( - client, - &accounts, - opts.min_priority_fee, - ) - .await?, + priority_fee::compute_price_instruction_for_accounts(client, &accounts, opts.fee_range()) + .await?, issue_ix, ]; diff --git a/helium-lib/src/hotspot/mod.rs b/helium-lib/src/hotspot/mod.rs index 0ad37e47..3ce73974 100644 --- a/helium-lib/src/hotspot/mod.rs +++ b/helium-lib/src/hotspot/mod.rs @@ -202,12 +202,8 @@ pub async fn direct_update_message + AsRef> let ixs = &[ priority_fee::compute_budget_instruction(200_000), - priority_fee::compute_price_instruction_for_accounts( - client, - &accounts, - opts.min_priority_fee, - ) - .await?, + priority_fee::compute_price_instruction_for_accounts(client, &accounts, opts.fee_range()) + .await?, ix, ]; diff --git a/helium-lib/src/lib.rs b/helium-lib/src/lib.rs index 7bb782aa..78a7198f 100644 --- a/helium-lib/src/lib.rs +++ b/helium-lib/src/lib.rs @@ -59,7 +59,7 @@ use client::SolanaRpcClient; use error::Error; use keypair::Pubkey; use solana_sdk::{instruction::Instruction, transaction::Transaction}; -use std::sync::Arc; +use std::{ops::RangeInclusive, sync::Arc}; pub fn init(solana_client: Arc) -> Result<(), error::Error> { kta::init(solana_client) @@ -67,6 +67,7 @@ pub fn init(solana_client: Arc) -> Result<(), error::Er pub struct TransactionOpts { pub min_priority_fee: u64, + pub max_priority_fee: u64, pub lut_addresses: Vec, } @@ -74,11 +75,18 @@ impl Default for TransactionOpts { fn default() -> Self { Self { min_priority_fee: priority_fee::MIN_PRIORITY_FEE, + max_priority_fee: priority_fee::MAX_PRIORITY_FEE, lut_addresses: vec![message::COMMON_LUT], } } } +impl TransactionOpts { + fn fee_range(&self) -> RangeInclusive { + RangeInclusive::new(self.min_priority_fee, self.max_priority_fee) + } +} + pub async fn mk_transaction_with_blockhash>( client: &C, ixs: &[Instruction], diff --git a/helium-lib/src/memo.rs b/helium-lib/src/memo.rs index 99f755bc..0b13e08c 100644 --- a/helium-lib/src/memo.rs +++ b/helium-lib/src/memo.rs @@ -19,7 +19,7 @@ pub async fn memo_message>( priority_fee::compute_price_instruction_for_accounts( client, &ix.accounts, - opts.min_priority_fee, + opts.fee_range(), ) .await?, ix, diff --git a/helium-lib/src/priority_fee.rs b/helium-lib/src/priority_fee.rs index 4e9d376c..a794c748 100644 --- a/helium-lib/src/priority_fee.rs +++ b/helium-lib/src/priority_fee.rs @@ -1,3 +1,5 @@ +use std::ops::RangeInclusive; + use crate::{ anchor_lang::ToAccountMetas, client::SolanaRpcClient, error::Error, keypair::Pubkey, solana_client, @@ -6,17 +8,18 @@ use itertools::Itertools; pub const MAX_RECENT_PRIORITY_FEE_ACCOUNTS: usize = 128; pub const MIN_PRIORITY_FEE: u64 = 1; +pub const MAX_PRIORITY_FEE: u64 = 2500000; -pub async fn get_estimate_with_min>( +pub async fn get_estimate>( client: &C, accounts: &impl ToAccountMetas, - min_priority_fee: u64, + fee_range: RangeInclusive, ) -> Result { let client_url = client.as_ref().url(); if client_url.contains("mainnet.helius") { - helius::get_estimate_with_min(client, accounts, min_priority_fee).await + helius::get_estimate(client, accounts, fee_range).await } else { - base::get_estimate_with_min(client, accounts, min_priority_fee).await + base::get_estimate(client, accounts, fee_range).await } } @@ -35,10 +38,10 @@ mod helius { use serde::Deserialize; use serde_json::json; - pub async fn get_estimate_with_min>( + pub async fn get_estimate>( client: &C, accounts: &impl ToAccountMetas, - min_priority_fee: u64, + fee_range: RangeInclusive, ) -> Result { #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase")] @@ -54,22 +57,25 @@ mod helius { "accountKeys": account_keys, "options": { "recommended": true, + "evaluateEmptySlotAsZero": true } } ]); let response: Response = client.as_ref().send(request, params).await?; - Ok((response.priority_fee_estimate.ceil() as u64).max(min_priority_fee)) + Ok((response.priority_fee_estimate.ceil() as u64) + .min(*fee_range.end()) + .max(*fee_range.start())) } } mod base { use super::*; - pub async fn get_estimate_with_min>( + pub async fn get_estimate>( client: &C, accounts: &impl ToAccountMetas, - min_priority_fee: u64, + fee_range: RangeInclusive, ) -> Result { let account_keys: Vec<_> = account_keys(accounts).collect(); let recent_fees = client @@ -91,14 +97,15 @@ mod base { let num_recent_fees = max_per_slot.len(); let mid = num_recent_fees / 2; let estimate = if num_recent_fees == 0 { - min_priority_fee + *fee_range.start() } else if num_recent_fees % 2 == 0 { // If the number of samples is even, taken the mean of the two median fees (max_per_slot[mid - 1] + max_per_slot[mid]) / 2 } else { max_per_slot[mid] } - .max(min_priority_fee); + .min(*fee_range.end()) + .max(*fee_range.start()); Ok(estimate) } } @@ -114,8 +121,8 @@ pub fn compute_price_instruction(priority_fee: u64) -> solana_sdk::instruction:: pub async fn compute_price_instruction_for_accounts>( client: &C, accounts: &impl ToAccountMetas, - min_priority_fee: u64, + fee_range: RangeInclusive, ) -> Result { - let priority_fee = get_estimate_with_min(client, accounts, min_priority_fee).await?; + let priority_fee = get_estimate(client, accounts, fee_range).await?; Ok(compute_price_instruction(priority_fee)) } diff --git a/helium-lib/src/reward.rs b/helium-lib/src/reward.rs index f9cbe46d..37197e0f 100644 --- a/helium-lib/src/reward.rs +++ b/helium-lib/src/reward.rs @@ -371,7 +371,7 @@ pub async fn claim_transaction + AsRef + Ge priority_fee::compute_price_instruction_for_accounts( client, &ixs_accounts, - opts.min_priority_fee, + opts.fee_range(), ) .await?, ]; @@ -629,7 +629,7 @@ pub mod recipient { priority_fee::compute_price_instruction_for_accounts( client, &ix.accounts, - opts.min_priority_fee, + opts.fee_range(), ) .await?, ix, diff --git a/helium-wallet/src/cmd/mod.rs b/helium-wallet/src/cmd/mod.rs index e1259373..4fa91e71 100644 --- a/helium-wallet/src/cmd/mod.rs +++ b/helium-wallet/src/cmd/mod.rs @@ -92,6 +92,9 @@ pub struct CommitOpts { /// Minimum priority fee in micro lamports #[arg(long, default_value_t = priority_fee::MIN_PRIORITY_FEE)] min_priority_fee: u64, + /// Maximum priority fee in micro lamports + #[arg(long, default_value_t = priority_fee::MAX_PRIORITY_FEE)] + max_priority_fee: u64, /// Commit the transaction #[arg(long)] commit: bool, @@ -158,6 +161,7 @@ impl CommitOpts { pub fn transaction_opts>(&self, client: &C) -> TransactionOpts { TransactionOpts { min_priority_fee: self.min_priority_fee, + max_priority_fee: self.max_priority_fee, lut_addresses: if client::is_devnet(&client.as_ref().url()) { vec![message::COMMON_LUT_DEVNET] } else {