Uniswap V3: Liquidity providing 101

Uniswap v2 recap: a trader’s perspective

  • Traders to swap one asset for another;
  • Liquidity providers (LPs) to provide liquidity and earn trading fees.
Figure 1: Uniswap v2 trader’s perspective

Uniswap v2 recap: a liquidity provider’s perspective

Figure 2: Uniswap v2 liquidity provider’s perspective

Uniswap v3: single position

Figure 3: Uniswap v3 single position

Uniswap v3: multiple positions

Figure 4: Uniswap v3 two positions

Ticks and tick spacing

Figure 5: Ticks and tick spacing

Liquidity value for a position

Effective liquidity providing

Figure 6: Aligning R to rᵃᵇ
  1. Is R > rᵃᵇ(p₀)? If yes, we need to swap Y for X, otherwise — X for Y.
  2. As we swap — will the pool price ever cross a tick spacing tick? If no — we can solve the problem right away. If yes — we need to adjust our values as if we swapped all the way to the tick and then repeat our algorithm on the new tick with the new liquidity.
  1. Swapping Y for X inside one tick interval: R > rᵃᵇ(p₀), R+ ≤ rᵃᵇ(p+)
  2. Swapping X for Y inside one tick interval: R < rᵃᵇ(p₀), R- ≥ rᵃᵇ(p-)
  3. Swapping Y for X in different tick intervals: R > rᵃᵇ(p₀), R+ > rᵃᵇ(p+)
  4. Swapping X for Y in different tick intervals: R < rᵃᵇ(p₀), R- < rᵃᵇ(p-)
Figure 7: Swapping Y for X inside one tick interval. As we swap from Y to X the price is growing to p₃, R is decreasing to R+, while rᵃᵇ is increasing to rᵃᵇ+. Since initially R > rᵃᵇ and R+ ≤ rᵃᵇ+ it is guaranteed that R = r is inside the tick interval.
Figure 8: Swapping X for Y inside one tick interval. As we swap from X to Y the price is decreasing to p₂, R is growing to R-, while rᵃᵇ is decreasing to rᵃᵇ-. Since initially R < rᵃᵇ and R- ≥ rᵃᵇ- it is guaranteed that R = r is inside the tick interval.
Figure 9: Swapping Y for X in different tick intervals. As we swap from Y to X the price is growing to p₂ and then to p₃, R is decreasing to R+, while rᵃᵇ is increasing to rᵃᵇ+. Since initially R > rᵃᵇ and R+ > rᵃᵇ+ it is guaranteed that the price will cross tick spacing tick while we swap to R = rᵃᵇ
Figure 10: Swapping X for Y in different tick intervals. As we swap from X to Y the price is decreasing to p₃ and then to p₂, R is increasing to R-, while rᵃᵇ is decreasing to rᵃᵇ-. Since initially R < rᵃᵇ and R- < rᵃᵇ- it is guaranteed that the price will cross tick spacing tick while we swap to R = rᵃᵇ

Conclusion

Who we are

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Mellow Protocol

Mellow Protocol

Exploring the depths of math on LPing, AMMs and trading strategies.