Skip to content

Commit b8d99e0

Browse files
authored
redeemer : joinAndQuit + FundingRequest (#777)
* redeemer : joinAndQuit + FundingRequest lint issue bump builder version to 1.4.0 * more test coverage
1 parent 13d2a22 commit b8d99e0

File tree

6 files changed

+468
-212
lines changed

6 files changed

+468
-212
lines changed

contracts/schemes/TokenTrade.sol

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ contract TokenTrade is VotingMachineCallbacks, ProposalExecuteInterface {
7777
onlyVotingMachine(_proposalId)
7878
override
7979
returns(bool) {
80-
Proposal memory proposal = proposals[_proposalId];
8180
if (_decision == 1) {
8281
proposals[_proposalId].passed = true;
8382
}
@@ -87,7 +86,6 @@ contract TokenTrade is VotingMachineCallbacks, ProposalExecuteInterface {
8786
return true;
8887
}
8988

90-
9189
function execute(bytes32 _proposalId) public {
9290
Proposal storage proposal = proposals[_proposalId];
9391
require(proposal.decided, "must be a decided proposal");

contracts/utils/Redeemer.sol

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ pragma solidity ^0.6.10;
33

44
import "../schemes/ContributionReward.sol";
55
import "../schemes/ContributionRewardExt.sol";
6+
import "../schemes/FundingRequest.sol";
7+
import "../schemes/JoinAndQuit.sol";
68
import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/IERC20.sol";
79

810

@@ -119,6 +121,96 @@ contract Redeemer {
119121
}
120122
}
121123

124+
/**
125+
* @dev helper to redeem rewards for a proposal
126+
* It calls execute on the proposal if it is not yet executed.
127+
* It tries to redeem reputation and stake from the GenesisProtocol.
128+
* It tries to redeem proposal rewards from the JoinAndQuit scheme.
129+
* This function does not emit events.
130+
* A client should listen to GenesisProtocol and JoinAndQuit redemption events
131+
* to monitor redemption operations.
132+
* @param _joinAndQuit joinAndQuit scheme
133+
* @param _genesisProtocol genesisProtocol
134+
* @param _proposalId the ID of the voting in the voting machine
135+
* @param _beneficiary beneficiary
136+
* @return gpRewards array
137+
* gpRewards[0] - stakerTokenAmount
138+
* gpRewards[1] - voterReputationAmount
139+
* gpRewards[2] - proposerReputationAmount
140+
* @return gpDaoBountyReward array
141+
* gpDaoBountyReward[0] - staker dao bounty reward -
142+
* will be zero for the case there is not enough tokens in avatar for the reward.
143+
* gpDaoBountyReward[1] - staker potential dao bounty reward.
144+
* @return executed bool true or false
145+
* @return winningVote
146+
* 1 - executed or closed and the winning vote is YES
147+
* 2 - executed or closed and the winning vote is NO
148+
* @return joinAndQuitReputationReward Reputation - from JoinAndQuit reputation reward
149+
*/
150+
function redeemJoinAndQuit(JoinAndQuit _joinAndQuit,
151+
GenesisProtocol _genesisProtocol,
152+
bytes32 _proposalId,
153+
address _beneficiary)
154+
external
155+
returns(uint[3] memory gpRewards,
156+
uint[2] memory gpDaoBountyReward,
157+
bool executed,
158+
uint256 winningVote,
159+
uint256 joinAndQuitReputationReward
160+
)
161+
{
162+
bool callJoinAndQuit;
163+
(gpRewards, gpDaoBountyReward, executed, winningVote, callJoinAndQuit) =
164+
genesisProtocolRedeem(_genesisProtocol, _proposalId, _beneficiary);
165+
if (callJoinAndQuit) {
166+
joinAndQuitReputationReward = _joinAndQuit.redeemReputation(_proposalId);
167+
}
168+
}
169+
170+
/**
171+
* @dev helper to redeem rewards for a proposal
172+
* It calls execute on the proposal if it is not yet executed.
173+
* It tries to redeem reputation and stake from the GenesisProtocol.
174+
* It tries to redeem proposal rewards from the FundingRequest scheme.
175+
* This function does not emit events.
176+
* A client should listen to GenesisProtocol and FundingRequest redemption events
177+
* to monitor redemption operations.
178+
* @param _fundingRequest fundingRequest scheme
179+
* @param _genesisProtocol genesisProtocol
180+
* @param _proposalId the ID of the voting in the voting machine
181+
* @param _beneficiary beneficiary
182+
* @return gpRewards array
183+
* gpRewards[0] - stakerTokenAmount
184+
* gpRewards[1] - voterReputationAmount
185+
* gpRewards[2] - proposerReputationAmount
186+
* @return gpDaoBountyReward array
187+
* gpDaoBountyReward[0] - staker dao bounty reward -
188+
* will be zero for the case there is not enough tokens in avatar for the reward.
189+
* gpDaoBountyReward[1] - staker potential dao bounty reward.
190+
* @return executed bool true or false
191+
* @return winningVote
192+
* 1 - executed or closed and the winning vote is YES
193+
* 2 - executed or closed and the winning vote is NO
194+
*/
195+
function redeemFundingRequest(FundingRequest _fundingRequest,
196+
GenesisProtocol _genesisProtocol,
197+
bytes32 _proposalId,
198+
address _beneficiary)
199+
external
200+
returns(uint[3] memory gpRewards,
201+
uint[2] memory gpDaoBountyReward,
202+
bool executed,
203+
uint256 winningVote
204+
)
205+
{
206+
bool callFundingRequest;
207+
(gpRewards, gpDaoBountyReward, executed, winningVote, callFundingRequest) =
208+
genesisProtocolRedeem(_genesisProtocol, _proposalId, _beneficiary);
209+
if (callFundingRequest) {
210+
_fundingRequest.redeem(_proposalId);
211+
}
212+
}
213+
122214
function genesisProtocolRedeem(GenesisProtocol _genesisProtocol,
123215
bytes32 _proposalId,
124216
address _beneficiary)

0 commit comments

Comments
 (0)