Skip to content

Commit

Permalink
Improve StdDaoToken - startVoting/endVoting through the DaoBase #210
Browse files Browse the repository at this point in the history
  • Loading branch information
RostyslavBortman committed Jul 24, 2018
1 parent 5ec5a4d commit 3567bc0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
4 changes: 2 additions & 2 deletions contracts/governance/Voting_SimpleToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ contract Voting_SimpleToken is IVoting, Ownable {

constructor(IDaoBase _dao, IProposal _proposal,
address _origin, uint _minutesToVote,
uint _quorumPercent, uint _consensusPercent, address _tokenAddress, bool _isQuadraticVoting) public
uint _quorumPercent, uint _consensusPercent, address _tokenAddress, bool _isQuadraticVoting, uint _votingID) public
{
require((_quorumPercent<=100)&&(_quorumPercent>0));
require((_consensusPercent<=100)&&(_consensusPercent>0));
Expand All @@ -66,7 +66,7 @@ contract Voting_SimpleToken is IVoting, Ownable {
consensusPercent = _consensusPercent;
isQuadraticVoting = _isQuadraticVoting;
stdDaoToken = StdDaoToken(_tokenAddress);
votingID = stdDaoToken.startNewVoting();
votingID = _votingID;

genesis = uint64(now);

Expand Down
13 changes: 11 additions & 2 deletions contracts/tokens/StdDaoToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "zeppelin-solidity/contracts/token/ERC20/DetailedERC20.sol";

import "./CopyOnWriteToken.sol";
import "./ITokenVotingSupport.sol";
import "../DaoBase.sol";

/**
* @title StdDaoToken
Expand All @@ -24,13 +25,17 @@ import "./ITokenVotingSupport.sol";
* finishVoting()
* getBalanceAtVoting()
*/
contract StdDaoToken is DetailedERC20, PausableToken, CopyOnWriteToken, ITokenVotingSupport {
contract StdDaoToken is DetailedERC20, PausableToken, CopyOnWriteToken, ITokenVotingSupport, DaoBase {
uint256 public cap;
bool isBurnable;
bool isPausable;

address[] public holders;
mapping (address => bool) isHolder;
mapping (uint => mapping(address => bool)) isOwner;


bytes32 public TOKEN_StartNewVoting = keccak256(abi.encodePacked("TOKEN_StartNewVoting"));

modifier isBurnable_() {
require (isBurnable);
Expand Down Expand Up @@ -58,14 +63,18 @@ contract StdDaoToken is DetailedERC20, PausableToken, CopyOnWriteToken, ITokenVo

// ITokenVotingSupport implementation
// TODO: VULNERABILITY! no onlyOwner!
function startNewVoting() public whenNotPaused returns(uint) {
function startNewVoting() public whenNotPaused isCanDo(TOKEN_StartNewVoting) returns(uint) {
uint idOut = super.startNewEvent();
isOwner[idOut][msg.sender] = true;
emit VotingStarted(msg.sender, idOut);
return idOut;
}

// TODO: VULNERABILITY! no onlyOwner!
function finishVoting(uint _votingID) whenNotPaused public {
require (isOwner[_votingID][msg.sender]);
isOwner[_votingID][msg.sender] = false;

super.finishEvent(_votingID);
emit VotingFinished(msg.sender, _votingID);
}
Expand Down
17 changes: 15 additions & 2 deletions contracts/utils/GenericCaller.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "../IDaoBase.sol";
import "../governance/Voting_1p1v.sol";
import "../governance/Voting_SimpleToken.sol";
import "../governance/Proposals.sol";
import "../tokens/StdDaoToken.sol";

import "zeppelin-solidity/contracts/ownership/Ownable.sol";

Expand Down Expand Up @@ -91,6 +92,13 @@ contract GenericCaller is DaoClient, Ownable {
}
}

function finishVoting(bytes32 _permissionIdHash, uint _votingID) public onlyOwner {
VotingParams memory vp = votingParams[_permissionIdHash];
StdDaoToken memory token = StdDaoToken(address(vp.param5));
token.finishVoting(_votingID);
}


function setVotingParams(bytes32 _permissionIdHash, uint _votingType,
bytes32 _param1, bytes32 _param2,
bytes32 _param3, bytes32 _param4, bytes32 _param5) public onlyOwner {
Expand All @@ -107,6 +115,8 @@ contract GenericCaller is DaoClient, Ownable {

function createVoting(bytes32 _permissionIdHash, IProposal _proposal, address _origin)internal returns(IVoting){
VotingParams memory vp = votingParams[_permissionIdHash];
StdDaoToken memory token = StdDaoToken(address(vp.param5));
uint votingID = token.startNewVoting();

if(VotingType.Voting1p1v==vp.votingType){
return new Voting_1p1v(dao, _proposal, _origin,
Expand All @@ -117,12 +127,14 @@ contract GenericCaller is DaoClient, Ownable {
}

if(VotingType.VotingSimpleToken==vp.votingType){

return new Voting_SimpleToken(dao, _proposal, _origin,
uint(vp.param1),
uint(vp.param3),
uint(vp.param4),
address(vp.param5),
false);
false,
votingID);
}

if(VotingType.VotingQuadratic==vp.votingType){
Expand All @@ -131,7 +143,8 @@ contract GenericCaller is DaoClient, Ownable {
uint(vp.param3),
uint(vp.param4),
address(vp.param5),
true);
true,
votingID);
}

/*if(VotingType.VotingLiquid==vp.votingType){
Expand Down

0 comments on commit 3567bc0

Please sign in to comment.