> For the complete documentation index, see [llms.txt](https://docs.ferra.ag/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ferra.ag/integration/dlmm/typescript-sdk/getting-started/key-concepts.md).

# Key Concepts

### Bins

Bins are the core building blocks of DLMM. Each bin represents a discrete price level where liquidity can be deposited.

#### Key Properties

* **Discrete Prices**: Each bin has one specific price
* **Fixed Width**: Price increment determined by bin step
* **Liquidity Container**: Holds reserves of both tokens
* **Zero Slippage**: Trades within a bin have no price impact

### Bin IDs

Every bin has a unique ID that determines its price.

#### ID System

* **Base ID**: 8388608 represents price = 1.0
* **Lower IDs**: Below 8388608 = price < 1.0
* **Higher IDs**: Above 8388608 = price > 1.0

#### ID to Price Formula

```typescript
price = (1 + binStep/10000) ^ (binId - 8388608)
```

#### Examples

```typescript
import { BinMath } from '@ferra-labs/dlmm'

// Bin 8388608 = price 1.0
const price1 = BinMath.getPriceFromId(8388608, 10, 9, 6)
// Result: 1.0

// Bin 8388618 = higher price
const price2 = BinMath.getPriceFromId(8388618, 10, 9, 6)
// Result: ~1.01 (10 bins × 0.1% = 1% higher)
```

### Bin Steps

The bin step defines the price increment between adjacent bins.

#### Common Bin Steps

| Bin Step | Percentage | Use Case             |
| -------- | ---------- | -------------------- |
| 1        | 0.01%      | Stablecoins          |
| 5        | 0.05%      | Low volatility       |
| 10       | 0.10%      | Medium volatility    |
| 20       | 0.20%      | Medium volatility    |
| 50       | 0.50%      | High volatility      |
| 100      | 1.00%      | very high volatility |
| 200      | 2.00%      | very high volatility |
| 500      | 5.00%      | very high volatility |

#### Bin Step Impact

```typescript
// Smaller bin step = tighter price ranges
binStep = 1  // 0.01% increments
// Bins: [..., 0.9999, 1.0000, 1.0001, ...]

// Larger bin step = wider price ranges  
binStep = 100 // 1% increments
// Bins: [..., 0.99, 1.00, 1.01, ...]
```

### Active Bin

The active bin is where the current market price resides.

#### Properties

* **Current Trading Price**: All swaps start here
* **Mixed Reserves**: Contains both tokens
* **Price Discovery**: Moves as liquidity is consumed

#### Active Bin Behavior

```typescript
// Get current active bin
const pair = await sdk.Pair.getPair(pairId)
const activeId = pair.parameters.active_id

// Calculate current price
const currentPrice = BinMath.getPriceFromId(
  activeId,
  Number(pair.binStep),
  9, // tokenX decimals
  6  // tokenY decimals
)
```

#### Bin Transitions

When active bin liquidity is exhausted:

1. **Buy (X→Y)**: Active bin moves up (higher ID)
2. **Sell (Y→X)**: Active bin moves down (lower ID)

### Price Calculation

#### Price from Bin ID

```typescript
const price = BinMath.getPriceFromId(
  binId,      // Bin ID
  binStep,    // Bin step (basis points)
  decimalsX,  // Token X decimals
  decimalsY   // Token Y decimals
)
```

#### Bin ID from Price

```typescript
const binId = BinMath.getIdFromPrice(
  price,      // Target price
  binStep,    // Bin step
  decimalsX,  // Token X decimals
  decimalsY   // Token Y decimals
)
```

#### Price Impact

```typescript
// Calculate bins needed for swap
const currentBin = 8388608
const targetPrice = 1.05 // 5% higher
const targetBin = BinMath.getIdFromPrice(targetPrice, 10, 9, 6)
const binsToMove = targetBin - currentBin
```

### Practical Example

```typescript
// Understanding a position across bins
const activeId = 8388608
const binStep = 20 // 0.2%

// Create position ±10 bins from active
const minBin = activeId - 10
const maxBin = activeId + 10

// Calculate price range
const minPrice = BinMath.getPriceFromId(minBin, binStep, 9, 6)
const maxPrice = BinMath.getPriceFromId(maxBin, binStep, 9, 6)

console.log(`Position range: ${minPrice} - ${maxPrice}`)
// Result: ~0.98 - 1.02 (±2% from center)
```

### Key Takeaways

1. **Bins = Price Levels**: Each bin is a discrete price point
2. **Bin ID = Price**: Higher ID means higher price
3. **Bin Step = Precision**: Smaller steps mean finer price control
4. **Active Bin = Market**: Current trading happens here
5. **No Continuous Prices**: Everything is discretized

### Next Steps

Now that you understand the concepts:

* [Create Pair](/integration/dlmm/typescript-sdk/trading-pairs/create-lb-pair.md) - Deploy with chosen bin step
* [Add Liquidity](/integration/dlmm/typescript-sdk/add-liquidity.md) - Apply distribution strategies
