Verification checklist

  • fee is the gross fee in millionths. Liquidity providers are credited only with what remains after the protocol's integer division.
  • The low nibble and the high nibble of slot0.feeProtocol are two denominators. A reading of 100 is not 100%.
  • A swap step that has reached its target price divides by 1000000 minus fee. A flash loan divides by 1000000. The same input can differ by 9.
  • The protocol's share rounds down. A fee of 1 divided by 4 is 0, and that 1 still enters LP fee growth only when liquidity is above 0.

1. The printed 0.30% has not been split yet

A pool page prints fee 3000 as 0.30%, and that label is easy to read as the liquidity provider's yield. In the v1.0.0 pool, 3000 means the fee is cut from the input at 3000 per million. That cut still passes through slot0.feeProtocol. When the denominator is above 0, the protocol takes the integer quotient and only the remainder is added to feeGrowthGlobal. UniswapV3Pool v1.0.0 subtracts amountIn plus feeAmount from the remaining input before it splits the fee. The swapper pays the gross fee. The LP checkpoint sees the remainder.

So "0.30% all goes to LPs" is true only when the denominator is 0. At denominator 4, the protocol takes 750 of a 3000 fee and the growth accumulator adds 2250. Writing 3000 as the LP fee overstates it by 750, one third of the remainder. At denominator 6 the protocol takes 500 and the remainder is 2500, so the overstatement is 500. The two mistakes are not one percentage applied twice. They are two denominators.

This is not the question in the position article. That one asks whether the liquidity field is a token balance. This one assumes the inventory has already been separated, and asks whether the fee tier is the cut LPs keep. Quote, inventory, and fee are three ledgers. Multiplying the fee tier by the inventory produces a swap fee that has not happened. It is not the amount already written into tokensOwed.

2. One byte holds two denominators. 100 is not a percent

setFeeProtocol accepts 0, or a value from 4 through 10. The require treats those values as denominators, not percentages. 4 means the protocol takes one fourth, not 4%. 0 means that side takes no protocol fee. The two arguments are the token0 direction and the token1 direction. Storage is the low nibble plus the high nibble shifted left by 4: feeProtocol0 + (feeProtocol1 << 4). The teaching pair 4 and 6 stores 4 + 96 = 100. The uint8 read back from the chain is 100.

A swap unpacks that byte by direction. The price-decreasing path, which sells token0, uses 100 % 16 and gets 4. The price-increasing path uses 100 >> 4 and gets 6. Flash settlement splits the same way: paid0 uses the low nibble, paid1 uses the high nibble. Reading 100 as "the protocol takes 100%" writes 0 for LPs. Reading 100 as one denominator for both directions writes the same remainder twice. 100 is not an allowed denominator. It is what 4 and 6 look like after they share a byte.

Gross fee 3000, slot0.feeProtocol = 100
DirectionDenominatorProtocol takesLPs keep
Price down, low nibble47502250
Price up, high nibble65002500
Denominator read as 0003000
100 read as a percentmisread30000

The same 3000 differs by 250 across the two legal directions. 250 is 750 minus 500, not a rounding dust. A note that copies only the printed 0.30% writes 3000 for both directions, overstating one by 750 and the other by 500.

3. After the target price is reached, round up, then divide

When the step has already reached its target price, SwapMath v1.0.0 does not compute the fee as amountIn times 3000 divided by 1000000. The denominator is 1000000 minus fee, which is 997000, and FullMath.mulDivRoundingUp rounds up. At amountIn 997000 and fee 3000, 997000 times 3000 divides 997000 exactly, so the fee is 3000. The input on that step is 997000 plus 3000, which is 1000000. The printed 0.30% of 1000000 is also 3000. The match is this input only. It does not make the two formulas the same.

At amountIn 997001, the product 2991003000 divided by 997000 has quotient 3000 and a non-zero remainder, so the rounded-up fee is 3001. Protocol denominator 4 divides 3001 down to 750 and records 2251 in the growth accumulator. Denominator 6 divides down to 500 and records 2501. Rounding 3001 back to 3000 before the split keeps the protocol share at 750 or 500 and drops 1 from the LP remainder. That 1 is the round-up, not the protocol denominator.

The branch that has not reached the target price uses a different expression: the fee is the remaining input minus amountIn. The teaching fees 3000 and 3001 both use the branch that has reached the target, so the two rounding rules are not mixed into one number.

4. A flash loan divides by 1000000. The same input can differ by 9

flash multiplies the borrowed amount by fee, divides by 1000000, and rounds up. That result is the minimum the callback must repay above the principal. Borrowing 1000000 at fee 3000 produces 3000, the same as the swap fee in the previous section. Borrowing 997001 produces quotient 2991 from 2991003000 divided by 1000000, then rounds up to 2992. The swap fee at amountIn 997001 is 3001. The formulas differ by 9. Using the flash divisor on the swap's amountIn understates the fee by 9. Using the swap divisor on the flash principal overstates it by 9.

If the callback repays exactly 2992, paid0 is 2992. With low-nibble denominator 4, the protocol takes 748, which is 2992 divided by 4, and LP growth records 2244. Filling the flash protocol fee with the swap's 3001 overstates the protocol fee by 2 and the growth by 7. The gross gap of 9 does not land on one side. Settlement requires the balance to rise by at least fee. Any extra repayment is part of paid and is divided by the same denominator. A note that writes the minimum fee as the actual paid drops that extra.

5. A fee of 1 can leave the protocol with 0

A flash loan of 1 at fee 3000 divides 1 times 3000 by 1000000, gets quotient 0, and rounds up to 1 because the remainder is not 0. The printed 0.30% of 1 is below one unit, and rounding it down writes 0. The contract asks the callback for 1. At denominator 4 or 6, integer division of 1 is 0, so the protocol fee does not increase and the whole unit stays in the remainder. Writing "the protocol takes one fourth" as 0.25 still leaves the protocol-fee field at 0. Integer division does not keep the 0.25.

Inside the swap loop, the growth accumulator is updated only when liquidity is above 0. At liquidity 0 the protocol fee is still accumulated, and the remainder is not added to feeGrowthGlobal. Teaching gross fee 3000, denominator 4, liquidity 0: protocol fees increase by 750 and the growth accumulator does not move. The swapper has already paid the gross 3000. Reading a growth reading of 0 as "no fee was charged" misses 3000 already paid into the pool. 750 sits in protocol fees. 2250 was never written onto a position checkpoint. Later liquidity does not backfill that interval.

6. Read both denominators, then round up and divide

The failing sentences are "0.30% is the LP fee" and "a feeProtocol reading of 100 means a 100% cut." The sentence that can be checked is "fee; the low nibble and the high nibble of slot0.feeProtocol; whether this step reached the target price; whether the divisor is the swap's 997000 or the flash loan's 1000000; the gross fee after rounding up; the protocol fee after integer division; whether a liquidity of 0 kept the remainder out of the growth accumulator." In the teaching case, feeProtocol 100 and a gross fee of 3000 leave 2250 one way and 2500 the other. When amountIn and the borrowed amount are both 997001, the swap fee is 3001 and the flash fee is 2992.

This is an analytical frame. The split order, the packed denominators, and the two round-ups come from the v1.0.0 sources cited above. 3000, 2250, 2500, 3001, 2992, and 1 are teaching conversions. They were not measured on a live pool, and they are not investment advice.

7. Misreadings that keep coming back

Is the printed 0.30% the fee liquidity providers receive?

No. In v1.0.0, fee 3000 is the gross fee in millionths. The protocol then integer-divides that fee by the slot0.feeProtocol denominator. At denominator 4, the protocol takes 750 of 3000 and LP fee growth records 2250. The full 3000 stays with LPs only when the denominator is 0.

Does a feeProtocol reading of 100 mean a 100% protocol fee?

No. setFeeProtocol(4, 6) stores 4 in the low nibble and 6 in the high nibble, so the uint8 is 100. A price-decreasing swap uses 100 modulo 16, which is 4. A price-increasing swap uses 100 shifted right by 4, which is 6. The stored 100 is not a percentage.

Do swap fees and flash fees use the same formula?

No. Once a swap step has reached its target price, the fee is amountIn times fee, divided by 1000000 minus fee, then rounded up. A flash loan uses the borrowed amount times fee, divided by 1000000, then rounded up. At 997001 and fee 3000, the swap fee is 3001 and the flash fee is 2992.