Skip to content

Commit 57d5fa3

Browse files
committed
sec gov
1 parent 33c582d commit 57d5fa3

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
lines changed

packages/utils/src/components/roles/interface.cairo

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub type RoleId = felt252;
1212
// TOKEN_ADMIN | APP_ROLE_ADMIN
1313
// SECURITY_ADMIN | SECURITY_ADMIN
1414
// SECURITY_AGENT | SECURITY_ADMIN.
15+
// SECURITY_GOVERNOR | SECURITY_ADMIN.
1516

1617
// int.from_bytes(Web3.keccak(text="ROLE_APP_GOVERNOR"), "big") & MASK_250 .
1718
pub const APP_GOVERNOR: RoleId = 0xd2ead78c620e94b02d0a996e99298c59ddccfa1d8a0149080ac3a20de06068;
@@ -45,6 +46,10 @@ pub const SECURITY_ADMIN: RoleId =
4546
pub const SECURITY_AGENT: RoleId =
4647
0x37693ba312785932d430dccf0f56ffedd0aa7c0f8b6da2cc4530c2717689b96;
4748

49+
// int.from_bytes(Web3.keccak(text="ROLE_SECURITY_GOVERNOR"), "big") & MASK_250 .
50+
pub const SECURITY_GOVERNOR: RoleId =
51+
0xa5a83e9807e87f281d865ab54b7b0ed2f7f4bbfef73888810ca16e95e734eb;
52+
4853
#[starknet::interface]
4954
pub trait IRoles<TContractState> {
5055
fn is_app_governor(self: @TContractState, account: ContractAddress) -> bool;
@@ -56,6 +61,7 @@ pub trait IRoles<TContractState> {
5661
fn is_upgrade_governor(self: @TContractState, account: ContractAddress) -> bool;
5762
fn is_security_admin(self: @TContractState, account: ContractAddress) -> bool;
5863
fn is_security_agent(self: @TContractState, account: ContractAddress) -> bool;
64+
fn is_security_governor(self: @TContractState, account: ContractAddress) -> bool;
5965
fn register_app_governor(ref self: TContractState, account: ContractAddress);
6066
fn remove_app_governor(ref self: TContractState, account: ContractAddress);
6167
fn register_app_role_admin(ref self: TContractState, account: ContractAddress);
@@ -75,6 +81,8 @@ pub trait IRoles<TContractState> {
7581
fn remove_security_admin(ref self: TContractState, account: ContractAddress);
7682
fn register_security_agent(ref self: TContractState, account: ContractAddress);
7783
fn remove_security_agent(ref self: TContractState, account: ContractAddress);
84+
fn register_security_governor(ref self: TContractState, account: ContractAddress);
85+
fn remove_security_governor(ref self: TContractState, account: ContractAddress);
7886
fn has_legacy_role(self: @TContractState, account: ContractAddress, role: RoleId) -> bool;
7987
fn reclaim_legacy_roles(ref self: TContractState);
8088
}
@@ -146,6 +154,18 @@ pub(crate) struct SecurityAgentRemoved {
146154
pub removed_by: ContractAddress,
147155
}
148156

157+
#[derive(Copy, Drop, PartialEq, starknet::Event)]
158+
pub(crate) struct SecurityGovernorAdded {
159+
pub added_account: ContractAddress,
160+
pub added_by: ContractAddress,
161+
}
162+
163+
#[derive(Copy, Drop, PartialEq, starknet::Event)]
164+
pub(crate) struct SecurityGovernorRemoved {
165+
pub removed_account: ContractAddress,
166+
pub removed_by: ContractAddress,
167+
}
168+
149169
#[derive(Copy, Drop, PartialEq, starknet::Event)]
150170
pub(crate) struct SecurityAdminAdded {
151171
pub added_account: ContractAddress,

packages/utils/src/components/roles/roles.cairo

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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_AGENT, UPGRADE_GOVERNOR,
9-
UpgradeAgentAdded, UpgradeAgentRemoved, UpgradeGovernorAdded, 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,6 +37,8 @@ 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,
@@ -97,6 +100,13 @@ pub(crate) mod RolesComponent {
97100
access_comp.has_role(role: SECURITY_AGENT, :account)
98101
}
99102

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+
100110
fn is_token_admin(self: @ComponentState<TContractState>, account: ContractAddress) -> bool {
101111
let access_comp = get_dep_component!(self, Access);
102112
access_comp.has_role(role: TOKEN_ADMIN, :account)
@@ -186,6 +196,25 @@ pub(crate) mod RolesComponent {
186196
self._revoke_role_and_emit(role: SECURITY_AGENT, :account, :event);
187197
}
188198

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+
}
189218

190219
fn register_governance_admin(
191220
ref self: ComponentState<TContractState>, account: ContractAddress,
@@ -382,6 +411,7 @@ pub(crate) mod RolesComponent {
382411
access_comp._grant_role(role: SECURITY_ADMIN, account: governance_admin);
383412
access_comp.set_role_admin(role: SECURITY_ADMIN, admin_role: SECURITY_ADMIN);
384413
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);
385415
}
386416

387417
fn only_app_governor(self: @ComponentState<TContractState>) {
@@ -432,5 +462,13 @@ pub(crate) mod RolesComponent {
432462
AccessErrors::ONLY_SECURITY_AGENT,
433463
);
434464
}
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+
}
435473
}
436474
}

0 commit comments

Comments
 (0)