From c592ecfcda1eb553f69a28cfa396e0be0caed529 Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Fri, 5 Apr 2024 14:52:54 -0400 Subject: [PATCH] add priority fees --- cli/src/bin/cli.rs | 4 +++ cli/src/bin/instructions/process_claim.rs | 17 +++++++++- cli/src/bin/instructions/process_fund_all.rs | 32 +++++++++++++------ .../instructions/process_new_distributor.rs | 12 +++++++ 4 files changed, 55 insertions(+), 10 deletions(-) diff --git a/cli/src/bin/cli.rs b/cli/src/bin/cli.rs index ed18e91..fcfaf6b 100644 --- a/cli/src/bin/cli.rs +++ b/cli/src/bin/cli.rs @@ -64,6 +64,10 @@ pub struct Args { /// Payer keypair #[clap(long, env)] pub keypair_path: Option, + + /// Priority fee + #[clap(long, env)] + pub priority: Option, } impl Args { diff --git a/cli/src/bin/instructions/process_claim.rs b/cli/src/bin/instructions/process_claim.rs index cd5da55..165471a 100644 --- a/cli/src/bin/instructions/process_claim.rs +++ b/cli/src/bin/instructions/process_claim.rs @@ -1,3 +1,4 @@ +use solana_sdk::compute_budget::ComputeBudgetInstruction; use crate::*; pub fn process_claim(args: &Args, claim_args: &ClaimArgs) { @@ -32,6 +33,18 @@ pub fn process_claim(args: &Args, claim_args: &ClaimArgs) { let claimant_ata = get_associated_token_address(&claimant, &args.mint); + let mut ixs = vec![]; + + let priority_fee = args.priority.unwrap_or(0); + if priority_fee > 0 { + let instruction = ComputeBudgetInstruction::set_compute_unit_price(priority_fee); + ixs.push(instruction); + println!( + "Added priority fee instruction of {} microlamports", + priority_fee + ); + } + let claim_ix = Instruction { program_id: args.program_id, accounts: merkle_distributor::accounts::ClaimLocked { @@ -46,9 +59,11 @@ pub fn process_claim(args: &Args, claim_args: &ClaimArgs) { data: merkle_distributor::instruction::ClaimLocked {}.data(), }; + ixs.push(claim_ix); + let blockhash = client.get_latest_blockhash().unwrap(); let tx = Transaction::new_signed_with_payer( - &[claim_ix], + &ixs, Some(&claimant.key()), &[&keypair], blockhash, diff --git a/cli/src/bin/instructions/process_fund_all.rs b/cli/src/bin/instructions/process_fund_all.rs index 67516b8..f63fca4 100644 --- a/cli/src/bin/instructions/process_fund_all.rs +++ b/cli/src/bin/instructions/process_fund_all.rs @@ -1,3 +1,4 @@ +use solana_sdk::compute_budget::ComputeBudgetInstruction; use crate::*; pub fn process_fund_all(args: &Args, fund_all_args: &FundAllArgs) { @@ -32,16 +33,29 @@ pub fn process_fund_all(args: &Args, fund_all_args: &FundAllArgs) { continue; } + let mut ixs = vec![]; + + let priority_fee = args.priority.unwrap_or(0); + if priority_fee > 0 { + let instruction = ComputeBudgetInstruction::set_compute_unit_price(priority_fee); + ixs.push(instruction); + println!( + "Added priority fee instruction of {} microlamports", + priority_fee + ); + } + + ixs.push(spl_token::instruction::transfer( + &spl_token::id(), + &source_vault, + &token_vault, + &keypair.pubkey(), + &[], + merkle_tree.max_total_claim, + ).unwrap()); + let tx = Transaction::new_signed_with_payer( - &[spl_token::instruction::transfer( - &spl_token::id(), - &source_vault, - &token_vault, - &keypair.pubkey(), - &[], - merkle_tree.max_total_claim, - ) - .unwrap()], + &ixs, Some(&keypair.pubkey()), &[&keypair], client.get_latest_blockhash().unwrap(), diff --git a/cli/src/bin/instructions/process_new_distributor.rs b/cli/src/bin/instructions/process_new_distributor.rs index 66c9469..298d940 100644 --- a/cli/src/bin/instructions/process_new_distributor.rs +++ b/cli/src/bin/instructions/process_new_distributor.rs @@ -1,3 +1,4 @@ +use solana_sdk::compute_budget::ComputeBudgetInstruction; use crate::*; pub fn process_new_distributor(args: &Args, new_distributor_args: &NewDistributorArgs) { @@ -49,6 +50,17 @@ pub fn process_new_distributor(args: &Args, new_distributor_args: &NewDistributo } let mut ixs = vec![]; + + let priority_fee = args.priority.unwrap_or(0); + if priority_fee > 0 { + let instruction = ComputeBudgetInstruction::set_compute_unit_price(priority_fee); + ixs.push(instruction); + println!( + "Added priority fee instruction of {} microlamports", + priority_fee + ); + } + let token_vault = spl_associated_token_account::get_associated_token_address( &distributor_pubkey, &args.mint,