Liquidity Provider Fundamentals: How DEX Fees Affect “k” (Part 6)

You are currently viewing Liquidity Provider Fundamentals: How DEX Fees Affect “k” (Part 6)

Understanding k in DEXs with Trading Fees

In previous discussions, we established that k (the constant product of reserves) changes when liquidity is added or removed but remains constant during swaps – assuming no fees. However, in reality, k almost always changes due to trading fees.

This article focuses on how k evolves when swaps include fees, as liquidity provision/withdrawal does not incur fees.

Why Do Fees Impact k?

This is one of the most misunderstood concepts in DEXes.

Key Insight:

  • Fees are not charged when adding/removing liquidity – only during swaps.
  • Trading fees accumulate inside the pool, altering the reserves and thus changing k.

Let’s break it down step by step.

How a Swap with Fees Affects k

Consider a liquidity pool with:

  • x₁ reserves of Token X
  • y₁ reserves of Token Y
  • f = DEX fee (e.g., 0.3% for Uniswap)

When a Trader Swaps x₂ of Token X for Token Y

The trader receives y2,with fee (less than the no-fee scenario due to the fee deduction):

\displaystyle y_{2,\text{with fee}} = \frac{(1 - f) \times x_2 \times y_1}{x_1 + (1 - f) \times x_2}

Intuition Behind the Fee Mechanism

  • Without fees, the trader would receive y2,no fee.
  • With fees, they get y2,with fee, where the difference approximates the fee rate f:

\displaystyle \frac{y_{2,\text{no fee}}}{y_{2,\text{with fee}}} - 1 \approx f

Where does the fee go?

  • The fee is paid in the input token (Token X).
  • While the trader spends x2, only (1 – f) × x2 is used for the swap.

Calculating k Before and After Fees

1. No-Fee Scenario

After the swap, the new reserves are:

  • x1 + x2 (Token X)
  • y1 – y2,no fee (Token Y)

Thus, k remains:

\displaystyle k_{2,\text{no fee}} = (x_1 + x_2) \times ( y_1 - y_{2,\text{no fee}} ) = (x_1 + x_2) \times \left( y_1 - \frac{x_2 \times y_1}{x_1 + x_2} \right)

2. With Fee Scenario

The new reserves are:

  • x1 + x2 (Token X)
  • y1 – y2,with fee (Token Y)

Thus, k changes to:

\displaystyle k_{2,\text{with fee}} = (x_1 + x_2) \times ( y_1 - y_{2,\text{with fee}} ) = (x_1 + x_2) \times \left( y_1 - \frac{(1 - f) \times x_2 \times y_1}{x_1 + (1 - f) \times x_2} \right)

Key Takeaway

  • Each Token X → Token Y swap increases Token X reserves only.
  • Each Token Y → Token X swap increases Token Y reserves only.
  • This asymmetrically impacts k over multiple swaps.

Why Does This Matter?

The change in k helps measure total accumulated fees in the pool. This is crucial for:

  • Liquidity providers (LPs) evaluating returns.
  • Impermanent loss (IL) calculations (next topic).

Brief Summary

✅ k changes with swaps when fees are applied (but not with liquidity adjustments).
✅ Fees are paid in the input token, altering reserves asymmetrically.
✅ Tracking k helps quantify fee accumulation for LPs.

Next: Impermanent Loss and Fee Impact

Now that we understand how fees alter k, we can explore how this affects impermanent loss – the difference between holding assets in a pool versus holding them outright.

What is GHOST Chain?

GHOST Chain is a decentralized EVM bridge with a privacy layer providing a much needed cross-chain interoperability and anonimity in the web3 space.

Become Validator | GHOST Chain | ghostDAO Litepaper