Skip to content

Commit bf0ecdb

Browse files
authored
Competition contract + ContributionRewardExt scheme (#697)
* first version * comp version * wip : competition scheme * add redeem to competition. * remove experimental pragma * wip add contributionrewardext test * tests * tests * fixes and cosmetics * fix refreshTopSuggestions * add initilize function * update tests * naming address payable _suggester * remove redundent line * update pr comments * add sendLeftOverFunds * naming + tests * comments * bump version to 0.0.1-rc.35 increase GAS_LIMIT to 62000000 due to new openzeppeling-solidity * better test timing setup * suggestionEndTime test
1 parent 8e9e2e3 commit bf0ecdb

File tree

8 files changed

+2279
-13
lines changed

8 files changed

+2279
-13
lines changed

contracts/schemes/Competition.sol

Lines changed: 395 additions & 0 deletions
Large diffs are not rendered by default.

contracts/schemes/ContributionRewardExt.sol

Lines changed: 465 additions & 0 deletions
Large diffs are not rendered by default.

contracts/utils/Redeemer.sol

Lines changed: 102 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pragma solidity 0.5.13;
22

33
import "../universalSchemes/ContributionReward.sol";
4+
import "../schemes/ContributionRewardExt.sol";
45
import "@daostack/infra/contracts/votingMachines/GenesisProtocol.sol";
56
import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";
67

@@ -53,6 +54,82 @@ contract Redeemer {
5354
uint256 crEthReward,
5455
uint256 crExternalTokenReward)
5556
{
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) {
56133
GenesisProtocol.ProposalState pState = _genesisProtocol.state(_proposalId);
57134

58135
if ((pState == GenesisProtocolLogic.ProposalState.Queued)||
@@ -70,11 +147,7 @@ contract Redeemer {
70147
_genesisProtocol.redeemDaoBounty(_proposalId, _beneficiary);
71148
}
72149
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;
78151
}
79152
}
80153

@@ -105,4 +178,28 @@ contract Redeemer {
105178
}
106179
(reputation, nativeToken, eth, externalToken) = _contributionReward.redeem(_proposalId, _avatar, whatToRedeem);
107180
}
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+
}
108205
}

package-lock.json

Lines changed: 11 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@daostack/arc",
3-
"version": "0.0.1-rc.34",
3+
"version": "0.0.1-rc.35",
44
"description": "A platform for building DAOs",
55
"files": [
66
"contracts/",
@@ -12,7 +12,7 @@
1212
"tsconfig.json"
1313
],
1414
"config": {
15-
"gasLimit": "6100000"
15+
"gasLimit": "6200000"
1616
},
1717
"scripts": {
1818
"test": "cross-conf-env run-with-ganache --ganache-cmd 'npm run ganache' 'npm run truffle compile && npm run truffle migrate && npm run truffle test'",
@@ -77,7 +77,7 @@
7777
"dependencies": {
7878
"@daostack/infra": "0.0.1-rc.15",
7979
"math": "0.0.3",
80-
"openzeppelin-solidity": "2.3.0",
80+
"openzeppelin-solidity": "2.4.0",
8181
"truffle-flattener": "^1.4.2"
8282
},
8383
"peerDependencies": {

0 commit comments

Comments
 (0)