> ## Documentation Index
> Fetch the complete documentation index at: https://docs.meteora.ag/llms.txt
> Use this file to discover all available pages before exploring further.

# Collect Fee Modes

> The three ways DAMM v2 pools can collect trading fees: BothToken (both tokens), OnlyB (quote only), and Compounding (auto-reinvest into liquidity).

## Overview

Every DAMM v2 pool has a `collectFeeMode` that determines how trading fees flow to LPs. This is set at pool creation and cannot be changed.

| Mode          | Value | Fee Token(s)              | Single-Sided | Price Range     |
| ------------- | ----- | ------------------------- | ------------ | --------------- |
| `BothToken`   | `0`   | Token A + Token B         | ✅            | Any             |
| `OnlyB`       | `1`   | Token B only              | ✅            | Any             |
| `Compounding` | `2`   | Token B (auto-reinvested) | ❌            | Full range only |

***

## BothToken (mode 0)

Fees accumulate in the output token of each swap. When a trader swaps A→B, the fee is taken from the output (token B). When they swap B→A, the fee is taken from the output (token A).

**LP fee claim:** Separate `claimPositionFee` instruction. Both `fee_a_pending` and `fee_b_pending` on the position are claimable.

**Use when:** You want LPs to accumulate fees in both tokens — typical for symmetric liquidity provision.

***

## OnlyB (mode 1)

All fees are collected in token B (the quote token), regardless of swap direction. For A→B swaps, the fee is taken from the output token (token B) directly. For B→A swaps, the fee is taken from the output token (token A) and then converted to the quote token (token B) internally.

**LP fee claim:** Only `fee_b_pending` accumulates. `fee_a_pending` is always 0.

**Use when:** LPs prefer a single, predictable fee token. Common for one-sided launches where token A is the new token and token B is SOL/USDC.

***

## Compounding (mode 2)

The most distinctive mode. A configurable percentage of each trade's LP fee (`compoundingFeeBps`) is **automatically reinvested** back into the pool's reserves as token B rather than being held for claiming. The remainder is still claimable.

### How it works

```
Total Trading Fee
  ├── Protocol Fee  (protocol_fee_percent % of total trading fee)
  └── LP Fee (remainder)
        ├── compoundingFeeBps / 10000 → added to pool token B reserves (grows pool liquidity)
        └── remainder → fee_b_pending (claimable by LP)
```

`compoundingFeeBps` is a u16 (0–10000). E.g., `5000` = 50% of LP fees compound, 50% claimable.

### Constraints

<Warning>
  * **Full range only** — Compounding pools use `MIN_SQRT_PRICE` to `MAX_SQRT_PRICE`. Custom price ranges are not supported.
  * **Balanced pools only** — Both `tokenAAmount` and `tokenBAmount` must be > 0. One-sided deposits cause a `DEAD_LIQUIDITY` error.
  * `compoundingFeeBps` must be > 0 when `collectFeeMode = 2` (`InvalidCompoundingFeeBps` error if zero).
</Warning>

### Swap result fields

In compounding mode, the swap result exposes two separate fee fields:

| Field            | Description                           |
| ---------------- | ------------------------------------- |
| `claimingFee`    | Portion the LP can claim later        |
| `compoundingFee` | Portion reinvested into pool reserves |

For non-compounding modes, `compoundingFee = 0` and `claimingFee = tradingFee`.

### Reading from events

The `EvtSwap2` event emits `collect_fee_mode` on every swap, so you can filter events by mode to track fee behaviour.

***

## Choosing a Mode

<AccordionGroup>
  <Accordion title="I'm doing a token launch and want simplicity">
    Use **OnlyB (mode 1)**. Fees accumulate in your quote token (SOL/USDC), LPs get a clean single-token yield, and it works with one-sided deposits for a bootstrap launch.
  </Accordion>

  <Accordion title="I want LPs to earn fees in both my token and SOL/USDC">
    Use **BothToken (mode 0)**. LPs benefit from fee accumulation in the base token if it appreciates.
  </Accordion>

  <Accordion title="I want liquidity to grow automatically over time">
    Use **Compounding (mode 2)**. Pool depth increases with every trade. Best for mature, full-range pools with long-term LPs who prefer position growth over regular fee claims.
  </Accordion>
</AccordionGroup>
