Skip to content

None universal voting machines #757

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

Merged
merged 13 commits into from
Jun 3, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
75 changes: 54 additions & 21 deletions contracts/schemes/ArcScheme.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@ 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;
bytes32 public voteParamsHash;

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)";

/**
* @dev _initialize
Expand All @@ -24,35 +32,60 @@ 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 genesisProtocol parameter - 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.
*/
function _initializeGovernance(
Avatar _avatar,
IntVoteInterface _votingMachine,
bytes32 _voteParamsHash,
uint256[11] memory _votingParams,
address _voteOnBehalf
address _voteOnBehalf,
DAOFactory _daoFactory,
address _stakingToken,
address _callbacks,
address _authorizedToPropose,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe combine here _callbacks with _authorizedToPropose ?
This is anyway only for our schemes and I don't think we have a use case which needs them to be different.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there might be a use case for that .
for now lets keep it like that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

uint64[3] memory _packageVersion,
string memory _votingMachineName
) internal
{
require(_votingMachine != IntVoteInterface(0), "votingMachine cannot be zero");

require(_daoFactory != DAOFactory(0), "daoFactory cannot be zero");
require(
_daoFactory.getImplementation(_packageVersion, _votingMachineName) != address(0),
"votingMachine name does not exist in ArcHive"
);
_initialize(_avatar);
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);
}

bytes memory initData;
if (_votingMachineName.hashCompareWithLengthCheck("GenesisProtocol")) {
initData = abi.encodeWithSignature(
GENESIS_PROTOCOL_INIT_FUNC_SIGNATURE,
_stakingToken,
_votingParams,
_voteOnBehalf,
avatar,
_callbacks,
_authorizedToPropose);
} else {
//for other voting machines
voteParamsHash = _voteParamsHash;
initData = abi.encodeWithSignature(
ABSOLUTE_VOTE_INIT_FUNC_SIGNATURE,
_votingParams[0],
_voteOnBehalf,
avatar,
_callbacks,
_authorizedToPropose);
}

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

}
}
10 changes: 2 additions & 8 deletions contracts/schemes/Auction4Reputation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ contract Auction4Reputation is Agreement, ArcScheme {
uint256 public auctionPeriod;
uint256 public redeemEnableTime;
IERC20 public token;
address public wallet;

/**
* @dev initialize
Expand All @@ -49,9 +48,6 @@ contract Auction4Reputation is Agreement, ArcScheme {
* @param _redeemEnableTime redeem enable time .
* redeem reputation can be done after this time.
* @param _token the bidding token
* @param _wallet the address of the wallet the token will be transfer to.
* Please note that _wallet address should be a trusted account.
* Normally this address should be set as the DAO's avatar address.
* @param _agreementHash is a hash of agreement required to be added to the TX by participants
*/
function initialize(
Expand All @@ -62,7 +58,6 @@ contract Auction4Reputation is Agreement, ArcScheme {
uint256 _numberOfAuctions,
uint256 _redeemEnableTime,
IERC20 _token,
address _wallet,
bytes32 _agreementHash )
external
{
Expand All @@ -76,7 +71,6 @@ contract Auction4Reputation is Agreement, ArcScheme {
token = _token;
auctionsStartTime = _auctionsStartTime;
numberOfAuctions = _numberOfAuctions;
wallet = _wallet;
auctionReputationReward = _auctionReputationReward;
reputationRewardLeft = _auctionReputationReward.mul(_numberOfAuctions);
redeemEnableTime = _redeemEnableTime;
Expand Down Expand Up @@ -133,14 +127,14 @@ contract Auction4Reputation is Agreement, ArcScheme {
}

/**
* @dev transferToWallet transfer the tokens to the wallet.
* @dev transferToWallet transfer the tokens to the avatar.
* can be called only after auctionsEndTime
*/
function transferToWallet() public {
// solhint-disable-next-line not-rely-on-time
require(now > auctionsEndTime, "now > auctionsEndTime");
uint256 tokenBalance = token.balanceOf(address(this));
token.safeTransfer(wallet, tokenBalance);
token.safeTransfer(address(avatar), tokenBalance);
}

/**
Expand Down
29 changes: 21 additions & 8 deletions contracts/schemes/ContributionReward.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,35 @@ contract ContributionReward is
/**
* @dev initialize
* @param _avatar the avatar this scheme referring to.
* @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 _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.
*/
function initialize(
Avatar _avatar,
IntVoteInterface _votingMachine,
uint256[11] calldata _votingParams,
address _voteOnBehalf,
bytes32 _voteParamsHash
DAOFactory _daoFactory,
address _stakingToken,
uint64[3] calldata _packageVersion,
string calldata _votingMachineName
)
external
initializer
{
super._initializeGovernance(_avatar, _votingMachine, _voteParamsHash, _votingParams, _voteOnBehalf);
super._initializeGovernance(
_avatar,
_votingParams,
_voteOnBehalf,
_daoFactory,
_stakingToken,
address(this),
address(this),
_packageVersion,
_votingMachineName);
}

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

/**
* @dev initialize
* @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 _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 _rewarderName the rewarder contract name.

*/
function initialize(
Avatar _avatar,
IntVoteInterface _votingMachine,
uint[11] calldata _votingParams,
uint256[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, _votingMachine, _voteParamsHash, _votingParams, _voteOnBehalf);
super._initializeGovernance(
_avatar,
_votingParams,
_voteOnBehalf,
_daoFactory,
_stakingToken,
address(this),
address(this),
_packageVersion,
_votingMachineName);
vault = new Vault();
vault.initialize(address(this));
if (_daoFactory != DAOFactory(0)) {
if (bytes(_rewarderName).length != 0) {
rewarder = address(_daoFactory.createInstance(
_packageVersion,
_rewarderName,
Expand Down Expand Up @@ -163,7 +170,7 @@ contract ContributionRewardExt is VotingMachineCallbacks, ProposalExecuteInterfa
if (proposer == address(0)) {
proposer = msg.sender;
}
proposalId = votingMachine.propose(2, voteParamsHash, proposer, address(avatar));
proposalId = votingMachine.propose(2, proposer);
address payable beneficiary = _beneficiary;
if (beneficiary == address(0)) {
beneficiary = msg.sender;
Expand Down
31 changes: 22 additions & 9 deletions contracts/schemes/ControllerUpgradeScheme.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,34 @@ contract ControllerUpgradeScheme is VotingMachineCallbacks, ProposalExecuteInter
/**
* @dev initialize
* @param _avatar the avatar this scheme referring to.
* @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 _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.
*/
function initialize(
Avatar _avatar,
IntVoteInterface _votingMachine,
uint256[11] calldata _votingParams,
address _voteOnBehalf,
bytes32 _voteParamsHash
DAOFactory _daoFactory,
address _stakingToken,
uint64[3] calldata _packageVersion,
string calldata _votingMachineName
)
external
{
super._initializeGovernance(_avatar, _votingMachine, _voteParamsHash, _votingParams, _voteOnBehalf);
super._initializeGovernance(
_avatar,
_votingParams,
_voteOnBehalf,
_daoFactory,
_stakingToken,
address(this),
address(this),
_packageVersion,
_votingMachineName);
}

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

UpgradeProposal memory proposal = UpgradeProposal({
Expand Down
29 changes: 21 additions & 8 deletions contracts/schemes/FundingRequest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,36 @@ contract FundingRequest is
/**
* @dev initialize
* @param _avatar the avatar this scheme referring to.
* @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 _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 _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,
bytes32 _voteParamsHash,
DAOFactory _daoFactory,
address _stakingToken,
uint64[3] calldata _packageVersion,
string calldata _votingMachineName,
IERC20 _fundingToken
)
external
{
super._initializeGovernance(_avatar, _votingMachine, _voteParamsHash, _votingParams, _voteOnBehalf);
super._initializeGovernance(
_avatar,
_votingParams,
_voteOnBehalf,
_daoFactory,
_stakingToken,
address(this),
address(this),
_packageVersion,
_votingMachineName);
fundingToken = _fundingToken;
}

Expand Down Expand Up @@ -104,7 +117,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, voteParamsHash, msg.sender, address(avatar));
bytes32 proposalId = votingMachine.propose(2, msg.sender);
address payable beneficiary = _beneficiary;
if (beneficiary == address(0)) {
beneficiary = msg.sender;
Expand Down
Loading