use solana_client::nonblocking::rpc_client::RpcClient;
use solana_sdk::{
compute_budget::ComputeBudgetInstruction, instruction::Instruction, pubkey::Pubkey,
};
use super::{Fee, Priority};
use crate::BloberClientResult;
#[derive(Debug, Clone, Copy)]
pub enum FeeStrategy {
Fixed(Fee),
BasedOnRecentFees(Priority),
}
impl Default for FeeStrategy {
fn default() -> Self {
Self::BasedOnRecentFees(Priority::default())
}
}
impl FeeStrategy {
pub async fn set_compute_unit_price(
&self,
client: &RpcClient,
mutable_accounts: &[Pubkey],
use_helius: bool,
) -> BloberClientResult<Instruction> {
let compute_unit_price = match self {
Self::Fixed(fee) => fee.prioritization_fee_rate,
Self::BasedOnRecentFees(priority) => {
priority
.get_priority_fee_estimate(client, mutable_accounts, use_helius)
.await?
}
};
Ok(ComputeBudgetInstruction::set_compute_unit_price(
compute_unit_price.0,
))
}
}