Dynamic Fees
Last updated
Last updated
DLMM implements dynamic fees with surge pricing based on market fluctuations and volatility.
LPs earn a swap fee from traders when they perform a swap. The total swap fee will have two components: a base fee and a variable fee . Total swap fee
The variable fee is a function of real-time price volatility. The fee rate will be applied to the swap amount in each liquidity bin and distributed proportionally to the LPs in that bin.
LPs can claim these fees whenever they are available.
The base fee of a market is configured by the pool creator and determined by the base factor (B) and the bin step (s):
Base factor is the amplification to add to the bin step, to allow for adjustment of the pool base fees.
The variable fee depends on the volatility of the market where it is affected by swap frequencies as well as swaps that span across many bins. Fees are calculated and distributed on a per bin basis, to allow for a fair fee distribution to the LPs of each bin that is crossed.
For large swaps that span across bins, fees are calculated iteratively. This means that if a large swap crosses bins, total swap fee is calculated per bin (such that ), where is the difference in the bin IDs from the initial bin where the swap originated and the current bin in which it is being calculated.
For example, let's use SOL/USDC. We also assume each bin step is $1 for simplicity. Let us assume that the active bin (ID = 1000) before swap is $100. A large buy order was made that pushed the price up to $102.
Volatility Accumulater:
High frequency trades will stack up volatility, while low frequency trades will slowly reduce the volatility. If a long time has passed without any trade, the volatility will reset to 0.
This example will show how the volatility accumulator will look as swaps are made.
Quick Recap:
Swap 1
Swap 2
Swap 3
You can see that the volatility accumulator is decreasing despite high frequency of transactions, prevening people from manipulating fees by making lots of small transactions that increase/decrease prices.
Protocol fees will be a percentage of the total swap fees.
The value of for each bin is illustrated below:
$100 bin - ID = 1000; = 0
$101 bin - ID = 1001; = 1
$102 bin - ID = 1002; = 2
Note that can also be negative if it pushes the price downwards.
The variable fee for a bin will be calculated using the variable fee control parameter , bin step and volatility accumulator :
Volatility Accumulator captures instantaneous volatility.
Variable Fee Control Parameter is used to scale the variable fee component depending on the expected dynamics of the market.
Volatility on the DLMM is derived from the number of bin changes that occur over time. Each bin change is a fixed price movement of the bin step. The Volatility Accumulator allows us to use bin crossovers as a measure of volatility beyond a single transaction.
Think of the Volatility Accumulator as a witness of the current volatility of the token pair. Between each calculation step, this value will be kept in memory. It is calculated during a swap and depends on two factors:
Volatility Reference from the previous swaps
Introduced Volatility
(Note: is the ID of the active bin before the swap is made.)
The volatility reference depends on the time passed since the last transaction We will define a window with an upper and lower bound. The lower bound of this window is defined as filter period , and upper bound as decay period .
If is smaller than the filter period (this indicates a high frequency of transactions occurring), then stays the same.
If is greater than the decay period (this indicates a low frequency of transactions occurring), then is reset to 0.
If is within the window bounded by & , then takes the previous value of decayed by a factor
We introduce a new variable, the index reference to calculate the volatility introduced by the trade. In most cases, will be the ID of the active bin before the swap is made. In times of high frequency transactions, will keep its old value instead. Doing this will help prevent people from manipulating fees through making small lots of small transaction that increase and decrease price.
The volatility accumulated for the bin will then be used to calculate the fees generated by swapping through this bin and be allocated to the liquidity providers of the bin.
The final fee for the bin will be:
Volatility Accumulator:
is time elapsed since last transaction
is filter period
is decay period
R is the factor that decays , the volatility accumulator when
Let = 1 sec, = 5 secs, = 0.5 sec, and active bin ID is 100.
You make a trade that crosses +3 bins to 103. So :
At the end of swap 1, .
John makes a trade 4 seconds later that crosses +5 bins to 108. As , . So :
At the end of swap 2, .
Jane makes a trade 0.3 seconds later that crosses -2 bins to 106. As , which is of 1 second, and stays the same. So :
At the end of swap 3, .