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

Simplify ProtocolFeeSplitter inheritance #2129

Merged
merged 4 commits into from
Dec 13, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,4 @@ interface IProtocolFeeSplitter {
* @notice Returns the `ProtocolFeesWithdrawer`, used to withdraw funds from the `ProtocolFeesCollector`.
*/
function getProtocolFeesWithdrawer() external view returns (IProtocolFeesWithdrawer);

/**
* @notice Returns the address of the Balancer Vault.
*/
function getVault() external view returns (IVault);
}
31 changes: 6 additions & 25 deletions pkg/standalone-utils/contracts/ProtocolFeeSplitter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pragma solidity >=0.7.0 <0.9.0;
import "@balancer-labs/v2-interfaces/contracts/standalone-utils/IProtocolFeeSplitter.sol";
import "@balancer-labs/v2-interfaces/contracts/standalone-utils/IProtocolFeesWithdrawer.sol";
import "@balancer-labs/v2-interfaces/contracts/vault/IVault.sol";
import "@balancer-labs/v2-solidity-utils/contracts/helpers/Authentication.sol";
import "@balancer-labs/v2-solidity-utils/contracts/helpers/SingletonAuthentication.sol";
import "@balancer-labs/v2-solidity-utils/contracts/math/FixedPoint.sol";
import "@balancer-labs/v2-interfaces/contracts/vault/IProtocolFeesCollector.sol";

Expand All @@ -35,7 +35,7 @@ interface Pool {
* governance to prevent certain tokens (on a denyList) from being withdrawn. `collectFees` would fail if the BPT
* token were on this denyList.
*/
contract ProtocolFeeSplitter is IProtocolFeeSplitter, Authentication {
contract ProtocolFeeSplitter is IProtocolFeeSplitter, SingletonAuthentication {
using FixedPoint for uint256;

// All fee percentages are 18-decimal fixed point numbers.
Expand All @@ -44,9 +44,6 @@ contract ProtocolFeeSplitter is IProtocolFeeSplitter, Authentication {

IProtocolFeesWithdrawer private immutable _protocolFeesWithdrawer;

// Balancer vault
IVault private immutable _vault;

// The recipient of the DAO portion of the revenue share; e.g., the Balancer DAO treasury account.
address private _daoFundsRecipient;

Expand All @@ -65,13 +62,10 @@ contract ProtocolFeeSplitter is IProtocolFeeSplitter, Authentication {
mapping(bytes32 => RevenueShareSettings) private _poolSettings;

constructor(IProtocolFeesWithdrawer protocolFeesWithdrawer, address daoFundsRecipient)
// The ProtocolFeeSplitter is a singleton, so it simply uses its own address to disambiguate action
// identifiers.
Authentication(bytes32(uint256(address(this))))
SingletonAuthentication(protocolFeesWithdrawer.getProtocolFeesCollector().vault())
{
_protocolFeesWithdrawer = protocolFeesWithdrawer;
_daoFundsRecipient = daoFundsRecipient;
_vault = protocolFeesWithdrawer.getProtocolFeesCollector().vault();
}

// Fund recipients
Expand All @@ -90,7 +84,7 @@ contract ProtocolFeeSplitter is IProtocolFeeSplitter, Authentication {

/// @inheritdoc IProtocolFeeSplitter
function setPoolBeneficiary(bytes32 poolId, address newBeneficiary) external override {
(address pool, ) = _vault.getPool(poolId);
(address pool, ) = getVault().getPool(poolId);
_require(msg.sender == Pool(pool).getOwner(), Errors.SENDER_NOT_ALLOWED);

_poolSettings[poolId].beneficiary = newBeneficiary;
Expand Down Expand Up @@ -155,15 +149,15 @@ contract ProtocolFeeSplitter is IProtocolFeeSplitter, Authentication {

/// @inheritdoc IProtocolFeeSplitter
function getAmounts(bytes32 poolId) external view override returns (uint256 beneficiaryAmount, uint256 daoAmount) {
(address pool, ) = _vault.getPool(poolId);
(address pool, ) = getVault().getPool(poolId);
IERC20 bpt = IERC20(pool);

return _getAmounts(bpt, poolId);
}

/// @inheritdoc IProtocolFeeSplitter
function collectFees(bytes32 poolId) external override returns (uint256 beneficiaryAmount, uint256 daoAmount) {
(address pool, ) = _vault.getPool(poolId);
(address pool, ) = getVault().getPool(poolId);
IERC20 bpt = IERC20(pool);
address beneficiary = _poolSettings[poolId].beneficiary;

Expand All @@ -182,21 +176,8 @@ contract ProtocolFeeSplitter is IProtocolFeeSplitter, Authentication {
return _protocolFeesWithdrawer;
}

/// @inheritdoc IProtocolFeeSplitter
function getVault() external view override returns (IVault) {
return _vault;
}

// Internal functions

function _canPerform(bytes32 actionId, address account) internal view override returns (bool) {
return _getAuthorizer().canPerform(actionId, account, address(this));
}

function _getAuthorizer() internal view returns (IAuthorizer) {
return _protocolFeesWithdrawer.getProtocolFeesCollector().getAuthorizer();
}

function _withdrawBpt(
IERC20 bpt,
uint256 amount,
Expand Down