LateStageGovernor

Git Source

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

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

init

Intializes the Governor's state

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

Parameters

NameTypeDescription

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

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

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

Parameters

NameTypeDescription

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

NameTypeDescription

<none>

uint256

The proposal ID for the proposal

cancel

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

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

Parameters

NameTypeDescription

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

NameTypeDescription

<none>

uint256

The proposal ID for the proposal

execute

Executes a proposal that succeeded.

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

Parameters

NameTypeDescription

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

NameTypeDescription

<none>

uint256

The proposal ID for the proposal

state

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

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

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

Parameters

NameTypeDescription

timepoint

uint256

The timepoint to get the quorum for

Returns

NameTypeDescription

<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

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

Returns

NameTypeDescription

<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

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

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

Parameters

NameTypeDescription

proposalId

uint256

The ID of the proposal

Returns

NameTypeDescription

<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

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

Parameters

NameTypeDescription

proposalId

uint256

The ID of the proposal

Returns

NameTypeDescription

<none>

uint256

The deadline of the proposal, which is measured in seconds from the Unix epoch

proposalProposer

Returns the proposer of a proposal

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

Returns

NameTypeDescription

<none>

address

The address of the proposer

votingDelay

Returns the voting delay in seconds

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

Returns

NameTypeDescription

<none>

uint256

The voting delay in seconds

votingPeriod

Returns the voting period

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

Returns

NameTypeDescription

<none>

uint256

The voting period in seconds

hasVoted

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

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

Returns

NameTypeDescription

<none>

bool

True if the account has voted, false otherwise

clock

EIP-6372 support

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

CLOCK_MODE

EIP-6372 support

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--

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

Returns

NameTypeDescription

<none>

string

The URL-encoded sequence of key-value pairs

name

Returns the name of the governor

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"))

function coreId() public pure virtual override(ProposalGovernor, ICredentialed) returns (bytes32);

version

Returns the version of the implementation as a uint256

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

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

Parameters

NameTypeDescription

proposalId

uint256

The ID of the proposal to cast the vote for

support

uint8

The vote type

Returns

NameTypeDescription

<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

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

Parameters

NameTypeDescription

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

NameTypeDescription

<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

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

Parameters

NameTypeDescription

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

NameTypeDescription

<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

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

Parameters

NameTypeDescription

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

NameTypeDescription

<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

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

NameTypeDescription

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

NameTypeDescription

<none>

uint256

The number of votes of the voter

_castVote

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

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

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

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

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

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

Returns

NameTypeDescription

<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

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

Returns

NameTypeDescription

<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

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

Returns

NameTypeDescription

<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

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

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

Last updated