FeeConfig
Overview
The FeeConfig
contract is a configuration module used within the protocol to manage and enforce protocol-level fees. It enables fine-grained control over fee application logic across different operations and protocol participants.
This contract is deployed on-chain and is designed to be upgradeable. It provides both default and customizable fee structures, allowing the protocol to charge fees for specific actions (such as withdrawals or reward claims) and route them to a designated treasury address.
Key Features
Precision-based fee system: all fees are calculated using a precision constant (
PRECISION
) equal to 1025, which represents 100%. For example,0.05*10^25
is equivalent to 5%.Default and custom fees: allows setting a global base fee, operation-specific base fees, sender-specific custom fees, and operation-specific custom fees per sender.
Treasury routing: all collected fees are directed to a treasury address, which can be updated by the protocol owner.
Access control: only the contract owner (protocol administrator) can set or update fee configurations, ensuring controlled and secure modifications.
Write functions
FeeConfig_init
Initializes the contract with essential parameters and configuration contracts. This function must be called once after deployment.
function FeeConfig_init(
address treasury_,
uint256 baseFee_
) external initializer
treasury_
Address of the new treasury.
baseFee_
The base fee value (must be less than PRECISION). Where 100% = 1025.
setTreasury
Updates the treasury address.
function setTreasury(address treasury_) public onlyOwner
treasury_
Address of the new treasury.
Set and receive base (default) fee for the caller
setBaseFee
Sets the global base (default) fee for all callers. Only for the contract owner.
function setBaseFee(uint256 baseFee_) public onlyOwner
baseFee_
The base fee value (must be less than PRECISION). Where 100% = 1025.
setFee
Sets the fee for the specific callers. Only for the contract owner.
function setFee(address sender_, uint256 fee_) external onlyOwner
sender_
The address for which to query fee.
fee_
The base fee value (must be less than PRECISION). Where 100% = 1025.
getFeeAndTreasury
Returns the fee for the caller or base fee (if caller fee isn't set), treasury address for a sender (contract).
function getFeeAndTreasury(address sender_) external view returns (uint256, address)
sender_
The address for which to query fee.
Set and receive operation fee for the caller
setBaseFeeForOperation
Sets the base fee for a specific operation across the protocol. Only for the contract owner.
function setBaseFeeForOperation(
bytes32 operation_,
uint256 baseFeeForOperation_
) public onlyOwner
operation_
Operation identifier.
baseFeeForOperation_
The base fee for this operation (must be less than PRECISION). Where 100% = 1025.
setFeeForOperation
Sets the fee for a specific operation across the protocol for the specific caller. Only for the contract owner.
function setFeeForOperation(
address sender_,
bytes32 operation_,
uint256 fee_
) external onlyOwner
operation_
Operation identifier.
baseFeeForOperation_
The base fee for this operation (must be less than PRECISION). Where 100% = 1025
sender_
The address for which to query fee.
discardCustomFee
Removes custom fee override for an operation for a specific caller.
function discardCustomFee(
address sender_,
bytes32 operation_
) external onlyOwner
sender_
Address for which the custom fee is being discarded
operation_
Operation identifier (e.g., "claim"
or "withdraw"
)
getFeeAndTreasuryForOperation
Returns the fee for a specific operation or base fee for a specific operation (if fee for a specific operation isn't set) and treasury address.
function getFeeAndTreasuryForOperation(
address sender_,
bytes32 operation_
) external view returns (uint256, address)
sender_
Address requesting the operation
operation_
Operation for which to retrieve the fee and treasury address
Read functions
supportsInterface
Used for interface detection (ERC165). Returns true if the contract supports a specific interfaceId_
. Supports IFeeConfig
, IERC165
.
function supportsInterface(bytes4 interfaceId_) external pure returns (bool)
Last updated
Was this helpful?