Skip to content

Commit

Permalink
Return universal VMs, leave DAOFactory changes (#763)
Browse files Browse the repository at this point in the history
* Revert "None universal voting machines (#757)"

This reverts commit 51c72e5.

* New infra

* lint

* Remove duplicated avatar from signal scheme

* Fix coverage

* Test

* infra version + test

* Fix coverage
  • Loading branch information
ben-kaufman authored Jun 15, 2020
1 parent 51c72e5 commit b9b4345
Show file tree
Hide file tree
Showing 32 changed files with 957 additions and 1,180 deletions.
75 changes: 21 additions & 54 deletions contracts/schemes/ArcScheme.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,12 @@ import "../controller/Avatar.sol";
import "@daostack/infra-experimental/contracts/votingMachines/GenesisProtocol.sol";
import "@daostack/infra-experimental/contracts/votingMachines/IntVoteInterface.sol";
import "@openzeppelin/upgrades/contracts/Initializable.sol";
import "../utils/DAOFactory.sol";
import "../libs/StringUtil.sol";


contract ArcScheme is Initializable {
using StringUtil for string;
Avatar public avatar;
IntVoteInterface public votingMachine;

string public constant GENESIS_PROTOCOL_INIT_FUNC_SIGNATURE =
"initialize(address,uint256[11],address,address,address,address)";

string public constant ABSOLUTE_VOTE_INIT_FUNC_SIGNATURE =
"initialize(uint256,address,address,address,address)";
bytes32 public voteParamsHash;

/**
* @dev _initialize
Expand All @@ -32,60 +24,35 @@ contract ArcScheme is Initializable {
/**
* @dev _initializeGovernance
* @param _avatar the scheme avatar
* @param _votingMachine the scheme voting machine
* @param _voteParamsHash the scheme vote params
* @param _votingParams genesisProtocol parameters - valid only if _voteParamsHash is zero
* @param _voteOnBehalf parameter
* @param _daoFactory DAOFactory instance to instance a votingMachine.
* @param _stakingToken (for GenesisProtocol)
* @param _callbacks should fulfill voting callbacks interface
* @param _authorizedToPropose only this address allow to propose (unless it is zero)
* @param _packageVersion packageVersion to instance the votingMachine from.
* @param _votingMachineName the votingMachine contract name.
* @param _voteOnBehalf genesisProtocol parameter - valid only if _voteParamsHash is zero
*/
function _initializeGovernance(
Avatar _avatar,
IntVoteInterface _votingMachine,
bytes32 _voteParamsHash,
uint256[11] memory _votingParams,
address _voteOnBehalf,
DAOFactory _daoFactory,
address _stakingToken,
address _callbacks,
address _authorizedToPropose,
uint64[3] memory _packageVersion,
string memory _votingMachineName
address _voteOnBehalf
) internal
{

require(_daoFactory != DAOFactory(0), "daoFactory cannot be zero");
require(
_daoFactory.getImplementation(_packageVersion, _votingMachineName) != address(0),
"votingMachine name does not exist in ArcHive"
);
require(_votingMachine != IntVoteInterface(0), "votingMachine cannot be zero");
_initialize(_avatar);

bytes memory initData;
if (_votingMachineName.hashCompareWithLengthCheck("GenesisProtocol")) {
initData = abi.encodeWithSignature(
GENESIS_PROTOCOL_INIT_FUNC_SIGNATURE,
_stakingToken,
_votingParams,
_voteOnBehalf,
avatar,
_callbacks,
_authorizedToPropose);
votingMachine = _votingMachine;
if (_voteParamsHash == bytes32(0)) {
//genesisProtocol
GenesisProtocol genesisProtocol = GenesisProtocol(address(_votingMachine));
voteParamsHash = genesisProtocol.getParametersHash(_votingParams, _voteOnBehalf);
(uint256 queuedVoteRequiredPercentage, , , , , , , , , , , ,) =
genesisProtocol.parameters(voteParamsHash);
if (queuedVoteRequiredPercentage == 0) {
//params not set already
genesisProtocol.setParameters(_votingParams, _voteOnBehalf);
}
} else {
initData = abi.encodeWithSignature(
ABSOLUTE_VOTE_INIT_FUNC_SIGNATURE,
_votingParams[0],
_voteOnBehalf,
avatar,
_callbacks,
_authorizedToPropose);
//for other voting machines
voteParamsHash = _voteParamsHash;
}

votingMachine = IntVoteInterface(address(_daoFactory.createInstance(
_packageVersion,
_votingMachineName,
address(avatar),
initData)));

}
}
29 changes: 8 additions & 21 deletions contracts/schemes/ContributionReward.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,35 +65,22 @@ contract ContributionReward is
/**
* @dev initialize
* @param _avatar the avatar this scheme referring to.
* @param _votingParams genesisProtocol parameters
* @param _voteOnBehalf parameter
* @param _daoFactory DAOFactory instance to instance a votingMachine.
* @param _stakingToken (for GenesisProtocol)
* @param _packageVersion packageVersion to instance the votingMachine from.
* @param _votingMachineName the votingMachine contract name.
* @param _votingMachine the voting machines address to
* @param _votingParams genesisProtocol parameters - valid only if _voteParamsHash is zero
* @param _voteOnBehalf genesisProtocol parameter - valid only if _voteParamsHash is zero
* @param _voteParamsHash voting machine parameters.
*/
function initialize(
Avatar _avatar,
IntVoteInterface _votingMachine,
uint256[11] calldata _votingParams,
address _voteOnBehalf,
DAOFactory _daoFactory,
address _stakingToken,
uint64[3] calldata _packageVersion,
string calldata _votingMachineName
bytes32 _voteParamsHash
)
external
initializer
{
super._initializeGovernance(
_avatar,
_votingParams,
_voteOnBehalf,
_daoFactory,
_stakingToken,
address(this),
address(this),
_packageVersion,
_votingMachineName);
super._initializeGovernance(_avatar, _votingMachine, _voteParamsHash, _votingParams, _voteOnBehalf);
}

/**
Expand Down Expand Up @@ -140,7 +127,7 @@ contract ContributionReward is
returns(bytes32)
{
validateProposalParams(_reputationChange, _rewards);
bytes32 proposalId = votingMachine.propose(2, msg.sender);
bytes32 proposalId = votingMachine.propose(2, voteParamsHash, msg.sender, address(avatar));
address payable beneficiary = _beneficiary;
if (beneficiary == address(0)) {
beneficiary = msg.sender;
Expand Down
35 changes: 14 additions & 21 deletions contracts/schemes/ContributionRewardExt.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,37 +83,30 @@ contract ContributionRewardExt is VotingMachineCallbacks, ProposalExecuteInterfa

/**
* @dev initialize
* @param _avatar the avatar this scheme referring to.
* @param _votingParams genesisProtocol parameters
* @param _voteOnBehalf parameter
* @param _daoFactory DAOFactory instance to instance a votingMachine.
* @param _stakingToken (for GenesisProtocol)
* @param _packageVersion packageVersion to instance the votingMachine from.
* @param _votingMachineName the votingMachine contract name.
* @param _avatar the avatar to mint reputation from
* @param _votingMachine the voting machines address
* @param _votingParams genesisProtocol parameters - valid only if _voteParamsHash is zero
* @param _voteOnBehalf genesisProtocol parameter - valid only if _voteParamsHash is zero
* @param _voteParamsHash voting machine parameters
* @param _daoFactory DAOFactory instance to instance a rewarder.
* if _daoFactory is zero so no rewarder will be set.
* @param _packageVersion packageVersion to instance the rewarder from.
* @param _rewarderName the rewarder contract name.
*/
function initialize(
Avatar _avatar,
uint256[11] calldata _votingParams,
IntVoteInterface _votingMachine,
uint[11] calldata _votingParams,
address _voteOnBehalf,
bytes32 _voteParamsHash,
DAOFactory _daoFactory,
address _stakingToken,
uint64[3] calldata _packageVersion,
string calldata _votingMachineName,
string calldata _rewarderName
)
external
{
super._initializeGovernance(
_avatar,
_votingParams,
_voteOnBehalf,
_daoFactory,
_stakingToken,
address(this),
address(this),
_packageVersion,
_votingMachineName);
super._initializeGovernance(_avatar, _votingMachine, _voteParamsHash, _votingParams, _voteOnBehalf);
vault = new Vault();
vault.initialize(address(this));
if (bytes(_rewarderName).length != 0) {
Expand Down Expand Up @@ -170,7 +163,7 @@ contract ContributionRewardExt is VotingMachineCallbacks, ProposalExecuteInterfa
if (proposer == address(0)) {
proposer = msg.sender;
}
proposalId = votingMachine.propose(2, proposer);
proposalId = votingMachine.propose(2, voteParamsHash, proposer, address(avatar));
address payable beneficiary = _beneficiary;
if (beneficiary == address(0)) {
beneficiary = msg.sender;
Expand Down
31 changes: 9 additions & 22 deletions contracts/schemes/ControllerUpgradeScheme.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,21 @@ contract ControllerUpgradeScheme is VotingMachineCallbacks, ProposalExecuteInter
/**
* @dev initialize
* @param _avatar the avatar this scheme referring to.
* @param _votingParams genesisProtocol parameters
* @param _voteOnBehalf parameter
* @param _daoFactory DAOFactory instance to instance a votingMachine.
* @param _stakingToken (for GenesisProtocol)
* @param _packageVersion packageVersion to instance the votingMachine from.
* @param _votingMachineName the votingMachine contract name.
* @param _votingMachine the voting machines address to
* @param _votingParams genesisProtocol parameters - valid only if _voteParamsHash is zero
* @param _voteOnBehalf genesisProtocol parameter - valid only if _voteParamsHash is zero
* @param _voteParamsHash voting machine parameters.
*/
function initialize(
Avatar _avatar,
IntVoteInterface _votingMachine,
uint256[11] calldata _votingParams,
address _voteOnBehalf,
DAOFactory _daoFactory,
address _stakingToken,
uint64[3] calldata _packageVersion,
string calldata _votingMachineName
bytes32 _voteParamsHash
)
external
{
super._initializeGovernance(
_avatar,
_votingParams,
_voteOnBehalf,
_daoFactory,
_stakingToken,
address(this),
address(this),
_packageVersion,
_votingMachineName);
super._initializeGovernance(_avatar, _votingMachine, _voteParamsHash, _votingParams, _voteOnBehalf);
}

/**
Expand Down Expand Up @@ -116,7 +103,7 @@ contract ControllerUpgradeScheme is VotingMachineCallbacks, ProposalExecuteInter
public
returns(bytes32)
{
bytes32 proposalId = votingMachine.propose(2, msg.sender);
bytes32 proposalId = votingMachine.propose(2, voteParamsHash, msg.sender, address(avatar));
UpgradeProposal memory proposal = UpgradeProposal({
proposalType: 1,
upgradeContract: _newController
Expand Down Expand Up @@ -148,7 +135,7 @@ contract ControllerUpgradeScheme is VotingMachineCallbacks, ProposalExecuteInter
public
returns(bytes32)
{
bytes32 proposalId = votingMachine.propose(2, msg.sender);
bytes32 proposalId = votingMachine.propose(2, voteParamsHash, msg.sender, address(avatar));
require(organizationProposals[proposalId].proposalType == 0);

UpgradeProposal memory proposal = UpgradeProposal({
Expand Down
29 changes: 8 additions & 21 deletions contracts/schemes/FundingRequest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,36 +46,23 @@ contract FundingRequest is
/**
* @dev initialize
* @param _avatar the avatar this scheme referring to.
* @param _votingParams genesisProtocol parameters
* @param _voteOnBehalf parameter
* @param _daoFactory DAOFactory instance to instance a votingMachine.
* @param _stakingToken (for GenesisProtocol)
* @param _packageVersion packageVersion to instance the votingMachine from.
* @param _votingMachineName the votingMachine contract name.
* @param _votingMachine the voting machines address to
* @param _votingParams genesisProtocol parameters - valid only if _voteParamsHash is zero
* @param _voteOnBehalf genesisProtocol parameter - valid only if _voteParamsHash is zero
* @param _voteParamsHash voting machine parameters.
* @param _fundingToken token to transfer to funding requests. 0x0 address for the native coin
*/
function initialize(
Avatar _avatar,
IntVoteInterface _votingMachine,
uint256[11] calldata _votingParams,
address _voteOnBehalf,
DAOFactory _daoFactory,
address _stakingToken,
uint64[3] calldata _packageVersion,
string calldata _votingMachineName,
bytes32 _voteParamsHash,
IERC20 _fundingToken
)
external
{
super._initializeGovernance(
_avatar,
_votingParams,
_voteOnBehalf,
_daoFactory,
_stakingToken,
address(this),
address(this),
_packageVersion,
_votingMachineName);
super._initializeGovernance(_avatar, _votingMachine, _voteParamsHash, _votingParams, _voteOnBehalf);
fundingToken = _fundingToken;
}

Expand Down Expand Up @@ -117,7 +104,7 @@ contract FundingRequest is
avatar.db(FUNDED_BEFORE_DEADLINE_KEY).hashCompareWithLengthCheck(FUNDED_BEFORE_DEADLINE_VALUE),
"funding is not allowed yet"
);
bytes32 proposalId = votingMachine.propose(2, msg.sender);
bytes32 proposalId = votingMachine.propose(2, voteParamsHash, msg.sender, address(avatar));
address payable beneficiary = _beneficiary;
if (beneficiary == address(0)) {
beneficiary = msg.sender;
Expand Down
31 changes: 9 additions & 22 deletions contracts/schemes/GenericScheme.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,37 +47,24 @@ contract GenericScheme is VotingMachineCallbacks, ProposalExecuteInterface {

/**
* @dev initialize
* @param _avatar the avatar this scheme referring to.
* @param _votingParams genesisProtocol parameters
* @param _voteOnBehalf parameter
* @param _daoFactory DAOFactory instance to instance a votingMachine.
* @param _stakingToken (for GenesisProtocol)
* @param _packageVersion packageVersion to instance the votingMachine from.
* @param _votingMachineName the votingMachine contract name.
* @param _avatar the avatar to mint reputation from
* @param _votingMachine the voting machines address to
* @param _votingParams genesisProtocol parameters - valid only if _voteParamsHash is zero
* @param _voteOnBehalf genesisProtocol parameter - valid only if _voteParamsHash is zero
* @param _voteParamsHash voting machine parameters.
* @param _contractToCall the target contract this scheme will call to
*/
function initialize(
Avatar _avatar,
IntVoteInterface _votingMachine,
uint256[11] calldata _votingParams,
address _voteOnBehalf,
DAOFactory _daoFactory,
address _stakingToken,
uint64[3] calldata _packageVersion,
string calldata _votingMachineName,
bytes32 _voteParamsHash,
address _contractToCall
)
external
{
super._initializeGovernance(
_avatar,
_votingParams,
_voteOnBehalf,
_daoFactory,
_stakingToken,
address(this),
address(this),
_packageVersion,
_votingMachineName);
super._initializeGovernance(_avatar, _votingMachine, _voteParamsHash, _votingParams, _voteOnBehalf);
contractToCall = _contractToCall;
}

Expand Down Expand Up @@ -142,7 +129,7 @@ contract GenericScheme is VotingMachineCallbacks, ProposalExecuteInterface {
public
returns(bytes32)
{
bytes32 proposalId = votingMachine.propose(2, msg.sender);
bytes32 proposalId = votingMachine.propose(2, voteParamsHash, msg.sender, address(avatar));

organizationProposals[proposalId] = CallProposal({
callData: _callData,
Expand Down
Loading

0 comments on commit b9b4345

Please sign in to comment.