Skip to content

Commit

Permalink
priority fee cap
Browse files Browse the repository at this point in the history
  • Loading branch information
miralandlabs committed Aug 15, 2024
1 parent 038ac5d commit 13aab4b
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 11 deletions.
97 changes: 97 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ bytemuck = "1.16"
cached = "0.46.1"
chrono = "0.4.38"
clap = { version = "4.4.12", features = ["derive"] }
color-eyre = { version = "0.6" }
colored = "2.0"
core_affinity = "0.8.1"
drillx = "2.0.0"
Expand Down
2 changes: 1 addition & 1 deletion src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pub struct MineArgs {
long,
short,
value_name = "EXTRA_FEE_PERCENT",
help = "The extra percentage that the miner thinks deserves to pay more priority fee. Integer range 0..100 inclusive and the final priority fee cannot exceed the priority fee cap.",
help = "The extra percentage that the miner feels deserves to pay more of the priority fee. A positive integer in the range 0..100 [inclusive] is preferred (although integer > 100 is possible, but not recommended), and the final priority fee cannot exceed the priority fee cap.",
default_value = "0"
)]
pub extra_fee_percent: u64,
Expand Down
10 changes: 7 additions & 3 deletions src/dynamic_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,14 @@ impl Miner {
match calculated_fee {
Err(err) => Err(err),
Ok(fee) => {
if let Some(max_fee) = self.priority_fee {
Ok(fee.min(max_fee))
if let Some(max_fee) = self.priority_fee_cap {
// MI vanilla
// Ok(fee.min(max_fee))
Ok((fee + 5000).min(max_fee)) // add extra 5000 microlamports as buffer
} else {
Ok(fee)
// MI vanilla
// Ok(fee)
Ok(fee + 5000)
}
}
}
Expand Down
38 changes: 33 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ mod utils;
use std::sync::Arc;

use args::*;
use clap::{command, Parser, Subcommand};
use clap::{
builder::{
styling::{AnsiColor, Effects},
Styles,
},
command, Parser, Subcommand,
};
use solana_client::nonblocking::rpc_client::RpcClient;
use solana_sdk::{
commitment_config::CommitmentConfig,
Expand All @@ -32,6 +38,7 @@ use solana_sdk::{
struct Miner {
pub keypair_filepath: Option<String>,
pub priority_fee: Option<u64>,
pub priority_fee_cap: Option<u64>,
pub dynamic_fee_url: Option<String>,
pub dynamic_fee: bool,
pub rpc_client: Arc<RpcClient>,
Expand Down Expand Up @@ -83,7 +90,7 @@ enum Commands {
}

#[derive(Parser, Debug)]
#[command(about, version)]
#[command(about, version, styles = styles())]
struct Args {
#[arg(
long,
Expand Down Expand Up @@ -120,13 +127,22 @@ struct Args {

#[arg(
long,
value_name = "MICROLAMPORTS",
help = "Price to pay for compute units. If dynamic fees are enabled, this value will be used as the cap.",
default_value = "500000",
value_name = "FEE_MICROLAMPORTS",
help = "Price to pay for compute units when dynamic fee flag is off, or dynamic fee is unavailable.",
default_value = "20000",
global = true
)]
priority_fee: Option<u64>,

#[arg(
long,
value_name = "FEE_CAP_MICROLAMPORTS",
help = "Max price to pay for compute units when dynamic fees are enabled.",
default_value = "500000",
global = true
)]
priority_fee_cap: Option<u64>,

#[arg(
long,
value_name = "DYNAMIC_FEE_URL",
Expand Down Expand Up @@ -154,6 +170,7 @@ struct Args {

#[tokio::main]
async fn main() {
color_eyre::install().unwrap();
let args = Args::parse();

// Load the config file from custom path, the default path, or use default config values
Expand All @@ -177,6 +194,7 @@ async fn main() {
let miner = Arc::new(Miner::new(
Arc::new(rpc_client),
args.priority_fee,
args.priority_fee_cap,
Some(default_keypair),
args.dynamic_fee_url,
args.dynamic_fee,
Expand Down Expand Up @@ -233,6 +251,7 @@ impl Miner {
pub fn new(
rpc_client: Arc<RpcClient>,
priority_fee: Option<u64>,
priority_fee_cap: Option<u64>,
keypair_filepath: Option<String>,
dynamic_fee_url: Option<String>,
dynamic_fee: bool,
Expand All @@ -243,6 +262,7 @@ impl Miner {
rpc_client,
keypair_filepath,
priority_fee,
priority_fee_cap,
dynamic_fee_url,
dynamic_fee,
fee_payer_filepath,
Expand All @@ -266,3 +286,11 @@ impl Miner {
}
}
}

fn styles() -> Styles {
Styles::styled()
.header(AnsiColor::Red.on_default() | Effects::BOLD)
.usage(AnsiColor::Red.on_default() | Effects::BOLD)
.literal(AnsiColor::Blue.on_default() | Effects::BOLD)
.placeholder(AnsiColor::Green.on_default())
}
4 changes: 2 additions & 2 deletions src/send_and_confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ impl Miner {
}) = difficulty_payload
{
if solution_difficulty > extra_fee_difficulty {
prio_fee = if let Some(priority_fee) = self.priority_fee {
priority_fee.min(
prio_fee = if let Some(priority_fee_cap) = self.priority_fee_cap {
priority_fee_cap.min(
prio_fee
.saturating_mul(
100u64.saturating_add(extra_fee_percent),
Expand Down

0 comments on commit 13aab4b

Please sign in to comment.