NomicFoundation / hardhat

Hardhat is a development environment to compile, deploy, test, and debug your Ethereum software.
https://hardhat.org
Other
7k stars 1.35k forks source link

Support Vyper contract compilation via `sys.path` modules #5479

Open pcaversaccio opened 2 days ago

pcaversaccio commented 2 days ago

Describe the feature

When using the Vyper CLI, the search path defaults to the current working directory and the Python sys.path since the 0.4.0 release.

How does this look like in practice: Let's do a typical workflow using 🐍 snekmate contracts:

~$ mkdir test && cd test
~$ python -m venv && source venv/bin/activate
~$ pip install vyper snekmate
~$ mkdir src && cd src && vi token.vy # here you put the example I paste below
~$ cd .. && vyper src/token.vy
# pragma version ~=0.4.0
from ethereum.ercs import IERC20
from ethereum.ercs import IERC20Detailed
from snekmate.auth import ownable
from snekmate.tokens import erc20

initializes: ownable
initializes: erc20[ownable := ownable]
exports: (
    erc20.owner,
    erc20.IERC20,
    erc20.IERC20Detailed,
    erc20.mint,
    erc20.set_minter,
)

@deploy
def __init__():
    ownable.__init__()
    erc20.__init__("Vyper", "VY", 18, "Vyper", "1")

As a result, all imported 🐍 snekmate contracts (e.g. from snekmate.tokens import erc20) are seamlessly located during compilation.

I have tested this workflow with the latest hardhat-vyper version and unfortunately it fails:

Error: Command failed: <path-to-compiler> --evm-version paris --optimize gas -f combined_json <some-path>/vyper-sandbox/contracts/vyper/Foo.vy
vyper.exceptions.ModuleNotFound: snekmate.auth.ownable

  contract "<some-path>/vyper-sandbox/contracts/vyper/Foo.vy:4", line 4:0
       3 from ethereum.ercs import IERC20Detailed
  ---> 4 from snekmate.auth import ownable
  -------^
       5 from snekmate.tokens import erc20

[32916] Failed to execute script 'vyper_compile' due to unhandled exception!

Can you guys consider adding this in the near future since it will boost Vyper devex a lot IMHO.

Search terms

vyper, syspath, modules