Skip to content
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

Create Rewarder instance within ConributionRewardExt init function #746

Merged
merged 2 commits into from
May 7, 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
6 changes: 4 additions & 2 deletions contracts/controller/Controller.sol
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ contract Controller is Initializable {
onlyUpgradingScheme
returns(bool)
{
require(newController == address(0), "this controller was already upgraded"); // so the upgrade could be done once for a contract.
// make sure upgrade could be done once for a contract.
require(newController == address(0), "this controller was already upgraded");
require(_newController != address(0), "new controller cannot be 0");
newController = _newController;
avatar.transferOwnership(_newController);
Expand All @@ -340,7 +341,8 @@ contract Controller is Initializable {
}
if (nativeReputation.owner() == address(this)) {
nativeReputation.transferOwnership(_newController);
require(nativeReputation.owner() == _newController, "failed to transfer reputation ownership to the new controller");
require(nativeReputation.owner() == _newController,
"failed to transfer reputation ownership to the new controller");
}
emit UpgradeController(address(this), newController);
return true;
Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/Competition.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity 0.5.17;
import "./ContributionRewardExt.sol";


contract Competition is Initializable {
contract Competition is Initializable, Rewarder {
using SafeMath for uint256;

uint256 constant public MAX_NUMBER_OF_WINNERS = 100;
Expand Down
26 changes: 22 additions & 4 deletions contracts/schemes/ContributionRewardExt.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
pragma solidity 0.5.17;

import "../votingMachines/VotingMachineCallbacks.sol";
import "../utils/DAOFactory.sol";


interface Rewarder {
function initialize(address payable) external;
}


/**
* @title A scheme for proposing and rewarding contributions to an organization
Expand Down Expand Up @@ -81,23 +88,34 @@ contract ContributionRewardExt is VotingMachineCallbacks, ProposalExecuteInterfa
* @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 _rewarder an address which allowed to redeem the contribution.
if _rewarder is 0 this param is agnored.
* @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,
IntVoteInterface _votingMachine,
uint[11] calldata _votingParams,
address _voteOnBehalf,
bytes32 _voteParamsHash,
address _rewarder
DAOFactory _daoFactory,
uint64[3] calldata _packageVersion,
string calldata _rewarderName
)
external
{
super._initializeGovernance(_avatar, _votingMachine, _voteParamsHash, _votingParams, _voteOnBehalf);
rewarder = _rewarder;
vault = new Vault();
vault.initialize(address(this));
if (_daoFactory != DAOFactory(0)) {
rewarder = address(_daoFactory.createInstance(
_packageVersion,
_rewarderName,
address(avatar),
abi.encodeWithSignature("initialize(address)", address(this))));
}
}

/**
Expand Down
32 changes: 32 additions & 0 deletions contracts/test/RewarderMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
pragma solidity ^0.5.17;

import "../schemes/ContributionRewardExt.sol";


contract RewarderMock is Rewarder {
ContributionRewardExt public contributionRewardExt;

function initialize(address payable _contributionRewardExt) external {
contributionRewardExt = ContributionRewardExt(_contributionRewardExt);
}

function redeemEtherByRewarder(bytes32 _proposalId, address payable _beneficiary, uint256 _amount)
public {
contributionRewardExt.redeemEtherByRewarder(_proposalId, _beneficiary, _amount);
}

function redeemNativeTokenByRewarder(bytes32 _proposalId, address payable _beneficiary, uint256 _amount)
public {
contributionRewardExt.redeemNativeTokenByRewarder(_proposalId, _beneficiary, _amount);
}

function redeemExternalTokenByRewarder(bytes32 _proposalId, address payable _beneficiary, uint256 _amount)
public {
contributionRewardExt.redeemExternalTokenByRewarder(_proposalId, _beneficiary, _amount);
}

function redeemReputationByRewarder(bytes32 _proposalId, address payable _beneficiary, uint256 _amount)
public {
contributionRewardExt.redeemReputationByRewarder(_proposalId, _beneficiary, _amount);
}
}
Loading