# Technical Design

### Liquidity Distribution

In CLMM, liquidity is concentrated within user-defined price ranges rather than spread uniformly. Each liquidity position is defined by a lower tick $$T\_L$$ and an upper tick $$T\_U$$, corresponding to specific prices $$P\_L$$ and $$P\_U$$. The total liquidity at any price is the sum of all active positions that include that price. When the market price moves outside a position’s range, the liquidity becomes inactive, earning no fees and potentially incurring impermanent loss.

### Tick-Based Model

CLMM discretizes the price spectrum into ticks, each representing a small price increment. For example, a tick spacing of 1 might correspond to a 0.01% price change (e.g., a multiplier of 1.0001). This tick-based model:

* **Enables Precise Liquidity Placement**: LPs can target specific price ranges, such as $100 to $110 for a token pair.
* **Reduces Computational Overhead**: Discrete ticks simplify liquidity calculations compared to a continuous price model.
* **Supports Granularity**: Smaller tick spacing allows finer control, suitable for stablecoin pairs, while larger spacing suits volatile assets.

The price at a given `tick (i)` can be calculated as: `P(i) = 1.0001^i` where (i) is the tick index, and 1.0001 is the price multiplier per tick for a 0.01% fee tier.

<figure><img src="/files/iaDeBiegTAcAH9YrHxxQ" alt=""><figcaption><p>Tick-based in Ferra's CLMM liquidity model</p></figcaption></figure>

### **Fee Structure**

<table><thead><tr><th width="191.37890625">Component</th><th>Description</th></tr></thead><tbody><tr><td>Swap Fee</td><td>Percentage charged on every trade (e.g., 0.05 %, 0.30 %, 1 %).</td></tr><tr><td>Fee Tier</td><td>Each pool has a fixed swap‑fee tier chosen at deployment. Multiple pools with different tiers can coexist for the same token pair.</td></tr><tr><td>Protocol Fee</td><td>A configurable share of the swap fee routed to the Ferra treasury. The remainder goes to LPs. It is set to 20% by default</td></tr></tbody></table>

### Fee Calculation

Fees in CLMM are collected when trades occur within a position’s active price range. The fee rate depends on the pool’s fee tier (e.g., 0.3% for volatile pairs, 0.01% for stable pairs). Fees are distributed proportionally to LPs based on their share of liquidity at the traded price. The protocol tracks fee growth per tick, allowing LPs to claim accumulated fees when they withdraw liquidity or collect earnings.

#### Mathematical Formulas

CLMM relies on mathematical formulas to manage liquidity and fees. Key equations include:

* **Liquidity Amount L**: When an LP adds liquidity, the amount of liquidity provided is calculated based on the token amounts and the price range. For a position between prices $$P\_L$$ and $$P\_U$$, the liquidity (L) is:

$$
L = \frac{\Delta y}{\sqrt{P\_U} - \sqrt{P\_L}} \quad \text{(for token Y when price is below range)}
$$

$$
L = \frac{\Delta x \cdot \sqrt{P\_L} \cdot \sqrt{P\_U}}{\sqrt{P\_U} - \sqrt{P\_L}} \quad \text{(for token X when price is above range)}
$$

Where $$\Delta X$$ and $$\Delta Y$$ are the amounts of token X and token Y provided, respectively.

* **Position Value**: The value of a position depends on the current price (P). If $$P\_L \leq P \leq P\_U$$, the position is active, and its value includes both tokens and accumulated fees.
* **Fee Growth**: Fees are tracked as “fee growth per unit of liquidity” for each tick range. When a trade occurs, the fee growth is updated, and LPs can claim fees proportional to their liquidity share.

### Position Management

LPs interact with CLMM through the following actions:

* **Minting Positions**: Create a new position by specifying a tick range and token amounts.
* **Adding Liquidity**: Increase liquidity in an existing position.
* **Removing (Burning) Positions**: Withdraw liquidity, receiving the underlying tokens and any accumulated fees.
* **Collecting Fees**: Claim earned fees without removing liquidity.

Positions are active only when the current price is within the specified range. If the price moves outside, the position earns no fees and may face impermanent loss.

### Impermanent Loss

CLMM reduces impermanent loss by allowing LPs to focus liquidity in stable price ranges, but it does not eliminate it. If the price moves outside a position’s range, the LP holds only one token (the less valuable one), potentially leading to losses compared to holding the tokens outside the pool. The concentrated nature of CLMM can amplify impermanent loss in volatile markets, requiring active position management.

### **Swap Mechanics (High‑Level)**

* User submits `amountIn` of `TokenA` for `TokenB`.
* Contract computes the maximum amount consumable before hitting the next initialized tick.
* Constant‑product math updates the pool within the current tick and deducts the swap fee.
* If `amountIn` remains, the algorithm crosses the next tick, activates its liquidity, and repeats until the full amount is swapped.
* Fee growth variables are updated so LPs can later collect their share.

### Liquidity Strategies

Unlike DLMM, a CLMM pool has only one fundamental liquidity layout, functionally similar to the Spot shape in DLMM. Your strategy therefore comes from how wide or narrow you set your price range, not from choosing different shapes. The comparison below shows how range width affects performance and maintenance.

<table><thead><tr><th>Range Strategy</th><th>Typical Width</th><th>When to Use</th><th>Pros</th><th>Const</th><th width="114.03125">Upkeep</th></tr></thead><tbody><tr><td><strong>Narrow</strong></td><td>±0.5 – 2 % around spot</td><td>High‑volume, low‑volatility pairs; active LPs</td><td>Highest fee APR per dollar</td><td>Falls out‑of‑range quickly; needs frequent re‑centering</td><td><strong>High</strong></td></tr><tr><td><strong>Medium</strong></td><td>±5 – 10 %</td><td>Range‑bound blue chips</td><td>Balanced uptime vs. efficiency</td><td>Lower APR than narrow; some upkeep</td><td><strong>Medium</strong></td></tr><tr><td><strong>Wide</strong></td><td>±20 – 50 %</td><td>Long‑term passive LPs; volatile tokens</td><td>Stays active longer; low maintenance</td><td>Capital spread thin → lower fee capture</td><td><strong>Low</strong></td></tr><tr><td><strong>Ladder</strong></td><td>Stacked narrow + medium + wide</td><td>Diversify IL risk and fee capture</td><td>Blends benefits of multiple widths</td><td>Higher gas costs; more complex</td><td><p><strong>Medium,</strong></p><p><strong>High</strong></p></td></tr></tbody></table>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ferra.ag/core-protocols/publish-your-docs/technical-design.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
