This issue can lead to an under-distribution of the remaining rewards to claimants, leaving a portion of the funds locked in the contract. This is particularly critical in scenarios with many claimants, where the miscalculation could result in significant locked funds.
function testIncorrectClosure() public mintAndApproveTokens {
vm.startPrank(user);
ContestManager testConMan = ContestManager(conMan);
address testPot = testConMan.createContest(
testPlayers,
testRewards,
IERC20(weth),
testTotalRewards
);
testConMan.fundContest(0);
vm.stopPrank();
console.log("Initial Pot Balance: ", weth.balanceOf(address(testPot)));
uint256 numberOfClaimers = 5;
for (uint i; i < numberOfClaimers; i++) {
vm.prank(testPlayers[i]);
Pot(testPot).claimCut();
}
console.log(
"Pot Balance after Claim: ",
weth.balanceOf(address(testPot))
);
uint256 potBalance = weth.balanceOf(address(testPot));
vm.warp(block.timestamp + 100 days);
console.log(
"Owner Balance before Closure: ",
weth.balanceOf(address(user))
);
console.log(
"Player Balance before Closure: ",
weth.balanceOf(address(testPlayers[0]))
);
uint256 playerBalanceBeforeClosure = weth.balanceOf(
address(testPlayers[0])
);
console.log(
"ContestManager Balance before Closure: ",
weth.balanceOf(address(conMan))
);
vm.prank(user);
testConMan.closeContest(testPot);
console.log(
"Owner Balance after Closure: ",
weth.balanceOf(address(user))
);
console.log(
"ContestManager Balance after Closure: ",
weth.balanceOf(address(conMan))
);
console.log(
"Player Balance after Closure: ",
weth.balanceOf(testPlayers[0])
);
console.log(
"Expected Player Balance after Closure: ",
playerBalanceBeforeClosure +
((potBalance - (potBalance / 10)) / numberOfClaimers)
);
console.log("Pot Balance after Closure: ", weth.balanceOf(testPot));
console.log("Expected Pot Balance after Closure: 0");
assertEq(
weth.balanceOf(testPlayers[0]),
playerBalanceBeforeClosure +
((potBalance - (potBalance / 10)) / numberOfClaimers)
);
assertEq(weth.balanceOf(testPot), 0);
}
function closePot() external onlyOwner {
if (block.timestamp - i_deployedAt < 90 days) {
revert Pot__StillOpenForClaim();
}
if (remainingRewards > 0) {
uint256 managerCut = remainingRewards / managerCutPercent;
i_token.transfer(msg.sender, managerCut);
- uint256 claimantCut = (remainingRewards - managerCut) /
- i_players.length;
+ uint256 claimantCut = (remainingRewards - managerCut) /
+ claimants.length;
for (uint256 i = 0; i < claimants.length; i++) {
_transferReward(claimants[i], claimantCut);
}
}
}