> For the complete documentation index, see [llms.txt](https://docs.bean.exchange/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.bean.exchange/spot-market/dlmm/dynamic-fee.md).

# Dynamic Fee

Bean's DLMM introduces a **Dynamic Fee** system — a smart, self-adjusting mechanism that tunes trading fees in real-time, based on volatility, price movement, and deposit behavior. The goal is simple: reward LPs fairly during volatile periods, keep costs low for traders during calm times, and make the protocol sustainable long-term.

#### **Core Objectives**

| Stakeholder                   | Goals                                                                                                                      |
| ----------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
| **Liquidity Providers (LPs)** | <p>✅ Volatility-adjusted returns</p><p>✅ Minimum guaranteed base fees</p><p>✅ Protection against toxic/imbalanced flow</p> |
| **Traders**                   | <p>✅ Lower fees during stable periods</p><p>✅ Predictable and transparent pricing</p><p>✅ Fair cost during volatility</p>  |
| **Protocol**                  | <p>✅ Consistent revenue share</p><p>✅ Adaptive market efficiency</p><p>✅ Built-in risk controls</p>                        |

***

## 1. Fee Architecture

Bean calculates the total trading fee as:

$$
TotalFee = Base Fee + Variable Fee
$$

{% hint style="info" %}
Base Fee : The fixed minimum charged regardless of volatility

Variable Fee: Increases as price volatility rises
{% endhint %}

All calculations utilize 9-decimal precision (1,000,000,000 = 100%)

System safeguards:

* Max Total Fee: 10%
* Max Protocol Share: 25% of total fees

### Base Fee:

Provides a fixed floor to reward LPs even in calm markets.&#x20;

$$
Base Fee = Base Factor \* Bin Step \* 10
$$

{% hint style="info" %}

* Base Factor: Set during pool creation (e.g., 100)
* Bin Step: The price gap between adjacent bins (e.g., 5)
* 10: Fixed scaling Constant
  {% endhint %}

*Think of this as your guaranteed minimum paycheck.*

### Variable Fee:

Encourages LPs to stay in volatile markets by rewarding them with higher fees.

$$
Variable Fee = (Volatility Accumulator × Bin Step)² × Variable Fee Control ÷ 100
$$

{% hint style="info" %}

* Volatility Accumulator: Measures recent price fluctuations
* Variable Fee Control: Adjusts sensitivity (e.g., 2500 = 0.25x)
  {% endhint %}

*The more the price jumps around, the more LPs earn.*

### Worked Example:

Given:&#x20;

* Base Factor = 100
* Bin Step = 5
* Volatility Accumulator = 50,000
* Control = 2,500

Results:&#x20;

```
Base Fee = 100 × 5 × 10 = 5,000 (0.0005%)
Variable Fee = (50,000 × 5)² × 2,500 ÷ 100 = 1,562,500,000,000 (0.156%)
Total Fee = 0.1565%
```

***

## 2. Volatility Management System

To avoid manipulation and overreaction to short-term noise, Ferra introduces a decay-based tracking system.

### Accumulator Formula:

$$
Volatility Accumulator = Volatility Reference + (Current Bin ID − Reference Bin ID) × 10,000
$$

Tracks how far price has moved from its last "anchor" bin.

### Time-Weighted Decay Logic:

| Time Passed Since Last Update (Δt) | Behavior                              |
| ---------------------------------- | ------------------------------------- |
| **Δt < t\_f (Filter)**             | No update — blocks spam/MEV           |
| **t\_f ≤ Δt < t\_d (Decay)**       | Volatility decays by reduction factor |
| **Δt ≥ t\_d (Reset)**              | Full reset of volatility tracker      |

*Think of it like a memory that forgets old volatility if things calm down.*

### Worked Example:

```
T=0: 8-bin move → Accumulator = 80,000
T=45s: 3-bin move → Accumulator = 70,000 (decay applies)
T=350s: 1-bin move → Reset to 10,000
```

***

## 3. Specialized Fee Types

### Composition Fee:

Prevents LP manipulation from imbalanced deposits (e.g., only one token).

$$
Composition Fee = Excess Amount × Total Fee × (Total Fee + 1)
$$

* Triggered when a deposit skews the ideal token ratio.
* Applies **only** in active bins.

### Flash Loan Fee:

Charged on flash loans independently of volatility.&#x20;

$$
Flash Loan Fee = Loan Amount × Flash Loan Rate ÷ 1,000,000,000
$$

* Max Fee: 10%
* Flat Rate: Does not vary with volatility

### Worked Example:&#x20;

Given:&#x20;

* Excess deposit: 300 USDC
* Total fee: 1%

Results:&#x20;

```
Composition Fee = 300 × 0.01 × 1.01 = 3.02 USD
```

***

## 4. Fee Distribution Logic

Fees are distributed proportionally based on LP contribution per bin.

### Bin-Level Fee Growth:

$$
Fee Growth Per Unit = Accumulated Fees ÷ Total Bin Liquidity
$$

### LP Earnings Formula:

$$
LP Fees = LP Liquidity × (Current Fee Growth - Last Claimed Growth)
$$

Ensures long-term LPs earn more if they stay in active bins.

### Worked Example:&#x20;

Given:&#x20;

* Total Fee: 100 USDC
* Protocol Share: 20%

Results:&#x20;

```
Protocol = 100 × 20% = 20 USDC  
LPs = 80 USDC
```

***

## 5. Configuration Parameters

| Type                          | Parameters                                                                                      |
| ----------------------------- | ----------------------------------------------------------------------------------------------- |
| Static (Set on Pool Init)     | Base Factor, Variable Fee Control, Protocol Share, Max Volatility, t\_f, t\_d, Reduction Factor |
| Dynamic (Updated with Trades) | Volatility Accumulator, Reference Bin, Last Update Timestamp                                    |
