How to Deploy bZx Protocol on Matic Network
To enable a set of decentralized protocols on the Matic Network to make it easy for decentralized app (DApp) developers to reuse this functionality in their DApps just like on Ethereum, rather than reinventing the wheel.
Introduction
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. More about Matic Network…
bZx is a Decentralized margin-lending protocol
How to set it up
Prerequisites:
- Node.js (v10+): Install or update Node.js from official page.
$ node -v
$ npm -v
$ npm install -g update-node
- Truffle (v5+): Install Truffle a development environment for blockchain from official page.
$ truffle -version
- Yarn (v1+): Install Yarn from official Page.
$ yarn --version
Setup the environment
Install protocol dependencies
$ git clone https://github.com/bZxNetwork/bZx-monorepo
$ cd bZx-monorepo
bZx-monorepo$ yarn
$ cd packages/contracts
$ yarn
Open bZx-monorepo/packages/contracts/truffle.config
file and add matic network details for migration. Your file should look like this.
- Comment out
var HDWalletProvider = require("truffle-hdwallet-provider");
- Add the below network details in the subsection of module exports.
matic: {
provider: function () {
return new HDWalletProvider(
"gesture rather obey video awake genuine patient base soon parrot upset lounge",
"https://testnet2.matic.network"
);
},
network_id: 8995,
gas: 8000000,
gasPrice: 0
}
Here, HDWalletProvider passes two arguments, first is mnemonic and second is network link.
Warning: Please keep your mnemonic or private key safe. Use the above mnemonic for testing purposes only.
Deploy Contracts
Now, Let’s prepare the migration files for Matic Network.
bZx protocol have many files which aren’t required or important to matic network.
- Let’s Remove the migration files which aren’t required to be deployed on matic network. Go to
bZx-monorepo/packages/contracts/migrations
and remove or transfer the following files out of the migrations directory. Se this for reference.
7_deploy_BZRxTokenConvert.js
13_deploy_iToken_Helpers.js
18_deploy_TestNetFaucet.js
19_dev_deploy_test_tokens.js
20_testnetonly_deploy_sample_orders.js
2. Now, Let’s prepare Protocol-config.js which includes addresses of protocols, coins and oracle. For matic, some of them are required to be mapped as it is a sidechain. And others have to be manually deployed on Matic testnet.
Here is the link of the addresses.
Mapped Addresses
ZRXToken: "0xc38ec8c07b3cfbf59cd9e5e9d01efed3bdd41384", EtherToken: "0x3a33ddf84eb9e16129b00e92dd3445a96b329d29", WETH9: "0x84e7ab5ec187ce4fa96588fee28b4d9299bd6332",
BZRXToken:"0xb2f849d046b7fc5f90f18aac63d56e40cab186e2",
DAITokenAddress: "0xfef8a6d3e37683bd16bb7a54052a85ad70b09192", WBTCTokenAddress: "0x0cf3cf33448cb705ffbe88a934b4eafe8b0c2758"
P.S: Thanks to Angela from Matic Network for the above mapped addresses.
Manually Deployed
TokenTransferProxy: "0x3026cAD1B2e0E4c4893B7FE8fF868a0Ef3F8975f", ExchangeV1: "0xCc786388E6e82C525b8ac324d81dCaCAC32Eb853", TokenRegistry: "0xd574C27132f00F5b82A09F8E05726Ab3433c5617",
ERC20Proxy: "0xc2fF576A20BB628aD646FA46f04A306f6D74695A", ERC721Proxy: "0xa43AF06155F3f79CA2504473706bF17310814d22"
Other Addresses are not required while deploying but could be deployed if required.
Follow this easy guide to deploy contracts on Matic. Contracts can be found on mainnet or other test network. Just copy the address and search on etherscan.
Add the below set of addresses to the protocol-config.js
matic: {
ZeroEx: {
//Mapped Addresses
ZRXToken: "0xc38ec8c07b3cfbf59cd9e5e9d01efed3bdd41384",
EtherToken: "0x3a33ddf84eb9e16129b00e92dd3445a96b329d29",
WETH9: "0x84e7ab5ec187ce4fa96588fee28b4d9299bd6332",
//Deployed Addresses
TokenTransferProxy: "0x3026cAD1B2e0E4c4893B7FE8fF868a0Ef3F8975f",
ExchangeV1: "0xCc786388E6e82C525b8ac324d81dCaCAC32Eb853",
TokenRegistry: "0xd574C27132f00F5b82A09F8E05726Ab3433c5617",
ExchangeV2: "0x0000000000000000000000000000000000000000",
ERC20Proxy: "0xc2fF576A20BB628aD646FA46f04A306f6D74695A",
ERC721Proxy: "0xa43AF06155F3f79CA2504473706bF17310814d22",
AssetProxyOwner: "0x0000000000000000000000000000000000000000"
},
ENS: {
Registry: "0x0000000000000000000000000000000000000000",
Resolver: "0x0000000000000000000000000000000000000000"
},
BZRXToken: "0xb2f849d046b7fc5f90f18aac63d56e40cab186e2",
OracleNotifier: "0x0000000000000000000000000000000000000000",
KyberContractAddress: "0x0000000000000000000000000000000000000000",
BZRXTokenSale: "0x0000000000000000000000000000000000000000",
BZxEther: "0x0000000000000000000000000000000000000000",
MultiSig: "0x0000000000000000000000000000000000000000",
TokenizedRegistry: "0x0000000000000000000000000000000000000000", // old: "0xaa5c713387972841995553c9690459596336800b",
DAITokenAddress: "0xfef8a6d3e37683bd16bb7a54052a85ad70b09192",
WBTCTokenAddress: "0x0cf3cf33448cb705ffbe88a934b4eafe8b0c2758"
}
Now, We are all prepared to migrate the contracts on Matic Net.
Open Terminal
cd bZx-monorepo/packages/contracts
truffle migrate --network matic
Volla!!! Just like that bZx protocol is deployed on Matic Network.
Updates and Changes
bZx protocol is in active devlopment and will make changes in near future. If you face any problem while deploying join bZx and matic community on telegram or discord. They will definetly help you.
Thumbs up to Tom Bean(bZx Team) and Angela(Matic) for helping me out.