0

I have a contract that needs to be compiled with solc so I can get Go bindings.

$ tree
.
├── openzeppelin
├── Swap.sol
└── @uniswap
pragma solidity >0.7.0 < 0.9.0;

import { IUniswapV2Pair } from "@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol";
import { IUniswapV2Factory } from "@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol";
import { IUniswapV2Router02 } from "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol";

This compiles and deploys on Remix. But when I compile it locally using:

docker run -v /my-path/contracts:/sources ethereum/solc:0.8.18 --allow-paths=/sources/solc -o /sources/abi --optimize --overwrite --abi --bin /sources/solc/Swap.sol

I get:

Error: Source "@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol" not found: File not found. Searched the following locations: "".
 --> sources/solc/Swap.sol:4:1:
  |
4 | import { IUniswapV2Pair } from "@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol";
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Error: Source "@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol" not found: File not found. Searched the following locations: "".
 --> sources/solc/Swap.sol:5:1:
  |
5 | import { IUniswapV2Factory } from "@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol";
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Error: Source "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol" not found: File not found. Searched the following locations: "".
 --> sources/solc/Swap.sol:6:1:
  |
6 | import { IUniswapV2Router02 } from "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol";
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I have to fix it by downloading the code and then prefix it with "./":

import { IUniswapV2Pair } from "./@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol";
import { IUniswapV2Factory } from "./@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol";
import { IUniswapV2Router02 } from "./@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol";

I don't like it because I might not get the proper version of the imported contract.

Any suggestion on how to fix this?

4
  • In your local directory where are the @uniswap/v2-... libs installed relative to your project root? I suspect they're located in ./@uniswap/v2-... hence why you have to prepend the import with ./
    – MShakeG
    Commented Sep 10, 2023 at 13:27
  • And yes, @uniswap/v2-... libs are installed relative to your project root. I added tree to the code above.
    – pigfox
    Commented Sep 10, 2023 at 13:41
  • 1
    I'm not sure if there's a way around this directly with solc, you could consider using a framework like hardhat or foundry which will allow you to import external dependencies with "@uniswap/..."
    – MShakeG
    Commented Sep 10, 2023 at 13:43
  • The problem using Hardhat is that I don't get any Go bindings. That forces me to use solc.
    – pigfox
    Commented Sep 11, 2023 at 7:18

0

Your Answer

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