Skip to content
Open
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
24 changes: 10 additions & 14 deletions contracts/BlockReward.sol
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
pragma solidity ^0.4.24;

pragma solidity ^0.8.0;

import "./abstracts/BlockRewardBase.sol";
import "./interfaces/IConsensus.sol";
import "./eternal-storage/EternalStorage.sol";
import "./ProxyStorage.sol";
import "openzeppelin-solidity/contracts/math/SafeMath.sol";

/**
* @title Contract handling block reward logic
* @author LiorRabin
*/
contract BlockReward is EternalStorage, BlockRewardBase {
using SafeMath for uint256;

uint256 public constant DECIMALS = 10 ** 18;
uint256 public constant INFLATION = 5;
uint256 public constant BLOCKS_PER_YEAR = 6307200;
Expand Down Expand Up @@ -80,7 +78,7 @@ contract BlockReward is EternalStorage, BlockRewardBase {
* @param kind array of reward types. We support only arrays with one item and type = 0 (Author - Reward attributed to the block author)
* See https://wiki.parity.io/Block-Reward-Contract.html
*/
function reward(address[] benefactors, uint16[] kind) external onlySystem returns (address[], uint256[]) {
function reward(address[] calldata benefactors, uint16[] calldata kind) external override onlySystem returns (address[] memory, uint256[] memory) {
require(benefactors.length == kind.length);
require(benefactors.length == 1);
require(kind[0] == 0);
Expand All @@ -97,13 +95,13 @@ contract BlockReward is EternalStorage, BlockRewardBase {
for (uint256 i = 1; i <= _delegators.length; i++) {
receivers[i] = _delegators[i - 1];
rewards[i] = _rewards[i - 1];
rewards[0] = rewards[0].sub(rewards[i]);
rewards[0] = rewards[0] - rewards[i];
}

_setRewardedOnCycle(getRewardedOnCycle().add(blockRewardAmount));
_setTotalSupply(getTotalSupply().add(blockRewardAmount));
_setRewardedOnCycle(getRewardedOnCycle() + blockRewardAmount);
_setTotalSupply(getTotalSupply() + blockRewardAmount);

if ((block.number).mod(getBlocksPerYear()) == 0) {
if (block.number % getBlocksPerYear() == 0) {
_setBlockRewardAmount();
}

Expand Down Expand Up @@ -140,7 +138,6 @@ contract BlockReward is EternalStorage, BlockRewardBase {
}

function _setTotalSupply(uint256 _supply) private {
require(_supply >= 0);
uintStorage[TOTAL_SUPPLY] = _supply;
}

Expand All @@ -153,7 +150,6 @@ contract BlockReward is EternalStorage, BlockRewardBase {
}

function _setRewardedOnCycle(uint256 _amount) private {
require(_amount >= 0);
uintStorage[REWARDED_THIS_CYCLE] = _amount;
}

Expand All @@ -171,12 +167,12 @@ contract BlockReward is EternalStorage, BlockRewardBase {
/**
* returns blocks per year (block time is 5 seconds)
*/
function getBlocksPerYear() public pure returns(uint256) {
function getBlocksPerYear() public pure virtual returns(uint256) {
return BLOCKS_PER_YEAR;
}

function _setBlockRewardAmount() private {
uintStorage[BLOCK_REWARD_AMOUNT] = (getTotalSupply().mul(getInflation().mul(DECIMALS).div(100))).div(getBlocksPerYear()).div(DECIMALS);
uintStorage[BLOCK_REWARD_AMOUNT] = (getTotalSupply() * (getInflation() * DECIMALS / 100)) / getBlocksPerYear() / DECIMALS;
}

function getBlockRewardAmount() public view returns(uint256) {
Expand All @@ -193,7 +189,7 @@ contract BlockReward is EternalStorage, BlockRewardBase {
if (totalStakeAmount == 0) {
return getBlockRewardAmount();
}
return getBlockRewardAmount().mul(stakeAmount).mul(currentValidatorsLength).div(totalStakeAmount);
return getBlockRewardAmount() * stakeAmount * currentValidatorsLength / totalStakeAmount;
}


Expand Down
18 changes: 13 additions & 5 deletions contracts/Consensus.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.4.24;

pragma solidity ^0.8.0;

import "./interfaces/IBlockReward.sol";
import "./interfaces/IVoting.sol";
Expand Down Expand Up @@ -29,14 +30,14 @@ contract Consensus is ConsensusUtils {
/**
* @dev Function which returns the current validator addresses
*/
function getValidators() external view returns(address[]) {
function getValidators() external view override returns(address[] memory) {
return currentValidators();
}

/**
* @dev See ValidatorSet.finalizeChange
*/
function finalizeChange() external onlySystem notFinalized {
function finalizeChange() external override onlySystem notFinalized {
if (newValidatorSetLength() > 0) {
_setCurrentValidators(newValidatorSet());
emit ChangeFinalized(currentValidators());
Expand All @@ -45,9 +46,16 @@ contract Consensus is ConsensusUtils {
}

/**
* @dev Fallback function allowing to pay to this contract. Whoever sends funds is considered as "staking" and wanting to become a validator.
* @dev Receive function allowing to pay to this contract. Whoever sends funds is considered as "staking" and wanting to become a validator.
*/
receive() external payable {
_delegate(msg.sender, msg.value, msg.sender);
}

/**
* @dev Fallback function preserving the legacy behaviour - any call with unknown calldata and value attached is considered as "staking"
*/
function () external payable {
fallback() external payable {
_delegate(msg.sender, msg.value, msg.sender);
}

Expand Down
Loading