Skip to content

Commit e46f6b6

Browse files
committed
👷🏻 🧹Add _getLatestValueFromCheckpoints helper
1 parent d459697 commit e46f6b6

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

contracts/StakingRewardsV2.sol

+12-12
Original file line numberDiff line numberDiff line change
@@ -174,27 +174,27 @@ contract StakingRewardsV2 is
174174

175175
/// @inheritdoc IStakingRewardsV2
176176
function totalSupply() public view returns (uint256) {
177-
uint256 length = totalSupplyCheckpoints.length;
178-
unchecked {
179-
return length == 0 ? 0 : totalSupplyCheckpoints[length - 1].value;
180-
}
177+
return _getLatestValueFromCheckpoints(totalSupplyCheckpoints);
181178
}
182179

183180
/// @inheritdoc IStakingRewardsV2
184181
function balanceOf(address _account) public view returns (uint256) {
185-
Checkpoint[] storage checkpoints = balancesCheckpoints[_account];
186-
uint256 length = checkpoints.length;
187-
unchecked {
188-
return length == 0 ? 0 : checkpoints[length - 1].value;
189-
}
182+
return _getLatestValueFromCheckpoints(balancesCheckpoints[_account]);
190183
}
191184

192185
/// @inheritdoc IStakingRewardsV2
193186
function escrowedBalanceOf(address _account) public view returns (uint256) {
194-
Checkpoint[] storage checkpoints = escrowedBalancesCheckpoints[_account];
195-
uint256 length = checkpoints.length;
187+
return _getLatestValueFromCheckpoints(escrowedBalancesCheckpoints[_account]);
188+
}
189+
190+
function _getLatestValueFromCheckpoints(Checkpoint[] storage _checkpoints)
191+
internal
192+
view
193+
returns (uint256)
194+
{
195+
uint256 length = _checkpoints.length;
196196
unchecked {
197-
return length == 0 ? 0 : checkpoints[length - 1].value;
197+
return length == 0 ? 0 : _checkpoints[length - 1].value;
198198
}
199199
}
200200

0 commit comments

Comments
 (0)