Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use external contract addresses as function arguments in Vyper contract interface #1375

Closed
Pet3ris opened this issue Apr 1, 2019 · 9 comments

Comments

@Pet3ris
Copy link

Pet3ris commented Apr 1, 2019

I'm trying to compile the Uniswap Exchange contract using the latest vyper compiler.

I first updated the ERC20 references to the new token: ERC20 definition and set up an import from vyper.interfaces import ERC20.

The next issue is with the getExchange() function in the Factory interface.

vyper.exceptions.TypeMismatchException: line 68:15 Typecasting from base type address(ERC20) to address unavailable

This occurs on the following line:

assert self.factory.getExchange(self.token) == self

I tried to solve it by amending the getExchange interface to:

    def getExchange(token_addr: ERC20) -> address: constant

but this produces another error:

vyper.exceptions.InvalidTypeException: line 8: Invalid base type: ERC20
    def getExchange(token_addr: ERC20) -> address: constant

Any thoughts on how to get this to compile?

Vyper version

vyper --version
# 0.1.0b9
@fubuloubu
Copy link
Member

Yup! Someone else ran into this bug. Was fixed in #1373, but not released yet

@Pet3ris
Copy link
Author

Pet3ris commented Apr 1, 2019

@fubuloubu

The latest changes still don't seem to let me compile uniswap :(. I updated from the master branch:

pipenv install -e "git+https://github.com/ethereum/vyper.git@master#egg=vyper"

then tried to change getExchange in 4 ways:

    def getExchange(token_addr: address) -> address: constant
    def getExchange(token_addr: ERC20) -> address: constant
    def getExchange(token_addr: ERC20(address)) -> address: constant
    def getExchange(token_addr: address(ERC20)) -> address: constant

The last one returns the following error:

vyper.exceptions.TypeMismatchException: line 68:15 Typecasting from base type address(ERC20) to address(ERC20) unavailable

@fubuloubu
Copy link
Member

I think that's our April Fool's joke this year, isn't is @jacqueswww? Please tell me that error is a joke. Please.

@jacqueswww
Copy link
Contributor

@fubuloubu @Pet3ris Use def getExchange(token_addr: address) -> address: constant instead. Inline interface definitions don't support interface constructs at the moment. And not 100% sure they should - because ABI only supports address.

@jacqueswww
Copy link
Contributor

jacqueswww commented Apr 1, 2019

@Pet3ris if you use the original setup with master, all should be well.

token: address
...
assert self.factory.getExchange(self.token) == self

Additionally if you want to compile the current mainnet uniswap contract you have to use vyper beta 4.

@jacqueswww
Copy link
Contributor

jacqueswww commented Apr 1, 2019

I just tested this code on master, and it's all 👍 :

from vyper.interfaces import ERC20
 

contract Factory:
   def getExchange(token_addr: address) -> address: constant


factory: Factory
token: ERC20



@public
def test():
   assert self.factory.getExchange(self.token) == self

@Pet3ris
Copy link
Author

Pet3ris commented Apr 1, 2019

Thanks @jacqueswww, @fubuloubu for the clarification, works now!

@Pet3ris
Copy link
Author

Pet3ris commented Apr 1, 2019

Please feel free to close.

@jacqueswww
Copy link
Contributor

Closed, in favour of #1376

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants