I am working on building an ERC20 token with the help of the OpenZeppelin project.
I wanted to add a burn fee on transfer, so I overrode my transfer function as follows:
function transfer(address _to, uint256 _value) public virtual override returns (bool) {
uint256 willBurn = _value / _burnRate;
if (ERC20.transfer(_to, _value - willBurn)) {
_burn(_msgSender(), willBurn);
return true;
} else return false;
}
And my transferFrom function as follows:
function transferFrom(address _from, address _to, uint256 _value) public virtual override returns (bool) {
uint256 willBurn = _value / _burnRate;
if (ERC20.transferFrom(_from, _to, _value - willBurn)) {
_burn(_from, willBurn);
return true;
} else return false;
}
This works almost perfectly!
When I swap on uniswap, buying works fine, and selling it works fine if I change the number of tokens to sell. But when selling, if I change the amount of ETH that I want, it shows an error saying:
The Uniswap invariant x*y=k was not satisfied by the swap. This usually means one of the tokens you are swapping incorporates custom behavior on transfer.
When researching, I found another token that behaved in the exact same way:
This ONLY happens if you edit the amount of ETH to get out and click "Swap"
I found some information on this error in uniswap's documentation, but I was wondering if there is a way for me to get around it? Does anyone know?