Skip to content

Align shutdown timestamp to draw period #116

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

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
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
Loading