Vyper: Cannot use external contract addresses as function arguments in Vyper contract interface

Created on 1 Apr 2019  路  9Comments  路  Source: vyperlang/vyper

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

All 9 comments

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

@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

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

@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.

@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.

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

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

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

Please feel free to close.

Closed, in favour of #1376

Was this page helpful?
0 / 5 - 0 ratings