From db52be36047f77fab609d280a4abe0235e3a668f Mon Sep 17 00:00:00 2001 From: Shahul Hameed <10547529+shahthepro@users.noreply.github.com> Date: Wed, 24 Apr 2024 20:49:29 +0530 Subject: [PATCH] Remove casting --- contracts/FixedRateRewardsSource.sol | 12 ++++-------- tests/staking/FixedRateRewardsSource.t.sol | 6 ------ 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/contracts/FixedRateRewardsSource.sol b/contracts/FixedRateRewardsSource.sol index 8ffd19c8..2c51f4d4 100644 --- a/contracts/FixedRateRewardsSource.sol +++ b/contracts/FixedRateRewardsSource.sol @@ -47,7 +47,7 @@ contract FixedRateRewardsSource is Governable, Initializable { /// @param _strategistAddr Address of the Strategist /// @param _rewardsTarget Address that receives rewards /// @param _rewardsPerSecond Rate of reward emission - function initialize(address _strategistAddr, address _rewardsTarget, uint256 _rewardsPerSecond) + function initialize(address _strategistAddr, address _rewardsTarget, uint192 _rewardsPerSecond) external initializer { @@ -121,20 +121,16 @@ contract FixedRateRewardsSource is Governable, Initializable { /// @dev Set the rate of reward emission /// @param _rewardsPerSecond Amount of rewardToken to distribute per second - function setRewardsPerSecond(uint256 _rewardsPerSecond) external onlyGovernorOrStrategist { + function setRewardsPerSecond(uint192 _rewardsPerSecond) external onlyGovernorOrStrategist { _setRewardsPerSecond(_rewardsPerSecond); } /// @dev Set the rate of reward emission /// @param _rewardsPerSecond Amount of rewardToken to distribute per second - function _setRewardsPerSecond(uint256 _rewardsPerSecond) internal { - if (_rewardsPerSecond > type(uint192).max) { - revert InvalidRewardRate(); - } - + function _setRewardsPerSecond(uint192 _rewardsPerSecond) internal { // Update storage RewardConfig storage _config = rewardConfig; emit RewardsPerSecondChanged(_rewardsPerSecond, _config.rewardsPerSecond); - _config.rewardsPerSecond = uint192(_rewardsPerSecond); + _config.rewardsPerSecond = _rewardsPerSecond; } } diff --git a/tests/staking/FixedRateRewardsSource.t.sol b/tests/staking/FixedRateRewardsSource.t.sol index 91373da9..fce7c11b 100644 --- a/tests/staking/FixedRateRewardsSource.t.sol +++ b/tests/staking/FixedRateRewardsSource.t.sol @@ -100,12 +100,6 @@ contract FixedRateRewardsSourceTest is Test { assertEq(rewards.previewRewards(), 0 ether, "Pending reward mismatch"); } - function testInvalidRewardRate() public { - vm.prank(strategist); - vm.expectRevert(bytes4(keccak256("InvalidRewardRate()"))); - rewards.setRewardsPerSecond(type(uint256).max); - } - function testRewardRatePermission() public { // Should allow Strategist to change vm.prank(strategist);