0

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:

enter image description here

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?

2
  • Is this UniswapV2 or V3? At least V2 had special trade functions for tokens which incorporate such internal fees Aug 7 at 6:36
  • Yeah, it is uniswapV2, and it does work, but only if you change the token value. If you change the eth value it doesn't work at all.
    – BananaNeil
    Aug 7 at 6:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.