Giter Club home page Giter Club logo

smart-contracts-1's Introduction

This repository has the main contracts in KyberNetwork platform. There are three main components in this repository including KyberNetwork contract, KyberReserve and KyberWallet contracts. In addition, we have a couple of mock modules that simulate testnet tokens and centralized exchanges. This repository is for testing purposes only, do not use it for real deployment.

Testnet deployment

We have a functional deployment running on kovan testnet. The deployed contracts are as below.

  1. KyberNetworkcontract address = 0x11542d7807dfb2b44937f756b9092c76e814f8ed

The abi of KyberNetwork contract is available at https://github.com/KyberNetwork/smart-contracts/blob/master/contracts/KyberNetwork.abi

  1. Three dummy token contracts created for the demo. Each token/ contract is called "Test i", symbol "TSTi" for i=0,1,2. The addresses for these contracts are 0xbb9c28a16654a0cd510f5b0a250255c4a07211f2, 0x950b87923d52b09b1050abda589f91521e17e606 and 0x2c018fc6c9bb2b7653136dc7c5b7b588f2d11986.

  2. The Reserve contract's address on Kovan testnet: 0x60860ce9688f4200e87e61b9a9a171cee1dc5f65

token_i => eth (wei) rate = 2^{i+1} * (10^18), for i = 0,1,2 eth (wei) => token_i rate = (10^18)/2^{i+1}.

reserve has many (10^40) tokens now, but very few ethers.

Main functions

We describe the main functions of the Kyber contract as below.

Trade function

    function trade( ERC20 source, uint srcAmount,
                    ERC20 dest, address destAddress, uint maxDestAmount,
                    uint minConversionRate,
                    bool throwOnFailure )

throwOnFailure = false maxDestAmount = MAX_UINT destAddress is a simple account (not a contract).

token address = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee means the token is ETH. If source is ETH then you also need to send ether along with your call. If source is token, then you need to call token.approve(kyber network address, amount) before your call.

Important notice: any value below 1000 wei/tokens is considered 0. Deals must be over 1000 wei (1000 tokens).

getRate function

    function getRate( ERC20 source, ERC20 dest, uint reserveIndex ) constant returns(uint rate, uint expBlock, uint balance);

reserveIndex should be 0. The function returns three numbers (guessing in web3 it is an array of size 3. It is like that in truffle) including rate, expiration block and balance (how many tokens reserve has).

Kyber wallet contract

Kyber wallet integrates with existing Kyber Network. A user needs to deploy this contract with c'tor param _kyberNetwork = 0x11542d7807dfb2b44937f756b9092c76e814f8ed. Then user should send ether and/or tokens to the contract. It can be in a standard way (just send or transfer ether or tokens to contract address).

The function to call is

    function convertAndCall( ERC20 srcToken, uint srcAmount,
                             ERC20 destToken, uint maxDestAmount,
                             uint minRate,
                             address destination,
                             bytes   destinationData,
                             bool onlyApproveTokens,
                             bool throwOnFail ) {

If onlyApproveTokens = true and destToken is not ETH, then function does not transfer tokens to destination, instead it is just appoving it. If destinationData is an empty array, then then default function is called in destination (and destination could also be a standard account). It is probably better to first try with empty data. An example to non-empty data can be found here and here.

For basic testings, it is possible to set the wallet as destination address and make the transfer invoke recieveEther and recieveTokens.

smart-contracts-1's People

Contributors

ilandoron avatar yaronvel avatar talbaneth avatar namnm1991 avatar xcrux avatar loiluu avatar ductm54 avatar tranvictor avatar

Watchers

James Cloos avatar Bigdot avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.