0x Protocol for ERC20 DEX

Applicature
Applicature
Published in
9 min readSep 6, 2018

The Essence of a Decentralized Exchange

Blockchains have been widely used recently, as they allow any user owning certain digital assets to easily trade and transfer them across an entire network without an intermediary or the need for third-party intervention. Considering the vast range of various assets offered on the global market today, there arises the need for an efficient, scalable, secure exchange capable of processing thousands of transactions at once to satisfy all user needs. With smart-contract execution and deployment, it is now possible to trade and exchange all kinds of digital assets between parties in a decentralized and secure manner.

In order to progress from a centralized ecosystem and offer the community a highly efficient exchange with all of the advantages of decentralization, DEX (decentralized exchanges) have come into use. DEXs provide token/coin holders and traders with an enhanced security in terms of independence from the control of governments and other types of authority. Users are provided with full control over their funds, trustless transaction processing, and increased privacy, which eliminates the possibility of hacking attacks or the chance of funds being lost due to government shutdowns.

Since the appearance of Ethereum, the last two years have seen the development of numerous dApps and the creation of a vast variety of smart contracts that allow direct, peer-to-peer transactions between interested parties. The current problem is that quantity does not necessarily mean quality. Hence, many existing smart contracts can have security issues. Additionally, user fragmentation in the use of certain decentralized applications causes unnecessary spending and affects global network liquidity.

What Is the 0x Protocol?

0x (pronounced as “zero ex”) is an open-source, permissionless protocol used by blockchain-based DEXs running on the Ethereum platform. 0x protocol serves as a basic block capable of combining with other protocols for application management. The protocol applies an open-source smart contract system as an accessible, shared infrastructure for an array of decentralized applications:

To put this in perspective, technically, open standards overtake closed standards. Considering the high number of assets being tokenized monthly, a larger number of decentralized applications will require the implementation and use of a variety of tokens. Consequently, exchanges must meet the requirements of these economies, and be capable of providing highly scalable solutions.

Current DEX Issues and Solutions

The great number of decentralized exchanges launched due to Ethereum SC implementation have been faced with issues of volume generation because of incomplete design and program drawbacks. This has resulted in increased market friction costs, as users have been required to spend additional gas on each transaction call, modification, or cancellation. Considering the fact that the actual transaction cost is pretty low, order modification turns out to be pretty expensive in terms of additional gas charges. Therefore, on-chain orders and transaction maintenance result in expensive operational costs as well as network bandwidth consumption. This inflates the blockchain but doesn’t necessarily guarantee value transfer.

To solve the above-mentioned issues, the following solutions are provided:

  • AMM (automated market maker) SCs are offered as a solution for on-chain transaction maintenance. These contracts replace the on-chain order book with a price-adjustment model in which the asset price reacts to market conditions and participants on their own behalf during the trade instead of correlating with each other.
  • State channels are offered to scale the blockchain and decrease fees for a number of dApps. All users within these channels can exchange cryptographically encrypted messages and gather/save state changes eliminating the need to publish them in the canonical chain until its closure.

State channels work best with “bar tab” dApps, as multiple intermediate state changes can be stored and gathered in an off-chain manner before the on-chain transaction settlement. Therefore, in case one of the members leaves the channel or tries to deceive the others, a challenge period is implemented in which other members can introduce the offender’s recent activity. In order to challenge the cheating behavior, all other channel members have to be online.

Considering the fact that state channels significantly decrease the quantity of on-chain transactions in certain cases, multiple on-chain actions and security deposits result in inefficiency for single-transaction processes.

A hybrid solution has been proposed to relay off-chain orders while settling them on-chain. This solution conjoins state-channel productivity and immediate-order book settlement in an on-chain manner. This guarantees safe trades and minimizes the cost per transaction.

Specification: How Does It Work?

The graph below illustrates how the off-chain order is relayed within on-chain settlement:

1. The maker confirms the DEX exchange contract to view the Token A balance.

2. The maker establishes an order to exchange tokens (A for B) and provides details concerning the rate and timelines, signing it with private keys.

3. The maker transmits the order in any desired communication environment.

4. The taker views the order and makes the choice whether or not to take it.

5. The taker confirms the DEX contract to view Token B balance.

6. The taker approves the maker’s signed order for the decentralized exchange contract.

7. Finally, the signatures and all contract data are verified and authorized in order to be executed.

Take a quick glance at how easy it is to generate an order:

The message format contains the order parameters (joint and hashed via Keccak SHA-3 function) with relative signatures.

0x protocol allows users to place point-to-point orders and broadcast them:

0x protocol is used with Ethereum SC implementation, which can be accessed from the public library. A significant advantage is its lack of fees. Contracts are programmed in the Solidity language, which provides two main functions: “fill” and “cancel.” Considering the fact that the average code size is one hundred lines, the cost comes out to 90k gas per order.

Exchange SCs provide the maker’s signature authentication by way of the recover function:

References to previous orders are usually stored by smart contract within the “mapping” data structure to avoid replication.

When an order is filled, this data structure saves and keeps the hash details along with the order value. The taker can partially fill it, providing certain details on argument or value. Furthermore, numerous partial fills have the option to be executed within one order, if the total number of fills is not larger than the whole order value.

It should be stated that orders have timelines for execution. They can expire according to the timelines provided by the maker while signing the contract. This expiration date cannot be changed.

If the order is not filled and the expiration is still ahead, it can be canceled by the maker with map hashes of the order to prevent subsequent fills.

This option charges gas, and serves mostly as a fallback method. It is expected that one will avoid order cancellation and set the expiration date to match the frequency of order updates.

Token Protocol

As more and more digital assets are becoming tokenized, Ethereum is serving as an open, limitless system enabling trade and exchange. 0x protocol enables ERC20 token trade within the platform. This provides a number of benefits:

Cryptocurrency protocols incentivize users financially and stimulate the economic network of agents. 0x protocol promotes cooperation between the parties (buyers and sellers) to serve as an open and accessible model for decentralized applications consolidating exchange goals.

The maintenance and establishment of such an open and accessible operating model becomes an additional coordination issue, as it increases the expenses of supporting parties. This coordination becomes especially complicated in terms of the parties’ various needs, requirements, and incentive interests.

The distinguishing feature of a token protocol is that it adjusts economic incentives and balances spending according to one model and technical standard. In addition to adjusting and using such incentives, protocol token approaches present another significant issue: they provide a future Proof-of-Protocol executed in a permanent smart-contract system with decentralized, management independent of government.

0x decentralized governance provides:

  • Constant/endless integration. Since the deployment of Ethereum SC, constant upgrades have been necessary. Protocol can force a decentralized upgrade mechanism, thereby requiring constant updates while providing user security and protection.

Ethereum-based 0x protocol will provide a set token supply distributed between partnered decentralized applications and potential users. These tokens will be used to pay transaction costs by market users and upgrade the protocol through DEX governance.

The 0x native token will provide cost efficiency by not charging unnecessary transaction fees. 0x smart contracts will be accessible, free, and open to the community. In addition, one group won’t have any privileges over another other, ensuring fairness and equality.

  • Token registry. This registry will keep the ERC20 token inventory secure with relative data such as name, address, symbol, etc.
    The registry can be publicly accessed on-chain to verify token details before trade settlement. It will provide transparent and up-to-date information for token holders, who will be able to check order validity.

0x protocol is a great solution for trading any token designed in accordance with the ERC20 standard interface:

Over time, the format of the 0x order will be altered to contribute to better user comprehension. Tokens will have the option to be distinguished by a three-character symbol listed in the registry. Users may be provided with readable names instead of addresses.

Recently, an alpha 0x OTC release of a dApp was launched. It is meant to promote trustless and secure over-the-counter (OTC) trade of ERC20 standard tokens. Within this version, users can purchase tokens in test mode for trading purposes in social networks. Smart contracts have been implemented within this testing network, and 0x continues to upgrade and work on the system to provide better efficiency and import a greater number of SCs to the Ethereum mainnet.

Final Thoughts

Having discussed the basic working principles of the 0x Protocol, it is clear that it possesses a range of benefits, such as decreasing friction costs for users along with fast deal settlement.

Personal liquidity pools can be created for relayers to set transaction costs according to volume. In addition, a shared protocol layer guarantees compatibility between various decentralized applications, reduces duplications, and enhances user security with constant upgrades.

Stanislav Chernenko, Applicature Solidity developer, comments:

“Taking into consideration the fact that 0x protocol improves the world of crypto-currency exchange, it enables anyone to quickly exchange his/her ERC20 tokens without the need for personal identification. 0x is going to be an integrated part of the cryptocurrency world, because its appearance has allowed an increase in the value of ERC20 tokens.

However, 0x is useful for the cryptocurrency world only, due to the fact that business does not rule out speculation and margin trading, which is common for most traders.”

Join discussions on Applicature’s official Twitter and Telegram accounts!

--

--

Applicature
Applicature

Applicature is a Venture Builder and Accelerator of Blockchain companies. Since 2017, we’ve helped more than 270 companies grow.