Skip to content

Commit

Permalink
Use mean priority fee instead of max. Also adjust compute unit limits
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed Apr 18, 2024
1 parent 97e2e53 commit 0b28453
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
18 changes: 14 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,22 @@ fn apply_priority_fee(
let recent_compute_unit_prices =
rpc_client_utils::get_recent_priority_fees_for_instructions(rpc_client, instructions)?;

let compute_unit_price_micro_lamports = recent_compute_unit_prices
let mean_compute_unit_price_micro_lamports =
recent_compute_unit_prices.iter().copied().sum::<u64>()
/ recent_compute_unit_prices.len() as u64;

/*
let max_compute_unit_price_micro_lamports = recent_compute_unit_prices
.iter()
.max()
.copied()
.unwrap_or_default();
println!("{recent_compute_unit_prices:?}: mean {mean_compute_unit_price_micro_lamports}, max {max_compute_unit_price_micro_lamports}");
*/

let compute_unit_price_micro_lamports = mean_compute_unit_price_micro_lamports;

if let Ok(priority_fee_estimate) = helius_rpc::get_priority_fee_estimate_for_instructions(
rpc_client,
helius_rpc::HeliusPriorityLevel::High,
Expand Down Expand Up @@ -3331,7 +3341,7 @@ async fn process_account_sweep<T: Signers>(

let (signature, maybe_transaction) = match existing_signature {
None => {
apply_priority_fee(rpc_client, &mut instructions, 10_000, priority_fee)?;
apply_priority_fee(rpc_client, &mut instructions, 7_000, priority_fee)?;

let mut message = Message::new(&instructions, Some(&from_authority_address));
message.recent_blockhash = recent_blockhash;
Expand Down Expand Up @@ -3944,7 +3954,7 @@ async fn process_account_wrap<T: Signers>(
spl_token::instruction::sync_native(&spl_token::id(), &wsol_address).unwrap(),
]);

apply_priority_fee(rpc_client, &mut instructions, 10_000, priority_fee)?;
apply_priority_fee(rpc_client, &mut instructions, 5_000, priority_fee)?;
let message = Message::new(&instructions, Some(&authority_address));

let mut transaction = Transaction::new_unsigned(message);
Expand Down Expand Up @@ -4040,7 +4050,7 @@ async fn process_account_unwrap<T: Signers>(
)
.unwrap(),
];
apply_priority_fee(rpc_client, &mut instructions, 10_000, priority_fee)?;
apply_priority_fee(rpc_client, &mut instructions, 5_000, priority_fee)?;

let message = Message::new(&instructions, Some(&authority_address));

Expand Down
5 changes: 4 additions & 1 deletion src/rpc_client_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ pub async fn get_signature_date(
}
}

// Returns a sorted list of compute unit prices in micro lamports, from low to high
pub fn get_recent_priority_fees_for_instructions(
rpc_client: &RpcClient,
instructions: &[Instruction],
Expand All @@ -118,7 +119,7 @@ pub fn get_recent_priority_fees_for_instructions(
account_keys.sort();
account_keys.dedup();

let prioritization_fees: Vec<_> = rpc_client
let mut prioritization_fees: Vec<_> = rpc_client
.get_recent_prioritization_fees(&account_keys)
.map(|response| {
response
Expand All @@ -128,5 +129,7 @@ pub fn get_recent_priority_fees_for_instructions(
})
.map_err(|err| format!("Failed to invoke RPC method getRecentPrioritizationFees: {err}"))?;

prioritization_fees.sort();

Ok(prioritization_fees)
}

0 comments on commit 0b28453

Please sign in to comment.