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( _tokenBorrow, WETH ); // 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.