Smart contract for facilitating voting and polling
npm install @openzeppelin/contracts-ethereum-package
when deploy it is need to pass parameters in to init method Params:
| name | type | description |
|---|---|---|
| InitSettings | tuple | see InitSettings |
| contractAddress | address | contract's address which will call after user vote. contract nede to implement method with params: ((string,uint256)[],uint256). (tuples of tag:value, user weight) |
| communityAddress | address | address of community contract |
| communitySettings | tuple[] | see CommunitySettings |
once installed will be use methods:
| method name | called by | description |
|---|---|---|
| init | anyone | need to initialize after contract deploy |
| setWeight | owner | [TBD] ability to owner setup weight for role community |
| vote | only which roles specified at Community Contract | vote method |
| wasEligible | anyone | is block eligible for sender or not |
| getVoterInfo | anyone | return voter info |
| getVoters | anyone | return voter's addresses |
Checking if the user was eligible in blockNumber block
Params:
| name | type | description |
|---|---|---|
| addr | address | user's address |
| blockNumber | uint256 | Block number |
user can vote if he hasn't vote before and he has was eligible in blockNumber block
Params:
| name | type | description |
|---|---|---|
| blockNumber | uint256 | Block number |
| voterData | array of tuples | see voterData |
Return voter info. tuple of voter Params:
| name | type | description |
|---|---|---|
| addr | address | user's address |
[TBD] setup weight for community role Params:
| name | type | description |
|---|---|---|
| role | string | role name |
| weight | uint256 | weight value |
return all addresses which already voted
| name | type | description |
|---|---|---|
| voteTitle | string | Vote title |
| blockNumberStart | uint256 | vote will start from blockNumberStart |
| blockNumberEnd | uint256 | vote will end at blockNumberEnd |
| voteWindowBlocks | uint256 | period in blocks then we check eligible |
| name | type | description |
|---|---|---|
| communityRole | string | community role of participants which allowance to vote |
| communityFraction | uint256 | fraction (percents mul by 1e6). setup if minimum/memberCount too low |
| communityMinimum | uint256 | community minimum |
| name | type | description |
|---|---|---|
| name | string | string |
| value | uint256 | uint256 |
| name | type | description |
|---|---|---|
| contractAddress | address | contract address |
| contractMethodName | string | contract method name |
| voterData | tuple | see voterData |
| alreadyVoted | bool | true if voter is already voted |
-
deploy( or got) contract which method
votewe will be call from voting contract. for example<address contract1> -
got contract of Community and roles name. for example
<address community>and role "members" -
creation VotingContract and call init method with params
- initSettings = ["My First Vote",11105165,11155165,100] ([
<voteTitle>,<blockNumberStart>,<blockNumberEnd>,<voteWindowBlocks>]) - contractAddress =
<address contract1> - communityAddress =
<address community> - communitySettings = [['members',150000,20]] ([
<communityRole>,<communityFraction>,<communityMinimum>])
- initSettings = ["My First Vote",11105165,11155165,100] ([
-
now any user which contain in contract community with role 'members' can vote in period from
blockNumberStarttoblockNumberEndif was eligible inblockNumberblock calling vote with Params- blockNumber = 11105222
- methodName = 'vote'
- voterData = [["orange",12],["blackberry",34],["lemon",56]]
-
each successful vote will call method
vote(tuple(name,value)[], weight)of<address contract1>. [TBD] weight = 1 unless owner will set new value for role callingsetWeight