Fee model

The TWMM utilizes three distinct fee concepts:

  • Base Fee: A fee charged unconditionally on every swap, liquidity addition, and liquidity removal.

  • Deviation Fee: A conditional fee charged if a trade increases the deviation of an asset.

  • Cashbacks: A negative fee, or rebate, funded by previously collected deviation fees, used to reward users who decrease an asset's deviation.

Fees are collected on both the input and output assets and are initially held within the pool. This allows fees designated for liquidity providers to be auto-compounded. Ultimately, these fees are distributed among the following roles:

  • Manager Fee: The pool manager receives their fee in the form of newly minted LP tokens, which can be claimed. These tokens are minted according to the manager's configured fee share and do not dilute the value held by existing liquidity providers.

  • LP Fee: This portion of the fee accrues to the value of the LP tokens held by liquidity providers.

  • Protocol Fee: This fee is distributed in a similar manner to the manager fee, typically via minted LP tokens.

Fee Flow

The following diagram illustrates how fees are distributed among the pool's roles.

Deviation fees

Deviation fees are calculated using a linear function that scales with the increase in an asset's absolute deviation. The final absolute deviation after a trade determines the magnitude of the fee.

The following chart describes the relationship between the deviation fee and the trade size. Within a certain range, a trade may cause the absolute deviation to decrease or stay the same; in these cases, the deviation fee is zero. For trades that increase the absolute deviation, the fee grows linearly.

This defines two parameters that govern the behavior of the deviation fee curve:

  • Deviation Fee Offset: Defines a fixed, immediate fee amount that is applied as soon as a trade begins to increase the absolute deviation.

  • Deviation Fee Multiplier: Shows how quickly the deviation fee grows relative to the growth in deviation. This value is defined as the fee rate that would be applied if a trade were to cause the deviation to reach 100%.

Another parameter is the Deviation Limit. This value describes the maximum absolute deviation an asset is allowed to have. If a trade would cause the final absolute deviation to exceed this parameter, the transaction is reverted.

Cashbacks

Cashback reserves are funded by a portion of the collected deviation fees. The specific percentage of deviation fees allocated to this reserve is determined by a parameter called the Cashback Fee Share. These cashback funds are stored separately from the pool's main asset reserves. Cashback distribution is handled independently for each asset in the pool.

Consider the following example of a cashback calculation for an input asset:

This example for an input asset can also be applied identically to an output asset. In this example, the trade can only decrease the deviation's value, as it starts from a deficit (a deviation lower than zero). The chart illustrates that a cashback is awarded for trades that move the deviation toward zero.

A cashback for an input asset is applied as an additional amount credited to the user's trade. This application of the cashback, in turn, impacts the final deviation. The cashback amount is constrained to prevent it from pushing the final deviation past zero.

The cashback is awarded proportionally to the reduction in absolute deviation. For example, if the deviation before a trade was -10% and the trade moved it to -2%, the absolute deviation was reduced by 80%, entitling the user to receive 80% of the available cashback funds.

However, to ensure a sustainable distribution, there is a parameter called Maximum Cashback that caps the size of any single cashback award. This maximum is typically expressed as a percentage of the trade size (e.g., a 5% maximum means the cashback cannot exceed 5% of the user's trade value). This works in concert with the constraint that a cashback can never be larger than the amount required to bring the final deviation to exactly zero.

Fee parameters

Name
Description

Base fee

Fee charged unconditionally with every operation

Deviation fee offset

A additional base fee when deviation increases

Deviation fee multiplier

Linearly growing part of deviation fee

Deviation limit

Limit of the deviation that can not be violated by a trade if it increases deviation

Cashback fee share

Share of deviation fee to be converted into cashback

Maximum cashback

Maximum possible value of cashback in trade respectively to trade size, denominated as percentage value

Last updated