-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
980 additions
and
377 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.18; | ||
|
||
import { ZNSRoles } from "./ZNSRoles.sol"; | ||
import { IZNSAccessController } from "./IZNSAccessController.sol"; | ||
|
||
|
||
abstract contract AccessControlled is ZNSRoles { | ||
event AccessControllerSet(address accessController); | ||
|
||
IZNSAccessController internal accessController; | ||
|
||
modifier onlyRole(bytes32 role) { | ||
accessController.checkRole(role, msg.sender); | ||
_; | ||
} | ||
|
||
/** | ||
* @dev This is here to make sure the external function is always implemented in children, | ||
* otherwise we will not be able to reset the module (not ideal since it might | ||
* not get to the final interface of a child). | ||
* TODO AC: how do we make sure this gets to the final interface? | ||
*/ | ||
function setAccessController(address _accessController) external virtual; | ||
|
||
function getAccessController() external view returns (address) { | ||
return address(accessController); | ||
} | ||
|
||
function _setAccessController(address _accessController) internal { | ||
require(_accessController != address(0), "AC: _accessController is 0x0 address"); | ||
accessController = IZNSAccessController(_accessController); | ||
emit AccessControllerSet(_accessController); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.18; | ||
|
||
import { IAccessControlUpgradeable } from "@openzeppelin/contracts-upgradeable/access/IAccessControlUpgradeable.sol"; | ||
|
||
|
||
interface IZNSAccessController is IAccessControlUpgradeable { | ||
function initialize( | ||
address[] calldata governorAddresses, | ||
address[] calldata operatorAddresses | ||
) external; | ||
|
||
function checkRole(bytes32 role, address account) external view; | ||
|
||
function setRoleAdmin(bytes32 role, bytes32 adminRole) external; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.18; | ||
|
||
import { AccessControlUpgradeable } from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol"; | ||
import { IZNSAccessController } from "./IZNSAccessController.sol"; | ||
import { ZNSRoles } from "./ZNSRoles.sol"; | ||
|
||
|
||
contract ZNSAccessController is AccessControlUpgradeable, ZNSRoles, IZNSAccessController { | ||
// solhint-disable-next-line func-name-mixedcase | ||
function initialize( | ||
address[] calldata governorAddresses, | ||
address[] calldata adminAddresses | ||
) external override initializer { | ||
// give roles to all addresses | ||
_grantRoleToMany(GOVERNOR_ROLE, governorAddresses); | ||
_grantRoleToMany(ADMIN_ROLE, adminAddresses); | ||
|
||
// all of the governors control admins TODO AC: ??? | ||
_setRoleAdmin(ADMIN_ROLE, GOVERNOR_ROLE); | ||
// all of the governors control governors TODO AC: ??? | ||
_setRoleAdmin(GOVERNOR_ROLE, GOVERNOR_ROLE); | ||
// all of the admins control registrar TODO AC: ??? | ||
_setRoleAdmin(REGISTRAR_ROLE, ADMIN_ROLE); | ||
} | ||
|
||
// TODO AC: should we keep this function here so that we can get standardized message? | ||
// test this function for gas usage with a standardized message vs a custom message | ||
// when using the recommended method of `hasRole` | ||
function checkRole(bytes32 role, address account) external view override { | ||
_checkRole(role, account); | ||
} | ||
|
||
// TODO AC: is this function necessary? how often will it be used? | ||
function _grantRoleToMany(bytes32 role, address[] calldata addresses) internal { | ||
for (uint256 i = 0; i < addresses.length; i++) { | ||
_grantRole(role, addresses[i]); | ||
} | ||
} | ||
|
||
// TODO AC: how safe is this? | ||
function setRoleAdmin(bytes32 role, bytes32 adminRole) external override onlyRole(GOVERNOR_ROLE) { | ||
_setRoleAdmin(role, adminRole); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.18; | ||
|
||
|
||
abstract contract ZNSRoles { | ||
// TODO AC: test getting this from AC contract vs inheriting these roles in every other contract | ||
// the highest rank, only assigns Admins | ||
bytes32 public constant GOVERNOR_ROLE = keccak256("GOVERNOR_ROLE"); | ||
// the main maintainer role, that gets access to all system functions | ||
// TODO AC: should we split responsibilities in a better way? | ||
bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE"); | ||
// operator can be here to future proof, if we need a new role | ||
// so we don't have to upgrade all contracts | ||
// TODO AC: change name of this role | ||
bytes32 public constant OPERATOR_ROLE = keccak256("OPERATOR_ROLE"); | ||
// this role is here specifically for the ZNSEthRegistrar contract | ||
bytes32 public constant REGISTRAR_ROLE = keccak256("REGISTRAR_ROLE"); | ||
// TODO AC: what other roles do we need here? | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.