# LateStageGovernor

[Git Source](https://github.com/EntreDevelopers-Lab-Inc/Mezz-Companies/blob/f7a3e84e3dd5bb33c4bd7f77283983f9e8ba20b2/src/core/governance/late-stage/LateStageGovernor.sol)

**Inherits:** ProposalGovernor, ModifiedGovernorUpgradeable, ILateStageGovernor

**Author:** Daniel Yamagata & Naveen Ailawadi

A governance contract that is based off of OpenZeppelin's Governor contract. This contract enables the voting of arbitrary on-chain actions, which are represented as proposals. Only 'for-votes' are counted towards the quorum

*Many of these contract's functions run in O(n), where n is the number of shares that a treasury has.  The maximum number of share classes that a Treasury can have is 15.  This contract used a modified version of GovernorUpgradeable to allow access to the the Governor Upgradeable storage internally This is specifically used in propose() and state() to allow for the board of directors to propose and a proposal with a super majority to instantly be executable, respectively.*

## Functions

### constructor

```solidity
constructor(address _mezzHub, address _mezzMigrator) MezzGovernor(_mezzHub, _mezzMigrator);
```

### init

Intializes the Governor's state

```solidity
function init(address initTreasury, bytes memory) external virtual override initializer;
```

**Parameters**

| Name           | Type      | Description                                                   |
| -------------- | --------- | ------------------------------------------------------------- |
| `initTreasury` | `address` | The address of the Treasury that the Governor is in charge of |
| `<none>`       | `bytes`   |                                                               |

### \_\_LateStageGovernor\_init

*The 'params' argument is maintained in case future versions require additional initialization parameters*

```solidity
function __LateStageGovernor_init(address initTreasury, bytes memory) internal virtual onlyInitializing;
```

### propose

Creates a new proposal. Vote starts after the delay specified by votingDelay()

*Overridden propose function to add pausable modifier and enable the treasury to make proposals Reference: <https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/4d9d9073b84f56fe3eea360e5067c6ffd864c43d/contracts/governance/GovernorUpgradeable.sol#L277-L330>*

```solidity
function propose(address[] memory targets, uint256[] memory values, bytes[] memory calldatas, string memory description)
    public
    virtual
    override(ModifiedGovernorUpgradeable, ILateStageGovernor)
    freezable
    returns (uint256);
```

**Parameters**

| Name          | Type        | Description                                          |
| ------------- | ----------- | ---------------------------------------------------- |
| `targets`     | `address[]` | Target addresses for proposal calls                  |
| `values`      | `uint256[]` | Blockchain native currency values for proposal calls |
| `calldatas`   | `bytes[]`   | Calldatas for proposal calls                         |
| `description` | `string`    |                                                      |

**Returns**

| Name     | Type      | Description                      |
| -------- | --------- | -------------------------------- |
| `<none>` | `uint256` | The proposal ID for the proposal |

### cancel

Cancels a proposal.  Only callable by the Proposer, the Mezz Hub Owner, or a 'Defender'

```solidity
function cancel(address[] memory targets, uint256[] memory values, bytes[] memory calldatas, bytes32 descriptionHash)
    public
    virtual
    override(ModifiedGovernorUpgradeable, ILateStageGovernor)
    returns (uint256);
```

**Parameters**

| Name              | Type        | Description                                          |
| ----------------- | ----------- | ---------------------------------------------------- |
| `targets`         | `address[]` | Target addresses for proposal calls                  |
| `values`          | `uint256[]` | Blockchain native currency values for proposal calls |
| `calldatas`       | `bytes[]`   | Calldatas for proposal calls                         |
| `descriptionHash` | `bytes32`   | Hash of the proposal description                     |

**Returns**

| Name     | Type      | Description                      |
| -------- | --------- | -------------------------------- |
| `<none>` | `uint256` | The proposal ID for the proposal |

### execute

Executes a proposal that succeeded. &#x20;

```solidity
function execute(address[] memory targets, uint256[] memory values, bytes[] memory calldatas, bytes32 descriptionHash)
    public
    payable
    virtual
    override(ModifiedGovernorUpgradeable, ILateStageGovernor)
    freezable
    returns (uint256);
```

**Parameters**

| Name              | Type        | Description                                          |
| ----------------- | ----------- | ---------------------------------------------------- |
| `targets`         | `address[]` | Target addresses for proposal calls                  |
| `values`          | `uint256[]` | Blockchain native currency values for proposal calls |
| `calldatas`       | `bytes[]`   | Calldatas for proposal calls                         |
| `descriptionHash` | `bytes32`   | Hash of the proposal description                     |

**Returns**

| Name     | Type      | Description                      |
| -------- | --------- | -------------------------------- |
| `<none>` | `uint256` | The proposal ID for the proposal |

### state

Returns the state of a proposal associated with 'proposalId' as a ProposalState enum

```solidity
function state(uint256 proposalId)
    public
    view
    virtual
    override(ModifiedGovernorUpgradeable, ProposalGovernor, IProposalGovernor)
    returns (ProposalState);
```

### quorum

Changed the following line such that if a super majority is reached before the voting period ends, the proposal is instantly executable. There's no need to check if \_quorumReached() or \_voteSucceeded(), since a super majority will always have more for-votes than a quorum, and a super majority will always more for-votes than against-votes, since it is a majority of the total votes.

*The quorum is not a raw value: it is a percentage of the total votes across all share classes*

```solidity
function quorum(uint256 timepoint)
    public
    view
    virtual
    override(ModifiedGovernorUpgradeable, ILateStageGovernor)
    returns (uint256);
```

**Parameters**

| Name        | Type      | Description                         |
| ----------- | --------- | ----------------------------------- |
| `timepoint` | `uint256` | The timepoint to get the quorum for |

**Returns**

| Name     | Type      | Description |
| -------- | --------- | ----------- |
| `<none>` | `uint256` | The quorum  |

### proposalThreshold

Returns the proposal threshold, which is the minimum number of votes that the sender must have for a proposal to be created

*The proposal threshold is not a raw value: it is a percentage of the total votes across all share classes*

```solidity
function proposalThreshold()
    public
    view
    virtual
    override(ModifiedGovernorUpgradeable, ILateStageGovernor)
    returns (uint256);
```

**Returns**

| Name     | Type      | Description              |
| -------- | --------- | ------------------------ |
| `<none>` | `uint256` | The proposal threxwshold |

### superMajority

Returns the nominal value for a super majority at a 'timepoint', which is the number of for-votes needed to execute a proposal instantaneously during the voting period

```solidity
function superMajority(uint256 timepoint) public view virtual returns (uint256);
```

### proposalSnapshot

Returns a proposal's snapshot, which is the time at which votes are counted. Any votes accumulated past this point are not counted towards the proposal

*The snapshot is set during the proposal's and is the sum of the voting delay and block.timestamp*

```solidity
function proposalSnapshot(uint256 proposalId)
    public
    view
    virtual
    override(ModifiedGovernorUpgradeable, IProposalGovernor)
    returns (uint256);
```

**Parameters**

| Name         | Type      | Description            |
| ------------ | --------- | ---------------------- |
| `proposalId` | `uint256` | The ID of the proposal |

**Returns**

| Name     | Type      | Description                                                                    |
| -------- | --------- | ------------------------------------------------------------------------------ |
| `<none>` | `uint256` | The snapshot of the proposal, which is measured in seconds from the Unix epoch |

### proposalDeadline

Returns a proposal's deadline, which is the time at which the proposal can no longer be voted on

*The deadline is set during the proposal's creation and is the sum of the voting delay, voting period, and block.timestamp*

```solidity
function proposalDeadline(uint256 proposalId)
    public
    view
    virtual
    override(ModifiedGovernorUpgradeable, IProposalGovernor)
    returns (uint256);
```

**Parameters**

| Name         | Type      | Description            |
| ------------ | --------- | ---------------------- |
| `proposalId` | `uint256` | The ID of the proposal |

**Returns**

| Name     | Type      | Description                                                                    |
| -------- | --------- | ------------------------------------------------------------------------------ |
| `<none>` | `uint256` | The deadline of the proposal, which is measured in seconds from the Unix epoch |

### proposalProposer

Returns the proposer of a proposal

```solidity
function proposalProposer(uint256 proposalId)
    public
    view
    virtual
    override(ModifiedGovernorUpgradeable, IProposalGovernor)
    returns (address);
```

**Returns**

| Name     | Type      | Description                 |
| -------- | --------- | --------------------------- |
| `<none>` | `address` | The address of the proposer |

### votingDelay

Returns the voting delay in seconds

```solidity
function votingDelay()
    public
    view
    virtual
    override(ProposalGovernor, IProposalGovernor, ModifiedGovernorUpgradeable)
    returns (uint256);
```

**Returns**

| Name     | Type      | Description                 |
| -------- | --------- | --------------------------- |
| `<none>` | `uint256` | The voting delay in seconds |

### votingPeriod

Returns the voting period

```solidity
function votingPeriod()
    public
    view
    virtual
    override(ProposalGovernor, IProposalGovernor, ModifiedGovernorUpgradeable)
    returns (uint256);
```

**Returns**

| Name     | Type      | Description                  |
| -------- | --------- | ---------------------------- |
| `<none>` | `uint256` | The voting period in seconds |

### hasVoted

Returns true if 'account' has voted on a proposal with 'proposalId', false otherwise

```solidity
function hasVoted(uint256 proposalId, address account)
    public
    view
    virtual
    override(ProposalGovernor, IProposalGovernor, IModifiedGovernor)
    returns (bool);
```

**Returns**

| Name     | Type   | Description                                    |
| -------- | ------ | ---------------------------------------------- |
| `<none>` | `bool` | True if the account has voted, false otherwise |

### clock

*EIP-6372 support*

```solidity
function clock()
    public
    view
    virtual
    override(ProposalGovernor, ModifiedGovernorUpgradeable, IERC6372)
    returns (uint48);
```

### CLOCK\_MODE

*EIP-6372 support*

```solidity
function CLOCK_MODE()
    public
    view
    virtual
    override(ProposalGovernor, ModifiedGovernorUpgradeable, IERC6372)
    returns (string memory);
```

### COUNTING\_MODE

Returns a URL-encoded sequence of key-value pairs that each describe one aspect of voting

*Mezzanine Proposal Governors use votes in line with Bravo. The quorum also only counts for votes, like in Bravo. Reference: <https://docs.openzeppelin.com/contracts/4.x/api/governance#IGovernor-COUNTING\\_MODE-->*

```solidity
function COUNTING_MODE() public view virtual override(IModifiedGovernor, IProposalGovernor) returns (string memory);
```

**Returns**

| Name     | Type     | Description                                 |
| -------- | -------- | ------------------------------------------- |
| `<none>` | `string` | The URL-encoded sequence of key-value pairs |

### name

Returns the name of the governor

```solidity
function name() public view virtual override(ModifiedGovernorUpgradeable, MezzGovernor) returns (string memory);
```

### 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(ProposalGovernor, ICredentialed) returns (bytes32);
```

### version

Returns the version of the implementation as a uint256

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

### castVote

Casts the caller's votes towards the proposal associated with 'proposalId' There are three different vote types defined by the following enum:

* 0: Against
* 1: For
* 2: Abstain

*A voter can only vote once and cannot revoke or change their vote. Votes are calculated from the proposal's snapshot and the counting of votes is bespoke and must be implemented by the inheritor*

```solidity
function castVote(uint256 proposalId, uint8 support)
    public
    virtual
    override(ModifiedGovernorUpgradeable, ProposalGovernor, IProposalGovernor)
    returns (uint256);
```

**Parameters**

| Name         | Type      | Description                                 |
| ------------ | --------- | ------------------------------------------- |
| `proposalId` | `uint256` | The ID of the proposal to cast the vote for |
| `support`    | `uint8`   | The vote type                               |

**Returns**

| Name     | Type      | Description                       |
| -------- | --------- | --------------------------------- |
| `<none>` | `uint256` | The number of votes of the caller |

### castVoteWithReason

Casts the caller's votes with a 'reason' towards the proposal associated with 'proposalId'

*The 'reason' is not stored on-chain but, rather, emitted in an event*

```solidity
function castVoteWithReason(uint256 proposalId, uint8 support, string calldata reason)
    public
    virtual
    override(ModifiedGovernorUpgradeable, ProposalGovernor, IProposalGovernor)
    returns (uint256);
```

**Parameters**

| Name         | Type      | Description                                 |
| ------------ | --------- | ------------------------------------------- |
| `proposalId` | `uint256` | The ID of the proposal to cast the vote for |
| `support`    | `uint8`   | The vote type                               |
| `reason`     | `string`  | The reason for the vote                     |

**Returns**

| Name     | Type      | Description                       |
| -------- | --------- | --------------------------------- |
| `<none>` | `uint256` | The number of votes of the caller |

### castVoteWithReasonAndParams

Casts the caller's votes with a 'reason' and 'params' towards the proposal associated with 'proposalId'

*'params' are bespoke, abi-encoded arguments that could be used for casting a vote*

```solidity
function castVoteWithReasonAndParams(uint256 proposalId, uint8 support, string calldata reason, bytes memory params)
    public
    virtual
    override(ModifiedGovernorUpgradeable, ProposalGovernor, IProposalGovernor)
    returns (uint256);
```

**Parameters**

| Name         | Type      | Description                                 |
| ------------ | --------- | ------------------------------------------- |
| `proposalId` | `uint256` | The ID of the proposal to cast the vote for |
| `support`    | `uint8`   | The vote type                               |
| `reason`     | `string`  | The reason for the vote                     |
| `params`     | `bytes`   | The abi-encoded parameters for the vote     |

**Returns**

| Name     | Type      | Description                       |
| -------- | --------- | --------------------------------- |
| `<none>` | `uint256` | The number of votes of the caller |

### castVoteBySig

Casts the votes of 'voter' towards the proposal associated with 'proposalId' via an EIP-712 signature

*Reference: <https://eips.ethereum.org/EIPS/eip-712>*

```solidity
function castVoteBySig(uint256 proposalId, uint8 support, address voter, bytes memory signature)
    public
    virtual
    override(ModifiedGovernorUpgradeable, ProposalGovernor, IProposalGovernor)
    returns (uint256);
```

**Parameters**

| Name         | Type      | Description                                 |
| ------------ | --------- | ------------------------------------------- |
| `proposalId` | `uint256` | The ID of the proposal to cast the vote for |
| `support`    | `uint8`   | The vote type                               |
| `voter`      | `address` | The address of the voter                    |
| `signature`  | `bytes`   | The EIP-712 signature of the voter          |

**Returns**

| Name     | Type      | Description                      |
| -------- | --------- | -------------------------------- |
| `<none>` | `uint256` | The number of votes of the voter |

### castVoteWithReasonAndParamsBySig

Casts the votes of 'voter' towards the proposal associated with 'proposalId' via an EIP-712 signature

*Reference: <https://eips.ethereum.org/EIPS/eip-712> 'params' are bespoke, abi-encoded arguments that could be used for casting a vote*

```solidity
function castVoteWithReasonAndParamsBySig(
    uint256 proposalId,
    uint8 support,
    address voter,
    string calldata reason,
    bytes memory params,
    bytes memory signature
) public virtual override(ModifiedGovernorUpgradeable, ProposalGovernor, IProposalGovernor) returns (uint256);
```

**Parameters**

| Name         | Type      | Description                                 |
| ------------ | --------- | ------------------------------------------- |
| `proposalId` | `uint256` | The ID of the proposal to cast the vote for |
| `support`    | `uint8`   | The vote type                               |
| `voter`      | `address` | The address of the voter                    |
| `reason`     | `string`  | The reason for the vote                     |
| `params`     | `bytes`   | The abi-encoded parameters for the vote     |
| `signature`  | `bytes`   | The EIP-712 signature of the voter          |

**Returns**

| Name     | Type      | Description                      |
| -------- | --------- | -------------------------------- |
| `<none>` | `uint256` | The number of votes of the voter |

### \_castVote

```solidity
function _castVote(uint256 proposalId, address account, uint8 support, string memory reason)
    internal
    virtual
    override(ProposalGovernor, ModifiedGovernorUpgradeable)
    returns (uint256);
```

### \_castVote

*OZ's GovernorUpgradeable vote casting is used directly here*

```solidity
function _castVote(uint256 proposalId, address account, uint8 support, string memory reason, bytes memory params)
    internal
    virtual
    override(ProposalGovernor, ModifiedGovernorUpgradeable)
    returns (uint256);
```

### \_countVote

*Counts a vote for a given proposal. Sets the receipt in storage. Assumes that weight has already been calculated*

```solidity
function _countVote(uint256 proposalId, address account, uint8 support, uint256 votes, bytes memory)
    internal
    virtual
    override(ModifiedGovernorUpgradeable, ProposalGovernor);
```

### \_getTotalVotesAtTimepoint

*Queries all the shares and returns the summation of the total votes at the given timepoint*

```solidity
function _getTotalVotesAtTimepoint(uint256 timepoint) internal view returns (uint256);
```

### \_getVotes

*Queries all the shares and returns the summation of the votes for the account at the given timepoint*

```solidity
function _getVotes(address account, uint256 timepoint, bytes memory) internal view virtual override returns (uint256);
```

### \_superMajorityReached

*Returns whether or not a super majority has been reached for a given proposal. Only for-votes are counted towards the super majority*

```solidity
function _superMajorityReached(uint256 proposalId) internal view virtual returns (bool);
```

**Returns**

| Name     | Type   | Description                                                                |
| -------- | ------ | -------------------------------------------------------------------------- |
| `<none>` | `bool` | True if the for-votes are greater than the super majority, false otherwise |

### \_quorumReached

*Returns whether or not the quourum has been reached for a given proposal. Only for-votes are counted towards the quorum*

```solidity
function _quorumReached(uint256 proposalId) internal view override returns (bool);
```

**Returns**

| Name     | Type   | Description                                                        |
| -------- | ------ | ------------------------------------------------------------------ |
| `<none>` | `bool` | True if the for votes are greater than the quorum, false otherwise |

### \_voteSucceeded

*Returns whether or not the vote succeeded for a given proposal*

```solidity
function _voteSucceeded(uint256 proposalId)
    internal
    view
    override(ModifiedGovernorUpgradeable, ProposalGovernor)
    returns (bool);
```

**Returns**

| Name     | Type   | Description                                                               |
| -------- | ------ | ------------------------------------------------------------------------- |
| `<none>` | `bool` | True if the for votes are greater than the against votes, false otherwise |

### eip712Domain

*EIP-5267 support. Reference: <https://eips.ethereum.org/EIPS/eip-5267>*

```solidity
function eip712Domain()
    public
    view
    virtual
    override(EIP712Upgradeable, IERC5267, MezzEIP712)
    returns (
        bytes1 fields,
        string memory __name,
        string memory __version,
        uint256 chainId,
        address verifyingContract,
        bytes32 salt,
        uint256[] memory extensions
    );
```

### supportsInterface

*EIP-165 support. Reference: <https://eips.ethereum.org/EIPS/eip-165>*

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