require(_endRound <= currentRound, "end round must be before or equal to current round");
require(_endRound > del.lastClaimRound, "end round must be after last claim round");
The second require statement forces client devs to check a delegator's lastClaimRound before calling either function because otherwise the functions will return 0. The functions can be updated in the following way to eliminate the need for that check:
Note: This example is for pendingStake(), but the logical flow can be applied to pendingFees() as well.
// Rest of function...
if (_endRound > currentRound) {
// Highest round we can calculate up to is the current round
_endRound = currentRound;
}
uint256 currentBondedAmount = del.bondedAmount;
if (_endRound == del.lastClaimRound) {
// If the end round is equal to the last claim round then we can skip the calculations since
// since the delegator has claimed earnings through the end round already
return currentBondedAmount;
}
// Rest of function...
At the moment, BondingManager.pendingStake() and BondingManager.pendingFees() both revert if the following require statements fail:
The second require statement forces client devs to check a delegator's
lastClaimRound
before calling either function because otherwise the functions will return 0. The functions can be updated in the following way to eliminate the need for that check:Note: This example is for
pendingStake()
, but the logical flow can be applied topendingFees()
as well.