From d0678a3648bb6f6ec8b61ad6f9c6a5077592fb15 Mon Sep 17 00:00:00 2001 From: orenyodfat Date: Mon, 16 Nov 2020 16:46:54 +0200 Subject: [PATCH] remove import of genesis protocol + lint (#806) * remove import of genesis protocol + lint * Use infra 20 * require valid vote params Co-authored-by: benk10 --- .../utils/GenericSchemeMultiCallFactory.sol | 43 ++++++++++--------- .../votingMachines/VotingMachineCallbacks.sol | 4 +- package-lock.json | 8 ++-- package.json | 4 +- test/genericschememulticallfactory.js | 15 +++++++ 5 files changed, 45 insertions(+), 29 deletions(-) diff --git a/contracts/utils/GenericSchemeMultiCallFactory.sol b/contracts/utils/GenericSchemeMultiCallFactory.sol index 4d9835e3..d1ad5eab 100644 --- a/contracts/utils/GenericSchemeMultiCallFactory.sol +++ b/contracts/utils/GenericSchemeMultiCallFactory.sol @@ -1,11 +1,11 @@ pragma solidity 0.5.17; +import "@daostack/infra/contracts/votingMachines/GenesisProtocolInterface.sol"; import "../schemes/GenericSchemeMultiCall.sol"; import "../schemes/SimpleSchemeConstraints.sol"; -import "@daostack/infra/contracts/votingMachines/GenesisProtocol.sol"; /** - * @title + * @title GenericSchemeMultiCallFactory */ contract GenericSchemeMultiCallFactory { uint8 public constant CUSTOM = 0; @@ -24,14 +24,33 @@ 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) { 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 = GenesisProtocolInterface(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 +96,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 { 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" 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); + } + }); });