1
1
pragma solidity 0.5.13 ;
2
2
3
3
import "../universalSchemes/ContributionReward.sol " ;
4
+ import "../schemes/ContributionRewardExt.sol " ;
4
5
import "@daostack/infra/contracts/votingMachines/GenesisProtocol.sol " ;
5
6
import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol " ;
6
7
@@ -53,6 +54,82 @@ contract Redeemer {
53
54
uint256 crEthReward ,
54
55
uint256 crExternalTokenReward )
55
56
{
57
+ bool callContributionReward;
58
+ (gpRewards, gpDaoBountyReward, executed, winningVote, callContributionReward) =
59
+ genesisProtocolRedeem (_genesisProtocol, _proposalId, _beneficiary);
60
+ if (callContributionReward) {
61
+ //redeem from contributionReward only if it executed
62
+ if (_contributionReward.getProposalExecutionTime (_proposalId, address (_avatar)) > 0 ) {
63
+ (crReputationReward, crNativeTokenReward, crEthReward, crExternalTokenReward) =
64
+ contributionRewardRedeem (_contributionReward, _proposalId, _avatar);
65
+ }
66
+ }
67
+ }
68
+
69
+ /**
70
+ * @dev helper to redeem rewards for a proposal
71
+ * It calls execute on the proposal if it is not yet executed.
72
+ * It tries to redeem reputation and stake from the GenesisProtocol.
73
+ * It tries to redeem proposal rewards from the contribution rewards scheme.
74
+ * This function does not emit events.
75
+ * A client should listen to GenesisProtocol and ContributionReward redemption events
76
+ * to monitor redemption operations.
77
+ * @param _contributionRewardExt contributionRewardExt
78
+ * @param _genesisProtocol genesisProtocol
79
+ * @param _proposalId the ID of the voting in the voting machine
80
+ * @param _beneficiary beneficiary
81
+ * @return gpRewards array
82
+ * gpRewards[0] - stakerTokenAmount
83
+ * gpRewards[1] - voterReputationAmount
84
+ * gpRewards[2] - proposerReputationAmount
85
+ * @return gpDaoBountyReward array
86
+ * gpDaoBountyReward[0] - staker dao bounty reward -
87
+ * will be zero for the case there is not enough tokens in avatar for the reward.
88
+ * gpDaoBountyReward[1] - staker potential dao bounty reward.
89
+ * @return executed bool true or false
90
+ * @return winningVote
91
+ * 1 - executed or closed and the winning vote is YES
92
+ * 2 - executed or closed and the winning vote is NO
93
+ * @return int256 crReputationReward Reputation - from ContributionReward
94
+ * @return int256 crNativeTokenReward NativeTokenReward - from ContributionReward
95
+ * @return int256 crEthReward Ether - from ContributionReward
96
+ * @return int256 crExternalTokenReward ExternalToken - from ContributionReward
97
+ */
98
+ function redeemFromCRExt (ContributionRewardExt _contributionRewardExt ,
99
+ GenesisProtocol _genesisProtocol ,
100
+ bytes32 _proposalId ,
101
+ address _beneficiary )
102
+ external
103
+ returns (uint [3 ] memory gpRewards ,
104
+ uint [2 ] memory gpDaoBountyReward ,
105
+ bool executed ,
106
+ uint256 winningVote ,
107
+ int256 crReputationReward ,
108
+ uint256 crNativeTokenReward ,
109
+ uint256 crEthReward ,
110
+ uint256 crExternalTokenReward )
111
+ {
112
+ bool callContributionReward;
113
+ (gpRewards, gpDaoBountyReward, executed, winningVote, callContributionReward) =
114
+ genesisProtocolRedeem (_genesisProtocol, _proposalId, _beneficiary);
115
+ if (callContributionReward) {
116
+ //redeem from contributionReward only if it executed
117
+ if (_contributionRewardExt.getProposalAcceptedByVotingMachine (_proposalId)) {
118
+ (crReputationReward, crNativeTokenReward, crEthReward, crExternalTokenReward) =
119
+ contributionRewardExtRedeem (_contributionRewardExt, _proposalId);
120
+ }
121
+ }
122
+ }
123
+
124
+ function genesisProtocolRedeem (GenesisProtocol _genesisProtocol ,
125
+ bytes32 _proposalId ,
126
+ address _beneficiary )
127
+ private
128
+ returns (uint [3 ] memory gpRewards ,
129
+ uint [2 ] memory gpDaoBountyReward ,
130
+ bool executed ,
131
+ uint256 winningVote ,
132
+ bool callContributionReward ) {
56
133
GenesisProtocol.ProposalState pState = _genesisProtocol.state (_proposalId);
57
134
58
135
if ((pState == GenesisProtocolLogic.ProposalState.Queued)||
@@ -70,11 +147,7 @@ contract Redeemer {
70
147
_genesisProtocol.redeemDaoBounty (_proposalId, _beneficiary);
71
148
}
72
149
winningVote = _genesisProtocol.winningVote (_proposalId);
73
- //redeem from contributionReward only if it executed
74
- if (_contributionReward.getProposalExecutionTime (_proposalId, address (_avatar)) > 0 ) {
75
- (crReputationReward, crNativeTokenReward, crEthReward, crExternalTokenReward) =
76
- contributionRewardRedeem (_contributionReward, _proposalId, _avatar);
77
- }
150
+ callContributionReward = true ;
78
151
}
79
152
}
80
153
@@ -105,4 +178,28 @@ contract Redeemer {
105
178
}
106
179
(reputation, nativeToken, eth, externalToken) = _contributionReward.redeem (_proposalId, _avatar, whatToRedeem);
107
180
}
181
+
182
+ function contributionRewardExtRedeem (ContributionRewardExt _contributionRewardExt , bytes32 _proposalId )
183
+ private
184
+ returns (int256 reputation , uint256 nativeToken , uint256 eth , uint256 externalToken )
185
+ {
186
+ bool [4 ] memory whatToRedeem;
187
+ whatToRedeem[0 ] = true ; //reputation
188
+ whatToRedeem[1 ] = true ; //nativeToken
189
+ uint256 ethReward = _contributionRewardExt.getProposalEthReward (_proposalId);
190
+ uint256 externalTokenReward = _contributionRewardExt.getProposalExternalTokenReward (_proposalId);
191
+ address externalTokenAddress = _contributionRewardExt.getProposalExternalToken (_proposalId);
192
+ if ((ethReward == 0 ) || (address (_contributionRewardExt.avatar ()).balance < ethReward)) {
193
+ whatToRedeem[2 ] = false ;
194
+ } else {
195
+ whatToRedeem[2 ] = true ;
196
+ }
197
+ if ((externalTokenReward == 0 ) ||
198
+ (IERC20 (externalTokenAddress).balanceOf (address (_contributionRewardExt.avatar ())) < externalTokenReward)) {
199
+ whatToRedeem[3 ] = false ;
200
+ } else {
201
+ whatToRedeem[3 ] = true ;
202
+ }
203
+ (reputation, nativeToken, eth, externalToken) = _contributionRewardExt.redeem (_proposalId, whatToRedeem);
204
+ }
108
205
}
0 commit comments