I'm trying to upgrade a flashloan file from my study and I don't get one moment about checking pool existence. Here is the code.

// Get the Factory Pair address for combined tokens
        address pair = IUniswapV2Factory(UNISWAP_FACTORY).getPair(

        // Return error if combination does not exist
        require(pair != address(0), "Pool does not exist");

        // Figure out which token (0 or 1) has the amount and assign
        address token0 = IUniswapV2Pair(pair).token0();
        address token1 = IUniswapV2Pair(pair).token1();
        uint256 amount0Out = _tokenBorrow == token0 ? _amount : 0;
        uint256 amount1Out = _tokenBorrow == token1 ? _amount : 0;

        // Passing data as bytes so that the 'swap' function knows it is a flashloan
        bytes memory data = abi.encode(_tokenBorrow, _amount, msg.sender);

        // Execute the initial swap to get the loan
        IUniswapV2Pair(pair).swap(amount0Out, amount1Out, address(this), data)

In my study file we always borrow USDC, so pair USDC/Weth exists and pair != address(0) But when the borrowed coin is WETH I receive an error : VM Exception while processing transaction: reverted with reason string 'Pool does not exist' As I understand this situation we need to check the existence of this tokenBorrow/WETH pair to be sure that we can borrow a token. But what should I do with WETH? Maybe I should check WETH/ETH pair? But ETH and WETH have the same addresses so I'm stuck here.

1 Answer 1


Seems like I found an answer after 5 hours of thinking :

if (_tokenBorrow == address(WETH)) {
        address pair = IUniswapV2Factory(UNISWAP_FACTORY).getPair(

Now I get Uniswap:Locked error. But it seems like uniswap simply needs an existing pair to start swapping. And if I give give him address of this pair it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.