Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip transfer if leaving rewards in prize pool #107

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading