Skip to content

Commit

Permalink
Merge pull request #117 from GenerationSoftware/gen-1768-28-drawtimeo…
Browse files Browse the repository at this point in the history
…utat-is-one-draw-early-compared-to-what-the

Enforce minimum draw timeout and clarify natspec
  • Loading branch information
trmid committed Jun 28, 2024
2 parents 1338ae0 + ddf87b3 commit 71cec5d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
19 changes: 14 additions & 5 deletions src/PrizePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ import { DrawAccumulatorLib, Observation, MAX_OBSERVATION_CARDINALITY } from "./
import { TieredLiquidityDistributor, Tier } from "./abstract/TieredLiquidityDistributor.sol";
import { TierCalculationLib } from "./libraries/TierCalculationLib.sol";

/* ============ Constants ============ */

// The minimum draw timeout. A timeout of two is necessary to allow for enough time to close and award a draw.
uint24 constant MINIMUM_DRAW_TIMEOUT = 2;

/* ============ Errors ============ */

/// @notice Thrown when the prize pool is constructed with a first draw open timestamp that is in the past
error FirstDrawOpensInPast();

Expand Down Expand Up @@ -89,8 +96,10 @@ error InvalidPrizeIndex(uint32 invalidPrizeIndex, uint32 prizeCount, uint8 tier)
/// @notice Thrown when there are no awarded draws when a computation requires an awarded draw.
error NoDrawsAwarded();

/// @notice Thrown when the Prize Pool is constructed with a draw timeout of zero
error DrawTimeoutIsZero();
/// @notice Thrown when the prize pool is initialized with a draw timeout lower than the minimum.
/// @param drawTimeout The draw timeout that was set
/// @param minimumDrawTimeout The minimum draw timeout
error DrawTimeoutLtMinimum(uint24 drawTimeout, uint24 minimumDrawTimeout);

/// @notice Thrown when the Prize Pool is constructed with a draw timeout greater than the grand prize period draws
error DrawTimeoutGTGrandPrizePeriodDraws();
Expand Down Expand Up @@ -280,7 +289,7 @@ contract PrizePool is TieredLiquidityDistributor {
/// @notice The timestamp at which the first draw will open.
uint48 public immutable firstDrawOpensAt;

/// @notice The maximum number of draws that can be missed before the prize pool is considered inactive.
/// @notice The maximum number of draws that can pass since the last awarded draw before the prize pool is considered inactive.
uint24 public immutable drawTimeout;

/// @notice The address that is allowed to set the draw manager
Expand Down Expand Up @@ -335,8 +344,8 @@ contract PrizePool is TieredLiquidityDistributor {
params.grandPrizePeriodDraws
)
{
if (params.drawTimeout == 0) {
revert DrawTimeoutIsZero();
if (params.drawTimeout < MINIMUM_DRAW_TIMEOUT) {
revert DrawTimeoutLtMinimum(params.drawTimeout, MINIMUM_DRAW_TIMEOUT);
}

if (params.drawTimeout > params.grandPrizePeriodDraws) {
Expand Down
16 changes: 13 additions & 3 deletions test/PrizePool.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import {
PrizeIsZero,
ConstructorParams,
InsufficientRewardsError,
DrawTimeoutIsZero,
DrawTimeoutLtMinimum,
MINIMUM_DRAW_TIMEOUT,
DrawTimeoutGTGrandPrizePeriodDraws,
PrizePoolNotShutdown,
DidNotWin,
Expand Down Expand Up @@ -160,9 +161,18 @@ contract PrizePoolTest is Test {
assertEq(prizePool.drawPeriodSeconds(), drawPeriodSeconds);
}

function testDrawTimeoutIsZero() public {
function testDrawTimeoutLtMinimum() public {
params.drawTimeout = 0;
vm.expectRevert(abi.encodeWithSelector(DrawTimeoutIsZero.selector));
vm.expectRevert(abi.encodeWithSelector(DrawTimeoutLtMinimum.selector, 0, 2));
new PrizePool(params);

params.drawTimeout = 1;
vm.expectRevert(abi.encodeWithSelector(DrawTimeoutLtMinimum.selector, 1, 2));
new PrizePool(params);

assertEq(MINIMUM_DRAW_TIMEOUT, 2); // validate assumptions
params.drawTimeout = 2;
// no revert
new PrizePool(params);
}

Expand Down

0 comments on commit 71cec5d

Please sign in to comment.