Skip to content

VIP: Interfaces #885

@fubuloubu

Description

@fubuloubu

Preamble

VIP: 885
Title: Interfaces
Author: @fubuloubu
Status: Draft
Created: 2018-06-09

Simple Summary

Have contracts specify and implement interfaces.

Abstract

We need a succinct way of describing how our contracts implement interfaces that is intuitive and easy to understand, so that we can do pretty standard things like write compliant tokens.

Motivation

Currently there is no way for contracts to actually import an interface, only use standard ones we define. When we add the capability to import, we will very soon need a way to actually have a contract implement them.

Specification

from vyper.interfaces import (
    ERC20, # External Contract Type
)

# Mostly to inform compiler to do error checks described below
implements: (
    ERC20,
)
  • Compiling this contract will raise an UnimplmenetedInterface Error if any standard ERC20 function (totalSupply(), balanceOf(), transfer()) is unimplemented.
  • Compiling this contract will raise a UnimplmenetedInterface Warning for each optional ERC20 function (approve(), allowance(), transferFrom()) that is unimplemented.
  • Compiling this contract will raise an UnimplmenetedInterface
  • Compiling this contract will raise an IncorrectInterface Error if the interface is not implemented correctly.
  • Compiling this contract will raise a UnusedEvent Warning for each event defined in an interface that is not triggered in a function.

Imports from files

The vyper compiler (bin/vyper) should know how to import custom defined interfaces, which are read from the compilers execution path (pwd).

import one as One
implement: One

Which will read the one.vy contract file and make the given interface is implemented.

External contract calls

Interface should also be able to be used to make external contract calls e.g.

from vyper.interfaces import ERC20

token: address(ERC20)
# ...
@public
def test(addy: address, to: address):
     ERC20(addy).transfer(to, msg.value)

Backwards Compatibility

implements is backwards compatible.
Adding events in contract definition is backwards compatible.

Copyright

Copyright and related rights waived via CC0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions