use serde::{Deserialize, Serialize};
use solana_pubkey::Pubkey;
use crate::chain::Address;
use crate::exact::{PHANTOM_LIGHTHOUSE_PROGRAM, SOLFLARE_LIGHTHOUSE_PROGRAM, SPL_MEMO_PROGRAM};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SolanaExactFacilitatorConfig {
#[serde(default = "default_allow_additional_instructions")]
pub allow_additional_instructions: bool,
#[serde(default = "default_max_instruction_count")]
pub max_instruction_count: usize,
#[serde(default = "default_allowed_program_ids")]
pub allowed_program_ids: Vec<Address>,
#[serde(default)]
pub blocked_program_ids: Vec<Address>,
}
const fn default_allow_additional_instructions() -> bool {
true
}
const fn default_max_instruction_count() -> usize {
6
}
fn default_allowed_program_ids() -> Vec<Address> {
vec![
Address::new(*PHANTOM_LIGHTHOUSE_PROGRAM),
Address::new(*SOLFLARE_LIGHTHOUSE_PROGRAM),
Address::new(SPL_MEMO_PROGRAM),
]
}
impl Default for SolanaExactFacilitatorConfig {
fn default() -> Self {
Self {
allow_additional_instructions: default_allow_additional_instructions(),
max_instruction_count: default_max_instruction_count(),
allowed_program_ids: default_allowed_program_ids(),
blocked_program_ids: Vec::new(),
}
}
}
impl SolanaExactFacilitatorConfig {
#[must_use]
pub fn is_blocked(&self, program_id: &Pubkey) -> bool {
self.blocked_program_ids
.iter()
.any(|addr| addr.pubkey() == program_id)
}
#[must_use]
pub fn is_allowed(&self, program_id: &Pubkey) -> bool {
self.allowed_program_ids
.iter()
.any(|addr| addr.pubkey() == program_id)
}
}