Uniswap / v3-sdk

🛠 An SDK for building applications on top of Uniswap V3
MIT License
544 stars 416 forks source link

Pool.getAddress function return a wrong address #205

Closed Ligengxin96 closed 3 months ago

Ligengxin96 commented 3 months ago
const { Token, ChainId } = require('@uniswap/sdk-core');
const { FeeAmount, Pool } = require('@uniswap/v3-sdk');

// explorer url: https://sepolia.etherscan.io/
const tokenA = new Token(ChainId.SEPOLIA, '0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14', 18, 'WETH', 'WETH');
const tokenB = new Token(ChainId.SEPOLIA, '0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984', 6, 'USDT', 'USDT');

const main = () => {
  const address = Pool.getAddress(tokenA, tokenB, FeeAmount.MEDIUM);
  console.log(address); // output 0xef3304094A3dd8AB2E748a9f6a87238F1eDD720b, this address is not a contract address
}
main()

Get wrong address: 0xef3304094A3dd8AB2E748a9f6a87238F1eDD720b https://sepolia.etherscan.io/address/0xef3304094A3dd8AB2E748a9f6a87238F1eDD720b

Ligengxin96 commented 3 months ago

Thanks this guy. Copy his reply to here. I think Pool.getAddress is not quite what you need. Try doing the folowing

import { computePoolAddress } from "@uniswap/v3-sdk";

  const POOL_FACTORY_CONTRACT_ADDRESS_SEPOLIA = "0x0227628f3F023bb0B980b67D528571c95c6DaC1c";

  const address = computePoolAddress({
    factoryAddress: POOL_FACTORY_CONTRACT_ADDRESS_SEPOLIA,
    tokenA,
    tokenB,
    fee: FeeApount.MEDIUM,
  });

I didn't include boilerplate code like main() and so on, hope you'll get where to put this. And I'm also not claiming that this is 100% correct way to do stuff, it just worked for me so give it a try upd: now I can tell this is the recommended way check the docs here: https://docs.uniswap.org/sdk/v3/guides/swaps/quoting#computing-the-pools-deployment-address

image