Integrate a Usage Fee

As previously established, a Usage Fee can be either a static fee (a burn fee or a transfer fee) or a percentage fee.

In either case, the fee payment logic must be inserted into the model contract according to the business logic of your contract.

So, when you code your model contract according to these guidelines, you have to keep in mind to code your Usage Fees logics.

This example shows the Fees logic of the Covenants Farming contract cloned by the Farming Factory, implementing the EthereansFactory contract.

You should use it as a guideline to adapt to your Fees system.

Usage Fee Integration Example

The Covenants Farming Factory implements the EthereansFactory utility contract. In this way, the Farming model contract can have Usage Fees inside.

In particular, when a farmer withdraws his liquidity he can choose to:

  • pay the static burn usage fee -> it interacts with the burnOrTransferTokenAmount of the EthereansFactory

  • pay the percentage usage fee -> it interacts with the payFee of the EthereansFactory

if(feeAmount0 > 0 || feeAmount1 > 0) {
    if(burnData.length == 0) {
        dfoFee0 = feeAmount0 == 0 ? 0 : _payFee(token0, feeAmount0);
        dfoFee1 = feeAmount1 == 0 ? 0 : _payFee(token1, feeAmount1);
    } else {

function _payFee(address tokenAddress, uint256 feeAmount) private returns (uint256) {
    if(tokenAddress != address(0)) {
        _safeApprove(tokenAddress, IFarmFactory(initializer).initializer(), feeAmount);
    return IFarmFactory(initializer).payFee{value : tokenAddress != address(0) ? 0 : feeAmount}(address(this), tokenAddress, feeAmount, "");

function _burnFee(bytes memory burnData) private returns (uint256) {
    (, burnData) = abi.decode(burnData, (bool, bytes));
    return IFarmFactory(initializer).burnOrTransferToken(msg.sender, burnData);

Last updated