Skip to content
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
66 changes: 38 additions & 28 deletions contracts/votingMachines/GenesisProtocolLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ contract GenesisProtocolLogic is IntVoteInterface {
uint256 daoBounty;
uint256 totalStakes;// Total number of tokens staked which can be redeemable by stakers.
uint256 confidenceThreshold;
//The percentage from upper stakes which the caller for the expiration was given.
uint256 expirationCallBountyPercentage;
uint256 secondsFromTimeOutTillExecuteBoosted;
uint[3] times; //times[0] - submittedTime
//times[1] - boostedPhaseTime
//times[2] -preBoostedPhaseTime;
Expand Down Expand Up @@ -201,12 +200,7 @@ contract GenesisProtocolLogic is IntVoteInterface {
//calc dao bounty
uint256 daoBounty =
parameters[_paramsHash].daoBountyConst.mul(averagesDownstakesOfBoosted[proposal.organizationId]).div(100);
if (daoBounty < parameters[_paramsHash].minimumDaoBounty) {
proposal.daoBountyRemain = parameters[_paramsHash].minimumDaoBounty;
} else {
proposal.daoBountyRemain = daoBounty;
}
proposal.totalStakes = proposal.daoBountyRemain;
proposal.daoBountyRemain = daoBounty.max(parameters[_paramsHash].minimumDaoBounty);
proposals[proposalId] = proposal;
proposals[proposalId].stakes[NO] = proposal.daoBountyRemain;//dao downstake on the proposal

Expand All @@ -216,6 +210,9 @@ contract GenesisProtocolLogic is IntVoteInterface {

/**
* @dev executeBoosted try to execute a boosted or QuietEndingPeriod proposal if it is expired
* it rewards the msg.sender with P % of the proposal's upstakes upon a successful call to this function.
* P = t/150, where t is the number of seconds passed since the the proposal's timeout.
* P is capped by 10%.
* @param _proposalId the id of the proposal
* @return uint256 expirationCallBounty the bounty amount for the expiration call
*/
Expand All @@ -224,14 +221,13 @@ contract GenesisProtocolLogic is IntVoteInterface {
require(proposal.state == ProposalState.Boosted || proposal.state == ProposalState.QuietEndingPeriod,
"proposal state in not Boosted nor QuietEndingPeriod");
require(_execute(_proposalId), "proposal need to expire");
uint256 expirationCallBountyPercentage =

proposal.secondsFromTimeOutTillExecuteBoosted =
// solhint-disable-next-line not-rely-on-time
(uint(1).add(now.sub(proposal.currentBoostedVotePeriodLimit.add(proposal.times[1])).div(15)));
if (expirationCallBountyPercentage > 100) {
expirationCallBountyPercentage = 100;
}
proposal.expirationCallBountyPercentage = expirationCallBountyPercentage;
expirationCallBounty = expirationCallBountyPercentage.mul(proposal.stakes[YES]).div(100);
now.sub(proposal.currentBoostedVotePeriodLimit.add(proposal.times[1]));

expirationCallBounty = calcExecuteCallBounty(_proposalId);
proposal.totalStakes = proposal.totalStakes.sub(expirationCallBounty);
require(stakingToken.transfer(msg.sender, expirationCallBounty), "transfer to msg.sender failed");
emit ExpirationCallBounty(_proposalId, msg.sender, expirationCallBounty);
}
Expand Down Expand Up @@ -314,21 +310,13 @@ contract GenesisProtocolLogic is IntVoteInterface {
require((proposal.state == ProposalState.Executed)||(proposal.state == ProposalState.ExpiredInQueue),
"Proposal should be Executed or ExpiredInQueue");
Parameters memory params = parameters[proposal.paramsHash];
uint256 lostReputation;
if (proposal.winningVote == YES) {
lostReputation = proposal.preBoostedVotes[NO];
} else {
lostReputation = proposal.preBoostedVotes[YES];
}
lostReputation = (lostReputation.mul(params.votersReputationLossRatio))/100;
//as staker
Staker storage staker = proposal.stakers[_beneficiary];
uint256 totalStakes = proposal.stakes[NO].add(proposal.stakes[YES]);
uint256 totalWinningStakes = proposal.stakes[proposal.winningVote];

uint256 totalStakesLeftAfterCallBounty =
proposal.stakes[NO].add(proposal.stakes[YES]).sub(calcExecuteCallBounty(_proposalId));
if (staker.amount > 0) {
uint256 totalStakesLeftAfterCallBounty =
totalStakes.sub(proposal.expirationCallBountyPercentage.mul(proposal.stakes[YES]).div(100));

if (proposal.state == ProposalState.ExpiredInQueue) {
//Stakes of a proposal that expires in Queue are sent back to stakers
rewards[0] = staker.amount;
Expand All @@ -350,7 +338,9 @@ contract GenesisProtocolLogic is IntVoteInterface {
proposal.state != ProposalState.ExpiredInQueue &&
proposal.winningVote == NO) {
rewards[0] =
rewards[0].add((proposal.daoBounty.mul(totalStakes))/totalWinningStakes).sub(proposal.daoBounty);
rewards[0]
.add((proposal.daoBounty.mul(totalStakesLeftAfterCallBounty))/totalWinningStakes)
.sub(proposal.daoBounty);
proposal.daoRedeemItsWinnings = true;
}

Expand All @@ -361,6 +351,13 @@ contract GenesisProtocolLogic is IntVoteInterface {
//give back reputation for the voter
rewards[1] = ((voter.reputation.mul(params.votersReputationLossRatio))/100);
} else if (proposal.winningVote == voter.vote) {
uint256 lostReputation;
if (proposal.winningVote == YES) {
lostReputation = proposal.preBoostedVotes[NO];
} else {
lostReputation = proposal.preBoostedVotes[YES];
}
lostReputation = (lostReputation.mul(params.votersReputationLossRatio))/100;
rewards[1] = ((voter.reputation.mul(params.votersReputationLossRatio))/100)
.add((voter.reputation.mul(lostReputation))/proposal.preBoostedVotes[proposal.winningVote]);
}
Expand Down Expand Up @@ -425,6 +422,18 @@ contract GenesisProtocolLogic is IntVoteInterface {
}
}

/**
* @dev calcExecuteCallBounty calculate the execute boosted call bounty
* @param _proposalId the ID of the proposal
* @return uint256 executeCallBounty
*/
function calcExecuteCallBounty(bytes32 _proposalId) public view returns(uint256) {
uint maxRewardSeconds = 1500;
uint rewardSeconds =
uint256(maxRewardSeconds).min(proposals[_proposalId].secondsFromTimeOutTillExecuteBoosted);
return rewardSeconds.mul(proposals[_proposalId].stakes[YES]).div(maxRewardSeconds*10);
}

/**
* @dev shouldBoost check if a proposal should be shifted to boosted phase.
* @param _proposalId the ID of the proposal
Expand Down Expand Up @@ -644,7 +653,8 @@ contract GenesisProtocolLogic is IntVoteInterface {
//This is to prevent average downstakes calculation overflow
//Note that any how GEN cap is 100000000 ether.
require(staker.amount <= 0x100000000000000000000000000000000, "staking amount is too high");
require(proposal.totalStakes <= 0x100000000000000000000000000000000, "total stakes is too high");
require(proposal.totalStakes <= uint256(0x100000000000000000000000000000000).sub(proposal.daoBountyRemain),
"total stakes is too high");

if (_vote == YES) {
staker.amount4Bounty = staker.amount4Bounty.add(amount);
Expand Down
Loading