# DelegateRegistry

[Git Source](https://github.com/EntreDevelopers-Lab-Inc/Mezz-Companies/blob/f7a3e84e3dd5bb33c4bd7f77283983f9e8ba20b2/src/core/ancillary/delegate-registry/DelegateRegistry.sol)

**Inherits:** NoncesUpgradeable, StateAware, BoardControlled, Patchable, MezzEIP712, IDelegateRegistry

**Author:** Daniel Yamagata

A contract used to delegate voting power of a company's non-vesting and vesting shares. Delegates will receive the voting power of the delegator which can subsequently be used in governance

Invariant: the delegate of address(0) will always be address(0)

## State Variables

### DELEGATION\_TYPEHASH

```solidity
bytes32 public constant DELEGATION_TYPEHASH = keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
```

### DelegateRegistryStorageLocation

```solidity
bytes32 private constant DelegateRegistryStorageLocation =
    0xa90ac951d12c63c63be62b72ff9c8457724b4d380ebdd06ffdd610ee98f70300;
```

## Functions

### constructor

```solidity
constructor(address _mezzHub, address _mezzMigrator) StateAware(_mezzHub) Patchable(_mezzMigrator);
```

### \_getDelegateRegistryStorage

```solidity
function _getDelegateRegistryStorage() internal pure returns (DelegateRegistryStorage storage $);
```

### init

Initializes the delegate registry's state. Called atomically by the Mezz Deployer

```solidity
function init(address initTreasury) external virtual initializer;
```

### \_\_DelegateRegisitry\_init

```solidity
function __DelegateRegisitry_init(address initTreasury) internal virtual onlyInitializing;
```

### selfDelegate

Self-delegates 'account' under the following conditions:

* account is not address(0)
* The delegatee of 'account' is not set
* The caller is a valid share class or the token timelock
* 'account' is an EOA or properly supports the 'IMezzSelfDelegator' interface&#x20;

If any of these conditions are false, the function will make no changes to state and return

```solidity
function selfDelegate(address account) external virtual;
```

### delegate

Updates the delegatee of the caller to 'newDelegatee' and updates the state of all share classes and the token timelock

```solidity
function delegate(address newDelegate) external virtual freezable;
```

### delegateBySig

Updates the delegatee of 'account' to 'newDelegatee' and updates the state of all share classes and the token timelock. A valid 'signature' for 'account' is required, otherwise this function will revert

```solidity
function delegateBySig(address account, address newDelegate, bytes memory signature) external virtual freezable;
```

### \_delegate

Validate

*Updates the voting power of 'newDelegate' for all shares and the Token Timelock. Runs in O(n) The number of shares that a company can have is limited to 15. This is reasonable, preventing the reversion of this function due to the block gas limit*

```solidity
function _delegate(address account, address newDelegate) internal virtual;
```

### delegates

Returns the delegatee for 'account' if it is set. Otherwise, returns address(0)

```solidity
function delegates(address account) public view virtual returns (address);
```

### version

Returns the version of the implementation as a uint256

```solidity
function version() public pure virtual override(Credentialed, ICredentialed) returns (uint256);
```

### coreId

Returns the coreId of the implementation as a bytes32

*The core ID is the keccak256 hash of the contract name followed by a version under the following syntax: "mezzanine.coreId.ContractName.vX" For example, the core ID of the 2nd version of the Treasury would be the following: keccak256(abi.encodePacked("mezzanine.coreId.Treasury.v2"))*

```solidity
function coreId() public pure virtual override(Credentialed, ICredentialed) returns (bytes32);
```

### getDelegationTransactionHash

Returns the transaction hash for

```solidity
function getDelegationTransactionHash(address account, address newDelegate, uint256 accountNonce)
    public
    view
    returns (bytes32);
```

### \_getDelegationStructHash

```solidity
function _getDelegationStructHash(address account, address newDelegate, uint256 accountNonce)
    internal
    pure
    returns (bytes32);
```

### supportsInterface

*ERC165 support*

```solidity
function supportsInterface(bytes4 interfaceId)
    public
    view
    virtual
    override(MezzEIP712, MezzUUPSUpgradeable, IERC165)
    returns (bool);
```

### upgradeToNewerVersion

Upgrades 'this' to a newer version via the Mezz Migrator. Only callable by the Treasury, whose signers are the board of directors

*Will revert if the protocol state is 'Paused' or 'Frozen'*

```solidity
function upgradeToNewerVersion(uint256 newVersion, bytes memory data) public virtual onlyProxy onlyBoard;
```

**Parameters**

| Name         | Type      | Description                                                                                              |
| ------------ | --------- | -------------------------------------------------------------------------------------------------------- |
| `newVersion` | `uint256` | The new version to upgrade to                                                                            |
| `data`       | `bytes`   | The data to be passed to the new implementation, which likely should be a reinitializer function if used |

### \_authorizePatch

*Access control for 'resetToPatchedLatestVersion()'*

```solidity
function _authorizePatch(bytes memory) internal view virtual override;
```

## Structs

### DelegateRegistryStorage

```solidity
struct DelegateRegistryStorage {
    mapping(address => address) _delegateeByAccount;
}
```


---

# 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://docs.mezzanine.xyz/smart-contracts/source-code/core/delegateregistry.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.
