Dao Manager allows for proposals and voting to securely take place within a Up. Relies heavily on the ERC725Y and ERC725X standard for setting, getting and executing. Voting and proposal data are stored within the Up conforming to the ERC725YJSONSchema
(LSP2). By leveraging methods in LSP7 Digital Asset, Dao Manager also has the ability for weighted votes at the same time solving the double voting problem.
Proposals are stored through the using of an array. Proposal data is derived by first hashing the Proposal[]
string. This key will return the amount of elements (proposals) within the Up. Combining the proposal key and element number together generates a new key (Proposal Element) which returns proposal data from the Dao Up.
Hashing the proposal element key and Votes
string creates new unique key. This key is used to generate a mapping. Mapping the proposal data to the vote data (Vote Map).
By combining the proposal key, vote map key and an address creates a mapping with grouping. Mapping votes to voters.
Proposal data is divided between what is necessary to maintain key features. Below shows what aspects of a proposal is saved in the Dao Up. Information that is not saved in the Dao Up is still linked using an assetUrl.
- DaoUP
- amount of choices
- cut off date
- voting strategie
- assetURL link
- Not Saved
- Title
- Description
- Choice Titles
- ...
Within the proposal method a uint256
array is created with the size set to the amount of choices the proposal has. This allows for each index to represent a choice and value to represent the amount of votes.
uint256[] memory newVoteArray = new uint256[](_amountOfChoices);
A struct with two uint256
saves a vote cast by a voter.
voteIndex
: What index choice they voted.voteAmount
: Amount they voted.
Currently only two voting strategies exist 1to1
and isOperatorFor
i.e. weighted.
Weighted votes work by utilizing isOperatorFor
, authorizeOperator
and transfer
methods from the LSP7 DigitalAsset
standard.
How it works
-
Voter will set the amount of voting power they want to allocate to the vote.
-
Calling the token's contract
authorizeOperator
method with DaoUp as the operator and amount -
This will give the DaoUp the right to access the set amount.
-
-
Voter cast a vote on a weighted proposal.
- Calls the
isOperatorFor
to get the DaoUp operator amount - Then transfer the operator amount from voter to DaoUp
- Sets the operator amount into the votes array at the correct index also setting voter data.
- Calls the
-
Voter can get their tokens back in one of two ways.
-
Wait until the poll is over then call
claimGovToken
method.- Only
voteAmount
is zero out, keeping the record they voted.
- Only
-
While the poll is active call
RemoveVote
-
Subtract the
voterAmount
from the vote array. -
Both
voterIndex
andvoterAmount
is zero out
-
-
Note To prevent a double transfer, voter amount is set to 0 before transferring tokens.
Contract can be categorized into four sections followed by respective methods.
- Proposal Creation
createProposal
-
Vote Management
vote
changeVote
removeVote
-
End of poll
announceProposal
claimGovToken
-
Tools (Internal)
genVoterKey
genVoteKey
genKey
toBytes
fromBytes
constructor(address _keyManager,address _govToken,uint256 _minimumTokenAmount)
Parameters
_keyManager
address of the key manager for the DaoUp_govToken
address of governance token that will be used (LSP7 DigitalAsset standard)_minimumTokenAmount
minimum amount of governance tokens to set a proposal.
function govToken() external view returns(address)
Returns the address
of the acting governance token.
function target() external view returns(address)
Returns the address
of the target contract acting as the DaoUp controlled by the key manager.
function keyManagerAddress() external view returns(uint256)
Returns the address
of the acting key manager.
function minimumTokenAmount() external view returns(uint256)
Returns a uint256
of the minimum token amount to create a proposal.
function announceProposal() public
Emits the winning choice and amount of votes for proposal.
Only callable a single time after the poll is closed.
Sets the announced boolean to true
in the proposal data.
function claimGovToken(bytes32 _elementKey) public
Transfers governance tokens back to voters used in voting.
Only callable after the poll is closed
Parameters
_elementKey
proposal element that was voted upon.
function createProposal(uint8 _strategie,uint8 _amountOfChoices,uint256 _cutoffDate, bytes memory _assetURL) public
Create a new proposal within the DaoUp. Sender must have the minimumTokenAmount
in order to submit a proposal.
Note Element are increment automatically
Parameters
_strategy
voting strategy that will be used._amountOfChoices
amount of choices proposal will have_cutoffDate
cut off date of the poll (Starts immediately)_assetURL
AssetUrl of proposal
function vote(bytes32 _elementKey,uint8 _voteIndex) public
Cast a vote for msg.sender
.
Parameters
_elementKey
proposal key_voteIndex
choice index
function changeVote(bytes32 _elementKey, uint256 _newIndex) public
Changes msg.sender
vote within a given proposal.
Parameters
_elementKey
proposal key_newIndex
updated index voter wants to vote for
function removeVote(bytes32 _elementKey) public
Removes msg.sender
vote within a given proposal.
Parameters
_elementKey
proposal key