MuesliSwap presents: The protocol powering Cardano’s first DEX
Join the party at https://ada.muesliswap.com.
On November 26, 2021, MuesliSwap successfully launched a decentralized exchange (DEX) on Cardano mainnet, making it the first among many competitors to leap into a new era of DeFi on Cardano. As team MuesliSwap, we have been thrilled to see the very first decentralized token swaps happening on Cardano, and we are more than grateful for the warm welcome into the Cardano community. Great interest has been shown in how MuesliSwap operates from a technical perspective, and therefore in this article, we would like to take a step back and shed some light on the inner workings of the MuesliSwap DEX.
Note that a few weeks back, we published our whitepaper which contains an in-depth treatment of how to conceptually build a DEX on an EUTXO-based blockchain such as Cardano, including discussions on how to best leverage concurrency, avoid contention, ensure fairness, and alike. These considerations are all necessary and important when developing a DEX. In this article though, we want to break down all the concepts relevant for interested users. Because as team MuesliSwap, we believe in true decentralization. Openly discussing our technical solutions and having a user base that understands the platform they are trading on well is a crucial part to decentralization, and the best source of trust for everyone.
First of all, the exchange model at the basis of MuesliSwap is fundamentally different from DEXs on other chains like Uniswap on Ethereum, and in fact replicates the traditional order book exchange in a new, decentralized way. For a detailed discussion on why we believe this is a good choice, check our whitepaper. We now describe the trading workflow from a user’s perspective.
Let’s say Charles wants to buy some of his favorite tokens, namely 10 MILK, and is willing to give at most 5 ADA in return. This corresponds to him setting a limit price of 0.5 ADA per MILK. He then places an order at ada.muesliswap.com/swap which is then being entered into the decentralized order book by locking the respective 5 ADA along with some additional metadata in the MuesliSwap smart contract on the Cardano blockchain.
Now Alice comes along with the intention of selling some MILK. She wants to receive at least 6 ADA in return for the 10 MILK she puts into her order, and therefore 6 ADA is her buy-amount. Similarly, Bob places an order selling 10 MILK but only asks for 4 ADA in return, meaning he takes into account a lower limit price than Alice. Our order book now looks as follows:
Notice how Charles, Alice and Bob directly interact with our smart contract on the blockchain, with no third party being involved. This is also the key difference to the traditional order book exchange where orders are submitted to a central trusted coordinator that then matches orders and executes trades. In our case, orders are submitted to the smart contract which cannot actively coordinate itself. Therefore, the question is of course how orders get matched such that they then become executed without introducing a central coordinator.
This is where matchmakers come in: A matchmaker is an agent observing the state of all orders currently locked in our smart contract. Once two matching orders are found, the matchmaker initiates the exchange via the smart contract, with the possibility of keeping the remaining profit margin as an incentive. We point out that the smart contract enforces such exchanges to be valid (in the sense that all parties get their ordered amount at the specified price), meaning the matchmaker is not taking the role of a trusted broker but only of a trustless initiator. Having only a single matchmaker would still lead to some central concentration of power, as we have argued in the whitepaper. Therefore, MuesliSwap decentralizes matchmaking as well: Everyone can become a matchmaker and thereby contribute to the MuesliSwap exchange platform and earn matchmaking incentives. More guidance on how matchmakers can interact with our smart contract will be made available soon.
Back to our example: Say matchmaker M1, by scanning the blockchain for new entries in the MuesliSwap smart contract, first looks at the top two orders in the order book. Clearly, these will not be matched since the smart contract would enforce Alice to receive her 6 ADA as requested but Charles only provides 5 ADA. Next, M1 looks at the top and the bottom order in the order book. In this case, limits are set in a way that makes both Charles (getting his ordered 10 MILK) and Bob (getting his ordered 4 ADA) happy. There even remains an extra 1 ADA leftover from the 5 ADA Charles has provided. The matchmaker can keep this difference as a reward for initiating the match and enabling the market to make progress.
To those brave pioneers among you that have already benefited from trading on MuesliSwap, we hope this gentle look under the hood of our exchange will enable you to execute your future trades even more confidently. Perhaps you’re even eager to learn more and delve deep into our whitepaper. To those that so far have hesitated to join the trading party, we’re looking forward to seeing your newly acquired skills put into action on MuesliSwap soon.
To conclude, we would like to recapitulate three points that are of great importance to us, and that are the core features that give MuesliSwap it’s a truly decentralized nature:
- Traders are registering their interest to trade in a decentralized Plutus smart contract. This smart contract is designed such that users’ funds can only be spent as intended, eliminating the need to trust in a third party. This is the beauty of blockchain.
- The task of matching orders is distributed across multiple matchmakers and openly accessible to anyone. Similar to mining rewards on proof-of-work blockchains, by earning rewards for each matched order, community members are incentivized to run a matchmaker. Of course, all matchmakers are bound to the rules defined in the smart contract guaranteeing safety of traders’ funds and fairness in the matchmaking process.
- The MuesliSwap website is only one of potentially many interfaces to interact with the protocol’s smart contract. Any community member can build their own website and enrich the MuesliSwap platform with their unique UI features. Orders placed on different front-ends will still be submitted to the one and only MuesliSwap platform. This guarantees increased liquidity, faster settlement of trades, and hence a more seamless trading experience. With both front-end and matchmaker modularly replaceable, MuesliSwap is in every sense of the word a truly decentralized exchange protocol.
Check our website (ada.muesliswap.com), follow us on Twitter (twitter.com/MuesliSwapTeam), and feel free to inspect our smart contract on our GitHub (github.com/MuesliSwapTeam/muesliswap-cardano-contracts).