Course Content
What Is a Decentralized Exchange (DEX)?
You probably know the drill with cryptocurrency exchanges. Sign up with your email, come up with a strong password, verify your account, and start trading cryptocurrency. Decentralized exchanges are like that, minus the hassle of sign-ups. In most cases, there’s no depositing or withdrawing crypto. The trade happens directly between two users’ wallets, with limited (if any!) input from a third-party. Decentralized exchanges can be a bit trickier to get the hang of, and they might not always have the assets you want. But, as the tech and interest in it grow, these may very well become integral components in the cryptocurrency sphere.
What Is a Decentralized Exchange (DEX)?
About Lesson
DEXs are similar to their centralized counterparts in some ways but significantly different in others. Let’s first note that there are a few different types of decentralized exchanges available to users. The common theme among them is that orders are executed on-chain (with smart contracts) and that users do not sacrifice custody of their funds at any point.
Some work has been done on cross-chain DEXs, but the most popular ones revolve around assets on a single blockchain (such as Ethereum or Binance Chain).

On-chain order books

In some decentralized exchanges, everything is done on-chain (we’ll talk about hybridized approaches shortly). Every order (as well as alteration and cancellation) is written to the blockchain. This is arguably the most transparent approach, as you’re not trusting a third party to relay the orders to you, and there’s no way to obfuscate them. 
Unfortunately, it’s also the most impractical. Since you’re asking every node on the network to record the order forever, you end up paying a fee. You need to wait until a miner adds your message to the blockchain, meaning the experience can be cumbersome, too. 
Some identify front running as a flaw in this model. Front running occurs in markets when an insider is aware of a pending transaction and uses that information to place a trade before the transaction is processed. The front runner, therefore, benefits from information not known to the public. Generally speaking, this is illegal. 

Of course, if everything is published on a global ledger, there’s no opportunity to front run in the traditional sense. That said, a different kind of attack can be deployed: one where a miner sees the order before it’s confirmed, and ensures that their own order gets added to the blockchain first.

Examples of on-chain order book models include the Stellar and Bitshares DEXs.

Off-chain order books

Off-chain order book DEXs are still decentralized in some regards, but they’re admittedly more centralized than the previous entry. Instead of every order being posted to the blockchain, they’re hosted somewhere. 

Where? That depends. You could have a centralized entity completely in charge of the order book. If that entity is malicious, then they could game the markets to an extent (i.e., by front running or misrepresenting orders). However, you would still benefit from non-custodial storage.

The 0x protocol for ERC-20 and other tokens deployed on the Ethereum blockchain is a good example of this. Rather than act as a singular DEX, it provides a framework for parties known as “relayers” to manage off-chain order books. Leveraging 0x smart contracts and some other tools, hosts can tap into a combined liquidity pool and relay orders between users. The trade is only executed on-chain once the parties are matched.

These approaches are superior from a usability perspective than those that rely on on-chain order books. They don’t face the same constraints in terms of speed, as they don’t use the blockchain as much. Still, the trade must be settled on it, so the off-chain order book model is still inferior to centralized exchanges in terms of speed.

Implementations of off-chain order books include Binance DEX, IDEX, and EtherDelta.

Automated Market Makers (AMM)

Fed up of reading the term “order book?” Great, because the Automated Market Maker (AMM) model does away with the idea altogether. It doesn’t require makers or takers, just users, game theory, and a bit of formulaic black magic. 
The specifics of AMMs depend on the implementation – generally, they string together a bunch of smart contracts and offer clever incentives to ensure user participation. We won’t detail these implementations, but check out What Is Uniswap and How Does It Work? for an example of how the Uniswap DEX works.
The available AMM-based DEXs today tend to be relatively user-friendly, integrating with wallets like MetaMask or Trust Wallet. As with other forms of DEXs, though, an on-chain transaction must be made to settle trades.

Projects working on this front include the aforementioned Uniswap and Kyber Network (which taps into the Bancor protocol), both facilitating the trade of ERC-20 tokens.

Exercise Files
No Attachment Found
No Attachment Found