Concepts
Bins & ranges.
From a market-cap range to Uniswap ticks, tick spacing and bin splitting.
You think in market caps; Uniswap thinks in ticks. Here is how a range in the app becomes a list of bins on-chain.
Ticks in one paragraph
Uniswap prices live on a grid: tick i means a price of 1.0001^i (token1 per token0). Each pool has a tick spacing (for example 60 for a 0.3% V3 pool, or whatever a V4 pool chose), and positions can only start and end on multiples of it. See Uniswap: concentrated liquidity.
From your range to bins
Market caps become ticks
The app reads the pool's current tick and converts your min and max market caps into ticks around it. If the token is
token1of the pool, the direction flips: a higher token price is a lower tick.Ticks are aligned
The contract rounds the lower tick down and the upper tick up to the tick spacing, and clamps them to the usable tick range.
The range is split
It is cut into
numBinsequal slices, each a whole number of tick spacings. If the range is too narrow for the number of bins you asked for, the bin count is reduced so every bin spans at least one tick spacing.Each bin gets its liquidity
The contract computes the liquidity each bin can hold with its share of the deposit at the current price, using Uniswap's liquidity math, so it never takes more than you sent.
The price guard
Along with the range, the app sends minTick and maxTick: the current tick plus or minus your slippage. If the pool's tick is outside that window when your transaction executes, it reverts with PriceOutOfBounds. This protects you from sandwich attacks that push the price before adding liquidity.
Choosing a bin count