BlockRewardAuRa
contract BlockRewardAuRa
Generates and distributes rewards according to the logic and formulas described in the POSDAO white paper.
Index
Reference
Functions
_dequeueValidator
function _dequeueValidator() internal returns (address)
Dequeues a validator enqueued for the snapshotting or rewarding process. Used by the `reward` and `_distributeRewards` functions. If the queue is empty, the function returns a zero address.
- Returns:
- address
_distributeRewards
function _distributeRewards(IValidatorSet _validatorSetContract, address _erc20TokenContract, bool _erc20Restricted, IStakingAuRa _stakingContract, uint256 _stakingEpoch, uint256 _rewardPointBlock) internal returns (address[], uint256[], bool)
Distributes rewards among participants during the last MAX_VALIDATORS * DELEGATORS_ALIQUOT blocks of a staking epoch. This function is called by the `reward` function.
- Parameters:
_validatorSetContract
- The address of the ValidatorSet contract._erc20TokenContract
- The address of the ERC20 staking token contract._erc20Restricted
- A boolean flag indicating whether the StakingAuRa contract restricts using ERC20/677 contract. If it's set to `true`, native staking coins are used instead of ERC staking tokens._stakingContract
- The address of the Staking contract._stakingEpoch
- The number of the current staking epoch._rewardPointBlock
- The number of the block within the current staking epoch when the rewarding process should start. This number is calculated by the `_rewardPointBlock` getter.- Returns:
- `address[] receivers` - The array of native coins receivers which should be rewarded at the current block by the `erc-to-native` bridge or by the fixed native reward. `uint256[] rewards` - The array of amounts corresponding to the `receivers` array. `bool noop` - The boolean flag which is set to `true` when there are no complex operations during the function launch. The flag is used by the `reward` function to control the load on the block inside the `_mintNativeCoins` function.
_enqueueValidator
function _enqueueValidator(address _validatorStakingAddress) internal
Enqueues the specified validator for the snapshotting or rewarding process. Used by the `reward` and `_distributeRewards` functions. See also DELEGATORS_ALIQUOT.
- Parameters:
_validatorStakingAddress
- The staking address of a validator to be enqueued.
_rewardPointBlock
function _rewardPointBlock(IStakingAuRa _stakingContract, IValidatorSet _validatorSetContract) internal view returns (uint256)
Calculates the starting block number for the rewarding process at the end of the current staking epoch. Used by the `reward` and `_distributeRewards` functions.
- Parameters:
_stakingContract
- The address of the StakingAuRa contract._validatorSetContract
- The address of the ValidatorSet contract.- Returns:
- uint256
_subNativeRewardUndistributed
function _subNativeRewardUndistributed(uint256 _minus) internal
Reduces an undistributed amount of native coins. This function is used by the `_distributeRewards` function.
- Parameters:
_minus
- The subtraction value.
_subTokenRewardUndistributed
function _subTokenRewardUndistributed(uint256 _minus) internal
Reduces an undistributed amount of staking tokens. This function is used by the `_distributeRewards` function.
- Parameters:
_minus
- The subtraction value.
_validatorsQueueSize
function _validatorsQueueSize() internal view returns (uint256)
Returns the size of the validator queue used for the snapshotting and rewarding processes. See `_enqueueValidator` and `_dequeueValidator` functions. This function is used by the `reward` and `_distributeRewards` functions.
- Returns:
- uint256
getBlocksCreated
function getBlocksCreated(uint256 _stakingEpoch, address _validatorMiningAddress) public view returns (uint256)
Returns a number of blocks produced by the specified validator during the specified staking epoch (beginning from the block when the `finalizeChange` function is called until the block specified by the `_rewardPointBlock` function). The results are used by the `_distributeRewards` function to track each validator's downtime (when a validator's node is not running and doesn't produce blocks).
- Parameters:
_stakingEpoch
- The number of the staking epoch for which the statistics should be returned._validatorMiningAddress
- The mining address of the validator for which the statistics should be returned.- Returns:
- uint256
getEpochPoolNativeReward
function getEpochPoolNativeReward(uint256 _stakingEpoch, address _poolStakingAddress) public view returns (uint256)
Returns the reward amount to be distributed in native coins among participants (the validator and their delegators) of the specified pool at the end of the specified staking epoch.
- Parameters:
_stakingEpoch
- The number of the staking epoch for which the amount should be returned._poolStakingAddress
- The staking address of the pool for which the amount should be returned.- Returns:
- uint256
getEpochPoolTokenReward
function getEpochPoolTokenReward(uint256 _stakingEpoch, address _poolStakingAddress) public view returns (uint256)
Returns the reward amount to be distributed in staking tokens among participants (the validator and their delegators) of the specified pool at the end of the specified staking epoch.
- Parameters:
_stakingEpoch
- The number of the staking epoch for which the amount should be returned._poolStakingAddress
- The staking address of the pool for which the amount should be returned.- Returns:
- uint256
getNativeRewardUndistributed
function getNativeRewardUndistributed() public view returns (uint256)
Returns the total reward amount in native coins which is not yet distributed among participants.
- Returns:
- uint256
getTokenRewardUndistributed
function getTokenRewardUndistributed() public view returns (uint256)
Returns the total reward amount in staking tokens which is not yet distributed among participants.
- Returns:
- uint256
reward
function reward(address[] benefactors, uint16[] kind) external returns (address[], uint256[])
Called by the validator's node when producing and closing a block, see https://wiki.parity.io/Block-Reward-Contract.html. This function performs all of the automatic operations needed for controlling secrets revealing by validators, accumulating block producing statistics, starting a new staking epoch, snapshotting reward coefficients at the beginning of a new staking epoch, rewards distributing at the end of a staking epoch, and minting native coins needed for the `erc-to-native` bridge.
- Modifiers:
- onlySystem
- Parameters:
benefactors
- address[]kind
- uint16[]- Returns:
- address[]
- uint256[]