🌊Concentrated Liquidity

HorizonDEX is a decentralized exchange built on the Linea blockchain, offering users a seamless trading experience with enhanced liquidity and reduced slippage. This document aims to provide a comprehensive understanding of the technical aspects behind the HorizonDEX platform. Decentralized exchanges have gained significant traction in recent years, offering users the ability to trade cryptocurrencies directly from their wallets without relying on intermediaries. However, traditional automated market maker (AMM) models suffer from liquidity fragmentation, resulting in higher slippage and lower capital efficiency. HorizonDEX addresses these limitations by introducing a concentrated liquidity model on the Linea blockchain, empowering traders with enhanced liquidity and improved trading experiences.

A Novel Way of Pooling Liquidity

Earlier implementations of AMMs (such as Uniswap v2) used the so-called XYK model, based on the x*y=k price curve

DEX liquidity pools distribute tokens across a price range, allowing price discovery and adjusting token value based on supply and demand. Deep liquidity minimizes slippage, while thin liquidity causes price movements. A swap of $5,000 DAI for Token B with deep liquidity barely affects the price, but with thin liquidity, a swap of $5,000 USDC for Token B raises the price. Most tokens on the price curve are unused, resulting in inefficient capital deployment for LPs. Providing liquidity to a first-gen AMM earns fees proportionate to contributed tokens but restricts liquidity for other DeFi services.

Increasing Capital Efficiency with Concentrated Liquidity Market Makers

Increasing Capital Efficiency with Concentrated Liquidity Market Makers (CLMMs) allows LPs to choose specific price ranges for their token allocation, enhancing control. These ranges are divided into ticks, ensuring equal distribution of liquidity. Tokens remain in their allocated ticks until withdrawn, and fees are only earned within the chosen price range. CLMMs focus on supplying tokens around the current market value, significantly increasing capital efficiency compared to traditional AMMs. This technology enables LPs to achieve higher yields with fewer tokens, benefiting traders with reduced slippage and projects with optimized liquidity deployment for growth. In conclusion, concentrating liquidity around the current price and updating positions based on price changes is an effective strategy for maximizing gains while minimizing the risk of asset devaluation. This approach benefits both liquidity providers and traders, allowing LPs to allocate capital strategically and earn higher fees while providing traders with deeper liquidity and reduced slippage.

Diving into the Depths of Concentrated Liquidity

Technically, to understand concentrated liquidity. Consider a pair of tokens 𝑋 and π‘Œ where we measure the price of token 𝑋 in terms of token π‘Œ. When providing liquidity for this pair, an LP chooses a price range [π‘π‘Ž, 𝑝𝑏 ] in which they would like to provide liquidity. (We use the terms range and interval interchangeably in the following.) Together with the current price 𝑝, this determines the ratio of the two tokens the LP needs to deposit. The exact amounts of both tokens the LP decides to deposit then determines the amount of liquidity 𝐿 provided to the interval. When a trade occurs, it moves the current price of the pool. All LPs earn a portion of the trading fees proportional to the amount of liquidity they provided to the interval by which the price moved. Note that if the price moves outside the chosen range of an LP, the position consists of only one of the two tokens and stops earning fees. Once the price returns to the range, the position earns fees again. Providing liquidity to a price range can also be thought of as leveraging a passive LP position in the following sense: LPs only put up a fraction of the reserves which are used to calculate their proportion of the fees. The smaller the chosen range, the higher the leverage and the larger the proportion of fees the LP can earn. However, smaller ranges also lead to greater losses for the LP when asset prices decline. We will demonstrate this with an example later

Consider a liquidity position in the range [π‘π‘Ž, 𝑝𝑏 ] as shown in Figure 1. Let π‘₯ β€² (𝑝) and 𝑦 β€² (𝑝) be the virtual reserves of the position at a price of 𝑝 ∈ [π‘π‘Ž, 𝑝𝑏 ] (i.e. the amounts of tokens used to calculate trades against the liquidity position). Then π‘₯ β€² (𝑝)𝑦 β€² (𝑝) = π‘˜ = 𝐿 2 and 𝑦 β€² (𝑝)/π‘₯ β€² (𝑝) = 𝑝. This implies π‘₯ β€² (𝑝) = 𝐿/ √ 𝑝 and 𝑦 β€² (𝑝) = 𝐿 √ 𝑝. Hence, the real reserves π‘₯ (𝑝) and 𝑦(𝑝) at price 𝑝 (i.e. the amounts of tokens the position actually consists of) can be calculated as follows.

π‘₯ (𝑝) = π‘₯ β€² (𝑝) βˆ’ π‘₯ β€² (𝑝𝑏 ) = 𝐿 1 √ 𝑝 βˆ’ 1 √ 𝑝𝑏 𝑦(𝑝) = 𝑦 β€² (𝑝) βˆ’ 𝑦 β€² (π‘π‘Ž) = 𝐿 √ 𝑝 βˆ’ √ π‘π‘Ž Note that the formulas above only hold for 𝑝 ∈ [π‘π‘Ž, 𝑝𝑏 ]. When the price is not in this range, we have π‘₯ (𝑝) = π‘₯ (π‘π‘Ž) and 𝑦(𝑝) = 0 for 𝑝 < π‘π‘Ž as well as π‘₯ (𝑝) = 0 and 𝑦(𝑝) = 𝑦(𝑝𝑏 ) for 𝑝 > 𝑝𝑏 . The equations (1) can be used to calculate the current value of a liquidity position. In our case, asset π‘Œ will always be USDC, a stablecoin pegged to the US Dollar. At price 𝑝, the liquidity position, consists of 𝑦(𝑝) USDC and π‘₯ (𝑝) units of the second token. The latter amount is worth π‘₯ (𝑝)𝑝 in USDC, meaning the total value of the position is 𝑦(𝑝) + π‘₯ (𝑝)𝑝

As an illustration, consider the following example. Consider an ETH-USDC pool and assume the current price of ETH is 2000 USDC. Two liquidity providers 𝐴 and 𝐡 both start with a position worth 1000 USDC. LP 𝐴 chooses the range [1818, 2200], while LP 𝐡 chooses [1667, 2400]. According to (1), this means that they provide about 240 and 128 units of liquidity, respectively. If ETH’s price now falls to 1900, the position of LP 𝐴 will consist of 288.23 USDC and ETH worth 739.40 USDC which adds up to 967.63 USDC. LP 𝐡’s position on the other hand consists of 354.54 USDC and ETH worth 617.27 USDC, i.e. 971.81 USDC in total. In particular, the LP with the smaller interval suffered a larger loss. On the other hand, LP A earns 240/128 = 1.875 times more fees on trades occurring in the range [1818, 2200] than LP B

In Uniswap v3, LPs cannot choose liquidity range completely arbitrarily. Instead, the price range is divided by so-called ticks which can be chosen as boundaries for liquidity ranges. The ticks are located at 1.0001𝑖 for 𝑖 ∈ Z. For every pool, a tick spacing 𝑑𝑠 is specified, and only ticks with 𝑑𝑠 |𝑖 may be used

Last updated