How to contribute to “Hylian” the decentralized price oracle of ICON (½)

As a P-Rep or an ICONist there are plenty of ways that you can collaborate and help to expand the ICON network and Ecosystem, today we are going to talk about a very interesting way of collaborating.

As the ICON network grows and more DApps and services are built into it, it’s important to have a decentralized and easy way of consulting the current ICX price without the need to depend on only one exchange market value, this is where Hylian comes into play.

Hylian is a decentralized price oracle for ICON created by the P-Rep team ICONation, and what it does is that it reads the ICX price from different SCORE (Smart Contract on Reliable Environment) on the blockchain and takes the median value of all those prices, the SCORE are written in the blockchain by several bots that periodically consult the prices from different open markets.

In order for this to work, we need to have several SCORE dedicated to this and several bots querying for the price on open markets and updating those SCORE, and this is where you as P-Rep or ICONist can help, you can create the SCORE and set up a bot in your pc, a remote server or even a lambda service to update the SCORE and in that way, you will be contributing to Hylian.

Daedric and Marvin

Our goal in this tutorial is to teach you how to set up Daedric and Marvin on the ICON testnet and mainnet so you can collaborate to Hylian and all the DApps that depend on it.

Daedric

Daedric is a price feed designed to be a component required for a price oracle running on ICON to work. The Daedric SCORE operator can update and share a price associated with a ticker symbol at any time. Once deployed, the Daedric SCORE operator may subscribe its SCORE to a price oracle (such as Hylian) in order to take part in the price consensus needed for the oracle to work in a decentralized manner.

In order to create a Daedric price feed, we need to install a couple of packages ( tbears and jq) and verify that we have the necessary python related packages on our machine.

First, check if you have python installed:

$ python3 -V> Python 3.6.9

In case you don’t have python installed run the following:

$ sudo apt update$ sudo apt install python3

Install the Python development package:

$ sudo apt install python3-dev

Install other required packages:

# Install levelDB$ sudo apt install libleveldb1 libleveldb-dev# Install libSecp256k$ sudo apt install libsecp256k1-dev# install RabbitMQ and start service$ sudo apt install rabbitmq-server#install jq a JSON preprocessor$ sudo apt install jq

Set up a working directory:

$ mkdir tbears-work$ cd tbears-work

Create a python virtual environment to work in:

$ python -m venv ./venv && source ./venv/bin/activate

You should now see that you are inside a python virtual environment by seeing this in your console (to get out of the virtual environment simply type deactivate):

(venv) user@machine: ~/tbears-work$

Now inside the virtual environment lets install tbears:

$ pip install tbears

Currently, we are inside our tbears-work/ folder and within a python virtual environment, since tbears was installed using pip inside a virtual environment anytime we want to use tbears we need to source our virtual environment ( source ./venv/bin/activate ) and execute tbears from there.

After successfully installing tbears we can continue with the process of creating our Daedric SCORE.

$ git clone https://github.com/iconation/Daedric.git && cd Daedric

Start tbears using the start_tbears.sh script located at the root folder of the Daedric repository.

$ ./start_tbears.sh

Install the operator wallets:

$ ./install.sh

It will generate 3 operator wallets inside the ./config/ folder.

  • A first one on the Yeouido network in ./config/yeouido/keystores/operator.icx
  • A second one on the Euljiro network in ./config/euljiro/keystores/operator.icx
  • A last one on the Mainnet network in ./config/mainnet/keystores/operator.icx

Inside each respective keystores/ folder there will be a file named operator.password.txt which contains the password of each respective wallet file.

We are going to first deploy a Daedric SCORE on the testnet, so you need to have testnet ICX, you can get them using either one of these faucets:

After funding our wallet with testnet ICX the next step is to deploy the Daedric SCORE with the following command:

./scripts/score/deploy_score.sh -n yeouido -t ICXUSD

The terminal will ask for the wallet password, copy the password from the operator.password.txt file inside the keystores/ folder and paste it into the terminal.

A successful output will look something like this:

tbears deploy output
tbears deploy output

You can test your Daedric SCORE by manually calling the following script:

./scripts/bots/equalizer/icxusd/post.sh -n yeouido

A correct result will look like this:

testing daedric
testing daedric

So what just happened?, well we used a bot to check for the ICX/USD price on an open market and we wrote that price into a transaction against the Daedric SCORE, we can see the transaction hash in the output JSON:

“txHash”: “0x152008ba2818d687328b4d167fed229fda9450df00f4fdc48ae66564fb58d390”

We can check on the testnet wallet the data output written on that transaction (https://bicon.tracker.solidwallet.io/transaction/0x152008ba2818d687328b4d167fed229fda9450df00f4fdc48ae66564fb58d390).

{  “method”: “post”,  “params”: {    “value”: “4716448159773378560”  }}

And that value translates as follow to a USD price 1/4716448159773378560*10**18 = 0.21202395661 USD.

NOTE: You might get an error like the following:

If that’s the case, open the calls/post.json file and replace the value of the key nid from 0x1to 0x3 and run the command again. It’s important to change that value back to 0x1 for the mainnet Daedric SCORE to work correctly.

You can check the value of your feed using the ICON Yeouido (testnet) tracker.

https://bicon.tracker.solidwallet.io/contract/<your_contract_address>#readcontract

After finishing with the testnet when can now continue with the deployment on the mainnet. Run the following command:

./scripts/score/deploy_score.sh -n mainnet -t ICXUSD

NOTE: This command sometimes displays an error even when the SCORE has been successfully deployed, for an unknown reason. If that happens to you, please check for the contract address in the tracker by checking the last transaction in your mainnet wallet:

tracker.icon.foundation/address/<operator_hx_address>

Once you retrieved the SCORE address, write it in the ./config/mainnet/score_address.txt file.

The ICON team may take 3–4 working days for approving your SCORE. Please remain patient, and once your SCORE has been approved please go to the following forum post to share your Daedric SCORE to the ICONation Team so they can whitelist you and add your SCORE into Hylian.

https://forum.icon.community/t/hylian-icon-price-oracle/97

This is the end of this first article, in our next one we will be configuring another amazing tool called Marvin created by the P-Rep Team RHIZOME, Marvin is a bot that you can easily set up in your computer, a remote server and even as an AWS lambda service, to update your Daedric SCORE at intervals.

Thanks for reading, and don’t forget to vote and support your favorite teams so you can help them continue creating amazing projects and expand the ICON Ecosystem!

Link to part 2: https://medium.com/@espanicon/how-to-contribute-to-hylian-the-decentralized-price-oracle-of-icon-2-2-1c4f9032a2f3

Espanicon Team

Website: espanicon.team

Twitter: www.twitter.com/espanicon

Team Telegram Channel: https://t.me/espanicon

Medium: www.medium.com/@espanicon

ICON P-Rep. espanicon.team