Why use DEXes?

primex.finance
primex.finance
Published in
8 min readJul 2, 2021

--

Decentralized exchanges carry out an exchange that operates directly on a blockchain and do not need a centralized third party to govern it all. They appeared later than the centralized ones; however, they have become very popular now and work in parallel with centralized exchanges, competing with the latter in some aspects.

DEXes offer the core functions of a CEX:

  • a trading venue;
  • a matching system (CEX uses order book and DEX uses order book or automated market maker);

however, with some differences: all these functions are decentralized.

Decentralized exchanges offer solutions to the most significant weaknesses of CEX — such as the influence of third parties, inadequate security, or lack of anonymity. A DEX acts as a decentralized application on a blockchain. The advantage here is that users can trade immediately and control their private keys at all times. There is no KYC and no personal documents uploaded.

DEXes provide trading with numerous trading pairs: listing on centralized exchanges is quite tricky, while everyone can create a liquidity pool on DEX. The risk of attack or server failures is minimized here. The danger and problem of DEXes are possible vulnerabilities in smart contracts. However, the fact that the code is open and available on the Internet allows quickly identifying and eliminating those vulnerabilities.

This article provides an overview of three widely used DEXes now: Uniswap, 1inch, and Balancer. Fundamentally different DEXes were chosen because there is no need to review those that work similarly to Uniswap.

Uniswap

Uniswap is an automated liquidity protocol that allows the direct exchange of tokens without the need to use a centralized intermediary. It is launched on the basis of Ethereum smart contracts.

Uniswap liquidity pools use a constant product market maker algorithm: the product of the amounts of the 2 supplied tokens before and after a swap stays the same. One token will be exchanged for the other as long as this formula is preserved. It means that trades must not change the product of a pair’s reserve balances.

These pools are working thanks to liquidity providers. Anyone who is able to supply a pair of ERC-20 tokens to an Uniswap exchange contract can become a liquidity provider. Every LP receives special LP tokens when they supply liquidity to a pool (according to the proportion of liquidity they have supplied to the pool). A 0.3% fee is proportionally distributed among all liquidity providers. LP must burn their tokens to get their liquidity back, plus any accrued fees.

The constant product formula ensures that a pool can always provide liquidity, despite the size of a trade. It works because the algorithm asymptotically increases the token price as the desired quantity begins to grow.

The main conclusion of the basics of liquidity pool work: the ratio of the tokens in the pool determines what the price will be.

Also, there is impermanent or divergence loss present. This loss only occurs when the liquidity provider withdraws their liquidity and is based on the price difference between deposit and withdrawal. If the price returns to the same value as when the liquidity provider added their liquidity, this loss will disappear.

There are three different versions of Uniswap now. (although version 1 is still functional, it is no longer under active development).

In Uniswap v1 only swap between ETH and a single ERC20 token is available. Uniswap V2 allows direct swaps between ERC20. At the same time, for consistency, it works with WETH, not just ETH. In addition to this, in Uniswap V2, a user can withdraw any amount of any ERC20 token at no upfront cost. It is called a flash swap. The background for this includes any of the following options:

1) Pay for the entire withdrawal of tokens;

2) Pay partially for the ERC20 tokens and return the rest;

3) Return all the ERC20 tokens withdrawn.

Version 3 provides new features that make Uniswap v3 the most flexible and efficient automated market maker ever designed: concentrated liquidity, giving individual liquidity providers control over what price ranges their capital is allocated to; Multiple fee tiers, allowing LPs to be appropriately compensated for taking on varying degrees of risk. Also, there is a new layer 2 in this version of Uniswap, which aims to reduce fees and speed up transactions.

1inch

1inch — a decentralized exchange aggregator that sources liquidity and pricing from different exchanges into one platform and is capable of splitting a single trade transaction across multiple DEXs to minimize slippage and provide the best pricing possible.

It has released its own automated market maker protocol, Mooniswap, that utilizes virtual balances to provide liquidity providers with more profit than any other AMM.

Mooniswap keeps most of the slippage revenue in the pool by maintaining virtual balances for different swap directions.

When a swap happens, a market maker does not automatically apply the invariant algorithm but displays relevant prices for upcoming trades. The AMM improves exchange rates for arbitrage traders over approximately a 5-minute time period. As a result, they will be able to collect only a portion of slippage, while the rest will remain in the pool shared among liquidity providers.

High competition among arbitrageurs prevents them from waiting for the price that will maximize their profit. Such delay in price updates forces arbitrageurs to perform trades at less profitable prices, adding value to the liquidity providers.

The key issues that 1inch solves:

  • low and fragmented liquidity problem that leads to slippage and bad pricing for trades. 1inch reduces the issues of relying on a single exchange for liquidity by splitting orders among different exchanges. At the same time, it keeps the trade within one transaction;
  • saves on transaction fees by utilizing GasToken, a token that stabilizes the price of gas.

The key takeaway: 1inch’s algorithm finds the cheapest way to place the trade using all the possible exchanges and liquidity protocols to facilitate this trade.

Balancer

Balancer is a protocol for multi-token automated market-making. Balancer Pools contain two or more tokens. Each token has an independent weight that shows its proportion of the total value in the pool. Pools are automated market-makers, since anyone can swap any two tokens in any pool.

The central concept of Balancer: instead of paying fees to portfolio managers to rebalance financial portfolios, users (liquidity providers) collect the fees from traders. Traders automatically rebalance users’ portfolios because of arbitrage opportunities. So, there are two types of users who benefit from the Balancer Protocol: liquidity providers because they own Balancer Pools or participate in such shared pools and, as a result, have advantages in the form of portfolio rebalancing and commissions and traders because they buy or sell the underlying pool assets on the open market.

Balancer Pool is the fundamental block of the Balancer Protocol. Pools are smart contracts that implement the Balancer Protocol. Two or more ERC20 tokens are held in every contract.

There are three types of Balancer pools :

  1. Shared pools. These pools have fixed parameters. They cannot be changed by the user who created the pool and are more suitable for general use since they allow users to provide liquidity and profit as they see fit.
  2. Private pools. These pools are very flexible: tokens can be easily added or removed here, their weights can be changed, and so on. But, of course, the user who owns this pool can easily use the system to get profit from other liquidity providers. Consequently, only the creator can provide liquidity for this type of pool.
  3. Smart pools. They are like a private pool, where a smart contract controls any arbitrary logic connected to the changing of pool parameters.

Balancer pools charge a percentage of the input amount traded for each trade. This charged fee goes to the Balancer Pool liquidity providers. V2 Balancer has three kinds of protocol fees: a swap fee, a withdrawal fee and a flash loan fee.

The main innovation introduced by the Balancer Protocol is a multi-dimensional invariant function. It is used to continuously define swap prices between any two tokens in a pool. It is an n-dimensional generalization of Uniswap’s x * y = k formula:

, where

— ranges over the tokens in the pool;

— is the balance of the token in the pool;

— is the normalized weight of the token, such that the sum of all normalized weights is 1.

In the DEXes described above, traders are limited by the amount of liquidity they have and can’t trade with leverage. Several DEXes provide margin trading capabilities but trades are limited with the pools of these DEXes. Primex credit buckets are an intermediary between traders and DEXes that provides additional liquidity for trades, leaving the logic of exchange operations the same. They assure higher interest rates and more precise risk control for lenders and benefits for traders: underdeposited cross-margin trading and the possibility to increase profits by leveraging liquidity from Primex credit buckets.

In order to simplify the user experience for traders and avoid rebuilding interfaces, we plan to allow traders to access liquidity from buckets directly via DEX interfaces.

We are developing specific contracts that control the liquidity borrowed by traders. The rules of such liquidity’s usage will be strictly defined. All interactions with DEXes will be performed through such contracts. Also, are developing a wallet that interacts with the DEXes interfaces and allows users to avoid direct transactions to a DEX by just making calls to such “trader-proxy” smart contracts.

Algorithm for such wallet’s work:

  • For a trader to employ liquidity from a pool, a special “trader-proxy” smart contract is deployed, which holds the liquidity available for the trader and controls the use of this liquidity;
  • The trader’s keys and addresses of the appropriate contracts will be held in the wallet;
  • When the trader interacts with the DEX’s UI, they connect the wallet;
  • When the trader initiates an exchange on the DEX UI, the DEX frontend sends a request to the wallet to sign a transaction;
  • Our wallet will modify the incoming request, replacing the direct transaction from the user to the exchange with a transaction to the “trader-proxy” contract, which will deploy liquidity from the bucket to the DEX contract to execute the trade.

In this way, the trader need only interact directly with DEXes’ interfaces, leaving their Primex wallet in the background.

In addition to this, Primex will also use the pool model to minimize the number of transactions between traders and associated blockchain transaction fees.

Summing up the above, it can be said without a doubt that DEXes offer plenty of benefits for users compared to CEXes, while the algorithm that Primex proposes is a useful tool for traders who work with DEXes as they can increase their profits by leveraging liquidity that is provided by credit buckets. In addition to this, lenders can benefit from higher interest rates and risk diversification as opposed to regular pools. Also, Primex provides a simple user experience for interactions between traders and DEXes.

--

--