Skip to content

Commit

Permalink
create mock bridge roles
Browse files Browse the repository at this point in the history
  • Loading branch information
tsnewnami committed Nov 15, 2023
1 parent d00f1b8 commit 4cc81c4
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 0 deletions.
101 changes: 101 additions & 0 deletions src/lib/BridgeRoles.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// SPDX-License-Identifier: Apache 2.0
pragma solidity 0.8.19;

import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";

/**
*
* @title BridgeRoles.sol
* @notice BridgeRoles.sol is an abstract contract that defines the roles and permissions and pausable functionality across the root and child chain bridge contracts.
* @dev This contract uses OpenZeppelin's AccessControl and Pausable contracts. This contract is abstract and is intended to be inherited by the root and child chain bridge contracts.
*/
abstract contract BridgeRoles is AccessControlUpgradeable, PausableUpgradeable {
// Roles
/// @notice Role identifier for those who can pause functionanlity.
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER");

/// @notice Role identifier for those who can unpause functionality.
bytes32 public constant UNPAUSER_ROLE = keccak256("UNPAUSER");

/// @notice Role identifier those who can update the cumulative IMX deposit limit.
bytes32 public constant VARIABLE_MANAGER_ROLE = keccak256("VARIABLE_MANAGER");

/// @notice Role identifier for those who can update the bridge adaptor.
bytes32 public constant ADAPTOR_MANAGER_ROLE = keccak256("ADAPTOR_MANAGER");

// Role granting functions
/**
* @notice Function to grant pauser role to an address
*/
function grantPauserRole(address account) external onlyRole(DEFAULT_ADMIN_ROLE) {
grantRole(PAUSER_ROLE, account);
}

/**
* @notice Function to grant unpauser role to an address
*/
function grantUnpauserRole(address account) external onlyRole(DEFAULT_ADMIN_ROLE) {
grantRole(UNPAUSER_ROLE, account);
}

/**
* @notice Function to grant variable manager role to an address
*/
function grantVariableManagerRole(address account) external onlyRole(DEFAULT_ADMIN_ROLE) {
grantRole(VARIABLE_MANAGER_ROLE, account);
}

/**
* @notice Function to grant adaptor manager role to an address
*/
function grantAdaptorManagerRole(address account) external onlyRole(DEFAULT_ADMIN_ROLE) {
grantRole(ADAPTOR_MANAGER_ROLE, account);
}

// Role revoking functions
/**
* @notice Function to revoke pauser role from an address
*/
function revokePauserRole(address account) external onlyRole(DEFAULT_ADMIN_ROLE) {
revokeRole(PAUSER_ROLE, account);
}

/**
* @notice Function to revoke unpauser role from an address
*/
function revokeUnpauserRole(address account) external onlyRole(DEFAULT_ADMIN_ROLE) {
revokeRole(UNPAUSER_ROLE, account);
}

/**
* @notice Function to revoke variable manager role from an address
*/
function revokeVariableManagerRole(address account) external onlyRole(DEFAULT_ADMIN_ROLE) {
revokeRole(VARIABLE_MANAGER_ROLE, account);
}

/**
* @notice Function to revoke adaptor manager role from an address
*/
function revokeAdaptorManagerRole(address account) external onlyRole(DEFAULT_ADMIN_ROLE) {
revokeRole(ADAPTOR_MANAGER_ROLE, account);
}

// Pausable functions
/**
* @notice Function to pause the contract
* @dev Only PAUSER_ROLE can call this function
*/
function pause() external onlyRole(PAUSER_ROLE) {
_pause();
}

/**
* @notice Function to pause the contract
* @dev Only UNPAUSER_ROLE can call this function
*/
function unpause() external onlyRole(UNPAUSER_ROLE) {
_unpause();
}
}
10 changes: 10 additions & 0 deletions test/unit/common/MockBridgeRoles.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

import "../../../src/common/BridgeRoles.sol";

contract MockBridgeRoles is BridgeRoles {
constructor(address admin) {
_setupRole(DEFAULT_ADMIN_ROLE, admin);
}
}

0 comments on commit 4cc81c4

Please sign in to comment.