# RewardsStaking

# Overview

Keep tracing the pending staking and commission rate and last settled era.

# settings

contract ISettings settings

# pendingStakers

mapping(address => mapping(uint256 => address)) pendingStakers

# pendingStakerNos

mapping(address => mapping(address => uint256)) pendingStakerNos

# pendingStakeChangeLength

mapping(address => uint256) pendingStakeChangeLength

# pendingCommissionRateChange

mapping(address => uint256) pendingCommissionRateChange

# lastSettledEra

mapping(address => uint256) lastSettledEra

# totalStakingAmount

mapping(address => uint256) totalStakingAmount

# delegation

mapping(address => mapping(address => uint256)) delegation

# commissionRates

mapping(address => uint256) commissionRates

Emitted when the stake amount change.

# StakeChanged

event StakeChanged(address indexer, address staker, uint256 amount)

Emitted when the indexer commission rates change.

# ICRChanged

event ICRChanged(address indexer, uint256 commissionRate)

Emitted when lastSettledEra update.

# SettledEraUpdated

event SettledEraUpdated(address indexer, uint256 era)

Initialize this contract.

# initialize

function initialize(contract ISettings _settings) external

# setSettings

function setSettings(contract ISettings _settings) external

# onlyStaking

modifier onlyStaking()

# onlyIndexerRegistry

modifier onlyIndexerRegistry()

Callback method of stake change, called by Staking contract when Indexers or Delegators try to change their stake amount. Update pending stake info stored in contract states with Staking contract, and wait to apply at next Era. New Indexer's first stake change need to apply immediately。 Last era's reward need to be collected before this can pass.

# onStakeChange

function onStakeChange(address _indexer, address _source) external

Callback method of stake change, called by Staking contract when Indexers try to change commitionRate. Update commitionRate info stored in contract states with Staking contract, and wait to apply at two Eras later. Last era's reward need to be collected before this can pass.

# onICRChange

function onICRChange(address indexer, uint256 startEra) external

Apply the stake change and calaulate the new rewardDebt for staker.

# applyStakeChange

function applyStakeChange(address indexer, address staker) external

Apply the CommissionRate change and update the commissionRates stored in contract states.

# applyICRChange

function applyICRChange(address indexer) external

Check if the previous Era has been settled, also update lastSettledEra. Require to be true when someone try to claimRewards() or onStakeChangeRequested().

# checkAndReflectSettlement

function checkAndReflectSettlement(address indexer, uint256 lastClaimEra) public returns (bool)

Update the totalStakingAmount of the indexer with the state from Staking contract. Called when applyStakeChange or applyICRChange.

# _updateTotalStakingAmount

function _updateTotalStakingAmount(contract IStakingManager stakingManager, address indexer, uint256 lastClaimEra) private
Name Type Description
stakingManager contract IStakingManager Staking contract interface
indexer address Indexer address
lastClaimEra uint256

Get RewardsDistributer instant

# _getRewardsDistributer

function _getRewardsDistributer() private view returns (contract IRewardsDistributer)

Get current Era number from EraManager.

# _getCurrentEra

function _getCurrentEra() private returns (uint256)

Check whether the indexer has pending stake changes for the staker.

# _pendingStakeChange

function _pendingStakeChange(address _indexer, address _staker) private view returns (bool)

# getTotalStakingAmount

function getTotalStakingAmount(address indexer) public view returns (uint256)

# getLastSettledEra

function getLastSettledEra(address indexer) public view returns (uint256)

# getCommissionRate

function getCommissionRate(address indexer) public view returns (uint256)

# getDelegationAmount

function getDelegationAmount(address source, address indexer) public view returns (uint256)

# getCommissionRateChangedEra

function getCommissionRateChangedEra(address indexer) public view returns (uint256)

# getPendingStakeChangeLength

function getPendingStakeChangeLength(address indexer) public view returns (uint256)

# getPendingStaker

function getPendingStaker(address indexer, uint256 i) public view returns (address)