On-Chain Order Books 101: Econia, Injective, Sei + More
Table of Contents
Rounding up the CLOBs you need to know
Central Limit Order Books (CLOBs) are one of the biggest innovations in decentralized trading. They connect buyers and sellers on a DEX, enabling limit orders and other advantages of the CEX trading experience while keeping it trustless.
Our partner Econia Labs has built such an order book on Aptos, and it now powers our Gator trading interface. So let’s break down what an on-chain order book is, how it works, and what other blockchain CLOBs you need to know about.
What is an order book?
An order book is a list of limit buy orders (bids) and sell orders (asks) for a traded asset, such as a security or cryptocurrency. Buy orders are listed in green, while sell orders are in red. Instead of listing each order individually, an order book lumps all the orders placed at the same price together and shows the cumulative quantity.
Limit orders are bids and asks that specify a certain price; for instance, if bitcoin is trading at $43,000, one might place a limit order to purchase a certain amount if the price falls to $41,000. Sometimes you’ll see an order book called a CLOB (Central Limit Order Book).
Limit orders exist in contrast to market orders, which buy or sell an asset as soon as possible at the current price. Order books are necessary for limit orders, as bids often must be held for some time until an ask of corresponding price and size is made, or vice versa. For swing traders, the wait can take months!
The “top of the book” contains the lowest bids and highest asks, which will be filled first. The “spread” is the difference between those figures, while the average current market price is displayed in the middle. For example, in this APT/USDT order book on Pontem’s Gator platform there are 2,194.487 APT offered at the price of 9.237 USDT.
These limit orders are used to fill market orders - always at the best available price. Once the supply at a certain price level (tick) is exhausted, the price moves to the next tick. This is called slippage. You’ll see the numbers on an order book move really fast as the price slips between ticks.
In our example, if someone places a huge market buy order for 2,500 APT, it will be filled as follows:
- 2,194.487 APT at 9.237;
- 133.645 APT at 9.244;
- the remaining 171.868 APT at 9.248.
An order book is a key feature of any centralized exchange. In fact, keeping track of the open bids and asks to match buyers and sellers is the most essential function of an exchange.
Order books are also a useful source of information. For example, you can gauge buy or sell pressure on an asset. Or you can look for large order volumes to identify potential support and resistance levels.
See the 29,842 APT worth of sell orders at 10.802 on the screenshot? The order book is very thin in between 9.6 USDT and 10.802, so once the price goes beyond 9.6, it could plough through very quickly to hit resistance at 10.802, which can absorb a lot of buys - act as a sell wall, as they say.
Why put an order book on the blockchain?
Regular DEXes (AMMs, or Automated Market Makers) don’t have order books; instead, they use liquidity pools. The advantage of a pool is that any order can be filled - though the price can slip a lot in the process if there isn’t much liquidity. See our detailed article on those here.
Also, pools are permissionless, transparent, and non-custodial, with the price of each swap determined by a formula depending on the current liquidity in the pool.
The problem with liquidity pools is that they don’t support limit orders. Either you swap at the current price or you come back later when the price reaches your desired level.
Can you put a CLOB on-chain? Turns out that you can: you may see such implementations called “settlement engines” or “matching engines,” referring to the function of an order book which pairs bids and asks.
Howevert you need a blockchain with the following characteristics:
- High throughput - because orders should be matched almost in real time and the CLOB needs to be updated immediately. Even worse, a slow CLOB would open up huge opportunities for front-running orders.
- Low fees - because each matching, if done on-chain, incurs gas fees.
In short, you need a blockchain like Aptos or Solana. You can’t build a good CLOB on a slow and expensive chain like Ethereum.
Advantages of on-chain CLOBs
In Econia’s view, on-chain order books combine “the benefits of CEXs (efficient price discovery and minimal slippage) with the strengths of DEXs (decentralization, permissionless, and user custody of assets).”
CLOB vs a CEX order book
- Trustlessness. The CLOB and matching function can be operated without interference by a centralized party. On-chain order books prevent the possibility of backdoors, emergency controls, or privileging certain customers, which could exist on centralized exchanges.
- Use of non-custodial wallets. Users can trade from a non-custodial wallet like MetaMask or Pontem Wallet, without entrusting their money to the exchange. Not your keys, not your crypto, remember?
- Resistance to future centralization. Putting the order book on the blockchain means a decentralized exchange stays truly decentralized; even a single centralized element introduces an opportunity for exploits. This is especially crucial for the matching engine, which could eliminate the fairness of an exchange if used improperly. Plus, order books are ledgers of past transactions, a role which blockchains are naturally suited for.
CLOB vs a DEX liquidity pool
- Limit orders. You don’t have to monitor the price all the time: when it hits your desired level, the order will be filled. Of course, you can also place a market order if you’d rather buy the tokens at the current price.
- Efficiency for liquidity providers. When you place a limit order in a CLOB, you act as a liquidity provider - and you choose the price and the token. On an AMM, users are forced to provide liquidity to both sides (i.e. in both tokens) and along the whole price range (unless it’s a concentrated liquidity DEX).
- Lower slippage and liquidity requirements. If an AMM pool has low liquidity, a single large order can move the price by a lot. Often inexperienced DEX users approve swaps without checking the price impact and liquidity first - only to find that their swap was executed at the price that is 20% or 50% higher or lower than the real market price.
For example, here swapping 1 ETH ($2,237) would give you just 0.0045 worth of BTC ($200) - because there is almost nothing in the pool and because that’s how the liquidity formula works.
CLOBs don’t have this problem: a limit order will be filled at the specified price. If there isn’t enough liquidity at that level, it will fill partially - but you’ll get the price you wanted.
CLOB design principles and challenges
There are several parts to a CLOB DEX:
- Order book: the list of open orders and token prices;
- Matching engine: the mechanism that matches incoming market orders with open limit orders;
- Settlement: filling the orders and updating account balances.
Of these three, the last one really needs to happen on-chain - otherwise it’s not a DEX. As for the order book and the matching engine, they can also run off-chain. This does diminish decentralization, but it makes the CLOB much faster.
Think about it: Binance Futures has a latency of just 5 milliseconds, or 0.005s. The fastest blockchains, such as Aptos, still require at least half a second for a transaction to become final - that’s still 100 times slower than Binance.
Fees are another trade-off. If adding an order to the book, matching it with another, and filling it are all blockchain transactions, then the user will have to pay the gas fee at least three times.
An interesting solution is an atomic matching engine, like the one built by Econia (see below). By having order placement and filling occur within the same transaction, it cuts down on the number of required transactions.
For the time being, latency and fees aren’t really a problem, because there isn’t much demand for high-frequency trading on the blockchain, anyway. For a regular user, who is prepared to wait for a few days for a limit order to fill, it doesn’t matter if it takes a second or a millisecond. However, it’s worth keeping in mind that there is simply no way to match CEX latency and keep everything on-chain at the same time.
Now that we know what they are and how they work, let’s look at the major on-chain order books and even CLOB-optimized blockchains that you need to know.
Econia and Pontem Gator
Econia Labs’ settlement engine is the first of its kind on Aptos. Econia originated at the 2021 Aptos Hackathon, where it won a prize and was selected for the Aptos accelerator program. This led to a $6.5 million seed round including Dragonfly, Lightspeed Faction, Wintermute Ventures, Hudson River Trading, Flow Traders, Aptos Labs, and others. Econia contains several key technological advantages that leverage Aptos’s speed and throughput.
Econia’s matching engine is atomic: all the steps involved in completing an order fit into one sub-second operation. The order is matched, the book is updated, and the assets are routed in one single transaction. This greatly improves efficiency and time to finality, and is only possible on a blockchain as advanced as Aptos.
In addition, Econia is hyperparallelized. It isolates the data for different markets (trading pairs) into different memory regions in order to be able to process multiple transactions at once. The result is top-tier responsiveness, speed and scalability that rival non-blockchain solutions.
Econia’s architecture is also asset-agnostic, meaning users can trade advanced products like options or even leveraged perpetual futures. As the code is open-source, projects can integrate Econia into their own dApps to enable derivatives, or leveraged securities that might not be permissioned on centralized exchanges.
To celebrate its launch on testnet, Econia recently ran a testnet trading contest. 1000+ traders from 68 countries generated $7.6 billion in volume on testnet in just a few days, illustrating the massive demand for Aptos DeFi. This gave the team insights into how to strengthen the infrastructure to handle massive data flows. Looking ahead, Econia is preparing a mainnet launch for 2024.
We are proud to have Econia as a Pontem partner, and we already have a project running on their order book: Gator.
Here’s how you can use Gator as of January 2024:
- First, create a market account and deposit some funds into it from your wallet. Gator is optimized for Pontem Wallet, but you can also use Petra, Martian, Rise, and other Aptos wallets;
- Choose a trading pair: APT-USDC (LayerZero) or WETH-USDC;
- Place limit or market orders;
- Explore the order book and enjoy proper price charts - something you won’t find on most AMMs (the charts are sourced from Bitfinex);
- Use hundreds of indicators, such as the RSI, stochastic RSI, Ichimoku Cloud, Bollinger Bands, EMA Cross, etc.;
- Customize the chart: candle style and color, grid lines, background, etc.
- View your order history.
Other Aptos platforms to have integrated Econia’s order book are Aries Markets, Kana Labs, and SwapGPT.
Order Book Blockchains: Injective and Sei
Injective and Helix DEX
Injective was incubated in 2018 by Binance Labs. In 2019, it created an order book primitive, as well as a derivatives primitive, which form the basis of the chain. In 2020, the INJ token was launched and the testnet went live. The mainnet launched in 2021, with the Cosmos SDK and the Tendermint proof-of-stake consensus network. Injective’s exchange module enables order book management, trade execution, order matching, and transaction settlement, all on-chain.
Injective hosts a wide ecosystem, including the Helix DEX, Mito DeFi protocol, Black Panther asset manager, and Talis NFT marketplace. In 2022, the mainnet was updated to support binary options, a type of yes-or-no derivative, which enables the development of on-chain prediction markets on Injective.
Injective’s token INJ has been a hot choice for traders recently, approaching all-time highs at $17 in October 2023. The chain’s TVL almost tripled in 2023, going from $8.5m to $25m at the peak and $20.5m at the end of the year.
Helix is the biggest dApp on Injective. It offers swaps via an AMM; spot trading via an on-chain order book; and on-chain perpetual futures (perps). Helix supports not only assets in the Cosmos and Injective ecosystem (INJ, ATOM, TIA, etc.) but also cross-chain assets - BTC, ETH, SOL, XRP, and so on.
Sei ($SEI) is part of the Cosmos ecosystem and is positioned as the first L1 blockchain created for DeFi and specifically for orderbooks. A reminder: Cosmos is an interconnected network of blockchains such as Cosmos Hub ($ATOM), Osmosis ($OSMO), Juno ($JUNO), Kava ($KAVA), etc. They can exchange assets via the Inter-Blockchain Communication protocol (IBC).
Sei is built around an on-chain CLOB that records orders and executed transactions, and provides this data to exchanges in it ecosystem.
- very fast time to finality - 0.6s, similar to Aptos;
- high throughput - 22,000 TPS;
- a twin-turbo consensus mechanism;
- market-based parallelization;
- native matching engine (powered by the order book);
- frontrunning protection to combat bots and protect traders: orders aren’t executed one by one but rather grouped by price at the end of each block and executed in batches.
Sei already has an ecosystem of its own, with projects like Astroport (DEX), Kryptonite and Eris (liquid staking), Axelar (cross-chain bridge), Levana Perps (derivatives trading platform), etc.
Serum (Solana): the once-great but dead CLOB
Launched in August 2020, Serum ($SRM) CLOB was one of the first big dApps on Solana and the first major on-chain CLOB. At the peak in November 2021, its TVL exceeded $1.8 billion. The project was hurt by the fact that Sam Bankman-Fried was a major investor and promoter, and in late November 2022 it closed down.
SRM still enjoys reasonable trading volume and even pumps from time to time. This is common for tokens of dead protocols, but such pumps are purely speculative. Always DYOR and be very careful around such “dead” assets.
On-chain order books could become a hot narrative in 2024, so we will keep reporting on this space in the Pontem blog. Don’t miss the next article - and of course, make sure to follow us on X (Twitter) and Telegram!
Pontem is a blockchain product studio building for Aptos and the Move ecosystem. We work closely with the Aptos team to produce innovative and secure dApps and dev tools, including: