use serde::{Deserialize, Serialize};
use steel::*;
use crate::state::{config_pda, OreAccountV4};
use super::OreAccountV1;
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable, Serialize, Deserialize)]
pub struct ConfigV1 {
pub admin: Pubkey,
pub buffer_a: [u8; 32],
pub buffer_b: [u8; 32],
pub buffer_c: [u8; 32],
pub buffer_d: [u8; 32],
pub buffer_e: [u8; 8],
}
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable, Serialize, Deserialize)]
pub struct ConfigV4 {
pub admin: AdminConfig,
pub protocol: ProtocolConfig,
}
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable, Serialize, Deserialize)]
pub struct AdminConfig {
pub authority: Pubkey,
pub fee_collector: Pubkey,
pub fee_rate: u64,
}
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable, Serialize, Deserialize)]
pub struct ProtocolConfig {
pub authority: Pubkey,
pub fee_collector: Pubkey,
pub fee_rate: u64,
pub intermission_slots: u64,
pub round_slots: u64,
pub entropy_var_address: Pubkey,
pub entropy_program_id: Pubkey,
}
impl ConfigV1 {
pub fn pda() -> (Pubkey, u8) {
config_pda()
}
}
impl ConfigV4 {
pub fn pda() -> (Pubkey, u8) {
config_pda()
}
}
account!(OreAccountV1, ConfigV1);
account!(OreAccountV4, ConfigV4);
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
pub enum Config {
V1(ConfigV1),
V4(ConfigV4),
}
impl Config {
pub fn admin(&self) -> Pubkey {
match self {
Config::V1(c) => c.admin,
Config::V4(c) => c.admin.authority,
}
}
pub fn buffer_a(&self) -> [u8; 32] {
match self {
Config::V1(c) => c.buffer_a,
Config::V4(_) => [0; 32],
}
}
pub fn buffer_b(&self) -> [u8; 32] {
match self {
Config::V1(c) => c.buffer_b,
Config::V4(_) => [0; 32],
}
}
pub fn buffer_c(&self) -> [u8; 32] {
match self {
Config::V1(c) => c.buffer_c,
Config::V4(_) => [0; 32],
}
}
pub fn buffer_d(&self) -> [u8; 32] {
match self {
Config::V1(c) => c.buffer_d,
Config::V4(_) => [0; 32],
}
}
pub fn buffer_e(&self) -> [u8; 8] {
match self {
Config::V1(c) => c.buffer_e,
Config::V4(_) => [0; 8],
}
}
}