How to contribute to “Hylian” the decentralized price oracle of ICON (2/2)
This is the second part of our two-part series on “How to contribute to ‘Hylian’ the decentralized price oracle of ICON” if you haven’t read the first part you can find it on this link.
As we explained in our last article, in order to be a part of “Hylian” we need a SCORE and a bot. For the SCORE we use Daedric (you can check our last article to learn about that) and for the bot, we are going to be using Marvin which is a bot created by P-Rep team RHIZOME.
Marvin is a price feed application (bot) designed to provide an hourly price update to a Daedric SCORE running on the ICON Public Blockchain (see here: https://github.com/iconation/Daedric). Marvin has been written in .Net Core 2.1 and is able to run on Windows, Ubuntu or on Amazon Web Services Lambda (https://aws.amazon.com/lambda/)
In this article, we are going to be installing and running Marvin on a machine running ubuntu 18.04.
INSTALLING AND CONFIGURING MARVIN
NOTE: For the steps on this article we are assuming that you already followed the steps and installations detailed in our first part of this series.
By now you should have tbears
and jq
already installed in your computer so the next step will be to install the necessary prerequisites to run Marvin on our computer.
Register Microsoft key and feed
$ wget -q https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb$ sudo dpkg -i packages-microsoft-prod.deb
Install the .NET SDK
$ sudo apt-get install apt-transport-https$ sudo apt-get update$ sudo apt-get install dotnet-sdk-2.1
After installing the prerequisites, the next step is to clone Marvin from the official repo
$ git clone https://github.com/rhizomeicx/marvin.git$ cd marvin/
Inside this folder, we are going to create a new folder and paste inside the Keystore file (wallet) we generated while setting up Daedric
$ mkdir SCORE
After pasting the files inside we should see the following
$ ls SCORE/
> operator.icx operator.password.txt
Marvin is designed to be driven via an appconfig.json
file that looks like this
{ “LogPath”: “log/”, “Keystore”: “SCORE/operator.icx”, “Daedric_Address”: “cx58ca994194cf0c6a2a68b789d81c70484a5675b3”, “Network_Url”: “https://bicon.net.solidwallet.io/api/v3", “testTransactions”: “true”}
The Network_Url
values for mainnet and testnet (yeouido) are as follow:
- testnet: https://bicon.net.solidwallet.io/api/v3
- mainnet: https://ctz.solidwallet.io/api/v3
Edit your appconfig.json
file with your SCORE address, in our case we will be running on both testnet and mainnet.
An important aspect to know is that the Keystore
folder path is relative to the folder that you are executing the commands on, so for example, if you are running Marvin from /home/user/marvin
like we are doing, and the value of Keystore
is log/
the logs files will be created in /home/user/marvin/log/
.
Inside the Marvin/Marvin-Ubuntu/
folder run the following command to build the bot
$ dotnet publish -c Release -r ubuntu.16.04-x64
After running the build command we can run Marvin but before doing so, there are some specific changes we need to make in order to run the bot on the testnet and the mainnet.
For running on the testnet we need to open the file Marvin/Marvin.cs
and change the code for the function called
private Transaction CreateTransaction(double price, bool testNet=false)
And update the NID
parameter as follow
var builder = new CallTransactionBuilder{ NID = 3, //Pass 3 for testNet PrivateKey = GetPrivateKey(), To = _appsetting.Daedric_Address, StepLimit = NumericsHelper.ICX2Loop(“0.000000001”), Method = “post”};
For running on the mainnet we can leave it as it is or change it like this
var builder = new CallTransactionBuilder{NID = 1, //Pass 3 for testNetPrivateKey = GetPrivateKey(),To = _appsetting.Daedric_Address,StepLimit = NumericsHelper.ICX2Loop(“0.000000001”),Method = “post”};
To make it easier here are the Marvin.cs files for the mainnet and testnet so you can simply download them and use the one you need.
Now we can go to the root folder of our project and run the following command (make sure to use your wallet password so that Marvin can sign the transaction)
/usr/bin/dotnet /Marvin/Marvin-Ubuntu/bin/Release/netcoreapp2.1/ubuntu.16.04-x64/publish/Marvin-Ubuntu.dll “keystorepassword”
After running the command you can check the log in log/<date>
to confirm the execution of Marvin and also check the wallet in the tracker to verify that a new transaction has been signed in the SCORE, here are the mainnet and testnet trackers:
- mainnet: https://tracker.icon.foundation/
- Testnet: https://bicon.tracker.solidwallet.io/
After checking out that everything is working fine, we need now to configure Marvin to run at intervals to update periodically the Daedric SCORE, each transaction will have a small fee so depending on how regularly you will be running Marvin you will need to have the necessary funds in your wallet.
At current transaction fee prices, running Marvin every 10 minutes will cost around 6.3 ICX per month (current TX fee at 0.0014 icx).
We are going to be setting ours to run every 15 minutes by using cron jobs in Linux, but first, we are going to create a bash script to make things less error-prone.
Run the which
command as follows to find out the folder path of your bash
and dotnet
.
$ which bash> /bin/bash$ which dotnet> /usr/bin/dotnet
Create a marvin-cron.sh
file and add the following (modify the paths to match your folders and add your wallet password)
#!/bin/bashcd /home/ubuntu/marvin-mainnet;/usr/bin/dotnet Marvin/Marvin-Ubuntu/bin/Release/netcoreapp2.1/ubuntu.16.04-x64/publish/Marvin-Ubuntu.dll “<password>;
Set the permissions on the file
$ chmod +x marvin-cron.sh
Open the cron job editor
$ crontab -e
Add the following task to cron
*/15 * * * * /home/ubuntu/marvin-mainnet/marvin-cron.sh
If your Daedric SCORE has already been approved everything should be working and your Marvin bot now will be updating the SCORE every 15 minutes with the current price of ICX.
Thanks for reading and for collaborating with the Hylian decentralized price oracle!, 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!
Espanicon Team
Website: espanicon.team
Twitter: www.twitter.com/espanicon
Team Telegram Channel: https://t.me/espanicon
Medium: www.medium.com/@espanicon