Skip to content

Commit

Permalink
remove import of genesis protocol + lint (#806)
Browse files Browse the repository at this point in the history
* remove import of genesis protocol + lint

* Use infra 20

* require valid vote params

Co-authored-by: benk10 <[email protected]>
  • Loading branch information
orenyodfat and ben-kaufman authored Nov 16, 2020
1 parent d316bd7 commit d0678a3
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 29 deletions.
43 changes: 22 additions & 21 deletions contracts/utils/GenericSchemeMultiCallFactory.sol
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 = [
Expand Down Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions contracts/votingMachines/VotingMachineCallbacks.sol
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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/",
Expand Down Expand Up @@ -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"
Expand Down
15 changes: 15 additions & 0 deletions test/genericschememulticallfactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

});

});

0 comments on commit d0678a3

Please sign in to comment.