@@ -2,8 +2,8 @@ pragma solidity ^0.4.24;
2
2
3
3
import "./IntVoteInterface.sol " ;
4
4
import { RealMath } from "../libs/RealMath.sol " ;
5
- import "./GenesisProtocolCallbacksInterface .sol " ;
6
- import "./GenesisProtocolExecuteInterface .sol " ;
5
+ import "./VotingMachineCallbacksInterface .sol " ;
6
+ import "./ProposalExecuteInterface .sol " ;
7
7
import "openzeppelin-solidity/contracts/math/SafeMath.sol " ;
8
8
import "openzeppelin-solidity/contracts/token/ERC20/StandardToken.sol " ;
9
9
import "openzeppelin-solidity/contracts/ECRecovery.sol " ;
@@ -47,7 +47,7 @@ contract GenesisProtocol is IntVoteInterface {
47
47
//and daoBountyConst is a constant factor that is configurable and changeable by the DAO given.
48
48
// daoBountyConst should be greater than stakerFeeRatioForVoters and less than 2 * stakerFeeRatioForVoters.
49
49
//daoBountyParams[1] = daoBountyLimit The daoBounty cannot be greater than daoBountyLimit.
50
- address voteOnBehalf; //this address is allowd to vote of behalf of someone else.
50
+ address voteOnBehalf; //this address is allowed to vote of behalf of someone else.
51
51
}
52
52
struct Voter {
53
53
uint vote; // YES(1) ,NO(2)
@@ -62,7 +62,8 @@ contract GenesisProtocol is IntVoteInterface {
62
62
}
63
63
64
64
struct Proposal {
65
- address organization; // the organization's address the proposal is target to. fullfill genesisProtocol callbacks interface.
65
+ bytes32 organization; // the organization unique identifier the proposal is target to.
66
+ address callbacks; // should fulfill voting callbacks interface.
66
67
uint numOfChoices;
67
68
uint votersStakes;
68
69
uint submittedTime;
@@ -87,10 +88,10 @@ contract GenesisProtocol is IntVoteInterface {
87
88
mapping (address => Staker ) stakers;
88
89
}
89
90
90
- event Stake (bytes32 indexed _proposalId , address indexed _organization , address indexed _staker ,uint _vote ,uint _amount );
91
- event Redeem (bytes32 indexed _proposalId , address indexed _organization , address indexed _beneficiary ,uint _amount );
92
- event RedeemDaoBounty (bytes32 indexed _proposalId , address indexed _organization , address indexed _beneficiary ,uint _amount );
93
- event RedeemReputation (bytes32 indexed _proposalId , address indexed _organization , address indexed _beneficiary ,uint _amount );
91
+ event Stake (bytes32 indexed _proposalId , bytes32 indexed _organization , address indexed _staker ,uint _vote ,uint _amount );
92
+ event Redeem (bytes32 indexed _proposalId , bytes32 indexed _organization , address indexed _beneficiary ,uint _amount );
93
+ event RedeemDaoBounty (bytes32 indexed _proposalId , bytes32 indexed _organization , address indexed _beneficiary ,uint _amount );
94
+ event RedeemReputation (bytes32 indexed _proposalId , bytes32 indexed _organization , address indexed _beneficiary ,uint _amount );
94
95
event GPExecuteProposal (bytes32 indexed _proposalId , ExecutionState _executionState );
95
96
96
97
mapping (bytes32 => Parameters) public parameters; // A mapping from hashes to parameters
@@ -100,25 +101,27 @@ contract GenesisProtocol is IntVoteInterface {
100
101
uint constant public NO = 2 ;
101
102
uint constant public YES = 1 ;
102
103
uint public proposalsCnt; // Total number of proposals
103
- mapping (address => uint ) public orgBoostedProposalsCnt;
104
+ mapping (bytes32 => uint ) public orgBoostedProposalsCnt;
104
105
StandardToken public stakingToken;
105
106
mapping (bytes => bool ) stakeSignatures; //stake signatures
106
107
address constant GEN_TOKEN_ADDRESS = 0x543Ff227F64Aa17eA132Bf9886cAb5DB55DCAddf ;
107
- mapping (address => OrderStatisticTree.Tree) proposalsExpiredTimes; //proposals expired times
108
+ mapping (bytes32 => OrderStatisticTree.Tree) proposalsExpiredTimes; //proposals expired times
108
109
109
110
// Digest describing the data the user signs according EIP 712.
110
111
// Needs to match what is passed to Metamask.
111
112
bytes32 public constant DELEGATION_HASH_EIP712 =
112
113
keccak256 (abi.encodePacked ("address GenesisProtocolAddress " ,"bytes32 ProposalId " , "uint Vote " ,"uint AmountToStake " ,"uint Nonce " ));
113
114
// web3.eth.sign prefix
114
115
string public constant ETH_SIGN_PREFIX= "\x19Ethereum Signed Message:\n32 " ;
115
-
116
116
/**
117
117
* @dev Constructor
118
118
*/
119
119
constructor (StandardToken _stakingToken ) public
120
120
{
121
-
121
+ //The GEN token (staking token) address is hard coded in the contract by GEN_TOKEN_ADDRESS .
122
+ //This will work for a network which already hosted the GEN token on this address (e.g mainnet).
123
+ //If such contract address does not exist in the network (e.g ganache) the contract will use the _stakingToken param as the
124
+ //staking token address.
122
125
if (isContract (address (GEN_TOKEN_ADDRESS))) {
123
126
stakingToken = StandardToken (GEN_TOKEN_ADDRESS);
124
127
} else {
@@ -140,9 +143,9 @@ contract GenesisProtocol is IntVoteInterface {
140
143
* @param _numOfChoices number of voting choices
141
144
* @param _paramsHash parameters hash
142
145
* @param _proposer address
143
- * @return proposal's id.
146
+ * @param _organization address
144
147
*/
145
- function propose (uint _numOfChoices , bytes32 _paramsHash ,address _proposer )
148
+ function propose (uint _numOfChoices , bytes32 _paramsHash ,address _proposer , address _organization )
146
149
external
147
150
returns (bytes32 )
148
151
{
@@ -156,7 +159,9 @@ contract GenesisProtocol is IntVoteInterface {
156
159
// Open proposal:
157
160
Proposal memory proposal;
158
161
proposal.numOfChoices = _numOfChoices;
159
- proposal.organization = msg .sender ;
162
+ proposal.callbacks = msg .sender ;
163
+ proposal.organization = keccak256 (abi.encodePacked (msg .sender ,_organization));
164
+
160
165
proposal.state = ProposalState.PreBoosted;
161
166
// solium-disable-next-line security/no-block-members
162
167
proposal.submittedTime = now ;
@@ -165,7 +170,6 @@ contract GenesisProtocol is IntVoteInterface {
165
170
proposal.winningVote = NO;
166
171
proposal.paramsHash = _paramsHash;
167
172
proposals[proposalId] = proposal;
168
- //GenesisProtocolCallbacksInterface(proposal.organization).setProposal(proposalId);
169
173
emit NewProposal (proposalId, proposal.organization, _numOfChoices, _proposer, _paramsHash);
170
174
return proposalId;
171
175
}
@@ -365,25 +369,12 @@ contract GenesisProtocol is IntVoteInterface {
365
369
/**
366
370
* @dev getProposalOrganization return the organization for a given proposal
367
371
* @param _proposalId the ID of the proposal
368
- * @return uint total reputation supply
372
+ * @return bytes32 organization identifier
369
373
*/
370
- function getProposalOrganization (bytes32 _proposalId ) external view returns (address ) {
374
+ function getProposalOrganization (bytes32 _proposalId ) external view returns (bytes32 ) {
371
375
return (proposals[_proposalId].organization);
372
376
}
373
377
374
- /**
375
- * @dev scoreThresholdParams return the score threshold params for a given
376
- * organization.
377
- * @param _organization the organization's organization
378
- * @return uint thresholdConstA
379
- * @return uint thresholdConstB
380
- */
381
- /*function scoreThresholdParams(address _organization) external view returns(uint,uint) {
382
- bytes32 paramsHash = GenesisProtocolCallbacksInterface(_organization).getParametersHash();
383
- Parameters memory params = parameters[paramsHash];
384
- return (params.thresholdConstA,params.thresholdConstB);
385
- }*/
386
-
387
378
/**
388
379
* @dev getStaker return the vote and stake amount for a given proposal and staker
389
380
* @param _proposalId the ID of the proposal
@@ -519,7 +510,7 @@ contract GenesisProtocol is IntVoteInterface {
519
510
emit Redeem (_proposalId,proposal.organization,_beneficiary,amount);
520
511
}
521
512
if (reputation != 0 ) {
522
- GenesisProtocolCallbacksInterface (proposal.organization ).mintReputation (reputation,_beneficiary,_proposalId);
513
+ VotingMachineCallbacksInterface (proposal.callbacks ).mintReputation (reputation,_beneficiary,_proposalId);
523
514
emit RedeemReputation (_proposalId,proposal.organization,_beneficiary,reputation);
524
515
}
525
516
}
@@ -552,9 +543,11 @@ contract GenesisProtocol is IntVoteInterface {
552
543
potentialAmount = beneficiaryLimit;
553
544
}
554
545
}
555
- if ((potentialAmount != 0 )&& (stakingToken.balanceOf (proposal.organization) >= potentialAmount)) {
546
+ if ((potentialAmount != 0 )&&
547
+ (VotingMachineCallbacksInterface (proposal.callbacks).balanceOfStakingToken (stakingToken,_proposalId) >= potentialAmount))
548
+ {
556
549
proposal.daoBountyRemain = proposal.daoBountyRemain.sub (potentialAmount);
557
- require (GenesisProtocolCallbacksInterface (proposal.organization ).stakingTokenTransfer (stakingToken,_beneficiary,potentialAmount,_proposalId));
550
+ require (VotingMachineCallbacksInterface (proposal.callbacks ).stakingTokenTransfer (stakingToken,_beneficiary,potentialAmount,_proposalId));
558
551
proposal.stakers[_beneficiary].amountForBounty = 0 ;
559
552
redeemedAmount = potentialAmount;
560
553
emit RedeemDaoBounty (_proposalId,proposal.organization,_beneficiary,redeemedAmount);
@@ -582,10 +575,10 @@ contract GenesisProtocol is IntVoteInterface {
582
575
583
576
/**
584
577
* @dev getBoostedProposalsCount return the number of boosted proposal for an organization
585
- * @param _organization the organization
578
+ * @param _organization the organization identifier
586
579
* @return uint number of boosted proposals
587
580
*/
588
- function getBoostedProposalsCount (address _organization ) public view returns (uint ) {
581
+ function getBoostedProposalsCount (bytes32 _organization ) public view returns (uint ) {
589
582
uint expiredProposals;
590
583
if (proposalsExpiredTimes[_organization].count () != 0 ) {
591
584
// solium-disable-next-line security/no-block-members
@@ -598,11 +591,11 @@ contract GenesisProtocol is IntVoteInterface {
598
591
* @dev threshold return the organization's score threshold which required by
599
592
* a proposal to shift to boosted state.
600
593
* This threshold is dynamically set and it depend on the number of boosted proposal.
601
- * @param _organization the organization
594
+ * @param _organization the organization identifier
602
595
* @param _paramsHash the organization parameters hash
603
596
* @return int organization's score threshold.
604
597
*/
605
- function threshold (bytes32 _paramsHash ,address _organization ) public view returns (int ) {
598
+ function threshold (bytes32 _paramsHash ,bytes32 _organization ) public view returns (int ) {
606
599
uint boostedProposals = getBoostedProposalsCount (_organization);
607
600
int216 e = 2 ;
608
601
@@ -634,6 +627,7 @@ contract GenesisProtocol is IntVoteInterface {
634
627
* _params[11] -_votersGainRepRatioFromLostRep
635
628
* _params[12] - _daoBountyConst
636
629
* _params[13] - _daoBountyLimit
630
+ * @param _voteOnBehalf - authorized to vote on behalf of others.
637
631
*/
638
632
function setParameters (
639
633
uint [14 ] _params , //use array here due to stack too deep issue.
@@ -654,7 +648,7 @@ contract GenesisProtocol is IntVoteInterface {
654
648
require (_params[12 ] <= (2 * _params[9 ]),"daoBountyConst <= 2 * stakerFeeRatioForVoters " );
655
649
require (_params[12 ] >= _params[9 ],"daoBountyConst >= stakerFeeRatioForVoters " );
656
650
657
- bytes32 paramsHash = getParametersHash (_params,_voteOnBehalf);
651
+ bytes32 paramsHash = getParametersHash (_params, _voteOnBehalf);
658
652
659
653
uint [2 ] memory _daoBountyParams;
660
654
_daoBountyParams[0 ] = _params[12 ];
@@ -710,7 +704,7 @@ contract GenesisProtocol is IntVoteInterface {
710
704
_params[12 ],
711
705
_params[13 ]
712
706
)),
713
- _voteOnBehalf
707
+ _voteOnBehalf
714
708
));
715
709
}
716
710
@@ -724,7 +718,7 @@ contract GenesisProtocol is IntVoteInterface {
724
718
Proposal storage proposal = proposals[_proposalId];
725
719
Parameters memory params = parameters[proposal.paramsHash];
726
720
Proposal memory tmpProposal = proposal;
727
- uint totalReputation = GenesisProtocolCallbacksInterface (proposal.organization ).getTotalReputationSupply (_proposalId);
721
+ uint totalReputation = VotingMachineCallbacksInterface (proposal.callbacks ).getTotalReputationSupply (_proposalId);
728
722
uint executionBar = totalReputation * params.preBoostedVoteRequiredPercentage/ 100 ;
729
723
ExecutionState executionState = ExecutionState.None;
730
724
@@ -775,8 +769,7 @@ contract GenesisProtocol is IntVoteInterface {
775
769
}
776
770
emit ExecuteProposal (_proposalId, proposal.organization, proposal.winningVote, totalReputation);
777
771
emit GPExecuteProposal (_proposalId, executionState);
778
- GenesisProtocolExecuteInterface (proposal.organization).executeProposal (_proposalId,int (proposal.winningVote));
779
- //(tmpProposal.executable).execute(_proposalId, tmpProposal.organization, int(proposal.winningVote));
772
+ ProposalExecuteInterface (proposal.callbacks).executeProposal (_proposalId,int (proposal.winningVote));
780
773
}
781
774
return (executionState != ExecutionState.None);
782
775
}
@@ -850,7 +843,7 @@ contract GenesisProtocol is IntVoteInterface {
850
843
Proposal storage proposal = proposals[_proposalId];
851
844
852
845
// Check voter has enough reputation:
853
- uint reputation = GenesisProtocolCallbacksInterface (proposal.organization ).reputationOf (_voter,_proposalId);
846
+ uint reputation = VotingMachineCallbacksInterface (proposal.callbacks ).reputationOf (_voter,_proposalId);
854
847
require (reputation >= _rep,"reputation >= _rep " );
855
848
uint rep = _rep;
856
849
if (rep == 0 ) {
@@ -891,7 +884,7 @@ contract GenesisProtocol is IntVoteInterface {
891
884
if (proposal.state == ProposalState.PreBoosted) {
892
885
proposal.preBoostedVotes[_vote] = rep.add (proposal.preBoostedVotes[_vote]);
893
886
uint reputationDeposit = (params.votersReputationLossRatio * rep)/ 100 ;
894
- GenesisProtocolCallbacksInterface (proposal.organization ).burnReputation (reputationDeposit,_voter,_proposalId);
887
+ VotingMachineCallbacksInterface (proposal.callbacks ).burnReputation (reputationDeposit,_voter,_proposalId);
895
888
}
896
889
// Event:
897
890
emit VoteProposal (_proposalId, proposal.organization, _voter, _vote, rep);
0 commit comments