Skip to content

Commit da0696a

Browse files
authored
Create Rewarder instance within ConributionRewardExt init function (#746)
* bump version to 0.1.1-rc.17 * Create Rewarder instance from ConributionRewardExt
1 parent 6343cc5 commit da0696a

File tree

9 files changed

+227
-657
lines changed

9 files changed

+227
-657
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+
}

0 commit comments

Comments
 (0)