Surge Pricing: improving swaps and protecting liquidity providers
Cryptocurrency markets are known to be highly volatile. It’s not rare to see double-digit daily price swings. While this volatility presents a golden opportunity for traders, it leaves liquidity providers on decentralised exchanges exposed.
Impermanent Loss (IL), defined as the difference in the performance of LP position compared to just holding assets in a wallet, is one of the biggest worries for liquidity providers. They have very little control over the price and even less control over the fee they charge for their services. That fee is often predefined by the exchange they use, with 0.3% considered an industry standard.
However, that fee alone is rarely enough to compensate for the Impermanent Loss (IL) when it comes to volatile pairs. This is where Trader Joe’s new Liquidity Book comes in.
Every time someone uses Liquidity Book to swap tokens, they are charged a flat Base Fee. Depending on current volatility, they might also be charged an additional fee based on a Surge Pricing mechanism. That fee is derived using two parameters:
Bin Step - variable set at the initialisation of the pair. It defines the price difference between each of the bins.
Volatility Accumulator - a novel counter introduced by the Liquidity Book to track on-the-spot pair volatility.
Bin step
The Bin Step defines price increase or decrease for each bin in basis points. One basis point (BPS) is equal to 0.01%. For example, having a bin step of 20 BPS means that the price of each bin in the pair differs by 0.2%.
Consider an AVAX-USDC pair with a bin step of 10 BPS created when AVAX was worth $15. If the price moves up one bin, it will be worth 15.015 (15*1.001); if it moves down one bin, it will be 14.985 (15*0.999).
For volatile pairs, it makes sense to have a relatively high bin step to allow for bigger price movements. Smaller bin steps are more useful for pairs like USDC.e-USDC that are expected to trade within a might tighter range. Having bin step as a part of Surge Pricing calculations allows Liquidity Book to account for different pairs with different anticipated levels of volatility.
Volatility Accumulator
The Volatility Accumulator (VA) is one of the most significant innovations of the Liquidity Book. It allows for the calculation of the pair's current volatility instantly and without delay. For each swap, it counts how many bin changes occurred during it (denoted by k). Depending on how much time passed since the last transaction, it then either:
Decays - multiply the current count by the reduction factor R, which is set to a value between 0 and 1, then adds k to it;
Increases - adds k to the current count;
Resets - sets current to k.
The exact behaviour is governed by the contract's upper and lower time limits. If the interval between two consecutive transactions is smaller than the lower time limit, the Volatility Accumulator increases. If it is larger than the upper time limit, it resets. Otherwise, the accumulator decays.
It is important to note that the Volatility Accumulator takes the direction of trades into account when they occur below the lower time limit. When buys and sales occur in short succession, the volatility accumulator movements counteract each other.
Consider an example in which someone sells tokens resulting in the price going five bins down. Instantly, another person buys the same tokens leading to the price going four bins up. As a result, the net change in the Volatility Accumulator would be the same as the one for a sale that crosses one bin.
Volatility Accumulator Example
Let’s say that the AVAX-USDC pair's lower time limit is 10 seconds and the upper limit is 10 minutes. Four traders are using this pair to buy and sell tokens:
The Volatility Accumulator starts at 0, with Bob selling some AVAX. His transaction is relatively small in size, so no bin changes occur. The k is 0, and VA is 0 as well.
Seven seconds later, a whale named Alice decides that she also wants to sell some AVAX. Her transaction results in 3 bin changes. Because the swap occurred under the lower time limit, the k is 3, and VA at the last bin is 3 (0+3).
Charlie sees Alice’s sale and uses this opportunity to buy some cheap AVAX 20 seconds later. Because his transaction, which also crossed 3 bins, occurred after lower but before upper limits, the k is now 3, and the final Volatility Accumulator is 4.5 (3/2+3).
After this initial burst, the activity in the pair dies down with no swaps occurring for the next 10 minutes. Dan then decides to follow Charlie and also buy some AVAX, crossing 1 bin in the process. As it’s now past the upper time limit, the accumulator has reset and is now equal to 1 (4.5*0+1).
It’s important to note that because k records bin crossovers one by one, each bin's volatility accumulator is calculated separately. For instance, in step 3, VA is 4.5 at the third bin. It will, however, be 1.5 at the starting bin, 2.5 at the next one and 3.5 when the swap crosses the second bin.
While this is a very simple example, it is easy to see how Volatility Accumulator adjusts to market participants' actions to reflect current volatility levels accurately.
Conclusion
If many swaps occur in short succession, indicating increasing levels of uncertainty in the market, the Volatility Accumulator will ramp up. In turn, this will result in a higher fee on each swap. That fee would go to Liquidity Providers, in some cases allowing them to outperform the market or at least recoup some of the losses from IL.
Because there is no reliance on external oracles or time-bound observations, the Volatility Accumulator can measure instantaneous volatility. This way, even a couple of swaps are enough for the Surge Pricing to kick in. So liquidity providers can benefit from extreme volatility and usual activities such as bots arbitraging pools.
Such an approach is specifically enabled by the Liquidity Book’s design and would be impossible elsewhere. Additionally, all aspects of Surge Pricing calculations are customisable, allowing the protocol to adapt and change over time. Upper and lower time bounds can change, and a maximum limit can be set for the accumulator to prevent it from growing out of proportion.
Having Surge Pricing built into the Liquidity Book not only protects liquidity providers during volatile times but allows them to reduce fees during normal operations. This results in great swap rates on top of the low slippage already built into the Liquidity Book.