Skip to content

Commit ea381c4

Browse files
author
Oren Sokolowsky
committed
Create Rewarder instance from ConributionRewardExt
1 parent 8f2fa92 commit ea381c4

File tree

7 files changed

+163
-71
lines changed

7 files changed

+163
-71
lines changed

contracts/controller/Controller.sol

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,8 @@ contract Controller is Initializable {
329329
onlyUpgradingScheme
330330
returns(bool)
331331
{
332-
require(newController == address(0), "this controller was already upgraded"); // so the upgrade could be done once for a contract.
332+
// make sure upgrade could be done once for a contract.
333+
require(newController == address(0), "this controller was already upgraded");
333334
require(_newController != address(0), "new controller cannot be 0");
334335
newController = _newController;
335336
avatar.transferOwnership(_newController);
@@ -340,7 +341,8 @@ contract Controller is Initializable {
340341
}
341342
if (nativeReputation.owner() == address(this)) {
342343
nativeReputation.transferOwnership(_newController);
343-
require(nativeReputation.owner() == _newController, "failed to transfer reputation ownership to the new controller");
344+
require(nativeReputation.owner() == _newController,
345+
"failed to transfer reputation ownership to the new controller");
344346
}
345347
emit UpgradeController(address(this), newController);
346348
return true;

contracts/schemes/Competition.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pragma solidity 0.5.17;
33
import "./ContributionRewardExt.sol";
44

55

6-
contract Competition is Initializable {
6+
contract Competition is Initializable, Rewarder {
77
using SafeMath for uint256;
88

99
uint256 constant public MAX_NUMBER_OF_WINNERS = 100;

contracts/schemes/ContributionRewardExt.sol

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
pragma solidity 0.5.17;
22

33
import "../votingMachines/VotingMachineCallbacks.sol";
4+
import "../utils/DAOFactory.sol";
5+
6+
7+
interface Rewarder {
8+
function initialize(address payable) external;
9+
}
10+
411

512
/**
613
* @title A scheme for proposing and rewarding contributions to an organization
@@ -81,23 +88,34 @@ contract ContributionRewardExt is VotingMachineCallbacks, ProposalExecuteInterfa
8188
* @param _votingParams genesisProtocol parameters - valid only if _voteParamsHash is zero
8289
* @param _voteOnBehalf genesisProtocol parameter - valid only if _voteParamsHash is zero
8390
* @param _voteParamsHash voting machine parameters
84-
* @param _rewarder an address which allowed to redeem the contribution.
85-
if _rewarder is 0 this param is agnored.
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.
94+
* @param _rewarderName the rewarder contract name.
95+
8696
*/
8797
function initialize(
8898
Avatar _avatar,
8999
IntVoteInterface _votingMachine,
90100
uint[11] calldata _votingParams,
91101
address _voteOnBehalf,
92102
bytes32 _voteParamsHash,
93-
address _rewarder
103+
DAOFactory _daoFactory,
104+
uint64[3] calldata _packageVersion,
105+
string calldata _rewarderName
94106
)
95107
external
96108
{
97109
super._initializeGovernance(_avatar, _votingMachine, _voteParamsHash, _votingParams, _voteOnBehalf);
98-
rewarder = _rewarder;
99110
vault = new Vault();
100111
vault.initialize(address(this));
112+
if (_daoFactory != DAOFactory(0)) {
113+
rewarder = address(_daoFactory.createInstance(
114+
_packageVersion,
115+
_rewarderName,
116+
address(avatar),
117+
abi.encodeWithSignature("initialize(address)", address(this))));
118+
}
101119
}
102120

103121
/**

contracts/test/RewarderMock.sol

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
pragma solidity ^0.5.17;
2+
3+
import "../schemes/ContributionRewardExt.sol";
4+
5+
6+
contract RewarderMock is Rewarder {
7+
ContributionRewardExt public contributionRewardExt;
8+
9+
function initialize(address payable _contributionRewardExt) external {
10+
contributionRewardExt = ContributionRewardExt(_contributionRewardExt);
11+
}
12+
13+
function redeemEtherByRewarder(bytes32 _proposalId, address payable _beneficiary, uint256 _amount)
14+
public {
15+
contributionRewardExt.redeemEtherByRewarder(_proposalId, _beneficiary, _amount);
16+
}
17+
18+
function redeemNativeTokenByRewarder(bytes32 _proposalId, address payable _beneficiary, uint256 _amount)
19+
public {
20+
contributionRewardExt.redeemNativeTokenByRewarder(_proposalId, _beneficiary, _amount);
21+
}
22+
23+
function redeemExternalTokenByRewarder(bytes32 _proposalId, address payable _beneficiary, uint256 _amount)
24+
public {
25+
contributionRewardExt.redeemExternalTokenByRewarder(_proposalId, _beneficiary, _amount);
26+
}
27+
28+
function redeemReputationByRewarder(bytes32 _proposalId, address payable _beneficiary, uint256 _amount)
29+
public {
30+
contributionRewardExt.redeemReputationByRewarder(_proposalId, _beneficiary, _amount);
31+
}
32+
}

test/competition.js

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ const setupContributionRewardExt = async function(
1414
genesisProtocol,
1515
token,
1616
avatarAddress,
17-
rewarderAddress
17+
_daoFactoryAddress,
18+
_packageVersion = [0,1,0],
19+
_rewarderName = 'Competition'
1820
) {
1921
var contributionRewardParams = new ContributionRewardParams();
2022

@@ -27,7 +29,10 @@ const setupContributionRewardExt = async function(
2729
contributionRewardParams.votingMachine.uintArray,
2830
contributionRewardParams.votingMachine.voteOnBehalf,
2931
helpers.NULL_ADDRESS,
30-
rewarderAddress)
32+
_daoFactoryAddress,
33+
_packageVersion,
34+
_rewarderName
35+
)
3136
.encodeABI();
3237
} else {
3338
contributionRewardParams.votingMachine = await helpers.setupAbsoluteVote(helpers.NULL_ADDRESS,50);
@@ -38,7 +43,9 @@ const setupContributionRewardExt = async function(
3843
[1,1,1,1,1,1,1,1,1,1,1],
3944
helpers.NULL_ADDRESS,
4045
contributionRewardParams.votingMachine.params,
41-
rewarderAddress)
46+
_daoFactoryAddress,
47+
_packageVersion,
48+
_rewarderName)
4249
.encodeABI();
4350
}
4451
return contributionRewardParams;
@@ -65,21 +72,13 @@ const setup = async function (accounts,genesisProtocol = false,tokenAddress=0) {
6572
[1000,0,0],
6673
testSetup.reputationArray);
6774

68-
var tx = await registration.daoFactory.createInstance(
69-
[0,0,0],
70-
"Competition",
71-
testSetup.proxyAdmin,
72-
Buffer.from(''),
73-
{from:testSetup.proxyAdmin});
74-
assert.equal(tx.logs.length, 1);
75-
assert.equal(tx.logs[0].event, "ProxyCreated");
76-
testSetup.competition = await Competition.at(tx.logs[0].args._proxy);
75+
7776
testSetup.contributionRewardExtParams= await setupContributionRewardExt(
7877
accounts,
7978
genesisProtocol,
8079
tokenAddress,
8180
testSetup.org.avatar.address,
82-
testSetup.competition.address);
81+
registration.daoFactory.address);
8382

8483
var permissions = "0x00000000";
8584
tx = await registration.daoFactory.setSchemes(
@@ -89,10 +88,9 @@ const setup = async function (accounts,genesisProtocol = false,tokenAddress=0) {
8988
[helpers.getBytesLength(testSetup.contributionRewardExtParams.initdata)],
9089
[permissions],
9190
"metaData",{from:testSetup.proxyAdmin});
92-
93-
testSetup.contributionRewardExt = await ContributionRewardExt.at(tx.logs[1].args._scheme);
94-
95-
await testSetup.competition.initialize(testSetup.contributionRewardExt.address);
91+
testSetup.contributionRewardExt = await ContributionRewardExt.at(tx.logs[2].args._scheme);
92+
var competitionAddress = await testSetup.contributionRewardExt.rewarder();
93+
testSetup.competition = await Competition.at(competitionAddress);
9694
testSetup.admin = accounts[0];
9795

9896
return testSetup;

0 commit comments

Comments
 (0)