Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi Call factory #804

Merged
merged 10 commits into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions contracts/utils/GenericSchemeMultiCallFactory.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
pragma solidity 0.5.17;

import "../schemes/GenericSchemeMultiCall.sol";
import "../schemes/SimpleSchemeConstraints.sol";
import "@daostack/infra/contracts/votingMachines/GenesisProtocol.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,
uint256[11] memory _votingParams,
address _voteOnBehalf,
address[] memory _contractsWhiteList,
string memory _descriptionHash
) public returns(address) {
orenyodfat marked this conversation as resolved.
Show resolved Hide resolved
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 == FAST) {
// Fast params hash
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 = [
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 = [
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 = _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)
);
return address(genericSchemeMultiCall);
orenyodfat marked this conversation as resolved.
Show resolved Hide resolved
}
}
109 changes: 109 additions & 0 deletions test/genericschememulticallfactory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import * as helpers from './helpers';

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();
return testSetup;
};

contract('genericSchemeMultiCallFactory', function(accounts) {
it('initialize', async () => {
let testSetup = await setup();
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);
}
}

});

});