1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
use anchor_lang::prelude::*;
use hpl_utils::Default;
/// Account representing delegated authority for a project.
/// This account stores permissions granted to accounts to perform certain actions on behalf of the project authority.
/// PDA: [ 'delegate_authority', project, authority, delegate ]
/// Category: delegate_state
#[account]
#[derive(PartialEq, Eq, Debug)]
pub struct DelegateAuthority {
    /// Bump value used for PDA.
    pub bump: u8,
    /// Public key of the project associated with this delegated authority.
    pub project: Pubkey,
    /// Public key of the authority getting these permissions.
    pub authority: Pubkey,
    /// List of service delegations, each specifying the program and its permissions.
    pub delegations: Vec<ServiceDelegation>,
}
/// Default implementation for the `DelegateAuthority` struct.
/// It sets default values for each field when creating a new `DelegateAuthority` instance.
impl Default for DelegateAuthority {
    const LEN: usize = 96 + 8; // base size + 8 align
    /// Sets default values for each field of the `DelegateAuthority` struct.
    fn set_defaults(&mut self) {
        self.bump = 0;
        self.project = Pubkey::default();
        self.authority = Pubkey::default();
        self.delegations = vec![];
    }
}
/// Enum representing different types of service delegations and their permissions.
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Eq, PartialEq)]
pub enum ServiceDelegation {
    /// Master program delegation with a specific set of permissions.
    Master {
        /// The permissions granted to the master program.
        permission: MasterProgramPermission,
    },
    /// Asset hub program delegation with a specific set of permissions and an associated index.
    AssetHub {
        /// Index of the service in the service vector in the project struct.
        index: u8,
        /// The permissions granted to the asset hub programs.
        permission: AssetHubPermission,
    },
    /// Nectar utility program delegation with a specific set of permissions and an associated index.
    NectarUtility {
        /// Index of the service in the service vector in the project struct.
        index: u8,
        /// The permissions granted to the Nectar utility programs.
        permission: NectarUtilityPermission,
    },
}
/// Implementation for the `ServiceDelegation` enum.
impl ServiceDelegation {
    /// Length of the `ServiceDelegation` enum in bytes.
    pub const LEN: usize = 3; // base size
}
/// Enum representing different types of permissions for the master program delegation.
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Eq, PartialEq)]
pub enum MasterProgramPermission {
    /// Permission to manage criterias i.e, collections and creators.
    ManageCriterias,
    /// Permission to manage services.
    ManageServices,
    /// Permission to manage indexing.
    ManageIndexing,
    /// Permission to manage profiles.
    ManageProfiles,
}
/// Enum representing different types of permissions for the asset hub program delegation.
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Eq, PartialEq)]
pub enum AssetHubPermission {
    /// Permission to manage assembler.
    ManageAssembler,
    /// Permission to update block.
    UpdateBlock,
    /// Permission to update block definition.
    UpdateBlockDefinition,
    /// Permission to update NFT.
    UpdateNFT,
    /// Permission for initial art generation.
    InitialArtGeneration,
    /// Permission to manage assets.
    ManageAssets,
}
/// Enum representing different types of permissions for the Nectar utility program delegation.
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Eq, PartialEq)]
pub enum NectarUtilityPermission {
    /// Permission to manage the staking pool.
    ManageStakingPool,
    /// Permission to withdraw staking pool rewards.
    WithdrawStakingPoolRewards,
    /// Permission to manage the mission pool.
    ManageMissionPool,
    /// Permission to withdraw mission pool rewards.
    WithdrawMissionPoolRewards,
}