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
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
UnimplmenetedInterfaceError if any standard ERC20 function (totalSupply(),balanceOf(),transfer()) is unimplemented.UnimplmenetedInterfaceWarning for each optional ERC20 function (approve(),allowance(),transferFrom()) that is unimplemented.UnimplmenetedInterfaceIncorrectInterfaceError if the interface is not implemented correctly.UnusedEventWarning 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).
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.
Backwards Compatibility
implementsis backwards compatible.Adding events in contract definition is backwards compatible.
Copyright
Copyright and related rights waived via CC0