Skip to content

Commit 0678502

Browse files
authored
Multi Call factory (#804)
* Multi Call factory * Fix compile * Write to GP * Update genericschememulticallfactory.js * Update genericschememulticallfactory.js * Tests * Move dir * Update genericschememulticallfactory.js * Update GenericSchemeMultiCallFactory.sol * Update GenericSchemeMultiCallFactory.sol
1 parent badb64f commit 0678502

File tree

2 files changed

+209
-0
lines changed

2 files changed

+209
-0
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
pragma solidity 0.5.17;
2+
3+
import "../schemes/GenericSchemeMultiCall.sol";
4+
import "../schemes/SimpleSchemeConstraints.sol";
5+
import "@daostack/infra/contracts/votingMachines/GenesisProtocol.sol";
6+
7+
/**
8+
* @title
9+
*/
10+
contract GenericSchemeMultiCallFactory {
11+
uint8 public constant CUSTOM = 0;
12+
uint8 public constant FAST = 1;
13+
uint8 public constant NORMAL = 2;
14+
uint8 public constant SLOW = 3;
15+
16+
event NewGenericSchemeMultiCall(address genericSchemeMultiCall);
17+
18+
function createGenericSchemeMultiCallSimple(
19+
Avatar _avatar,
20+
IntVoteInterface _votingMachine,
21+
uint8 _voteParamsType,
22+
uint256[11] memory _votingParams,
23+
address _voteOnBehalf,
24+
address[] memory _contractsWhiteList,
25+
string memory _descriptionHash
26+
) public returns(address) {
27+
GenericSchemeMultiCall genericSchemeMultiCall = new GenericSchemeMultiCall();
28+
address simpleSchemeConstraints;
29+
if (_contractsWhiteList.length > 0) {
30+
simpleSchemeConstraints = address(new SimpleSchemeConstraints());
31+
SimpleSchemeConstraints(simpleSchemeConstraints).initialize(_contractsWhiteList, _descriptionHash);
32+
}
33+
34+
uint256[11] memory voteParams;
35+
if (_voteParamsType == FAST) {
36+
// Fast params hash
37+
voteParams = [
38+
uint256(50),
39+
uint256(604800),
40+
uint256(129600),
41+
uint256(43200),
42+
uint256(1200),
43+
uint256(86400),
44+
uint256(10000000000000000000),
45+
uint256(1),
46+
uint256(50000000000000000000),
47+
uint256(10),
48+
uint256(0)
49+
];
50+
} else if (_voteParamsType == NORMAL) {
51+
// Normal params hash
52+
voteParams = [
53+
uint256(50),
54+
uint256(2592000),
55+
uint256(345600),
56+
uint256(86400),
57+
uint256(1200),
58+
uint256(172800),
59+
uint256(50000000000000000000),
60+
uint256(4),
61+
uint256(150000000000000000000),
62+
uint256(10),
63+
uint256(0)
64+
];
65+
} else if (_voteParamsType == SLOW) {
66+
// Slow params hash
67+
voteParams = [
68+
uint256(50),
69+
uint256(5184000),
70+
uint256(691200),
71+
uint256(172800),
72+
uint256(1500),
73+
uint256(345600),
74+
uint256(200000000000000000000),
75+
uint256(4),
76+
uint256(500000000000000000000),
77+
uint256(10),
78+
uint256(0)
79+
];
80+
} else {
81+
// Custom params hash
82+
voteParams = _votingParams;
83+
}
84+
85+
GenesisProtocol genesisProtocol = GenesisProtocol(address(_votingMachine));
86+
bytes32 voteParamsHash = genesisProtocol.getParametersHash(voteParams, _voteOnBehalf);
87+
(uint256 queuedVoteRequiredPercentage, , , , , , , , , , , ,) =
88+
genesisProtocol.parameters(voteParamsHash);
89+
if (queuedVoteRequiredPercentage == 0) {
90+
//params not set already
91+
genesisProtocol.setParameters(voteParams, _voteOnBehalf);
92+
}
93+
genericSchemeMultiCall.initialize(
94+
_avatar, _votingMachine, voteParamsHash, SchemeConstraints(simpleSchemeConstraints)
95+
);
96+
97+
emit NewGenericSchemeMultiCall(address(genericSchemeMultiCall));
98+
return address(genericSchemeMultiCall);
99+
}
100+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import * as helpers from './helpers';
2+
3+
const GenericSchemeMultiCall = artifacts.require('./GenericSchemeMultiCall.sol');
4+
const GenericSchemeMultiCallFactory = artifacts.require('./GenericSchemeMultiCallFactory.sol');
5+
6+
const params = [
7+
[
8+
50,
9+
1800,
10+
600,
11+
600,
12+
2000,
13+
300,
14+
web3.utils.toWei('5', "ether"),
15+
1,
16+
web3.utils.toWei('10', "ether"),
17+
10,
18+
0
19+
],
20+
[
21+
50,
22+
604800,
23+
129600,
24+
43200,
25+
1200,
26+
86400,
27+
web3.utils.toWei('10', "ether"),
28+
1,
29+
web3.utils.toWei('50', "ether"),
30+
10,
31+
0
32+
],
33+
[
34+
50,
35+
2592000,
36+
345600,
37+
86400,
38+
1200,
39+
172800,
40+
web3.utils.toWei('50', "ether"),
41+
4,
42+
web3.utils.toWei('150', "ether"),
43+
10,
44+
0
45+
],
46+
[
47+
50,
48+
5184000,
49+
691200,
50+
172800,
51+
1500,
52+
345600,
53+
web3.utils.toWei('200', "ether"),
54+
4,
55+
web3.utils.toWei('500', "ether"),
56+
10,
57+
0
58+
]
59+
];
60+
61+
const setup = async function () {
62+
var testSetup = new helpers.TestSetup();
63+
testSetup.genericSchemeMultiCallFactory = await GenericSchemeMultiCallFactory.new();
64+
return testSetup;
65+
};
66+
67+
contract('genericSchemeMultiCallFactory', function(accounts) {
68+
it('initialize', async () => {
69+
let testSetup = await setup();
70+
let votingMachine = await helpers.setupGenesisProtocol(accounts,helpers.SOME_ADDRESS,0,helpers.NULL_ADDRESS);
71+
72+
for (let i=0; i < 4; i++) {
73+
let address = await testSetup.genericSchemeMultiCallFactory.createGenericSchemeMultiCallSimple.call(
74+
helpers.SOME_ADDRESS,
75+
votingMachine.genesisProtocol.address,
76+
i,
77+
(i === 0 ? params[0] : [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),
78+
helpers.NULL_ADDRESS,
79+
(i === 0 ? [helpers.SOME_ADDRESS] : []),
80+
'0x0'
81+
);
82+
83+
await testSetup.genericSchemeMultiCallFactory.createGenericSchemeMultiCallSimple(
84+
helpers.SOME_ADDRESS,
85+
votingMachine.genesisProtocol.address,
86+
i,
87+
(i === 0 ? params[0] : [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),
88+
helpers.NULL_ADDRESS,
89+
(i === 0 ? [helpers.SOME_ADDRESS] : []),
90+
'0x0'
91+
);
92+
93+
let genericSchemeMultiCall = await GenericSchemeMultiCall.at(address);
94+
assert.equal(await genericSchemeMultiCall.avatar(), helpers.SOME_ADDRESS);
95+
assert.equal(await genericSchemeMultiCall.votingMachine(), votingMachine.genesisProtocol.address);
96+
assert.equal(
97+
await genericSchemeMultiCall.voteParams(),
98+
await votingMachine.genesisProtocol.getParametersHash(params[i], helpers.NULL_ADDRESS)
99+
);
100+
if (i === 0) {
101+
assert.notEqual(await genericSchemeMultiCall.schemeConstraints(), helpers.NULL_ADDRESS);
102+
} else {
103+
assert.equal(await genericSchemeMultiCall.schemeConstraints(), helpers.NULL_ADDRESS);
104+
}
105+
}
106+
107+
});
108+
109+
});

0 commit comments

Comments
 (0)