Skip to content

Commit

Permalink
Merge pull request #116 from GenerationSoftware/gen-1775-133-force-al…
Browse files Browse the repository at this point in the history
…ign-prize-pool-shutdown-time-to-start-of-draw

Align shutdown timestamp to draw period
  • Loading branch information
trmid committed Jun 28, 2024
2 parents bf073c3 + 6d57310 commit 1338ae0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/PrizePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ contract PrizePool is TieredLiquidityDistributor {
/// @notice Returns the timestamp at which the prize pool will be considered inactive and shutdown
/// @return The timestamp at which the prize pool will be considered inactive
function shutdownAt() public view returns (uint256) {
uint256 twabShutdownAt = twabController.lastObservationAt();
uint256 twabShutdownAt = drawOpensAt(getDrawId(twabController.lastObservationAt()));
uint256 drawTimeoutAt_ = drawTimeoutAt();
return drawTimeoutAt_ < twabShutdownAt ? drawTimeoutAt_ : twabShutdownAt;
}
Expand Down
30 changes: 28 additions & 2 deletions test/PrizePool.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -649,19 +649,45 @@ contract PrizePoolTest is Test {
}

function testAwardDraw_twabShutdown() public {
vm.warp(prizePool.drawClosesAt(1)); // warp to end of draw 1
vm.mockCall(
address(twabController),
abi.encodeWithSelector(twabController.lastObservationAt.selector),
abi.encode(true)
abi.encode(block.timestamp + 5) // not aligned with draw period (TWAB shutdown is 5 seconds into this draw)
);
vm.expectRevert(
abi.encodeWithSelector(
PrizePoolShutdown.selector
PrizePoolShutdown.selector // prize pool will truncate the TWAB shutdown with the draw period and will shutdown
)
);
prizePool.awardDraw(winningRandomNumber);
}

function testShutdownAt_twabShutdown() public {
vm.warp(prizePool.drawClosesAt(1)); // warp to end of draw 1

vm.mockCall(
address(twabController),
abi.encodeWithSelector(twabController.lastObservationAt.selector),
abi.encode(block.timestamp) // aligned with draw period
);
assertEq(prizePool.shutdownAt(), block.timestamp); // will be aligned with current time

vm.mockCall(
address(twabController),
abi.encodeWithSelector(twabController.lastObservationAt.selector),
abi.encode(block.timestamp - 5) // sometime in last draw period
);
assertEq(prizePool.shutdownAt(), block.timestamp - prizePool.drawPeriodSeconds()); // will be aligned with start of last draw

vm.mockCall(
address(twabController),
abi.encodeWithSelector(twabController.lastObservationAt.selector),
abi.encode(block.timestamp + 5) // sometime in next draw period
);
assertEq(prizePool.shutdownAt(), block.timestamp); // will be aligned with current draw open time (last draw close time)
}

function testAwardDraw_emittedDrawIdSameAsReturnedDrawId() public {
contribute(510e18);
uint24 expectedDrawId = 1;
Expand Down

0 comments on commit 1338ae0

Please sign in to comment.