Scroll down
Close -

Understanding Decentralized Exchanges (DEXs)

Published on: 18 December, 2020

In 2008, Bitcoin’s release sparked a major paradigm shift in the global outlook towards money and financial institutions. Among other aspects, it marked the first-ever stable implementation of blockchain technology to build a decentralized, peer-to-peer monetary framework. It enabled the possibility for creating, storing and transferring monetary value without involving third-party intermediaries such as banks, brokers and other traditional actors. Such was the original principle of the blockchain-cryptocurrency community, as envisioned by Satoshi Nakamoto—Bitcoin’s pseudonymous creator.

Over the years, the crypto space has been one of the most rapidly proliferating domains globally. Today, there are 2000+ altcoins and several are backed by highly promising and ground-breaking innovations. Yet, some of the most common and accessible ways of interacting with these assets have been centralized platforms.

As a counter force to this situation, innovations in Decentralized Exchanges (DEX) platforms have been steadily on the rise. Among others, Uniswap is a famous example on this regard. Against such a backdrop, this article discusses DEXs from within and without, taking an in-depth look into the subject. In doing so, we will also highlight RSK’s contributions in this area.

Index

Understanding Decentralized Exchange (DEX) — A Complete Guide for Beginners by RSK

Cryptocurrency Exchange: Definition & Demand

The Problem of Custodial Exchanges

The Rise of Non-Custodial DEXs

   Shifting Away from Order Books: Towards Greater Decentralization

The Working of DEX: Pillars of P2P Trading

  Atomic Swap

  Liquidity Pools

  Automated Market Making

The Advantages of DEX

  Non-Custodial

  Broader Access

The Challenges for DEX

RSK for DEX: RSK Swap & TEX

Conclusion

Cryptocurrency Exchange: Definition & Demand

Let’s begin by answering something basic—why do we need cryptocurrency exchanges in the first place? Now, imagine accessing the internet if there were no web browsers. To reach any web-hosted asset, you’d have to type in the IP address and some blocks of code on, say, your computer’s Command Prompt. By far, that is a severely simplified imagery and the reality would be much more complex. 

As a structural framework, blockchain networks are similar to the Internet. Therefore, much like we need browsers and other applications to access the web, we also need platforms, protocols, and applications to interact with blockchains. A cryptocurrency, as we know, is a blockchain-based asset and the platforms through which we interact with such assets are known as cryptocurrency exchanges. 

Primarily of two kinds—centralized and decentralized—these exchanges enable crypto-users to buy, sell, trade and transfer cryptocurrencies. By extension, they serve as platforms for projects to enlist their tokens for market participation.

The Problem of Custodial Exchanges

As the name suggests, Centralized Exchanges are owned, managed, and governed by centralized entities such as for-profit companies. Such platforms are also predominantly custodial, in the sense that they retain possession and control of the users’ private keys. To participate on a custodial exchange, the user has to deposit their funds in the latter’s wallets, which effectively amounts to giving up the ownership of the deposited asset. This evokes serious concerns and risks, as discussed in this section.

First, it violates one of the most fundamental crypto principles—users’ autonomy. To use the cliché, you own your crypto-asset only as long as you own the associated private key. As such, since transactions with most cryptocurrencies are settled on the blockchain, they are essentially always decentralized. Yet, by ‘facilitating’ such transactions, custodial exchanges play a similar role as the ‘trusted intermediaries’ of traditional financial systems.

Secondly, to meet regulatory obligations, custodial exchanges subject their users to stringent KYC/AML-based onboarding procedures. The information accrued thereof are then stored in centrally located servers, as are the deposited funds. In turn, these servers represent single-points-of-error and are vulnerable to a wide range of security and privacy breaches. 

Thirdly, custodial exchanges are often opaque, wherein users don’t have access to the data generated by a majority of the associated processes. Furthermore, centralized governance fosters the risks of manipulation, as well as of censorship and espionage by competent authorities. Effectively, this demeans some of the pivotal advantages of having a blockchain-based ecosystem.

The Rise of Non-Custodial DEXs

Contrary to centralized exchanges, decentralized exchange (DEX) platforms are not governed by any singular entity. Instead, they leverage smart contracts and other distributed solutions to directly connect counterparties, thus enabling P2P trading and exchange of crypto-assets. 

Although some of the elements of the DEX infrastructure came alongside Bitcoin, Ethereum played a major role in their proliferation, initially at least. Smart contracts not only allowed trading processes to be automated without third-party intervention, but they also made DEXs inherently non-custodial. Instead of hot and/or cold wallets owned by the exchange, funds could now be escrowed in decentralized smart contracts. Since these smart contracts are deployed on the blockchain and record transactional information thereof, they are accessible to the network. This substantially addresses the opacity of centralized exchange platforms. 

Later in this article, we shall discuss the advantages of being non-custodial in more detail. Let’s first gain a better understanding of some nuances of DEXs. In this context, one must note that exchange platforms can have varying degrees of decentralization. Similar to any blockchain-based solution, they can be partially or fully decentralized, depending upon the nature and architecture of their individual elements. Apart from that, a DEX can predominantly be of two kinds: currency-centric and currency-agnostic.

A currency-centric DEX is a non-interoperable system built on top of a particular blockchain, whose functionalities are limited to the blockchain’s native cryptocurrency. In other words, they only support trading and transactions using a particular crypto-asset. On the other hand, a currency-agnostic DEX is more like an interoperable protocol. Although built within a particular blockchain ecosystem, it can function with tokens from other blockchains. Further, they may even be deployed outside their native network. Understandably, the latter form is more decentralized, in the sense that it doesn’t have a single underlying crypto-asset.

Shifting Away from Order Books: Towards Greater Decentralization

In the context of cryptocurrency exchanges, the Order Book plays a crucial role as the ground for counterparty discovery. In general, traders enlist their Buy/Sell orders on the exchange, which are then used to match counterparties. However, in the case of centralized exchanges, the matching mechanism isn’t controlled by or accessible to the users. Moreover, unlike with DEXs, centralized order books show aggregated orders instead of individual ones.

Ideally, DEXs tend to shift away from the order book model in favor of liquidity reserves. Instead of involving market makers that are always “willing” to buy or sell a given asset, facilitating trades in the process, a liquidity reserve represents an asset pool that provides a consistent market. We shall elaborate on this point later, presently focusing on the DEX version of order books. 

The primary feature of a DEX order book is that it presents particular Buy/Sell orders from individual users. That is, it doesn’t aggregate multiple orders into one and requires the trader to identify orders from the counterparty with whom they wish to trade. They automate the order matching mechanism, thereby eliminating centralized market makers. Furthermore, DEXs mostly use on-chain order books, wherein transactions are recorded on the blockchain at the time of trade. However, in partial DEXs, the order book may also be hosted off-chain, which instills a centralized element despite enabling direct counterparty interactions.

The Working of DEX: Pillars of P2P Trading

Until this point, we have discussed the holistic structure of decentralized exchanges. Now, let us focus on some of the individual elements that facilitate P2P trading. In the absence of any centralized authority, the interconnected functioning of these individual elements is the binding factor for a decentralized exchange. In turn, this expands the possibility for combining these elements and enhances the overall scope for innovations in DEX ecosystems.

Atomic Swap

Backed by smart contracts, Atomic Swaps are a decentralized way of exchanging one crypto-asset with another. The process is instantaneous—almost real-time settlements—and does not require any third-party intermediary. In this sense, then, atomic swaps emerge as one of the most crucial pillars of DEX ecosystems. Throughout the exchange process, the involved counterparties retain complete control over the ongoing swap, mutually determining the terms of the trade. 

Interoperability is among the strongest upsides of atomic swaps, as they can seamlessly occur across blockchains. For instance, if Alice wants to exchange 10 BTC for its ETH equivalent, she can perform a swap with someone, say Bob, who has the required ETH and is willing to participate in the trade. Without atomic swaps, the process would be much longer and involve intermediaries—Alice deposits her BTC to a centralized exchange, which matches her Buy Order with a corresponding Sell Order. In this case, Alice’s choice of platform would be limited to exchanges offering a trading pair that is relevant to her needs—here, BTC/ETH. Although this works fine for popular cryptocurrencies, it’s a major hindrance to exchanging niche or low-value assets. 

To perform their P2P function, atomic swaps use Hash Timelock Contracts (HTLC). In simple terms, an HTLC is a smart contract that generates a key pair and self-executes the predefined action in a time-based manner. Both counterparties involved in an atomic swap have to acknowledge the receipt of funds within a specific time-frame, and if either party fails to do so, the entire transaction is rendered null and void. This minimizes the risks of counterparty frauds, while also allowing the involved parties to opt-out of the swap at any point in the process. 

Liquidity Pools

In order to trade any given crypto-asset, there must be adequate supply—that is, the asset must have liquidity. If not, then either there won’t be enough tokens to buy/sell, or individual trades will result in massive fluctuation in the asset’s price. Understandably, neither is desirable. 

The centralized solution to the liquidity problem is to have market makers—entities that facilitate trades by always willing to buy or sell any given asset. That, however, is vesting too much control on such entities, which in turn, increases the risk of manipulation and significantly threatens fair trading. 

On the contrary, DEXs use liquidity pools. Basically smart contracts, these are escrowed reserves wherein multiple providers ‘pool’ their assets to generate liquidity. Liquidity pools have proportional amounts of asset pairs—say, BTC and LTC. For any given asset pair, the underlying pool represents a consistent market where users can trade using atomic swaps. In general, DEX protocols require the trader to provide liquidity at one end of the pair, while swapping out from at the other end. Liquidity providers, on the other hand, are incentivized to contribute equal proportions of both assets to the pair. 

Suppose, Alice has LTC which she wants to swap with BTC, thus trading in the BTC-LTC pool mentioned above. To do this, she will add liquidity to the LTC end of the pair and withdraw an equivalent amount of BTC. 

Automated Market Making

Automated Market Making or AMM is a mechanism that algorithmically determines the price of assets held in a given liquidity pool. Usually, the base price of the assets or their swapping ratio is fixed by the liquidity provider that initiates the pool. Thereafter, the AMM algorithm automatically sets prices based on demand-supply metrics and the size of individual trades. 

AMMs often involve a minimal trading fee that cumulatively accumulates in the reserve. The process has a dual purpose. One, it maintains a stability in the pool’s overall volume, thus curtailing volatility due to individual trades. Second, it incentivizes liquidity providers who receive Annual Percentage Yields (APY) for their assets staked in the DEX’s pools. 

Commonly, the term AMM is used synonymously with DEX, but that, of course, is a misuse. Furthermore, one must also note that AMM’s can themselves be of two kind, in theory—the order book model, but automated, and the fully-automated algorithmic mechanism. However, by AMM, we mostly refer to the latter.

By determining prices algorithmically, AMMs eliminate the need to have order books. The purpose of listing trades on the order book is to specify and notify the asset’s trading price. In other words, Buy Orders specify the price at which the trader wants to buy an asset, while Sell Orders denote the price at which the maker is willing to send. Therefore, in AMM-based decentralized trading, there is no need to have such orders. As a whole, AMMs enhance the reliability and fairness of DEX-based crypto-trading, while also facilitating an unprecedented and diverse methods for generating passive income.

The Advantages of DEX

In light of the foregoing discussion, we might already have some idea about the contents and highlights of this section. Yet, the advantages of DEXs must be mentioned in bold and clear terms. 

Although apparent, one must categorically bear in mind that DEXs are facilitated and governed by globally distributed networks of computers (nodes). The network architecture is not hierarchical, meaning that every node is theoretically at the same horizontal level. Ideally, there aren’t any identifiable points of control, and by extension, there is no single-point-of-error. Both funds and users’ data are recorded on the blockchain—that is, stored on the distributed ledger, rather than in centrally located servers. As such, the advantages of DEX are largely a courtesy of this architecture.

Non-Custodial

We already know that DEXs are predominantly non-custodial, in the sense that they don’t hold onto the user’s funds like their centralized counterparts. Now, one might argue that DEXs lock up funds in smart contracts and that’s tantamount to being custodial. Such claims would be misinformed for two reasons, at least. First, smart contracts are themselves decentralized protocols, unlike most exchange-owned wallets, and second, while locking funds in smart contracts, DEXs don’t take control over the users´ private keys. In fact, the private-key aspect is a greater marker of being non-custodial, rather than the point of locking or not locking funds in some manner. 

Security is a major outcome of being non-custodial, since centrally located server and storage locations are easier to breach. However, the fact remains that vulnerabilities in smart contracts may also be hacked into, but the risk is far less because interactions with smart contracts happen over decentralized channels. That apart, security isn’t only about hacks, but also about censorship, monitoring, and espionage which are virtually impossible in the context of DEX. In this sense, security and privacy emerge as intertwined entities, and DEXs optimally uphold both ends for crypto-users. Above all, the ecosystem perceives traders and providers as autonomous self-sovereign entities, which stands true to the founding principles of the blockchain-cryptocurrency domain. 

Broader Access

DEXs are mostly permissionless platforms, meaning that anyone can use them, as long as they have a basic internet-enabled device. Coupled with the globally increasing availability of such devices, DEXs become accessible to a greater section of the world’s population, as compared to centralized exchange platforms. 

Moreover, by virtue of being based on distributed networks, DEXs are not bound by geographical and/or cultural barriers, and their services can be accessed from around the world. From the project owner’s perspective as well, DEXs feature minimal barriers to entry, thus allowing niche tokens to be listed for trading. However, this also retains the scope for misuse by fake tokens, that can be similarly listed on these platforms—the irony of being permissionless, that DEX innovators would hopefully overcome in the near future. 

The Challenges for DEXs

Despite their proliferation and disruptive potential, DEXs are still facing some persistent challenges to mass adoption, primarily due to the technology’s nascence. In all fairness though, these are not essentially related to DEXs protocols, but rather to the state of the underlying technologies at work.

First, a majority of existing DEXs suffer from low-scalability, resulting in a competitive disadvantage with regard to centralized exchanges. Since every action is directly recorded and settled on the blockchain, there is a limited capacity for handling large trading volumes. That being said, developments on Sidechains, SegWit and other scalability solutions present a rather bright light at the end of the tunnel.

Secondly, DEXs often tend to be difficult to use for beginners and involve a steep learning curve for traders, as well as for liquidity providers. At least, this applies to those who intend to use these fully leverage DEX protocols. However, considering that interactive UIs and user-friendly solutions are already being developed for DEXs, the usability concerns are also on the verge of being minimized, if not eliminated completely. 

RSK for DEX: RSK Swap & TEX

Before concluding and in light of the challenges mentioned in the preceding section, let’s turn to some DEX innovations that are being played out on RSK. 

Developed by IOV Labs—an RSK and RIFOS partnership—RSK Swap is a DEX protocol leveraging atomic swaps, liquidity pools and AMM. As a fork of Uniswap v2, the protocol enables users to swap ERC20 tokens in a decentralized, permissionless, secure and censorship-resistant manner. Considering that RSK is a Bitcoin-based ecosystem, the inclusion of Ethereum-based ERC20 tokens into its ambit has been a significant breakthrough in terms of interoperability.

Further, in 2020,  Money on Chain (MoC) have leveraged RSK’s technology stack for Bitcoin-based DeFi to build an innovative DEX platform, namely TEX. In doing so, they have created a robust secondary market for MOC-native assets.

TEX adopts an intuitive pricing mechanism that combines the best of AMMs and Order Books. Instead of instantaneous order execution, a tick-based approach enables the protocol to facilitate trades at the most recent price based on market dynamics. While the advantages of atomic swaps still remain, TEX’s method is highly conducive of early-stage tokens that are in the phase of organically growing their asset’s liquidity. 

Based on the decentralized order book, TEX facilitates Limit Orders and a unique sub-category called Market Maker Orders. While the former allows traders to specify the maximum price at which they intend to buy an asset, providers can use the latter to specify the percentage difference in relation to a “fair” price. Backed by Oracle-compatibility, the method minimizes the risks of loss due to slippage during trade. For more details on TEX, the interested reader can experience the platform live.

Conclusion

Blockchain-based crypto assets keep gaining popularity and so are the methods of interacting with them. One of these methods is through centralized exchanges but it introduces several risk vectors. Most importantly, it stands in violation of some of the basic principles upon which the community was founded. 

As a solution for this crisis, Decentralized Exchanges or DEXs have emerged on the scene. Unlike their centralized counterparts, DEXs leverage atomic swaps, liquidity pools, and Automated Market Making (AMM) protocols to facilitate P2P trading. Moreover, DEXs are non-custodial and don’t assert control over the user’s private keys. In combination, these enable a user-oriented and decentralized trading ecosystem, with significant security and privacy benefits. 

RSK—a dedicated proponent of DeFi-based open financial frameworks—has been in the game not just by innovating the RSK Swap protocol, but also by offering a tech stack to enable further innovation. Taking cue, Money on Chain (MoC) has developed TEX, which is a unique DEX with hybrid pricing mechanism. Empowered by Bitcoin-based stability, security and decentralization, we are on a journey towards transforming the future of crypto-trading.A journey that can’t be trodden alone but only alongside the community.