-
Notifications
You must be signed in to change notification settings - Fork 26
SingleVoteGovernance
File: SingleVoteGovernance.sol
- This contract implements a single-vote governance module.
- This contract keeps a list of authorized addresses, and these addresses can create
Votesthat other addresses can support or reject. - Votes are open for a set length of time. If they don't reach quorum at the time of voting, they won't be able to be executed later, even if the quorum is lowered.
- Each address can vote only once. Votes can not be modified.
- The stored action can only be executed after the voting period ends, even if the quorum was reached earlier.
modifier onlySelf()This modifier ensures that the msg.sender is the same as the SingleVoteGovernor contract (address(this)).
modifier onlyVoter()This modifier ensures that the msg.sender is an authorised voter (member of the mapping isVoter).
modifier isValidVoterAddress(address voter)Verifies whether the voter address is valid or not. Valid addresses are addresses that ae not address(0), not the singleVoteGovernor contract address and not the orchestrator address.
1. isAuthorized
function isAuthorized(address who) public view returns (bool);This function checks whether the address who is authorized or not.
Parameter(s)
-
address who-> The address whose authorization you want to check.
Return Data
-
bool-> True if addresswhoisauthorized(), false otherwise.
NOTE: The governance contract (
SingleVoteGovernance.sol) itself is only authorized.
2. getReceipt
function getReceipt(uint _ID, address voter) public view returns (Receipt memory);This function helps to fetch the Receipt (see NOTE 1 below) of a Motion(see NOTE 2 below) with id of _ID and associated with the address voter.
NOTE 1:
Receiptis the a struct containingbool hasVotedanduint8 support.
NOTE 2:
Motionis a struct with the following structure:
struct Motion {
// Execution data.
address target;
bytes action;
// Governance data.
uint startTimestamp;
uint endTimestamp;
uint requiredQuorum;
// Voting result.
uint forVotes;
uint againstVotes;
uint abstainVotes;
mapping(address => Receipt) receipts;
// Execution result.
uint executedAt;
bool executionResult;
bytes executionReturnData;
}Parameter(s)
-
uint _ID-> The identifying number of theMotionfor which you want to see theReceipt. -
address voter-> Given the_IDof theMotion, the address of the voter for which you want to see theReceipt.
Return Data
- Receipt -> A
Receiptof the addressvoterfrom theMotionwith id_ID.
3. MAX_DURATION_DURATION
function MAX_VOTING_DURATION() external view returns (unit);Return Data
-
uint-> The maximum duration for voting, which is currently hardcoded to2 weeks.
4. MIN_VOTING_DURATION
function MIN_VOTING_DURATION() external view returns (unit);Return Data
-
uint-> The minimum duration for voting, which is currently hardcoded to1 days.
1. initialize
function initialize(IProposal proposal, uint8 _startingQuorum, uint _voteDuration, Metadata memory metadata) externalThis function initializes the module and then sets the quorum, list of voters and voteDuration.
Parameters
-
IProposal proposal-> The module's proposal instance. -
Metadata metadata-> The module's metadata. -
bytes configData-> Encrypted data which contains list of voters, the required quorum, and the voting duration.
2. setThreshold
function setThreshold(uint newThreshold) external;This function can only be called by the SingleVoteGovernance contract and it sets/updates the threshold of the proposal.
Parameter(s)
-
uint newThreshold-> The new value of thethreshold.
NOTE: 0 is a valid threshold value
3. setVotingDuration
function setVotingDuration(uint newVoteDuration) external;This function can only be called by the SingleVoteGovernance contract and it sets/updates the voteDuration of the proposal.
Parameter(s)
-
uint newVoteDuration-> The newvoteDuration.
NOTE: The
newVoteDurationmust be between theMIN_VOTING_DURATIONandMAX_VOTING_DURATION.
4. addVoter
function addVoter(address who) external;This function is used to add address who as a voter in case they are not already added as a voter.
Parameter(s)
-
address who-> The address of the voter to add to the voting list.
5. removeVoter
function removeVoter(address who) external;Callable only by the SingleVoteGovernance contract and used to remove the address who as a valid voter. This will revert in case address who is the last voter or if removing who will lead to the quorum never being reached.
Parameter(s)
-
address who-> The address of the voter to remove from the voting list.
6. transferVotingRights
function transferVotingRights(address to) external;This function can only be called by a valid voter and used to transfer the voting rights of the msg.sender to address to. Also, this function would revert if the address to is already a voter.
Parameter(s)
-
address to-> The address to whom you want to transfer your voting rights to.
NOTE: You cannot transfer your voting rights to
address(0)
7. createMotion
function createMotion(address target, bytes calldata action) external returns (uint);This function is used to create a new Motion with the given target address and the given action bytes. This function is callable only by a valid voter and returns the ID of the newly created Motion.
Parameter(s)
-
address target-> The target address for creating the newMotion. -
bytes action-> The action bytes for creating the newMotion.
Return Data
-
uint-> ID of the newMotionthat was created.
8. castVote
function castVote(uint motionId, uint8 support) external;This function is used to cast vote (support) to a Motion with ID motionId. The function revert if support is invalid. Otherwise,
0 == for
1 == against
2 == abstain
Parameter(s)
-
uint motionId-> The ID of theMotionwhere you want to cast vote -
uint8 support-> Vote in support, against or abstain.
9. executeMotion
function executeMotion(uint motionId) external;This function is used to execute the Motion with id of motionId. This function will revert if motionId is invalid or voting duration has passed or if the motion has already been executed or the necessary quorum was not reached.
Parameter(s)
-
uint motionId-> The ID of theMotionto execute