Bin Mathematics

What are Bins?

Think of bins as price buckets that hold liquidity. Each bin represents a specific price point where tokens can be traded. Instead of spreading liquidity across a continuous range, DLMM splits it into these discrete bins.

Key characteristics:

  • Each bin has a unique ID

  • Bins contain reserves of both tokens (X and Y)

  • Only one bin is "active" for trading at any time

  • Price moves by jumping between adjacent bins

How Bin IDs Work

Bin IDs are 24-bit integers that directly map to price levels:

Bin ID 8388608 (2^23) = Price of 1.0 (X/Y = 1)
Bin ID > 8388608 = Price > 1.0
Bin ID < 8388608 = Price < 1.0

Important concepts:

  • Active Bin: The current trading bin where swaps occur

  • Bin Step: The price difference between adjacent bins (in basis points)

  • Bin Range: A sequence of bins where you can place liquidity

Example

For a USDC/USDT pair with 1 basis point bin step:

  • Bin 8388608: 1 USDC = 1.0000 USDT

  • Bin 8388609: 1 USDC = 1.0001 USDT

  • Bin 8388610: 1 USDC = 1.0002 USDT

This discretization enables gas-efficient trading and precise liquidity placement at exact price points.

Bin ID Calculations

Find the appropriate bin ID for any target price using the reverse price formula.

The Reverse Formula

To calculate bin ID from a target price:

Where:

  • price: Target price (X/Y ratio)

  • binStep: The step size in basis points

  • 8388608: The reference bin where price = 1.0 for example

  • Result must be rounded to nearest integer

Quick Examples

Finding bin IDs for common prices:

Code Implementation

Rounding Considerations

  • Round: For finding nearest tradeable bin

  • Floor: For conservative sell orders

  • Ceil: For conservative buy orders

Bin step guides

Choose the optimal bin step for your trading pair based on asset volatility, trading patterns, and capital efficiency needs.

What is Bin Step?

Bin step defines the price increment between adjacent bins in basis points (bps):

  • 1 bps = 0.01% price difference

  • Range: 1 to 10,000 bps

  • Affects price granularity and capital efficiency

Choosing Your Bin Step

Stable Pairs (1-10 bps)

Best for: USDC/USDT, wBTC/BTC, haSUI/SUI

Blue-chip Pairs (10-50 bps)

Best for: SUI/USDC, DEEP/USDC, WAL/USDC

Volatile Pairs (50-200 bps)

Best for: MEME/USDC, New tokens, Low liquidity pairs

Trade-offs

Bin Step
Pros
Cons

Small (1-10 bps)

• Minimal slippage

• Precise pricing

• Better for limit orders

• Liquidity spread thin

• More bins needed

• Higher gas on rebalancing

Large (100+ bps)

• Concentrated liquidity

• Fewer bins to manage

• Lower rebalancing costs

• Higher slippage

• Larger price jumps

• Less precise entries

Quick Reference

Practical Example

For SUI/USDC with 20 bps bin step:

  • Bin 8388608: $3.00

  • Bin 8388609: $3.01 (0.3% higher)

  • Bin 8388610: $3.02 (0.6% higher)

This provides good balance between capital efficiency and price precision.

Last updated