From 4460ab24bb7c47b4f461c55052cce741fbaa5a5b Mon Sep 17 00:00:00 2001 From: Brendan Asselstine Date: Thu, 21 Mar 2024 14:03:01 -0700 Subject: [PATCH 1/2] Updated DrawManager events to include reward --- src/DrawManager.sol | 38 +++++++++++++++++++------------------- test/DrawManager.t.sol | 29 ++++++++++++++--------------- 2 files changed, 33 insertions(+), 34 deletions(-) diff --git a/src/DrawManager.sol b/src/DrawManager.sol index 86889d6..0345964 100644 --- a/src/DrawManager.sol +++ b/src/DrawManager.sol @@ -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 ); /// @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, uint remainingReserve ); @@ -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, @@ -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; @@ -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 ); diff --git a/test/DrawManager.t.sol b/test/DrawManager.t.sol index 3e1030d..086026f 100644 --- a/test/DrawManager.t.sol +++ b/test/DrawManager.t.sol @@ -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 ); @@ -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 ); @@ -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 ); @@ -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); } From a6813aaedd5a9cb36c3e22ad84fc9cd6d347149f Mon Sep 17 00:00:00 2001 From: Brendan Asselstine Date: Thu, 21 Mar 2024 14:31:39 -0700 Subject: [PATCH 2/2] updated coverage to 100%, and added natspec --- .github/workflows/coverage.yml | 2 +- src/DrawManager.sol | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 3225192..0a5adf3 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -50,5 +50,5 @@ jobs: uses: zgosalvez/github-actions-report-lcov@v1.5.0 with: coverage-files: lcov.info - minimum-coverage: 90 + minimum-coverage: 100 github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/src/DrawManager.sol b/src/DrawManager.sol index 0345964..2dfec5b 100644 --- a/src/DrawManager.sol +++ b/src/DrawManager.sol @@ -116,8 +116,9 @@ contract DrawManager { /// @param sender The address that triggered the rng auction /// @param recipient The recipient of the auction reward /// @param drawId The draw id that this request is for - /// @param rngRequestId The RNGInterface request ID /// @param elapsedTime The amount of time that had elapsed when start draw was called + /// @param reward The reward for the start draw auction + /// @param rngRequestId The RNGInterface request ID event DrawStarted( address indexed sender, address indexed recipient, @@ -128,9 +129,10 @@ contract DrawManager { ); /// @notice Emitted when the finish draw is called + /// @param sender The address that triggered the finish draw auction + /// @param recipient The recipient of the finish draw auction reward /// @param drawId The draw id /// @param elapsedTime The amount of time that had elapsed between start draw and finish draw - /// @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(