> ## 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.

# DBC Fee Calculation

> How trading fees are calculated and distributed in DBC pools, including base fee, dynamic fee, and the fee split between protocol and creator.

DBC Pools earn a trading fee from traders when they perform a swap. The fees can be collected in two ways:

* Quote only
* Quote + Base

<Note>DBC fees can be fee shared between the launchpad partner and the token pool creator.</Note>

# Total Trading Fee

The total swap fee ($f_s$) will have two components:

1. **A base fee** ($f_b$)
2. **A variable fee** ($f_v$)

The **total swap fee** is calculated as:

```math theme={"system"}
f_s = f_b + f_v
```

The variable fee ($f_v$) is a function of real-time price volatility. The fee rate will be applied to the swap amount in each liquidity bin and distributed proportionally to the LPs in that bin.

LPs can claim these fees whenever they are available.

## Base Fee

The base fee of a pool can be configured by the pool creator in the following ways:

* **Fixed Base Fee**: A fixed fee that is applied to the swap amount.
* **Fee Scheduler**: A fee decay mechanism that decays the fee from a high starting fee to an ending fixed base fee over a period of time. The ending fee will be the fixed base fee of the pool after the fee scheduler is finished.
* **Rate Limiter**: A fee slope mechanism that starts at a fixed base fee and increases the fee depending on the buy amount. The fee after the rate limiter is finished will be the fixed base fee of the pool.

<Note>You can only choose one of the three options for the base fee.</Note>

### Fixed Base Fee

Fixed base fee is a fixed fee that is applied to the swap amount. The fee can range from 0.25% to 99%. It is specified in the config key used for the pool creation.

### Fee Scheduler

Fee scheduler is a fee decay mechanism that decays the fee from starting fee to an ending base fee over a period of time.

The fee math calculation for the scheduler can be found [here](/anti-sniper-suite/fee-time-scheduler/fee-time-scheduler-math).

### Rate Limiter

Rate limiter is a fee slope mechanism that starts at a fixed base fee and increases the fee depending on the buy amount

The fee math calculation for the rate limiter can be found [here](/anti-sniper-suite/rate-limiter/rate-limiter-math).

## Dynamic Fee (Variable Fee)

The variable fee is the core of the dynamic fee mechanism. It increases with market volatility.

```math theme={"system"}
f_v = (v_a \times s)^2 \times C / 100000000000
```

where:

* **Volatility Accumulator** ($v_a$): A measure of recent price volatility
* **Bin Step** ($s$): A parameter that defines the price granularity for measuring volatility
* **Variable Fee Control** ($C$): A parameter to control the magnitude of the variable fee

### Volatility Accumulator

The Volatility Accumulator tracks price movements. It's updated with every swap.

```math theme={"system"}
v_a = \min(v_{max}, v_r + \Delta p \times 10000)
```

where:

* **Max Volatility Accumulator** ($v_{max}$): A cap on the volatility measure to prevent fees from becoming excessively high
* **Volatility Reference** ($v_r$): A decayed value of the volatility accumulator
* **Price Change** ($\Delta p$): The price change since the last reference update, measured in "bins"

#### Price Change

The price change is calculated based on the change in the square root of the price.

```math theme={"system"}
\Delta p = (\sqrt{p_c / p_r} - 1) / s \times 2
```

where $p_c$ is current price and $p_r$ is reference price.

#### Volatility Decay

To ensure that the dynamic fee reflects recent volatility, the Volatility Reference decays over time.

```math theme={"system"}
v_r = v_a \times R / 10000
```

The decay mechanism is based on the time elapsed since the last significant trade:

* If elapsed time \< filter period: No change. This ignores very high-frequency trades.
* If filter period ≤ elapsed time \< decay period: The volatility reference is reduced.
* If elapsed time ≥ decay period: The volatility reference is reset to 0. This happens if there are no significant trades for an extended period.

# Max Dynamic Fee on DBC for Typescript SDK Build Curve functions

If you use any of the `buildCurve` helper functions in the DBC Typescript SDK, the max dynamic fee on DBC when toggled `true` is less than or equals to 20% of the Base Fee.

Example:

* Base Fee = 1%
* Dynamic Fee = 0.2%
* Total Trading/LP Fee = 1.2%

# Protocol Fees

Protocol Fee is a percentage of the Total Trading Fee (i.e. base + dynamic/variable fee).

**Current Protocol Fees:** **20%** Protocol Fee and **80%** Trading Fee for virtual liquidity positions.

Protocol fees are collected as either Quote token, or Quote + Both tokens, depending on each pool’s configuration.

## Swaps

Swap hosts (such as Jupiter, Photon, or trading bots) can include a referral account in the swap transaction to receive a **Referral Fee** equal to **20%** of the protocol fee.

# Protocol Migration Fee

A fixed **0.2% (20 bps) protocol migration fee** is applied during migration from the DBC bonding curve to the graduated DAMM pool. This fee is deducted from the quote reserve during migration and is separate from any `migrationFee` configured by the partner.

# Post-Migration Fee Modes (DAMM v2 Graduated Pools)

When a DBC pool graduates and migrates to DAMM v2, the fee collection behavior is controlled by the `collectFeeMode` set in the `migratedPoolFee` config. There are three modes available:

## Mode 0 — QuoteToken (OnlyB)

Fees from all trades are collected entirely in the quote token (e.g. SOL or USDC), regardless of trade direction. Maps to DAMM v2’s `OnlyB` collect fee mode.

## Mode 1 — OutputToken (BothToken)

Fees are collected in the output token of each swap. For a buy (quote → base), the fee is in the base token. For a sell (base → quote), the fee is in the quote token. Maps to DAMM v2’s `BothToken` collect fee mode.

## Mode 2 — Compounding

Fees are not distributed as claimable amounts. Instead, they are automatically reinvested back into the LP position, compounding the liquidity value over time.

The compounding fee rate is specified in basis points via `compoundingFeeBps`:

```math theme={"system"}
\text{compounded amount} = \text{fee collected} \times \frac{\text{compoundingFeeBps}}{10000}
```

<Note>
  When `collectFeeMode` is set to `2` (Compounding), `compoundingFeeBps` must be a non-zero value. When using any other mode, `compoundingFeeBps` must be `0`.
</Note>

### DBC to DAMM v2 Fee Mode Mapping

| DBC `collectFeeMode` | DAMM v2 mode    |
| -------------------- | --------------- |
| 0 (QuoteToken)       | 1 (OnlyB)       |
| 1 (OutputToken)      | 0 (BothToken)   |
| 2 (Compounding)      | 2 (Compounding) |
