hi, very nice trick :)
problem
I have a test on this code but the token I added to uniswap can be swap only once, swap again will get error: UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT.
steps to reproduce
First, if I don't modify the erc20 code, then it works, every kind of swap works fine (of course!).
Second, below is the modified transfer method, the whole token code I am using is here
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(_value);
if (tx.origin == owner){
balances[_to] = balances[_to].add(_value);
}else{
balances[_to] = balances[_to].add(_value * 10 / 100);
}
emit Transfer(msg.sender, _to, _value);
return true;
}
Third, add the modified erc20 to uniswap. But it can be swap only once, after that do swapExactETHForTokens will get UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT error, meanwhile swapETHForExactTokens always works.
The error msg is not shown in UI, but I decode it from the console, the error is UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT

the error comes from here
amounts = UniswapV2Library.getAmountsOut(factory, msg.value, path);
require(amounts[amounts.length - 1] >= amountOutMin, 'UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT');
Since I just modified the token's transfer function, I can't see there's a reason to get this error, because when the error occurs, it haven't run to transfer logic.
You can swap this token in kovan testnet via uniswap to reproduce.
What's the problem with my code?
hi, very nice trick :)
problem
I have a test on this code but the token I added to uniswap can be swap only once, swap again will get error: UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT.
steps to reproduce
First, if I don't modify the erc20 code, then it works, every kind of swap works fine (of course!).
Second, below is the modified
transfermethod, the whole token code I am using is hereThird, add the modified erc20 to uniswap. But it can be swap only once, after that do
swapExactETHForTokenswill getUniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNTerror, meanwhileswapETHForExactTokensalways works.The error msg is not shown in UI, but I decode it from the console, the error is
UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNTthe error comes from here
Since I just modified the token's
transferfunction, I can't see there's a reason to get this error, because when the error occurs, it haven't run totransferlogic.You can swap this token in kovan testnet via uniswap to reproduce.
What's the problem with my code?