gmsol_timelock/states/
config.rs

1use anchor_lang::prelude::*;
2use gmsol_store::{states::Seed, CoreError};
3
4/// Timelock Config.
5#[account(zero_copy)]
6pub struct TimelockConfig {
7    version: u8,
8    pub(crate) bump: u8,
9    padding_0: [u8; 6],
10    delay: u32,
11    padding_1: [u8; 4],
12    pub(crate) store: Pubkey,
13    reserved: [u8; 256],
14}
15
16impl Seed for TimelockConfig {
17    const SEED: &'static [u8] = b"timelock_config";
18}
19
20impl gmsol_utils::InitSpace for TimelockConfig {
21    const INIT_SPACE: usize = std::mem::size_of::<Self>();
22}
23
24impl TimelockConfig {
25    pub(crate) fn init(&mut self, bump: u8, delay: u32, store: Pubkey) {
26        self.bump = bump;
27        self.delay = delay;
28        self.store = store;
29    }
30
31    /// Get delay.
32    pub fn delay(&self) -> u32 {
33        self.delay
34    }
35
36    /// Increase delay.
37    pub(crate) fn increase_delay(&mut self, delta: u32) -> Result<u32> {
38        let new_delay = self
39            .delay
40            .checked_add(delta)
41            .ok_or_else(|| error!(CoreError::InvalidArgument))?;
42        self.delay = new_delay;
43        Ok(new_delay)
44    }
45}