April 28, 2023
Written By Ankit Singh
A decentralized exchange (DEX) is a platform that allows people to buy and sell cryptocurrencies directly with each other, without needing to go through a middleman like a bank or a centralized exchange. Instead, DEXs use smart contracts and decentralized ledger technology to ensure secure and transparent transactions. Because DEXs eliminate the need for intermediaries, they provide users with greater privacy, autonomy, and control over their funds. DEXs are considered more secure and transparent than centralized exchanges, which are more vulnerable to hacks and cyber attacks.
But How DEX actually works?
In blockchain space, users hold their own private keys and trade directly with other users through a programmed interface. The executable program on a blockchain is known as Smart Contract. These contracts can automatically manage the exchange process, ensuring that both parties receive the correct amount of cryptocurrency in the transaction.
Below are some important concepts of DEX:
- Liquidity Pool
A liquidity pool is a pool of tokens that are held by a decentralized exchange (DEX) and used to facilitate trades on the platform. Think of the Liquidity pool as two tokens of the same amount deposited on the protocols. These tokens can be exchanged for one another by the users. Users that contribute to the pools are known as liquidity providers and in exchange for providing liquidity, liquidity providers earn a portion of the transaction fees charged by the DEX.
A fee is a small percentage of a transaction that is charged by a decentralized exchange (DEX) for facilitating trades on the platform. These fees are typically used to incentivize liquidity providers and to pay for the costs associated with running the DEX. Fees vary depending on the DEX and can range from less than 0.1% to several per cent per trade.
A swap is the process of exchanging one token for another on a decentralized exchange (DEX). Swaps are facilitated by liquidity pools, which hold the tokens being traded. When a user wants to swap one token for another, they send the first token to the liquidity pool and receive the second token in return. The swap price is determined by the ratio of tokens in the liquidity pool, which changes as tokens are added or removed from the pool. The swap price is always based on the current market price of the tokens, and the user is charged a fee for the trade.
Decentralized exchanges (DEXs) offer incentives for users who provide liquidity to their liquidity pools. These incentives can come in the form of earning additional tokens or a percentage of the transaction fees generated by the Liquidity Pool. Or the liquidity providers get pool tokens of the specific protocol.
DEX Advantages over Centralised Exchanges
Decentralization: DEXs operate on a decentralized network that is not controlled by a single entity. This eliminates the need for users to trust a centralized exchange with their funds, as users maintain full control over their private keys. As a result, DEXs offer increased security and reduce the risk of hacks and theft.
Privacy and Anonymity: DEXs offer greater privacy and anonymity for users compared to centralized exchanges. Users can trade without having to provide personal information, which protects their identity and reduces the risk of identity theft.
Transparency: Transactions on a DEX are recorded on a public ledger, providing increased transparency and making it difficult for bad actors to engage in fraudulent activities.
User Control: In a DEX, users hold their private keys, which gives them complete ownership of their assets. This is in contrast to centralized exchanges, where users must trust the exchange to hold their funds on their behalf.
Interoperability: DEXs are built on blockchain technology, which allows for enhanced interoperability between different blockchain projects. This means that users can trade a wide variety of cryptocurrencies without having to leave the DEX platform.
Unlike banks, users can earn rewards directly in the form of pool rewards by providing liquidity to the protocol. Users can let their tokens earn by providing liquidity and withdraw tokens at any time.
Our platform facilitates the exchange of cryptocurrencies across multiple blockchain networks including Ethereum, BNB Chain, Polygon, Avalanche, Arbitrum, and Optimism, through an API. We have integrated various Decentralised Exchanges (DEX) such as Uniswap, SushiSwap, PancakeSwap, TraderJoe, QuickSwap, Velodrome, VVS, OKCSwap, KuSwap and Swappi(Conflux Network).
We also support non-custodial wallets, including EOA wallets like Metamask, WalletConnect, Crypto.com, OKX Wallet, KuCoin Wallet and Fluent Wallet.
The developer dashboard offers transaction logging and monitoring of user activity. We offer API key management with specific permission controls.
- Using ThirdFi, developers can standardise the integration process for multiple protocols from multiple blockchains with a single codebase.
Currently supported Protocols
We have already built our Swap and Liquidity session API for swapping and providing liquidity. You can get the supported token by calling the “List of supported tokens” API and “List of Supported Pool” API.
With ThirdFi, developers can customize the user experience and the API parameters. The user can be redirected to a different site based on a successful transaction or if the user cancels the transaction.
The user can swap tokens by connecting their wallet and specific network chain. Swapping requires two tokens to be present in the user’s wallet and some native(for eg: ETH for swapping on Ethereum) assets for the gas fee.
2. Liquidity Session Provider
We use Liquidity pools of Decentralised Exchange to provide a simple interface to both developers and users.
- Users can contribute to liquidity pools by calling a simple API on ThirdFi. We create a liquidity session based on the API request.
Check out the API reference here.
There are two types of Liquidity sessions, one is Single Asset Liquidity session and a Dual Asset Liquidity session.
Single Asset liquidity
It provides a simple and straightforward option for liquidity provision. Involves providing liquidity with a single token asset. It reduces the need for managing multiple assets
Offers an excellent choice for users who want to earn rewards without investing excessive time or effort in managing their liquidity
Dual Asset liquidity
Dual Asset liquidity provides a more advanced option for liquidity provision. It involves providing liquidity using two different token assets
Offers greater control over liquidity management and customization of the liquidity strategy. It enables users to optimize their liquidity strategy and maximize rewards.
How ThirdFi Handles the Transactions
The flow is very simple, a user will request a session(can be a swap session or liquidity session) from the app or directly from ThirdFi. ThirdFi will create a new webview session and send a response back to the API call.
The user can use the session for the transaction purpose and ThirdFi will interact with the blockchain network and get the transaction done. After a successful transaction, ThirFi will return transaction data back to the developers and developers can redirect the user to the confirmation page.
ThirdFi also sends a webhook whenever a transaction is successful so that developers can customize the user experience based on the transaction event type.
Below is the sequence diagram for the same:
What can be built 👀
Automated trading bots: Developers can use the platform to access DeFi protocols for trading cryptocurrencies and create automated trading bots that execute trades based on predefined rules and algorithms.
Exchanges: Developers can use the platform to access decentralized exchange (DEX) protocols and build dApps that enable users to trade digital assets without relying on centralized exchanges.
Liquidity provision: Developers can use the platform to access liquidity protocols and provide liquidity to DeFi protocols.
Price feeds: The platform can be used to provide access to decentralized price feed protocols, which provide accurate and up-to-date information on the prices of digital assets. Developers can ensure that the prices used for trading are fair and accurate.