Understanding DeFi: Decentralized Exchanges

in #defilast year

“Exchange” or “Exchanges” is something that is exceedingly familiar. It always passes by in one or the other order. When it comes to a financial ecosystem, the weight of exchanges is heavier as the system is no complete without the mentioning of “exchanges.”

Well, one is very well acquainted with the traditional fiat and stock exchanges that enables to trade seamlessly the assets. Once a niche offering, the exchanges are now a heavy webbed strap that everyone is associated it.

Similarly, is the new phenomenon fondly called the DeFi.

Decentralized Finance (DeFi) enables the trading of digital assets or tokens in a peer-to-peer manner. And the Decentralized Exchanges allow the users to buy and sell their digital assets. More on, the DeFi Exchanges allow holders of different digital assets to use different DeFi services.

Amused??? Let’s get deeper.

If we flip, the majority of crypto trading happens via centralized exchanges (CEX) that include the intervention of a trusted third party between buyers and sellers. The mislike is that they keep users’ digital assets under their custody, decide the prices, match buyers-sellers, and finally settle the transactions. The idea of decentralization or peer-to-peer trading is a never heard thing. Coinbase and Binance are some well-known centralized exchanges.

By facilitating the transaction through a well-built, centralized platform, the centralized exchanges offer DeFi beginners higher comfort levels. However, charging a high transaction fee for their services. Also, like any other centralized system, exchanges face the downsides associated with third-party involvement.

The solution called for was the Decentralized Exchanges.

Decentralized Exchanges (DEX)

Decentralized Exchanges or DEX include those DeFi protocols that facilitate the non-custodial exchange of on-chain digital assets. In decentralized exchanges, the trading functionalities are coded as smart contracts. They allow direct communication between buyers and sellers by interacting with the smart contracts behind the trading platform. Users are fully responsible for their funds since the exchange will not have ownership over the user’s fund. A transaction fee will be associated with every trading operation.

DEX settles all transactions on-chain, thereby ensuring public verifiability for all transactions to network participants. A DEX can only trade assets that are native to the underlying blockchain. For example, a DEX built on Ethereum cannot trade bitcoin (which belongs to an external blockchain) or fiat currency (an external asset). Cross-chain solutions and token wrapping techniques like wrapped Bitcoin are the proposed solution to overcome this limitation. But they are not widely adopted in DEXs.
Means of Division

DEXs are primarily classified based on the methods used for price discovery. Price discovery denotes fixing the price of an asset based on its supply and demand.

Order Book based Decentralized Exchanges

Order Books are electronic ledgers that record trading activities. A bid or buying order denotes that a trader is ready to buy a particular asset for a specific price. A selling order or ask indicates that a trader is prepared to sell an asset under consideration for a particular price. The bids and asks against an asset determine its market price.

image.png

A user can submit two types of orders: a market order or a limit order. A market order is for buying and selling assets immediately for the best available price. They are filled by instantly pairing buyers and sellers. In case of a limit order, a user can set the price at which he wants to buy or sell an asset. The order waits in the order book. Once the asset hits the quoted price, the order book will automatically execute the trade on behalf of the user. This method is incredibly convenient for users who aren’t frequent traders. A trade gets successfully executed when a buying-selling order gets matched.

Now the question is, who is performing this match?

Well…this can be executed either manually or algorithmically. It will introduce additional delays if done manually, and price discovery may be inefficient. A matching algorithm can match buyers to sellers such that for each matching buyer-seller, the buyer’s price is no less than the seller’s price. For matched orders, the DEX also determines a settlement price which the buyer should pay the seller, and the seller transfers ownership of the asset to the buyer. Orders that aren’t getting matched in one round can be carried forward to the next matching round.

The order books occupy a decent amount of memory space and computational cost, and thus maintaining the order book on the chain can be expensive. This further divides order book DEX into two: off-chain order book DEX and on-chain order book DEX. In the off-chain order book, DEX trading activities occur outside the blockchain, and only final transaction settlements are on the blockchain. The profit is the reduced cost and time for transaction processing. Those who save their open order information on the blockchain are referred to as on-chain order book DEXs. It can help users access funds from lenders on the same platform; however, a costly affair. Here, in on-chain transactions, there will be an imposing of some additional fees Exchanges like 0x , dYdX and IDEX are examples of order book-based DEX.
Image source: Dex.guru

Automated Market Makers

Automated Market Maker (AMM) is an automated system to settle traders which uses an on-chain liquidity pool instead of an order book for matching. In liquidity pool, a collection of funds for two or more assets(tokens) are locked in a smart contract. Entities that contribute to the liquidity pool are called liquidity providers. They implement a peer-to-pool method, where liquidity providers contribute tokens to liquidity pools. At the same time, individual users exchange tokens in a pool that contains specific input and output tokens.

image.png

Trading activities are performed against the smart contract’s liquidity reserve for an asset, where liquidity is added to the reserves of one token and withdrawn from the reserves of one or more other tokens in the pool. It uses a mathematical function to determine the exchange rate of the asset. The price depends on the relative sizes of the provided liquidity on each side of a token pair. This function can vary according to the protocol.

Let’s take an example. Assume we maintain a liquidity pool of 2 tokens, token A and token B and uses a formula: x * y = k. Here x represents the amount of token A and y is the amount of token B in the pool, and k represents the total liquidity of the pool, which must remain constant. Suppose a user wants to buy token B with token A. In that case, it will decrease the balance of token B, which increases the price of token B and reduces the cost of token A. Price is calculated based on the ratio of token A and B, such that the k value remains constant. The above is an example of a constant function market maker.

AMM users obtain immediate liquidity without finding a matching seller/buyer. A liquidity pool decides a trading fee and pays out proportionally to the share of liquidity provided by each liquidity provider. Uniswap is a AMM protocol built on top of the Ethereum blockchain. Another example is Bancor.

DEX Aggregators

Since different DEXs operate on different protocols, the price of an asset also varies. DEX aggregators or liquidity aggregators group the exchange rates of numerous DEX platforms and helps the user identify the best place to trade. 1inch and Matcha are the well-known DEX Aggregators.

With the rising participation in DeFi, the significance of DEXs is also skyrocketing.

Unlike centralized exchanges, there is no entry barrier to DEXs. The users get more privacy and anonymity. But this factor makes them risky for investors because if the DEX gets hacked, there is no way to recover the fund loss.

Coin Marketplace

STEEM 0.18
TRX 0.14
JST 0.030
BTC 58665.81
ETH 3153.57
USDT 1.00
SBD 2.44