CRYPTO NEWS

Uniswap V2 Flashswap. Pool doesn’t exist

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.

Hardhat deploying multiple contracts to one address

I have a contract called Marketplace which gets deployed as a standalone contract with ethers.js. This contract instantiates another contract called NFT, therefore it’s supposedly deployed implicitly by ethers.js. Here’s how it’s instanciated: import "./NFT.sol"; contract Marketplace { NFT nft = new NFT(); … As mentioned, I only deploy Marketplace, and this is how I::Listen

I have a contract called Marketplace which gets deployed as a standalone contract with ethers.js. This contract instantiates another contract called NFT, therefore it’s supposedly deployed implicitly by ethers.js. Here’s how it’s instanciated:

import "./NFT.sol";  contract Marketplace {    NFT nft = new NFT();    ... 

As mentioned, I only deploy Marketplace, and this is how I do it in the deploy.js script:

const Marketplace = await ethers.getContractFactory("Marketplace"); const marketplace = await Marketplace.deploy(); 

I read that in Solidity when a contract inherits another contract, the code from both gets merged into one contract, but does this also happen when a contract instantiates another contract, like in my case above?

Initially I thought so, but looking around etherscan I found out that two contract addresses were deployed, and I wasn’t expecting to have two standalone contracts but one, since I am explicitly only deploying Marketplace.

Am I supposed to change Hardhat’s configuration or do something else in order to achieve that both Marketplace and NFT are deployed under one contract address, or that’s not how the compiler works?

Uniswap V2 Flashswap. Pool doesn’t exist

Shopping cart
There are no products in the cart!
Continue shopping
0