-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
- Loading branch information
1 parent
badb64f
commit 0678502
Showing
2 changed files
with
209 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
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; | ||
|
||
event NewGenericSchemeMultiCall(address genericSchemeMultiCall); | ||
|
||
function createGenericSchemeMultiCallSimple( | ||
Avatar _avatar, | ||
IntVoteInterface _votingMachine, | ||
uint8 _voteParamsType, | ||
uint256[11] memory _votingParams, | ||
address _voteOnBehalf, | ||
address[] memory _contractsWhiteList, | ||
string memory _descriptionHash | ||
) public returns(address) { | ||
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) | ||
); | ||
|
||
emit NewGenericSchemeMultiCall(address(genericSchemeMultiCall)); | ||
return address(genericSchemeMultiCall); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
||
}); | ||
|
||
}); |