Skip to content

redeemer : joinAndQuit + FundingRequest #777

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 2 commits into from
Jul 29, 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
2 changes: 0 additions & 2 deletions contracts/schemes/TokenTrade.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ contract TokenTrade is VotingMachineCallbacks, ProposalExecuteInterface {
onlyVotingMachine(_proposalId)
override
returns(bool) {
Proposal memory proposal = proposals[_proposalId];
if (_decision == 1) {
proposals[_proposalId].passed = true;
}
Expand All @@ -87,7 +86,6 @@ contract TokenTrade is VotingMachineCallbacks, ProposalExecuteInterface {
return true;
}


function execute(bytes32 _proposalId) public {
Proposal storage proposal = proposals[_proposalId];
require(proposal.decided, "must be a decided proposal");
Expand Down
92 changes: 92 additions & 0 deletions contracts/utils/Redeemer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ pragma solidity ^0.6.10;

import "../schemes/ContributionReward.sol";
import "../schemes/ContributionRewardExt.sol";
import "../schemes/FundingRequest.sol";
import "../schemes/JoinAndQuit.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/IERC20.sol";


Expand Down Expand Up @@ -119,6 +121,96 @@ contract Redeemer {
}
}

/**
* @dev helper to redeem rewards for a proposal
* It calls execute on the proposal if it is not yet executed.
* It tries to redeem reputation and stake from the GenesisProtocol.
* It tries to redeem proposal rewards from the JoinAndQuit scheme.
* This function does not emit events.
* A client should listen to GenesisProtocol and JoinAndQuit redemption events
* to monitor redemption operations.
* @param _joinAndQuit joinAndQuit scheme
* @param _genesisProtocol genesisProtocol
* @param _proposalId the ID of the voting in the voting machine
* @param _beneficiary beneficiary
* @return gpRewards array
* gpRewards[0] - stakerTokenAmount
* gpRewards[1] - voterReputationAmount
* gpRewards[2] - proposerReputationAmount
* @return gpDaoBountyReward array
* gpDaoBountyReward[0] - staker dao bounty reward -
* will be zero for the case there is not enough tokens in avatar for the reward.
* gpDaoBountyReward[1] - staker potential dao bounty reward.
* @return executed bool true or false
* @return winningVote
* 1 - executed or closed and the winning vote is YES
* 2 - executed or closed and the winning vote is NO
* @return joinAndQuitReputationReward Reputation - from JoinAndQuit reputation reward
*/
function redeemJoinAndQuit(JoinAndQuit _joinAndQuit,
GenesisProtocol _genesisProtocol,
bytes32 _proposalId,
address _beneficiary)
external
returns(uint[3] memory gpRewards,
uint[2] memory gpDaoBountyReward,
bool executed,
uint256 winningVote,
uint256 joinAndQuitReputationReward
)
{
bool callJoinAndQuit;
(gpRewards, gpDaoBountyReward, executed, winningVote, callJoinAndQuit) =
genesisProtocolRedeem(_genesisProtocol, _proposalId, _beneficiary);
if (callJoinAndQuit) {
joinAndQuitReputationReward = _joinAndQuit.redeemReputation(_proposalId);
}
}

/**
* @dev helper to redeem rewards for a proposal
* It calls execute on the proposal if it is not yet executed.
* It tries to redeem reputation and stake from the GenesisProtocol.
* It tries to redeem proposal rewards from the FundingRequest scheme.
* This function does not emit events.
* A client should listen to GenesisProtocol and FundingRequest redemption events
* to monitor redemption operations.
* @param _fundingRequest fundingRequest scheme
* @param _genesisProtocol genesisProtocol
* @param _proposalId the ID of the voting in the voting machine
* @param _beneficiary beneficiary
* @return gpRewards array
* gpRewards[0] - stakerTokenAmount
* gpRewards[1] - voterReputationAmount
* gpRewards[2] - proposerReputationAmount
* @return gpDaoBountyReward array
* gpDaoBountyReward[0] - staker dao bounty reward -
* will be zero for the case there is not enough tokens in avatar for the reward.
* gpDaoBountyReward[1] - staker potential dao bounty reward.
* @return executed bool true or false
* @return winningVote
* 1 - executed or closed and the winning vote is YES
* 2 - executed or closed and the winning vote is NO
*/
function redeemFundingRequest(FundingRequest _fundingRequest,
GenesisProtocol _genesisProtocol,
bytes32 _proposalId,
address _beneficiary)
external
returns(uint[3] memory gpRewards,
uint[2] memory gpDaoBountyReward,
bool executed,
uint256 winningVote
)
{
bool callFundingRequest;
(gpRewards, gpDaoBountyReward, executed, winningVote, callFundingRequest) =
genesisProtocolRedeem(_genesisProtocol, _proposalId, _beneficiary);
if (callFundingRequest) {
_fundingRequest.redeem(_proposalId);
}
}

function genesisProtocolRedeem(GenesisProtocol _genesisProtocol,
bytes32 _proposalId,
address _beneficiary)
Expand Down
Loading