HyperByte

How the fee calculated in uniswap-v2?

2026-07-30

Download uniswap whitepaper: https://app.uniswap.org/whitepaper.pdf

it’s not very friendly to read, I learned so hard, then this is my summaries.

Origin AMM formula:


Assume the fee is 0.3% (in uniswapv-v2, this is a fixed fee), dx is the token you’re trying to exchange, the fee will be charged on this dx, so we just change the dx of the formula above like list:

this is the dy we correctly will get. And, this formula actually is what the getAmountOut function does, look:

function getAmountOut(...) {
    ...
    uint amountInWithFee = amountIn.mul(997);  //1-0.003=0.997
    ...
}

Once the fee is taken out, it flows into the pool, not to a specific account, so the liquidity will increase as swaps accumulate.

Here is the breakdown of the flow.

​ let φ=1/6,

Sm goes to project team, the rest goes to the LPs.

← Back to Home