Skip to content

Commit

Permalink
skip transfer if leaving rewards in prize pool
Browse files Browse the repository at this point in the history
  • Loading branch information
trmid committed Apr 5, 2024
1 parent 19ffd4d commit 8b86ed1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/PrizePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,10 @@ contract PrizePool is TieredLiquidityDistributor {
_totalWithdrawn = SafeCast.toUint128(_totalWithdrawn + _amount);
_totalRewardsToBeClaimed = SafeCast.toUint104(_totalRewardsToBeClaimed - _amount);

prizeToken.safeTransfer(_to, _amount);
// skip transfer if recipient is the prize pool (tokens stay in this contract)
if (_to != address(this)) {
prizeToken.safeTransfer(_to, _amount);
}

emit WithdrawRewards(msg.sender, _to, _amount, _available);
}
Expand Down
10 changes: 10 additions & 0 deletions test/PrizePool.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1579,6 +1579,16 @@ contract PrizePoolTest is Test {
prizePool.withdrawRewards(address(1), 5e17);
}

function testWithdrawRewards_transferToPrizePool() public {
contribute(100e18);
awardDraw(winningRandomNumber);
mockTwab(address(this), msg.sender, 0);
claimPrize(msg.sender, 0, 0, 1e18, address(this));
prizePool.withdrawRewards(address(prizePool), 1e18); // leave the tokens in the prize pool
assertEq(prizeToken.balanceOf(address(this)), 0);
assertEq(prizeToken.balanceOf(address(prizePool)) - prizePool.accountedBalance(), 1e18); // tokens are in prize pool
}

function testDrawToAward_zeroDraw() public {
// current time *is* lastAwardedDrawAwardedAt
assertEq(prizePool.getDrawIdToAward(), 1);
Expand Down

0 comments on commit 8b86ed1

Please sign in to comment.