This repository is used as complement to the workshops conducted by Kyber. It can also be used to quickly test the Kyber contracts in your local machine.
- Slides
- KyberDeveloper Portal
- KyberDeveloper Telegram
- Workshop Repository
- Ropsten ETH Faucets
- Ropsten KyberSwap
Kyber is a widely used on-chain protocol that makes accessing liquidity simple for users, DApps and financial applications. The protocol has powered decentralised token swaps on popular wallets like MyEtherWallet and imToken, decentralised token payments (users can pay in any supported ERC20 token) in popular DApps like Etheremon and Peepeth and providing an on-chain liquidity source for decentralised financial applications like MelonPort, Set Protocol, b0x and many more.
Kyber protocol brings token inventories and prices on-chain, hence allowing developers to directly embed value exchanges into their smart contracts without any technical or security overhead. This allows for:
-
Instant confirmation. A transaction happens with instant confirmation if it's sent from on-chain entities like smart contracts. Otherwise, once the transaction is included on the blockchain, the execution triggered by the transaction is immediately confirmed.
-
Operation certainty. There is no transactional risk. Users know the rate and how much liquidity is available before they commit their transaction. There is also no settlement uncertainty or counterparty risk.
-
Global and diverse pool of different tokens. Kyber welcomes token holders to contribute their token to the liquidity pool. By having their token made available to the liquidity pool, the token will be available in all services integrated with Kyber.
-
Node and NPM LTS versions
10.14.1
and6.4.1
respectively. Download from nodejs.org -
Ganache
Install the Ganache AppImage by downloading here https://truffleframework.com/ganache.
To use the provided Ganache snapshot, install ganache-cli
.
sudo npm install -g ganache-cli
- Truffle
Install the latest Truffle v5 beta.
sudo npm install -g [email protected]
- Install the rest of the NPM packages
npm install
workshop
├── config
│ ├── network.json
│ └── tokens.json
├── contracts
│ ├── ConversionRatesInterface.sol
│ ├── ConversionRates.sol
│ ├── ERC20Interface.sol
│ ├── examples
│ │ ├── SwapEtherToToken.sol
│ │ ├── SwapTokenToEther.sol
│ │ └── SwapTokenToToken.sol
│ │ └── Trade.sol
│ ├── ExpectedRateInterface.sol
│ ├── ExpectedRate.sol
│ ├── FeeBurnerInterface.sol
│ ├── FeeBurner.sol
│ ├── KyberNetworkInterface.sol
│ ├── KyberNetworkProxyInterface.sol
│ ├── KyberNetworkProxy.sol
│ ├── KyberNetwork.sol
│ ├── KyberReserveInterface.sol
│ ├── KyberReserve.sol
│ ├── LiquidityConversionRates.sol
│ ├── LiquidityFormula.sol
│ ├── Migrations.sol
│ ├── mockTokens
│ │ ├── KyberGenesisToken.sol
│ │ ├── KyberNetworkCrystal.sol
│ │ ├── Mana.sol
│ │ ├── OmiseGo.sol
│ │ ├── Salt.sol
│ │ └── Zilliqa.sol
│ ├── PermissionGroups.sol
│ ├── SanityRatesInterface.sol
│ ├── SanityRates.sol
│ ├── SimpleNetworkInterface.sol
│ ├── Utils2.sol
│ ├── Utils.sol
│ ├── VolumeImbalanceRecorder.sol
│ ├── WhiteListInterface.sol
│ ├── WhiteList.sol
│ └── Withdrawable.sol
├── db
├── examples
│ ├── solidity
│ │ ├── SwapEtherToToken.sol -> ../../contracts/examples/SwapEtherToToken.sol
│ │ ├── SwapTokenToEther.sol -> ../../contracts/examples/SwapTokenToEther.sol
│ │ └── SwapTokenToToken.sol -> ../../contracts/examples/SwapTokenToToken.sol
│ │ └── Trade.sol -> ../../contracts/examples/Trade.sol
│ ├── truffle
│ │ ├── getExpectedRate.js
│ │ ├── swapEtherToToken.js
│ │ ├── swapTokenToEther.js
│ │ ├── swapTokenToToken.js
│ │ └── trade.js
│ └── web3
│ ├── abi
│ │ ├── KyberNetworkProxy.abi
│ │ ├── KNC.abi
│ │ ├── OMG.abi
│ │ ├── MANA.abi
│ │ ├── SALT.abi
│ │ └── ZIL.abi
│ ├── getExpectedRate.js
│ ├── swapEtherToToken.js
│ ├── swapTokenToEther.js
│ └── swapTokenToToken.js
├── LICENSE
├── migrations
│ ├── 1_initial_migration.js
│ ├── 2_deploy_tokens.js
│ ├── 3_deploy_contracts.js
│ ├── 4_setup_permissions.js
│ ├── 5_setup_KyberNetworkProxy.js
│ ├── 6_setup_KyberReserve.js
│ ├── 7_setup_KyberAutomatedReserve.js
│ ├── 8_setup_FeeBurner.js
│ ├── 9_setup_ExpectedRate.js
│ ├── 10_setup_ConversionRates.js
│ ├── 11_setup_LiquidityConversionRates.js
│ ├── 12_setup_SanityRates.js
│ ├── 13_setup_WhiteList.js
│ ├── 14_setup_KyberNetwork.js
│ ├── 15_transfer_tokens.js
│ └── 16_deployment_summary.js
├── package.json
├── README.md
├── test
└── truffle.js
config - contains JSON files that hold configuration details of the Kyber contracts used for migrations
contracts - contains all the Kyber contracts, plus some mock tokens and solidity examples for testing
examples - contains truffle and web3 example scripts to interact with Kyber's smart contracts, and also contains solidity examples for Kyber contract interactions
migrations - contains the truffle migration scripts to deploy and setup the Kyber contracts in a test environment
A Ganache snapshot has already been pre-made with the Kyber contracts deployed. You can immediately interact with the contracts without having to do migrations. The snapshot is stored in db
folder.
We use the mnemonic gesture rather obey video awake genuine patient base soon parrot upset lounge
for the accounts. The user wallet (0x47a793D7D0AA5727095c3Fe132a6c1A46804c8D2
) already contains some ETH and test ERC20 tokens.
NOTE: The mnemonic provided is used only for testing. DO NOT use the accounts generated for your own personal use in mainnet, as you can potentially lose those funds.
To run the snapshot locally, run the command:
ganache-cli --db db --accounts 10 --defaultBalanceEther 500 --mnemonic 'gesture rather obey video awake genuine patient base soon parrot upset lounge' --networkId 5777 --debug
If you wish to deploy the Kyber contracts yourself, you can run the following commands:
Run ganache-cli in one terminal session
ganache-cli --accounts 10 --defaultBalanceEther 500 --mnemonic 'gesture rather obey video awake genuine patient base soon parrot upset lounge' --networkId 5777 --debug
In a new terminal session, connect to the ganache network, and run the truffle migration scripts
truffle migrate --network development
You can directly interact with the Kyber contracts on the Ganache network. We have provided some example scripts in the example
directory.
For the Truffle examples:
truffle exec examples/truffle/<SCRIPT>
e.g.
truffle exec examples/truffle/swapEtherToToken.js
For the Web3 examples:
node examples/web3/<SCRIPT>
e.g.
node examples/web3/swapEtherToToken.js
For the Solidity examples, they are already deployed in the Ganache network using the Truffle migration scripts. You can interact with the Solidity examples using truffle console
, or write your own Truffle/Web3 scripts to interact with the Solidity example contracts.
development
(admin) 0x2B522cABE9950D1153c26C1b399B293CaA99FcF9
(operator) 0x3644B986B3F5Ba3cb8D5627A22465942f8E06d09
(alerter) 0x9e8f633D0C46ED7170EF3B30E291c64a91a49C7E
(user) 0x47a793D7D0AA5727095c3Fe132a6c1A46804c8D2
(reserve) 0x0d95EBB4874f17157e40635C19dBC6E9b0BFdb03
(tax) 0x5243B5970f327c328B2739dEc88abC46FaE8931A
(bob) 0xe1a1d3637eE02391ac4035e72456Ca7448c73FD4
(alice) 0x1cF1919d91cebAb2E56a5c0cC7180bB54eD4f3F6
(KNC) 0x8c13AFB7815f10A8333955854E6ec7503eD841B7
(OMG) 0x3750bE154260872270EbA56eEf89E78E6E21C1D9
(SALT) 0x7ADc6456776Ed1e9661B3CEdF028f41BD319Ea52
(ZIL) 0x400DB523AA93053879b20F10F56023b2076aC852
(MANA) 0xe19Ec968c15f487E96f631Ad9AA54fAE09A67C8c
(KyberNetwork) 0xA46E01606f9252fa833131648f4D855549BcE9D9
(KyberNetworkProxy) 0xF6084Ad447076da0246cD28e104533f9f51dbD2F
(ConversionRates) 0x738d8Ef6AcaE15660E467AB2B2cF3a488e40FF64
(LiquidityConversionRates) 0xd44B9352e4Db6d0640449ed653983827BD882885
(SanityRates) 0xd3add19ee7e5287148a5866784aE3C55bd4E375A
(KyberReserve) 0x6E9b241Eec2C4a80485c1D2dF750231AFaf1A167
(AutomatedKyberReserve) 0x8b3BdEcEac3d23A215300A3df19e1bEe43A0Ac9C
(FeeBurner) 0xf71D305142eC1aC03896526D52F743959db01624
(WhiteList) 0x63D556067eDbCD97ACc3356314398F70d4CcF948
(ExpectedRate) 0xE16d27F08e94D9d6f05C988169E388068C790B75
(SwapEtherToToken) 0x19F18bde9896890f161DeD31B05b58dc0ffD911b
(SwapTokenToEther) 0xdE4e2118f45f1b27699B25004563819B57f5E3b2
(SwapTokenToToken) 0x586F3cDCe25E76B69efD1C6Eb6104FAa0760A6a8
(Trade) 0x295631209354194B6453921bfFeFEe79cD42BdB9
NOTE: The KyberReserve
and AutomatedKyberReserve
are the same contracts. A duplicate was made as a workaround due to a limitation of Truffle where only one instance of a contract can be migrated.