# Fee Calculation

## Introduction

The AMM pool manages liquidity by placing limit orders at specific price ticks, and fees are incurred when these orders are matched with traders' orders. To ensure that traders have a consistent experience whether trading with the AMM pool or other users, the fee structure remains uniform across the trading pair and its corresponding AMM pools.

For simplicity, consider trades in the ETH/USDT pair, with ETH as the base asset and USDT as the quote asset, assuming a fixed fee rate $$r$$ and an AMM pool with tick spacing $$ts$$.

#### Fee Calculation when AMM's Buy Order is Filled&#x20;

When a buy order from the AMM is executed at $$Tick\_i$$, the fee is derived solely from the trading fee, paid by the trader in USDT. If the AMM’s buy order of size $$s$$ is fulfilled, the trading fee is calculated as:

$$
TradingFee=Tick\_i \times s \times r
$$

#### Fee Calculation when AMM's Sell Order is Filled

When a sell order from the AMM is executed at , the fee includes both the trading fee and the spread reward. From the trader's standpoint, the fee is paid in ETH. If the AMM’s sell order of size $$s$$ is fulfilled, the trading fee is:

$$
TradingFee=s \times r
$$

Since sell orders are placed at higher prices than buy orders within the same interval, each fulfillment generates a spread reward due to the price spread $$ts$$:

$$
SpreadReward=s \times ts
$$

In summary, the fee calculations for AMM orders ensure that traders experience consistent fees whether they trade with the AMM pool or other users. Additionally, AMM sell orders placed at higher prices than buy orders within the same interval always generate a spread reward, benefiting liquidity providers.

## Example: Fee Calculation

<figure><img src="/files/SeoJBNLXJrxPGSLpCu7o" alt=""><figcaption></figcaption></figure>

To clarify how AMM fees are calculated, let's revisit the previous exmaple with a trading fee rate of 0.1% for the ETH/USDT pair.

#### Trade 1

Alice’s buy order is filled for 0.7 ETH at a price of 3800 USDT. The AMM's order contributes 0.4 ETH, while the remaining 0.3 ETH comes from other users. Here, $$s=0.4$$, $$ts=1$$ , and $$r=0.001$$.

The total trading fee collected by the AMM pool is:

$$
TradingFee=0.4\times0.001=0.0004 \text{ ETH}
$$

Additionally, the spread reward collected by the AMM pool is:

$$
SpreadReward=0.4 \times 1 = 0.4 \text{  USDT}
$$

Thus, the total AMM fees amount to ( 0.0004 ETH + 0.4 USDT ). If an LP contributed 0.1 ETH in the interval \[3799, 3800], they would receive 25% of the collected fees from this trade, equating to ( 0.0001 ETH + 0.1 USDT ).

#### Trade 2

The remaining 0.3 ETH of Alice’s buy order is filled at a price of 3801 USDT, entirely by the AMM's order. Here, $$s=0.3$$, $$ts=1$$ , and $$r=0.001$$.

The calculations are:

$$
TradingFee=0.3\times0.001=0.0003 \text{ ETH}
$$

$$
SpreadReward=0.3 \times 1 = 0.3 \text{  USDT}
$$

Therefore, from this trade, a total of ( 0.0003 ETH + 0.4 USDT ) will be added to the AMM pool and distributed proportionally among the LPs within the interval \[3800, 3801].

## Protocol Fee

To cover the hardware costs associated with SNARK proof generation, the Vessel protocol takes a small percentage of all AMM fees. This protocol fee is set as a percentage and is encoded directly into the circuit.


---

# 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://vesselfinance.gitbook.io/vessel/vaelob/fee-calculation.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.
