# Mintlayer Authors - 5. Decentralized Exchange (Highlights)

## Metadata
**Review**:: [readwise.io](https://readwise.io/bookreview/25842483)
**Source**:: #from/readwise
**Zettel**:: #zettel/fleeting
**Status**:: #x
**Authors**:: [[Mintlayer Authors]]
**Full Title**:: 5. Decentralized Exchange
**Category**:: #articles #readwise/articles
**Category Icon**:: 📰
**URL**:: [docs.mintlayer.org](https://docs.mintlayer.org/whitepaper/5-decentralized-exchange-dex)
**Host**:: [[docs.mintlayer.org]]
**Highlighted**:: [[2023-03-29]]
**Created**:: [[2023-04-04]]
## Note
Mintlayer's decentralized exchange (DeX) offers two solutions for completing trades. The first is an atomic swap smart contract that facilitates communication through standardized order messages. The second is a peer-to-peer communication system based on a distributed hash table (DHT) that allows for swaps between unknown entities with no prior contact. Additionally, an "observer" can be used to store and cross-check the DHT order book and collect information about successful atomic swaps. Finally, a programmable pool DEX is also available, which provides less privacy but more efficiency. All of these solutions require a peer-to-peer messaging system to facilitate communication between users and enable the atomic swap transactions.
## Highlights
- Mintlayer users and developers can choose between six different types of DEX interactions, depending on their needs in terms of decentralization, privacy, and censorship resistance: from a fully decentralized solution in both trading engine and messaging system to milder solutions that introduce intermediaries in the communication to increase the spectrum of possible trades. ([View Highlight](https://read.readwise.io/read/01gwpmwzxv13tg77z1s9ng8514)) ^499747410
### 5.2. The atomic swap DEX
- The first solution is based on the **atomic swap** smart contract playing the part of the trading engine. It does not rely on any particular communication system: users can exchange order intentions using **any medium of communication**. ([View Highlight](https://read.readwise.io/read/01gwpn0a3zzf1yymmwqpz2612q)) ^499748687
### 5.3. DHT multiparty swaps
- Like the first solution, the second one uses the **atomic swap** as a trading engine and also introduces a **peer-to-peer communication** system that allows swaps between parties that are unknown entities to each other with no prior contact. ([View Highlight](https://read.readwise.io/read/01gwpn0xtfner3zq6nhzqtscb9)) ^499748721
- Not all orders that reach the peer are registered on the hash table; instead, each node stores only those orders that are filtered based on their interest and will pass on to the network only what is stored, just like it happens on BitTorrent or other similar peer-to-peer systems. ([View Highlight](https://read.readwise.io/read/01gwpn376ez7rj8sh4k7xc91rh)) ^499748942
- Orders can have a **due-date**; some are dropped by the nodes who created them, while others are closed because the swap has already been successfully finalized. To notify peers of **closed or canceled orders**, it is necessary to prove those orders’ ownership by signing the message with the private key connected to the original order creator’s DID. Nodes also notify the peers by relaying messages about the closed orders. ([View Highlight](https://read.readwise.io/read/01gwpn53wvmp589c2nxw5jcw11)) ^499749456
- An anti-spam filter is necessary because an attacker could populate the DHT with fake orders. ([View Highlight](https://read.readwise.io/read/01gwpn5q2f8rw5zy5a53x9s3ph)) ^499749497
- The user creating an order may use a **price ratio** suggested directly by the wallet node. The user chooses between two indicators: a) the price provided by a **centralized exchange/service through API** or b) the price **retrieved from the DHT**, which is calculated in a fully decentralized way. ([View Highlight](https://read.readwise.io/read/01gwpn8nabs53wwnyz5qknvkbj)) ^499749693
### 5.4. Observer of multiparty swaps
- Nodes can subscribe to the “observer” services, which act as the quality guarantee to its subscribers. The observer aims to voluntarily store the entire DHT, plus a few additional pieces of information provided by the nodes connected to them that report the effective status of the orders. ([View Highlight](https://read.readwise.io/read/01gwpnbmddeymtqm7qzq24t1v1)) ^499750206
- The observer checks the status and the frequency of the operations to create a rank, which is higher when the number of finalized operations is higher when both involved users confirm that the atomic swap was successfully achieved. ([View Highlight](https://read.readwise.io/read/01gwpncnk25mjs7vry61exh7mj)) ^499750341
reputation system
### 5.5. Book aggregators for multiparty swaps
- A second solution to avoid the drawbacks of a DHT constructed in a peer-to-peer way is to trust special node relayers that act as book aggregators and store the DHT on behalf of the users. ([View Highlight](https://read.readwise.io/read/01gwpnjkyj8tw9g21fd0whfayj)) ^499751018
- When users intend to exchange tokens, the Mintlayer wallet uses bloom-filters to ask a book aggregator for a specific pair’s order. ([View Highlight](https://read.readwise.io/read/01gwpnkgpa4ajq18n274k7a2s5)) ^499751060
- Such “book aggregator” relayers can be paid off ([View Highlight](https://read.readwise.io/read/01gwpnncrabcf1anv0t4km361z)) ^499751375
### 5.6. Programmable pool DEX
- To participate in a programmable pool DEX, the traders need to “consolidate” one or more UTXO in an account-based address. ([View Highlight](https://read.readwise.io/read/01gwpnqjksbvmv0ywvathdnjxa)) ^499751616
### 5.7. Lightning Network DEX
### 5.8. Peer-to-peer messaging system
- Each message is a data packet that contains order parameters concatenated and hashed to 32 bytes using the Keccak SHA3 function. The maker signs the order with the private key associated with his digital identity ([DID, see §4.4.](https://docs.mintlayer.org/whitepaper/4-decentralized-finance-defi#4-4-decentralized-identity-did-and-oracles)).
Once packaged, the order can be sent to the recipient using whatever medium of communication, even a direct message (i.e., using Messenger, Telegram, etc.), that is if the recipient already knows the maker. ([View Highlight](https://read.readwise.io/read/01gwpnxdr26tf7nn8x0d0904qq)) ^499752173