uniswap
flashloan
fee
uniswap-v2
Refer to Uniswap v2 Whitepaper, each swap should satisfy following formula:
To simplify the calculation on-chain:
When we flash loan from Uniswap v2 pair, what is the amount including fee we should repay?
Suppose we flash loan amount of token
The problem is to calculate
Since we don't flash loan token
The relation between
Using formula (4) and (5):
We can calculate
In Solidity contract, to avoid rouding down error, we should add 1 to round up:
uint256 repayAmount = amountOut.mul(1000).div(997).add(1)
where repayAmount is
So the flashloan fee of Uniswap v2 is: