Skip to content

Commit

Permalink
Competition contract + ContributionRewardExt scheme (#697)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
orenyodfat authored Dec 5, 2019
1 parent 8e9e2e3 commit bf0ecdb
Show file tree
Hide file tree
Showing 8 changed files with 2,279 additions and 13 deletions.
395 changes: 395 additions & 0 deletions contracts/schemes/Competition.sol

Large diffs are not rendered by default.

465 changes: 465 additions & 0 deletions contracts/schemes/ContributionRewardExt.sol

Large diffs are not rendered by default.

107 changes: 102 additions & 5 deletions contracts/utils/Redeemer.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pragma solidity 0.5.13;

import "../universalSchemes/ContributionReward.sol";
import "../schemes/ContributionRewardExt.sol";
import "@daostack/infra/contracts/votingMachines/GenesisProtocol.sol";
import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";

Expand Down Expand Up @@ -53,6 +54,82 @@ contract Redeemer {
uint256 crEthReward,
uint256 crExternalTokenReward)
{
bool callContributionReward;
(gpRewards, gpDaoBountyReward, executed, winningVote, callContributionReward) =
genesisProtocolRedeem(_genesisProtocol, _proposalId, _beneficiary);
if (callContributionReward) {
//redeem from contributionReward only if it executed
if (_contributionReward.getProposalExecutionTime(_proposalId, address(_avatar)) > 0) {
(crReputationReward, crNativeTokenReward, crEthReward, crExternalTokenReward) =
contributionRewardRedeem(_contributionReward, _proposalId, _avatar);
}
}
}

/**
* @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 contribution rewards scheme.
* This function does not emit events.
* A client should listen to GenesisProtocol and ContributionReward redemption events
* to monitor redemption operations.
* @param _contributionRewardExt contributionRewardExt
* @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 int256 crReputationReward Reputation - from ContributionReward
* @return int256 crNativeTokenReward NativeTokenReward - from ContributionReward
* @return int256 crEthReward Ether - from ContributionReward
* @return int256 crExternalTokenReward ExternalToken - from ContributionReward
*/
function redeemFromCRExt(ContributionRewardExt _contributionRewardExt,
GenesisProtocol _genesisProtocol,
bytes32 _proposalId,
address _beneficiary)
external
returns(uint[3] memory gpRewards,
uint[2] memory gpDaoBountyReward,
bool executed,
uint256 winningVote,
int256 crReputationReward,
uint256 crNativeTokenReward,
uint256 crEthReward,
uint256 crExternalTokenReward)
{
bool callContributionReward;
(gpRewards, gpDaoBountyReward, executed, winningVote, callContributionReward) =
genesisProtocolRedeem(_genesisProtocol, _proposalId, _beneficiary);
if (callContributionReward) {
//redeem from contributionReward only if it executed
if (_contributionRewardExt.getProposalAcceptedByVotingMachine(_proposalId)) {
(crReputationReward, crNativeTokenReward, crEthReward, crExternalTokenReward) =
contributionRewardExtRedeem(_contributionRewardExt, _proposalId);
}
}
}

function genesisProtocolRedeem(GenesisProtocol _genesisProtocol,
bytes32 _proposalId,
address _beneficiary)
private
returns(uint[3] memory gpRewards,
uint[2] memory gpDaoBountyReward,
bool executed,
uint256 winningVote,
bool callContributionReward) {
GenesisProtocol.ProposalState pState = _genesisProtocol.state(_proposalId);

if ((pState == GenesisProtocolLogic.ProposalState.Queued)||
Expand All @@ -70,11 +147,7 @@ contract Redeemer {
_genesisProtocol.redeemDaoBounty(_proposalId, _beneficiary);
}
winningVote = _genesisProtocol.winningVote(_proposalId);
//redeem from contributionReward only if it executed
if (_contributionReward.getProposalExecutionTime(_proposalId, address(_avatar)) > 0) {
(crReputationReward, crNativeTokenReward, crEthReward, crExternalTokenReward) =
contributionRewardRedeem(_contributionReward, _proposalId, _avatar);
}
callContributionReward = true;
}
}

Expand Down Expand Up @@ -105,4 +178,28 @@ contract Redeemer {
}
(reputation, nativeToken, eth, externalToken) = _contributionReward.redeem(_proposalId, _avatar, whatToRedeem);
}

function contributionRewardExtRedeem(ContributionRewardExt _contributionRewardExt, bytes32 _proposalId)
private
returns (int256 reputation, uint256 nativeToken, uint256 eth, uint256 externalToken)
{
bool[4] memory whatToRedeem;
whatToRedeem[0] = true; //reputation
whatToRedeem[1] = true; //nativeToken
uint256 ethReward = _contributionRewardExt.getProposalEthReward(_proposalId);
uint256 externalTokenReward = _contributionRewardExt.getProposalExternalTokenReward(_proposalId);
address externalTokenAddress = _contributionRewardExt.getProposalExternalToken(_proposalId);
if ((ethReward == 0) || (address(_contributionRewardExt.avatar()).balance < ethReward)) {
whatToRedeem[2] = false;
} else {
whatToRedeem[2] = true;
}
if ((externalTokenReward == 0) ||
(IERC20(externalTokenAddress).balanceOf(address(_contributionRewardExt.avatar())) < externalTokenReward)) {
whatToRedeem[3] = false;
} else {
whatToRedeem[3] = true;
}
(reputation, nativeToken, eth, externalToken) = _contributionRewardExt.redeem(_proposalId, whatToRedeem);
}
}
15 changes: 11 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@daostack/arc",
"version": "0.0.1-rc.34",
"version": "0.0.1-rc.35",
"description": "A platform for building DAOs",
"files": [
"contracts/",
Expand All @@ -12,7 +12,7 @@
"tsconfig.json"
],
"config": {
"gasLimit": "6100000"
"gasLimit": "6200000"
},
"scripts": {
"test": "cross-conf-env run-with-ganache --ganache-cmd 'npm run ganache' 'npm run truffle compile && npm run truffle migrate && npm run truffle test'",
Expand Down Expand Up @@ -77,7 +77,7 @@
"dependencies": {
"@daostack/infra": "0.0.1-rc.15",
"math": "0.0.3",
"openzeppelin-solidity": "2.3.0",
"openzeppelin-solidity": "2.4.0",
"truffle-flattener": "^1.4.2"
},
"peerDependencies": {
Expand Down
Loading

0 comments on commit bf0ecdb

Please sign in to comment.