@@ -4,12 +4,20 @@ import "../controller/Avatar.sol";
44import "@daostack/infra-experimental/contracts/votingMachines/GenesisProtocol.sol " ;
55import "@daostack/infra-experimental/contracts/votingMachines/IntVoteInterface.sol " ;
66import "@openzeppelin/upgrades/contracts/Initializable.sol " ;
7+ import "../utils/DAOFactory.sol " ;
8+ import "../libs/StringUtil.sol " ;
79
810
911contract ArcScheme is Initializable {
12+ using StringUtil for string ;
1013 Avatar public avatar;
1114 IntVoteInterface public votingMachine;
12- bytes32 public voteParamsHash;
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) " ;
1321
1422 /**
1523 * @dev _initialize
@@ -24,35 +32,60 @@ contract ArcScheme is Initializable {
2432 /**
2533 * @dev _initializeGovernance
2634 * @param _avatar the scheme avatar
27- * @param _votingMachine the scheme voting machine
28- * @param _voteParamsHash the scheme vote params
2935 * @param _votingParams genesisProtocol parameters - valid only if _voteParamsHash is zero
30- * @param _voteOnBehalf genesisProtocol parameter - 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.
3143 */
3244 function _initializeGovernance (
3345 Avatar _avatar ,
34- IntVoteInterface _votingMachine ,
35- bytes32 _voteParamsHash ,
3646 uint256 [11 ] memory _votingParams ,
37- address _voteOnBehalf
47+ address _voteOnBehalf ,
48+ DAOFactory _daoFactory ,
49+ address _stakingToken ,
50+ address _callbacks ,
51+ address _authorizedToPropose ,
52+ uint64 [3 ] memory _packageVersion ,
53+ string memory _votingMachineName
3854 ) internal
3955 {
40- require (_votingMachine != IntVoteInterface (0 ), "votingMachine cannot be zero " );
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+ );
4162 _initialize (_avatar);
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- }
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);
5374 } else {
54- //for other voting machines
55- voteParamsHash = _voteParamsHash;
75+ initData = abi.encodeWithSignature (
76+ ABSOLUTE_VOTE_INIT_FUNC_SIGNATURE,
77+ _votingParams[0 ],
78+ _voteOnBehalf,
79+ avatar,
80+ _callbacks,
81+ _authorizedToPropose);
5682 }
83+
84+ votingMachine = IntVoteInterface (address (_daoFactory.createInstance (
85+ _packageVersion,
86+ _votingMachineName,
87+ address (avatar),
88+ initData)));
89+
5790 }
5891}
0 commit comments