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
198
199
200
201
202
203
pub mod delegate_state;
pub mod events;
pub mod indexing_state;
pub mod project_state;
pub mod user_state;

pub use {delegate_state::*, events::*, indexing_state::*, project_state::*, user_state::*};

use {
    crate::constants::ACTIONS, anchor_lang::prelude::*, hpl_utils::Default,
    std::collections::HashMap,
};

#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Eq, PartialEq)]
pub enum Service {
    Assembler { assembler_id: Pubkey },
    AssetManager { asset_manager_id: Pubkey },
    Paywall,
    Staking { pool_id: Pubkey },
    Missions { pool_id: Pubkey },
    Raffles { pool_id: Pubkey },
    GuildKit { kit_id: Pubkey },
    GameState,
    MatchMaking,
}

#[derive(Clone, PartialEq)]
pub enum ActionType<'a> {
    Public,
    Restricted {
        delegations: &'a [ServiceDelegation],
    },
}

#[derive(Clone, PartialEq)]

pub struct Action<'a> {
    pub fee: u64,
    pub action_type: ActionType<'a>,
}

pub struct Actions<'a> {
    // General Actions
    pub fee_exempt: Action<'a>,
    pub public_low: Action<'a>,
    pub public_high: Action<'a>,
    pub driver_action: Action<'a>,

    // Hive Control Actions
    pub create_project: Action<'a>,
    pub manage_criterias: Action<'a>,
    pub add_service: Action<'a>,
    pub remove_service: Action<'a>,
    pub manage_indexing: Action<'a>,
    pub manage_delegate_authority: Action<'a>,
    pub manage_profiles: Action<'a>,

    // Asset Assembler Actions
    pub manage_assembler: Action<'a>,

    // Asset Manager Actions
    pub manage_assets: Action<'a>,

    // Currency Manager Actions
    pub manage_currencies: Action<'a>,
    pub mint_currencies: Action<'a>,
    pub manage_currency_status: Action<'a>,

    // Nectar Staking Actions
    pub manage_staking_pool: Action<'a>,
    pub withdraw_staking_pool_rewards: Action<'a>,

    // Nectar Missions Actions
    pub manage_mission_pool: Action<'a>,
    pub withdraw_mission_pool_rewards: Action<'a>,

    // Buzz Guild Actions
    pub manage_guild_kit: Action<'a>,
}

#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, PartialEq, Eq)]
pub enum SerializableActions {
    // General Actions
    FeeExempt,
    PublicLow,
    PublicHigh,
    DriverAction,

    // Hive Control Actions
    CreateProject,
    ManageCriterias,
    AddService,
    RemoveService,
    ManageIndexing,
    ManageDelegateAuthority,
    ManageProfiles,

    // Asset Assembler Actions
    ManageAssembler,

    // Asset Manager Actions
    ManageAssets,

    // Currency Manager Actions
    ManageCurrencies,
    MintCurrencies,
    ManageCurrencyStatus,

    // Nectar Staking Actions
    ManageStakingPool,
    WithdrawStakingPoolRewards,

    // Nectar Missions Actions
    ManageMissionPool,
    WithdrawMissionPoolRewards,

    // Buzz Guild Kit Actions
    ManageGuildKit,
}

impl SerializableActions {
    pub fn to_action<'a>(&self) -> Action<'a> {
        Action::from(self)
    }
    pub fn is_equal(&self, action: &Action) -> bool {
        *action == self.to_action()
    }
}

impl<'a> From<&SerializableActions> for Action<'a> {
    fn from(action: &SerializableActions) -> Action<'a> {
        match action {
            // General Actions
            SerializableActions::FeeExempt => ACTIONS.fee_exempt,
            SerializableActions::PublicLow => ACTIONS.public_low,
            SerializableActions::PublicHigh => ACTIONS.public_high,
            SerializableActions::DriverAction => ACTIONS.driver_action,

            // Hive Control Actions
            SerializableActions::CreateProject => ACTIONS.create_project,
            SerializableActions::ManageCriterias => ACTIONS.manage_criterias,
            SerializableActions::AddService => ACTIONS.add_service,
            SerializableActions::RemoveService => ACTIONS.remove_service,
            SerializableActions::ManageIndexing => ACTIONS.manage_indexing,
            SerializableActions::ManageDelegateAuthority => ACTIONS.manage_delegate_authority,
            SerializableActions::ManageProfiles => ACTIONS.manage_profiles,

            // Asset Assembler Actions
            SerializableActions::ManageAssembler => ACTIONS.manage_assembler,

            // Asset Manager Actions
            SerializableActions::ManageAssets => ACTIONS.manage_assets,

            // Currency Manager Actions
            SerializableActions::ManageCurrencies => ACTIONS.manage_currencies,
            SerializableActions::MintCurrencies => ACTIONS.mint_currencies,
            SerializableActions::ManageCurrencyStatus => ACTIONS.manage_currency_status,

            // Nectar Staking Actions
            SerializableActions::ManageStakingPool => ACTIONS.manage_staking_pool,
            SerializableActions::WithdrawStakingPoolRewards => {
                ACTIONS.withdraw_staking_pool_rewards
            }

            // Nectar Missions Actions
            SerializableActions::ManageMissionPool => ACTIONS.manage_mission_pool,
            SerializableActions::WithdrawMissionPoolRewards => {
                ACTIONS.withdraw_mission_pool_rewards
            }

            // Buzz Guild Actions
            SerializableActions::ManageGuildKit => ACTIONS.manage_guild_kit,
        }
    }
}

#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, PartialEq, Eq)]
pub struct AssociatedProgram {
    pub address: Pubkey,
    pub trusted_actions: Vec<SerializableActions>,
}
impl AssociatedProgram {
    pub const LEN: usize = 32 + 8; // base size + 32 align + 8 align
}

#[account]
pub struct PublicInfo {
    pub bump: u8,
    pub info: HashMap<String, Info>,
}
impl Default for PublicInfo {
    const LEN: usize = 8 + 8; // base size + 8 align

    fn set_defaults(&mut self) {
        self.bump = 0;
        self.info = HashMap::new();
    }
}

#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, PartialEq)]
pub enum Info {
    SingleValue { value: String },
}