Review of Decentralised Exchanges
This is a review of Decentralised Exchanges (DEX) in January 2023.
Uniswap
It is the largest DEX, with 50% of total DEX trading volume, at January 2023, according to Dune analytics (https://dune.com/hagaetc/dex-metrics).
It uses Automated Market Maker (AMM) architecture. Their github is at https://github.com/Uniswap/v3-core
AMM architecture:
In AMM, the trading uses liquidity pools with any pair of tokens. Token prices are determined by constant product market maker (CPMM) formula
tokenA_value * tokenB_value = K
AMM problems:
- Exposure to additional risk exposure:
AMM requires the supply of two assets in equal ratio. The liquidity providers (LP) takes on additional risk if they want to provide liquidity to the pools.
2. Impermanent loss
AMM relies on the equation of x*y=k to calculate asset prices and re-balance proportions in the liquidity pool. It does not know the real market prices of the tokens. It requires arbitrageurs to facilitate the price discovery process, meaning liquidity providers (LP) are paying arbitrageurs for price discovery.
3. Inefficient fund utilization rate
AMM allocates funds uniformly across the entire price range, meaning that only funds which are allocated near the market price can actually be effectively utilized, while the rest sits idle. This gives rise to high slippage and high capital inefficiency.
1inch
1inch is an exchange aggregator that scans DEX to find lowest crypto prices for traders. It supports limit order and RFQ (request for quotation).
- Limit order: sell token at specified price
- RFQ : customer requests a quote from a supplier (market maker) for the purchase of some tokens
Both type of orders is a data structure created off-chain and signed according to EIP-712. Off-chain order results in lower gas fees.
Their github is at https://github.com/1inch/limit-order-protocol.
Dodo
It is the fifth ranked DEX, at January 2023, according to Dune analytics (https://dune.com/hagaetc/dex-metrics). It uses PMM architecture.
PMM architecture:
Proactive market maker algorithm (PMM) proactively shift the price curve to ensure sufficient liquidity is available.
In PMM, two separate pools are used for a single trading pair of tokens. LP only need to deposit the token they choose (not necessary to deposit token pairs). PMM uses Chainlink to provide decentralised price feeds (no need to use CPMM formula to do price discovery).
Their github is at https://github.com/DODOEX/dodo-smart-contract.
Tokenlon
Tokenlon is a leading DEX powered by 0x protocol. It uses RFQ order matching method. It aggregates liquidity from uniswap, curve, sushiswap, etc.
Tokenlon architecture:
- Tokenlon contract: a transparent upgradable proxy
- UserProxy contract: a multicall contract
According to the figure above, the UserProxy contract will aggregate the orders and send to AMM, PMM or RFQ liquidity pools. Once there are orders matched, matched orders are stored in permanent storage.
Tokenlon usage:
deploy spender contract
deploy tokenlon contract
deploy userProxy contract (user proxy storage, for storing logic contract address )
deploy permanent storage
deploy proxy permanent storage contract (pss storage)
deploy RFQ contract
deploy market maker proxy contract
setup ERC1271 wallet
setup signer, withdrawer of market maker proxy
create RFQ EIP712 order
try to match taker asset with maker asset
settle the order in RFQ.sol in fill and _settle method
Their github is at https://github.com/consenlabs/tokenlon-contracts.
0x protocol:
It aggregates liquidity from makers (uniswap, sushiswap) with takers (metamask). It is gas efficient because of off-chain order relay, and on-chain settlement. 0x does not store orders on chain.
The end.