Skip to main content

sss_token/utils/
access_control.rs

1use anchor_lang::prelude::*;
2
3use crate::errors::SssError;
4use crate::state::{Role, RoleRegistry, StablecoinConfig};
5
6pub fn require_not_paused(config: &StablecoinConfig) -> Result<()> {
7    require!(!config.is_paused, SssError::ProgramPaused);
8    Ok(())
9}
10
11pub fn require_paused(config: &StablecoinConfig) -> Result<()> {
12    require!(config.is_paused, SssError::ProgramNotPaused);
13    Ok(())
14}
15
16pub fn require_role(roles: &RoleRegistry, authority: &Pubkey, role: Role) -> Result<()> {
17    require!(roles.has_role(authority, role), SssError::Unauthorized);
18    Ok(())
19}
20
21pub fn require_master_authority(roles: &RoleRegistry, authority: &Pubkey) -> Result<()> {
22    require_role(roles, authority, Role::MasterAuthority)
23}
24
25pub fn require_freeze_authority(role_registry: &RoleRegistry, authority: &Pubkey) -> Result<()> {
26    require!(
27        *authority == role_registry.master_authority || *authority == role_registry.pauser,
28        SssError::InvalidAuthority
29    );
30    Ok(())
31}