ApeWorX / ape

The smart contract development tool for Pythonistas, Data Scientists, and Security Professionals
https://apeworx.io
Apache License 2.0
890 stars 131 forks source link

Error while compiling `Uniswap-v3-core` & `Uniswap-v3-periphery` contracts [APE-1314] #1620

Closed Aviksaikat closed 1 year ago

Aviksaikat commented 1 year ago

Environment information

$ ape --version
# ...copy and paste result of above command here...
0.6.18

$ ape plugins list
# ...copy and paste result of above command here...
Installed Plugins:
  foundry      0.6.14
  etherscan    0.6.9
  solidity     0.6.8
  alchemy      0.6.2
$ cat ape-config.yaml
# ...copy and paste result of above command here...
name: Raise-warnings-if-value
plugins:
  - name: solidity
  - name: alchemy
  - name: foundry
ethereum:
  default_network: mainnet-fork
  mainnet_fork:
    default_provider: foundry
    transaction_acceptance_timeout: 99999999
  mainnet:
    transaction_acceptance_timeout: 99999999
ganache:
  fork:
    ethereum:
      mainnet:
        upstream_provider: alchemy
foundry:
  host: auto
  fork:
    ethereum:
      mainnet:
        upstream_provider: alchemy
dependencies:
  - name: Uniswap-periphery
    github: uniswap/v3-periphery
    ref: 1.3.0
  - name: Uniswap-core
    github: uniswap/v3-core
    ref: 1.0.0
  - name: OpenZeppelin
    github: OpenZeppelin/openzeppelin-contracts
    version: 4.9.3
  - name: OpenZeppelin
    github: OpenZeppelin/openzeppelin-contracts
    version: 4.9.0
  - name: OpenZeppelin
    github: OpenZeppelin/openzeppelin-contracts
    version: 4.9.1
test:
  mnemonic: test test test test test test test test test test test junk
  number_of_accounts: 10

What went wrong?

Please include information like:

command: /home/avik/.solcx/solc-v0.8.21 --standard-json --base-path /tmp/tmp9ta7ppi7/contracts return code: 0 stdout: {"errors":[{"component":"general","errorCode":"4907","formattedMessage":"TypeError: Built-in unary operator - cannot be applied to type uint256. Unary negation is only allowed for signed integers.\n --> libraries/FullMath.sol:64:24:\n |\n64 | uint256 twos = -denominator & denominator;\n | ^^^^^^^^^^^^\n\n","message":"Built-in unary operator - cannot be applied to type uint256. Unary negation is only allowed for signed integers.","severity":"error","sourceLocation":{"end":2580,"file":"libraries/FullMath.sol","start":2568},"type":"TypeError"}],"sources":{}}

stderr: SUCCESS: Package 'OpenZeppelin@4.9.3' compiled. SUCCESS: Package 'OpenZeppelin@4.9.0' compiled. SUCCESS: Package 'OpenZeppelin@4.9.1' compiled.

How can it be fixed?

Aviksaikat commented 1 year ago

When I changed the version of Uniswap-v3-core to 1.0.1 & tried to run ape pm compile I got version doesn't exist. Then I again changed the version to 1.0.0 for some reason it compiled successfully. But this doesn't solved the issue with the Uniswap-v3-periphery

antazoey commented 1 year ago

I was able to repro and am investigating.

antazoey commented 1 year ago

I had to do several things here to get this to work. There are some issues with your config. Basically, a good strategy is to try and compile the dependencies individually and figure out the configuration needed in those cases. Then, once you understand that, piece things back together in a central config and make-use of the config_override config for each dependency.

Here are some of the issues:

  1. There are missing dependencies needed, specifically for v3-periphery to work.
  2. I had to exclude test/ contracts because they cause issues
  3. You had the wrong OpenZeppelin version, so I fixed that.
  4. I had to tell v3-periphery which solidity version to use because it has some terrible pragma specs in its files (no problem)
  5. I had to clarify some import remappings needed for v3-periphery.

By far, v3-periphery was the most challenging dependency to compile of them all. If you need some of the contracts that require libraries, that will be an additional challenge.

However, I was able to run ape pm compile with the following config:

name: Raise-warnings-if-value
plugins:
  - name: solidity
  - name: alchemy
  - name: foundry
ethereum:
  default_network: mainnet-fork
  mainnet_fork:
    default_provider: foundry
    transaction_acceptance_timeout: 99999999
  mainnet:
    transaction_acceptance_timeout: 99999999
ganache:
  fork:
    ethereum:
      mainnet:
        upstream_provider: alchemy
foundry:
  host: auto
  fork:
    ethereum:
      mainnet:
        upstream_provider: alchemy
dependencies:
  - name: Uniswap-periphery
    github: uniswap/v3-periphery
    ref: 1.3.0
    config_override:
      compile:
        exclude:
          - test/*
      solidity:
        version: 0.7.6
        import_remapping:
        - "@uniswap/v3-core/contracts=Uniswap-core/main"
        - "@uniswap/v2-core/contracts=Uniswap-core-v2/master"
        - "@uniswap/lib/contracts=Uniswap-lib/master"
        - "@openzeppelin/contracts=OpenZeppelin/v3.4.2"
        - "base64-sol=base64-sol/main"
  - name: Uniswap-core
    github: uniswap/v3-core
    ref: 1.0.0
    config_override:
      compile:
        exclude:
          - test/*
      solidity:
        version: 0.7.6
  - name: OpenZeppelin
    github: OpenZeppelin/openzeppelin-contracts
    version: 3.4.2

  - name: Uniswap-lib
    github: uniswap/solidity-lib
    ref: master
    config_override:
      compile:
        exclude:
          - test/*
      solidity:
        version: 0.7.6

  - name: Uniswap-core
    github: uniswap/v3-core
    ref: main
    config_override:
      compile:
        exclude:
         - test/*
  - name: Uniswap-core-v2
    github: uniswap/v2-core
    ref: master
    config_override:
      compile:
        exclude:
         - test/*
  - name: base64-sol
    github: Brechtpd/base64
    ref: main
    contracts_folder: .

test:
  mnemonic: test test test test test test test test test test test junk
  number_of_accounts: 10

But I also had to fix a bug in Ape related to config_override to get it work right. The PR for this bugfix is here: https://github.com/ApeWorX/ape/issues/1656

antazoey commented 1 year ago

Note: I just edited the config in my comment above because i forgot some things, but it should be good now!