Section 15 of 16
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 withUniswapV2: Kbecause the invariant check runs against the assumed input amount. TheswapExactTokensForTokensSupportingFeeOnTransferTokensvariant fixes this by measuring the pair's actualbalanceOfbefore and after each hop, computing the real input/output, and usinggetAmountOutagainst 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
Requirements
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 continueAlready have an account? Log in