TokenVoting API

The contracts of build 3(use build 2) are currently being audited, DO NOT USE IN PRODUCTION.

Core

TokenVoting

v1.3 (Release 1, Build 3). For each upgrade, if the reinitialization step is required, increment the version numbers in the modifier for both the initialize and initializeFrom functions.

Functions
ProposalUpgradeable
ProtocolVersion
DaoAuthorizableUpgradeable

initialize(contract IDAO _dao, struct MajorityVotingBase.VotingSettings _votingSettings, contract IVotesUpgradeable _token, struct IPlugin.TargetConfig _targetConfig, uint256 _minApprovals, bytes _pluginMetadata) external

Initializes the component.

This method is required to support [ERC-1822](https://eips.ethereum.org/EIPS/eip-1822).

initializeFrom(uint16 _fromBuild, bytes _initData) external

Reinitializes the TokenVoting after an upgrade from a previous build version. For each reinitialization step, use the _fromBuild version to decide which internal functions to call for reinitialization.

The contract should only be upgradeable through PSP to ensure that _fromBuild is not incorrectly passed, and that the appropriate permissions for the upgrade are properly configured.

supportsInterface(bytes4 _interfaceId) → bool public

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

getVotingToken() → contract IVotesUpgradeable public

getter function for the voting token.

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

totalVotingPower(uint256 _blockNumber) → uint256 public

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

createProposal(bytes _metadata, struct Action[] _actions, uint256 _allowFailureMap, uint64 _startDate, uint64 _endDate, enum IMajorityVoting.VoteOption _voteOption, bool _tryEarlyExecution) → uint256 proposalId public

Creates a new majority voting proposal.

Requires the CREATE_PROPOSAL_PERMISSION_ID permission.

createProposal(bytes _metadata, struct Action[] _actions, uint64 _startDate, uint64 _endDate, bytes _data) → uint256 proposalId external

Creates a new proposal.

customProposalParamsABI() → string external

The human-readable abi format for extra params included in data of createProposal.

Used for UI to easily detect what extra params the contract expects.

isMember(address _account) → bool external

Checks if an account is a member of the DAO.

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

_vote(uint256 _proposalId, enum IMajorityVoting.VoteOption _voteOption, address _voter, bool _tryEarlyExecution) internal

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

_canVote(uint256 _proposalId, address _account, enum IMajorityVoting.VoteOption _voteOption) → bool internal

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

NoVotingPower() error

Thrown if the voting power is zero

bytes4 TOKEN_VOTING_INTERFACE_ID internal constant

The [ERC-165](https://eips.ethereum.org/EIPS/eip-165) interface ID of the contract.

MajorityVotingBase

This contract implements the IMajorityVoting interface.

Functions
ProposalUpgradeable
ProtocolVersion
DaoAuthorizableUpgradeable

__MajorityVotingBase_init(contract IDAO _dao, struct MajorityVotingBase.VotingSettings _votingSettings, struct IPlugin.TargetConfig _targetConfig, uint256 _minApprovals, bytes _pluginMetadata) internal

Initializes the component to be used by inheriting contracts.

This method is required to support [ERC-1822](https://eips.ethereum.org/EIPS/eip-1822).

supportsInterface(bytes4 _interfaceId) → bool public

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

vote(uint256 _proposalId, enum IMajorityVoting.VoteOption _voteOption, bool _tryEarlyExecution) public

Votes on a proposal and, optionally, executes the proposal.

_voteOption, 1 → abstain, 2 → yes, 3 → no

execute(uint256 _proposalId) public

Executes a proposal.

Requires the EXECUTE_PROPOSAL_PERMISSION_ID permission.

getVoteOption(uint256 _proposalId, address _voter) → enum IMajorityVoting.VoteOption public

Returns whether the account has voted for the proposal.

May return none if the _proposalId does not exist, or the _account does not have voting power.

canVote(uint256 _proposalId, address _account, enum IMajorityVoting.VoteOption _voteOption) → bool public

Checks if an account can participate on a proposal. This can be because the vote - has not started, - has ended, - was executed, or - the voter doesn’t have voting powers.

Reverts if the proposal with the given _proposalId does not exist.

canExecute(uint256 _proposalId) → bool public

Checks if a proposal can be executed.

Reverts if the proposal with the given _proposalId does not exist.

hasSucceeded(uint256 _proposalId) → bool public

Whether proposal succeeded or not.

Reverts if the proposal with the given _proposalId does not exist.

isSupportThresholdReached(uint256 _proposalId) → bool public

Checks if the support value defined as: \texttt{support} = \frac{N_\text{yes}}{N_\text{yes}+N_\text{no}} for a proposal is greater than the support threshold.

isSupportThresholdReachedEarly(uint256 _proposalId) → bool public

Checks if the worst-case support value defined as: \texttt{worstCaseSupport} = \frac{N_\text{yes}}{ N_\text{total}-N_\text{abstain}} for a proposal is greater than the support threshold.

isMinParticipationReached(uint256 _proposalId) → bool public

Checks if the participation value defined as: \texttt{participation} = \frac{N_\text{yes}+N_\text{no}+N_\text{abstain}}{N_\text{total}} for a proposal is greater or equal than the minimum participation value.

isMinApprovalReached(uint256 _proposalId) → bool public

Checks if the min approval value defined as: \texttt{minApproval} = \frac{N_\text{yes}}{N_\text{total}} for a proposal is greater or equal than the minimum approval value.

minApproval() → uint256 public

Returns the configured minimum approval value.

supportThreshold() → uint32 public

Returns the support threshold parameter stored in the voting settings.

minParticipation() → uint32 public

Returns the minimum participation parameter stored in the voting settings.

minDuration() → uint64 public

Returns the minimum duration parameter stored in the voting settings.

minProposerVotingPower() → uint256 public

Returns the minimum voting power required to create a proposal stored in the voting settings.

votingMode() → enum MajorityVotingBase.VotingMode public

Returns the vote mode stored in the voting settings.

totalVotingPower(uint256 _blockNumber) → uint256 public

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

getProposal(uint256 _proposalId) → bool open, bool executed, struct MajorityVotingBase.ProposalParameters parameters, struct MajorityVotingBase.Tally tally, struct Action[] actions, uint256 allowFailureMap, struct IPlugin.TargetConfig targetConfig public

Returns all information for a proposal by its ID.

updateVotingSettings(struct MajorityVotingBase.VotingSettings _votingSettings) external

Updates the voting settings.

Requires the UPDATE_VOTING_SETTINGS_PERMISSION_ID permission.

updateMinApprovals(uint256 _minApprovals) external

Updates the minimal approval value.

Requires the UPDATE_VOTING_SETTINGS_PERMISSION_ID permission.

createProposal(bytes _metadata, struct Action[] _actions, uint256 _allowFailureMap, uint64 _startDate, uint64 _endDate, enum IMajorityVoting.VoteOption _voteOption, bool _tryEarlyExecution) → uint256 proposalId external

Creates a new majority voting proposal.

_vote(uint256 _proposalId, enum IMajorityVoting.VoteOption _voteOption, address _voter, bool _tryEarlyExecution) internal

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

_execute(uint256 _proposalId) internal

Internal function to execute a proposal. It assumes the queried proposal exists.

_canVote(uint256 _proposalId, address _account, enum IMajorityVoting.VoteOption _voteOption) → bool internal

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

_hasSucceeded(uint256 _proposalId) → bool internal

An internal function that checks if the proposal succeeded or not.

_canExecute(uint256 _proposalId) → bool internal

Internal function to check if a proposal can be executed. It assumes the queried proposal exists.

Threshold and minimal values are compared with > and >= comparators, respectively.

_isProposalOpen(struct MajorityVotingBase.Proposal proposal_) → bool internal

Internal function to check if a proposal is still open.

_updateVotingSettings(struct MajorityVotingBase.VotingSettings _votingSettings) internal

Internal function to update the plugin-wide proposal settings.

_updateMinApprovals(uint256 _minApprovals) internal

Internal function to update minimal approval value.

_validateProposalDates(uint64 _start, uint64 _end) → uint64 startDate, uint64 endDate internal

Validates and returns the proposal dates.

UPDATE_VOTING_SETTINGS_PERMISSION_ID() → bytes32 public

The ID of the permission required to call the updateVotingSettings function.

CREATE_PROPOSAL_PERMISSION_ID() → bytes32 public

The ID of the permission required to call the createProposal functions.

EXECUTE_PROPOSAL_PERMISSION_ID() → bytes32 public

The ID of the permission required to call the execute function.

VotingSettingsUpdated(enum MajorityVotingBase.VotingMode votingMode, uint32 supportThreshold, uint32 minParticipation, uint64 minDuration, uint256 minProposerVotingPower) event

Emitted when the voting settings are updated.

VotingMinApprovalUpdated(uint256 minApprovals) event

Emitted when the min approval value is updated.

DateOutOfBounds(uint64 limit, uint64 actual) error

Thrown if a date is out of bounds.

MinDurationOutOfBounds(uint64 limit, uint64 actual) error

Thrown if the minimal duration value is out of bounds (less than one hour or greater than 1 year).

ProposalCreationForbidden(address sender) error

Thrown when a sender is not allowed to create a proposal.

NonexistentProposal(uint256 proposalId) error

Thrown when a proposal doesn’t exist.

VoteCastForbidden(uint256 proposalId, address account, enum IMajorityVoting.VoteOption voteOption) error

Thrown if an account is not allowed to cast a vote. This can be because the vote - has not started, - has ended, - was executed, or - the account doesn’t have voting powers.

ProposalExecutionForbidden(uint256 proposalId) error

Thrown if the proposal execution is forbidden.

ProposalAlreadyExists(uint256 proposalId) error

Thrown if the proposal with same actions and metadata already exists.

bytes4 MAJORITY_VOTING_BASE_INTERFACE_ID internal constant

The [ERC-165](https://eips.ethereum.org/EIPS/eip-165) interface ID of the contract.

mapping(uint256 => struct MajorityVotingBase.Proposal) proposals internal

A mapping between proposal IDs and proposal information.

TokenVotingSetup

v1.3 (Release 1, Build 3)

constructor(contract GovernanceERC20 _governanceERC20Base, contract GovernanceWrappedERC20 _governanceWrappedERC20Base) public

The contract constructor deploying the plugin implementation contract and receiving the governance token base contracts to clone from.

prepareInstallation(address _dao, bytes _data) → address plugin, struct IPluginSetup.PreparedSetupData preparedSetupData external

Prepares the installation of a plugin.

prepareUpdate(address _dao, uint16 _fromBuild, struct IPluginSetup.SetupPayload _payload) → bytes initData, struct IPluginSetup.PreparedSetupData preparedSetupData external

Prepares the update of a plugin.

Revoke the upgrade plugin permission to the DAO for all builds prior the current one (3).

prepareUninstallation(address _dao, struct IPluginSetup.SetupPayload _payload) → struct PermissionLib.MultiTargetPermission[] permissions external

Prepares the uninstallation of a plugin.

supportsIVotesInterface(address token) → bool public

Unsatisfiably determines if the token is an IVotes interface.

Many tokens don’t use ERC165 even though they still support IVotes.

governanceERC20Base() → address public

The address of the GovernanceERC20 base contract.

governanceWrappedERC20Base() → address public

The address of the GovernanceWrappedERC20 base contract.

TokenNotContract(address token) error

Thrown if the passed token address is not a token contract.

TokenNotERC20(address token) error

Thrown if token address is not ERC20.

VotingPowerCondition

constructor(address _tokenVoting) public

Initializes the contract with the TokenVoting plugin address and fetches the associated token.

isGranted(address _where, address _who, bytes32 _permissionId, bytes _data) → bool public

Checks if a call is permitted.

The function checks both the voting power and token balance to ensure _who meets the minimum voting threshold defined in the TokenVoting plugin. Returns false if the minimum requirement is unmet.