Skip to main content
The FeeCollector contract manages fee collection for both LiFi protocol fees and integrator fees. It tracks balances per integrator and token, and allows withdrawal of collected fees.

Functions

Fee Collection

collectTokenFees

Collects fees in ERC20 tokens from a transaction.
function collectTokenFees(
  tokenAddress: string,
  integratorFee: BigNumberish,
  lifiFee: BigNumberish,
  integratorAddress: string
): Promise<ContractTransaction>
tokenAddress
address
required
Address of the ERC20 token
integratorFee
uint256
required
Amount of tokens to collect as integrator fee
lifiFee
uint256
required
Amount of tokens to collect as LiFi protocol fee
integratorAddress
address
required
Address of the integrator to credit the fee to

collectNativeFees

Collects fees in native currency (ETH, MATIC, etc.).
function collectNativeFees(
  integratorFee: BigNumberish,
  lifiFee: BigNumberish,
  integratorAddress: string
): Promise<ContractTransaction>
integratorFee
uint256
required
Amount of native currency to collect as integrator fee
lifiFee
uint256
required
Amount of native currency to collect as LiFi protocol fee
integratorAddress
address
required
Address of the integrator to credit the fee to

Fee Withdrawal

withdrawIntegratorFees

Withdraws collected fees for a specific token (integrator only).
function withdrawIntegratorFees(
  tokenAddress: string
): Promise<ContractTransaction>
tokenAddress
address
required
Address of the token to withdraw (zero address for native)

withdrawLifiFees

Withdraws LiFi protocol fees for a specific token (owner only).
function withdrawLifiFees(
  tokenAddress: string
): Promise<ContractTransaction>
tokenAddress
address
required
Address of the token to withdraw (zero address for native)

batchWithdrawIntegratorFees

Withdraws integrator fees for multiple tokens at once.
function batchWithdrawIntegratorFees(
  tokenAddresses: string[]
): Promise<ContractTransaction>
tokenAddresses
address[]
required
Array of token addresses to withdraw

batchWithdrawLifiFees

Withdraws LiFi protocol fees for multiple tokens at once (owner only).
function batchWithdrawLifiFees(
  tokenAddresses: string[]
): Promise<ContractTransaction>
tokenAddresses
address[]
required
Array of token addresses to withdraw

View Functions

getTokenBalance

Gets the fee balance for a specific integrator and token.
function getTokenBalance(
  integratorAddress: string,
  tokenAddress: string
): Promise<BigNumber>
integratorAddress
address
required
Address of the integrator
tokenAddress
address
required
Address of the token

getLifiTokenBalance

Gets the LiFi protocol fee balance for a specific token.
function getLifiTokenBalance(
  tokenAddress: string
): Promise<BigNumber>
tokenAddress
address
required
Address of the token

Ownership Functions

The FeeCollector implements a two-step ownership transfer pattern:

transferOwnership

function transferOwnership(_newOwner: string): Promise<ContractTransaction>

confirmOwnershipTransfer

function confirmOwnershipTransfer(): Promise<ContractTransaction>

cancelOwnershipTransfer

function cancelOwnershipTransfer(): Promise<ContractTransaction>

owner

function owner(): Promise<string>

pendingOwner

function pendingOwner(): Promise<string>

Events

FeesCollected

Emitted when fees are collected.
_token
address
Address of the token (zero for native)
_integrator
address
Address of the integrator
_integratorFee
uint256
Amount collected as integrator fee
_lifiFee
uint256
Amount collected as LiFi protocol fee

FeesWithdrawn

Emitted when integrator fees are withdrawn.
_token
address
Address of the withdrawn token
_to
address
Address receiving the fees
_amount
uint256
Amount withdrawn

LiFiFeesWithdrawn

Emitted when LiFi protocol fees are withdrawn.
_token
address
Address of the withdrawn token
_to
address
Address receiving the fees
_amount
uint256
Amount withdrawn

OwnershipTransferRequested

_from
address
Current owner
_to
address
Pending new owner

OwnershipTransferred

previousOwner
address
Previous owner
newOwner
address
New owner

Usage Example

import { FeeCollector__factory } from '@lifi/contract-types';
import { ethers } from 'ethers';

const provider = new ethers.providers.JsonRpcProvider(RPC_URL);
const signer = provider.getSigner();
const feeCollector = FeeCollector__factory.connect(FEE_COLLECTOR_ADDRESS, signer);

// Collect fees in USDC
const usdcAddress = '0xUSDC_ADDRESS';
const integratorFee = ethers.utils.parseUnits('1', 6); // 1 USDC
const lifiFee = ethers.utils.parseUnits('0.5', 6); // 0.5 USDC

const tx = await feeCollector.collectTokenFees(
  usdcAddress,
  integratorFee,
  lifiFee,
  '0xINTEGRATOR_ADDRESS'
);
await tx.wait();

// Check integrator balance
const balance = await feeCollector.getTokenBalance(
  '0xINTEGRATOR_ADDRESS',
  usdcAddress
);
console.log('Integrator USDC balance:', ethers.utils.formatUnits(balance, 6));

// Withdraw integrator fees
const withdrawTx = await feeCollector.withdrawIntegratorFees(usdcAddress);
await withdrawTx.wait();

Build docs developers (and LLMs) love