Section 15 of 16

Build
+15 Lynx

Router: Fee-on-Transfer Support

Key takeaway: Fee-on-transfer tokens (USDT-style fee mechanisms, SafeMoon-style burns, reflection tokens) deduct a percentage on every transfer, so the pair receives less than the Router pre-calculated. Standard _swap() reverts with UniswapV2: K because the invariant check runs against the assumed input amount. The swapExactTokensForTokensSupportingFeeOnTransferTokens variant fixes this by measuring the pair's actual balanceOf before and after each hop, computing the real input/output, and using getAmountOut against measured values rather than pre-calculations.

What You Are Building

Some ERC20 tokens deduct a fee on every transfer. When you call transfer(recipient, 100), the recipient might only receive 98 tokens. The missing 2 tokens are burned, sent to a treasury, or redistributed to holders. This behavior is called "fee on transfer" (FOT), and it breaks the standard Uniswap V2 swap functions in a way that is not immediately obvious.

Your Code

Solution.sol
Solidity
Loading editor...

Requirements

Write your implementation, then click Run Tests. Tests execute on the server.

Sign up free — keep reading + earn 15 Lynx

Zealynx Academy is free. Track your progress, earn Lynx, and climb the leaderboard.

Sign up free to continue

Already have an account? Log in