Introducing Wrapped Hive Engine Tokens - wTokens-in-a-box

in #hiveengine18 days ago (edited)

Wrapped Hive Engine Tokens

wHE-token.jpg
original image source

As some of you might be aware, I've been working on Wrapped tokens for the last 3 months. First Wrapped Hive, then modified oracle for wLEO and now I'm presenting an out-of-a-box solution for anyone to create their own Hive Engine Wrapped Token. It's meant mostly for "owners" of HE tribes, but anyone can start one if they want.

I tried to make setup as easy as possible, but you will still need to follow some instructions. But it's as close to no-code as possible. I tried to create the same experience as the hive-in-a-box does for the witness setup.

It's free for anyone, feel free to use & modify it. Donations are welcome ;)

First, why would you even want to wrap Hive Engine tokens to Ethereum when HE has free, almost instant transactions (compared to quite expensive fees on Ethereum). The answer is simple, users, and liquidity.

Even most "liquid" tokens on Hive Engine such as LEO or DEC have under $50k in liquidity. There is less than $100k (1M) swap.hive wrapped on HE. Compared to $2.9B ($2,900,000,000) on Uniswap alone and $11B locked in entire DeFi, you can see there is a big difference.

Before starting with the actual setup, you should know how this works (don't worry, no technical details here)
The setup (and app itself) is made of 3 parts:

  • Frontend:
    The frontend is a nice website that will show information about your wrapped token and provide an interface for interacting with smart contracts to non-technical users.
    It's using generic whive.network design, but you can modify header color in config ;) All other info such as token name, symbol, platforms... is updated directly from the config file, so no coding required. It does not have access to any private info such as private keys.
    Source code: https://github.com/fbslo/whe-frontend

  • Backend:
    This is an actual app that will track events on both Hive & Ethereum blockchain and take care of wrapping and unwrapping tokens. It's completely separated from the frontend and should be run on a separate server for maximum security.
    Source code: https://github.com/fbslo/whe-backend

  • Smart Contract:
    Smart contract for ERC20 Ethereum token.
    Source code: https://github.com/fbslo/wToken-contract

Security

As you might know, wLEO got hacked a few weeks ago and over $100k in liquidity was stolen. Here are some ways I implemented to prevent possible future disasters.

This oracle app is centralized, and as such, there is no way to make it 100% secure. But we can do a lot to reduce the effect any hack/exit scam/bug can cause.

While Hive Engine is (currently) centralized, this app has an option to prevent attacks from this. You can run your own Hive Engine node as a secondary node, and (if enabled), the app will check any incoming HE transaction in both the "official" server and your backup. Only if the transaction is valid on both nodes, ERC20 tokens will be issued. THIS FEATURE IS EXPERIMENTAL, PLEASE DON'T USE IN PRODUCTION YET.

While the default method for creating tokens is mint (new tokens are later burned), the app has native support for transfer method, where tokens are not minted, but instead transferred from the hot wallet (while you keep most of the tokens in the cold wallet). You can select your method during the contract setup. If you use transfer method, all tokens will be minted during setup and no new tokens will be created later. You will need to keep them in cold wallet.

What do you need?

  • Linux server (tested on Ubuntu 18.04)
  • API key from EthGasStation
  • Infura.io API key / Ethereum node endpoint
  • Some ETH to pay for fees (0.15-0.25 should be enough, but it varies a lot) when deploying a new token
  • ~20-30 minutes

Please be aware there might still be some bugs in the code. Use at your own risk!

ERC20 Token Smart Contract deployment

Edit: This will work on testnets, but on mainnet with Infura, it will fail. I will update when I find the solution.

Let's start with the smart contract deployment, so we will have a contract address later. ERC20 tokens are simply smart contracts on Ethereum that include a set of at least 6 basic functions.

Our token is using industry standard OpenZeppelin contract with 2 extra functions, convertTokenWithBurn()/ convertTokenWithTransfer()and convertTokenFromWithBurn() that are used when converting tokens back to native asset.


Install NodeJS:

curl -sL https://deb.nodesource.com/setup_12.x -o nodesource_setup.sh`
sudo bash nodesource_setup.sh
sudo apt install nodejs

Let's just clone source code && install dependencies and CLI:

git clone https://github.com/fbslo/wToken-contract && cd wToken-contract && npm install -g truffle && npm install && npm run install_cli

If you encounter any EACCES: permission denied errors, try running these commands (especially npm install -g truffle as root, so sudo npm install -g truffle)

Now run CLI: contract

You will be asked questions about installation, and in the end, you will receive a contract address. It's also stored in state.json. ABI will be generated in the tokenABI.js file.

Please copy tokenABI.js file into src/libs/ethereum/ during backend setup and replace existing tokenABI.js file.

Frontend

As I mentioned earlier, it should be running on a separate server as backend, but if you want to use only one server, use cloudflare to hide real IP and prevent DDoS attacks.

Install NodeJS (if you didn't already do it for token deployment):

curl -sL https://deb.nodesource.com/setup_12.x -o nodesource_setup.sh`
sudo bash nodesource_setup.sh
sudo apt install nodejs

Now clone the project source code from GitHub:

git clone https://github.com/fbslo/whe-frontend

Move to the project directory and install dependencies:

cd whe-frontend && npm install && npm run install_cli && npm install pm2 -g && npm install pm2

Now you only need to edit config file. But first, let's rename it and then open it with your favorite text editor (I prefer nano):

mv .env.demo .env && nano .env

You will see the config file, I think it's self-explanatory, but here you can see config file with comments.

Once you are done, save & close it with ctrl+x

Now customize "platforms":

Edit platforms.json file: nano platforms.json

Add objects to the array, like seen in the example below. Font Awesome icon names can be found at https://fontawesome.com/.

{
  "platforms": [
    {
      "url": "https://url.com",
      "name": "platform",
      "fa_icon": "fa-home"
    },
    {
      "url": "https://url2.com",
      "name": "platform2",
      "fa_icon": "fa-home"
    }
  ]
}

Now start the app with CLI: frontend start

You might see the error ReferenceError: document is not defined, just ignore it.

List of all available commands:

start, restart, logs, help, stop, status

Visit http://your_ip_or_localhost:8080 and you should see your website!

It's recommended to use a reverse proxy (such as Nginx) to redirect requests from ports 80 (http) and 443 (https) to 8080.

Backend

As before, you need NodeJS installed, so if you don't have it yet, install it:

curl -sL https://deb.nodesource.com/setup_12.x -o nodesource_setup.sh`
sudo bash nodesource_setup.sh
sudo apt install nodejs

Now clone source code:

git clone https://github.com/fbslo/whe-backend && cd whe-backend

Install MongoDB:

sudo apt install -y mongodb

Install dependencies and CLI:

npm install && npm run install_cli && npm install pm2 -g && npm install pm2

Again, now you need to edit config file:

mv .env.demo .env && nano .env

You will see the config file, I think it's self-explanatory, but here you can see the config file with comments.

Now you can start the oracle using the command: oracle start

List of all available commands:

start, restart, logs, help, stop, status

CLI is just wrapper for PM2 with some extra stuff (e.g. database status...).

I hope this tutorial was not too hard to understand. If you notice any errors or have any question send me a DM on discord: fbslo [Hive witness]#8470

If you think it's still to hard, you can hire me to do this for you (I charge $100 fee), also send me a DM on discord: fbslo [Hive witness]#8470

@fbslo

If you like my work, please support me by voting for my Hive Witness!
Witness announcement


This is a personal project and it's not affiliatted with official Hive Engine project!

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Sort:  

@tipu curate 3

This is awesome buddy, great to meet you on Hive

Pismu, spet sem zamudil, da ti stisnem en TipU :)

Važno da ostane v SLO ;)

Res je :)

!BEER


Hey @crazy-andy, here is a little bit of BEER from @ervin-lemark for you. Enjoy it!

Learn how to earn FREE BEER each day by staking your BEER.

Congratulations @fbslo! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s) :

You got more than 4750 replies. Your next target is to reach 5000 replies.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @hivebuzz:

Feedback from the November 1st Hive Power Up Day

I am testing this cool project. I created SWAP Token for testing, if completed successfully I will extend the tool to other HIVE token.

See the progress here: https://swap.swaptoken.com/
Still fixing some minor bugs, in collaboration with @fbslo to make this project run smoothly.

Loading...