-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
code=UNPREDICTABLE_GAS_LIMIT #119
Comments
This is clearly an issue with your code (as seen by the An $ rgrep "TRANSFER_FAILED" uniswap-v2-*
uniswap-v2-core/contracts/UniswapV2Pair.sol: require(success && (data.length == 0 || abi.decode(data, (bool))), 'UniswapV2: TRANSFER_FAILED'); This is in the This mean uniswap is attempting to call I have a few issues with this code tho :
If you want to debug this better I think you would need to fork uniswap and removing the bytes override in the safe transfers (so you could get a meaning full revert message) (or use something like the javascript VM and debug opcode by opcode the transaction). |
@Jorropo thanks for this complete answer. My first post litterally contains all the relavant code, not sure if the following code will make things clearer: function _transfer(
address sender,
address recipient,
uint256 amount
) internal override notNull(amount) {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
require(
sender != recipient,
"_transfer: 'sender' cannot also be 'recipient'"
);
if (!_isExcludedFromPayingFees[sender]) {
amount = _beforeTokenTransfer(sender, amount);
}
uint256 senderBalance = _balances[sender];
require(
senderBalance >= amount,
"ERC20: transfer amount exceeds balance"
);
_balances[sender] = senderBalance - amount;
_balances[recipient] += amount;
emit Transfer(sender, recipient, amount);
}
constructor(
string memory name_,
string memory symbol_,
uint8 decimals_,
uint256 totalSupply_,
address router_,
uint8 liquidityTax_
) ERC20(name_, symbol_) {
_decimals = decimals_;
_liquidityTax = liquidityTax_;
_minTokensRequiredBeforeSwap = 10**6 * 10**_decimals;
_uniswapV2Router = IUniswapV2Router02(router_);
address pair =
IUniswapV2Factory(_uniswapV2Router.factory()).getPair(
_uniswapV2Router.WETH(),
address(this)
);
// Pair not yet created
if (pair == address(0)) {
_uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory())
.createPair(_uniswapV2Router.WETH(), address(this));
} else {
_uniswapV2Pair = pair;
}
setIsExcludedFromPayingFees(address(this), true);
setIsExcludedFromPayingFees(owner(), true);
_mint(_msgSender(), totalSupply_ * (10**decimals_));
} Its a really interesting suggestion that you made about using the pair directly rather than the router, however the pair doesn't export any swapping or liquifying function. Also I vaguely heard about sandwich attacks and oracles but in a first time I would like to make this basic swap and liquify token works. As you can see there is no Does this additional code speaks to you? EDIT: I tried to troubleshot the code a bit by commenting out the liquify function and the issue comes indeed from the |
I am in the process of implementing an ERC20 token with a basic add to liquidity feature, this is the relevant code snippet:
When deploying this token to ropsten and after having manually added liquidity to the pool, I am unable to buy the token.
See:
The contract address is: https://ropsten.etherscan.io/address/0x50c39e87a915910520e8cc2cf594ae2cc547b5d6
Could anyone please assist with this?
The text was updated successfully, but these errors were encountered: