Komodo’s Challenges with Creating the BarterDex Exchange

When a user on the decentralized exchange BarterDex posts a trade offer, the protocol does not do a recount of the funds that the user has in his or her wallets. Instead, the protocol of the exchange looks for the largest UTXO that is smaller than the trade that the user wants to make. The protocol treats the UTXOs as a proof-of-funds just like the Bitcoin network treats UTXOs as unspent funds. Using UTXOs allows cryptocurrency networks operate more efficiently and quickly because instead of recounts they can just use the UTXOs to determine if a transaction can happen or not.

Here’s an example of how this works on BarterDex: let’s say a user has 50 KMD (Komodo Coins) and they consist of three UTXOs: UTXO #1, 25 KMD, UTXO #2, 20 KMD, UTXO #3, 5 KMD. Let’s also say that the user wants to exchange 15 KMD into Monaize cryptocurrency, MNZ. BarterDex will not do anything to the UTXOs that the user has. It will simply look for a UTXO that is smaller than 15 KMD, which in this case is UTXO #3 of 5 KMD. It would then calculate the fee and also withdraw it from the wallet. Management of UTXOs is up to the users of the decentralized exchange. BarterDex only operates with existing UTXOs.

Another challenge and goal of any decentralized exchange is to provide both parties in a trade with incentives to complete the trade. This is something that most users won’t even think about when trading on a centralized exchange, because a centralized exchange can introduce and enforce a lot of requirements on users. For example, users may need to provide identification that the exchange employees would check. Then, users may need to transfer funds from their cryptocurrency wallets into their exchange accounts, so that the exchange can use internal vouchers for trading between users.

All of this is much harder to accomplish on a decentralized platform, because such a platform by definition can’t have employees or accounts where users can send funds. For this reason, Komodo developers looked at the trading process and for each step of the process, they have created incentives to complete the step and disincentives that users would have to deal with if they were to abandon a transaction when it is not finished. With such a structure in place, if a transaction goes through, everyone is happy. A seller sold coins and buyer bought coins. However, even if a transaction doesn’t go through, participants of the transaction still are responsible for their actions. If a  party that has misbehaved or didn’t complete the transaction pays a disincentive, the disincentive becomes a reward for the party that has behaved properly. This structure creates a foundation for a decentralized trustless exchange.

Finally, it is important to understand that while a network may be decentralized and have no central point, computers still execute code in a linear fashion, which means that step two comes after step one. One of the biggest accomplishments of the way the Bitcoin network implemented the blockchain technology was ordering transactions and sealing them in the blocks of blockchain with a proof-of-work algorithm in a way that makes the network tamper-proof.

In practical terms applied to a decentralized exchange, all of this means that money can’t leave a wallet and arrive at another wallet at the same time. While the period of time can be very small, it has to be a part of the process because first someone sends the money, the network processes the request, and only then the receiving party received the money in its wallet. The BarterDex decentralized exchange protects the users by implementing an atomic-swap protocol.