Fee Calculation
Last updated
Last updated
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 and an AMM pool with tick spacing .
When a buy order from the AMM is executed at , the fee is derived solely from the trading fee, paid by the trader in USDT. If the AMM’s buy order of size is fulfilled, the trading fee is calculated as:
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 is fulfilled, the trading fee is:
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 :
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.
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.
The total trading fee collected by the AMM pool is:
Additionally, the spread reward collected by the AMM pool is:
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 ).
The calculations are:
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].
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.
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, , , and .
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, , , and .