11pragma solidity 0.5.17 ;
22
3+ import "@daostack/infra/contracts/votingMachines/GenesisProtocolInterface.sol " ;
34import "../schemes/GenericSchemeMultiCall.sol " ;
45import "../schemes/SimpleSchemeConstraints.sol " ;
5- import "@daostack/infra/contracts/votingMachines/GenesisProtocol.sol " ;
66
77/**
8- * @title
8+ * @title GenericSchemeMultiCallFactory
99 */
1010contract 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}
0 commit comments