Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set empty slot param, allow for min and max priority fees (with defaults) #443

Merged
merged 2 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions helium-lib/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,8 @@ pub async fn transfer_message<C: AsRef<SolanaRpcClient> + AsRef<DasClient>>(

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,
];

Expand Down Expand Up @@ -244,12 +240,8 @@ pub async fn burn_message<C: AsRef<SolanaRpcClient> + AsRef<DasClient>>(

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,
];

Expand Down
2 changes: 1 addition & 1 deletion helium-lib/src/boosting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub async fn start_boost_message<C: AsRef<SolanaRpcClient>>(
priority_fee::compute_price_instruction_for_accounts(
client,
&ix_accounts,
opts.min_priority_fee,
opts.fee_range(),
)
.await?,
],
Expand Down
8 changes: 4 additions & 4 deletions helium-lib/src/dc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub async fn mint_message<C: AsRef<SolanaRpcClient>>(
priority_fee::compute_price_instruction_for_accounts(
client,
&ix.accounts,
opts.min_priority_fee,
opts.fee_range(),
)
.await?,
ix,
Expand Down Expand Up @@ -145,7 +145,7 @@ pub async fn delegate_message<C: AsRef<SolanaRpcClient>>(
priority_fee::compute_price_instruction_for_accounts(
client,
&ix.accounts,
opts.min_priority_fee,
opts.fee_range(),
)
.await?,
ix,
Expand Down Expand Up @@ -202,7 +202,7 @@ pub async fn burn_message<C: AsRef<SolanaRpcClient>>(
priority_fee::compute_price_instruction_for_accounts(
client,
&ix.accounts,
opts.min_priority_fee,
opts.fee_range(),
)
.await?,
ix,
Expand Down Expand Up @@ -283,7 +283,7 @@ pub async fn burn_delegated_message<C: AsRef<SolanaRpcClient>>(
priority_fee::compute_price_instruction_for_accounts(
client,
&burn_ix.accounts,
opts.min_priority_fee,
opts.fee_range(),
)
.await?,
burn_ix,
Expand Down
12 changes: 4 additions & 8 deletions helium-lib/src/hotspot/dataonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -291,12 +291,8 @@ pub async fn issue_transaction<C: AsRef<SolanaRpcClient> + 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,
];

Expand Down
8 changes: 2 additions & 6 deletions helium-lib/src/hotspot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,8 @@ pub async fn direct_update_message<C: AsRef<SolanaRpcClient> + AsRef<DasClient>>

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,
];

Expand Down
10 changes: 9 additions & 1 deletion helium-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,34 @@ 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<client::SolanaRpcClient>) -> Result<(), error::Error> {
kta::init(solana_client)
}

pub struct TransactionOpts {
pub min_priority_fee: u64,
pub max_priority_fee: u64,
pub lut_addresses: Vec<Pubkey>,
}

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<u64> {
RangeInclusive::new(self.min_priority_fee, self.max_priority_fee)
}
}

pub async fn mk_transaction_with_blockhash<C: AsRef<SolanaRpcClient>>(
client: &C,
ixs: &[Instruction],
Expand Down
2 changes: 1 addition & 1 deletion helium-lib/src/memo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub async fn memo_message<C: AsRef<SolanaRpcClient>>(
priority_fee::compute_price_instruction_for_accounts(
client,
&ix.accounts,
opts.min_priority_fee,
opts.fee_range(),
)
.await?,
ix,
Expand Down
33 changes: 20 additions & 13 deletions helium-lib/src/priority_fee.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::ops::RangeInclusive;

use crate::{
anchor_lang::ToAccountMetas, client::SolanaRpcClient, error::Error, keypair::Pubkey,
solana_client,
Expand All @@ -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<C: AsRef<SolanaRpcClient>>(
pub async fn get_estimate<C: AsRef<SolanaRpcClient>>(
client: &C,
accounts: &impl ToAccountMetas,
min_priority_fee: u64,
fee_range: RangeInclusive<u64>,
) -> Result<u64, Error> {
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
}
}

Expand All @@ -35,10 +38,10 @@ mod helius {
use serde::Deserialize;
use serde_json::json;

pub async fn get_estimate_with_min<C: AsRef<SolanaRpcClient>>(
pub async fn get_estimate<C: AsRef<SolanaRpcClient>>(
client: &C,
accounts: &impl ToAccountMetas,
min_priority_fee: u64,
fee_range: RangeInclusive<u64>,
) -> Result<u64, Error> {
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
Expand All @@ -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<C: AsRef<SolanaRpcClient>>(
pub async fn get_estimate<C: AsRef<SolanaRpcClient>>(
client: &C,
accounts: &impl ToAccountMetas,
min_priority_fee: u64,
fee_range: RangeInclusive<u64>,
) -> Result<u64, Error> {
let account_keys: Vec<_> = account_keys(accounts).collect();
let recent_fees = client
Expand All @@ -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)
}
}
Expand All @@ -114,8 +121,8 @@ pub fn compute_price_instruction(priority_fee: u64) -> solana_sdk::instruction::
pub async fn compute_price_instruction_for_accounts<C: AsRef<SolanaRpcClient>>(
client: &C,
accounts: &impl ToAccountMetas,
min_priority_fee: u64,
fee_range: RangeInclusive<u64>,
) -> Result<solana_sdk::instruction::Instruction, Error> {
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))
}
4 changes: 2 additions & 2 deletions helium-lib/src/reward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ pub async fn claim_transaction<C: AsRef<DasClient> + AsRef<SolanaRpcClient> + Ge
priority_fee::compute_price_instruction_for_accounts(
client,
&ixs_accounts,
opts.min_priority_fee,
opts.fee_range(),
)
.await?,
];
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions helium-wallet/src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -158,6 +161,7 @@ impl CommitOpts {
pub fn transaction_opts<C: AsRef<SolanaRpcClient>>(&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 {
Expand Down
Loading