# π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**

**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