Description
Preamble
EIP: <to be assigned>
Title: Token Changer Standard
Authors: Eyal Hertzog & Yudi Levi (yudi|at|bancor.network)
Type: Informational
Category: ERC
Status: Draft
Created: 2016-03-12
Requires: 20
Simple Summary
Standard functions for contracts offering token change services of standard ERC20 tokens.
Abstract
This ERC proposes a set of standard APIs for contracts providing change services between different ERC20 tokens.
The APIs can be used for:
- Querying the list of tokens changeable through the contract
- Querying the exchange rate between two changeable tokens, for a specific amount
- Token change - the action of converting one changeable token to another through the contract.
Motivation
Those functions will allow dapps and wallets to utilize token-changing contracts across multiple interface/dapps. Token changing contracts function as automatic money-changers / market-markers, solving the ‘double coincidence of wants’ problem for token exchange.
Specification
Token Change
Methods
changeableTokenCount
function changeableTokenCount() public constant returns (uint16 count)
Gets the number of changeable tokens supported by the contract.
changeableToken
function changeableToken(uint16 _tokenIndex) public constant returns (address tokenAddress)
Given a changeable token index, gets the changeable token contract address.
getReturn
function getReturn(address _fromToken, address _toToken, uint256 _amount) public constant returns (uint256 amount)
Returns the currently expected return for changing a specific _amount
of _fromToken
to _toToken
.
change
function change(address _fromToken, address _toToken, uint256 _amount, uint256 _minReturn) public returns (uint256 amount)
Change _amount
of _fromToken
to _toToken
.
The change will only take place if the returned amount of the _toToken
is greater or equal to _minReturn
.
NOTE: Sufficient allowance needs to be set for the _fromToken
prior to executing the change function (except when the _fromToken
is managed by the token change contract)
Events
Update
event Update();
Triggered when the list of changeable tokens is modified.
Change
event Change(address indexed _fromToken, address indexed _toToken, address indexed _changer, uint256 _amount, uint256 _return);
Triggered when a change between two tokens takes place.
Rationale
This is a simple standard which works well for different exchange rate calculation methods and fee structures.
The token changer functions may be integrated with an ERC20 functions, in which case, the contract may be listed as one of the changeable tokens.
Implementation
see https://github.com/bancorprotocol/contracts
Copyright
Copyright and related rights waived via CC0.