Contract
Create a contract calledWeightedVoting. Add the following:
- A
maxSupplyof 1,000,000 - Errors for:
TokensClaimedAllTokensClaimedNoTokensHeldQuorumTooHigh, returning the quorum amount proposedAlreadyVotedVotingClosed
- A struct called
Issuecontaining:- An OpenZeppelin Enumerable Set storing addresses called
voters - A string
issueDesc - Storage for the number of
votesFor,votesAgainst,votesAbstain,totalVotes, andquorum - Bools storing if the issue is
passedandclosed
- An OpenZeppelin Enumerable Set storing addresses called
- An array of
Issues calledissues - An
enumforVotecontaining:AGAINSTFORABSTAIN
- Anything else needed to complete the tasks
Constructor
Initialize the ERC-20 token and burn the zeroeth element ofissues.
Claim
Add apublic function called claim. When called, so long as a number of tokens equalling the maximumSupply have not yet been distributed, any wallet that has not made a claim previously should be able to claim 100 tokens. If a wallet tries to claim a second time, it should revert with TokensClaimed.
Once all tokens have been claimed, this function should revert with an error AllTokensClaimed.
Create Issue
Implement anexternal function called createIssue. It should add a new Issue to issues, allowing the user to set the description of the issue, and quorum - which is how many votes are needed to close the issue.
Only token holders are allowed to create issues, and issues cannot be created that require a quorum greater than the current total number of tokens.
This function must return the index of the newly-created issue.
Get Issue
Add anexternal function called getIssue that can return all of the data for the issue of the provided _id.
EnumerableSet has a mapping underneath, so it can’t be returned outside of the contract. You’ll have to figure something else out.
HintThe return type for this function should be a
struct very similar to the one that stores the issues.Vote
Add apublic function called vote that accepts an _issueId and the token holder’s vote. The function should revert if the issue is closed, or the wallet has already voted on this issue.
Holders must vote all of their tokens for, against, or abstaining from the issue. This amount should be added to the appropriate member of the issue and the total number of votes collected.
If this vote takes the total number of votes to or above the quorum for that vote, then:
- The issue should be set so that
closedis true - If there are more votes for than against, set
passedtotrue