Skip to content

Commit

Permalink
Add external/public functions in the main meta swap contract
Browse files Browse the repository at this point in the history
  • Loading branch information
penandlim committed Dec 5, 2022
1 parent 39aa197 commit 8ade918
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 2 additions & 0 deletions contracts/interfaces/IGauge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ interface IGauge {
function SDL() external view returns (address);

function FACTORY() external view returns (address);

function set_rewards_receiver(address) external;
}
10 changes: 10 additions & 0 deletions contracts/meta/MetaSwapGaugeSupportV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -450,4 +450,14 @@ contract MetaSwapGaugeSupportV1 is SwapV2, GaugeTokenHolder {
maxBurnAmount
);
}

/**
* @notice Sets the reward receiver for the gauge rewards.
* @param _rewardReceiver the address to receive the gauge rewards
* @dev Both the SDL gauge reward and the third party rewards will be
* forwarded to this address.
*/
function setRewardReceiver(address _rewardReceiver) external onlyOwner {
GaugeTokenHolder._setRewardReceiver(_rewardReceiver);
}
}
15 changes: 14 additions & 1 deletion contracts/xchainGauges/GaugeTokenHolder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ abstract contract GaugeTokenHolder {
/// If a rewardReceiver is set, the reward token is forwarded to the
/// rewardReceiver. Otherwise, the reward token is kept.
function _claim() internal {
address _gaugeToken = gaugeToken;
require(_gaugeToken != address(0), "gaugeToken address not set");

address _rewardToken = rewardToken;
address _minter = minter;

Expand All @@ -58,17 +61,27 @@ abstract contract GaugeTokenHolder {
uint256 amount = IERC20(_rewardToken).balanceOf(address(this));
emit Claimed(amount);

// If a rewardReceiver is set, forward the reward token to the rewardReceiver
address _rewardReceiver = rewardReceiver;

if (_rewardReceiver != address(0)) {
IERC20(_rewardToken).safeTransfer(_rewardReceiver, amount);
emit Forwarded(_rewardReceiver, amount);
}
}

/// @notice Claim the reward token from the associated Minter contract.
/// If a rewardReceiver is set, the reward token is forwarded to the
/// rewardReceiver. Otherwise, the reward token is kept.
function claimGaugeRewards() public virtual {
_claim();
}

function _setRewardReceiver(address _rewardReceiver) internal {
address oldRewardReceiver = rewardReceiver;
rewardReceiver = _rewardReceiver;
emit RewardReceiverUpdated(oldRewardReceiver, _rewardReceiver);

// Set reward receiver for the gauge's third party rewards as well
IGauge(gaugeToken).set_rewards_receiver(_rewardReceiver);
}
}

0 comments on commit 8ade918

Please sign in to comment.