Author: Jean Baptiste NKOMEJIMANA, CoinEx Business Ambassador
HOW COULD NEW DECENTRALIZED EXCHANGE LOOK LIKE TODAY
The goal of this Essay is to explain what could be the criteria to create a new decentralized exchange according to willing of today’s world in architectural structure, performance, and security trade-offs associated with various architectural choices.
Decentralized exchanges are becoming a critical tool for purchasing and selling an increasing percentage of cryptocurrencies. The term “decentralized exchange” generally refers to distributed ledger protocols and applications that enable users to transact cryptocurrencies without the need to trust a centralized entity to be an intermediary for the trade or a custodian for their cryptocurrencies. Decentralized exchanges provide a number of important benefits, including
- lower counterparty risk (i.e., no need to trust a centralized exchange to secure and manage private keys),
- the potential for lower transaction fees, and
- A more diverse array of trading pairs that can unlock access to riskier or less liquid cryptocurrencies
As demand for these features increases, decentralized exchange technology may witness tremendous growth in usage, development, and adoption within the next couple of years. Additionally, decentralized exchange usage is being fueled by concurrent regulatory and industry trends, including
- a surge in the quantity of distinct cryptocurrencies that makes comprehensive listing impractical,
- regulatory risks of listing cryptocurrencies on centralized exchanges and
- Users’ desire to avoid centralized exchanges’ Know-Your-Customer requirements for more private and less censorable transactions.
Decentralized exchanges can differ dramatically in terms of technology, trustlessness, security, legal implications, economic implications, and more. These differences render some exchanges more or less suitable for specific use cases. The goal of this essay is to explain the architectural structure of decentralized exchanges, and the performance and security tradeoffs associated with various architectural choices. By understanding these technical differences, the reader will have a better grasp of which decentralized exchanges are optimized for which use cases.
A decentralized exchange (DEX) is a peer-to-peer (p2p) online service that allows direct cryptocurrency transactions between two interested parties. Decentralized cryptocurrency exchanges are aimed at solving problems that are inherent in centralized exchanges. They create p2p markets directly on the blockchain, which allows traders to independently store and operate funds. Users of such exchanges can make transactions with cryptocurrency directly between each other i.e., without third-party involvement.
Decentralized services are supervised either automatically or by the participants. The safety of assets is provided by a distributed ledger technology (DLT) in general, mostly the following blockchains are utilized for DEXs: Ethereum (EtherDelta, IDEX, etc.), Graphene (BitShares, CryptoBridge, etc.) or blockchains powered by other cryptocurrencies (Waves, Switcheo, etc.).
1. 1. How are decentralized exchanges different from centralized exchanges?
In centralized, users must be identified, and their coins are kept in the accounts belonging to companies. Decentralized exchanges do the exact opposite. Centralized exchanges are managed by a specific company or a person focused on making a profit. Such exchanges are responsible for protecting user data and their trading information. They fully control the platform’s operation and independently make decisions that are important for the development of the service.
Decentralized exchanges, in contrast, are managed automatically or semi-automatically with the involvement of platform participants in the process of making important decisions. Such platforms provide the technical possibility of direct interaction between the participants and use a distributed registry for storing and processing all or almost all data.
A decentralized exchange does not store funds or users’ personal data on its servers and serves only as a platform for finding matches for the purpose of buying or selling.
1.2. The Two Types of Decentralized Exchanges
As exchanges revolve around transacting currencies, there are two fundamental exchange models: currency-centric and currency-neutral. Either of these models can be centralized or decentralized, depending on how the four key functions of the exchange are handled.
1. Currency-centric exchanges are built on top of singular blockchain platforms, such as Ethereum. A currency-centric exchange is limited to escrowing only the currency of the platform it is built on, such as ERC20 assets and other contracts if the exchange is built on top of Ethereum. This is the way traditional exchanges are built.
2. Currency-neutral is newer mode, which is architected to connect different native cryptocurrencies, meaning that users do not have to adhere to any specific currency ecosystem. These systems allow users to trade cryptocurrencies without a coin underlying that exchange, which acts as a sort of additional “middleman” to go through since it is no longer fully peer-to-peer. Examples of these models include Bisq, altcoin.io, and flyp.me.
These newer projects allow for securely matching and handling order books, and not just asset exchange, in a decentralized manner, which is done using the blockchain. Because an exchange is a community of users, there has to be a way to broadcast and match orders. One way of trustless trading is through “atomic swaps” for order matching, but atomic swaps alone cannot create a trustless marketplace, as it is done from one specific peer to another, rather than as a broadcast to anyone on the network. An atomic swap is when a trade is done in a single, or atomic, operation, as opposed to two separate transactions (such as first sending one coin, then waiting for the receiver to send their coin). This is facilitated through smart contracts that act as a trustless escrow holding onto one currency until the other user sends their currency as well when both currencies can be released.
1.3. How Does a Decentralized Exchange Work?
At its core, a decentralized exchange is essentially a decentralized application (dApp). The validity of its processes is guaranteed by the execution of smart contracts, chunks of code that give blockchains the behind-the-curtain logic needed to remain operational.
Here is a simple explanation of how a decentralized exchange works from the perspective of someone wishing to trade digital assets:
Step 1: You use your wallet address to register for a DEX, no sign up is necessary.
Step 2: You place an order by stating which cryptocurrencies you would like to exchange and for what kind of asset (one that’s, of course, available on the DEX you are currently on). You specify the number of units you wish to sell, the minimal value of what you have and until which time bidding for the assets will be allowed.
Step 3: Once the selling order and its custom parameters are set, your request becomes public and other users of the network can start submitting bids.
Step 4: Once the bidding time expires, all the proposals are automatically reviewed and an exchange is executed when the system identifies the best offer, all thanks to smart contracts running in the background.
As you can see, decentralized exchanges are not that complex. Of course, creating one is a much more daunting task than simply understanding how they work, but the point of our simple example was to demonstrate the non-custodial nature of the DEX process. From start to finish, users remain completely in control of their funds while trading within these decentralized networks. They only hand over control once the trade has been executed by the DEX network.
If you were to create a new decentralized exchange based on Ethereum, you must know how the current decentralized exchange works so that you would add the missing features. Here are the most important things you must take care of and these features are actually working on decentralized exchanges.
2. 1. Architecture of a Decentralized Exchange
The term “decentralized exchange”is used colloquially to describe both blockchain-based exchange protocols, as well as applications that leverage the protocols. A decentralized exchange protocol generally describes a software program, hosted on or integrated into one or more distributed ledgers (e.g., Ethereum), that enables peer-to-peer transactions that are automatically settled on the distributed ledger.6 Users retain sole custody of their private keys throughout the transaction process. A decentralized exchange application builds on top of a decentralized exchange protocol, and adds an on-chain or off-chain order book database and a graphic user interface (GUI) and/or APIs so that the information is easily accessible.
Overall, a decentralized exchange application can be broken down into the following components:
1. The blockchain platform & technical implementation
2. The counterparty discovery mechanism
3. The order matching algorithm
4. The transaction settlement protocol
1. Platform & Technical Compatibility
Most decentralized exchange protocols generally operate with tokens that feature the same technical implementation and are on the same distributed ledger platform. For example, AirSwap, 7 EtherDelta, 8, and 0x9 are independent protocols that are operable only with standardized ERC-20 tokens on the Ethereum blockchain. Beyond Ethereum, Stellar’s decentralized exchange is operable with tokens issued on the Stellar network,10 and BitShares’ OpenLedger DEX is operable only with tokens issued on the BitShares blockchain platform.11 Off-chain cryptocurrencies and assets could also be traded through the Stellar decentralized exchange or OpenLedger DEX if an “anchor” issues tokens onto the network that represents ownership of a defined unit of the off-chain
cryptocurrency.12 However, this requires users to trust that the anchor has sufficient reserves of the off-chain cryptocurrency to satisfy all redemptions of the tokens.
2. Counterparty Discovery Mechanisms
Counterparty discovery mechanisms enable buyers to discover sellers who are willing to execute transactions on mutually acceptable terms. On traditional cryptocurrency exchanges such as Binance, Bittrex, and Kraken, users have the option of submitting both market orders and limit orders, and these orders are automatically matched with unidentified counterparties using the exchange’s central limit order book, which aggregates all user orders.
Most decentralized exchanges also have order books. These order books may exist on-chain, hosted on a distributed ledger, or off-chain, hosted by third parties. Most decentralized order books display the separate orders of each counterparty, rather than the aggregated orders of all counterparties. Users normally will need to identify a particular order, and thus a particular counterparty, in order to trade.
For the rest of this Essay, the term “Maker” will refer to the party that provides an order, and the term “Taker” will refer to the party that fills it.
On-chain order books are hosted directly on the distributed ledger: all orders are submitted to the distributed ledger network and are confirmed by the network. Anyone can host and access a copy of the order book, and anyone may submit their own orders to be included in the order book as long as the distributed ledger is public. Examples of on-chain order books include the Bitshares and Stellar decentralized exchanges. Benefits:
1. Less censorable: There is lower reliance on a centralized party to host and operate the order book.
2. Less trust required decentralized, on-chain order book hosting means that one does not need to trust centralized, off-chain actors to accurately and reliably publish or broadcast order books.
1. Order book inherits performance, cost, and security characteristics of the underlying blockchain: The speed and cost of submitting or removing an offer on an on-chain order book are limited by the speed and cost of interacting with the underlying blockchain. Users must pay for each order book update on the network, wait for the network to reach consensus on their updates, and then wait for secure confirmation of the updates.
2. Slower updates: In the absence of second-layer technologies like the Lightning Network or Raiden Network, on-chain order books are generally updated based on the information contained in the latest block or ledger
3. Stale orders: On-chain decentralized exchanges generally support resting orders, where the desired price and quantity have been fixed by the Maker upon creation of an offer. In a resting order, the offer must be proactively canceled by the Maker if she no longer wishes to trade on those terms if, for example, the price has changed dramatically.
Off-chain order books are order books that are hosted by a centralized entity outside of a distributed ledger. The centralized entity helps parties discover other parties who make offers on the asset and can restrict access to view or submit to the order book. The practicality of using an on-chain or off-chain order book depends significantly on the performance of the chain. Decentralized exchanges normally do not employ on-chain order books given that every order and adjustment to an on-chain order book would require an update to the blockchain, thereby incurring transaction fees and wait time.
For this reason, four of the most prominent decentralized exchanges in Ethereum — 0x, AirSwap, EtherDelta, and IDEX employ off-chain order books. As of October 2018, 0x, AirSwap, EtherDelta, and IDEX support ERC-20 tokens.
In the 0x ecosystem, entities called “Relayers” host, manage and publish off-chain order books. Makers will submit buy and sell orders directly to a Relayer, and the Relayer will aggregate all received orders into its order book. Takers discover Makers’ orders by querying the Relayer’s order books. Upon finding a suitable order, a Taker will fill the order by submitting information pursuant to the 0x protocol to the 0x exchange contract on the Ethereum blockchain.
On the AirSwap platform, a Maker will submit an “intent to trade” in a certain trading pair to an entity called the “Indexer.” The Indexer will aggregate information about the Makers and their intents to trade. Takers who wish to trade in a certain trading pair will query the Indexer to discover the identities of suitable Makers, using the Indexer as a counterparty discovery mechanism. Once a Taker finds a suitable Maker, they will negotiate off-chain on the terms of the trade, potentially using the input of an off-chain “Oracle” that will suggest fair pricing for the trade.
On the EtherDelta web application, in order to make or fulfill an order, Makers and Takers will deposit tokens from their Ethereum wallet into EtherDelta’s on-chain smart contract. Makers will submit orders to be publicly broadcast on the EtherDelta off-chain order book, and the order book will ping the blockchain to verify that the Maker has sufficient balance deposited in the smart contract to fulfill the order. Takers will then select an order and click “Buy” on the web application, causing the EtherDelta smart contract to perform the trade.
On the IDEX web application, in order to make or fulfill an order, users will deposit tokens from their Ethereum wallet into an IDEX smart contract. Users then use the IDEX application interface to place buy and sell orders on an off-chain order book. IDEX and EtherDelta have similar structures in that they both integrate an off-chain order book with an on-chain smart contract for settlement, but IDEX adds on a “transaction processing arbiter” that helps to manage the order of pending trades so that trades are confirmed in the correct order.
There are both benefits and trade-offs to having an off-chain order book.
- Performance improvements
- Cost improvements
- Fewer blockchain-originated risks to the order book
- Compatible with all ERC-20 token
- Higher degree of trust required
- Greater restrictions
- Inaccurate order books
No (or hidden) order book: liquidity reserves
To solve the issue of low liquidity, some decentralized exchange protocols, such as KyberNetwork, Bancor, and Omega One build-up and/or leverage liquidity reserves that are readily accessible when users wish to exchange tokens. The performance of these models depends on reserve depth/breadth and accurate pricing.
- Lower friction to trade: The reserve model enables users to enter trades more easily given that the supply and demand sides (i.e., the reserve) have fixed terms and are readily available to trade upon those terms.
- Requires trust in a smart contract or third party:
- Uncertain pricing
- Tendency to favor large reserve contributors
- Reserves may be available and liquid only for the most popular tokens:
3. Matching Mechanisms
Matching is the process through which buy orders are paired with sell orders that have mutually acceptable terms. Decentralized exchanges may feature automatic matching or require Takers to manually identify and fill an order. Automatic matching occurs when a computer algorithm is used to pair and execute buy and sell orders.
Manual order filling
With manual order filling, Takers must proactively find and accept a counterparty order. This mechanism introduces more latency into order filling, but generally requires less trust and provides users more control given that users do not have to rely on a centralized or smart contract-based matching algorithm. For example,
In 0x, takers discover Makers’ orders via Relayers. If a Taker wishes to accept an order, she will submit a counterorder to the Relayer, digitally sign, and send the completed transaction to an on-chain smart contract that will settle the transaction. If a Maker’s orders are not actively monitored, Takers could exploit stale orders upon changes in the fair market price of the underlying token.
In AirSwap, users can query Indexers to find addresses of counterparties. Users must negotiate with counterparties privately to reach agreement on transaction terms and fulfill an order. This mechanism helps to protect Makers from losing money on stale orders (e.g., orders that are not reflective of current price movements).
On EtherDelta, Makers will post resting orders onto the order book, specifying a desired price and quantity for a trade. A Taker must manually select a Maker’s order from the order book and submit the order on the web application. Even if there are buy and sell orders that intersect on their desired terms, EtherDelta will not automatically match and execute these orders.
Automated order filling
With automated order filling, an algorithm will match orders automatically. Automated order filling reduces the amount of user time and effort needed to identify suitable trades, thereby reducing order-filling latency. However, this approach requires users to trust the matching mechanism to execute securely and provide them a favorable price.
4. Transaction Settlement
All decentralized exchanges feature on-chain settlement. On-chain settlement is a necessary element that enables users to eliminate the need to trust a centralized party (such as a centralized exchange) to control user assets, settle trades, and ensure that account balances are correct. On-chain settlement helps users publicly verify on the ledger that their trades were settled according to their desired terms. The performance of any decentralized exchange is limited, at the very minimum, by the latency involved in securely confirming a transaction on the underlying chain. Therefore, the speed of confirming a transaction in a distributed ledger network is the bottleneck for decentralized exchanges.
2.2 New features to strengthen while creating new DEX
While the spike in the development of decentralized exchanges is encouraging, some shortcomings to this technology need to be taken into account. If we put those more easily solvable aside, there are some main drawbacks to DEXs that need to be amended sooner rather than later:
1. Improve the system functionality: In order to maintain the trade simplicity we described earlier, decentralized exchanges tend to be very bare-bone, which can lead to issues with speed and liquidity. Most decentralized exchanges only support basic market functions, which take features such as margin trading and stop loss out the window. All currently operational DEXs are relatively small in size, so figuring out a way to create a vast yet sustainable and well-oiled decentralized exchange should be a top priority.
2. Addition of FIAT currencies is a more logical drawback since there’s a total lack of Know Your Customer (KYC) and Anti Money Laundering (AML) regulations within DEX networks, FIAT exchanges are simply not something these exchanges can host. Their inclusion would necessitate the introduction of a point of centralization, something the entire technology was developed in order to avoid. Nevertheless, the absence of FIAT currencies is a problem for some, and, at least at this moment, we do not see a way they can be included without breaking down the fundamental parts of DEX’s identity.
3. Add the ability to restore access: For example, due to lack of a KYC process and the ability to cancel a transaction in the event of broken passwords or loss of a private key, the user cannot recover his or her data and return the assets. Chargeback and refund procedures are incompatible with a distributed registry. Users who have committed an operation by mistake or have lost control over their keys are not able to recover their access.
4. Increase set of options: Many options for traders, such as stop loss, margin trading, or lending, are not available for users of most DEXs. Since many decentralized exchanges are managed by smart contracts, cryptocurrencies that do not support interaction with smart contracts cannot bargain on them.
5. Increase liquidity: Decentralized exchanges usually have a much smaller pool of liquidity compared to centralized sites. Thus, while Bitshares DEX has a daily volume of 197 BTC, the same parameter in Binance reaches 227,123 BTC. Such a difference is caused by the fact that traders prefer centralized services, where the choice of instruments, currency pairs, and orders themselves are much greater than on a DEX. As a result, the decentralized service falls into the so-called vicious circle — i.e., there are few users due to low liquidity, while the achievement of liquidity is impossible without a large number of traders.
6. Fix the scalability issues: An influx of a large number of people who wish to trade cryptocurrencies will almost inevitably cause a large load on the network and may cause delays, an increase in commissions, and all other problems already familiar from stories with centralized exchanges.
7. Add a way of support service: A decentralized exchange, by definition, cannot have a support service that can handle transactions or user accounts. When choosing such an exchange for trading digital money, the user is fully responsible for their funds and, in the event of losing a private key or sending a wrong transaction, they cannot apply for qualified assistance. The lack of advance support service also means that a dramatic increase in the number of user requests may lead to difficulties with scalability, and an operator response time may increase in the event of technical problems.
8. Increase transaction speed: Transactions take time to be checked and confirmed on a blockchain, and the processing time does not depend on the exchange, but on the miners. Since DEXs are less popular than their centralized analogues, users may face difficulty finding someone to match their buy or sell orders — or with making a deal at a good price. Buying or selling new currencies or those with low trading volumes can be even more difficult.
9. Solve fake volumes and malpractice: In an interview with Forbes, Sasha Ivanov, the CEO at $200 million smart contracts blockchain Waves and blockchain infrastructure development firm Vostok, said that decentralized crypto exchanges are capable of competing against centralized trading platforms and eliminate fake volumes from the global market. Last time, Changpeng Zhao, the CEO of the biggest centralized cryptocurrency exchange Binance, shared an analysis of fake volumes created by leading trading platforms, which explicitly described the dishonest methods employed by market leaders to inflate their volumes. Researchers at CER, a cryptocurrency research group, investigated BitForex and FCoin, the two trading platforms that managed to climb up the rankings to become top 10 cryptocurrency exchanges within months since their debut, evaluating their business models and volumes.
2.3. What are the advantages of decentralized exchanges?
Most of the strengths of decentralized exchanges stem from their distributed architecture and the lack of a single control center.
1. Security: Decentralized exchanges do not store user assets. Therefore, neither hacker attacks nor the total collapse of the exchange can lead to a loss of funds. The absence of a single entry point, through which one could gain access to all assets and data, complicates work for hackers and makes an attack meaningless in itself, which radically distinguishes decentralized exchanges from centralized ones that are regularly hacked.
2. Low risk of manipulation: Another advantage of this kind of service is the minimal risk of price manipulation or falsification of trade volumes, due to the absence of a central structure that is interested in manipulation inside the exchange.
There are no personal accounts on the decentralized exchange, no verification is required and there is no need to specify an email address, so personal data of users cannot be stolen. This structure makes services based on a distributed registry more anonymous than exchanges that require personal authentication for the purposes of Know Your Customer (KYC) and Anti-Money Laundering (AML) compliance.
3. Independence from regulators: The distributed architecture protects the exchange from interference by local or international authorities. In the case of a centralized structure, following regulations means that the exchange service can be either completely blocked or partially, in which case the service becomes limited in terms of location or options.
4. Accessibility for different projects: In contrast to its centralized brother, a decentralized exchange makes it possible not only to place orders for existing cryptocurrencies but also to create new ones directly in the system. This allows startup projects to provide minimal liquidity, without having to pay high fees for placement on major platforms.
2.4 How could I name the new DEX based on Ethereum?
After mentioning all the features for existing decentralized exchanges and the features to be improved while wanting to create a new decentralized exchange, if I was the owner of the new DEX I could name it Visible Light Decentralized Exchange (ViLiDEX) as an improved DEX.
I choose the name of Visible Light because light is an important thing in our daily and living life where it helps to see everything by our sights and light can be used in medicines when it is transformed. My new ViLiDEX should look easy to use for everyone as light is for all, the transactions should be quick and speed as light has high speed, all features should be well performed and workable for everyone.
The term “decentralized exchange” encompasses diverse applications and protocols that differ in architecture, but all enable users to transact cryptocurrencies without relinquishing control over their private keys to an intermediary.
Decentralized exchanges are still in an early development stage; their higher trade latency, lower liquidity, and less intuitive user interfaces make them less attractive for mainstream retail users. However, as centralized exchanges continue to experience security exploits and delay the listing of new cryptocurrencies, more users will elect to adopt decentralized exchanges despite their high friction. It is worthwhile to invest in the development and growth of the decentralized exchange ecosystem to promote liquidity in an increasingly diverse token ecosystem, greater user control of cryptocurrencies, more privacy features, and lower risk of censorship.
1. Guide to Atomic Swaps and Trustless Cross-Chain Trading
2. Blocknet White Paper
3. “The Trouble With Centralized Exchanges” by Blocknet
4. “Decentralized Cryptocurrency Exchanges” on Hackernoon
5. “Decentralized Exchanges:Three Types That Will Be Essential For The Crypto Economy” by Totle
6. “Analyzing Activities on Decentralized Exchanges” by ConsenSys
7. “70% of Value in Tech is Driven by Network Effects” by NFX