Technical Docs
FeeCollector

FeeCollector

Description

The FeeCollector contract is responsible for collecting and allocating protocol fees.

Write Functions

collectFees

Collects and allocates fees after user savings have been deducted from the maximum protocol fee. This function is called by Position contracts whenever add and addLeverage are called.

function collectFees(
    address _client,
    address _token,
    uint256 _amt,
    uint256 _clientFee
) external payable;

Input Parameters

Parameter NameTypeDescription
_clientaddressThe address of the client operator.
_tokenaddressThe ERC-20 token address in which to collect fees.

This is the collateral token of the calling Position contract.
_amtuint256The total amount of fees to collect after user savings have been deducted from the maximum protocol fee.

The transaction-specific user savings and _clientFee are returned by getClientAllocations.
_clientFeeuint256The portion of the maximum protocol fee that is allocated to the specified client.

clientWithdraw

Allows client operators to withdraw accumulated fees from the contract, for the specified ERC-20 token.

🚨 Client operators can check if they have any fees to withdraw by calling balances.

function clientWithdraw(
    address _token
) external payable;

Input Parameters

Parameter NameTypeDescription
_tokenaddressThe address of the ERC-20 token to withdraw.

setClientTakeRate

Allows client operators to set their take rate. This is the percentage of the client rate that the client operator keeps. Amounts less than 100% give the client's users a protocol fee discount.

🚨 The default client take rate is 0%. If a client operator does not set a take rate, 100% of the client fees will go to the users of that client.

function setClientTakeRate(
    uint256 _clientTakeRate
) external payable;

Input Parameters

Parameter NameTypeDescription
_clientTakeRateuint256The percentage of the client rate that the calling client operator keeps.

Ex: 50 = 50%.

If the clientTakeRate for a given client is 50%, this means that 50% of the fees that the client collects are given back to their users. This is done by discounting the total protocol fee that their users have to pay when calling add or addLeverage on a Position contract.

Read Functions

feeRate

Returns the maximum percentage that the protocol charges each revenue-generating transaction.

This fee is charged only when the add and addLeverage functions are called on the Position contract.

Ex: Suppose feeRate = 3. When add is called, 0.3% of the supplied C_TOKEN would be taken as a fee. When addLeverage is called, 0.3% of the supplied D_TOKEN would be taken as a fee.

🚨 Depending on the specific arrangement, a portion of this fee may be allocated to client operators, their users, or both. This variability is the reason it is referred to as the "maximum" fee.

function feeRate() external view returns (uint256);

Output Parameters

Parameter NameTypeDescription
feeRateuint256The maximum percentage fee charged by the protocol each revenue-generating transaction.

Ex: 3 = 0.3%

clientRate

Returns the current client rate, which is the percentage of the maximum protocol fee that a client operator receives if their clientTakeRate is set to 100%.

🚨 Client operators are guaranteed between 30%-100% (opens in a new tab) of the total protocol fee.

function clientRate() external view returns (uint256);

Output Parameters

Parameter NameTypeDescription
clientRateuint256The maximum percentage of the maximum protocol fee a client operator can receive.

Ex: 30 = 30%

clientTakeRates

Returns the take rate of the specified client operator. This is the percentage of the client rate that the specified client operator keeps.

🚨 Amounts less than 100% give the client's users a protocol fee discount. Client operators that do not set this to a non-zero value will not earn any fees.

function clientTakeRates(
    address _client
) external view returns (uint256);

Input Parameters

Parameter NameTypeDescription
_clientaddressThe address of the client operator.

Output Parameters

Parameter NameTypeDescription
clientTakeRateuint256The percentage of the client rate that the given client operator keeps.

Ex: 50 = 50%

If the clientTakeRate for a given client is 50%, this means that 50% of the fees that the client collects are given back to their users. This is done by discounting the total protocol fee that users of that client have to pay when calling add or addLeverage on a Position contract.

balances

Returns the balance that the specified client operator can withdraw from the FeeCollector contract, for the specified ERC-20 token.

🚨 Client fees can be accumulated in any ERC-20 token that was used as collateral by users of the specified client.

function balances(
    address _client,
    address _token
) external view returns (uint256);

Input Parameters

Parameter NameTypeDescription
_clientaddressThe address of the client operator.
_tokenaddressThe address of the ERC-20 token.

Output Parameters

Parameter NameTypeDescription
balanceuint256The balance that the specified client operator can withdraw from the FeeCollector contract, for the specified ERC-20 token.

To withdraw this balance, the client operator must call clientWithdraw on the FeeCollector contract.

totalClientBalances

Returns the total amount of fees allocated to client operators, for the specified ERC-20 token.

function totalClientBalances(
    address _token
) external view returns (uint256);

Input Parameters

Parameter NameTypeDescription
_tokenaddressThe address of the ERC-20 token.

Output Parameters

Parameter NameTypeDescription
balanceuint256The total amount of fees allocated to client operators, for the specified ERC-20 token.

getClientAllocations

Returns the fee amounts allocated to the specified client operator and its users, given a transaction-specific protocol fee.

function getClientAllocations(
    address _client,
    uint256 _maxFee
) external view returns (uint256 userSavings, uint256 clientFee);

Input Parameters

Parameter NameTypeDescription
_clientaddressThe address of the client operator.
_maxFeeuint256The maximum fee a user will pay.

This fee is be denominated in C_DECIMALS for fees collected through add and in D_DECIMALS for fees collected through addLeverage.

Refer to the Fees page for details on how to calculate.

Output Parameters

Parameter NameTypeDescription
userSavingsuint256The amount of fees that the user is discounted from the maximum protocol fee, when using the specified client.
clientFeeuint256The amount of the maximum protocol fee the client operator will receive.

owner

Returns the owner of the FeeCollector contract.

function owner() external view returns (address);

Output Parameters

Parameter NameTypeDescription
owneraddressThe address of the account that has owner privileges on the FeeCollector contract.