Skip to content

Commit 15301e1

Browse files
committed
Revert "None universal voting machines (#757)"
This reverts commit 51c72e5.
1 parent 51c72e5 commit 15301e1

32 files changed

+937
-1185
lines changed

contracts/schemes/ArcScheme.sol

Lines changed: 21 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,12 @@ import "../controller/Avatar.sol";
44
import "@daostack/infra-experimental/contracts/votingMachines/GenesisProtocol.sol";
55
import "@daostack/infra-experimental/contracts/votingMachines/IntVoteInterface.sol";
66
import "@openzeppelin/upgrades/contracts/Initializable.sol";
7-
import "../utils/DAOFactory.sol";
8-
import "../libs/StringUtil.sol";
97

108

119
contract ArcScheme is Initializable {
12-
using StringUtil for string;
1310
Avatar public avatar;
1411
IntVoteInterface public votingMachine;
15-
16-
string public constant GENESIS_PROTOCOL_INIT_FUNC_SIGNATURE =
17-
"initialize(address,uint256[11],address,address,address,address)";
18-
19-
string public constant ABSOLUTE_VOTE_INIT_FUNC_SIGNATURE =
20-
"initialize(uint256,address,address,address,address)";
12+
bytes32 public voteParamsHash;
2113

2214
/**
2315
* @dev _initialize
@@ -32,60 +24,35 @@ contract ArcScheme is Initializable {
3224
/**
3325
* @dev _initializeGovernance
3426
* @param _avatar the scheme avatar
27+
* @param _votingMachine the scheme voting machine
28+
* @param _voteParamsHash the scheme vote params
3529
* @param _votingParams genesisProtocol parameters - valid only if _voteParamsHash is zero
36-
* @param _voteOnBehalf parameter
37-
* @param _daoFactory DAOFactory instance to instance a votingMachine.
38-
* @param _stakingToken (for GenesisProtocol)
39-
* @param _callbacks should fulfill voting callbacks interface
40-
* @param _authorizedToPropose only this address allow to propose (unless it is zero)
41-
* @param _packageVersion packageVersion to instance the votingMachine from.
42-
* @param _votingMachineName the votingMachine contract name.
30+
* @param _voteOnBehalf genesisProtocol parameter - valid only if _voteParamsHash is zero
4331
*/
4432
function _initializeGovernance(
4533
Avatar _avatar,
34+
IntVoteInterface _votingMachine,
35+
bytes32 _voteParamsHash,
4636
uint256[11] memory _votingParams,
47-
address _voteOnBehalf,
48-
DAOFactory _daoFactory,
49-
address _stakingToken,
50-
address _callbacks,
51-
address _authorizedToPropose,
52-
uint64[3] memory _packageVersion,
53-
string memory _votingMachineName
37+
address _voteOnBehalf
5438
) internal
5539
{
56-
57-
require(_daoFactory != DAOFactory(0), "daoFactory cannot be zero");
58-
require(
59-
_daoFactory.getImplementation(_packageVersion, _votingMachineName) != address(0),
60-
"votingMachine name does not exist in ArcHive"
61-
);
40+
require(_votingMachine != IntVoteInterface(0), "votingMachine cannot be zero");
6241
_initialize(_avatar);
63-
64-
bytes memory initData;
65-
if (_votingMachineName.hashCompareWithLengthCheck("GenesisProtocol")) {
66-
initData = abi.encodeWithSignature(
67-
GENESIS_PROTOCOL_INIT_FUNC_SIGNATURE,
68-
_stakingToken,
69-
_votingParams,
70-
_voteOnBehalf,
71-
avatar,
72-
_callbacks,
73-
_authorizedToPropose);
42+
votingMachine = _votingMachine;
43+
if (_voteParamsHash == bytes32(0)) {
44+
//genesisProtocol
45+
GenesisProtocol genesisProtocol = GenesisProtocol(address(_votingMachine));
46+
voteParamsHash = genesisProtocol.getParametersHash(_votingParams, _voteOnBehalf);
47+
(uint256 queuedVoteRequiredPercentage, , , , , , , , , , , ,) =
48+
genesisProtocol.parameters(voteParamsHash);
49+
if (queuedVoteRequiredPercentage == 0) {
50+
//params not set already
51+
genesisProtocol.setParameters(_votingParams, _voteOnBehalf);
52+
}
7453
} else {
75-
initData = abi.encodeWithSignature(
76-
ABSOLUTE_VOTE_INIT_FUNC_SIGNATURE,
77-
_votingParams[0],
78-
_voteOnBehalf,
79-
avatar,
80-
_callbacks,
81-
_authorizedToPropose);
54+
//for other voting machines
55+
voteParamsHash = _voteParamsHash;
8256
}
83-
84-
votingMachine = IntVoteInterface(address(_daoFactory.createInstance(
85-
_packageVersion,
86-
_votingMachineName,
87-
address(avatar),
88-
initData)));
89-
9057
}
9158
}

contracts/schemes/ContributionReward.sol

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -65,35 +65,22 @@ contract ContributionReward is
6565
/**
6666
* @dev initialize
6767
* @param _avatar the avatar this scheme referring to.
68-
* @param _votingParams genesisProtocol parameters
69-
* @param _voteOnBehalf parameter
70-
* @param _daoFactory DAOFactory instance to instance a votingMachine.
71-
* @param _stakingToken (for GenesisProtocol)
72-
* @param _packageVersion packageVersion to instance the votingMachine from.
73-
* @param _votingMachineName the votingMachine contract name.
68+
* @param _votingMachine the voting machines address to
69+
* @param _votingParams genesisProtocol parameters - valid only if _voteParamsHash is zero
70+
* @param _voteOnBehalf genesisProtocol parameter - valid only if _voteParamsHash is zero
71+
* @param _voteParamsHash voting machine parameters.
7472
*/
7573
function initialize(
7674
Avatar _avatar,
75+
IntVoteInterface _votingMachine,
7776
uint256[11] calldata _votingParams,
7877
address _voteOnBehalf,
79-
DAOFactory _daoFactory,
80-
address _stakingToken,
81-
uint64[3] calldata _packageVersion,
82-
string calldata _votingMachineName
78+
bytes32 _voteParamsHash
8379
)
8480
external
8581
initializer
8682
{
87-
super._initializeGovernance(
88-
_avatar,
89-
_votingParams,
90-
_voteOnBehalf,
91-
_daoFactory,
92-
_stakingToken,
93-
address(this),
94-
address(this),
95-
_packageVersion,
96-
_votingMachineName);
83+
super._initializeGovernance(_avatar, _votingMachine, _voteParamsHash, _votingParams, _voteOnBehalf);
9784
}
9885

9986
/**
@@ -140,7 +127,7 @@ contract ContributionReward is
140127
returns(bytes32)
141128
{
142129
validateProposalParams(_reputationChange, _rewards);
143-
bytes32 proposalId = votingMachine.propose(2, msg.sender);
130+
bytes32 proposalId = votingMachine.propose(2, voteParamsHash, msg.sender, address(avatar));
144131
address payable beneficiary = _beneficiary;
145132
if (beneficiary == address(0)) {
146133
beneficiary = msg.sender;

contracts/schemes/ContributionRewardExt.sol

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -83,37 +83,30 @@ contract ContributionRewardExt is VotingMachineCallbacks, ProposalExecuteInterfa
8383

8484
/**
8585
* @dev initialize
86-
* @param _avatar the avatar this scheme referring to.
87-
* @param _votingParams genesisProtocol parameters
88-
* @param _voteOnBehalf parameter
89-
* @param _daoFactory DAOFactory instance to instance a votingMachine.
90-
* @param _stakingToken (for GenesisProtocol)
91-
* @param _packageVersion packageVersion to instance the votingMachine from.
92-
* @param _votingMachineName the votingMachine contract name.
86+
* @param _avatar the avatar to mint reputation from
87+
* @param _votingMachine the voting machines address
88+
* @param _votingParams genesisProtocol parameters - valid only if _voteParamsHash is zero
89+
* @param _voteOnBehalf genesisProtocol parameter - valid only if _voteParamsHash is zero
90+
* @param _voteParamsHash voting machine parameters
91+
* @param _daoFactory DAOFactory instance to instance a rewarder.
92+
* if _daoFactory is zero so no rewarder will be set.
93+
* @param _packageVersion packageVersion to instance the rewarder from.
9394
* @param _rewarderName the rewarder contract name.
95+
9496
*/
9597
function initialize(
9698
Avatar _avatar,
97-
uint256[11] calldata _votingParams,
99+
IntVoteInterface _votingMachine,
100+
uint[11] calldata _votingParams,
98101
address _voteOnBehalf,
102+
bytes32 _voteParamsHash,
99103
DAOFactory _daoFactory,
100-
address _stakingToken,
101104
uint64[3] calldata _packageVersion,
102-
string calldata _votingMachineName,
103105
string calldata _rewarderName
104106
)
105107
external
106108
{
107-
super._initializeGovernance(
108-
_avatar,
109-
_votingParams,
110-
_voteOnBehalf,
111-
_daoFactory,
112-
_stakingToken,
113-
address(this),
114-
address(this),
115-
_packageVersion,
116-
_votingMachineName);
109+
super._initializeGovernance(_avatar, _votingMachine, _voteParamsHash, _votingParams, _voteOnBehalf);
117110
vault = new Vault();
118111
vault.initialize(address(this));
119112
if (bytes(_rewarderName).length != 0) {
@@ -170,7 +163,7 @@ contract ContributionRewardExt is VotingMachineCallbacks, ProposalExecuteInterfa
170163
if (proposer == address(0)) {
171164
proposer = msg.sender;
172165
}
173-
proposalId = votingMachine.propose(2, proposer);
166+
proposalId = votingMachine.propose(2, voteParamsHash, proposer, address(avatar));
174167
address payable beneficiary = _beneficiary;
175168
if (beneficiary == address(0)) {
176169
beneficiary = msg.sender;

contracts/schemes/ControllerUpgradeScheme.sol

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,34 +41,21 @@ contract ControllerUpgradeScheme is VotingMachineCallbacks, ProposalExecuteInter
4141
/**
4242
* @dev initialize
4343
* @param _avatar the avatar this scheme referring to.
44-
* @param _votingParams genesisProtocol parameters
45-
* @param _voteOnBehalf parameter
46-
* @param _daoFactory DAOFactory instance to instance a votingMachine.
47-
* @param _stakingToken (for GenesisProtocol)
48-
* @param _packageVersion packageVersion to instance the votingMachine from.
49-
* @param _votingMachineName the votingMachine contract name.
44+
* @param _votingMachine the voting machines address to
45+
* @param _votingParams genesisProtocol parameters - valid only if _voteParamsHash is zero
46+
* @param _voteOnBehalf genesisProtocol parameter - valid only if _voteParamsHash is zero
47+
* @param _voteParamsHash voting machine parameters.
5048
*/
5149
function initialize(
5250
Avatar _avatar,
51+
IntVoteInterface _votingMachine,
5352
uint256[11] calldata _votingParams,
5453
address _voteOnBehalf,
55-
DAOFactory _daoFactory,
56-
address _stakingToken,
57-
uint64[3] calldata _packageVersion,
58-
string calldata _votingMachineName
54+
bytes32 _voteParamsHash
5955
)
6056
external
6157
{
62-
super._initializeGovernance(
63-
_avatar,
64-
_votingParams,
65-
_voteOnBehalf,
66-
_daoFactory,
67-
_stakingToken,
68-
address(this),
69-
address(this),
70-
_packageVersion,
71-
_votingMachineName);
58+
super._initializeGovernance(_avatar, _votingMachine, _voteParamsHash, _votingParams, _voteOnBehalf);
7259
}
7360

7461
/**
@@ -116,7 +103,7 @@ contract ControllerUpgradeScheme is VotingMachineCallbacks, ProposalExecuteInter
116103
public
117104
returns(bytes32)
118105
{
119-
bytes32 proposalId = votingMachine.propose(2, msg.sender);
106+
bytes32 proposalId = votingMachine.propose(2, voteParamsHash, msg.sender, address(avatar));
120107
UpgradeProposal memory proposal = UpgradeProposal({
121108
proposalType: 1,
122109
upgradeContract: _newController
@@ -148,7 +135,7 @@ contract ControllerUpgradeScheme is VotingMachineCallbacks, ProposalExecuteInter
148135
public
149136
returns(bytes32)
150137
{
151-
bytes32 proposalId = votingMachine.propose(2, msg.sender);
138+
bytes32 proposalId = votingMachine.propose(2, voteParamsHash, msg.sender, address(avatar));
152139
require(organizationProposals[proposalId].proposalType == 0);
153140

154141
UpgradeProposal memory proposal = UpgradeProposal({

contracts/schemes/FundingRequest.sol

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,36 +46,23 @@ contract FundingRequest is
4646
/**
4747
* @dev initialize
4848
* @param _avatar the avatar this scheme referring to.
49-
* @param _votingParams genesisProtocol parameters
50-
* @param _voteOnBehalf parameter
51-
* @param _daoFactory DAOFactory instance to instance a votingMachine.
52-
* @param _stakingToken (for GenesisProtocol)
53-
* @param _packageVersion packageVersion to instance the votingMachine from.
54-
* @param _votingMachineName the votingMachine contract name.
49+
* @param _votingMachine the voting machines address to
50+
* @param _votingParams genesisProtocol parameters - valid only if _voteParamsHash is zero
51+
* @param _voteOnBehalf genesisProtocol parameter - valid only if _voteParamsHash is zero
52+
* @param _voteParamsHash voting machine parameters.
5553
* @param _fundingToken token to transfer to funding requests. 0x0 address for the native coin
5654
*/
5755
function initialize(
5856
Avatar _avatar,
57+
IntVoteInterface _votingMachine,
5958
uint256[11] calldata _votingParams,
6059
address _voteOnBehalf,
61-
DAOFactory _daoFactory,
62-
address _stakingToken,
63-
uint64[3] calldata _packageVersion,
64-
string calldata _votingMachineName,
60+
bytes32 _voteParamsHash,
6561
IERC20 _fundingToken
6662
)
6763
external
6864
{
69-
super._initializeGovernance(
70-
_avatar,
71-
_votingParams,
72-
_voteOnBehalf,
73-
_daoFactory,
74-
_stakingToken,
75-
address(this),
76-
address(this),
77-
_packageVersion,
78-
_votingMachineName);
65+
super._initializeGovernance(_avatar, _votingMachine, _voteParamsHash, _votingParams, _voteOnBehalf);
7966
fundingToken = _fundingToken;
8067
}
8168

@@ -117,7 +104,7 @@ contract FundingRequest is
117104
avatar.db(FUNDED_BEFORE_DEADLINE_KEY).hashCompareWithLengthCheck(FUNDED_BEFORE_DEADLINE_VALUE),
118105
"funding is not allowed yet"
119106
);
120-
bytes32 proposalId = votingMachine.propose(2, msg.sender);
107+
bytes32 proposalId = votingMachine.propose(2, voteParamsHash, msg.sender, address(avatar));
121108
address payable beneficiary = _beneficiary;
122109
if (beneficiary == address(0)) {
123110
beneficiary = msg.sender;

contracts/schemes/GenericScheme.sol

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,37 +47,24 @@ contract GenericScheme is VotingMachineCallbacks, ProposalExecuteInterface {
4747

4848
/**
4949
* @dev initialize
50-
* @param _avatar the avatar this scheme referring to.
51-
* @param _votingParams genesisProtocol parameters
52-
* @param _voteOnBehalf parameter
53-
* @param _daoFactory DAOFactory instance to instance a votingMachine.
54-
* @param _stakingToken (for GenesisProtocol)
55-
* @param _packageVersion packageVersion to instance the votingMachine from.
56-
* @param _votingMachineName the votingMachine contract name.
50+
* @param _avatar the avatar to mint reputation from
51+
* @param _votingMachine the voting machines address to
52+
* @param _votingParams genesisProtocol parameters - valid only if _voteParamsHash is zero
53+
* @param _voteOnBehalf genesisProtocol parameter - valid only if _voteParamsHash is zero
54+
* @param _voteParamsHash voting machine parameters.
5755
* @param _contractToCall the target contract this scheme will call to
5856
*/
5957
function initialize(
6058
Avatar _avatar,
59+
IntVoteInterface _votingMachine,
6160
uint256[11] calldata _votingParams,
6261
address _voteOnBehalf,
63-
DAOFactory _daoFactory,
64-
address _stakingToken,
65-
uint64[3] calldata _packageVersion,
66-
string calldata _votingMachineName,
62+
bytes32 _voteParamsHash,
6763
address _contractToCall
6864
)
6965
external
7066
{
71-
super._initializeGovernance(
72-
_avatar,
73-
_votingParams,
74-
_voteOnBehalf,
75-
_daoFactory,
76-
_stakingToken,
77-
address(this),
78-
address(this),
79-
_packageVersion,
80-
_votingMachineName);
67+
super._initializeGovernance(_avatar, _votingMachine, _voteParamsHash, _votingParams, _voteOnBehalf);
8168
contractToCall = _contractToCall;
8269
}
8370

@@ -142,7 +129,7 @@ contract GenericScheme is VotingMachineCallbacks, ProposalExecuteInterface {
142129
public
143130
returns(bytes32)
144131
{
145-
bytes32 proposalId = votingMachine.propose(2, msg.sender);
132+
bytes32 proposalId = votingMachine.propose(2, voteParamsHash, msg.sender, address(avatar));
146133

147134
organizationProposals[proposalId] = CallProposal({
148135
callData: _callData,

0 commit comments

Comments
 (0)