Deploying Kyber on the Matic testnet
Matic Network is a sidechain based scaling solution for public blockchains. It is based on an adapted implementation of Plasma framework. Matic provides scalability while ensuring a superior user experience in a secured and decentralized manner.
Kyber Network is an on-chain liquidity protocol that aggregates liquidity from a wide range of reserves, powering instant and secure token exchange in any decentralized application.
This guide will take you through:
- Deploying Kyber contracts on Matic testnet
- Updating KyberSwap frontend to work with these contracts
- Deploying the frontend to IPFS
Pre-requisite
Our migrate project using package aliases, we will need npm v6.9.0+.
To see which version you have
$ npm -v
then install the newest npm update if needed
$ npm install npm@latest -g
Deploy contracts
I tried to deploy Kyber network contracts using their scripts in smart-contracts repository but got no luck. The deploy scripts in master branch seem out-of-sync with the contracts. Also i didn’t find the Swap contract in any branch.
Eventually i used https://etherscan.io to get the current mainnet contracts source code. For example, their KyberSwapLimitOrder
can be found here.
To make this article easier to follow, i collected all needed contracts in this repository.
Clone the repository and install node dependencies
$ git clone https://github.com/bakaoh/kyber-matic.git
$ cd kyber-matic/
$ npm install
Deploy the contracts
$ npm run migrate
You don’t need to input a deploy address and its private key because the script randomly creats and prints them out. Keep the private key in safe place, you will need it to operate the Kyber contracts, or use it to transfer the admin role to another address.
As always, the deployment process on Matic testnet will just take few seconds. The output contains the all the needed addresses
Deploy from: 0x8B4410C882dC2e01e1dE3022f0cd94C7D82723bF
Private key: 0x2d8f7c4810608f7fd1d258288e1c2dd9b171c0a07493324f4f3b989bad51f4fe
Starting compilation
Finished compilation
KyberNetworkCrystal: 0xa8274022E892fAFaC6a244200d38f9d3e4b5DbBd
KyberNetworkProxy: 0xfB6bC957AcfcAd5bfe32dD66081F797fF6CD0974
KyberNetwork: 0x5BbF1cE19E6b7A40435DF83f8D4aC60D8E7E48B9
ExpectedRate: 0x1d463bc37056EB4763D6A94B3F823955a04854Ed
FeeBurner: 0x3AB6ec775ffABF490DE41E74D8E98AB015a75f20
ConversionRates: 0x41ea11A0922604b7caF3D1D9E132De400Eb80cc2
KyberReserve: 0xB1445813d21DfB29A93E6DBBEf77A270BEf3b63A
KyberSwapLimitOrder: 0x985DfF5d7AA2107253b45866AaB5B9588e6D8c3f
You can place these addresses to the explorer URL, like this, to make sure the contracts is correctly deployed on Matic.
The migrate
command also update matic.json
file in the root directory with the new addresses.
Update KyberSwap frontend
Clone the repository and install node dependencies
$ git clone https://github.com/KyberNetwork/KyberSwap.git
$ cd KyberSwap/
$ npm ci
Copy matic.json
file created in the previous session to env/config-env/
folder. Your env/config-env/
folder will look like this
$ ls -1 env/config-env/
matic.json
production.json
rinkeby.json
ropsten.json
staging.json
staging_limit_order.json
Open package.json
file and add these lines to the scripts session
...
"build-matic": "NODE_ENV=matic node webpack-wrapper.js",
"matic": "webpack-dev-server --content-base src --inline --hot --history-api-fallback --host 0.0.0.0 --port 3002 --env.chain=matic --env.logger=true",
...
Open src/js/services/ethereum/nodeProviders/BaseProvider.js
file, find getRateAtSpecificBlock
function, you will see a rpc call like this
this.rpc.eth.call({
to: BLOCKCHAIN_INFO.network,
data: data
}, blockno)
Remove the blockno
parameter in that call
this.rpc.eth.call({
to: BLOCKCHAIN_INFO.network,
data: data
})
Run the frontend and go to http://localhost:3002 to see the result
$ npm run matic
Don’t forget installing Metamask and configuring it to Matic testnet. Follow the official document for more details.
Deploy frontend
Build the frontend
$ npm run build-matic
A new directory matic
will be created in the dist
folder.
Copy these files/folders from dist/ropsten
to your dist/matic
- trading_view/
- foundation-float.min.css
- foundation-prototype.min.css
- 0f7ddc24583501b1de6e5e652c6fb450.png
- aed5c16656d0b0cff3bf115adcd3935d.svg
- ea54324259d087da144746490d84dcb8.ttf
- 66313f98b4b49bebfc632fcdebe6a8bb.svg
- 9c46095118380d38f12e67c916b427f9.ttf
- a98626e1aef6ceba5dfc1ee7112e235a.ttf
- c88cecbffad6d8e731fd95de49561ebd.ttf
Check if the build version work as expected
$ cd dist/matic/
$ python3 -m http.server
Go to http://localhost:8000
Deploy the frontend to ipfs is just a few steps away using ipfs-deploy
$ npm install -g ipfs-deploy
$ ipfs-deploy dist/matic
You may deploy it to gh-pages or any web server of your choice.
Conclusion
There’re till some internal api that the Kyber team hasn’t open source yet, so you may see errors in browser console.
To operate the network, you may need some basic understanding of their model. The developer document is a good start. Some actions should be done next is
- Add admin, operator, alerter for KyberNetwork, KyberReserve, ConversionRates, FeeBurner, ExpectedRate contracts
- Set expected rate parameters
- Set burn fee parameters
- Set conversion rate parameters
- List token
Thanks for reading and I do hope you found this article somewhat helpful.