data_anchor_client/fees/
fee_strategy.rs1use solana_client::nonblocking::rpc_client::RpcClient;
2use solana_sdk::{
3 compute_budget::ComputeBudgetInstruction, instruction::Instruction, pubkey::Pubkey,
4};
5
6use super::{Fee, Priority};
7use crate::BloberClientResult;
8
9#[derive(Debug, Clone, Copy)]
11pub enum FeeStrategy {
12 Fixed(Fee),
14 BasedOnRecentFees(Priority),
16}
17
18impl Default for FeeStrategy {
19 fn default() -> Self {
20 Self::BasedOnRecentFees(Priority::default())
21 }
22}
23
24impl FeeStrategy {
25 pub async fn set_compute_unit_price(
31 &self,
32 client: &RpcClient,
33 mutable_accounts: &[Pubkey],
34 use_helius: bool,
35 ) -> BloberClientResult<Instruction> {
36 let compute_unit_price = match self {
37 Self::Fixed(fee) => fee.prioritization_fee_rate,
38 Self::BasedOnRecentFees(priority) => {
39 priority
40 .get_priority_fee_estimate(client, mutable_accounts, use_helius)
41 .await?
42 }
43 };
44 Ok(ComputeBudgetInstruction::set_compute_unit_price(
45 compute_unit_price.0,
46 ))
47 }
48}