ErgoDEX: A Decentralized Interoperable Exchange – Part II

ErgoDEX is a decentralized cross-chain exchange. The eUTXO model gives a unique possibility to have shared liquidity among different types of exchanges on top of Ergo and Cardano ecosystems.

In a previous article I explained about the Ergo blockchain, its relationship with Cardano, and about the general topics of ErgoDEX. Now I am going to explain the structure of the DEX.

In traditional and centralized finance, the act of exchange is facilitated by a trusted third party, such as a market maker, stockbroker, or other intermediary. For this, order books are used, in which the buy and sell orders are paired. This is how traditional stock markets operate, and this is how centralized exchanges (CEX) operate, in the crypto industry.

The act of exchange without trusted parties is one of the most basic characteristics necessary for decentralized finance (DeFi) on blockchain. Instead of trusted intermediaries, a decentralized exchange (DEX) works using trusted smart contracts. 

Many of the features of centralized order book exchanges (such as partial orders, buyback guarantees, etc.) have been successfully implemented in smart contracts. In smart contracts, these features are usually composable. Composable elements in smart contracts are good for traders because they make them easier to understand and use.

In DeFi, there are two types of decentralized exchanges (DEX):

  1. order-book, similar to traditional financial exchanges, and 
  2. Automated Market Maker (AMM). 

The AMM protocol uses mathematical models to set the price and match buyers and sellers, instead of simply matching buy and sell orders, as in traditional order-books. 

One of the characteristics of the AMM protocol is that liquidity providers add assets to the exchange in exchange for a commission, and the market benefits from increased liquidity, with lower latency, limited price slippage, and a lower market volatility by utilizing this additional liquidity. 

One of the unique features of Ergo and Cardano is that, thanks to the eUTXO ledger model they use, the liquidity pool contracts for AMM DEXs can be combined with the order contracts used in the order book DEXs. This ability allows liquidity to be shared between different types of exchanges on the Ergo and Cardano blockchains.

Protocol Architecture

The DEX works with Order-book or with AMM (Automated Market Maker). 

The Order-book has the advantage of working better for those pairs with high liquidity and the AMM protocol is better suited for pairs with little liquidity.


The Dex manages an order book to represent liquidity and determine prices. Orders are waiting for other orders to be matched, or awaiting cancellation. 

There are the following three types of orders: 

  • buy, to buy tokens for the native asset,
  • for sale, to sell tokens for the native asset, or 
  • exchange, to buy tokens with other tokens.

There are atomic orders, which can only be executed in their entirety and, otherwise, they are reimbursed. Said orders can be added by the ErgoDEX client so that users can choose between them, or they can coincide in a book with the partial orders, defined below.

Partial orders are somewhat more familiar to those who have ever used the classic centralized exchanges (CEX). These orders can be partially executed, without having to coincide with the total ordered for the operation, so the best way to work with them is an order book, where they can be added and executed by the ErgoDEX bots.


This protocol uses an automated market making mechanism (AMM) to provide instant information on rates and slippage. 

Each AMM liquidity pool is a trading venue for a pair of assets. In order for operations to be carried out, the liquidity pool accepts deposits of underlying assets proportional to their prices. 

Each time a deposit occurs, a proportional number of unique tokens known as liquidity tokens are minted. The minted liquidity tokens are distributed among liquidity providers in proportion to their deposits. Liquidity providers can subsequently exchange their quota of liquidity tokens for a proportional amount of underlying reserves.

Classic AMM pools are based on Constant Function Market Makers (CFMM) with a constant product formula, which is x * y = c, where x and y are the amount of deposits in X and Y tokens, respectively, and c is your product, which must remain constant after exchange operations. CFMMs provide liquidity across the entire price range.

Concentrated Liquidity Pools (AMM)

CFMMs liquidity is distributed evenly along the reserve curve, which is slightly inefficient, since much of the reserves held in a pool are never used. 

Instead, concentrated AMMs allow LPs (Liquidity Providers) to provide liquidity at smaller price ranges. 

Each pair for the token exchange is made up of smaller pools, each of which corresponds to some price range. 

The team has named this model Concentrated Liquidity Pool (CLP). 

A CLP only needs to maintain enough reserves to support trading within its range, and thus it can act as a constant product pool, with larger reserves (which they call virtual reserves) within that range. 

At the same time, LPs are not tied to a specific CLP and price range, and can provide liquidity to multiple adjacent CLPs, thus forming what they call a position. As long as the price of an asset is within the price range of a position, you are earning protocol fees. When the price breaks out of the position’s price range, its liquidity stops earning commissions because it is no longer active.

Economics of Ergo AMM DEX

There are three types of economic agents in an AMM DEX ecosystem:

  • DEXes (Parties which run DEX bots and UI)
  • Liquidity providers (LPs)
  • Traders

Each agent type benefits from using DEX in their own way

  • DEXes are earning fees from traders’ swaps in ERGs
  • LPs benefit from protocol fees paid in tokens and accumulated in liquidity pools
  • Traders benefit from DEX services they use

Off-chain Execution

For the sake of efficiency, most DEX actions fall into two stages: 

  1. creation of the order
  2. execution

Once an order is sent to the network, it can be executed by bots outside the chain. The off-chain bot is a piece of software that tracks orders and makes all the necessary state transitions. 

The legitimacy of all transitions is checked on the chain using validation scripts. 

The off-chain bot can be executed by anyone who is willing to support ErgoDEX, and earn execution commissions.

The Platform 

Currently, the application ErgoDEX can be used with the Yoroi Nightly Connector. Users can exchange and provide liquidity for ERG, SigRSV, SigUSD, Erdoge and Kushti. 

The new version of Yoroi will soon allow users to use ErgoDEX directly, and the Ergo team is working in collaboration with the EMURGO team to launch the wallet. 

Use Google Chrome, Brave or Sidekick browser to interact with ErgoDEX. Do not use Safari or Mozilla Firefox, because there are no wallet extensions.

  1. In order to start using ErgoDEX you need to install the following two Google Chrome extensions: Yoroi Nightly and Yoroi-Ergo dApp Connector Nightly
  2. Create new ERG wallet using Yoroi Nightly
  3. Send a small amount of ERGs (1-2 ERGs) to your Yoroi Nightly wallet address. For this step use or withdraw ERGs from your exchange account
  4. You are now ready to use ErgoDEX

The platform is open source, and is published in a Github repository: Automated Decentralized Exchange

1 comment
Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts