DEX overview: About differences and features from centralized exchanges [PART 1]

GAME
GAME
Published in
10 min readFeb 18, 2019

One of the world views that MOLD aims for may be to enable “free and rapid transactions of digital assets at P2P”. This digital asset refers not only to existing cryptographic currencies, but also to various things that will ride on the web, including assets of users in game in the future. To that end, the MOLD team is currently working as an alpha version with the goal of implementing a digital asset exchange protocol on Ethereum and publishing it as an SDK, and the MOLD team is working on three occasions this time I will introduce the exchange protocol. For the first time, we will explain from the basic points such as the DEX (Decentralized Exchange) known as the exchange protocol of assets in the first place, the advantages when compared with centralized exchanges , MOLD from the next time We will continue to consider the DEX we are working on.

Managing assets

Many people consider their own encryption currency wallet as a mere digital version of the real wallet used to store funds.

Actually however, the encryption currency is not stored in the wallet. Instead, the wallet has a pair of public and private keys that allow access to his digital inventory. In a nutshell, the public key is an alphanumeric character string that serves as an address that other users can use to send encryption currencies. Also, for cryptographic currencies like Bitcoin and Ethereum, only those who know the secret key associated with the address have the right to freely send the balance at that address to another address. Therefore, since the composition “Person who knows the secret key = manager of the address” is established, the address holder needs to pay close attention to the management of the secret key. The remittance, together with the difference between the sender and recipient’s wallet, is only recorded in the ledger of the block chain. Of course, using the word wallet, as if the cryptographic currency itself is included, it makes it easier for users to understand intuitively, it also improves UX, so there is nothing wrong with itself, but essentially Needs to know that it manages a pair of a private key and a public key.

Structure of centralized exchange

Centralized exchanges are platforms or applications that allow traders to trade cryptographic currencies using legal currencies or other cryptographic currencies. On such an ordinary exchange, we allocate the address for each user and manage the assets as before. The user wishing to trade will first transfer the cryptographic currency to that address (omitted if purchased in legal currency).Therefore, it is the exchange that manages the encryption currency and its secret key sent to the exchange. In addition, trading orders issued by users are matched in unique databases within exchanges. Of course, they are not recorded in the block chain. When an order is placed, the exchange is structured to check buy orders and sell orders in real time. The important thing here is that the user does not have the secret key of the crypto currency when doing such a token exchange. In other words, just like banks, users will have to trust the exchange to store and manage their own balances.

There is, of course, some guarantee of storing user’s cryptographic assets in a centralized way, but there are basic risks associated with doing so. Also, while a centralized exchange is legally responsible for user funds, it is often susceptible to hacking.

There is a word trustless as one of the idea of ​​public blockchain, but between the centralized exchange and the user, it is impossible to realize the essential trustless state.

What is DEX

On the other hand, in DEX, the user himself manages the secret key. Although this mechanism seems to be commonplace at first glance, as described above, it differs greatly from the case of a centralized exchange. Also, since it is executed on a Smart Contract when exchanging an asset, it can be said that it is a trustless mechanism (However, considering UX, it is necessary to perform order matching etc. on an off chain, so to some extent DEX service side I have to trust that).

Also, as seen in the 0x protocol, it is also an attraction that anyone can build a DEX network by using the same protocol. Indeed, DEX using the 0x protocol includes Paradex, Radar Relay, etc.

In summary it turns out that there are the following characteristics.

  • The user manages the private key by him / herself.
  • Management from centralized management on smart contract
  • Anyone can build a network

The need for DEX

Let’s think about why DEX is needed rather than centralized exchanges from multiple perspectives next.

privacy

One of the main benefits of distributed exchanges is the emphasis on privacy and anonymity. Distributed exchanges do not require anything other than a user name, password, and cryptographic wallet to initiate a transaction.

Being able to sign up and start trading without going through KYC is attractive to those who want anonymity and those who can quickly deposit, trade and withdraw their funds.

However, in November 2018, EtherDelta got fined from the SEC, and there are also places where KYC is taken among DEX.
Reference: https://www.sec.gov/news/press-release/2018-258

Security

Depending on the type of decentralized exchange, security tends to be strengthened more than centralized exchanges because there is no centralized hot wallet for hackers to target and steal all users’ funds.

Since DEX performs distributed settlement for each order, this can minimize the potential attack path that hackers can exploit and, in some cases, there is little chance of an attack succeeding I can say that.

While you are trading yourself, you can maintain complete custody of your own funds (held by the contract) that are located in escrow, while DEX relieves users of the safety of funds You can provide a feeling. Even if DEX stops functioning, users can recover their own funds after the escrow transaction expires.

The low possibility of human operation

It has censored tolerance to the centralized entity or government, authorities. This minimizes the possibility of operation by a third party without the orderbook itself maintaining and executing transactions.

In the past, some exchanges have generated waste trading volumes, reduced waste deposits and withdrawals at important transactions, or had wash transactions to manipulate trading orders and token prices There are centralized exchanges condemned as.

Reference: https://medium.com/@sylvainartplayribes/chasing-fake-volume-a-crypto-plague-ea1a3c1e0b5e

Since there is no managed orderbook for distributed exchanges, this means that there is less chance that such operational behavior will occur.

Problems of DEX

On the other hand, as a problem of DEX, the following points can be mentioned.

speed

Distributed exchanges are operated on-chain using Smart Contract, so it may take longer to implement an agreement and enforce trading orders than a centralized off-chain trading platform. When traffic is heavy, when congestion occurs in the block chain network, escrow, cash out, or execution of transactions becomes impossible in a timely manner, so that DEX can not be used effectively.

UX

In the case of on-chain support such as deposit and withdraw timing, it is necessary to wait until the transaction node is stored in the block and the network node confirms it. Therefore, it is often time consuming compared to a centralized exchange. Also, although most of the online services on the web have customer service, in the case of DEX, it becomes difficult to respond appropriately to each user when problems occur. (The user’s information is held on the DEX side Because it is not). Therefore, it can be said that there is a problem from the viewpoint of usability that it is difficult to master it to some extent if it is not person who is familiar with encryption currency or block chain.

Only exchange of crypto currencies can be done

Although it can not be helped because of the nature of DEX, it is impossible to exchange a statutory currency and a cryptographic currency which are not managed by a block chain with a smart contract. However, the development of protocols for exchanging tokens on different block chains is ongoing

Example:
WBTC: https://www.wbtc.network/
HTLCs: https://en.bitcoin.it/wiki/Hash_Time_Locked_Contracts

Types of DEX

Even if you say in a word with DEX there are various mechanisms there. First, let’s see the token exchange protocol conforming to the token specification of ERC 20. The data of Etherscan is as follows(2019/1/31).

Among them, the following are listed as relatively famous DEX.

Swap between matched boards is executed

Manage orders on-chain

Manage orders off-chain

Swap is executed by reservoir and ordering party

The exchange ratio is defined by a formula

The exchange rate is defined by the actual rate

Meanwhile, there are DEXs that allow trading of ERC 721 tokens like CryptoKitties, OpenSea is famous.

Mechanism of DEX

Since it is difficult to see all the DEX contracts mentioned earlier, we will explain the mechanism of DEX based on the relatively simple EtherDelta contract.

Reference: https://github.com/etherdelta/smart_contract/blob/master/etherdelta.sol

Contract inheritance relationship is as shown in the figure.

Features of the distributed exchange, DEX, are as follows.

token can be exchanged
Execute transactions, orders, deposits etc. on the contract

AccountLevels contract

A function to rank DEX users.
It is divided into regular user, silver user, gold user, and regular user is charged for ordering with taker or order by maker. In the case of a silver user, although fee is charged, in the case of a limit price, a fee is not charged, and a partial fee is paid as rebate (setting of rebate fee is done by admin). In the case of a gold user, although fee is charged, in the case of limit price, there is no fee and it is possible to get all the fee of the partner who issued the order to be rebated.

The determination of the rebate fee at AccountLevel is performed by the trade valance function of the EtherDelta contract .

EtherDelta contract

As a Constructor, the EtherDelta function executed at the time of deployment sets six arguments as admin, feeAccount , accountLevelsAddr , feeMake , feeTake , feeRebate .

Only those with an admin account can change the above six items.

deposit and withdraw event

In the array of tokens [], the contract address of each ERC 20 token is stored. By the way, ETH corresponds to tokens [0].

Order and cancel events

Ordering events are not particularly difficult. It is effective until a counterparty matching the condition comes out by the specified block height.

cancel event

In the cancel event, ecrecover (hash, v, r, s) finds the public key from the signature and the original hash data, and validation on whether it matches the address is entered.

Trading flow

Let’s see the flow from when the order actually entered until the transaction is done.

Let us consider the case where token α and token β are exchanged (user token α is set as Get and token β is gaged).

Since the total amount of wealth does not change, you can see how the value transfers among the three user/msg.sender/dex .

① First, user determines how much you want to exchange tokens α and tokens β (user is maker).

② Next, msg.sender makes a transaction between user and msg.sender by agreeing on conditions decided by user .

③ Finally, a predetermined account on the DEX side will be sent the total of the taker and maker’s fee minus the rebate.

As you can see, with EtherDelta contracts basically you know that you are doing from order to exchanges on contract, but with other DEX you can turn off matching of orders, set up reservoirs, In addition, there are ingenuity such as exchanging.

The future of DEX

Currently there are various Ðapps, but what is important is that you can freely exchange assets within each other ‘s Ðapps . Of course, all of the current Ðapps are not superior in terms of UX, so there are still many problems compared to existing applications, but as we improve the scalability problem in the future, UX improves and the number of users increases Expected. At that time, if exchange of token between Ðapps and exchange of assets between Ðapps can be done smoothly, it will be recognized as a new use case of the block chain.

Next Preview: About DEX advanced by MOLD team
Next Next Preview: On the Innovation of ERC 1155

— — — — — — — — — — — — — — — -
Cosmos Gaming Hub Project(Former MOLD project)
CEO & Co-Founder

Takumi Asano

For all game enthusiasts

--

--

GAME
GAME
Editor for

Cosmos Gaming Hub is a fair and secure distributed gaming platform which supports the development of new games and simplifies the trading of digital assets.