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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
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 {
/// Hive Control delegation with a specific set of permissions.
HiveControl {
/// The permissions granted to the Hive Control.
permission: HiveControlPermission,
},
/// Asset Assembler program delegation with a specific set of permissions and an associated index.
AssetAssembler {
/// Index of the service in the service vector in the project struct.
index: u8,
/// The permissions granted to the asset Assembler programs.
permission: AssetAssemblerPermission,
},
/// Asset Manager program delegation with a specific set of permissions and an associated index.
AssetManager {
/// Index of the service in the service vector in the project struct.
index: u8,
/// The permissions granted to the asset Manager programs.
permission: AssetManagerPermission,
},
/// Currency Manager program delegation with a specific set of permissions and an associated index.
CurrencyManager {
/// The permissions granted to the Currency Manager programs.
permission: CurrencyManagerPermission,
},
/// Nectar Staking program delegation with a specific set of permissions and an associated index.
NectarStaking {
/// Index of the service in the service vector in the project struct.
index: u8,
/// The permissions granted to the Nectar staking programs.
permission: NectarStakingPermission,
},
/// Nectar Missions program delegation with a specific set of permissions and an associated index.
NectarMissions {
/// Index of the service in the service vector in the project struct.
index: u8,
/// The permissions granted to the Nectar Missions programs.
permission: NectarMissionsPermission,
},
/// Buzz Guild program delegation with a specific set of permissions and an associated index.
BuzzGuild {
/// Index of the service in the service vector in the project struct.
index: u8,
/// The permissions granted to the Buzz Guild programs.
permission: BuzzGuildPermission,
},
}
impl ServiceDelegation {
/// Returns the byte length of the service delegation.
pub const LEN: usize = 3;
/// Returns the index of the service in the service vector in the project struct.
pub fn get_index(&self) -> u8 {
match self {
ServiceDelegation::AssetAssembler { index, .. } => *index,
ServiceDelegation::AssetManager { index, .. } => *index,
ServiceDelegation::CurrencyManager { .. } => 0,
ServiceDelegation::NectarStaking { index, .. } => *index,
ServiceDelegation::NectarMissions { index, .. } => *index,
ServiceDelegation::BuzzGuild { index, .. } => *index,
_ => 0,
}
}
}
/// Enum representing different types of permissions for the master program delegation.
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Eq, PartialEq)]
pub enum HiveControlPermission {
/// 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 assembler program delegation.
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Eq, PartialEq)]
pub enum AssetAssemblerPermission {
/// 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,
}
/// Enum representing different types of permissions for the asset manager delegation.
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Eq, PartialEq)]
pub enum AssetManagerPermission {
/// Permission to manage assets.
ManageAssets,
}
/// Enum representing different types of permissions for the currency manager delegation.
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Eq, PartialEq)]
pub enum CurrencyManagerPermission {
/// Permission to manage currencies.
ManageCurrencies,
/// Permission to mint currencies.
MintCurrencies,
/// Permission to manage currency status.
ManageCurrencyStatus,
}
/// Enum representing different types of permissions for the Nectar staking delegation.
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Eq, PartialEq)]
pub enum NectarStakingPermission {
/// Permission to manage the staking pool.
ManageStakingPool,
/// Permission to withdraw staking pool rewards.
WithdrawStakingPoolRewards,
}
/// Enum representing different types of permissions for the Nectar missions delegation.
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Eq, PartialEq)]
pub enum NectarMissionsPermission {
/// Permission to manage the mission pool.
ManageMissionPool,
/// Permission to withdraw mission pool rewards.
WithdrawMissionPoolRewards,
}
/// Enum representing different types of permissions for the Buzz guild delegation.
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Eq, PartialEq)]
pub enum BuzzGuildPermission {
/// Permission to manage the guild kits.
ManageGuildKit,
}