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 rr and an AMM pool with tick spacing tsts.

Fee Calculation when AMM's Buy Order is Filled

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

TradingFee=Ticki×s×rTradingFee=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 ss is fulfilled, the trading fee is:

TradingFee=s×rTradingFee=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 tsts:

SpreadReward=s×tsSpreadReward=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

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.4s=0.4, ts=1ts=1 , and r=0.001r=0.001.

The total trading fee collected by the AMM pool is:

TradingFee=0.4×0.001=0.0004 ETHTradingFee=0.4\times0.001=0.0004 \text{ ETH}

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

SpreadReward=0.4×1=0.4 USDTSpreadReward=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.3s=0.3, ts=1ts=1 , and r=0.001r=0.001.

The calculations are:

TradingFee=0.3×0.001=0.0003 ETHTradingFee=0.3\times0.001=0.0003 \text{ ETH}
SpreadReward=0.3×1=0.3 USDTSpreadReward=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.

Last updated