Skip to content

Commit

Permalink
Merge pull request #3 from drift-labs/crispheaney/priority-fees
Browse files Browse the repository at this point in the history
add priority fees
  • Loading branch information
crispheaney authored Apr 17, 2024
2 parents 18d4dc1 + c592ecf commit bef71a9
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 10 deletions.
4 changes: 4 additions & 0 deletions cli/src/bin/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ pub struct Args {
/// Payer keypair
#[clap(long, env)]
pub keypair_path: Option<String>,

/// Priority fee
#[clap(long, env)]
pub priority: Option<u64>,
}

impl Args {
Expand Down
17 changes: 16 additions & 1 deletion cli/src/bin/instructions/process_claim.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use solana_sdk::compute_budget::ComputeBudgetInstruction;
use crate::*;

pub fn process_claim(args: &Args, claim_args: &ClaimArgs) {
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
32 changes: 23 additions & 9 deletions cli/src/bin/instructions/process_fund_all.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use solana_sdk::compute_budget::ComputeBudgetInstruction;
use crate::*;

pub fn process_fund_all(args: &Args, fund_all_args: &FundAllArgs) {
Expand Down Expand Up @@ -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(),
Expand Down
12 changes: 12 additions & 0 deletions cli/src/bin/instructions/process_new_distributor.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use solana_sdk::compute_budget::ComputeBudgetInstruction;
use crate::*;

pub fn process_new_distributor(args: &Args, new_distributor_args: &NewDistributorArgs) {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit bef71a9

Please sign in to comment.