@@ -4,9 +4,10 @@ pub(crate) mod RolesComponent {
44 APP_GOVERNOR , APP_ROLE_ADMIN , AppGovernorAdded , AppGovernorRemoved , AppRoleAdminAdded ,
55 AppRoleAdminRemoved , GOVERNANCE_ADMIN , GovernanceAdminAdded , GovernanceAdminRemoved , IRoles ,
66 OPERATOR , OperatorAdded , OperatorRemoved , RoleId , SECURITY_ADMIN , SECURITY_AGENT ,
7- SecurityAdminAdded , SecurityAdminRemoved , SecurityAgentAdded , SecurityAgentRemoved ,
8- TOKEN_ADMIN , TokenAdminAdded , TokenAdminRemoved , UPGRADE_GOVERNOR , UpgradeGovernorAdded ,
9- UpgradeGovernorRemoved ,
7+ SECURITY_GOVERNOR , SecurityAdminAdded , SecurityAdminRemoved , SecurityAgentAdded ,
8+ SecurityAgentRemoved , SecurityGovernorAdded , SecurityGovernorRemoved , TOKEN_ADMIN ,
9+ TokenAdminAdded , TokenAdminRemoved , UPGRADE_AGENT , UPGRADE_GOVERNOR , UpgradeAgentAdded ,
10+ UpgradeAgentRemoved , UpgradeGovernorAdded , UpgradeGovernorRemoved ,
1011 };
1112 use core :: num :: traits :: Zero ;
1213 use starknet :: storage :: StorageMapReadAccess ;
@@ -36,10 +37,14 @@ pub(crate) mod RolesComponent {
3637 SecurityAdminRemoved : SecurityAdminRemoved ,
3738 SecurityAgentAdded : SecurityAgentAdded ,
3839 SecurityAgentRemoved : SecurityAgentRemoved ,
40+ SecurityGovernorAdded : SecurityGovernorAdded ,
41+ SecurityGovernorRemoved : SecurityGovernorRemoved ,
3942 TokenAdminAdded : TokenAdminAdded ,
4043 TokenAdminRemoved : TokenAdminRemoved ,
4144 UpgradeGovernorAdded : UpgradeGovernorAdded ,
4245 UpgradeGovernorRemoved : UpgradeGovernorRemoved ,
46+ UpgradeAgentAdded : UpgradeAgentAdded ,
47+ UpgradeAgentRemoved : UpgradeAgentRemoved ,
4348 }
4449 use openzeppelin :: access :: accesscontrol :: AccessControlComponent ;
4550 use openzeppelin :: access :: accesscontrol :: AccessControlComponent :: {
@@ -95,11 +100,25 @@ pub(crate) mod RolesComponent {
95100 access_comp . has_role (role : SECURITY_AGENT , : account )
96101 }
97102
103+ fn is_security_governor (
104+ self : @ ComponentState <TContractState >, account : ContractAddress ,
105+ ) -> bool {
106+ let access_comp = get_dep_component! (self , Access );
107+ access_comp . has_role (role : SECURITY_GOVERNOR , : account )
108+ }
109+
98110 fn is_token_admin (self : @ ComponentState <TContractState >, account : ContractAddress ) -> bool {
99111 let access_comp = get_dep_component! (self , Access );
100112 access_comp . has_role (role : TOKEN_ADMIN , : account )
101113 }
102114
115+ fn is_upgrade_agent (
116+ self : @ ComponentState <TContractState >, account : ContractAddress ,
117+ ) -> bool {
118+ let access_comp = get_dep_component! (self , Access );
119+ access_comp . has_role (role : UPGRADE_AGENT , : account )
120+ }
121+
103122 fn is_upgrade_governor (
104123 self : @ ComponentState <TContractState >, account : ContractAddress ,
105124 ) -> bool {
@@ -177,6 +196,25 @@ pub(crate) mod RolesComponent {
177196 self . _revoke_role_and_emit (role : SECURITY_AGENT , : account , : event );
178197 }
179198
199+ fn register_security_governor (
200+ ref self : ComponentState <TContractState >, account : ContractAddress ,
201+ ) {
202+ let event = Event :: SecurityGovernorAdded (
203+ SecurityGovernorAdded { added_account : account , added_by : get_caller_address () },
204+ );
205+ self . _grant_role_and_emit (role : SECURITY_GOVERNOR , : account , : event );
206+ }
207+
208+ fn remove_security_governor (
209+ ref self : ComponentState <TContractState >, account : ContractAddress ,
210+ ) {
211+ let event = Event :: SecurityGovernorRemoved (
212+ SecurityGovernorRemoved {
213+ removed_account : account , removed_by : get_caller_address (),
214+ },
215+ );
216+ self . _revoke_role_and_emit (role : SECURITY_GOVERNOR , : account , : event );
217+ }
180218
181219 fn register_governance_admin (
182220 ref self : ComponentState <TContractState >, account : ContractAddress ,
@@ -230,6 +268,24 @@ pub(crate) mod RolesComponent {
230268 self . _revoke_role_and_emit (role : TOKEN_ADMIN , : account , : event );
231269 }
232270
271+ fn register_upgrade_agent (
272+ ref self : ComponentState <TContractState >, account : ContractAddress ,
273+ ) {
274+ let event = Event :: UpgradeAgentAdded (
275+ UpgradeAgentAdded { added_account : account , added_by : get_caller_address () },
276+ );
277+ self . _grant_role_and_emit (role : UPGRADE_AGENT , : account , : event );
278+ }
279+
280+ fn remove_upgrade_agent (
281+ ref self : ComponentState <TContractState >, account : ContractAddress ,
282+ ) {
283+ let event = Event :: UpgradeAgentRemoved (
284+ UpgradeAgentRemoved { removed_account : account , removed_by : get_caller_address () },
285+ );
286+ self . _revoke_role_and_emit (role : UPGRADE_AGENT , : account , : event );
287+ }
288+
233289 fn register_upgrade_governor (
234290 ref self : ComponentState <TContractState >, account : ContractAddress ,
235291 ) {
@@ -349,26 +405,31 @@ pub(crate) mod RolesComponent {
349405 access_comp . set_role_admin (role : GOVERNANCE_ADMIN , admin_role : GOVERNANCE_ADMIN );
350406 access_comp . set_role_admin (role : OPERATOR , admin_role : APP_ROLE_ADMIN );
351407 access_comp . set_role_admin (role : TOKEN_ADMIN , admin_role : APP_ROLE_ADMIN );
408+ access_comp . set_role_admin (role : UPGRADE_AGENT , admin_role : APP_ROLE_ADMIN );
352409 access_comp . set_role_admin (role : UPGRADE_GOVERNOR , admin_role : GOVERNANCE_ADMIN );
353410
354411 access_comp . _grant_role (role : SECURITY_ADMIN , account : governance_admin );
355412 access_comp . set_role_admin (role : SECURITY_ADMIN , admin_role : SECURITY_ADMIN );
356413 access_comp . set_role_admin (role : SECURITY_AGENT , admin_role : SECURITY_ADMIN );
414+ access_comp . set_role_admin (role : SECURITY_GOVERNOR , admin_role : SECURITY_ADMIN );
357415 }
358416
359417 fn only_app_governor (self : @ ComponentState <TContractState >) {
360418 assert! (
361419 self . is_app_governor (get_caller_address ()), " {}" , AccessErrors :: ONLY_APP_GOVERNOR ,
362420 );
363421 }
422+
364423 fn only_operator (self : @ ComponentState <TContractState >) {
365424 assert! (self . is_operator (get_caller_address ()), " {}" , AccessErrors :: ONLY_OPERATOR );
366425 }
426+
367427 fn only_token_admin (self : @ ComponentState <TContractState >) {
368428 assert! (
369429 self . is_token_admin (get_caller_address ()), " {}" , AccessErrors :: ONLY_TOKEN_ADMIN ,
370430 );
371431 }
432+
372433 fn only_upgrade_governor (self : @ ComponentState <TContractState >) {
373434 assert! (
374435 self . is_upgrade_governor (get_caller_address ()),
@@ -377,6 +438,15 @@ pub(crate) mod RolesComponent {
377438 );
378439 }
379440
441+ fn only_upgrader (self : @ ComponentState <TContractState >) {
442+ assert! (
443+ self . is_upgrade_agent (get_caller_address ())
444+ || self . is_upgrade_governor (get_caller_address ()),
445+ " {}" ,
446+ AccessErrors :: ONLY_UPGRADER ,
447+ );
448+ }
449+
380450 fn only_security_admin (self : @ ComponentState <TContractState >) {
381451 assert! (
382452 self . is_security_admin (get_caller_address ()),
@@ -392,5 +462,13 @@ pub(crate) mod RolesComponent {
392462 AccessErrors :: ONLY_SECURITY_AGENT ,
393463 );
394464 }
465+
466+ fn only_security_governor (self : @ ComponentState <TContractState >) {
467+ assert! (
468+ self . is_security_governor (get_caller_address ()),
469+ " {}" ,
470+ AccessErrors :: ONLY_SECURITY_GOVERNOR ,
471+ );
472+ }
395473 }
396474}
0 commit comments