Dynamic fees
The LP Fee can be set to dynamic, meaning it will automatically adjust based on market volatility. Each swap transaction contributes to an increase in the measured volatility, which in turn raises the LP fee. In the absence of swaps, the fee gradually decreases over time as volatility decays.
Fee format
All fees within the protocol are stored as 16-bit unsigned integers representing the numerator of a fractional value with a fixed denominator of 10,000. That is, a value of 1 corresponds to a fee rate of 0.01%, while a value of 100 represents 1.00%.
Fee increasing
The LP fee increases with each swap according to the following formula: where:
- Fee (): current fee prior to the swap
- Volatility (): relative price change during the swap
- Dynamic fee factor (): pool-defined parameter that controls the sensitivity of the fee to volatility.
Base fee
Base fee () is a fixed fee applied to the swap amount. It is defined at the time of pool creation and remains constant throughout the lifetime of the pool.
Volatility
Volatility () is calculated as the relative change in price over the duration of a swap, using the following formula: This formulation captures the proportional, rather than absolute, change in price. By using a relative metric, the volatility impact remains consistent across different absolute price levels, ensuring that the same percentage change results in the same effect on fee adjustment, regardless of the price magnitude.
Dynamic fee factor
Dynamic fee factor () is a pool-level parameter that determines how sensitively the LP fee responds to changes in volatility.
Time-Based Fee Controls
To prevent manipulation of the dynamic fee mechanism through high-frequency swaps, the protocol introduces two additional time-based parameters: filter period and decay period.
- Filter period (): minimum required time interval between swaps for a new swap to contribute to fee increase. If a swap occurs before has elapsed since the previous one, it does not affect the volatility calculation and does not increase the dynamic fee. This mechanism protects the pool from fee inflation via spam-like swap activity.
- Decay period (): time over which the dynamic fee gradually decays back to the base fee in the absence of new swaps. Specifically, if no swap activity occurs for a duration equal to , the dynamic fee will return to its initial value.
Fee decay
In the absence of eligible swap activity, the dynamic fee gradually decreases over time, approaching the base fee (). The decay begins only after the time elapsed since the last swap exceeds the filter period threshold.
The dynamic fee at time t is computed using the following formula:
where:
- : dynamic fee immediately after the last swap
- : base liquidity provider fee set at pool creation
- : minimum interval required for swaps to influence the fee
- : total duration after which the fee fully returns to base fee
- (time delta): time elapsed since the last eligible swap
This piecewise-linear decay ensures that:
- The fee does not begin to decrease until filter period has passed.
- The decay is smooth and linear, reaching base fee exactly at decay period.
- The fee never drops below base fee or exceeds the last recorded dynamic fee.
Protocol fee
Protocol fee () is also dynamic and depends on the current dynamic LP fee. Specifically, the protocol receives a fraction of the dynamic fee, defined by the protocol fee reduction factor (). The protocol fee is calculated as:
Where:
- Swap amount (): amount of tokens being output in the swap
- Dynamic fee (): current LP fee
- Protocol fee reduction factor (): determines what fraction of the LP fee is allocated to the protocol
For example, if dynamic fee is 1% and , the protocol receives a fee equivalent to 0.2% of the swap amount.
If is set to 0, no protocol fee is charged.