# RoleManager

Central contract in the system that keeps and manages account roles and access to the system. Most crucial logic like setting address, changing {Resolver}'s signatures, contract initizlizing logic, trade settlement are restricted to accounts that have valid roles. See docs/SystemAccess.md for more details about roles (RoleManager.sol)

View Source: @nomisma/elektro-protocol-aux/contracts/access/RoleManager.sol

**↗ Extends: IRoleManager** **↘ Derived Contracts: RoleManagerProxy**

**RoleManager**

**Enums**

### OperationType

```js
enum OperationType {
 AddGovernor,
 RemoveGovernor
}
```

## Structs

### GovernorRequest

```js
struct GovernorRequest {
 uint256 confirmationCount,
 address[] confirmations
}
```

## Contract Members

**Constants & Variables**

```js
bytes32 public constant GOVERNOR_ROLE_NAME;
```

***

```js
bytes32 public constant ADMIN_ROLE_NAME;
```

***

```js
bytes32 public constant UTILITY_ACCOUNT_ROLE_NAME;
```

***

All add-governor requests already sumbitted to the system. Maps governor candidate address to {GovernorRequest} struct holding data of all requests for a particular candidate.

```js
mapping(address => struct RoleManager.GovernorRequest) public govRequests;
```

***

Variable set upon construction representing how many request are required to assing a new governor for the system.

```js
uint256 private confirmationsRequired;
```

***

Maps role name to {Roles} library to access all base role related functionality.

```js
mapping(bytes32 => struct Roles.Role) private roles;
```

***

## RoleAdded

Event fired upon adding a role for an address.

**Parameters**

| Name     | Type    | Description                                       |
| -------- | ------- | ------------------------------------------------- |
| roleName | bytes32 | - bytes32 representation of a role name           |
| user     | address | - address of a user that is assigned a role above |

## RoleRemoved

Event fired upon removing a role for an address.

**Parameters**

| Name     | Type    | Description                                                  |
| -------- | ------- | ------------------------------------------------------------ |
| roleName | bytes32 | - bytes32 representation of a role name                      |
| user     | address | - address of a user that for which the above role is removed |

## RequestConfirmed

Event fired upon submission/confirmation of a governor addition/removal request.See {submitGovernorRequest}.

**Parameters**

| Name          | Type                           | Description                                                                      |
| ------------- | ------------------------------ | -------------------------------------------------------------------------------- |
| sender        | address                        | - person who called {submitGovernorRequest} and sent the request                 |
| govAddress    | address                        | - address of the governor candidate to appoint/remove the role for               |
| operationType | enum RoleManager.OperationType | - an {OperationType} enum value representing if it's an addition or removal call |

## ConfirmationRevoked

Event fired upon revoking a request for addition/removal of a governor.See {revokeGovernorRequestConfirmation}.

**Parameters**

| Name       | Type    | Description                                                                  |
| ---------- | ------- | ---------------------------------------------------------------------------- |
| sender     | address | - person who called {revokeGovernorRequestConfirmation} and sent the request |
| govAddress | address | - address of a governor candidate for whom request is being revoked          |

## GovernorAdded

Event fired upon successful addition of a new governor.

**Parameters**

| Name       | Type    | Description                       |
| ---------- | ------- | --------------------------------- |
| govAddress | address | - address of a new governor added |

## GovernorRemoved

Event fired upon successful removal of a governor.

**Parameters**

| Name       | Type    | Description                         |
| ---------- | ------- | ----------------------------------- |
| govAddress | address | - address of a new governor removed |

## Modifiers

* onlyRole

### onlyRole

Modifier preventing unauthorized addresses from calling protected functions.

```js
modifier onlyRole(bytes32 roleName) internal
```

**Arguments**

| Name     | Type    | Description |
| -------- | ------- | ----------- |
| roleName | bytes32 |             |

## Functions

* (address\[] governors, uint256 \_confirmationsRequired)
* appointAdmins(address\[] admins)
* addRoleForAddress(address addr, bytes32 roleName)
* addRolesForAddresses(address\[] addresses, bytes32\[] rolesArr)
* removeRoleForAddress(address addr, bytes32 roleName)
* submitAddGovernorRequest(address govAddress)
* submitRemoveGovernorRequest(address govAddress)
* revokeGovernorRequestConfirmation(address govAddress)
* checkRole(address addr, bytes32 roleName)
* hasRole(address addr, bytes32 roleName)
* addRole(address addr, bytes32 roleName)
* removeRole(address addr, bytes32 roleName)
* submitGovernorRequest(address govAddress, enum RoleManager.OperationType operationType)
* acceptGovernorRequest(address govAddress, enum RoleManager.OperationType operationType)
* addGovernorRole(address addr)
* removeGovernorRole(address addr)
* isGovernorRequestConfirmed(address govAddress)
* isNotConfirmedBySender(address govAddress)

###

Constructor that assigns accounts with `governor` role Governor role can be only added during contract construction and when {\_confirmationsRequired} number of governors {submitAddGovernorRequest}. Note that `governors.length >= _confirmationsRequired`

```js
function (address[] governors, uint256 _confirmationsRequired) public nonpayable
```

**Arguments**

| Name                    | Type       | Description                                             |
| ----------------------- | ---------- | ------------------------------------------------------- |
| governors               | address\[] | array of addresses to be added as governors             |
| \_confirmationsRequired | uint256    | number of confirmations required to add/remove governor |

### appointAdmins

Adds an `ADMIN_ROLE_NAME` for the provided array of `admins`.

```js
function appointAdmins(address[] admins) external nonpayable onlyRole 
```

**Arguments**

| Name   | Type       | Description                              |
| ------ | ---------- | ---------------------------------------- |
| admins | address\[] | array of addresses to be added as admins |

### addRoleForAddress

Function to assign a role to an address

```js
function addRoleForAddress(address addr, bytes32 roleName) external nonpayable onlyRole 
```

**Arguments**

| Name     | Type    | Description             |
| -------- | ------- | ----------------------- |
| addr     | address | address to add role to  |
| roleName | bytes32 | name of the role to add |

### addRolesForAddresses

Assigns multiple roles to addresses.

```js
function addRolesForAddresses(address[] addresses, bytes32[] rolesArr) external nonpayable onlyRole 
```

**Arguments**

| Name      | Type       | Description                                             |
| --------- | ---------- | ------------------------------------------------------- |
| addresses | address\[] | array of user addresses for which roles should be added |
| rolesArr  | bytes32\[] | array of respective roles                               |

### removeRoleForAddress

Removes a `roleName` for the provided `addr`.

```js
function removeRoleForAddress(address addr, bytes32 roleName) external nonpayable onlyRole 
```

**Arguments**

| Name     | Type    | Description                                  |
| -------- | ------- | -------------------------------------------- |
| addr     | address | address to remove role from                  |
| roleName | bytes32 | name of the role to remove See {removeRole}. |

### submitAddGovernorRequest

Multisig implementation for adding new governor. In order to add new governor at least `confirmationsRequired` amount of governors need to call this function for same `govAddress`. For the first governor that calls this function with new `govAddress`, new `GovernorRequest` is created and stored in RoleManager. Only after last governor executed this function, `governor` role is added for `govAddress`.

```js
function submitAddGovernorRequest(address govAddress) external nonpayable onlyRole 
```

**Arguments**

| Name       | Type    | Description                                                        |
| ---------- | ------- | ------------------------------------------------------------------ |
| govAddress | address | account address for which `governor` role is requested to be added |

### submitRemoveGovernorRequest

Multisig implementation for removing governor. In order to remove governor at least `confirmationsRequired` amount of governors need to call this function for same `govAddress`. For the first governor that calls this function with new `govAddress`, new `GovernorRequest` is created and stored in {RoleManager.govRequests}. Only after last governor executed this function, `governor` role is removed for `govAddress`.

```js
function submitRemoveGovernorRequest(address govAddress) external nonpayable onlyRole 
```

**Arguments**

| Name       | Type    | Description                                                          |
| ---------- | ------- | -------------------------------------------------------------------- |
| govAddress | address | account address for which `governor` role is requested to be removed |

### revokeGovernorRequestConfirmation

Function to provide ability for current governors to revoke previously granted confirmation of adding or removing a new governor.

```js
function revokeGovernorRequestConfirmation(address govAddress) external nonpayable onlyRole 
```

**Arguments**

| Name       | Type    | Description                                                                       |
| ---------- | ------- | --------------------------------------------------------------------------------- |
| govAddress | address | account address for which confirmation was granted before and needs to be removed |

### checkRole

Checks the existence of a `roleName` value for the given `addr`. Function reverts if account does not have required role

```js
function checkRole(address addr, bytes32 roleName) public view
```

**Arguments**

| Name     | Type    | Description                    |
| -------- | ------- | ------------------------------ |
| addr     | address | address to check role for      |
| roleName | bytes32 | name of the role to be checked |

### hasRole

See {Roles.has}.

```js
function hasRole(address addr, bytes32 roleName) public view
returns(bool)
```

**Arguments**

| Name     | Type    | Description |
| -------- | ------- | ----------- |
| addr     | address |             |
| roleName | bytes32 |             |

### addRole

Adds a `roleName` for the provided `addr` and emits a `RoleAdded` event that can be found in the transaction events. See {Roles.add}.

```js
function addRole(address addr, bytes32 roleName) internal nonpayable
```

**Arguments**

| Name     | Type    | Description |
| -------- | ------- | ----------- |
| addr     | address |             |
| roleName | bytes32 |             |

### removeRole

Removes a role for the provided `addr` and emits a `RoleRemoved` event that can be found in the transaction events. See {Roles.remove}.

```js
function removeRole(address addr, bytes32 roleName) internal nonpayable
```

**Arguments**

| Name     | Type    | Description |
| -------- | ------- | ----------- |
| addr     | address |             |
| roleName | bytes32 |             |

### submitGovernorRequest

Internal function with base functionality for both adding and removing governors.Checks if this is a first request, in which case it would initialize new slot in {govRequests} adding request data or, in case of subsequent requests, would add new request to an existing mapping slot. Also fires an event and checks if the required number of requests reached, in which case it will add or remove new governor automatically.

```js
function submitGovernorRequest(address govAddress, enum RoleManager.OperationType operationType) internal nonpayable
```

**Arguments**

| Name          | Type                           | Description                                                   |
| ------------- | ------------------------------ | ------------------------------------------------------------- |
| govAddress    | address                        | - address of a governor candidate to add or remove            |
| operationType | enum RoleManager.OperationType | - enum value signifying type of the operation (add or remove) |

### acceptGovernorRequest

Function that adds/removes a governor.This function is launched automatically when the number of requests required is reached.

```js
function acceptGovernorRequest(address govAddress, enum RoleManager.OperationType operationType) internal nonpayable
```

**Arguments**

| Name          | Type                           | Description                                                   |
| ------------- | ------------------------------ | ------------------------------------------------------------- |
| govAddress    | address                        | - address of a governor candidate to add or remove            |
| operationType | enum RoleManager.OperationType | - enum value signifying type of the operation (add or remove) |

### addGovernorRole

Adds a `GOVERNOR_ROLE_NAME` for the provided `addr` and emit a `RoleAdded` event that can be found in the transaction events. Can only be run as a part of governor request/confirmation flow.

```js
function addGovernorRole(address addr) internal nonpayable
```

**Arguments**

| Name | Type    | Description                                         |
| ---- | ------- | --------------------------------------------------- |
| addr | address | address to check governor role for See {Roles.add}. |

### removeGovernorRole

Removes a `GOVERNOR_ROLE_NAME` for the provided `addr` and emit a `RoleRemoved` event that can be found in the transaction events. Can only be run as a part of governor request/confirmation flow.

```js
function removeGovernorRole(address addr) internal nonpayable
```

**Arguments**

| Name | Type    | Description                                            |
| ---- | ------- | ------------------------------------------------------ |
| addr | address | address to check governor role for See {Roles.remove}. |

### isGovernorRequestConfirmed

Function to check if governor request for `govAddress` has enough confirmations to be executed

```js
function isGovernorRequestConfirmed(address govAddress) internal view
returns(bool)
```

**Returns**

true if at least confirmationsRequired number of requests are confirmed for `govAddress`

**Arguments**

| Name       | Type    | Description                             |
| ---------- | ------- | --------------------------------------- |
| govAddress | address | address identifier of governor requests |

### isNotConfirmedBySender

Function to check if governor request has been already confirmed by this `msg.sender`

```js
function isNotConfirmedBySender(address govAddress) internal view
returns(bool)
```

**Returns**

true if `govAddress` is not already confirmed by `msg.sender`

**Arguments**

| Name       | Type    | Description                             |
| ---------- | ------- | --------------------------------------- |
| govAddress | address | address identifier of governor requests |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://elektro.gitbook.io/elektro-protocol/smart-contracts/natspec-technical-documentation/role-management/rolemanager.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
