From 4c9b67bb4ce309dab7a4c6f1372aaaf535b6d108 Mon Sep 17 00:00:00 2001 From: Oren Sokolowsky Date: Mon, 16 Nov 2020 09:00:49 +0200 Subject: [PATCH 1/3] remove import of genesis protocol + lint --- .../utils/GenericSchemeMultiCallFactory.sol | 52 +++++++++++-------- .../votingMachines/VotingMachineCallbacks.sol | 4 +- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/contracts/utils/GenericSchemeMultiCallFactory.sol b/contracts/utils/GenericSchemeMultiCallFactory.sol index 4d9835e3..c3771434 100644 --- a/contracts/utils/GenericSchemeMultiCallFactory.sol +++ b/contracts/utils/GenericSchemeMultiCallFactory.sol @@ -2,10 +2,20 @@ pragma solidity 0.5.17; import "../schemes/GenericSchemeMultiCall.sol"; import "../schemes/SimpleSchemeConstraints.sol"; -import "@daostack/infra/contracts/votingMachines/GenesisProtocol.sol"; + + +contract GenesisProtocolSetParameterInterface { + function setParameters( + uint[11] calldata _params, //use array here due to stack too deep issue. + address _voteOnBehalf + ) + external + returns(bytes32); +} + /** - * @title + * @title GenericSchemeMultiCallFactory */ contract GenericSchemeMultiCallFactory { uint8 public constant CUSTOM = 0; @@ -30,8 +40,26 @@ contract GenericSchemeMultiCallFactory { simpleSchemeConstraints = address(new SimpleSchemeConstraints()); SimpleSchemeConstraints(simpleSchemeConstraints).initialize(_contractsWhiteList, _descriptionHash); } - uint256[11] memory voteParams; + if (_voteParamsType == CUSTOM) { + // Custom params hash + voteParams = _votingParams; + } else { + voteParams = getDefaultVoteParams(_voteParamsType); + } + + bytes32 voteParamsHash = GenesisProtocolSetParameterInterface(address(_votingMachine)) + .setParameters(voteParams, _voteOnBehalf); + + genericSchemeMultiCall.initialize( + _avatar, _votingMachine, voteParamsHash, SchemeConstraints(simpleSchemeConstraints) + ); + + emit NewGenericSchemeMultiCall(address(genericSchemeMultiCall)); + return address(genericSchemeMultiCall); + } + + function getDefaultVoteParams(uint8 _voteParamsType) private pure returns(uint256[11] memory voteParams) { if (_voteParamsType == FAST) { // Fast params hash voteParams = [ @@ -77,24 +105,6 @@ contract GenericSchemeMultiCallFactory { uint256(10), uint256(0) ]; - } else { - // Custom params hash - voteParams = _votingParams; - } - - GenesisProtocol genesisProtocol = GenesisProtocol(address(_votingMachine)); - bytes32 voteParamsHash = genesisProtocol.getParametersHash(voteParams, _voteOnBehalf); - (uint256 queuedVoteRequiredPercentage, , , , , , , , , , , ,) = - genesisProtocol.parameters(voteParamsHash); - if (queuedVoteRequiredPercentage == 0) { - //params not set already - genesisProtocol.setParameters(voteParams, _voteOnBehalf); } - genericSchemeMultiCall.initialize( - _avatar, _votingMachine, voteParamsHash, SchemeConstraints(simpleSchemeConstraints) - ); - - emit NewGenericSchemeMultiCall(address(genericSchemeMultiCall)); - return address(genericSchemeMultiCall); } } diff --git a/contracts/votingMachines/VotingMachineCallbacks.sol b/contracts/votingMachines/VotingMachineCallbacks.sol index 499c0976..b0f7906b 100644 --- a/contracts/votingMachines/VotingMachineCallbacks.sol +++ b/contracts/votingMachines/VotingMachineCallbacks.sol @@ -1,8 +1,8 @@ pragma solidity 0.5.17; import "../universalSchemes/UniversalScheme.sol"; -import "@daostack/infra/contracts/votingMachines/GenesisProtocol.sol"; - +import "@daostack/infra/contracts/votingMachines/VotingMachineCallbacksInterface.sol"; +import "@daostack/infra/contracts/votingMachines/ProposalExecuteInterface.sol"; contract VotingMachineCallbacks is VotingMachineCallbacksInterface { From 5766e1750d8fc7541ccfe64b3b48e16e92756a94 Mon Sep 17 00:00:00 2001 From: benk10 Date: Mon, 16 Nov 2020 11:50:06 +0100 Subject: [PATCH 2/3] Use infra 20 --- contracts/utils/GenericSchemeMultiCallFactory.sol | 14 ++------------ package-lock.json | 8 ++++---- package.json | 4 ++-- 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/contracts/utils/GenericSchemeMultiCallFactory.sol b/contracts/utils/GenericSchemeMultiCallFactory.sol index c3771434..5e6a1661 100644 --- a/contracts/utils/GenericSchemeMultiCallFactory.sol +++ b/contracts/utils/GenericSchemeMultiCallFactory.sol @@ -1,19 +1,9 @@ pragma solidity 0.5.17; +import "@daostack/infra/contracts/votingMachines/GenesisProtocolInterface.sol"; import "../schemes/GenericSchemeMultiCall.sol"; import "../schemes/SimpleSchemeConstraints.sol"; - -contract GenesisProtocolSetParameterInterface { - function setParameters( - uint[11] calldata _params, //use array here due to stack too deep issue. - address _voteOnBehalf - ) - external - returns(bytes32); -} - - /** * @title GenericSchemeMultiCallFactory */ @@ -48,7 +38,7 @@ contract GenericSchemeMultiCallFactory { voteParams = getDefaultVoteParams(_voteParamsType); } - bytes32 voteParamsHash = GenesisProtocolSetParameterInterface(address(_votingMachine)) + bytes32 voteParamsHash = GenesisProtocolInterface(address(_votingMachine)) .setParameters(voteParams, _voteOnBehalf); genericSchemeMultiCall.initialize( diff --git a/package-lock.json b/package-lock.json index 0361a2ae..1996a5f6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@daostack/arc", - "version": "0.0.1-rc.49", + "version": "0.0.1-rc.50", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -145,9 +145,9 @@ } }, "@daostack/infra": { - "version": "0.0.1-rc.19", - "resolved": "https://registry.npmjs.org/@daostack/infra/-/infra-0.0.1-rc.19.tgz", - "integrity": "sha512-Izvhc+WSzo6FAqPpuO7trrpd0Eeawf2TvqIAuCcCHoAbQ4IYYdtcF127IMhdFWJqXYadIYsDnqTPdYzX0xPC0w==", + "version": "0.0.1-rc.20", + "resolved": "https://registry.npmjs.org/@daostack/infra/-/infra-0.0.1-rc.20.tgz", + "integrity": "sha512-twibH7xJACOsdC16eyifDfvK4wu7oZrxrjvbdJGMsC6zsh3NxFSTOaJjaYdfH6CgwAtFrydE5dZHWg+JSPEYOw==", "requires": { "ethereumjs-abi": "^0.6.5", "openzeppelin-solidity": "2.4.0" diff --git a/package.json b/package.json index bb30fcc3..4f7f3505 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@daostack/arc", - "version": "0.0.1-rc.49", + "version": "0.0.1-rc.50", "description": "A platform for building DAOs", "files": [ "contracts/", @@ -78,7 +78,7 @@ }, "homepage": "https://daostack.io", "dependencies": { - "@daostack/infra": "0.0.1-rc.19", + "@daostack/infra": "0.0.1-rc.20", "math": "0.0.3", "openzeppelin-solidity": "2.4.0", "truffle-flattener": "^1.4.2" From 43db23703584e58444196060e0768972ee8232da Mon Sep 17 00:00:00 2001 From: benk10 Date: Mon, 16 Nov 2020 15:00:04 +0100 Subject: [PATCH 3/3] require valid vote params --- contracts/utils/GenericSchemeMultiCallFactory.sol | 1 + test/genericschememulticallfactory.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/contracts/utils/GenericSchemeMultiCallFactory.sol b/contracts/utils/GenericSchemeMultiCallFactory.sol index 5e6a1661..d1ad5eab 100644 --- a/contracts/utils/GenericSchemeMultiCallFactory.sol +++ b/contracts/utils/GenericSchemeMultiCallFactory.sol @@ -24,6 +24,7 @@ contract GenericSchemeMultiCallFactory { address[] memory _contractsWhiteList, string memory _descriptionHash ) public returns(address) { + require(_voteParamsType < 4, "Vote params type specified does not exist"); GenericSchemeMultiCall genericSchemeMultiCall = new GenericSchemeMultiCall(); address simpleSchemeConstraints; if (_contractsWhiteList.length > 0) { diff --git a/test/genericschememulticallfactory.js b/test/genericschememulticallfactory.js index cb4656e7..80cf5f8a 100644 --- a/test/genericschememulticallfactory.js +++ b/test/genericschememulticallfactory.js @@ -104,6 +104,21 @@ contract('genericSchemeMultiCallFactory', function(accounts) { } } + try { + await testSetup.genericSchemeMultiCallFactory.createGenericSchemeMultiCallSimple( + helpers.SOME_ADDRESS, + votingMachine.genesisProtocol.address, + 4, + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + helpers.NULL_ADDRESS, + [], + '0x0' + ); + assert(false, "Vote params type specified does not exist"); + } catch(error) { + helpers.assertVMException(error); + } + }); });