From 8cca46cf2ce735ebd3f59d2612bc8fe6841918ab Mon Sep 17 00:00:00 2001 From: benk10 Date: Wed, 11 Nov 2020 16:21:57 +0100 Subject: [PATCH 01/10] Multi Call factory --- .../schemes/GenericSchemeMultiCallFactory.sol | 49 +++++++++++++++++++ test/genericschememulticallfactory.js | 32 ++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 contracts/schemes/GenericSchemeMultiCallFactory.sol create mode 100644 test/genericschememulticallfactory.js diff --git a/contracts/schemes/GenericSchemeMultiCallFactory.sol b/contracts/schemes/GenericSchemeMultiCallFactory.sol new file mode 100644 index 00000000..63fce437 --- /dev/null +++ b/contracts/schemes/GenericSchemeMultiCallFactory.sol @@ -0,0 +1,49 @@ +pragma solidity 0.5.17; + +import "./GenericSchemeMultiCall.sol"; +import "./SimpleSchemeConstraints.sol"; + +/** + * @title + */ +contract GenericSchemeMultiCallFactory { + uint8 public constant CUSTOM = 0; + uint8 public constant FAST = 1; + uint8 public constant NORMAL = 2; + uint8 public constant SLOW = 3; + + function createGenericSchemeMultiCallSimple( + Avatar _avatar, + IntVoteInterface _votingMachine, + uint8 _voteParamsType, + bytes32 _voteParamsHash, + address[] memory _contractsWhiteList, + string memory _descriptionHash + ) public returns(address) { + GenericSchemeMultiCall genericSchemeMultiCall = new GenericSchemeMultiCall(); + address simpleSchemeConstraints; + if (_contractsWhiteList.length > 0) { + simpleSchemeConstraints = new SimpleSchemeConstraints(); + SimpleSchemeConstraints(simpleSchemeConstraints).initialize(_contractsWhiteList, _descriptionHash); + } + + bytes32 voteParams; + if (_voteParamsType == FAST) { + // Fast params hash + voteParams = bytes32(0x1b46f925b15bc0590168247d8df7f72773ca64dec3334183b5387dd3945f7f2e); + } else if (_voteParamsType == NORMAL) { + // Normal params hash + voteParams = bytes32(0x2dfa7be2af300c250ab9037a744295d497648ab65f4f27baec5cb0e1d7784240); + } else if (_voteParamsType == SLOW) { + // Slow params hash + voteParams = bytes32(0x5d5931d5f0f6e9dc16afe1b3af57b44f5a83c2c731f372b0294c348a920362ff); + } else { + // Custom params hash + voteParams = _voteParamsHash; + } + genericSchemeMultiCall.initialize( + _avatar, _votingMachine, voteParams, simpleSchemeConstraints + ); + return address(genericSchemeMultiCall); + } +} diff --git a/test/genericschememulticallfactory.js b/test/genericschememulticallfactory.js new file mode 100644 index 00000000..476635d4 --- /dev/null +++ b/test/genericschememulticallfactory.js @@ -0,0 +1,32 @@ +import * as helpers from './helpers'; + +const GenericSchemeMultiCall = artifacts.require('./GenericSchemeMultiCall.sol'); +const genericSchemeMultiCallFactory = artifacts.require('./GenericSchemeMultiCall.sol'); + +const setup = async function (accounts) { + var testSetup = new helpers.TestSetup(); + testSetup.standardTokenMock = await ERC20Mock.new(accounts[1],100); + testSetup.genericSchemeMultiCallFactory = await genericSchemeMultiCallFactory.new(); + return testSetup; +}; + +contract('genericSchemeMultiCallFactory', function(accounts) { + before(function() { + helpers.etherForEveryone(accounts); + }); + + it('initialize', async () => { + let testSetup = await setup(accounts); + votingMachine = await helpers.setupGenesisProtocol(accounts,tokenAddress,0,helpers.NULL_ADDRESS); + + testSetup.genericSchemeMultiCallFactory.createGenericSchemeMultiCallSimple( + helpers.SOME_ADDRESS, + votingMachine.genesisProtocol.address, + 0, + votingMachine.params, + [], + '0x0' + ); + }); + +}); From 73fe4713f88c00d9d2f1ce0534359f49554d3c45 Mon Sep 17 00:00:00 2001 From: benk10 Date: Wed, 11 Nov 2020 16:33:03 +0100 Subject: [PATCH 02/10] Fix compile --- contracts/schemes/GenericSchemeMultiCallFactory.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/schemes/GenericSchemeMultiCallFactory.sol b/contracts/schemes/GenericSchemeMultiCallFactory.sol index 63fce437..8cb77899 100644 --- a/contracts/schemes/GenericSchemeMultiCallFactory.sol +++ b/contracts/schemes/GenericSchemeMultiCallFactory.sol @@ -23,7 +23,7 @@ contract GenericSchemeMultiCallFactory { GenericSchemeMultiCall genericSchemeMultiCall = new GenericSchemeMultiCall(); address simpleSchemeConstraints; if (_contractsWhiteList.length > 0) { - simpleSchemeConstraints = new SimpleSchemeConstraints(); + simpleSchemeConstraints = address(new SimpleSchemeConstraints()); SimpleSchemeConstraints(simpleSchemeConstraints).initialize(_contractsWhiteList, _descriptionHash); } @@ -42,7 +42,7 @@ contract GenericSchemeMultiCallFactory { voteParams = _voteParamsHash; } genericSchemeMultiCall.initialize( - _avatar, _votingMachine, voteParams, simpleSchemeConstraints + _avatar, _votingMachine, voteParams, SchemeConstraints(simpleSchemeConstraints) ); return address(genericSchemeMultiCall); } From 110324ed2d18ea66cc79301e7771dae1973ee59f Mon Sep 17 00:00:00 2001 From: benk10 Date: Wed, 11 Nov 2020 17:59:19 +0100 Subject: [PATCH 03/10] Write to GP --- .../schemes/GenericSchemeMultiCallFactory.sol | 61 ++++++++++++++++--- 1 file changed, 54 insertions(+), 7 deletions(-) diff --git a/contracts/schemes/GenericSchemeMultiCallFactory.sol b/contracts/schemes/GenericSchemeMultiCallFactory.sol index 8cb77899..4a36bf7b 100644 --- a/contracts/schemes/GenericSchemeMultiCallFactory.sol +++ b/contracts/schemes/GenericSchemeMultiCallFactory.sol @@ -2,6 +2,7 @@ pragma solidity 0.5.17; import "./GenericSchemeMultiCall.sol"; import "./SimpleSchemeConstraints.sol"; +import "@daostack/infra/contracts/votingMachines/GenesisProtocol.sol"; /** * @title @@ -16,7 +17,8 @@ contract GenericSchemeMultiCallFactory { Avatar _avatar, IntVoteInterface _votingMachine, uint8 _voteParamsType, - bytes32 _voteParamsHash, + uint256[11] memory _votingParams, + address _voteOnBehalf, address[] memory _contractsWhiteList, string memory _descriptionHash ) public returns(address) { @@ -27,22 +29,67 @@ contract GenericSchemeMultiCallFactory { SimpleSchemeConstraints(simpleSchemeConstraints).initialize(_contractsWhiteList, _descriptionHash); } - bytes32 voteParams; + uint256[11] memory voteParams; if (_voteParamsType == FAST) { // Fast params hash - voteParams = bytes32(0x1b46f925b15bc0590168247d8df7f72773ca64dec3334183b5387dd3945f7f2e); + voteParams = [ + uint256(50), + uint256(604800), + uint256(129600), + uint256(43200), + uint256(1200), + uint256(86400), + uint256(10000000000000000000), + uint256(1), + uint256(50000000000000000000), + uint256(10), + uint256(0) + ]; } else if (_voteParamsType == NORMAL) { // Normal params hash - voteParams = bytes32(0x2dfa7be2af300c250ab9037a744295d497648ab65f4f27baec5cb0e1d7784240); + voteParams = [ + uint256(50), + uint256(2592000), + uint256(345600), + uint256(86400), + uint256(1200), + uint256(172800), + uint256(50000000000000000000), + uint256(4), + uint256(150000000000000000000), + uint256(10), + uint256(0) + ]; } else if (_voteParamsType == SLOW) { // Slow params hash - voteParams = bytes32(0x5d5931d5f0f6e9dc16afe1b3af57b44f5a83c2c731f372b0294c348a920362ff); + voteParams = [ + uint256(50), + uint256(5184000), + uint256(691200), + uint256(172800), + uint256(1500), + uint256(345600), + uint256(200000000000000000000), + uint256(4), + uint256(500000000000000000000), + uint256(10), + uint256(0) + ]; } else { // Custom params hash - voteParams = _voteParamsHash; + 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, voteParams, SchemeConstraints(simpleSchemeConstraints) + _avatar, _votingMachine, voteParamsHash, SchemeConstraints(simpleSchemeConstraints) ); return address(genericSchemeMultiCall); } From 7245a5eb8e756e4b95705709333b8e5f1378ce44 Mon Sep 17 00:00:00 2001 From: benk10 Date: Wed, 11 Nov 2020 18:15:11 +0100 Subject: [PATCH 04/10] Update genericschememulticallfactory.js --- test/genericschememulticallfactory.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/genericschememulticallfactory.js b/test/genericschememulticallfactory.js index 476635d4..d1d5b369 100644 --- a/test/genericschememulticallfactory.js +++ b/test/genericschememulticallfactory.js @@ -1,11 +1,9 @@ import * as helpers from './helpers'; -const GenericSchemeMultiCall = artifacts.require('./GenericSchemeMultiCall.sol'); const genericSchemeMultiCallFactory = artifacts.require('./GenericSchemeMultiCall.sol'); -const setup = async function (accounts) { +const setup = async function () { var testSetup = new helpers.TestSetup(); - testSetup.standardTokenMock = await ERC20Mock.new(accounts[1],100); testSetup.genericSchemeMultiCallFactory = await genericSchemeMultiCallFactory.new(); return testSetup; }; @@ -16,7 +14,7 @@ contract('genericSchemeMultiCallFactory', function(accounts) { }); it('initialize', async () => { - let testSetup = await setup(accounts); + let testSetup = await setup(); votingMachine = await helpers.setupGenesisProtocol(accounts,tokenAddress,0,helpers.NULL_ADDRESS); testSetup.genericSchemeMultiCallFactory.createGenericSchemeMultiCallSimple( From 407de7e4e2370b835e737c4418280c7a6345cdd8 Mon Sep 17 00:00:00 2001 From: benk10 Date: Wed, 11 Nov 2020 19:04:00 +0100 Subject: [PATCH 05/10] Update genericschememulticallfactory.js --- test/genericschememulticallfactory.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/genericschememulticallfactory.js b/test/genericschememulticallfactory.js index d1d5b369..e52898ea 100644 --- a/test/genericschememulticallfactory.js +++ b/test/genericschememulticallfactory.js @@ -15,13 +15,14 @@ contract('genericSchemeMultiCallFactory', function(accounts) { it('initialize', async () => { let testSetup = await setup(); - votingMachine = await helpers.setupGenesisProtocol(accounts,tokenAddress,0,helpers.NULL_ADDRESS); + votingMachine = await helpers.setupGenesisProtocol(accounts,helpers.SOME_ADDRESS,0,helpers.NULL_ADDRESS); testSetup.genericSchemeMultiCallFactory.createGenericSchemeMultiCallSimple( helpers.SOME_ADDRESS, votingMachine.genesisProtocol.address, - 0, - votingMachine.params, + 1, + [], + helpers.NULL_ADDRESS, [], '0x0' ); From b361f2057935fb94a70c928ff33334ab039ca8c4 Mon Sep 17 00:00:00 2001 From: benk10 Date: Wed, 11 Nov 2020 21:02:55 +0100 Subject: [PATCH 06/10] Tests --- test/genericschememulticallfactory.js | 108 ++++++++++++++++++++++---- 1 file changed, 95 insertions(+), 13 deletions(-) diff --git a/test/genericschememulticallfactory.js b/test/genericschememulticallfactory.js index e52898ea..4432ac6e 100644 --- a/test/genericschememulticallfactory.js +++ b/test/genericschememulticallfactory.js @@ -1,10 +1,66 @@ import * as helpers from './helpers'; -const genericSchemeMultiCallFactory = artifacts.require('./GenericSchemeMultiCall.sol'); +const GenericSchemeMultiCall = artifacts.require('./GenericSchemeMultiCall.sol'); +const GenericSchemeMultiCallFactory = artifacts.require('./GenericSchemeMultiCallFactory.sol'); + +const params = [ + [ + 50, + 1800, + 600, + 600, + 2000, + 300, + web3.utils.toWei('5', "ether"), + 1, + web3.utils.toWei('10', "ether"), + 10, + 0 + ], + [ + 50, + 604800, + 129600, + 43200, + 1200, + 86400, + web3.utils.toWei('10', "ether"), + 1, + web3.utils.toWei('50', "ether"), + 10, + 0 + ], + [ + 50, + 2592000, + 345600, + 86400, + 1200, + 172800, + web3.utils.toWei('50', "ether"), + 4, + web3.utils.toWei('150', "ether"), + 10, + 0 + ], + [ + 50, + 5184000, + 691200, + 172800, + 1500, + 345600, + web3.utils.toWei('200', "ether"), + 4, + web3.utils.toWei('500', "ether"), + 10, + 0 + ] +]; const setup = async function () { var testSetup = new helpers.TestSetup(); - testSetup.genericSchemeMultiCallFactory = await genericSchemeMultiCallFactory.new(); + testSetup.genericSchemeMultiCallFactory = await GenericSchemeMultiCallFactory.new(); return testSetup; }; @@ -15,17 +71,43 @@ contract('genericSchemeMultiCallFactory', function(accounts) { it('initialize', async () => { let testSetup = await setup(); - votingMachine = await helpers.setupGenesisProtocol(accounts,helpers.SOME_ADDRESS,0,helpers.NULL_ADDRESS); - - testSetup.genericSchemeMultiCallFactory.createGenericSchemeMultiCallSimple( - helpers.SOME_ADDRESS, - votingMachine.genesisProtocol.address, - 1, - [], - helpers.NULL_ADDRESS, - [], - '0x0' - ); + let votingMachine = await helpers.setupGenesisProtocol(accounts,helpers.SOME_ADDRESS,0,helpers.NULL_ADDRESS); + + for (let i=0; i < 4; i++) { + let address = await testSetup.genericSchemeMultiCallFactory.createGenericSchemeMultiCallSimple.call( + helpers.SOME_ADDRESS, + votingMachine.genesisProtocol.address, + i, + (i === 0 ? params[0] : [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), + helpers.NULL_ADDRESS, + (i === 0 ? [helpers.SOME_ADDRESS] : []), + '0x0' + ); + + await testSetup.genericSchemeMultiCallFactory.createGenericSchemeMultiCallSimple( + helpers.SOME_ADDRESS, + votingMachine.genesisProtocol.address, + i, + (i === 0 ? params[0] : [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), + helpers.NULL_ADDRESS, + (i === 0 ? [helpers.SOME_ADDRESS] : []), + '0x0' + ); + + let genericSchemeMultiCall = await GenericSchemeMultiCall.at(address); + assert.equal(await genericSchemeMultiCall.avatar(), helpers.SOME_ADDRESS); + assert.equal(await genericSchemeMultiCall.votingMachine(), votingMachine.genesisProtocol.address); + assert.equal( + await genericSchemeMultiCall.voteParams(), + await votingMachine.genesisProtocol.getParametersHash(params[i], helpers.NULL_ADDRESS) + ); + if (i === 0) { + assert.notEqual(await genericSchemeMultiCall.schemeConstraints(), helpers.NULL_ADDRESS); + } else { + assert.equal(await genericSchemeMultiCall.schemeConstraints(), helpers.NULL_ADDRESS); + } + } + }); }); From 4da02c85771f81019e7818d6d57e983d7b577d48 Mon Sep 17 00:00:00 2001 From: benk10 Date: Wed, 11 Nov 2020 21:29:30 +0100 Subject: [PATCH 07/10] Move dir --- .../{schemes => utils}/GenericSchemeMultiCallFactory.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename contracts/{schemes => utils}/GenericSchemeMultiCallFactory.sol (97%) diff --git a/contracts/schemes/GenericSchemeMultiCallFactory.sol b/contracts/utils/GenericSchemeMultiCallFactory.sol similarity index 97% rename from contracts/schemes/GenericSchemeMultiCallFactory.sol rename to contracts/utils/GenericSchemeMultiCallFactory.sol index 4a36bf7b..17dd3c9b 100644 --- a/contracts/schemes/GenericSchemeMultiCallFactory.sol +++ b/contracts/utils/GenericSchemeMultiCallFactory.sol @@ -1,7 +1,7 @@ pragma solidity 0.5.17; -import "./GenericSchemeMultiCall.sol"; -import "./SimpleSchemeConstraints.sol"; +import "../schemes/GenericSchemeMultiCall.sol"; +import "../schemes/SimpleSchemeConstraints.sol"; import "@daostack/infra/contracts/votingMachines/GenesisProtocol.sol"; /** From a4839b4b5a6bebff8c02cfb68e514a83de4ef619 Mon Sep 17 00:00:00 2001 From: benk10 Date: Wed, 11 Nov 2020 21:30:03 +0100 Subject: [PATCH 08/10] Update genericschememulticallfactory.js --- test/genericschememulticallfactory.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/genericschememulticallfactory.js b/test/genericschememulticallfactory.js index 4432ac6e..cb4656e7 100644 --- a/test/genericschememulticallfactory.js +++ b/test/genericschememulticallfactory.js @@ -65,10 +65,6 @@ const setup = async function () { }; contract('genericSchemeMultiCallFactory', function(accounts) { - before(function() { - helpers.etherForEveryone(accounts); - }); - it('initialize', async () => { let testSetup = await setup(); let votingMachine = await helpers.setupGenesisProtocol(accounts,helpers.SOME_ADDRESS,0,helpers.NULL_ADDRESS); From 7aa8149e2f7b02ee6b23860a7f282838aacc60e0 Mon Sep 17 00:00:00 2001 From: benk10 Date: Wed, 11 Nov 2020 22:00:48 +0100 Subject: [PATCH 09/10] Update GenericSchemeMultiCallFactory.sol --- contracts/utils/GenericSchemeMultiCallFactory.sol | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/contracts/utils/GenericSchemeMultiCallFactory.sol b/contracts/utils/GenericSchemeMultiCallFactory.sol index 17dd3c9b..2601fef0 100644 --- a/contracts/utils/GenericSchemeMultiCallFactory.sol +++ b/contracts/utils/GenericSchemeMultiCallFactory.sol @@ -13,6 +13,8 @@ contract GenericSchemeMultiCallFactory { uint8 public constant NORMAL = 2; uint8 public constant SLOW = 3; + event NewGenericSchemeMultiCall(address indexed genericSchemeMultiCall); + function createGenericSchemeMultiCallSimple( Avatar _avatar, IntVoteInterface _votingMachine, @@ -21,7 +23,7 @@ contract GenericSchemeMultiCallFactory { address _voteOnBehalf, address[] memory _contractsWhiteList, string memory _descriptionHash - ) public returns(address) { + ) external returns(address) { GenericSchemeMultiCall genericSchemeMultiCall = new GenericSchemeMultiCall(); address simpleSchemeConstraints; if (_contractsWhiteList.length > 0) { @@ -91,6 +93,8 @@ contract GenericSchemeMultiCallFactory { genericSchemeMultiCall.initialize( _avatar, _votingMachine, voteParamsHash, SchemeConstraints(simpleSchemeConstraints) ); + + emit NewGenericSchemeMultiCall(genericSchemeMultiCall); return address(genericSchemeMultiCall); } } From a75b281ca3d3696860dcd619da3d7ace69c0c0f3 Mon Sep 17 00:00:00 2001 From: benk10 Date: Wed, 11 Nov 2020 22:08:01 +0100 Subject: [PATCH 10/10] Update GenericSchemeMultiCallFactory.sol --- contracts/utils/GenericSchemeMultiCallFactory.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contracts/utils/GenericSchemeMultiCallFactory.sol b/contracts/utils/GenericSchemeMultiCallFactory.sol index 2601fef0..4d9835e3 100644 --- a/contracts/utils/GenericSchemeMultiCallFactory.sol +++ b/contracts/utils/GenericSchemeMultiCallFactory.sol @@ -13,7 +13,7 @@ contract GenericSchemeMultiCallFactory { uint8 public constant NORMAL = 2; uint8 public constant SLOW = 3; - event NewGenericSchemeMultiCall(address indexed genericSchemeMultiCall); + event NewGenericSchemeMultiCall(address genericSchemeMultiCall); function createGenericSchemeMultiCallSimple( Avatar _avatar, @@ -23,7 +23,7 @@ contract GenericSchemeMultiCallFactory { address _voteOnBehalf, address[] memory _contractsWhiteList, string memory _descriptionHash - ) external returns(address) { + ) public returns(address) { GenericSchemeMultiCall genericSchemeMultiCall = new GenericSchemeMultiCall(); address simpleSchemeConstraints; if (_contractsWhiteList.length > 0) { @@ -94,7 +94,7 @@ contract GenericSchemeMultiCallFactory { _avatar, _votingMachine, voteParamsHash, SchemeConstraints(simpleSchemeConstraints) ); - emit NewGenericSchemeMultiCall(genericSchemeMultiCall); + emit NewGenericSchemeMultiCall(address(genericSchemeMultiCall)); return address(genericSchemeMultiCall); } }