# Fees and Incentives

## Overview

Fees in Fusion AMM are a critical component, distributed uniquely based on the interaction type. This section outlines how fees are calculated and allocated across different scenarios.

## Swap Fees

Swapping assets in a FusionPool incurs fees determined by the `fee_rate` field in the FusionPool account. This rate apply uniformly, whether the swap interacts with concentrated liquidity or limit order liquidity, ensuring consistent fee calculations across pool types.

## Limit Orders

Limit orders incur fees only when closed, not when opened, and are paid in the output token. The fee is calculated using the `order_protocol_fee_rate` field in the FusionPool account.

Beyond enabling precise price trading, limit orders provide liquidity for swaps, earning fees when trades execute at their specific price point (tick). These earned fees, like incurred fees, are collected upon closure and are accrued at the order’s exact price, not the entire tick.

## Concentrated Liquidity

Swaps in FusionPools generate fees for concentrated liquidity positions, similar to other CLMMs. Limit orders, being highly concentrated at a single price, increase price resistance when contributing liquidity, impacting swap dynamics. To ensure fairness, Fusion AMM allocates a portion of fees from swaps interacting with limit order liquidity to concentrated liquidity position owners. Let's call the ratio between these type of fees: _Concentrated Liquidity/Limit Orders Rebate Ratio_. These fees, tracked as `clp_reward_rate` in a FusionPool account, prevent penalization of position owners resulting from increased price resistance limit order prices.&#x20;

## Examples

### Scenario 1: Concentrated Liquidity Swap

{% hint style="info" %}
* Liquidity Pool: **SOL/USDC**
* Swap direction: **USDC -> SOL**
* Swap Input Amount: **1000** USDC
* Pool Price: **150.00** USDC per SOL
* Swap Fee Rate: **0.1%**
* Protocol Fee Rate: **10%**
* Liquidity: **concentrated liquidity** is only used for the swap
{% endhint %}

#### 1. Swap Fee

Total fees paid by the user who executed the swap in the form of the input token:

```
swap_fee = input_amount * fee_rate
```

&#x20;   _swap\_fee = 1000 \* 0.1% = 1.0 USDC_

#### 2. Liquidity Providers Incentives and Protocol Fee

The protocol fee is deducted from the swap fee amount, then transferred to the DefiTuna Staking program and distributed proportionally among TUNA token holders.

```
protocol_fee = swap_fee * protocol_fee_reate
```

&#x20;   _protocol\_fee = 1.0 \*10% = 0.10 USDC_

The liquidity providers' incentive is equal to the swap fee minus the protocol fee. It goes to concentrated liquidity positions active at the tick where the swap occurs.

```
clp_fee = swap_fee - protocol_fee

```

&#x20;   _clp\_fee = 1.0 - 0.10 = 0.90 USDC_

### Scenario 2: Limit Order Liquidity Swap

{% hint style="info" %}
* Liquidity Pool: **SOL/USDC**
* Swap direction: **USDC -> SOL**
* Swap Input Amount: **1000** USDC
* Pool Price: **150.00** USDC per SOL
* Swap Fee Rate: **0.1%**
* Order Protocol Fee Rate: **20%**
* Concentrated Liquidity Providers Reward Rate: **20%**
* Liquidity: the current price is exactly at the tick price, and only **limit order liquidity** is used for the swap
{% endhint %}

#### 1. Swap Fee

Total fees paid by the user who executed the swap in the form of the input token:

```
swap_fee = input_amount * fee_rate
```

&#x20;   _swap\_fee = 1000 \* 0.1% = 1.0 USDC_

This swap fee is distributed between limit order and concentrated liquidity providers (see below).

#### 2. Liquidity Providers Incentives and Protocol Fee

The liquidity providers' fee equals the swap fee minus the protocol fee. It is distributed between limit order liquidity providers (OLD) and concentrated liquidity providers (CLP) according to the pool's CLP reward rate and order protocol fee.

The protocol fee is deducted from the swap fee amount, then transferred to the DefiTuna Staking program and distributed proportionally among TUNA token holders.

```
protocol_fee = swap_fee * order_protocol_fee_reate
```

&#x20;   _protocol\_fee = 1.0 \* 20% = 0.20 USDC_

```
clp_fee = (swap_fee - protocol_fee) * clp_reward_rate
olp_fee = (swap_fee - protocol_fee) * (1 - clp_reward_rate)

```

&#x20;   _clp\_fee = (1.0 - 0.20) \* 20% = 0.16 USDC_\
&#x20;   _olp\_fee = (1.0 - 0.20) \* (100% - 20%) = 0.64 USDC_\
&#x20;   \
&#xNAN;_&#x63;lp\_fee_ goes to concentrated liquidity positions active at the tick where the swap occurs.\
&#xNAN;_&#x6F;lp\_fee_ goes to limit orders at the price point where the swap is executed.

### Scenario 3: Closing a filled limit order

{% hint style="info" %}
* Liquidity Pool: **SOL/USDC**
* Limit Order Direction: **USDC -> SOL**
* Limit Order Size: **1500** USDC
* Limit Order Execution Price: **150.00** USDC per SOL
* Swap Fee Rate: **0.1%**
* Limit Order Protocol Fee Rate: **20%**
* Concentrated Liquidity Providers Reward Rate: **10%**
* Fill Rate: **100%** (the limit order is fully filled)
{% endhint %}

#### 1. Limit order output amount

```
output_amount = input_amount * order_execution_price * fill_rate
```

&#x20;   _output\_amount = 1500 / 150 \* 100% = 10 SOL_

The output amount is not the final amount the user will receive when the order is closed. Fees and rewards must be applied to calculate the final amount.

#### 2. Limit Order Liquidity Provider Reward

The limit order liquidity provider's reward is a portion of the swap fee paid by users executing trades. See [Scenario 1: Concentrated Liquidity Swap](#scenario-1-concentrated-liquidity-swap) for a detailed explanation.

```
olp_fee = swap_fee * (1 - order_protocol_fee) * (1 - clp_reward_ratio)
```

&#x20;   _olp\_fee ≈ 0.01 \* (100% - 20%) \* (100% - 10%) = 0.0072 SOL_

#### 3. Total output amount received upon closing the limit order

```
total_output_amount = output_amount + olp_fee
```

&#x20;   _total\_output\_amount = 10 + 0.0072 = 10.0072 SOL_
