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

Updated DrawManager events to include reward #8

Merged
merged 2 commits into from Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
38 changes: 19 additions & 19 deletions src/DrawManager.sol
Expand Up @@ -121,26 +121,24 @@ contract DrawManager {
event DrawStarted(
address indexed sender,
address indexed recipient,
uint24 drawId,
uint32 rngRequestId,
uint48 elapsedTime
uint24 indexed drawId,
uint48 elapsedTime,
uint reward,
uint32 rngRequestId
);
Comment on lines 122 to 129
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing natspec updates


/// @notice Emitted when the finish draw is called
/// @param drawId The draw id
/// @param elapsedTime The amount of time that had elapsed between start draw and finish draw
/// @param startRecipient The recipient of the start rng auction reward
/// @param startReward The reward for the start rng auction
/// @param finishRecipient The recipient of the finish draw auction reward
/// @param finishReward The reward for the finish draw auction
/// @param recipient The recipient of the finish draw auction reward
/// @param reward The reward for the finish draw auction
/// @param remainingReserve The remaining reserve after the rewards have been allocated
event DrawFinished(
address indexed sender,
address indexed recipient,
uint24 indexed drawId,
uint elapsedTime,
address indexed startRecipient,
uint startReward,
address indexed finishRecipient,
uint finishReward,
uint48 elapsedTime,
uint reward,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing some natspec updates

uint remainingReserve
);

Expand Down Expand Up @@ -213,8 +211,8 @@ contract DrawManager {
if (lastRequest.drawId == drawId) revert AlreadyStartedDraw();
if (rng.requestedAtBlock(_rngRequestId) != block.number) revert RngRequestNotInSameBlock();

uint48 _auctionElapsedTimeSeconds = _elapsedTimeSinceDrawClosed(block.timestamp, closesAt);
if (_auctionElapsedTimeSeconds > auctionDuration) revert AuctionExpired();
uint48 auctionElapsedTimeSeconds = _elapsedTimeSinceDrawClosed(block.timestamp, closesAt);
if (auctionElapsedTimeSeconds > auctionDuration) revert AuctionExpired();

_lastStartDrawAuction = StartDrawAuction({
recipient: _rewardRecipient,
Expand All @@ -223,12 +221,15 @@ contract DrawManager {
rngRequestId: _rngRequestId
});

(uint[] memory rewards,) = computeRewards(auctionElapsedTimeSeconds, 0, prizePool.reserve() + prizePool.pendingReserveContributions());

emit DrawStarted(
msg.sender,
_rewardRecipient,
drawId,
_rngRequestId,
_auctionElapsedTimeSeconds
auctionElapsedTimeSeconds,
rewards[0],
_rngRequestId
);

return drawId;
Expand Down Expand Up @@ -293,11 +294,10 @@ contract DrawManager {
uint24 drawId = prizePool.awardDraw(randomNumber);

emit DrawFinished(
msg.sender,
_rewardRecipient,
drawId,
finishDrawElapsedTime,
startDrawAuction.recipient,
rewards[0],
_rewardRecipient,
rewards[1],
remainingReserve
);
Expand Down
29 changes: 14 additions & 15 deletions test/DrawManager.t.sol
Expand Up @@ -25,21 +25,22 @@ import {
} from "../src/DrawManager.sol";

contract DrawManagerTest is Test {

event DrawStarted(
address indexed sender,
address indexed recipient,
uint24 drawId,
uint32 rngRequestId,
uint48 elapsedTime
uint24 indexed drawId,
uint48 elapsedTime,
uint reward,
uint32 rngRequestId
);

event DrawFinished(
address indexed sender,
address indexed recipient,
uint24 indexed drawId,
uint elapsedTime,
address indexed startRecipient,
uint startReward,
address indexed finishRecipient,
uint finishReward,
uint48 elapsedTime,
uint reward,
uint remainingReserve
);

Expand Down Expand Up @@ -248,11 +249,10 @@ contract DrawManagerTest is Test {
mockFinishDraw(0x1234);
vm.expectEmit(true, true, true, true);
emit DrawFinished(
address(this),
bob,
1,
auctionTargetTime,
alice,
28,
bob,
199999999999999994,
1e18 - 199999999999999994 - 28
);
Expand All @@ -267,11 +267,10 @@ contract DrawManagerTest is Test {
mockFinishDraw(0x1234);
vm.expectEmit(true, true, true, true);
emit DrawFinished(
address(this),
bob,
1,
auctionTargetTime,
alice,
0,
bob,
0,
0
);
Expand Down Expand Up @@ -333,7 +332,7 @@ contract DrawManagerTest is Test {
mockReserve(1e18, 0);
mockRng(99, 0x1234);
vm.expectEmit(true, true, true, true);
emit DrawStarted(address(this), alice, 1, 99, 0);
emit DrawStarted(address(this), alice, 1, 0, 28, 99);
drawManager.startDraw(alice, 99);
}

Expand Down