In the previous posts of the 0xcert DEX Series, we explored identities in crypto assets and two ways of trading with them. After two use cases, the Academia and Cryptocollectibles, we are focusing back on the decentralized exchange and its mechanisms.
Peer-to-peer trading without central management is a promising goal, but how to achieve the level of trust that both parties need to comply with for such trade? They could do an agreement to barter their assets, but would this make it certain that they both get what they should, based on their deal? This is of special importance when there is no middleman that would provide a trust element, a certain level of guarantee, and liability in case of disagreements between the parties.
Here is where atomic swap comes in. In this episode of the DEX Series, we will explore how atomic swaps enable effective, trustless and decentralized trading between both parts of the trading equation.
What is at stake
In the previous DEX Series posts, we have mentioned bartering of assets as a way of cutting the need for having a common asset enabling the trade. Also, the whole point of a decentralized way of exchange – as its name suggests – is its abolition of a third-party middleman or authority providing the platform and terms of an exchange.
In any trade, at least four elements are involved:
- Trader #1 (source or destination of traded assets),
- Traded asset(s) #1,
- Trader #2 (destination or source of traded assets),
- Traded asset(s) #2.
Apart from the stakeholders and values of assets, it is also essential to understand the process in which a trade is executed, since it could lead to unfavorable tournouts:
a) If Trader #1 does not stick to the agreement, Trader 2 risks losing their assets, and vice versa.
b) If any of the traded assets don’t reach their destination, at least one party risks ending up empty-handed, while the other could find themselves better off than they should.
Therefore, for such barter trade to be executed in a fair way and for the benefit of both/all the traders involved, it would need to ensure the following elements:
- Decentralized way of exchanging the assets: trading 1-on-1,
- Safety of assets: leaving them in the hands of their owners,
- Power to the traders: trading process set up on mutual agreement,
- Successful completion of the agreement for both sides: either win-win or no win,
- Inscribing/recording the deal and trading process: verifiable procedure,
- Automatization of trading process: minimal or no human intervention or manipulation,
- Low risk of hacks: no exposure to third parties.
In blockchain tech, smart contracts have become a common mechanism for one-way transactions from sender to receiver of assets. However, for a transaction to go in both directions and to do so instantaneously, a specific type of smart contract technique is used, known as atomic swap.
Swapping in decentralized fashion
Atomic swap uses a particular type of smart contract technique to enable a trustless exchange of different crypto assets between two (or more) parties. Such a swap is done directly among traders and with zero default risk for either of them.
In contrast to centralized exchanges which use the central platform to provide trading on their own terms and for a certain fee, atomic swaps do not require a third party or escrow to serve as a center of the exchange. Therefore they are predominantly used on decentralized exchanges.
Instead of traders having to deposit their assets on centralized exchanges and thus losing ownership over them until their withdrawal, atomic swaps allow the assets to remain in traders’ wallets, protected by their private keys. This gives a trader a complete control over their assets, which reduces the risk of attacks that could occur otherwise on middle points of access.
Smart contract technology provides automatization to ensure that a certain agreement between both parties is reached. There are only two possible endpoints for an atomic swap: either
a) a successful completion of a trade for both parties or
b) an abolition of the process and returning to the starting point if the smart contract encounters issues in its settlement.
There is no middle ground for an atomic swap outcome which reduces the possibility of one party taking unfair advantage over the other.
A fixed sequence of required steps and conditions is secured by cryptography embedded in the atomic swap smart contract. Once all steps are completed, the swap is confirmed and successfully settled. If not, the atomic swap process is abolished and canceled, with no damage to the assets that were subject to swap.
While the trade agreement is created in an off-chain environment between trading parties, the settlement of the trade done by atomic swap, however, is performed entirely on blockchain. This makes every single step of the operation trackable and verifiable.
The steps are completed and advanced automatically. A new step can start only once the previous one is done in its entirety. And only once the final condition is achieved and confirmed, the atomic swap as a whole can be settled, no sooner and in no other way.
This immutability has contributed to the name of this asset bartering mechanism. Atomic swaps are indivisible and can provide results in only one of the two possible ways.
Atomic alternative to centralized exchanges
Atomic nature of swaps successfully reduces the issues that are common to centralized exchanges, namely hackability and fees.
Eliminating the central point of managing assets significantly reduces the potentials of hacking risks. By trading peer-to-peer or wallet-to-wallet, traders don’t have to hand their assets over to the hands of an exchange platform. Private keys remain traders’ secret throughout the entire atomic swap, too, meaning their assets are safe from third party hacking.
Having no central trading platform also brings a potential reduction of costs and fees incurred in the trade. Instead of traders having to pay trading fees and even withdrawal fees to the middleman on centralized exchanges, atomic swap usually comes off at a lower cost, as the process deducts only the fee that supports operations on the network.
Atomic NFT future?
In several ways, atomic swap allows for a more sovereign role of traders in managing ownership of their own assets. Since it is still a relatively new mechanism of trading assets in a safe and decentralized way, it has yet to undergo some refinement and testing, as well as become more approachable for the general non-tech audience adoption. Nevertheless, atomic swaps represent currently the safest and most decentralized mechanism for exchanging assets in a bartering manner.
Atomic swapping also allows for trading with a more diverse and large number of crypto coins and tokens. After the early-stage atomic swaps between few top cryptocurrencies, they are now gaining momentum also on a broader spectrum of crypto assets. We expect to see NFTs as the next crypto asset segment to be widely applied to atomic swapping, and our Swapmarket is one of its starting points.
Non-fungible tokens (NFTs), especially crypto-cryptocollectibles, are specific for its range of varieties and special features. Since each of them is a unique and unrepeatable asset, the barter of one NFT for another naturally lacks a common monetary exchange asset. Instead of having to own a certain cryptocurrency as a shared ground for a trade, NFT holders can interchange their non-fungible goods directly with atomic swap.
In more ways than one, this decentralized technique of swapping assets therefore represents a substantial advancement of safety and management of cryptocollectibles, while providing their owners with complete control and minimal risk. This can lead to less trust issues and consequently higher adoption among traditional collectors.