gmsol_utils/
role.rs

1use anchor_lang::prelude::*;
2use std::borrow::Borrow;
3
4/// Max length of the role anme.
5pub const MAX_ROLE_NAME_LEN: usize = 32;
6
7/// The key of a Role.
8#[derive(Clone, AnchorSerialize, AnchorDeserialize, InitSpace, PartialEq, Eq, PartialOrd, Ord)]
9#[cfg_attr(feature = "debug", derive(Debug))]
10pub struct RoleKey {
11    #[max_len(MAX_ROLE_NAME_LEN)]
12    name: String,
13}
14
15impl RoleKey {
16    /// Oracle Controller.
17    pub const ORACLE_CONTROLLER: &'static str = "ORACLE_CONTROLLER";
18
19    /// GT Controller.
20    pub const GT_CONTROLLER: &'static str = "GT_CONTROLLER";
21
22    /// Market Keeper.
23    pub const MARKET_KEEPER: &'static str = "MARKET_KEEPER";
24
25    /// Order Keeper.
26    pub const ORDER_KEEPER: &'static str = "ORDER_KEEPER";
27
28    /// Feature Keeper.
29    pub const FEATURE_KEEPER: &'static str = "FEATURE_KEEPER";
30
31    /// Config Keeper.
32    pub const CONFIG_KEEPER: &'static str = "CONFIG_KEEPER";
33
34    /// Restart Admin.
35    /// When the cluster restarts, this role can be used for **any** role, including ADMIN."
36    pub const RESTART_ADMIN: &'static str = "RESTART_ADMIN";
37
38    /// Price Keeper.
39    pub const PRICE_KEEPER: &'static str = "PRICE_KEEPER";
40
41    /// Migration Keeper.
42    pub const MIGRATION_KEEPER: &'static str = "MIGRATION_KEEPER";
43}
44
45impl Borrow<str> for RoleKey {
46    fn borrow(&self) -> &str {
47        &self.name
48    }
49}
50
51impl<'a> From<&'a str> for RoleKey {
52    fn from(value: &'a str) -> Self {
53        Self {
54            name: value.to_owned(),
55        }
56    }
57}