Skip to content

Commit d0678a3

Browse files
remove import of genesis protocol + lint (#806)
* remove import of genesis protocol + lint * Use infra 20 * require valid vote params Co-authored-by: benk10 <[email protected]>
1 parent d316bd7 commit d0678a3

File tree

5 files changed

+45
-29
lines changed

5 files changed

+45
-29
lines changed

contracts/utils/GenericSchemeMultiCallFactory.sol

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
pragma solidity 0.5.17;
22

3+
import "@daostack/infra/contracts/votingMachines/GenesisProtocolInterface.sol";
34
import "../schemes/GenericSchemeMultiCall.sol";
45
import "../schemes/SimpleSchemeConstraints.sol";
5-
import "@daostack/infra/contracts/votingMachines/GenesisProtocol.sol";
66

77
/**
8-
* @title
8+
* @title GenericSchemeMultiCallFactory
99
*/
1010
contract GenericSchemeMultiCallFactory {
1111
uint8 public constant CUSTOM = 0;
@@ -24,14 +24,33 @@ contract GenericSchemeMultiCallFactory {
2424
address[] memory _contractsWhiteList,
2525
string memory _descriptionHash
2626
) public returns(address) {
27+
require(_voteParamsType < 4, "Vote params type specified does not exist");
2728
GenericSchemeMultiCall genericSchemeMultiCall = new GenericSchemeMultiCall();
2829
address simpleSchemeConstraints;
2930
if (_contractsWhiteList.length > 0) {
3031
simpleSchemeConstraints = address(new SimpleSchemeConstraints());
3132
SimpleSchemeConstraints(simpleSchemeConstraints).initialize(_contractsWhiteList, _descriptionHash);
3233
}
33-
3434
uint256[11] memory voteParams;
35+
if (_voteParamsType == CUSTOM) {
36+
// Custom params hash
37+
voteParams = _votingParams;
38+
} else {
39+
voteParams = getDefaultVoteParams(_voteParamsType);
40+
}
41+
42+
bytes32 voteParamsHash = GenesisProtocolInterface(address(_votingMachine))
43+
.setParameters(voteParams, _voteOnBehalf);
44+
45+
genericSchemeMultiCall.initialize(
46+
_avatar, _votingMachine, voteParamsHash, SchemeConstraints(simpleSchemeConstraints)
47+
);
48+
49+
emit NewGenericSchemeMultiCall(address(genericSchemeMultiCall));
50+
return address(genericSchemeMultiCall);
51+
}
52+
53+
function getDefaultVoteParams(uint8 _voteParamsType) private pure returns(uint256[11] memory voteParams) {
3554
if (_voteParamsType == FAST) {
3655
// Fast params hash
3756
voteParams = [
@@ -77,24 +96,6 @@ contract GenericSchemeMultiCallFactory {
7796
uint256(10),
7897
uint256(0)
7998
];
80-
} else {
81-
// Custom params hash
82-
voteParams = _votingParams;
8399
}
84-
85-
GenesisProtocol genesisProtocol = GenesisProtocol(address(_votingMachine));
86-
bytes32 voteParamsHash = genesisProtocol.getParametersHash(voteParams, _voteOnBehalf);
87-
(uint256 queuedVoteRequiredPercentage, , , , , , , , , , , ,) =
88-
genesisProtocol.parameters(voteParamsHash);
89-
if (queuedVoteRequiredPercentage == 0) {
90-
//params not set already
91-
genesisProtocol.setParameters(voteParams, _voteOnBehalf);
92-
}
93-
genericSchemeMultiCall.initialize(
94-
_avatar, _votingMachine, voteParamsHash, SchemeConstraints(simpleSchemeConstraints)
95-
);
96-
97-
emit NewGenericSchemeMultiCall(address(genericSchemeMultiCall));
98-
return address(genericSchemeMultiCall);
99100
}
100101
}

contracts/votingMachines/VotingMachineCallbacks.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
pragma solidity 0.5.17;
22

33
import "../universalSchemes/UniversalScheme.sol";
4-
import "@daostack/infra/contracts/votingMachines/GenesisProtocol.sol";
5-
4+
import "@daostack/infra/contracts/votingMachines/VotingMachineCallbacksInterface.sol";
5+
import "@daostack/infra/contracts/votingMachines/ProposalExecuteInterface.sol";
66

77

88
contract VotingMachineCallbacks is VotingMachineCallbacksInterface {

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@daostack/arc",
3-
"version": "0.0.1-rc.49",
3+
"version": "0.0.1-rc.50",
44
"description": "A platform for building DAOs",
55
"files": [
66
"contracts/",
@@ -78,7 +78,7 @@
7878
},
7979
"homepage": "https://daostack.io",
8080
"dependencies": {
81-
"@daostack/infra": "0.0.1-rc.19",
81+
"@daostack/infra": "0.0.1-rc.20",
8282
"math": "0.0.3",
8383
"openzeppelin-solidity": "2.4.0",
8484
"truffle-flattener": "^1.4.2"

test/genericschememulticallfactory.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,21 @@ contract('genericSchemeMultiCallFactory', function(accounts) {
104104
}
105105
}
106106

107+
try {
108+
await testSetup.genericSchemeMultiCallFactory.createGenericSchemeMultiCallSimple(
109+
helpers.SOME_ADDRESS,
110+
votingMachine.genesisProtocol.address,
111+
4,
112+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
113+
helpers.NULL_ADDRESS,
114+
[],
115+
'0x0'
116+
);
117+
assert(false, "Vote params type specified does not exist");
118+
} catch(error) {
119+
helpers.assertVMException(error);
120+
}
121+
107122
});
108123

109124
});

0 commit comments

Comments
 (0)