Can BNB and tokens be recovered from a contract whose openTrading() always reverts with PAIR_EXISTS (router/pair never set, ManualSwap reverts)?

Can BNB and tokens be recovered from a contract whose openTrading() always reverts with PAIR_EXISTS (router/pair never set, ManualSwap reverts)?

Manage alerts

Loading saved threads...

Bobby Anggara · External communityPost link
External question — Ethereum Stack Exchange Author: Bobby Anggara Original post: https://ethereum.stackexchange.com/questions/172422 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I deployed an ERC-20/BEP-20 token on BNB Smart Chain (verified source on BscScan) using a common "openTrading" launch template. I funded the contract with liquidity (10.03 BNB and the full token supply), but a third party (a bot) created the PancakeSwap pair for my token address before I called openTrading(). Now openTrading() reverts with Pancake: PAIR_EXISTS and I can't get the funds out. Contract: 0x2Ad626d917490e79D78f9445932e5A20E5E40EC2 (BSC, verified, compiler 0.8.20) Pair created by someone else: 0x49952fbc693cFdEFf24DC46bF5e8439b8F4F1f2F [pair creation tx: 0x...] Current state Contract BNB balance: 10.03 BNB balanceOf(address(this)) = 1,000,000,000 BEIRO (entire supply) tradingOpen == false, and uniswapV2Router and uniswapV2Pair are still address(0) because they are only assigned inside openTrading() _taxWallet is my wallet, and I'm calling from that address Relevant code: solidity function openTrading() external onlyOwner { require(!tradingOpen, "trading is already open"); uniswapV2Router = IUniswapV2Router02(0x10ED43C718714eb63d5aA57B78B54704E256024E); _approve(address(this), address(uniswapV2Router), _tTotal); uniswapV2Pair = IUniswapV2Factory(uniswapV2Router.factory()).createPair( address(this), uniswapV2Router.WETH() ); // reverts: Pancake: PAIR_EXISTS uniswapV2Router.addLiquidityETH{value: address(this).balance}( address(this), balanceOf(address(this)), 0, 0, owner(), block.timestamp ); IERC20(uniswapV2Pair).approve(address(uniswapV2Router), type(uint256).max); swapEnabled = true; tradingOpen = true; lastLiquifyTime = uint64(block.number); } function ManualSwap() external { require(_msgSender() == _taxWallet); uint256 tokenBalance = balanceOf(address(this)); if (tokenBalance > 0) { swapTokensForEth(tokenBalance); } uint256 ethBalance = address(this).balance; sendETHToFee(ethBalance); } function swapTokensForEth(uint256 tokenAmount) private lockTheSwap { lastLiquifyTime = uint64(block.number); address[] memory path = new address; path[0] = address(this); path[1] = uniswapV2Router.WETH(); // router is address(0) here _approve(address(this), address(uniswapV2Router), tokenAmount); uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( tokenAmount, 0, path, _taxWallet, block.timestamp ); } Full source is on BscScan at the address above. The contract has no other functions that move tokens or BNB out (only transfer, transferFrom, approve, removeLimits, renounceOwnership), and it isn't upgradeable. What I tried openTrading() from the owner: always reverts with Pancake: PAIR_EXISTS ManualSwap() from _taxWallet: reverts [paste the exact error or "with no reason string"] My analysis (please correct me if wrong) createPair can never succeed again because the pair already exists. ManualSwap reverts because the contract's token balance is > 0, so it calls uniswapV2Router.WETH() on address(0). The contract's own tokens can't be moved out, because _allowances[address(this)][*] is only set inside openTrading()/swapTokensForEth(), and neither can succeed. So the BNB can't be reached either. Question: Is there any way (a storage trick, a call-ordering trick, an edge case in _transfer, or anything else) to recover the BNB or make ManualSwap succeed, or is this permanently locked? If it is locked, I'd also appreciate confirmation of the root cause so I can avoid it in a future contract.
Quote
Report

Post Reply

Checking account access…
Can BNB and tokens be recovered from a contract whose openTrading() always reverts with PAIR_EXISTS (router/pair never set, ManualSwap reverts)? | Forex.com.bd