Uniswap / v2-core

🦄 🦄 Core smart contracts of Uniswap V2
https://uniswap.org/docs
GNU General Public License v3.0
2.92k stars 3.13k forks source link

Uniswap getPair() does not deliver address(0) #144

Open repomani opened 2 years ago

repomani commented 2 years ago

I am currently testing the Uniswap function getPair()

mapping(address => mapping(address => address)) public override getPair;

and calling it from UI like this:

   const pairAddress = await this.state.factory.getPair(
            this.state.tokenAData.address,
            this.state.tokenBData.address
          );

For some reason, I am not always getting address(0) like in the documentation explained.

Using ether.js to create the instance:

 const factory = new ethers.Contract(
    this.isAddress(REACT_APP_FACTORY_ADDRESS),
    Factory.abi,
    signer
  );

I deployed a fresh contract and cleared and removed the cache but getting always an address, e.g. "0x1c1Cb37dCe1b1cFF98d798C670D0B2f790141b9a". Is there any other way to find out if the pair address exists or not?

Here is my hardhat.config.ts


import { task } from 'hardhat/config';
import '@nomiclabs/hardhat-waffle';
import { config as dotenvConfig } from 'dotenv';
import { resolve } from 'path';

dotenvConfig({ path: resolve(__dirname, './.env') });

task('accounts', 'Prints the list of accounts', async (args, hre) => {
  const accounts = await hre.ethers.getSigners();

  for (const account of accounts) {
    console.log(account.address);
  }
});

// You need to export an object to set up your config
// Go to https://hardhat.org/config/ to learn more

/**
 * @type import('hardhat/config').HardhatUserConfig
 */
module.exports = {
  networks: {
    localhost: {
      url: 'http://127.0.0.1:8545',
      chainId: 31337,
    },
    testnet: {
      url: 'https://speedy-nodes-nyc.moralis.io/{key}/bsc/testnet',
      chainId: 97,
      accounts: [process.env.TEST_NET_KEY],
    },
  },
  solidity: {
    version: '0.8.0',
    settings: {
      optimizer: {
        enabled: true,
        runs: 1000,
      },
    },
  },
  paths: {
    sources: './src/contracts',
    tests: './src/tests',
    cache: './cache',
    artifacts: './src/abi',
  },
  mocha: {
    timeout: 20000,
  },
};

Start: npx hardhat node Deploy: npx hardhat run --network localhost src/scripts/deploy.ts

ghost commented 8 months ago

Because when there is a pair, it is not an address(0) but a pair address.