Fee Manager

Intro

The FeeManager contract is used to calculate and collect fees from various operations within the Blueberry protocol, such as depositing, withdrawing, and generating rewards. The contract is responsible for deducting fees from the relevant token amounts and transferring them to the designated treasury address.

Contract Overview

The FeeManager contract is implemented in Solidity programming language with version 0.8.16. It is imported with the OwnableUpgradeable and SafeERC20Upgradeable contracts from the OpenZeppelin library, which are used for access control and safe ERC20 token transfers, respectively.

The contract implements four public functions for cutting fees from token transactions: doCutDepositFee, doCutWithdrawFee, doCutRewardsFee, and doCutVaultWithdrawFee. Each function takes the relevant token address and amount as input parameters and calls the internal function _doCutFee to calculate and collect the fee.

Functions

initialize

function initialize(IProtocolConfig config_) external initializer

This function is an initializer function that sets the config variable, which is an interface to the main Blueberry protocol configuration contract. The function also uses the __Ownable_init() function from the OwnableUpgradeable contract to initialize the owner of the contract.

doCutDepositFee

function doCutDepositFee(address token, uint256 amount) external returns (uint256)

This function cuts the deposit fee from the specified token amount and transfers it to the treasury address. The fee rate is obtained from the config variable using the depositFee function. The function then returns the amount of the token after the fee has been deducted.

doCutWithdrawFee

function doCutWithdrawFee(address token, uint256 amount) external returns (uint256)

This function cuts the withdraw fee from the specified token amount and transfers it to the treasury address. The fee rate is obtained from the config variable using the withdrawFee function. The function then returns the amount of the token after the fee has been deducted.

doCutRewardsFee

function doCutRewardsFee(address token, uint256 amount) external returns (uint256)

This function cuts the performance fee from the specified token amount and transfers it to the treasury address. The fee rate is obtained from the config variable using the rewardFee function. The function then returns the amount of the token after the fee has been deducted.

doCutVaultWithdrawFee

function doCutVaultWithdrawFee(address token, uint256 amount) external returns (uint256)

This function cuts the withdraw fee from the specified token amount only if the withdraw transaction is executed within a given window of time (2 months). The fee rate is obtained from the config variable using the withdrawVaultFee function. The function then returns the amount of the token after the fee has been deducted, or the full amount if the withdraw transaction is executed outside the withdraw fee window.

_doCutFee

function _doCutFee(address token, uint256 amount, uint256 feeRate) internal returns (uint256)

This function is an internal function that cuts a fee from a specified token amount based on the given feeRate and transfers the fee amount to the treasury address. The function returns the amount of the token after the fee has been deducted.

Last updated