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

Low severity #5

Merged
merged 9 commits into from
Jun 11, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 3 additions & 10 deletions contracts/Bribes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/access/Ownable.sol";



interface IERC20Ext {
function name() external returns(string memory);
function symbol() external returns(string memory);
}

contract Bribe is ReentrancyGuard {
using SafeERC20 for IERC20;

Expand Down Expand Up @@ -184,10 +178,7 @@ contract Bribe is ReentrancyGuard {
uint256 _endTimestamp = IMinter(minter).active_period(); // claim until current epoch
uint256 _userLastTime = userTimestamp[_owner][_rewardToken];

if(_endTimestamp == _userLastTime){
return (0, _userLastTime);
}


// if user first time then set it to first bribe - week to avoid any timestamp problem
if(_userLastTime < firstBribeTimestamp){
_userLastTime = firstBribeTimestamp - WEEK;
Expand Down Expand Up @@ -414,9 +405,11 @@ contract Bribe is ReentrancyGuard {
}

/// @notice Set a new Owner
event SetOwner(address indexed _owner);
function setOwner(address _owner) external onlyAllowed {
require(_owner != address(0));
owner = _owner;
emit SetOwner(_owner);
}


Expand Down
32 changes: 21 additions & 11 deletions contracts/GaugeExtraRewarder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ contract GaugeExtraRewarder is Ownable {
/// @notice Info of each user.
struct UserInfo {
uint256 amount;
int256 rewardDebt;
uint256 rewardDebt;
}

/// @notice Struct of pool info

struct PoolInfo {
uint256 accRewardPerShare;
uint256 lastRewardTime;
Expand Down Expand Up @@ -67,16 +66,25 @@ contract GaugeExtraRewarder is Ownable {
}


function onReward(uint256 /*pid*/, address _user, address to, uint256 /*extraData*/, uint256 lpToken) onlyGauge external {
/// @notice Call onReward from gauge, it saves the new user balance and get any available reward
/// @param pid PID of the pool if used
/// @param _user user address
/// @param to where to send rewards
/// @param extraData extra data for future upgrade
/// @param lpToken the balance of LP in gauge
function onReward(uint256 pid, address _user, address to, uint256 extraData, uint256 lpToken) onlyGauge external {

PoolInfo memory pool = updatePool();
UserInfo storage user = userInfo[_user];
uint256 pending;
if (user.amount > 0) {

pending = _pendingReward(_user);

rewardToken.safeTransfer(to, pending);
}
user.amount = lpToken;
user.rewardDebt = int256(lpToken.mul(pool.accRewardPerShare) / ACC_TOKEN_PRECISION);
user.rewardDebt = (lpToken.mul(pool.accRewardPerShare) / ACC_TOKEN_PRECISION);
}


Expand Down Expand Up @@ -105,7 +113,7 @@ contract GaugeExtraRewarder is Ownable {
uint256 reward = time.mul(rewardPerSecond);
accRewardPerShare = accRewardPerShare.add( reward.mul(ACC_TOKEN_PRECISION) / lpSupply );
}
pending = int256( user.amount.mul(accRewardPerShare) / ACC_TOKEN_PRECISION ).sub(user.rewardDebt).toUInt256();
pending = ( user.amount.mul(accRewardPerShare) / ACC_TOKEN_PRECISION ).sub(user.rewardDebt);
}


Expand All @@ -116,11 +124,13 @@ contract GaugeExtraRewarder is Ownable {




/// @notice Set the distribution rate for a given distributePeriod. Rewards needs to be sent before calling setDistributionRate
function setDistributionRate(uint256 amount) public onlyOwner {
updatePool();
require(IERC20(rewardToken).balanceOf(address(this)) >= amount);
require(IERC20(rewardToken).balanceOf(address(this)) >= amount, "not enough");
uint256 notDistributed;
if (lastDistributedTime > 0 && block.timestamp < lastDistributedTime) {
if (block.timestamp < lastDistributedTime) {
uint256 timeLeft = lastDistributedTime.sub(block.timestamp);
notDistributed = rewardPerSecond.mul(timeLeft);
}
Expand Down Expand Up @@ -159,11 +169,11 @@ contract GaugeExtraRewarder is Ownable {
}
}


/// @notice Recover any ERC20 available
function recoverERC20(uint amount, address token) external onlyOwner {
require(amount > 0);
require(token != address(0));
require(IERC20(token).balanceOf(address(this)) >= amount);
require(amount > 0, "amount > 0");
require(token != address(0), "addr0");
require(IERC20(token).balanceOf(address(this)) >= amount, "not enough");
IERC20(token).safeTransfer(msg.sender, amount);
}

Expand Down
33 changes: 14 additions & 19 deletions contracts/GaugeV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ contract GaugeV2 is ReentrancyGuard, Ownable {
uint256 public lastUpdateTime;
uint256 public rewardPerTokenStored;

uint public fees0;
uint public fees1;

mapping(address => uint256) public userRewardPerTokenPaid;
mapping(address => uint256) public rewards;

Expand All @@ -61,6 +58,8 @@ contract GaugeV2 is ReentrancyGuard, Ownable {
event Withdraw(address indexed user, uint256 amount);
event Harvest(address indexed user, uint256 reward);
event ClaimFees(address indexed from, uint claimed0, uint claimed1);
event EmergencyActivated(address indexed gauge, uint timestamp);
event EmergencyDeactivated(address indexed gauge, uint timestamp);

modifier updateReward(address account) {
rewardPerTokenStored = rewardPerToken();
Expand All @@ -78,7 +77,7 @@ contract GaugeV2 is ReentrancyGuard, Ownable {
}

modifier isNotEmergency() {
require(emergency == false);
require(emergency == false, "emergency");
_;
}

Expand Down Expand Up @@ -135,13 +134,15 @@ contract GaugeV2 is ReentrancyGuard, Ownable {
}

function activateEmergencyMode() external onlyOwner {
require(emergency == false);
require(emergency == false, "emergency");
emergency = true;
emit EmergencyActivated(address(this), block.timestamp);
}

function stopEmergencyMode() external onlyOwner {
require(emergency == false);
require(emergency == false, "emergency");
emergency = false;
emit EmergencyDeactivated(address(this), block.timestamp);
}


Expand Down Expand Up @@ -257,7 +258,7 @@ contract GaugeV2 is ReentrancyGuard, Ownable {
}

function emergencyWithdraw() external nonReentrant {
require(emergency);
require(emergency, "emergency");
require(_balances[msg.sender] > 0, "no balances");
uint256 _amount = _balances[msg.sender];
_totalSupply = _totalSupply.sub(_amount);
Expand All @@ -266,7 +267,7 @@ contract GaugeV2 is ReentrancyGuard, Ownable {
emit Withdraw(msg.sender, _amount);
}
function emergencyWithdrawAmount(uint256 _amount) external nonReentrant {
require(emergency);
require(emergency, "emergency");
_totalSupply = _totalSupply.sub(_amount);
_balances[msg.sender] = _balances[msg.sender] - _amount;
TOKEN.safeTransfer(msg.sender, _amount);
Expand Down Expand Up @@ -326,7 +327,7 @@ contract GaugeV2 is ReentrancyGuard, Ownable {

/// @dev Receive rewards from distribution
function notifyRewardAmount(address token, uint reward) external nonReentrant isNotEmergency onlyDistribution updateReward(address(0)) {
require(token == address(rewardToken));
require(token == address(rewardToken), "not rew token");
rewardToken.safeTransferFrom(DISTRIBUTION, address(this), reward);

if (block.timestamp >= periodFinish) {
Expand Down Expand Up @@ -361,26 +362,20 @@ contract GaugeV2 is ReentrancyGuard, Ownable {
address _token = address(TOKEN);
(claimed0, claimed1) = IPair(_token).claimFees();
if (claimed0 > 0 || claimed1 > 0) {
uint _fees0 = fees0 + claimed0;
uint _fees1 = fees1 + claimed1;
uint _fees0 = claimed0;
uint _fees1 = claimed1;
(address _token0, address _token1) = IPair(_token).tokens();

if (_fees0 > 0) {
fees0 = 0;
IERC20(_token0).approve(internal_bribe, 0);
IERC20(_token0).approve(internal_bribe, _fees0);
IBribe(internal_bribe).notifyRewardAmount(_token0, _fees0);
} else {
fees0 = _fees0;
}
}
if (_fees1 > 0) {
fees1 = 0;
IERC20(_token1).approve(internal_bribe, 0);
IERC20(_token1).approve(internal_bribe, _fees1);
IBribe(internal_bribe).notifyRewardAmount(_token1, _fees1);
} else {
fees1 = _fees1;
}
}
emit ClaimFees(msg.sender, claimed0, claimed1);
}
}
Expand Down
27 changes: 9 additions & 18 deletions contracts/GaugeV2_CL.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ contract GaugeV2_CL is ReentrancyGuard, Ownable {
uint256 public lastUpdateTime;
uint256 public rewardPerTokenStored;

uint public fees0;
uint public fees1;

mapping(address => uint256) public userRewardPerTokenPaid;
mapping(address => uint256) public rewards;

Expand Down Expand Up @@ -146,12 +143,12 @@ contract GaugeV2_CL is ReentrancyGuard, Ownable {
}

function activateEmergencyMode() external onlyOwner {
require(emergency == false);
require(emergency == false, "emergency");
emergency = true;
}

function stopEmergencyMode() external onlyOwner {
require(emergency == false);
require(emergency == false, "emergency");
emergency = false;
}

Expand Down Expand Up @@ -268,7 +265,7 @@ contract GaugeV2_CL is ReentrancyGuard, Ownable {
}

function emergencyWithdraw() external nonReentrant {
require(emergency);
require(emergency, "emergency");
require(_balances[msg.sender] > 0, "no balances");

uint256 _amount = _balances[msg.sender];
Expand All @@ -280,7 +277,7 @@ contract GaugeV2_CL is ReentrancyGuard, Ownable {
}

function emergencyWithdrawAmount(uint256 _amount) external nonReentrant {
require(emergency);
require(emergency, "emergency");
require(_balances[msg.sender] >= _amount, "no balances");

_totalSupply = _totalSupply.sub(_amount);
Expand Down Expand Up @@ -342,7 +339,7 @@ contract GaugeV2_CL is ReentrancyGuard, Ownable {

/// @dev Receive rewards from distribution
function notifyRewardAmount(address token, uint reward) external nonReentrant isNotEmergency onlyDistribution updateReward(address(0)) {
require(token == address(rewardToken));
require(token == address(rewardToken), "not rew token");
rewardToken.safeTransferFrom(DISTRIBUTION, address(this), reward);

if (block.timestamp >= periodFinish) {
Expand Down Expand Up @@ -376,27 +373,21 @@ contract GaugeV2_CL is ReentrancyGuard, Ownable {
(claimed0, claimed1) = IFeeVault(feeVault).claimFees();

if (claimed0 > 0 || claimed1 > 0) {
uint _fees0 = fees0 + claimed0;
uint _fees1 = fees1 + claimed1;
uint _fees0 = claimed0;
uint _fees1 = claimed1;
(address _token0) = IPairInfo(_token).token0();
(address _token1) = IPairInfo(_token).token1();
if (_fees0 > 0) {
fees0 = 0;
IERC20(_token0).approve(internal_bribe, 0);
IERC20(_token0).approve(internal_bribe, _fees0);
IBribe(internal_bribe).notifyRewardAmount(_token0, _fees0);
} else {
fees0 = _fees0;
}
}

if (_fees1 > 0) {
fees1 = 0;
IERC20(_token1).approve(internal_bribe, 0);
IERC20(_token1).approve(internal_bribe, _fees1);
IBribe(internal_bribe).notifyRewardAmount(_token1, _fees1);
} else {
fees1 = _fees1;
}
}
emit ClaimFees(msg.sender, claimed0, claimed1);
}
}
Expand Down