-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Voting: Allow to modify required support #458
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -18,6 +18,7 @@ contract Voting is IForwarder, AragonApp { | |||
using SafeMath64 for uint64; | ||||
|
||||
bytes32 public constant CREATE_VOTES_ROLE = keccak256("CREATE_VOTES_ROLE"); | ||||
bytes32 public constant MODIFY_SUPPORT_ROLE = keccak256("MODIFY_SUPPORT_ROLE"); | ||||
bytes32 public constant MODIFY_QUORUM_ROLE = keccak256("MODIFY_QUORUM_ROLE"); | ||||
|
||||
uint256 public constant PCT_BASE = 10 ** 18; // 0% = 0; 1% = 10^16; 100% = 10^18 | ||||
|
@@ -28,6 +29,7 @@ contract Voting is IForwarder, AragonApp { | |||
address creator; | ||||
uint64 startDate; | ||||
uint256 snapshotBlock; | ||||
uint256 supportRequiredPct; | ||||
uint256 minAcceptQuorumPct; | ||||
uint256 yea; | ||||
uint256 nay; | ||||
|
@@ -50,6 +52,7 @@ contract Voting is IForwarder, AragonApp { | |||
event StartVote(uint256 indexed voteId); | ||||
event CastVote(uint256 indexed voteId, address indexed voter, bool supports, uint256 stake); | ||||
event ExecuteVote(uint256 indexed voteId); | ||||
event ChangeSupportRequired(uint256 supportRequiredPct); | ||||
event ChangeMinQuorum(uint256 minAcceptQuorumPct); | ||||
|
||||
modifier voteExists(uint256 _voteId) { | ||||
|
@@ -85,6 +88,21 @@ contract Voting is IForwarder, AragonApp { | |||
voteTime = _voteTime; | ||||
} | ||||
|
||||
/** | ||||
* @notice Change required support to `(_supportRequiredPct - _supportRequiredPct % 10^16) / 10^14`% | ||||
* @param _supportRequiredPct New required support | ||||
*/ | ||||
function changeSupportRequiredPct(uint256 _supportRequiredPct) | ||||
external | ||||
authP(MODIFY_SUPPORT_ROLE, arr(_supportRequiredPct, supportRequiredPct)) | ||||
{ | ||||
require(minAcceptQuorumPct <= _supportRequiredPct); | ||||
require(_supportRequiredPct <= PCT_BASE); | ||||
supportRequiredPct = _supportRequiredPct; | ||||
|
||||
emit ChangeSupportRequired(_supportRequiredPct); | ||||
} | ||||
|
||||
/** | ||||
* @notice Change minimum acceptance quorum to `(_minAcceptQuorumPct - _minAcceptQuorumPct % 10^16) / 10^14`% | ||||
* @param _minAcceptQuorumPct New acceptance quorum | ||||
|
@@ -178,7 +196,7 @@ contract Voting is IForwarder, AragonApp { | |||
} | ||||
|
||||
// Voting is already decided | ||||
if (_isValuePct(vote_.yea, vote_.totalVoters, supportRequiredPct)) { | ||||
if (_isValuePct(vote_.yea, vote_.totalVoters, vote_.supportRequiredPct)) { | ||||
return true; | ||||
} | ||||
|
||||
|
@@ -189,7 +207,7 @@ contract Voting is IForwarder, AragonApp { | |||
return false; | ||||
} | ||||
// Has enough support? | ||||
if (!_isValuePct(vote_.yea, totalVotes, supportRequiredPct)) { | ||||
if (!_isValuePct(vote_.yea, totalVotes, vote_.supportRequiredPct)) { | ||||
return false; | ||||
} | ||||
// Has min quorum? | ||||
|
@@ -210,6 +228,7 @@ contract Voting is IForwarder, AragonApp { | |||
address creator, | ||||
uint64 startDate, | ||||
uint256 snapshotBlock, | ||||
uint256 supportRequired, | ||||
uint256 minAcceptQuorum, | ||||
uint256 yea, | ||||
uint256 nay, | ||||
|
@@ -224,6 +243,7 @@ contract Voting is IForwarder, AragonApp { | |||
creator = vote_.creator; | ||||
startDate = vote_.startDate; | ||||
snapshotBlock = vote_.snapshotBlock; | ||||
supportRequired = vote_.supportRequiredPct; | ||||
minAcceptQuorum = vote_.minAcceptQuorumPct; | ||||
yea = vote_.yea; | ||||
nay = vote_.nay; | ||||
|
@@ -251,6 +271,7 @@ contract Voting is IForwarder, AragonApp { | |||
vote_.metadata = _metadata; | ||||
vote_.snapshotBlock = getBlockNumber() - 1; // avoid double voting in this very block | ||||
vote_.totalVoters = token.totalSupplyAt(vote_.snapshotBlock); | ||||
vote_.supportRequiredPct = supportRequiredPct; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚨 The cached aragon-apps/apps/voting/contracts/Voting.sol Line 210 in 97ca6b0
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, thanks!! I see that the test for it below is wrong too. |
||||
vote_.minAcceptQuorumPct = minAcceptQuorumPct; | ||||
|
||||
emit StartVote(voteId); | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've never understood this radspec calculation (here and elsewhere) 😅. Why not just
supportRequiredPct / 10^14
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was supposed to round to 2 decimals, but I think it's wrong,
14
and16
should be reverted.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason I changed it in commit 6bb186b 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whatever it's the good solution, will fix it in another PR as it affects to other functions here and Survey too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another helper function for radspec :)