Technical Docs
Fees

Fees

Protocol fees are collected when add and addLeverage are called on a Position contract.

How are fees calculated when add is called?

When add is called on a Position contract, a small amount of the collateral token supplied is taken as a fee.

QuantityDescription
cAmtcAmtThe amount of collateral token supplied when calling add.
protocolFeeRateprotocolFeeRateThe maximum fee the user could pay, as a percentage of cAmtcAmt.

To get the current fee rate, call protocol fee rate on the FeeCollector contract.
maxFeemaxFeeThe maximum fee the user could pay, in terms of the position's collateral token.

=cAmtprotocolFeeRate=cAmt*protocolFeeRate
clientRateclientRateThe percentage of maxFeemaxFee that clients can keep.
clientTakeRateclientTakeRateThe percentage of clientRateclientRate that the utilized client keeps.
clientFeeclientFeeThe amount the utilized client keeps in terms of the position's collateral token.

=maxFeeclientRateclientTakeRate=maxFee*clientRate*clientTakeRate
protocolFeeprotocolFeeThe amount the protocol keeps.

=maxFee(100%clientRate)=maxFee*(100\%-clientRate)
userSavingsuserSavingsThe amount that users of the utilized client save.

=maxFee(100%clientTakeRate)clientRate=maxFee*(100\%-clientTakeRate)*clientRate

The following is an example calculation for a transaction where a user calls add using a client that has set their take rate to 90%, the current client rate is 30%, and the protocol fee rate is 0.3%.

cAmt=$1000cAmt=\$1000

protocolFeeRate=0.3%protocolFeeRate=0.3\%

clientRate=30%clientRate=30\%

clientTakeRate=90%clientTakeRate=90\%

maxFee=$10000.3%=$3maxFee=\$1000*0.3\%=\$3

clientFee=$330%90%=$0.81clientFee=\$3*30\%*90\%=\$0.81

protocolFee=$370%=$2.10protocolFee=\$3*70\%=\$2.10

userSavings=$310%30%=$0.09userSavings=\$3*10\%*30\%=\$0.09

\therefore Instead of paying the maximum fee of $3.00, the user only paid $2.91.

How are fees calculated when addLeverage is called?

When addLeverage is called on a Position contract, its base token is used to borrow more debt token. A small amount of the debt token borrowed is taken as a fee.

QuantityDescription
cTotalcTotalThe total amount of collateral backing the position's loan on Aave (collaterall token + base token).

Obtained by calling getUserAccountData on Aave's Pool contract (opens in a new tab).
dTotaldTotalThe total amount of debt the position has on Aave.

Obtained by calling getUserAccountData on Aave's Pool contract (opens in a new tab).
LTVLTVThe maximum loan-to-value ratio the position can have, given all of its current collateral on Aave.

Obtained by calling getUserAccountData on Aave's Pool contract (opens in a new tab).
dAmtdAmtThe amount of debt token borrowed when calling addLeverage.

dAmtmax=cTotalLTVdTotaldAmt_{max}=cTotal*LTV-dTotal

To minimize the risk of liquidation, dAmtdAmt should be less than dAmtmaxdAmt_{max}.
protocolFeeRateprotocolFeeRateThe maximum fee the user could pay, as a percentage of dAmtdAmt.

To get the current fee rate, call protocol fee rate on the FeeCollector contract.
maxFeemaxFeeThe maximum fee the user could pay, in terms of the position's debt token.

=dAmtprotocolFeeRate=dAmt*protocolFeeRate
clientRateclientRateThe percentage of maxFeemaxFee that clients can keep.
clientTakeRateclientTakeRateThe percentage of clientRateclientRate that the utilized client keeps.
clientFeeclientFeeThe amount the utilized client keeps in terms of the position's debt token.

=maxFeeclientRateclientTakeRate=maxFee*clientRate*clientTakeRate
protocolFeeprotocolFeeThe amount the protocol keeps.

=maxFee(100%clientRate)=maxFee*(100\%-clientRate)
userSavingsuserSavingsThe amount that users of the utilized client save.

=maxFee(100%clientTakeRate)clientRate=maxFee*(100\%-clientTakeRate)*clientRate

The following is an example calculation for a transaction where a user calls addLeverage using a client that has set their take rate to 90%, the current client rate is 30%, and the protocol fee rate is 0.3%.

cTotal=$5000cTotal=\$5000

dTotal=$2500dTotal=\$2500

LTV=80%LTV=80\%

dAmtmax=$500080%$2500=$1500dAmt_{max}=\$5000*80\%-\$2500=\$1500

dAmt=$1000dAmt=\$1000

protocolFeeRate=0.3%protocolFeeRate=0.3\%

clientRate=30%clientRate=30\%

clientTakeRate=90%clientTakeRate=90\%

maxFee=$10000.3%=$3maxFee=\$1000*0.3\%=\$3

clientFee=$330%90%=$0.81clientFee=\$3*30\%*90\%=\$0.81

protocolFee=$370%=$2.10protocolFee=\$3*70\%=\$2.10

userSavings=$310%30%=$0.09userSavings=\$3*10\%*30\%=\$0.09

\therefore Instead of paying the maximum fee of $3.00, the user only paid $2.91.