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

Revert if prize has already been claimed #100

Merged
merged 1 commit into from Mar 21, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/PrizePool.sol
Expand Up @@ -52,6 +52,13 @@ error InsufficientRewardsError(uint256 requested, uint256 available);
/// @param prizeIndex The prize index
error DidNotWin(address vault, address winner, uint8 tier, uint32 prizeIndex);

/// @notice Emitted when the prize being claimed has already been claimed
/// @param vault The vault address
/// @param winner The address checked for the prize
/// @param tier The prize tier
/// @param prizeIndex The prize index
error AlreadyClaimed(address vault, address winner, uint8 tier, uint32 prizeIndex);

/// @notice Emitted when the claim reward exceeds the maximum.
/// @param reward The reward being claimed
/// @param maxReward The max reward that can be claimed
Expand Down Expand Up @@ -510,7 +517,7 @@ contract PrizePool is TieredLiquidityDistributor {
}

if (_claimedPrizes[msg.sender][_winner][lastAwardedDrawId_][_tier][_prizeIndex]) {
return 0;
revert AlreadyClaimed(msg.sender, _winner, _tier, _prizeIndex);
}

_claimedPrizes[msg.sender][_winner][lastAwardedDrawId_][_tier][_prizeIndex] = true;
Expand Down
6 changes: 4 additions & 2 deletions test/PrizePool.t.sol
Expand Up @@ -25,6 +25,7 @@ import {
DrawTimeoutGTGrandPrizePeriodDraws,
PrizePoolNotShutdown,
DidNotWin,
AlreadyClaimed,
RangeSizeZero,
RewardTooLarge,
ContributionGTDeltaBalance,
Expand Down Expand Up @@ -1294,8 +1295,9 @@ contract PrizePoolTest is Test {
mockTwab(address(this), msg.sender, 0);
uint256 prize = prizePool.getTierPrizeSize(0);
assertEq(claimPrize(msg.sender, 0, 0), prize, "prize size");
// second claim is zero
assertEq(claimPrize(msg.sender, 0, 0), 0, "no more prize");
// second claim reverts
vm.expectRevert(abi.encodeWithSelector(AlreadyClaimed.selector, address(this), msg.sender, 0, 0));
claimPrize(msg.sender, 0, 0);
}

function testComputeNextNumberOfTiers_zero() public {
Expand Down