Skip to main content

TokenVoting

Description

The majority voting implementation using an OpenZeppelin Votes compatible governance token.

This contract inherits from MajorityVotingBase and implements the IMajorityVoting interface.

Implementation

internal variable TOKEN_VOTING_INTERFACE_ID

The ERC-165 interface ID of the contract.

bytes4 TOKEN_VOTING_INTERFACE_ID

error NoVotingPower

Thrown if the voting power is zero

error NoVotingPower()

external function initialize

Initializes the component.

function initialize(contract IDAO _dao, struct MajorityVotingBase.VotingSettings _votingSettings, contract IVotesUpgradeable _token) external
InputTypeDescription
_daocontract IDAOThe IDAO interface of the associated DAO.
_votingSettingsstruct MajorityVotingBase.VotingSettingsThe voting settings.
_tokencontract IVotesUpgradeableThe ERC-20 token used for voting.

This method is required to support ERC-1822.

public function supportsInterface

Checks if this or the parent contract supports an interface by its ID.

function supportsInterface(bytes4 _interfaceId) public view virtual returns (bool)
InputTypeDescription
_interfaceIdbytes4The ID of the interface.
Output
0boolReturns true if the interface is supported.

public function getVotingToken

getter function for the voting token.

function getVotingToken() public view returns (contract IVotesUpgradeable)
OutputTypeDescription
0contract IVotesUpgradeableThe token used for voting.

public function also useful for registering interfaceId and for distinguishing from majority voting interface.

public function totalVotingPower

Returns the total voting power checkpointed for a specific block number.

function totalVotingPower(uint256 _blockNumber) public view returns (uint256)
InputTypeDescription
_blockNumberuint256The block number.
Output
0uint256The total voting power.

external function createProposal

Creates a new majority voting proposal.

function createProposal(bytes _metadata, struct IDAO.Action[] _actions, uint256 _allowFailureMap, uint64 _startDate, uint64 _endDate, enum IMajorityVoting.VoteOption _voteOption, bool _tryEarlyExecution) external returns (uint256 proposalId)
InputTypeDescription
_metadatabytesThe metadata of the proposal.
_actionsstruct IDAO.Action[]The actions that will be executed after the proposal passes.
_allowFailureMapuint256Allows proposal to succeed even if an action reverts. Uses bitmap representation. If the bit at index x is 1, the tx succeeds even if the action at x failed. Passing 0 will be treated as atomic execution.
_startDateuint64The start date of the proposal vote. If 0, the current timestamp is used and the vote starts immediately.
_endDateuint64The end date of the proposal vote. If 0, _startDate + minDuration is used.
_voteOptionenum IMajorityVoting.VoteOptionThe chosen vote option to be casted on proposal creation.
_tryEarlyExecutionboolIf true, early execution is tried after the vote cast. The call does not revert if early execution is not possible.
Output
proposalIduint256The ID of the proposal.

external function isMember

Checks if an account is a member of the DAO.

function isMember(address _account) external view returns (bool)
InputTypeDescription
_accountaddressThe address of the account to be checked.
Output
0boolWhether the account is a member or not.

This function must be implemented in the plugin contract that introduces the members to the DAO.

internal function _vote

Internal function to cast a vote. It assumes the queried vote exists.

function _vote(uint256 _proposalId, enum IMajorityVoting.VoteOption _voteOption, address _voter, bool _tryEarlyExecution) internal
InputTypeDescription
_proposalIduint256The ID of the proposal.
_voteOptionenum IMajorityVoting.VoteOptionThe chosen vote option to be casted on the proposal vote.
_voteraddress
_tryEarlyExecutionboolIf true, early execution is tried after the vote cast. The call does not revert if early execution is not possible.

internal function _canVote

Internal function to check if a voter can vote. It assumes the queried proposal exists.

function _canVote(uint256 _proposalId, address _account, enum IMajorityVoting.VoteOption _voteOption) internal view returns (bool)
InputTypeDescription
_proposalIduint256The ID of the proposal.
_accountaddress
_voteOptionenum IMajorityVoting.VoteOptionWhether the voter abstains, supports or opposes the proposal.
Output
0boolReturns true if the given voter can vote on a certain proposal and false otherwise.
© 2024