This document describes how a third party wallet/exchange can perform an exchange deal with kyber network smart contract. The api we describe should be viewed at this point only as a reference. Changes are still expected before the mainnet launch.
A wallet/exchange service interacts with the contract in two ways:
- Price query: queries the offered price of, e.g., GNO to ETH conversion.
- Trade execution: e.g., convert X GNO to Y ETH
We describe the api for each bellow:
To query the conversion rate, one should call this function
function getPrice( ERC20 source, ERC20 dest ) constant returns(uint)
The function returns the conversion rate between source
and dest
tokens,
where source
and dest
are 20 bytes addresses.
Use address 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
to denote Ether.
For example, if user wants to sell GNO tokens in return to ETH, he should set
source = 0x6810e776880c02933d47db1b9fc05908e5386b96
and
dest = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
.
In return to 1 GNO token he will receive
getPrice(0x6810e776880c02933d47db1b9fc05908e5386b96,0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee)
ETH.
If he wants to buy GNO with ETH, he should set
source = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
, and
dest = 0x6810e776880c02933d47db1b9fc05908e5386b96
.
A return value of 0
indicates that an exchange from source
to dest
is
currently not available.
This could be either because kyber network does not support an exchange between such pair,
or because the reserve supply is temporarily depleted (this is a rare event).
To make an exchange via wallet application, one should call
function walletTrade( ERC20 source, uint srcAmount,
ERC20 dest, address destAddress, uint maxDestAmount,
uint minConversionRate,
bool throwOnFailure,
bytes32 walletId ) payable returns(uint)
In general, this function convert source
token to dest
token and send it
to destAddress
.
We now describe the function parameters with more details:
source
: the address of the source token. Where0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
stands for ETH. If the source token is ETH, thenmsg.value
should be equal tosrcAmount
. I.e., the user must send the amount he wishes to convert when calling the function. Otherwise, the user mustapprove
a sufficient amount (i.e., at leastsrcAmount
) of tokens to kyber network contract address. This is done in a separate call toapprove
function of the relevant token.srcAmount
: amount of tokens to convert. If sending ETH must be equal tomsg.value
. Otherwise, must not be higher than user token allowance to kyber network contract address.dest
: the address of the destination source. Where0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
stands for ETH.destAddress
: the address that will receive the converted token. For an exchange application, we recommend to setdestAddress = msg.sender
.maxDestAmount
: maximum destination amount. The actual converted amount will be the minimum ofsrcAmount
and required amount to getmaxDestAmount
ofdest
tokens. For an exchange application, we recommend to set it toMAX_UINT
(i.e.,2**256 - 1
).minConversionRate
: the minimal conversion rate. If the current rate is too high, then the transaction is reverted. For an exchange application this value can be set according to the current return value ofgetPrice
. However, in this case, the execution of the transaction is not guaranteed in case of changes in market price before the confirmation of the transaction. A value of1
will execute the trade according to market price in the time of the transaction confirmation.throwOnFailure
: indicates if transaction is reverted in the case of a failure. For an exchange application we recommend to set it totrue
.walletId
: the id of the service provider. Should be determined along with kyber network.
The contract is currently depolyed on kovan testnet, and unofficially also at rinkeby. The kovan addresses can be found here.
The contracts source code and abi are also available at kovan etherscan. For rinkeby deployment, please contact us by email.