Dynamic Fees for Automated Market Makers: Liquidity, Volatility, and Collected Fees

Atis E
9 min readJan 3, 2024

--

This work is part of a collaboration with Brokkr Finance, who are developing proof-of-concept Uniswap v4 hooks, including a dynamic fee hook.
The goal of this article isn’t to propose a specific dynamic fee policy, but to investigate the relation ship between the liquidity of the asset pool, the volatility of the asset pair, and the fees collected.

Motivation

Dynamic fees is a feature that can improve LP experience and profits. But exactly why do we need dynamic fees?

Reason #1: correctly pricing volatility

Consider how trading usually happens on traditional exchanges. When volatility (σ) increases, market makers increase their bid-ask spreads.

A constant-function automated market maker (CFAMM) like Uniswap v2 or Uniswap v3 cannot do that. In a sense, its bid-ask spread is determined by the fee, and is always approximately equal to 2x the fee. For instance, for a 0.3% pool the spread is approximately equal to 0.6%.

As a consequence:

  • When volatility is low relative to the trade volume in the pair, the trading fee is too high, leading the traders to prefer a CEX;
  • When volatility is high relative to the trade volume, the trading fee is too low, leading to LPs losses and LPs leaving the DEX.

The result is lose/lose for DeFi.

Reason #2: discriminating order flows

Some trades, like CEX-DEX arbitrage trades, belong to the so-called “toxic flow”. Taking these trades are short-term bad for the LPs. The remainder of the trades can be bundled together, and named “uninformed flow”.

Markout metrics can help to discriminate between these two flows. Markout measures LP profitability by estimates the profit of a trades by looking at the short-term future price of the asset.

The uninformed flow can be modeled as random, with no directional bias. Its markout is going to be approximately zero. As a result, for uninformed trades, the trading fee taken by the LP can be small. It just needs to offset the risk-free rate the LP could earn on their assets.

In contrast, the fees LP takes from a toxic flow trade should be higher. They need to offset the expected losses from the trade itself.

Dynamic fee approaches

Many ideas exist, and it’s impossible to discuss them all. Some examples include:

  • Volatility-based approach: tie the swap fee to the historical volatility of the asset pair. The volatility can be tracked either by the pool itself, or by an external oracle. (Used by Trader Joe Liquidity Book, Algebra, Hypersea and many others.)
  • Lookback approach. It requires a number of external pool with the same asset pair, but different fee tiers. The pool should be highly liquid, for example, they can be the mainnet Uniswap v3 pools. The idea is to set the fee same as the fee of the external pool most profitable in the lookback period. (Used by Ambient Finance.)
  • Price oracle approach: use an external price oracle to determine the correct price of the asset. A higher fee is asked if the trade moves the pool price closer to this external price. (Used by Swaap.)
  • Price momentum approach: look at the price history in the most recent block(s) and asymmetrically change the fee depending on the trade direction. The aim is to infer the dynamics of the external price without using an oracle. (Implemented as a Uniswap v4 hook.)
  • Asset composition approach: lower fee for trades that make the pool more balanced, higher for trades that imbalance it. (Used in some Curve pools.)
  • Transaction-source based approach: provide lower fee for transactions that are routed through aggregators, or are otherwise unlikely to be arbitrage-traded. (Example: Balancer has lower fees for trades coming from CowSwap solvers.)
  • Other ideas, such as using the swap size, the source address of the transaction, the transaction history of the source address, etc.

Coprocessors are a new technology that could be used to efficiently implement many of these ideas, especially in the latter group. For instance, there could be some discounts for “loyal clients”, as long as these clients aren’t likely to create toxic trades.

However, there’s a potential drawback for all of these dynamic fee methods. Increased trading fees are expected to reduce trading volumes. As such, they may have negative effects on the LPs. More generally, changing the fee based on the current trade flows changes the future trade flows. This is known as the Lucas critique; namely, the Lucas critique argues that “it is naive to try to predict the effects of a change in economic policy entirely on the basis of relationships observed in historical data”.

Further reading:

Experiments

Simulation settings: single-flow model

With the theory out of the way, let’s look into some simulation results.

Our simulations investigate a volatile/stable asset pair on an Uniswap v2-like DEX. The daily volatility of the asset σ is set to 0.05, corresponding to yearly volatility of approximately 1.0, which is similar to ETH in 2022 (but much higher than for ETH in 2023!), and neutral price drift (μ=0).

The swap volume in the model comes from CEX-DEX arbitrage. The arbitrage trades are modeled assuming a CEX with infinitely deep liquidity and without a trading fee. This CEX is external to the model that provides a history of the “true” price of the assets. The CEX price evolution is modeled by using GBM. All DEX trades happen at discrete intervals, determined by the block time, set to 12 seconds. The fixed transaction fee is set to $5.0, and liquidity pool sizes of around $1 million are used.

Dependence on pool’s depth and swap fee

By fixing the volatility σ=0.05 and varying the swap fee, we can model how higher or lower fees affect the total fees collected from arbitrage trades.

Luckily, there’s a simple linear relationship once some critical depth has been reached. If the pool is too shallow, no trades happen, as the fixed transaction cost together with the swap fee disincentivizes arbitragers. As more liquidity is added, trading starts to happens, and the amount of the fees collected per unit of liquidity in the pool remains constant.

The graphs confirm that generally, the higher the fee, the better from the LP’s perspective under this toxic flow model. The main reason is that directional (non-reverting) price movements tend to dominate volatile asset pair price trajectories, and for such movements, higher swap fees are better unless the fixed costs for making a swap are close to zero. Higher swap fees lead to fewer, but larger arbitrage transactions; as a result, the fees that arbitragers pay to the blockchain are much reduced relative to the fees they pay to liquidity providers.

Dependence on pool’s depth and asset volatility

Let’s fix the swap fee to 0.3% and investigate how the volatility affects the fees collected.

Once again there’s a simple linear relationship between the pool depth and the fees collected. (Beyond some point, at which trading starts to happen at all.)

It must be said that the increase in fees collected doesn’t offset the increased LVR of more volatile assets, as LVR is proportional to the square of the σ. To put it plainly, if there’s only toxic flow, the best strategy for the LP is not to trade at all. One way how to ensure that is to set an infinitely high fee.

Effect from the fixed tx cost

Clearly, the fixed cost also has a large impact, especially for the lower fee tier pools. The graph below shows that making the swap transaction 100x cheaper more than doubles the fees LP collects from arbitrage transactions.

The graph shows results for the 0.3% pool; with higher fee tiers the effect would be much less pronounced, as the LP already recaptures most of the LVR back via Tx fees, so even doubling the fees collected would not be possible, no matter how cheap the transaction cost is made.

Adding dynamic fees

What if we set the fee proportional to the asset’s volatility? Or as a function of volatility?

The graph above shows that setting the fee proportional to the σ² better approximates LVR than using a static fee or a fee proportional to σ. Of course, the even with σ², LVR is not fully recaptured via fees, because of the less-than-infinite depth of the DEX pool, the fixed block times, and gas fee costs for each transaction.

Adding uninformed flow

Simulation settings: two-flow, two-pool model

Let’s extended the model with some uninformed flow traders.

The uninformed traders make trades in a random direction, with trade sizes distributed exponentially. The trades are backrun by the arbitrage trader whenever it is profitable, according to CEX prices.

In addition, let’s consider a system that has two liquidity pools. Each retail trade is picked up by the pool which offers the best execution price for that trade.

Our goal is to maximize the fees collected by our own pool; the other pool has a fixed fee 0.3% (30 bps), which we don’t control.

Dependence on the other pool’s depth

The conclusion from the graph above is simple: if the other pool is deeper, it is going to capture a disproportionate part of the trades, making the LPs own pool much less profitable.

The amount of fees captured by the own pool is proportional to square root of the other pool.

Dependence on the fee policy

Under the two-flow & two-asset model the benefits from the dynamic fees becomes much less clear. In fact, for some asset volatility values the static fee model is better. However, the dynamic fee model does scale much better with volatility.

Dependence on the intensity of the retail flow

As the single-flow single-pool model shows, if there’s no uninformed flow, then setting a maximally high fee is the best approach.

Two pool model, low retail volume

This remains true in the multi-flow model if the retail activity is present, but low volume. (The other pool has 30 bps fee and a fixed liquidity of $1 million, matching the LP’s own pool.)

Two pool model, medium retail volume

However, at some point, the fees for the retail are significant enough so that the 20–40 bps pools outperform the higher fee-tier pools.

Two pool model, high retail volume

Finally, if the retail activity is large relative to the volatility of the asset, then 10 bps or lower fee-tier pools are the best choice from the LP profitability perspective!

To summarize:

  • If retail/uninformed volume is low, it’s best to have a higher fee than in the other pool, and let the other pool take most of the volume.
  • If retail volume is medium, it’s best to match the fee of the other pool.
  • If retail volume is high, it’s ok to have a lower swap fee, in order to pick up most of the volume.

This result shows that it isn’t possible to accurately set a pool’s fee just by looking the volume going through the pool; at least the asset volatility, or the type of the flow also must be taken into account.

Main lessons learned

  1. The simple linear relationship between the liquidity and arbitrage volume suggested by the single pool model is not accurate if uninformed flow and competing pools are present. In competitive settings, the total volume routed through a pool is proportional to sqrt(liquidity) of that pool. (One consequence of this: fragmentation of liquidity is bad not just for traders, but for LPs as well.)
  2. The best fee depends on at least two orthogonal factors: asset volatility and volume of the uninformed flow. In a DEX like Uniswap v3, which does not and cannot discriminate the flows, LPing in the low fee-tier pools only makes sense if both of these conditions are true (1) the uninformed flow is large and (2) the asset volatility is relatively low.

Caveat: these lessons apply to volatile asset pairs. The dynamics of stable pairs are completely different; e.g. lower fee tiers are much more attractive.

--

--