Skip to content

Commit 0bc13de

Browse files
committed
add consensus reward
1 parent bac2b33 commit 0bc13de

File tree

6 files changed

+84
-169
lines changed

6 files changed

+84
-169
lines changed

contracts/solidity/Governance.sol

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ interface IGovernance {
6262
}
6363

6464
interface IGovReward {
65-
function withdrawERC20(address to, address token, uint256 amount) external;
65+
function withdrawERC20(address to, address token, uint amount) external;
6666

67-
function withdraw(address to, uint256 amount) external;
67+
function withdraw(address to, uint amount) external;
6868
}
6969

7070
contract Governance is IGovernance {
@@ -103,11 +103,16 @@ contract Governance is IGovernance {
103103
// total withdrawed reward
104104
uint public totalWithdrawedReward;
105105

106-
uint256 private constant _NOT_ENTERED = 1;
107-
uint256 private constant _ENTERED = 2;
106+
uint private constant _NOT_ENTERED = 1;
107+
uint private constant _ENTERED = 2;
108108

109109
// status for nonReentrant modifier
110-
uint256 private _status;
110+
uint private _status;
111+
112+
// ratio base
113+
uint public constant RatioBase = 10000;
114+
// vote reward ratio
115+
uint public constant RatioVote = 5000;
111116

112117
/**
113118
* @dev Prevents a contract from calling itself, directly or indirectly.
@@ -126,10 +131,8 @@ contract Governance is IGovernance {
126131
_status = _NOT_ENTERED;
127132
}
128133

129-
receive() external payable {}
130-
131134
modifier onlyConsensus() {
132-
require(isMiner(msg.sender), "Not Consensus");
135+
require(isMiner(msg.sender), "sender is not a consensus member");
133136
_;
134137
}
135138

@@ -158,7 +161,7 @@ contract Governance is IGovernance {
158161

159162
require(
160163
block.number > lastStartHeight,
161-
"propose should after last phase active"
164+
"propose should be called after last phase start"
162165
);
163166

164167
endDraftId++;
@@ -180,8 +183,8 @@ contract Governance is IGovernance {
180183
}
181184

182185
function vote(
183-
uint256 draftId,
184-
uint256 amount
186+
uint draftId,
187+
uint amount
185188
) external payable override nonReentrant {
186189
require(
187190
draftId >= startDraftId && draftId <= endDraftId,
@@ -234,7 +237,7 @@ contract Governance is IGovernance {
234237
}
235238
}
236239

237-
function safeTransferETH(address to, uint256 value) internal {
240+
function safeTransferETH(address to, uint value) internal {
238241
(bool success, ) = to.call{value: value}(new bytes(0));
239242
require(success, "safeTransferETH: ETH transfer failed");
240243
}
@@ -274,8 +277,22 @@ contract Governance is IGovernance {
274277
// for pre phases, we get by rewardRecord
275278
currentReward = preReward;
276279
}
277-
// sum all the reward for msg.sender
278-
reward += (currentReward * share) / current.voteAmount;
280+
// sum all the vote reward for addr
281+
reward +=
282+
(currentReward * share * RatioVote) /
283+
current.voteAmount /
284+
RatioBase;
285+
286+
// sum all the consensus reward
287+
for (uint i = 0; i < current.miners.length; i++) {
288+
if (addr == current.miners[i]) {
289+
reward +=
290+
(currentReward * (RatioBase - RatioVote)) /
291+
current.miners.length /
292+
RatioBase;
293+
break;
294+
}
295+
}
279296

280297
// calculate the reward for pre phase
281298
preReward =

privnet/four/genesis_template.json

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

0 commit comments

Comments
 (0)