This issue pertains to the gaps created when users call the unstake() function - as shown in excerpt below:
for (uint256 i = 0; i < stakerPool.length; i += 1) {
uint256 beneficiary = stakerStorage.getUserId(backer);
if (stakerPool[i] == beneficiary) {
delete stakerPool[i];
}
}
Since we don't particularly care about the order, and to introduce an aspect of randomness in the staker pool, when a user unstakes, we can take the last staker in the staker pool and move that staker's index to the index of the unstaked user.
for (uint256 i = 0; i < stakerPool.length; i += 1) {
uint256 beneficiary = stakerStorage.getUserId(backer);
if (stakerPool[i] == beneficiary) {
delete stakerPool[i];
if (stakerPool.length > 1 && i != (stakerPool.length - 1)) {
stakerPool[i] = stakerPool[stakerPool.length - 1];
stakerPool.pop();
}
}
}
This issue pertains to the gaps created when users call the
unstake()
function - as shown in excerpt below:Since we don't particularly care about the order, and to introduce an aspect of randomness in the staker pool, when a user unstakes, we can take the last staker in the staker pool and move that staker's index to the index of the unstaked user.