Why DeFi is the future of exchanges and trading | The Radix Blog | Radix DLT

January 7, 2022

An exchange is an organized marketplace where assets such as securities, commodities, currencies, or derivatives can be bought and sold. Example exchanges include the Tokyo Stock Exchange, for the trading of company shares in Japan; or the Chicago Mercantile Exchange, for the trading of derivatives in the United States.

Decentralized Exchanges (DEXs), a new type of exchange enabled by DeFi, are a means of facilitating the trading of assets without relying on financial intermediaries such as the abovementioned exchanges: DEXs are peer-to-peer. They have the potential to be a real game changer — providing a host of new features and possibilities not previously possible.

This article provides a brief overview of exchanges in traditional finance, compares this to the DEX, and summarizes the benefits of a certain type of DEX, the Constant Function Market Maker (CFMM). We explore how this technology might disrupt the existing exchange industry, and through increased access and choice, permeate more deeply into our everyday lives.

What is an exchange, and how do they work?

Exchanges help buyers and sellers find an equilibrium price. Without an exchange, buyers and sellers have to independently find one another, resulting in different prices for the same asset, and a less efficient market.

All exchanges in traditional finance work on the concept of an order book. This is where buyers and sellers each submit orders to buy or sell an asset, each with their own desired buy or sell price. If an order between a buyer and seller matches, then the order is fulfilled.

To fulfill the order, a complex series of steps involving multiple financial intermediaries takes place, ending in settlement typically two or more days after the trade was made.

How do Decentralized Exchanges work?

This allows for not only the traditional order book model to be replicated in a trustless and permissionless manner, such as with Serum or DeversiFi; but also makes possible an entirely new type of exchange — the Automated Market Maker (AMM).

The rest of this article focuses on a highly popular type of AMM — the Constant Function Market Maker (CFMM).

How does a CFMM work?

To perform a trade, a user sends an asset, Token A, to the CFMM smart contract which owns “pools” of Token A and Token B that define the two assets of the trading pair. An exchange rate between Token A and B is then calculated based purely upon the ratio of Token A and Token B pools held by the CFMM, using a constant function (the curve in the graph). In our example, the Token A pool is approximately twice as large as the Token B pool, and so the exchange rate between the two assets is the point at which the quantity of Token A and B in both pools intersects with the function. With the exchange rate now established, the CFMM sends the correct quantity of Token B to the user to complete the trade.

Note that no order book was needed; the trade resolved instantly and was completed directly against the pool — not another trader’s order. The price of the pair that a trader can buy or sell at is an emergent property of the buying and selling activity of the users that trade against the CFMM.

As the price of an asset changes in other markets, buyers and sellers would be expected to arbitrage any price differences between those markets and the CFMM, resulting in the price offered by the CFMM at any one time being broadly in line with those other markets. If it’s not — you have a risk free opportunity to arbitrage the difference! Flash loans are a powerful example of a capital-efficient way of arbitraging these differences in DeFi.

Where do the pools get their liquidity?

When a user wishes to supply the CFMM with liquidity, they must deposit a quantity of Token A and Token B into the pool that matches the current ratio of the two pools — meaning that the price calculated by the constant function is unchanged. The user is then provided “LP” (Liquidity Provider) tokens, which represent a claim on the tokens in both pools and can be redeemed at any time.

But why provide liquidity?

Why CFMMs are a game changer

24/7 global composable markets

Additionally, because DeFi is globally accessible, you can compose transactions across multiple CFMMs no matter the country in which the CFMM was established. This is not possible in traditional finance, such as selling a share on the Tokyo Stock Exchange to buy one on NASDAQ within the same transaction.

Instantaneous and permissionless settlement

Access and choice

Imagine if concert tickets were tokenized. If you could no longer go, you could easily sell those tickets for the correct market price on a CFMM. This means that as DeFi matures and more assets are tokenized, we will likely be interacting with CFMMs (and other types of DEXs) much more often, as markets can be created for anything from tokenized parking spaces to in-game currencies.

Guaranteed liquidity

CFMMs are therefore integral to the proper functioning of other parts of DeFi that require guaranteed liquidity — reinforcing how important composability is within a DeFi ecosystem.

For a traditional order book exchange, in order to have liquidity, you must have someone else on the other side of the order. This means that there are some extreme scenarios where the liquidity for an asset could disappear. For lending dApps in DeFi such as Aave or Compound that need to liquidate positions at certain prices, this would be a problem, as an order book exchange cannot guarantee that orders will be matched.

However, guaranteeing liquidity at all price points isn’t always a good thing as the liquidity offered by the more extreme ends of the function, in 99.99% of cases, never gets used. This makes CFMMs relatively capital inefficient. Solutions to this are in the process of being addressed with innovations such as Uniswap v3, which allows for liquidity providers to more tightly define the function that they provide liquidity against, resulting in better capital efficiency.

Concluding Thoughts

But to harness the innovative disruption that DEXs can provide, the programming language used to create them must be fit-for-purpose. With DeFi hacks occurring weekly, and current languages such as Solidity being devilishly complex and unintuitive, a new development paradigm is needed if the potential of DEXs is to be fully realized.

This is why Radix is building Scrypto — the only programming language tailor-made for DeFi — with the concept of assets as a core feature. To understand why developing DEXs in Solidity just makes no sense, check out our article The Problem With Smart Contracts Today. To find out how Scrypto allows for DeFi development at the speed of thought, be sure to read Radix Engine v2: An Asset-Oriented Smart Contract Environment and Scrypto: An Asset-Oriented Smart Contract Language.

Be sure to also check out our developer site, developers.radixdlt.com, to get going with Scrypto and build your first DeFi dApp.

Originally published at https://www.radixdlt.com.

--

--

The first layer 1 protocol specifically built to serve DeFi

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store