# Get Pair Reserves

Fetch complete liquidity distribution across all bins in a pair, including reserves and accumulated fees. This method provides a comprehensive view of the entire liquidity landscape.

### Prerequisites

Before fetching reserves:

* Have a valid LBPair object from `getPair()`
* Understand the difference between reserves and fees
* Be prepared to handle potentially large datasets

### Basic Usage

```typescript
// Get pair first
const pair = await sdk.Pair.getPair(pairAddress);

// Fetch all bin reserves
const reserves = await sdk.Pair.getPairReserves(pair);

console.log(`Total bins with liquidity: ${reserves.length}`);

// Display first few bins
reserves.slice(0, 5).forEach(bin => {
  console.log(`Bin ${bin.id}:`, {
    reserveX: bin.reserve_x.toString(),
    reserveY: bin.reserve_y.toString(),
    feeX: bin.fee_x.toString(),
    feeY: bin.fee_y.toString()
  });
});
```

### Method Signature

```typescript
async getPairReserves(pair: LBPair): Promise<BinReserves[]>
```

#### Returns

Array of `BinReserves` objects sorted by bin ID:

```typescript
interface BinReserves {
  id: number;           // Bin ID
  reserve_x: bigint;    // Token X liquidity
  reserve_y: bigint;    // Token Y liquidity  
  fee_x: bigint;        // Accumulated X fees
  fee_y: bigint;        // Accumulated Y fees
}
```

### Understanding the Data

#### Reserves vs Fees

* **Reserves**: Liquidity available for trading
* **Fees**: Accumulated trading fees not yet collected
* **Total**: reserves + fees = total bin value

```typescript
const reserves = await sdk.Pair.getPairReserves(pair);

reserves.forEach(bin => {
  const totalX = bin.reserve_x + bin.fee_x;
  const totalY = bin.reserve_y + bin.fee_y;
  
  console.log(`Bin ${bin.id} total value:`, { totalX, totalY });
});
```

### Practical Examples

#### Calculate Total Value Locked (TVL)

```typescript
const reserves = await sdk.Pair.getPairReserves(pair);

let totalReserveX = 0n;
let totalReserveY = 0n;
let totalFeesX = 0n;
let totalFeesY = 0n;

reserves.forEach(bin => {
  totalReserveX += bin.reserve_x;
  totalReserveY += bin.reserve_y;
  totalFeesX += bin.fee_x;
  totalFeesY += bin.fee_y;
});

console.log("Pair TVL:", {
  reservesX: totalReserveX,
  reservesY: totalReserveY,
  uncollectedFeesX: totalFeesX,
  uncollectedFeesY: totalFeesY
});
```

#### Find Liquidity Distribution

```typescript
const reserves = await sdk.Pair.getPairReserves(pair);
const activeId = pair.parameters.active_id;

// Categorize bins by position relative to active
const distribution = {
  below: reserves.filter(bin => bin.id < activeId),
  active: reserves.filter(bin => bin.id === activeId),
  above: reserves.filter(bin => bin.id > activeId)
};

console.log("Liquidity distribution:", {
  binsBelow: distribution.below.length,
  binsAbove: distribution.above.length,
  hasActiveBin: distribution.active.length > 0
});
```

#### Analyze Fee Generation

```typescript
const reserves = await sdk.Pair.getPairReserves(pair);

// Find bins with highest accumulated fees
const topFeeBins = reserves
  .filter(bin => bin.fee_x > 0n || bin.fee_y > 0n)
  .sort((a, b) => {
    const totalFeesA = a.fee_x + a.fee_y;
    const totalFeesB = b.fee_x + b.fee_y;
    return Number(totalFeesB - totalFeesA);
  })
  .slice(0, 10);

console.log("Top 10 bins by accumulated fees:", topFeeBins);
```

#### Create Liquidity Heatmap Data

```typescript
const reserves = await sdk.Pair.getPairReserves(pair);
const binStep = Number(pair.binStep);

const heatmapData = reserves.map(bin => ({
  binId: bin.id,
  price: getPriceFromBinId(bin.id, binStep),
  liquidity: bin.reserve_x + bin.reserve_y,
  fees: bin.fee_x + bin.fee_y
}));

// Use for visualization
console.log("Heatmap data ready:", heatmapData.length, "points");
```

### Performance Considerations

* Fetches **all** bins with liquidity (no range limit)
* Uses pagination internally for large datasets
* May return hundreds of bins for active pairs
* Consider caching results for repeated analysis

### Differences from getPairBins

| Feature     | getPairReserves           | getPairBins             |
| ----------- | ------------------------- | ----------------------- |
| Range       | All bins with liquidity   | Specified range only    |
| Fees        | Includes accumulated fees | Reserves only           |
| Performance | Slower for large pairs    | Faster for small ranges |
| Use Case    | Complete analysis         | Targeted inspection     |

### Related Topics

* [Get Pair Bins](/integration/dlmm/typescript-sdk/trading-pairs/get-pair-bins.md) - Query specific bin ranges
* [Calculate Position Fees](/integration/dlmm/typescript-sdk/fees-and-analytics/calculate-position-fees.md) - Fee analysis
* [Position Value](/integration/dlmm/typescript-sdk/fees-and-analytics/position-value.md) - Calculate total worth


---

# 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/integration/dlmm/typescript-sdk/trading-pairs/get-pair-reserves.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.
