Skip to content

Commit 51c72e5

Browse files
authored
None universal voting machines (#757)
* wip * + * + * wip * update ArcScheme * wip * + daoFactory with single tx * tests * tests * package-lock.json * organizatin always is avatar * test * more tests
1 parent 8eb5cc4 commit 51c72e5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1941
-1635
lines changed

contracts/schemes/ArcScheme.sol

Lines changed: 54 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@ import "../controller/Avatar.sol";
44
import "@daostack/infra-experimental/contracts/votingMachines/GenesisProtocol.sol";
55
import "@daostack/infra-experimental/contracts/votingMachines/IntVoteInterface.sol";
66
import "@openzeppelin/upgrades/contracts/Initializable.sol";
7+
import "../utils/DAOFactory.sol";
8+
import "../libs/StringUtil.sol";
79

810

911
contract ArcScheme is Initializable {
12+
using StringUtil for string;
1013
Avatar public avatar;
1114
IntVoteInterface public votingMachine;
12-
bytes32 public voteParamsHash;
15+
16+
string public constant GENESIS_PROTOCOL_INIT_FUNC_SIGNATURE =
17+
"initialize(address,uint256[11],address,address,address,address)";
18+
19+
string public constant ABSOLUTE_VOTE_INIT_FUNC_SIGNATURE =
20+
"initialize(uint256,address,address,address,address)";
1321

1422
/**
1523
* @dev _initialize
@@ -24,35 +32,60 @@ contract ArcScheme is Initializable {
2432
/**
2533
* @dev _initializeGovernance
2634
* @param _avatar the scheme avatar
27-
* @param _votingMachine the scheme voting machine
28-
* @param _voteParamsHash the scheme vote params
2935
* @param _votingParams genesisProtocol parameters - valid only if _voteParamsHash is zero
30-
* @param _voteOnBehalf genesisProtocol parameter - valid only if _voteParamsHash is zero
36+
* @param _voteOnBehalf parameter
37+
* @param _daoFactory DAOFactory instance to instance a votingMachine.
38+
* @param _stakingToken (for GenesisProtocol)
39+
* @param _callbacks should fulfill voting callbacks interface
40+
* @param _authorizedToPropose only this address allow to propose (unless it is zero)
41+
* @param _packageVersion packageVersion to instance the votingMachine from.
42+
* @param _votingMachineName the votingMachine contract name.
3143
*/
3244
function _initializeGovernance(
3345
Avatar _avatar,
34-
IntVoteInterface _votingMachine,
35-
bytes32 _voteParamsHash,
3646
uint256[11] memory _votingParams,
37-
address _voteOnBehalf
47+
address _voteOnBehalf,
48+
DAOFactory _daoFactory,
49+
address _stakingToken,
50+
address _callbacks,
51+
address _authorizedToPropose,
52+
uint64[3] memory _packageVersion,
53+
string memory _votingMachineName
3854
) internal
3955
{
40-
require(_votingMachine != IntVoteInterface(0), "votingMachine cannot be zero");
56+
57+
require(_daoFactory != DAOFactory(0), "daoFactory cannot be zero");
58+
require(
59+
_daoFactory.getImplementation(_packageVersion, _votingMachineName) != address(0),
60+
"votingMachine name does not exist in ArcHive"
61+
);
4162
_initialize(_avatar);
42-
votingMachine = _votingMachine;
43-
if (_voteParamsHash == bytes32(0)) {
44-
//genesisProtocol
45-
GenesisProtocol genesisProtocol = GenesisProtocol(address(_votingMachine));
46-
voteParamsHash = genesisProtocol.getParametersHash(_votingParams, _voteOnBehalf);
47-
(uint256 queuedVoteRequiredPercentage, , , , , , , , , , , ,) =
48-
genesisProtocol.parameters(voteParamsHash);
49-
if (queuedVoteRequiredPercentage == 0) {
50-
//params not set already
51-
genesisProtocol.setParameters(_votingParams, _voteOnBehalf);
52-
}
63+
64+
bytes memory initData;
65+
if (_votingMachineName.hashCompareWithLengthCheck("GenesisProtocol")) {
66+
initData = abi.encodeWithSignature(
67+
GENESIS_PROTOCOL_INIT_FUNC_SIGNATURE,
68+
_stakingToken,
69+
_votingParams,
70+
_voteOnBehalf,
71+
avatar,
72+
_callbacks,
73+
_authorizedToPropose);
5374
} else {
54-
//for other voting machines
55-
voteParamsHash = _voteParamsHash;
75+
initData = abi.encodeWithSignature(
76+
ABSOLUTE_VOTE_INIT_FUNC_SIGNATURE,
77+
_votingParams[0],
78+
_voteOnBehalf,
79+
avatar,
80+
_callbacks,
81+
_authorizedToPropose);
5682
}
83+
84+
votingMachine = IntVoteInterface(address(_daoFactory.createInstance(
85+
_packageVersion,
86+
_votingMachineName,
87+
address(avatar),
88+
initData)));
89+
5790
}
5891
}

contracts/schemes/Auction4Reputation.sol

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ contract Auction4Reputation is Agreement, ArcScheme {
3434
uint256 public auctionPeriod;
3535
uint256 public redeemEnableTime;
3636
IERC20 public token;
37-
address public wallet;
3837

3938
/**
4039
* @dev initialize
@@ -49,9 +48,6 @@ contract Auction4Reputation is Agreement, ArcScheme {
4948
* @param _redeemEnableTime redeem enable time .
5049
* redeem reputation can be done after this time.
5150
* @param _token the bidding token
52-
* @param _wallet the address of the wallet the token will be transfer to.
53-
* Please note that _wallet address should be a trusted account.
54-
* Normally this address should be set as the DAO's avatar address.
5551
* @param _agreementHash is a hash of agreement required to be added to the TX by participants
5652
*/
5753
function initialize(
@@ -62,7 +58,6 @@ contract Auction4Reputation is Agreement, ArcScheme {
6258
uint256 _numberOfAuctions,
6359
uint256 _redeemEnableTime,
6460
IERC20 _token,
65-
address _wallet,
6661
bytes32 _agreementHash )
6762
external
6863
{
@@ -76,7 +71,6 @@ contract Auction4Reputation is Agreement, ArcScheme {
7671
token = _token;
7772
auctionsStartTime = _auctionsStartTime;
7873
numberOfAuctions = _numberOfAuctions;
79-
wallet = _wallet;
8074
auctionReputationReward = _auctionReputationReward;
8175
reputationRewardLeft = _auctionReputationReward.mul(_numberOfAuctions);
8276
redeemEnableTime = _redeemEnableTime;
@@ -133,14 +127,14 @@ contract Auction4Reputation is Agreement, ArcScheme {
133127
}
134128

135129
/**
136-
* @dev transferToWallet transfer the tokens to the wallet.
130+
* @dev transferToWallet transfer the tokens to the avatar.
137131
* can be called only after auctionsEndTime
138132
*/
139133
function transferToWallet() public {
140134
// solhint-disable-next-line not-rely-on-time
141135
require(now > auctionsEndTime, "now > auctionsEndTime");
142136
uint256 tokenBalance = token.balanceOf(address(this));
143-
token.safeTransfer(wallet, tokenBalance);
137+
token.safeTransfer(address(avatar), tokenBalance);
144138
}
145139

146140
/**

contracts/schemes/ContributionReward.sol

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,35 @@ contract ContributionReward is
6565
/**
6666
* @dev initialize
6767
* @param _avatar the avatar this scheme referring to.
68-
* @param _votingMachine the voting machines address to
69-
* @param _votingParams genesisProtocol parameters - valid only if _voteParamsHash is zero
70-
* @param _voteOnBehalf genesisProtocol parameter - valid only if _voteParamsHash is zero
71-
* @param _voteParamsHash voting machine parameters.
68+
* @param _votingParams genesisProtocol parameters
69+
* @param _voteOnBehalf parameter
70+
* @param _daoFactory DAOFactory instance to instance a votingMachine.
71+
* @param _stakingToken (for GenesisProtocol)
72+
* @param _packageVersion packageVersion to instance the votingMachine from.
73+
* @param _votingMachineName the votingMachine contract name.
7274
*/
7375
function initialize(
7476
Avatar _avatar,
75-
IntVoteInterface _votingMachine,
7677
uint256[11] calldata _votingParams,
7778
address _voteOnBehalf,
78-
bytes32 _voteParamsHash
79+
DAOFactory _daoFactory,
80+
address _stakingToken,
81+
uint64[3] calldata _packageVersion,
82+
string calldata _votingMachineName
7983
)
8084
external
8185
initializer
8286
{
83-
super._initializeGovernance(_avatar, _votingMachine, _voteParamsHash, _votingParams, _voteOnBehalf);
87+
super._initializeGovernance(
88+
_avatar,
89+
_votingParams,
90+
_voteOnBehalf,
91+
_daoFactory,
92+
_stakingToken,
93+
address(this),
94+
address(this),
95+
_packageVersion,
96+
_votingMachineName);
8497
}
8598

8699
/**
@@ -127,7 +140,7 @@ contract ContributionReward is
127140
returns(bytes32)
128141
{
129142
validateProposalParams(_reputationChange, _rewards);
130-
bytes32 proposalId = votingMachine.propose(2, voteParamsHash, msg.sender, address(avatar));
143+
bytes32 proposalId = votingMachine.propose(2, msg.sender);
131144
address payable beneficiary = _beneficiary;
132145
if (beneficiary == address(0)) {
133146
beneficiary = msg.sender;

contracts/schemes/ContributionRewardExt.sol

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,33 +83,40 @@ contract ContributionRewardExt is VotingMachineCallbacks, ProposalExecuteInterfa
8383

8484
/**
8585
* @dev initialize
86-
* @param _avatar the avatar to mint reputation from
87-
* @param _votingMachine the voting machines address
88-
* @param _votingParams genesisProtocol parameters - valid only if _voteParamsHash is zero
89-
* @param _voteOnBehalf genesisProtocol parameter - valid only if _voteParamsHash is zero
90-
* @param _voteParamsHash voting machine parameters
91-
* @param _daoFactory DAOFactory instance to instance a rewarder.
92-
* if _daoFactory is zero so no rewarder will be set.
93-
* @param _packageVersion packageVersion to instance the rewarder from.
86+
* @param _avatar the avatar this scheme referring to.
87+
* @param _votingParams genesisProtocol parameters
88+
* @param _voteOnBehalf parameter
89+
* @param _daoFactory DAOFactory instance to instance a votingMachine.
90+
* @param _stakingToken (for GenesisProtocol)
91+
* @param _packageVersion packageVersion to instance the votingMachine from.
92+
* @param _votingMachineName the votingMachine contract name.
9493
* @param _rewarderName the rewarder contract name.
95-
9694
*/
9795
function initialize(
9896
Avatar _avatar,
99-
IntVoteInterface _votingMachine,
100-
uint[11] calldata _votingParams,
97+
uint256[11] calldata _votingParams,
10198
address _voteOnBehalf,
102-
bytes32 _voteParamsHash,
10399
DAOFactory _daoFactory,
100+
address _stakingToken,
104101
uint64[3] calldata _packageVersion,
102+
string calldata _votingMachineName,
105103
string calldata _rewarderName
106104
)
107105
external
108106
{
109-
super._initializeGovernance(_avatar, _votingMachine, _voteParamsHash, _votingParams, _voteOnBehalf);
107+
super._initializeGovernance(
108+
_avatar,
109+
_votingParams,
110+
_voteOnBehalf,
111+
_daoFactory,
112+
_stakingToken,
113+
address(this),
114+
address(this),
115+
_packageVersion,
116+
_votingMachineName);
110117
vault = new Vault();
111118
vault.initialize(address(this));
112-
if (_daoFactory != DAOFactory(0)) {
119+
if (bytes(_rewarderName).length != 0) {
113120
rewarder = address(_daoFactory.createInstance(
114121
_packageVersion,
115122
_rewarderName,
@@ -163,7 +170,7 @@ contract ContributionRewardExt is VotingMachineCallbacks, ProposalExecuteInterfa
163170
if (proposer == address(0)) {
164171
proposer = msg.sender;
165172
}
166-
proposalId = votingMachine.propose(2, voteParamsHash, proposer, address(avatar));
173+
proposalId = votingMachine.propose(2, proposer);
167174
address payable beneficiary = _beneficiary;
168175
if (beneficiary == address(0)) {
169176
beneficiary = msg.sender;

contracts/schemes/ControllerUpgradeScheme.sol

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,34 @@ contract ControllerUpgradeScheme is VotingMachineCallbacks, ProposalExecuteInter
4141
/**
4242
* @dev initialize
4343
* @param _avatar the avatar this scheme referring to.
44-
* @param _votingMachine the voting machines address to
45-
* @param _votingParams genesisProtocol parameters - valid only if _voteParamsHash is zero
46-
* @param _voteOnBehalf genesisProtocol parameter - valid only if _voteParamsHash is zero
47-
* @param _voteParamsHash voting machine parameters.
44+
* @param _votingParams genesisProtocol parameters
45+
* @param _voteOnBehalf parameter
46+
* @param _daoFactory DAOFactory instance to instance a votingMachine.
47+
* @param _stakingToken (for GenesisProtocol)
48+
* @param _packageVersion packageVersion to instance the votingMachine from.
49+
* @param _votingMachineName the votingMachine contract name.
4850
*/
4951
function initialize(
5052
Avatar _avatar,
51-
IntVoteInterface _votingMachine,
5253
uint256[11] calldata _votingParams,
5354
address _voteOnBehalf,
54-
bytes32 _voteParamsHash
55+
DAOFactory _daoFactory,
56+
address _stakingToken,
57+
uint64[3] calldata _packageVersion,
58+
string calldata _votingMachineName
5559
)
5660
external
5761
{
58-
super._initializeGovernance(_avatar, _votingMachine, _voteParamsHash, _votingParams, _voteOnBehalf);
62+
super._initializeGovernance(
63+
_avatar,
64+
_votingParams,
65+
_voteOnBehalf,
66+
_daoFactory,
67+
_stakingToken,
68+
address(this),
69+
address(this),
70+
_packageVersion,
71+
_votingMachineName);
5972
}
6073

6174
/**
@@ -103,7 +116,7 @@ contract ControllerUpgradeScheme is VotingMachineCallbacks, ProposalExecuteInter
103116
public
104117
returns(bytes32)
105118
{
106-
bytes32 proposalId = votingMachine.propose(2, voteParamsHash, msg.sender, address(avatar));
119+
bytes32 proposalId = votingMachine.propose(2, msg.sender);
107120
UpgradeProposal memory proposal = UpgradeProposal({
108121
proposalType: 1,
109122
upgradeContract: _newController
@@ -135,7 +148,7 @@ contract ControllerUpgradeScheme is VotingMachineCallbacks, ProposalExecuteInter
135148
public
136149
returns(bytes32)
137150
{
138-
bytes32 proposalId = votingMachine.propose(2, voteParamsHash, msg.sender, address(avatar));
151+
bytes32 proposalId = votingMachine.propose(2, msg.sender);
139152
require(organizationProposals[proposalId].proposalType == 0);
140153

141154
UpgradeProposal memory proposal = UpgradeProposal({

contracts/schemes/FundingRequest.sol

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,36 @@ contract FundingRequest is
4646
/**
4747
* @dev initialize
4848
* @param _avatar the avatar this scheme referring to.
49-
* @param _votingMachine the voting machines address to
50-
* @param _votingParams genesisProtocol parameters - valid only if _voteParamsHash is zero
51-
* @param _voteOnBehalf genesisProtocol parameter - valid only if _voteParamsHash is zero
52-
* @param _voteParamsHash voting machine parameters.
49+
* @param _votingParams genesisProtocol parameters
50+
* @param _voteOnBehalf parameter
51+
* @param _daoFactory DAOFactory instance to instance a votingMachine.
52+
* @param _stakingToken (for GenesisProtocol)
53+
* @param _packageVersion packageVersion to instance the votingMachine from.
54+
* @param _votingMachineName the votingMachine contract name.
5355
* @param _fundingToken token to transfer to funding requests. 0x0 address for the native coin
5456
*/
5557
function initialize(
5658
Avatar _avatar,
57-
IntVoteInterface _votingMachine,
5859
uint256[11] calldata _votingParams,
5960
address _voteOnBehalf,
60-
bytes32 _voteParamsHash,
61+
DAOFactory _daoFactory,
62+
address _stakingToken,
63+
uint64[3] calldata _packageVersion,
64+
string calldata _votingMachineName,
6165
IERC20 _fundingToken
6266
)
6367
external
6468
{
65-
super._initializeGovernance(_avatar, _votingMachine, _voteParamsHash, _votingParams, _voteOnBehalf);
69+
super._initializeGovernance(
70+
_avatar,
71+
_votingParams,
72+
_voteOnBehalf,
73+
_daoFactory,
74+
_stakingToken,
75+
address(this),
76+
address(this),
77+
_packageVersion,
78+
_votingMachineName);
6679
fundingToken = _fundingToken;
6780
}
6881

@@ -104,7 +117,7 @@ contract FundingRequest is
104117
avatar.db(FUNDED_BEFORE_DEADLINE_KEY).hashCompareWithLengthCheck(FUNDED_BEFORE_DEADLINE_VALUE),
105118
"funding is not allowed yet"
106119
);
107-
bytes32 proposalId = votingMachine.propose(2, voteParamsHash, msg.sender, address(avatar));
120+
bytes32 proposalId = votingMachine.propose(2, msg.sender);
108121
address payable beneficiary = _beneficiary;
109122
if (beneficiary == address(0)) {
110123
beneficiary = msg.sender;

0 commit comments

Comments
 (0)