LiquidationPool::empty
excludes holder with pending stakes when decreasing a position, resulting in exclusion from asset distributionHigh Risk
https://github.com/Cyfrin/2023-12-the-standard/blob/91132936cb09ef9bf82f38ab1106346e2ad60f91/contracts/LiquidationPool.sol#L92-L94
If a holder has withdrawn from a previous consolidated position but still has pending stakes eligible for consolidation, they will not be included in the asset distribution. This is due to their prior exclusion from the LiquidationPool.holder
array through LiquidationPool::deletePosition
, given that the position will be considered as empty when position.TST == 0 && position.EUROs == 0
.
Pending stakes that are consolidated during asset distribution will be excluded from rewards if there is no previous consolidated position due to a prior complete withdrawal, leading to wrong asset distribution when a liquidation occurs
LiquidationPool.pendingStake
array.Lost of unclaimed yield
When decreasing a position, verify if there is a pending stake from the same holder. If there is, do not exclude the holder from holders
array. This means:
function empty(Position memory _position) private pure returns (bool) {
if (_position.TST == 0 && _position.EUROs == 0){
address positionHolder = _position.holder;
uint256 pendingStakesLen = pendingStakes.length();
for(uint i; i < pendingStakesLen;){
if(pendingStakes[i].holder == positionHolder){
return false;
}
unchecked{ ++i};
}
return true;
}else{
return false;
}
}