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

Add FeeDistributorBALClaimer contract #1212

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "@balancer-labs/v2-standalone-utils/contracts/interfaces/IBALTokenHolder.sol";
TomAFrench marked this conversation as resolved.
Show resolved Hide resolved

import "../interfaces/IFeeDistributor.sol";
import "../interfaces/ISingleRecipientGauge.sol";

/**
* @title FeeDistributorBALClaimer
* @notice Atomically mints any outstanding BAL from a SingleRecipientGauge and transfers it to the FeeDistributor
* in order for it to be distributed among veBAL holders.
*/
contract FeeDistributorBALClaimer {
IERC20 private immutable _balToken;
IAuthorizerAdaptor private immutable _authorizerAdaptor;
IFeeDistributor private immutable _feeDistributor;
ISingleRecipientGauge private immutable _gauge;
IBALTokenHolder private immutable _balTokenHolder;

constructor(
IFeeDistributor feeDistributor,
ISingleRecipientGauge gauge,
IAuthorizerAdaptor authorizerAdaptor
) {
IBALTokenHolder balTokenHolder = IBALTokenHolder(gauge.getRecipient());

_balToken = balTokenHolder.getBalancerToken();
_authorizerAdaptor = authorizerAdaptor;
_feeDistributor = feeDistributor;
_gauge = gauge;
_balTokenHolder = balTokenHolder;
}

/**
* @notice Returns the address of the Balancer token contract.
*/
function getBalancerToken() external view returns (IERC20) {
return _balToken;
}

/**
* @notice Returns the address of the AuthorizerAdaptor contract.
*/
function getAuthorizerAdaptor() external view returns (IAuthorizerAdaptor) {
return _authorizerAdaptor;
}

/**
* @notice Returns the address of the FeeDistributor contract.
*/
function getFeeDistributor() external view returns (IFeeDistributor) {
return _feeDistributor;
}

/**
* @notice Returns the address of the associated SingleRecipientGauge contract.
*/
function getGauge() external view returns (ISingleRecipientGauge) {
return _gauge;
}

/**
* @notice Returns the address of the associated BALTokenHolder contract.
*/
function getBALTokenHolder() external view returns (IBALTokenHolder) {
return _balTokenHolder;
}

/**
* @notice Mint any outstanding BAL emissions and send them to the FeeDistributor
TomAFrench marked this conversation as resolved.
Show resolved Hide resolved
* @dev In order to call this function the `FeeDistributorBALClaimer` must be authorized to:
* - Withdraw BAL from the linked BALTokenHolder
* - Checkpoint the associated SingleRecipientGauge in order to mint BAL.
*/
function distributeBAL() external {
_checkpointGauge(_gauge);
_balTokenHolder.withdrawFunds(address(_feeDistributor), _balToken.balanceOf(address(_balTokenHolder)));
_feeDistributor.checkpointToken(_balToken);
nventuro marked this conversation as resolved.
Show resolved Hide resolved
}

function _checkpointGauge(IStakelessGauge gauge) private {
_authorizerAdaptor.performAction(address(gauge), abi.encodeWithSelector(IStakelessGauge.checkpoint.selector));
}
}
6 changes: 3 additions & 3 deletions pkg/liquidity-mining/contracts/gauges/StakelessGauge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/ReentrancyGuard.
import "../interfaces/IBalancerMinter.sol";
import "../interfaces/IBalancerTokenAdmin.sol";
import "../interfaces/IGaugeController.sol";
import "../interfaces/ILiquidityGauge.sol";
import "../interfaces/IStakelessGauge.sol";

abstract contract StakelessGauge is ILiquidityGauge, ReentrancyGuard {
abstract contract StakelessGauge is IStakelessGauge, ReentrancyGuard {
IERC20 internal immutable _balToken;
IBalancerTokenAdmin private immutable _tokenAdmin;
IBalancerMinter private immutable _minter;
Expand Down Expand Up @@ -78,7 +78,7 @@ abstract contract StakelessGauge is ILiquidityGauge, ReentrancyGuard {
_startEpochTime = _tokenAdmin.startEpochTimeWrite();
}

function checkpoint() external payable nonReentrant returns (bool) {
function checkpoint() external payable override nonReentrant returns (bool) {
require(msg.sender == address(_authorizerAdaptor), "SENDER_NOT_ALLOWED");
uint256 lastPeriod = _period;
uint256 currentPeriod = _currentPeriod();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

pragma solidity ^0.7.0;

import "./ILiquidityGauge.sol";
import "./IStakelessGauge.sol";

interface ISingleRecipientGauge is ILiquidityGauge {
interface ISingleRecipientGauge is IStakelessGauge {
function initialize(address recipient) external;

function getRecipient() external view returns (address);
Expand Down
21 changes: 21 additions & 0 deletions pkg/liquidity-mining/contracts/interfaces/IStakelessGauge.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

pragma solidity ^0.7.0;

import "./ILiquidityGauge.sol";

interface IStakelessGauge is ILiquidityGauge {
function checkpoint() external payable returns (bool);
}
3 changes: 1 addition & 2 deletions pkg/standalone-utils/contracts/BALTokenHolder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import "@balancer-labs/v2-solidity-utils/contracts/helpers/Authentication.sol";
import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/SafeERC20.sol";

import "@balancer-labs/v2-vault/contracts/interfaces/IVault.sol";
import "@balancer-labs/v2-liquidity-mining/contracts/interfaces/IBalancerToken.sol";

import "./interfaces/IBALTokenHolder.sol";

Expand Down Expand Up @@ -51,7 +50,7 @@ contract BALTokenHolder is IBALTokenHolder, Authentication {
_name = name;
}

function getBalancerToken() external view returns (IBalancerToken) {
function getBalancerToken() external view override returns (IBalancerToken) {
return _balancerToken;
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/standalone-utils/contracts/interfaces/IBALTokenHolder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ pragma solidity ^0.7.0;

import "@balancer-labs/v2-solidity-utils/contracts/helpers/IAuthentication.sol";
import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/IERC20.sol";
import "@balancer-labs/v2-liquidity-mining/contracts/interfaces/IBalancerToken.sol";

interface IBALTokenHolder is IAuthentication {
function getBalancerToken() external view returns (IBalancerToken);

function withdrawFunds(address recipient, uint256 amount) external;

function sweepTokens(
Expand Down
6 changes: 1 addition & 5 deletions pkg/standalone-utils/contracts/test/MockUnbuttonERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ contract MockUnbuttonERC20 is ERC20, IButtonWrapper {

function initialize(uint256 initialRate) public {
uint256 mintAmount = INITIAL_DEPOSIT * initialRate;
IERC20(_underlying).safeTransferFrom(
msg.sender,
address(this),
INITIAL_DEPOSIT
);
IERC20(_underlying).safeTransferFrom(msg.sender, address(this), INITIAL_DEPOSIT);
_mint(address(this), mintAmount);
}

Expand Down