This blog explains how Uniswap v3 works under the hood, focusing on concentrated liquidity, ticks, and key smart contract functions.

What Makes Uniswap v3 Different?

Unlike earlier AMMs, Uniswap v3 introduces concentrated liquidity.

Instead of providing liquidity across the entire price range (0 → ∞), liquidity providers (LPs) can choose a specific price range where their capital is active.

👉 This makes capital far more efficient.

What is Tick Spacing?

Tick spacing defines which price points (ticks) LPs are allowed to use when setting their liquidity range.

Think of ticks as grid points on the price axis.

If:

tickSpacing = 10

Then valid ticks are:

…, -20, -10, 0, 10, 20, 30, …

Example

An LP can provide liquidity between:

10 → 30 ✅
But NOT:15 → 25 ❌ (not multiples of tick spacing)

Why Does Tick Spacing Exist?

If every possible tick were allowed:

There would be millions of tick valuesStorage would explodeGas costs would increase

So tick spacing ensures:

Fewer possible positionsLower storage usageCheaper swaps

💡 Important: Tick spacing does not directly affect price, only how liquidity positions are defined.

What is a Tick?

A tick is an integer that represents a specific price level.

Uniswap defines price as:

price = 1.0001 ^ tick

Where:

price = token0 / token1tick = integer (can be negative or positive)

Intuition

+1 tick ≈ +0.01% price increase+100 ticks ≈ +1%+6931 ticks ≈ 2× price

So ticks discretize price into very fine steps.

Why Do Ticks Exist?

Ticks are not for pricing, but for liquidity accounting.

They act as boundaries where liquidity turns ON or OFF.

Without Ticks:

Continuous price checks would be neededGas costs would be very highManaging liquidity would be inefficient

With Ticks:

Liquidity activates when price enters a rangeLiquidity deactivates when price exitsEverything becomes discrete and efficient

sqrtPriceX96 (Core Representation)

Instead of storing price directly, Uniswap stores:

sqrtPriceX96 = sqrt(price) × 2⁹⁶

Why?

Solidity does not support floating-point numbersThis format (called Q96 fixed-point) allows:High precisionEfficient mathSafer calculations

💡 Most calculations in Uniswap v3 are done using this value, not raw price.

Core Functions Explained

Now let’s walk through the important functions and what they actually do.

initialize()

This is the first function called after pool deployment.

Purpose:

Sets the initial price of the pool

Input:

sqrtPriceX96

What it does:

Initializes slot0Sets the starting tick and price

👉 Without calling this, the pool cannot operate.

mint()

This function is used when adding liquidity.

Purpose:

Creates a liquidity position

Inputs:

tickLowertickUpperliquidity amount

What happens internally:

Calls _modifyPosition()Calculates how much token0 and token1 are requiredTransfers tokens from user to poolUpdates liquidity accounting

liquidityDelta

This is not a function but an important concept.

Positive → liquidity addedNegative → liquidity removed

Used internally to update positions.

_modifyPosition()

This is the core internal function for managing positions.

Responsibilities:

Validates tick rangesLoads current state (slot0)Updates liquidityCalculates token amounts required

👉 Think of this as the engine behind both mint() and burn().

_updatePosition()

Handles actual updates to a user’s position.

What it does:

Updates liquidity balancesTracks fee growthAdjusts position state

Called internally by _modifyPosition().

burn()

Used to remove liquidity.

Inputs:

tickLowertickUpperliquidity amount

What it does:

Reduces liquidity in the positionCalculates how many tokens should be returnedDoes NOT transfer tokens yet

👉 Important: It only updates accounting.

collect()

This is when tokens are actually transferred to the user.

Purpose:

Withdraw earned fees and withdrawn liquidity

What it does:

Transfers token0 and token1 to the user

👉 Separation of burn() and collect() helps optimize gas and flexibility.

Key Design Insights

Here are some deeper insights that show strong understanding:

1. Discrete Liquidity Model

Uniswap v3 converts continuous price ranges into discrete ticks → enabling efficient computation.

2. Capital Efficiency

LPs can concentrate liquidity → earn more fees with less capital.

3. Gas Optimization

Tick spacing reduces storageslot0 packs variablesFixed-point math avoids floating errors

4. Separation of Concerns

mint() → add liquidityburn() → remove liquiditycollect() → withdraw tokens

Final Thoughts

Uniswap v3 is not just an AMM — it’s a highly optimized financial engine.

Key innovations:

Concentrated liquidityTick-based accountingFixed-point math (sqrtPriceX96)Gas-efficient storage design

Github: https://github.com/kshitij011/uniswap-v3-finance

LinkedIn: https://www.linkedin.com/in/kshitijbhoite011

#blockchain #defi #uniswap #finance #solidity #smartcontracts

Understanding Concentrated Liquidity in Uniswap v3 was originally published in Coinmonks on Medium, where people are continuing the conversation by highlighting and responding to this story.

By

Leave a Reply

Your email address will not be published. Required fields are marked *