Failing to compile multiple Solidity versions
Asked Answered
A

5

17

I'm trying to compile (through Hardhat) a contract that imports several interfaces with different Solidity versions but I'm getting the following error:

Error HH606: The project cannot be compiled, see reasons below.

These files and its dependencies cannot be compiled with your config. This can happen because they have incompatible Solidity pragmas, or don't match any of your configured Solidity compilers.

  * contracts/FlashLoaner.sol

Flashloaner.sol:

pragma solidity >=0.5.0 <=0.8.0;

import '@uniswap/v2-periphery/contracts/interfaces/IWETH.sol';
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import '@aave/protocol-v2/contracts/interfaces/ILendingPool.sol'; //---> Issue
import "hardhat/console.sol";


contract FlashLoaner {
    struct MyCustomData {
        address token;
        uint256 repayAmount;
    }

    address public logicContract;
    
    function execute(address _weth, address _contract) external view {
        console.log(_weth);
    }
}

The problem is with @aave/protocol-v2/contracts/interfaces/ILendingPool.sol. If I comment it out, my contract compiles good.

IlendingPool.sol: pragma solidity 0.6.12;

IERC20.sol: pragma solidity ^0.5.0;

IWETH.sol: pragma solidity >=0.5.0;

Hardhat.config:

module.exports = {
  solidity: {
    compilers: [
      {
        version: "0.5.7"
      },
      {
        version: "0.8.0"
      },
      {
        version: "0.6.12"
      }
    ]
  }
   ...
Antigen answered 28/6, 2021 at 12:23 Comment(0)
A
7

Solution:

Grab the signatures from the functions that I'm interested in from each interface, and put them on my own interface with pragma solidity ^0.8.0.

Antigen answered 29/6, 2021 at 11:34 Comment(1)
Yes this works, shame that the compiler makes us jump through these ridiculous hoops because it thinks a function might not exist at a specific addressAuxesis
A
7

I had a similar problem.

In my case, my contracts used pragma solidity version ^0.8.0

To fix the problem, I added those lines to my hardhat.config.js (Inside the existing module.exports for most cases).

module.exports = {
  solidity: "0.8.0",
}

I just deleted the "^" before the version.

Adamik answered 10/12, 2021 at 17:54 Comment(0)
H
5

Just try setting on hardhat.config.js

    module.exports = {   solidity: {
        compilers: [
          {
            version: "0.5.5",
          },
          {
            version: "0.6.7",
            settings: {},
          },
        ],   
}, 

};

see more!!!!

Hebetate answered 23/8, 2021 at 22:43 Comment(1)
Hi! How is that different from what I tried on the initial post? (the last part of it)Antigen
P
2

I found the info from A Hardhat FAQ to be useful:

In some scenarios, you might have a contract with pragma version ^0.7.0 that imports a contract with ^0.6.0. This can never be compiled.

If the ^0.6.0 file comes from a dependency, one possible fix is to upgrade that dependency (assuming newer versions use a newer version of solidity). Alternatively, you might need to downgrade the pragma versions of the contracts in your project.

Pronto answered 4/4, 2022 at 4:18 Comment(0)
D
0

One solution to this problem is the "Lock.sol" under the Contracts folder. The pragma solidity version there tends to be different from the other files, so you have to make them the same.

Dogma answered 3/9, 2022 at 2:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.