What is the Hydranet DEX and how does it work?

The Hydranet Decentralized Exchange (DEX) is a Layer 3 trading platform pioneered by Hydranet DAO. It combines Layer 2 off-chain solutions, such as the Lightning Network and the Connext Network, to enable cross-chain trading of fundamentally different cryptocurrencies. Trades are executed fast, cheap, and most importantly, trustless, as all users are always in control of their funds. Use this informative page to learn more about the distinctive features of the Hydranet DEX and how it works! 


The basics of Layer 2 off-chain trading

Before we delve into how the Hydranet DEX works, we need to understand the basics of off-chain trading. Off-chain trading makes it possible to cluster dozens of trades into only a few on-chain transactions. The Bitcoin and Ethereum blockchains both have their own off-chain technologies being worked on by several different actors. The fundamentals of both technologies are however principally the same.

To trade off-chain, there must exist a payment channel (state channel for Ethereum) between two transacting parties. This payment channel is created by the two parties depositing funds into a multi-signature contract. Since the contract runs entirely on the blockchain there is a network fee associated with this operation, but the two parties will always remain in custody of their funds.

With an open payment channel, the two parties trade by sending signed instructions on how to claim the funds (all, or parts of it) locked in the multi-signature contract. The instructions require no confirmation by the blockchain and are therefore virtually instant and feeless.

If any of the two transacting parties run out of funds but want to trade more, the trader can simply increase the capacity of the payment channel by locking more funds in the multi-signature contract. When either party is done transacting, the payment channel is closed and settled on-chain. The latest state/balance of the payment channel is then sent to the multi-signature contract to unlock each party's rightful share of the total funds locked in the contract.

Although payment channels are typically opened between only two transacting parties, the parties can reach virtually anyone in the off-chain network. As long as you have your receiver’s payment channel information, you can use other users’ payment channels to route your transaction to your receiver. This way, you can avoid opening unnecessary payment channels and the cost associated with it. Consider the example in which both Alice and Bob have open payment channels with Charlie. Alice owes Bob 1 BTC and figures she could use the Lightning Network to wire Bob his funds. Alice and Bob do not have a payment channel open between them, but because both of them have open payment channels with Charlie, they can use Charlie to route their payment. Alice will send 1 BTC to Charlie, and Charlie will send 1 BTC to Bob. Charlie will not have to do anything, and will probably not be aware that Alice sent BTC to Bob via him.

So, in short, what are the benefits with off-chain transactions?

  • Off-chain trades require no confirmation on the blockchain, which paves for fast and cheap trading while mitigating on-chain congestion
  • The transaction history of the payment channel will only be known to the transacting parties, which increases privacy. Only on-chain activities are publicly visible.

The Hydranet DEX solution

The Hydranet DEX consists of two types of communicating nodes; HUBs and Clients. While the Clients are what the traders interact with, the HUBs are the vital elements that enable Clients to trade.

The HUB is a complex piece of technology, but is essentially nothing more than a matchmaker. A HUB includes the following main components:

  • Lightning Network node
  • Connext Network node
  • Orderbook engine
  • Channel rental engine

The Lightning and Connext nodes are the HUB's gateway into the Bitcoin and Ethereum Layer 2 off-chain networks. Without the nodes, it would not be possible to open payment channels to/from other traders in the off-chain networks. The orderbook engine track and control the trade orders instantiated by the Clients in the Hydranet DEX. It stores and runs the Hydranet DEX orderbook locally, and forwards the information to the Clients in the DEX network. The Matchmaking engine is the functionality that matches two transacting Clients. When a Client creates a trade order, the Matchmaking engine scans the local database for a match. If a match is found, the Matchmaking engine connects the two transacting Clients, if not, the order is stored locally in the HUB's Orderbook engine and will be displayed on the Clients’ orderbooks. Lastly, the Channel rental engine is used by Clients to open payment channels for the currency they want to receive. Remember, to open a payment channel, the user must deposit funds into a multi-signature contract. If the user lacks these funds (which is probably the case when the user wants to buy a specific currency for the first time), the user will not be able to open the payment channel. To solve this, the Clients in the Hydranet DEX can rent liquidity from the HUB to open a payment channel with which the Client can receive funds.

The Client is the trader’s gateway into the Hydranet DEX. It is a downloadable desktop application that runs its own Lightning and Connext nodes for access to the Bitcoin and Ethereum Layer 2 off-chain networks. The Client mainly consists of a Multi-Currency Light Wallet (MCLW) and a classical orderbook. In the MCLW, traders can store their funds and control the on- and off-boarding of funds to the Lightning and Connext networks (opening and closing of payment channels). With funds on the off-chain networks, the trader can use the orderbook to trade with other Clients in the Hydranet DEX.

A trade executed on the Hydranet DEX is essentially the same thing as a transaction made on a payment channel, but with some help from the HUB. When two Clients match for a trade, the HUB connects these Clients and assures that both of them receive all necessary information about the other Client and about the trade order (Lightning channel ID, Connext channel ID, Client ID, order ID). When the Clients are connected, the HUB is not needed anymore, the Clients will manage the remaining steps of the trade by themselves. Safety and protection from malicious acts becomes a relevant topic at this instance. Neither Client wants to end up in a situation in which they have sent funds to the other Client but not received any funds back. To ensure that this does not happen, the Hydranet DEX uses hashed time-lock contracts (HTLC) for the trades between Clients. A HTLC is a type of smart contract used for trading in decentralized payment systems. The two trading Clients will send their funds to the HTLC. The HTLC contains all the details about the trade and will only release the funds if the conditions for the trade are met. If either Client fails to meet the conditions, either by not sending the agreed upon funds to the HTLC or simply taking too long to send thet agreed upon funds, the funds in the HTLC will be returned to its proprietors. This solution provides security for both Clients in the trade and enables trustless trading between them.

To get a better understanding of what happens when a trade is performed using the Hydranet DEX, you can study this fictive trading scenario:

Alice wants to trade her 1 BTC for 1 ETH. She is a long-time user of the Hydranet DEX and already has open payment channels with the HUB in the Hydranet DEX. Conveniently the states of her payment channels allow her to send 1 BTC and also receive 1 ETH. She is in no hurry with her trade and decides to place a limit order on the Hydranet DEX. When she places the order, her Client sends the information to the HUB. The HUB Matchmaking engine scans its local database for matching orders, but cannot find one. The information about Alice's order is therefore stored in the HUB’s local database and is also forwarded to the Orderbook engine, which displays her order on the orderbook.

Bob, a Bitcoin fanatic, has miraculously found 1 ETH laying around in his wallet. He wants to trade this 1 ETH for 1 BTC and decides to try the Hydranet DEX for this operation. He downloads the Hydranet DEX Client, deposits his 1 ETH to the Client, and is now ready to begin his trade. Bob starts by opening a Connext state channel, which will allow him to send his 1 ETH. Since he wants to receive 1 BTC, he rents liquidity from the HUB and opens a Lightning payment channel. He navigates to the order book and finds the limit order placed by Alice. He decides to place a market order and completely fill Alice's order.

As Bob presses buy on his Client, the information is sent to the HUB. The Matchmaking engine in the HUB scans its local database and finds Alice's order. It's a match! The Matchmaking engine sends Alice’s information to Bob and Bob’s information to Alice (Lightning channel ID, Connext channel ID, Client ID, order ID), which allows their Clients to connect. Before the trade is executed, Alice’s and Bob’s Clients validate that the trade is correct (currency and amount). If nothing malicious with the trade is found, the Lightning and Connext transactions take place.

The trade is finished! Alice and Bob can now decide if they want to continue their trading journey on the Hydranet DEX or if they want to close their respective payment channels and unlock their funds from the multi-signature contracts.

Why use the Hydranet DEX and how does it differ from other exchanges?

There are multiple reasons to use the Hydranet DEX. Today, cryptocurrency traders typically face a dilemma with security, privacy, and ease of use. To stay safe, traders can keep their funds in their self-custodial wallets but are then faced with a slow, unintuitive, and potentially expensive trading experience. The limited scalability of common blockchains, such as Bitcoin and Ethereum, is usually the underlying reason for these issues. Traders can turn to Centralized Exchanges (CEX) for a more seamless and cheaper trading experience, but at the expense of giving up custody of their funds. Major controversies happen and will continue to happen within the cryptocurrency industry. Keeping control of your funds is one way to protect yourself! The phrase “not your keys, not your coins” cannot be stressed enough!

The Hydranet DEX solves the “trader’s dilemma” presented above. The Hydranet DEX offers an orderbook on which traders can place limit and market orders, and a built-in wallet in which they can safely store their funds and be in complete control of their private keys. All trades made on the orderbook are executed off-chain using well-known and established Layer 2 off-chain solutions. This makes them virtually instant, feeless, and private. The Hydranet DEX infrastructure furthermore combines different Layer 2 off-chain solutions to allow trades of fundamentally different cryptocurrencies, such as BTC and ETH. This makes the Hydranet DEX the world's first true Layer 3 DEX. In short, the Hydranet DEX offers a trading experience as seamless and cheap as a CEX, and as private and secure as a DEX, trading nothing but native funds!

Except for the evident differences between the Hydranet DEX and other exchanges, there is one key feature that makes the Hydranet DEX unique. At other exchanges, all the computationally intensive operations are typically done at a single centralized place. Although the HUB in the Hydranet DEX is important for transaction handling, its main task is to be a mediator between the different Clients that exist in the Hydranet DEX. When two Clients are connected for a trade, the HUB is in fact not involved anymore. The trade validation and execution are done entirely by the Clients. Since a Client will most likely not do more than a few trades per second, combined with the Layer 2 off-chain solutions, the Hydranet DEX can theoretically scale indefinitely.