gmsol_timelock/
lib.rs

1use anchor_lang::prelude::*;
2
3/// States.
4pub mod states;
5
6/// Roles for the timelock program.
7pub mod roles;
8
9/// Instructions;
10pub mod instructions;
11
12use gmsol_store::{utils::CpiAuthenticate, CoreError};
13use instructions::*;
14
15declare_id!("TimeBQ7gQyWyQMD3bTteAdy7hTVDNWSwELdSVZHfSXL");
16
17#[program]
18pub mod gmsol_timelock {
19
20    use super::*;
21
22    /// Initialize timelock config.
23    #[access_control(CpiAuthenticate::only(&ctx, roles::TIMELOCK_ADMIN))]
24    pub fn initialize_config(ctx: Context<InitializeConfig>, delay: u32) -> Result<()> {
25        instructions::unchecked_initialize_config(ctx, delay)
26    }
27
28    /// Increase timelock delay.
29    #[access_control(CpiAuthenticate::only(&ctx, roles::TIMELOCK_ADMIN))]
30    pub fn increase_delay(ctx: Context<IncreaseDelay>, delta: u32) -> Result<()> {
31        instructions::unchecked_increase_delay(ctx, delta)
32    }
33
34    /// Initialize executor.
35    pub fn initialize_executor(ctx: Context<InitializeExecutor>, role: String) -> Result<()> {
36        instructions::initialize_executor(ctx, &role)
37    }
38
39    /// Create instruction buffer.
40    #[access_control(CpiAuthenticate::only(&ctx, roles::TIMELOCK_KEEPER))]
41    pub fn create_instruction_buffer<'info>(
42        ctx: Context<'_, '_, 'info, 'info, CreateInstructionBuffer<'info>>,
43        num_accounts: u16,
44        data_len: u16,
45        data: Vec<u8>,
46        signers: Vec<u16>,
47    ) -> Result<()> {
48        instructions::unchecked_create_instruction_buffer(
49            ctx,
50            num_accounts,
51            data_len,
52            &data,
53            &signers,
54        )
55    }
56
57    /// Approve instruction.
58    pub fn approve_instruction(ctx: Context<ApproveInstruction>, role: String) -> Result<()> {
59        instructions::approve_instruction(ctx, &role)
60    }
61
62    /// Approve multiple instructions.
63    pub fn approve_instructions<'info>(
64        ctx: Context<'_, '_, 'info, 'info, ApproveInstructions<'info>>,
65        role: String,
66    ) -> Result<()> {
67        instructions::approve_instructions(ctx, &role)
68    }
69
70    /// Cancel instruction.
71    #[access_control(CpiAuthenticate::only(&ctx, roles::TIMELOCK_ADMIN))]
72    pub fn cancel_instruction(ctx: Context<CancelInstruction>) -> Result<()> {
73        instructions::unchecked_cancel_instruction(ctx)
74    }
75
76    /// Cancel multiple instructions that sharing the same `executor` and `rent_receiver`.
77    #[access_control(CpiAuthenticate::only(&ctx, roles::TIMELOCK_ADMIN))]
78    pub fn cancel_instructions<'info>(
79        ctx: Context<'_, '_, 'info, 'info, CancelInstructions<'info>>,
80    ) -> Result<()> {
81        instructions::unchecked_cancel_instructions(ctx)
82    }
83
84    /// Execute instruction.
85    #[access_control(CpiAuthenticate::only(&ctx, roles::TIMELOCK_KEEPER))]
86    pub fn execute_instruction(ctx: Context<ExecuteInstruction>) -> Result<()> {
87        instructions::unchecked_execute_instruction(ctx)
88    }
89
90    /// Revoke role.
91    #[access_control(CpiAuthenticate::only(&ctx, roles::TIMELOCKED_ADMIN))]
92    pub fn revoke_role(ctx: Context<RevokeRole>, role: String) -> Result<()> {
93        instructions::unchecked_revoke_role(ctx, role)
94    }
95
96    /// Set expected price provider.
97    #[access_control(CpiAuthenticate::only(&ctx, roles::TIMELOCKED_MARKET_KEEPER))]
98    pub fn set_expected_price_provider(
99        ctx: Context<SetExpectedPriceProvider>,
100        new_expected_price_provider: u8,
101    ) -> Result<()> {
102        instructions::unchecked_set_expected_price_provider(
103            ctx,
104            new_expected_price_provider
105                .try_into()
106                .map_err(|_| error!(CoreError::InvalidProviderKindIndex))?,
107        )
108    }
109}