diff --git a/src/RewardsDistributor.sol b/src/RewardsDistributor.sol index 61e31b3..37bc9a9 100644 --- a/src/RewardsDistributor.sol +++ b/src/RewardsDistributor.sol @@ -1,6 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.26; +import {console} from "@forge-std/console.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import {Ownable2StepUpgradeable} from "@openzeppelin-upgradeable/contracts/access/Ownable2StepUpgradeable.sol"; @@ -78,12 +79,15 @@ contract RewardsDistributor is Ownable2StepUpgradeable, IRewardsDistributor { // difference in time since last update uint256 timeDelta = block.timestamp - rewardConfiguration.lastUpdate; + console.log("time-delta", timeDelta); + if (rewardConfiguration.emissionRate == 0 || timeDelta == 0) { // nothing to do return 0; } rewards = rewardConfiguration.emissionRate * timeDelta; + console.log("rewards", rewards); // update the last update timestamp rewardConfiguration.lastUpdate = block.timestamp; diff --git a/test/RewardsDistributor.t.sol b/test/RewardsDistributor.t.sol index 8da1fad..2140609 100644 --- a/test/RewardsDistributor.t.sol +++ b/test/RewardsDistributor.t.sol @@ -28,6 +28,8 @@ contract RewardsDistributorTest is Test { } function _jumpAhead(uint256 _seconds) public { + vm.assume(_seconds != 0); + _seconds = bound(_seconds, 1, 26 weeks); vm.warp(vm.getBlockTimestamp() + _seconds); } @@ -35,7 +37,7 @@ contract RewardsDistributorTest is Test { address receiver, uint256 emissionRate ) internal { - emissionRate = bound(emissionRate, 0, 1e18); + emissionRate = bound(emissionRate, 1, 1e18); rewardsDistributor.setRewardConfiguration(receiver, emissionRate); } } @@ -45,6 +47,8 @@ contract OwnableFunctions is RewardsDistributorTest { address _receiver, uint256 _emissionRate ) public { + vm.assume(_receiver != address(0)); + vm.expectEmit(); emit RewardsDistributor.RewardConfigurationSet( _receiver, @@ -57,6 +61,8 @@ contract OwnableFunctions is RewardsDistributorTest { address _receiver, uint256 _emissionRate ) public { + vm.assume(_receiver != address(0)); + rewardsDistributor.setRewardConfiguration(_receiver, _emissionRate); (uint256 emissionRate, ) = rewardsDistributor.rewardConfigurations( @@ -70,6 +76,8 @@ contract OwnableFunctions is RewardsDistributorTest { address _receiver, uint256 _emissionRate ) public { + vm.assume(_receiver != address(0)); + rewardsDistributor.setRewardConfiguration(_receiver, _emissionRate); (, uint256 lastUpdate) = rewardsDistributor.rewardConfigurations( @@ -156,6 +164,8 @@ contract OwnableFunctions is RewardsDistributorTest { } function testFuzz_WithdrawFunds(address _to, uint256 _amount) public { + vm.assume(_to != address(0)); + _amount = bound(_amount, 0, govToken.balanceOf(address(this))); govToken.transfer(address(rewardsDistributor), _amount); @@ -183,3 +193,15 @@ contract OwnableFunctions is RewardsDistributorTest { rewardsDistributor.withdrawFunds(_to, _amount); } } + +contract CollectRewards is RewardsDistributorTest { + // function testFuzz_CollectRewardsReturnsRewardAmount(address _receiver, uint256 _jump, uint256 _emisisonRate) public{ + // _setRewardConfiguration(_receiver, _emisisonRate); + // uint256 timestampBefore = vm.getBlockTimestamp(); + // _jumpAhead(_jump); + // uint256 expectedRewards = _emisisonRate * (block.timestamp - timestampBefore); + // vm.prank(_receiver); + // uint256 rewards = rewardsDistributor.collectRewards(); + // assertEq(rewards, expectedRewards); + // } +}