Hello everyone, I hope you all are doing well. I wanted to reach out regarding the verification process of my contract on Etherscan. Hopefully someone can help us.
To explain simply, we are receiving a ByteCode mismatch on our contract which is resulting in our mainnet Ethereum contract not being able to be verified properly. This contract is a simple router contract to facilitate trading for Uniswap pairs.
Note: Within the Compiler warnings during verification we do not see any notable issues.
When we compile our code in Remix, we also do not see any errors.
Within the Debug log it explains how it finds the proper contract names in the code. But is unable to find the matching ByteCode.
Contract Address: 0xD72B79835cD35c489E1b1e0a098c309eb0351CC4
Optimization: None
We deployed our contract via Remix using 0.8.25 version of solidity. As well as we have tested other versions. We have flattened our contract and submitted as a single file as well. We have tried using the EtherScan plugin and verifying directly from Remix and we are receiving this identical error message. I see this is a very common issue in which many do not have an exact fix for.
It seems Etherscan is looking for ByteCode that does not match what we have deployed. We also attempted verifying immediately after deployment, without changing any values, and it still presents us with this issue. We are getting our constructor arguments from HashDex.io in which they parse the correct values we input during deployment. Such as router address, initial owner and WETH pair.
Would love any advice on what to do next, Or if someone could attempt to verify as we feel we have exhausted many options. If not possible to fix, would love to know what we may have done wrong as well. That way we can avoid this issue in the future if we decide to redeploy if we absolutely have too.
Source Code: (Unflattened)
`// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol";
import "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract UniswapRouter is Ownable {
using SafeERC20 for IERC20;
IUniswapV2Router02 public immutable uniswapRouter;
address public immutable WETH;
// Mapping to store whether a token is stable or not
mapping(address => bool) public stable;
constructor(address _router, address _WETH, address initialOwner) Ownable(initialOwner) {
uniswapRouter = IUniswapV2Router02(_router);
WETH = _WETH;
}
// Function to set stability status of a token
function setStable(address token, bool isStable) external onlyOwner {
stable[token] = isStable;
}
function swapExactETHForTokens(
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external payable returns (uint[] memory amounts) {
require(path[0] == WETH, "UniswapRouter: INVALID_PATH");
amounts = uniswapRouter.swapExactETHForTokens{value: msg.value}(
amountOutMin,
path,
to,
deadline
);
}
function swapExactTokensForETH(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts) {
require(path[path.length - 1] == WETH, "UniswapRouter: INVALID_PATH");
IERC20(path[0]).safeTransferFrom(
msg.sender,
address(this),
amountIn
);
IERC20(path[0]).approve(address(uniswapRouter), amountIn);
amounts = uniswapRouter.swapExactTokensForETH(
amountIn,
amountOutMin,
path,
to,
deadline
);
}
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts) {
IERC20(path[0]).safeTransferFrom(
msg.sender,
address(this),
amountIn
);
IERC20(path[0]).approve(address(uniswapRouter), amountIn);
// Calculate fee amount
uint feeAmount = getFeeAmount(path[0], path[path.length - 1], amountIn);
// Transfer fee to owner
IERC20(path[0]).safeTransfer(owner(), feeAmount);
// Adjust amountIn by subtracting fee
uint netAmountIn = amountIn - feeAmount;
amounts = uniswapRouter.swapExactTokensForTokens(
netAmountIn,
amountOutMin,
path,
to,
deadline
);
}
function swapTokensForExactETH(
uint amountOut,
uint amountInMax,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts) {
IERC20(path[0]).safeTransferFrom(
msg.sender,
address(this),
amountInMax
);
IERC20(path[0]).approve(address(uniswapRouter), amountInMax);
// Calculate fee amount
uint feeAmount = getFeeAmount(path[0], WETH, amountInMax);
// Transfer fee to owner
IERC20(path[0]).safeTransfer(owner(), feeAmount);
// Adjust amountIn by subtracting fee
uint netAmountIn = amountInMax - feeAmount;
amounts = uniswapRouter.swapTokensForExactETH(
amountOut,
netAmountIn,
path,
to,
deadline
);
}
function swapTokensForExactTokens(
uint amountOut,
uint amountInMax,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts) {
IERC20(path[0]).safeTransferFrom(
msg.sender,
address(this),
amountInMax
);
IERC20(path[0]).approve(address(uniswapRouter), amountInMax);
// Calculate fee amount
uint feeAmount = getFeeAmount(path[0], path[path.length - 1], amountInMax);
// Transfer fee to owner
IERC20(path[0]).safeTransfer(owner(), feeAmount);
// Adjust amountIn by subtracting fee
uint netAmountIn = amountInMax - feeAmount;
amounts = uniswapRouter.swapTokensForExactTokens(
amountOut,
netAmountIn,
path,
to,
deadline
);
}
function withdrawETH(uint amount) external onlyOwner {
payable(owner()).transfer(amount);
}
function withdrawToken(address token, uint amount) external onlyOwner {
IERC20(token).safeTransfer(owner(), amount);
}
function approveToken(address token, uint amount) external onlyOwner {
IERC20(token).approve(address(uniswapRouter), amount);
}
// Function to calculate fee
function getFee(
address token0,
address token1
) internal view returns (uint256 fees) {
uint256 stableCount;
if (stable[token0]) {
stableCount = stableCount + 1;
}
if (stable[token1]) {
stableCount = stableCount + 1;
}
if (stableCount == 0) {
fees = 3000;
} else if (stableCount == 1) {
fees = 1500;
} else if (stableCount == 2) {
fees = 500;
}
}
// Function to calculate fee amount
function getFeeAmount(
address token0,
address token1,
uint amount
) internal view returns (uint256 feeAmount) {
uint256 fee = getFee(token0, token1);
feeAmount = (amount * fee) / 1000000;
}
}`
I appreciate anyones insight or help.