If you prefer a video version, CEO Julian Hops also made a detailed video:
Swap on a CEX: There is a central order book through which all trades are executed. Buyers and sellers each enter their desired price and when the prices meet, a trade takes place.
Swap on a non-custodial Exchange: Sometimes also with an order book, but others also do it via price oracles like Chainlink. In any case it is not completely decentralized.
Swap on the DeFiChain DEX: DeFiChain, like any real DEX, processes the swapping via so-called liquidity pools.
How liquidity pools work
A DEX allows two features:
- Liquidity Mining
- Decentralized Exchanging/Swapping
1. Liquidity Mining
Liquidity Mining is needed because there is no order book - there is no matching, and no price oracle, as these systems are always centralized and vulnerable.
So a DEX has no way to determine market prices via these channels. It needs something else: Liquidity Mining.
Liquidity mining means that always two trading pairs are fed into the system by independent liquidity miners, for example BTC-DFI.
These liquidity miners, who put money into the system, naturally want something in return: so-called Liquidity Mining Rewards.
These are calculated from the total Liquidity Mining Rewards of the Exchange, which can sometimes amount to more than 1000% APY, especially at the beginning of the DeFiChain DEX.
The second thing Liquidity Miners get is a share of the exchange fees - in the case of the DeFiChain DEX, this is 0.2%.
Let us assume that the fair value in the total market would be about 50,000 DFI for 1 BTC.
And let’s assume that at the beginning of the DEX the liquidity pool is worth 10 BTC & 500,000 DFI, at 1000% APY.
If your share of this is 1 BTC-50,000 DFI, you would get 1.00.000 DFI (1000% APY) return on your investment!
Important: As already mentioned, Liquidity can only be added in pairs. So it is not possible to simply add 1 BTC to the pool - with the numbers from the above example, you would also have to add 50,000 DFI.
2. Decentralized Exchanging/Swapping
The decentralized exhanging/swapping works practically like Liquidity Mining - with the big difference that you don’t have to add a pair, but only one cryptocurrency.
Let’s assume the liquidity pool consists of 10 BTC : 500.000 DFI
If you now want to buy DFI for 1 BTC, you add 1 BTC to the pool and subtract DFI.
Ideally, you will receive the exact price of 50,000 DFI. (Realistically, as with any CEX or non-custodial exchange as well, you would receive a worse exchange rate for such a significant buy order - but we’ll leave that out of this example for simplicity’s sake)
So the pool would optimally look like this after your purchase:
11 BTC : 450.000 DFI
Important: Seen from the outside, the total value in dollars has not changed within the pool. However, if you were to contribute liquidity again, say 10% of the total liquidity pool, the trading pairs would have shifted:
Instead of contributing 1 BTC at 50,000 DFI you would now have to contribute 1.1 BTC : 45,000 DFI, since liquidity mining cannot shift the relative ratio of the trading pair.
The Solution: Since this example shows a kind of imbalance for a short period of time and since you can buy a lot of BTC for comparatively little DFI, there will be arbitrators who want to buy this BTC immediately “at a discount” and add DFI to withdraw BTC from the DEX. (in order to sell them on a CEX with immediate profit, for example)
In the long term, the ratio thus automatically balances itself out and always adapts to the real, independently determined value of the free market.
That sounds very simple. What are the risks?
There are 3 different kinds of risks with a DEX.
1. Smart Contract
There is of course always the risk that there is some bug in the code of the Smart Contract that can be exploited. With DeFiChain, this risk is generally low (and much lower than with Ethereum), since the blockchain is non-turing-complete already and there are much fewer potential errors.
2. Project Risk
Are there any backdoors? Is the project independently audited? Is it open source? In general, everything is fine here for most large projects, because for example Uniswap and also DeFiChain are open source, everyone can check and verify the code themselves and the projects also regularly contract external security audits.
3. Impermanent Loss
The third and most complicated risk is that of an impermanent loss. This is explained in detail in the next part of this DEX explanation series. In short, the risk is that the pool shifts in such a way and the prices of BTC and DFI, for example, also develop in such a way that if you were to withdraw your liquidity from the pool now, you would make a loss. Because of the arbitrage already mentioned, however, this always balances out in the long term and this risk is only a temporary, short-term one.