DEX — How decentralized exchange is implemented on Bityuan network

Authored by Jackie

The centralized trading faces regulatory hurdles as it is required to meet institutional legal and compliance criteria. Traders, inevitably, have to comply with regulations set by the trading service providers and trade with commission fees.

Bityuan’s DEX trading pattern (Decentralized Exchange) will provide two convenient and secure solutions to this problem: BTC Relay and Hash Locking.

BTC Relay is a method with the idea to incorporate a Bitcoin Simplified Payment Verification on Bityuan network.

Here is a insight of Simplified Payment Verification given by the mysterious Mr. Satoshi Nakamoto:

It is possible to verify payments without running a full network node. A user only needs to keep a copy of the block headers of the longest proof-of-work chain, which he can get by querying network nodes until he’s convinced he has the longest chain, and obtain the Merkle branch linking the transaction to the block it’s timestamped in. He can’t check the transaction for himself, but by linking it to a place in the chain, he can see that network node has accepted it, and blocks added after it further confirm the network has accepted it. (Nakamoto, 2009)

BTC Relay is implemented by copying block headers in bitcoin blockchain to bityuan blockchain, though it is not possible to verify the transaction, by linking it to a place in bitcoin blockchain, it is possible to confirm that bitcoin network node has accepted it. In this way, any willing parties can transact anonymously without a third party, and the whole transaction process will be done within six hours.

Alternatively, Bityuan DEX proposes Hash Locking to complete an atomic cross-chain trading.

Atomic cross-chain trading refers to an approach where at least two parties own coins in separate cryptocurrencies, and want to exchange them without having to trust a third party. Between two parties, they agree on an exchange rate of the two cryptocurrencies and confirm to complete the trade.

Atomic cross-chain trading on bityuan network is performed by using scripting languages to build smart contracts that will supply an asset transaction between two separate blockchain network securely, and with no third party involved.

Hash locking originates from the HTLC (Hashed Time Lock Contract) of the Lightning Network. If A owns 1 bitcoin and wants to transact with B with 20,000 bityuan that he has, they will perform the following:

Transaction between A & B
  1. A generates a random number s, and calculates h = hash(s) and sends h to B;
  2. A generates a HTLC. The time lock is set to be 2 hours for instance. If B finds the random number s within 2 hours, then A’s bitcoin will be taken by B or otherwise A gets his bitcoin back. Note: both A and B know h but A has the key to the contract s;
  3. At the same time, B deploys a smart contract on Ethereum platform, the one who provides an s that will have the hash of h will unlock the contract and take the 20,000 bityuan away;
  4. A takes away 20,000 bityuan by providing the correct s;
  5. B gets to know s when A providing the correct s to take the bityuan, B can unlock HTLC and takes the bitcoin.

When the two parties agree on an exchange rate, their assets will be temporarily stored in a special place. Two ways to move away the coins, one is to provide the correct s which can lead to the per-calculated h with the hash algorithm, two is the time over-dues before the correct s is provided, and thus the coins will be back to each.

A provides the correct random number s to take the bityuan away from B, because the blockchain network is transparent, so B can naturally find out what the random number s is, to take A’s bitcoin.

Note that the smart contract is set to be in between party A and B exclusively, no third party can participate the trading, therefore when A broadcasts the number s to the whole network, no one else can take the coins away even though they all know what the number s is. The time lock on the smart contracts are different, the time lock A sets on his smart contract has to be longer than B’s so that B will have enough time to take A’s coins.

For future reference, bityuan team will develop a handful tools to utilize the atomic cross-chain process, in a way that the DEX can be also executed on the mobile end.

In conclusion, both BTC Relay and Hash Locking will make atomic cross-chain trading possible. Nevertheless, their differences are summarized in the following table:

Bityuan is more than just a simple, stable and scalable blockchain network. It promotes decentralized exchange with the method of BTC Relay and Hash Locking.

The world-leading blockchain solution company. Twitter: @FuzameiLtd