Crypto swaps: what they are and how they work
With the emergence of decentralised, or DEX, exchanges in the cryptocurrency space, a new concept appeared — the "token swap." The swap became not just a new phenomenon in the crypto market but also enabled the formation of an independent ecosystem with a wide range of decentralised financial tools.
What is a swap?
A token swap is the process of trading one digital asset for another directly on the blockchain via a smart contract. Unlike using regular exchanges or other online services, a swap happens without go-betweens, through a decentralised exchange or a non-custodial wallet*.
A non-custodial wallet is a way to store cryptocurrency where only you control your money and your keys.
The term "swap" originated in traditional financial markets and entered the cryptocurrency industry. A swap refers to the exchange of one currency for another at a fixed rate. The idea of token swaps was first proposed by developer Tier Nolan back in 2013. However, the term only became widespread in 2017, when Litecoin founder Charlie Lee carried out a successful swap of Bitcoin (BTC) for the altcoin Litecoin (LTC).
Note: initially, blockchain-based exchanges were called "atomic swaps" and used a hashed timelock mechanism (HTLC)*. However, with the emergence of decentralised exchanges based on liquidity pools, the simpler term "swap" began to be used, which differs from an atomic swap in its operating principle.
* Hashed TimeLock Contract (HTLC) is a smart contract for atomic swaps. It locks assets until a specified condition, such as providing a cryptographic hash, is met within a specified time. If not, the funds are returned to the owner, reducing trust requirements.
Different types of token swaps
The first type of token swap, which is called an atomic swap, involves exchanging tokens within a single blockchain. Most often, such exchanges use liquidity pools* on decentralized exchanges such as:
* A liquidity pool is a smart contract on a decentralized exchange that contains token pairs provided by users to ensure continuous asset exchange. Liquidity pools enable swaps without the need for a counterparty at the time of exchange, while liquidity providers (those supplying tokens for exchange) earn income from fees paid by traders.
Most DEXs use an automated market maker (AMM)* mechanism, first implemented by the Uniswap team in 2020. However, classic order-book*-based mechanisms and even hybrid models using AMM can also be found.
* An Automated Market Maker (AMM) is a DEX trading model in which token prices are set by an algorithm based on pool asset balances. This ensures liquidity without order books and reduces reliance on individual users.
* An order book is a list of buy and sell orders with specified prices and volumes. Trades occur when matching orders meet, provided there are enough buyers and sellers present.
AMM protocols such as Uniswap and Balancer use algorithms to form market prices for assets and automate the token swap process. This not only automates transactions but also eliminates counterparty risk.
Token swaps in AMM protocols work as follows:
- To perform a swap, the user selects a trading pair (for example, ETH–USDT) on a DEX and initiates a transaction in their wallet.
- Once the transaction is signed, the user's ETH tokens are transferred from their wallet to the exchange's liquidity pool. Simultaneously, the smart contract withdraws the corresponding USDT from the liquidity pool and sends it to the user's wallet. This entire process is managed automatically by a smart contract, so no third-party involvement is needed except in rare cases of successful attacks on the liquidity pool.
For each swap, the user pays a protocol-defined fee. During exchanges, the price of a particular asset on DEXs may differ from the market price. In such cases, the price difference attracts arbitrage traders*, as a result of which the cryptocurrency price on the DEX eventually aligns with the market price.
* Arbitrage traders profit from price differences in the same asset across platforms, buying low and selling high, thereby helping align prices.
Crypto wallets with swap support work similarly: they use liquidity pools on decentralised exchanges to trade digital assets. In other words, wallets can act as liquidity aggregators in the decentralised finance (DeFi) market, similar to the 1inch platform.
Beyond classic exchanges on DEXs, another significant advancement is cross-chain swapping. This process enables tokens to be transferred or exchanged between different blockchains, further expanding the range of possibilities for crypto users.
Here is an example of how a cross-chain swap works:
- A user needs to convert ETH on the Ethereum blockchain to USDT on the Polygon blockchain.
- When the user initiates the transaction, the smart contract of the cross-chain protocol is activated.
- During the exchange, the smart contract withdraws ETH from the user's wallet and deposits it into a liquidity pool of one of the protocols on the Ethereum blockchain.
- After that, the corresponding amount of USDT tokens is withdrawn from a liquidity pool of one of the protocols on the Polygon network and sent to the user's wallet.
Advantages and risks of token swaps
The first advantage of token swaps is their decentralisation and the absence of dependence on third parties (centralised exchanges) when exchanging digital assets. Decentralised exchanges cannot reject a transaction or block a wallet from withdrawing funds.
Another advantage of swaps is anonymity. Decentralised exchanges and cross-chain protocols do not require identity verification. Additional tools such as cryptocurrency mixers* can further enhance privacy, although they carry risks related to potential transaction blocking in the future.
* Cryptocurrency mixers are services that boost privacy by pooling funds and redistributing them, making transactions harder to trace. They're sometimes scrutinised for ties to illegal activities.
Note: as the DeFi market develops, anonymous token swaps may become increasingly rare, available only to a limited group of users. Some large decentralised exchanges, such as Uniswap, are already implementing KYC and AML mechanisms on their platforms.
Other advantages of swaps include:
- The ability to exchange quickly: to perform a token swap, it is enough to connect a wallet; there is no need to deposit funds on an exchange and withdraw them, which can take time.
- No additional fees are usually associated with deposits and withdrawals.
- Access to virtually any assets. Users can even create liquidity on decentralised exchanges themselves.
- No scam* risks during exchange (except in cases of purchasing fraudulent tokens or trading via fake platforms), since the smart contract guarantees transaction execution.
* A scam is fraudulent activity in crypto that aims to trick users into giving up their assets through fake services, offers, or addresses.
The main risk of token swaps is related to security threats. For example, hackers may exploit a platform's smart contract and steal users' funds. There is also the risk of phishing*. If a user signs a permission for a malicious smart contract, attackers may be able to withdraw assets from the user's wallet.
* Phishing is a fraud that disguises malicious links or smart contracts as real ones to gain unauthorised access to crypto assets.
An additional risk of swaps for users is the low liquidity of certain trading pairs on decentralised exchanges. Because of this, slippage* may occur during exchanges, resulting in the actual buy or sell rate differing significantly from the rate indicated by the exchange.
* Slippage is the difference between the expected exchange price and the actual rate at which the trade is executed. On decentralised exchanges, slippage most often occurs due to low liquidity or sharp price fluctuations, when a large trade significantly changes the asset ratio in a liquidity pool.
In addition, inexperienced users may make mistakes if they are not sufficiently familiar with how decentralised exchanges and wallets work.
