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

Audit Fixes QS-13 #68

Merged
merged 3 commits into from
Jun 21, 2024
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: 2 additions & 0 deletions contracts/interfaces/IFarm.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ interface IFarm {

function setRewardRate(address _rwdToken, uint256[] memory _newRwdRates) external;

function recoverRewardFunds(address _rwdToken, uint256 _amount) external;

function rewardData(address _token) external view returns (RewardData memory);

function cooldownPeriod() external view returns (uint256);
Expand Down
9 changes: 9 additions & 0 deletions contracts/rewarder/Rewarder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,18 @@ contract Rewarder is Ownable, Initializable, ReentrancyGuard {
/// @param _farm Farm's address in which the token manager is to be updated.
/// @param _newManager Address of the new token manager.
function updateTokenManagerOfFarm(address _farm, address _newManager) external onlyOwner {
_validateNonZeroAddr(_farm);
IFarm(_farm).updateRewardData(REWARD_TOKEN, _newManager);
}

/// @notice Function to recover reward funds from the farm.
/// @param _farm Farm's address from which reward funds is to be recovered.
/// @param _amount Amount which is to be recovered.
function recoverRewardFundsOfFarm(address _farm, uint256 _amount) external onlyOwner {
_validateNonZeroAddr(_farm);
IFarm(_farm).recoverRewardFunds(REWARD_TOKEN, _amount);
}

/// @notice Function to update APR.
/// @param _farm Address of the farm.
/// @param _apr APR in 1e8 precision.
Expand Down
25 changes: 24 additions & 1 deletion test/rewarder/Rewarder.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {CamelotV2Farm} from "../../contracts/e721-farms/camelotV2/CamelotV2Farm.
import {RewarderFactory} from "../../contracts/rewarder/RewarderFactory.sol";
import {Rewarder, IERC20, ERC20} from "../../contracts/rewarder/Rewarder.sol";
import {IOracle} from "../../contracts/interfaces/IOracle.sol";
import {VmSafe} from "forge-std/Vm.sol";
import {Farm} from "./../../contracts/Farm.sol";

contract RewarderTest is CamelotV2FarmTest {
RewarderFactory public rewarderFactory;
Expand Down Expand Up @@ -56,6 +56,29 @@ contract TestUpdateTokenManagerOfFarm is RewarderTest {
}
}

contract TestRecoverRewardFundsOfFarm is RewarderTest {
uint256 public amount;

function test_RevertWhen_CallerIsNotTheOwner() public useKnownActor(actors[5]) {
vm.expectRevert(abi.encodeWithSelector(Ownable.OwnableUnauthorizedAccount.selector, actors[5]));
rewarder.recoverRewardFundsOfFarm(lockupFarm, amount);
}

function test_recoverRewardFundsOfFarm() public {
vm.prank(owner);
CamelotV2Farm(lockupFarm).updateRewardData(USDCe, address(rewarder));
uint256 balanceBefore = IERC20(USDCe).balanceOf(address(rewarder));
amount = 100 * 10 ** ERC20(USDCe).decimals();
deal(USDCe, lockupFarm, amount);
vm.expectEmit(true, true, true, true, lockupFarm);
emit Farm.FundsRecovered(address(rewarder), USDCe, amount);
vm.prank(rewardManager);
rewarder.recoverRewardFundsOfFarm(lockupFarm, amount);
uint256 balanceAfter = IERC20(USDCe).balanceOf(address(rewarder));
assertEq(balanceAfter - balanceBefore, amount);
}
}

contract TestUpdateAPR is RewarderTest {
uint256 private APR;

Expand Down
Loading