I'm working on ERC20 token with a uniswapV2 router address initialized in the constructor. I also have method to change the router address. but I'm confused because when i create the new Pair with a different router address. The router Address variable updates. My question is even after the updated router address for example from uniswap to sushiswap. can a user will still be able to buy/sell on uniswap?
IUniswapV2Router02 public UniswapV2Router ;
address[] public UniswapV2Pairs;
constructor() ERC20("Hello", "HEY") {
UniswapV2Router = IUniswapV2Router02(0xC532a74256D3Db42D0Bf7a0400fEFDbad7694008);
address _UniswapV2Pair = IUniswapV2Factory(UniswapV2Router.factory()).createPair(address(this), UniswapV2Router.WETH());
UniswapV2Pairs.push(_UniswapV2Pair)
}
function addPairAddress(address newPair) external onlyOwner {
require(newPair != address(0), "Invalid pair address");
UniswapV2Pairs.push(newPair);
}
function changeRouterAddress(address newRouter) external onlyOwner {
require(newRouter != address(0), "Invalid router address");
UniswapV2Router = IUniswapV2Router02(newRouter);
address _UniswapV2Pair = IUniswapV2Factory(UniswapV2Router.factory())
.createPair(address(this), UniswapV2Router.WETH());
UniswapV2Pairs.push(_UniswapV2Pair);
}
function swapTokensForEth(uint256 tokenAmount) private {
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = UniswapV2Router.WETH();
_approve(address(this), address(UniswapV2Router), tokenAmount);
UniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0,
path,
address(this),
block.timestamp + 200
);
}
this is the code. my original router is uniswapv2 after adding a new router( sushiswap) the variable UniswapV2Router is updated with sushiswap address. Can i still be able to buy/sell on uniswap?