0

hope you all are well. I wanted to see if anyone would be able to help me diagnose what I could possibly be doing wrong. Ive read through numerous posts and it seems many solutions have not yet helped me.

Goal: Simply verify the contract I deployed on Ethereum Mainnet using Remix.

Problem: Receiving Error with mismatching ByteCode.

Contract Address: 0xd72b79835cd35c489e1b1e0a098c309eb0351cc4

Error Message from EtherScan: Found the following ContractName(s) in source code : Address, Context, IERC20, IERC20Permit, IUniswapV2Pair, IUniswapV2Router01, IUniswapV2Router02, Ownable, SafeERC20, UniswapRouter But we were unable to locate a matching bytecode (err_code_2)

We tried looking for a match from the list of compiled contract bytecode outputs (as listed below), but was unable to find an exact match.

  1. Address 6055604b600b8282823980515f1a607314603f577f4e487b7100000000000000000000000000000000000000000000000000000000

  2. SafeERC20 6055604b600b8282823980515f1a607314603f577f4e487b7100000000000000000000000000000000000000000000000000000000

  3. UniswapRouter 60c060405234801561000f575f80fd5b506040516125f63803806125f683398181016040528101906100319190610241565b

Etherscan claims its looking for the following Bytecode

60c060405234801561000f575f80fd5b506040516129b83803806129b883398181016040528101906100319190610300565b806100418161010260201b60201 (SHORTENED)

Compiler Version: v0.8.25+commit.b61c2a91

Compiler Type: Single File

License: MIT

Optimization: Always OFF

Constructor Arguments: (Found Using ABI HASHDEX)

0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000b825e0496673a897e637688064c28d928cb353d5

Library Addresses:

1.) UniSwapV2Router02 Library Contract Address: 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D

2.) WETH Library Contract Address 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2

What we have tried so far: 1.) I have tried numerous compiler versions above 0.8.20 and when we deployed we used Compiler Version: v0.8.25+commit.b61c2a91

2.) I have tried using the EtherScan plugin on Remix. In which we receive the same error.

3.) I have tried updating our ABI and constructor arguments.

4.) We have flattened our file, which is the source code provided

5.) Our code compiles perfectly on Remix and gives no error messages or indicators.

ANY HELP IS APPRECIATED <3

Source Code: (Not flattened to fit)

// 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;
    }
}

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.