# Control Facet

### Overview

The Control Facet provides the following key functionalities:

* **Role Management:** Grant, revoke, and configure role admins for the Account Layer's access control system.
* **Pause Control:** Pause and unpause the entire Account Layer diamond.
* **Account Configuration:** Set the AccountManager proxy bytecode and the global signer.
* **Affiliate Configuration:** Configure the Symmio fee receiver, whitelist Symmio cores, manage hook and call selector permissions, and add Symmio cores to active affiliates.

***

### Role Management

#### grantRole() / revokeRole()

Grants or revokes a role. Caller must be an admin for that role.

```solidity
function grantRole(address user, bytes32 role) external onlyRoleAdmin(role);
function revokeRole(address user, bytes32 role) external onlyRoleAdmin(role);
```

**Events:** `RoleGranted(bytes32 role, address user, address admin)` / `RoleRevoked(bytes32 role, address user, address admin)`

#### setRoleAdmin()

Adds or removes a user as a role admin for a specific role. Requires `DEFAULT_ADMIN_ROLE`.

```solidity
function setRoleAdmin(address user, bytes32 role, bool status) external onlyRole(DEFAULT_ADMIN_ROLE);
```

**Events:** `RoleAdminSet(bytes32 role, address user, bool status, address admin)`

***

### Pause Control

#### pause() / unpause()

Pauses or unpauses all state-changing operations on the Account Layer diamond.

```solidity
function pause() external onlyRole(PAUSER_ROLE);
function unpause() external onlyRole(UNPAUSER_ROLE);
```

***

### Account Configuration

#### setAccountManagerImplementation()

Sets the bytecode used to deploy new AccountManager proxy contracts when affiliates are approved.

```solidity
function setAccountManagerImplementation(bytes memory implementation) external onlyRole(SETTER_ROLE);
```

**Events:** `AccountManagerImplementationUpdated(bytes oldImplementation, bytes newImplementation)`

#### setSigner()

Sets the global signer for protocol-level operations. Pass `address(0)` to clear.

```solidity
function setSigner(address _signer) external onlyRole(SIGNER_SETTER_ROLE);
```

**Events:** `SignerUpdated(address oldSigner, address newSigner)`

***

### Affiliate Configuration

#### setSymmioFeeReceiver()

Sets the address that receives Symmio's share of affiliate fees.

```solidity
function setSymmioFeeReceiver(address receiver) external onlyRole(SETTER_ROLE);
```

**Events:** `SymmioFeeReceiverUpdated(address oldReceiver, address newReceiver)`

#### setWhitelistedSymmioCore()

Adds or removes a Symmio core diamond from the whitelist. Affiliates can only be registered against whitelisted cores.

```solidity
function setWhitelistedSymmioCore(address core, bool status) external onlyRole(SETTER_ROLE);
```

**Events:** `WhitelistedSymmioCoreSet(address core, bool status)`

#### setHookAllowedSelectors()

Configures which function selectors an affiliate's hook contracts are allowed to execute via `executeForAccount`.

```solidity
function setHookAllowedSelectors(address affiliate, bytes4[] calldata selectors, bool allowed) external onlyRole(SETTER_ROLE);
```

**Events:** `HookAllowedSelectorsSet(address affiliate, bytes4[] selectors, bool allowed)`

#### setCallAllowedSelectors()

Configures which function selectors an affiliate can invoke via `callAsAffiliate`.

```solidity
function setCallAllowedSelectors(address affiliate, bytes4[] calldata selectors, bool allowed) external onlyRole(SETTER_ROLE);
```

**Events:** `CallAllowedSelectorsSet(address affiliate, bytes4[] selectors, bool allowed)`

#### addSymmioCoreToAffiliate()

Adds a whitelisted Symmio core to an active affiliate and registers the affiliate on that core.

```solidity
function addSymmioCoreToAffiliate(address affiliate, address core) external onlyRole(APPROVER_ROLE);
```

**Events:** `SymmioCoreAddedToAffiliate(address affiliate, address core)`
