clockwork_pool_program/objects/
config.rs

1use anchor_lang::{prelude::*, AnchorDeserialize};
2
3pub const SEED_CONFIG: &[u8] = b"config";
4
5/**
6 * Config
7 */
8
9#[account]
10#[derive(Debug)]
11pub struct Config {
12    pub admin: Pubkey,
13    pub pool_authority: Pubkey,
14}
15
16impl Config {
17    pub fn pubkey() -> Pubkey {
18        Pubkey::find_program_address(&[SEED_CONFIG], &crate::ID).0
19    }
20}
21
22impl TryFrom<Vec<u8>> for Config {
23    type Error = Error;
24    fn try_from(data: Vec<u8>) -> std::result::Result<Self, Self::Error> {
25        Config::try_deserialize(&mut data.as_slice())
26    }
27}
28
29/**
30 * ConfigSettings
31 */
32
33#[derive(AnchorSerialize, AnchorDeserialize)]
34pub struct ConfigSettings {
35    pub admin: Pubkey,
36    pub pool_authority: Pubkey,
37}
38
39/**
40 * ConfigAccount
41 */
42
43pub trait ConfigAccount {
44    fn init(&mut self, admin: Pubkey, pool_authority: Pubkey) -> Result<()>;
45
46    fn update(&mut self, settings: ConfigSettings) -> Result<()>;
47}
48
49impl ConfigAccount for Account<'_, Config> {
50    fn init(&mut self, admin: Pubkey, pool_authority: Pubkey) -> Result<()> {
51        self.admin = admin;
52        self.pool_authority = pool_authority;
53        Ok(())
54    }
55
56    fn update(&mut self, settings: ConfigSettings) -> Result<()> {
57        self.admin = settings.admin;
58        self.pool_authority = settings.pool_authority;
59        Ok(())
60    }
61}