Cointime

Download App
iOS & Android

Clober:On-Chain Order Book DEX for The Ethereum Ecosystem

Abstract

Clober presents a new algorithm for order book DEX “LOBSTER — Limit Order Book with Segment Tree for Efficient oRder-matching” that enables on-chain order matching and settlement on decentralized smart contract platforms. With Clober, market participants can place limit and market orders in a fully decentralized, trustless way at a manageable cost.

DEX 2.0 — On-chain Order Book DEX

The emergence of AMM and the dawn of DeFi

Exchanging between assets is the most foundational component of financial activities. In the early days of Ethereum, there were many projects trying to build decentralized financial applications. However, before we had the means to exchange assets effectively in a decentralized way, their adoption was limited since any financial activities accompanying swaps between assets should have relied on centralized infrastructures. When Uniswap launched in 2019, it introduced a new way of providing liquidity for swaps between assets efficiently on a low-throughput execution environment and opened up a new era for the blockchain industry called “DeFi.”

AMM enabled us to make a swap between arbitrary sets of assets in a decentralized way — which means that it is non-custodial, trustless, and permissionless. Leveraging this infrastructure, many protocols such as DeFi protocols or DAOs were able to mint their own governance token and provide liquidity for it — to build community, raise capital, incentivize contributors, etc. Also, a certain form of AMM specialized for swaps between low-volatility pairs — which is called a “Stable Swap” — was introduced, which significantly contributed to the growth of the decentralized stablecoins by reducing their volatility.

Limitations of AMM-centric DeFi ecosystem

However, as the DeFi ecosystem grew, the pitfalls of AMMs emerged as well. The fundamental limitation of AMMs lies in the fact that users cannot place limit orders on them. This means that market makers have no control over the price range on which to provide liquidity or the margin they take from providing liquidity — i.e., the bid-ask spread.

For example, for high-volatility pairs, the risk of ‘Impermanent Loss’ might exceed the expected revenue from liquidity providing. Under a traditional order book environment, market makers would have increased the bid-ask spread to offset the volatility risk. However, it is not possible on AMM protocols. This is why many DeFi protocols provided a massive volume of inflation rewards to the liquidity providers of their governance tokens, which imposed a strong sell pressure on their prices and eventually made them all look like a bunch of decentralized Ponzi schemes.

Stable swaps handle liquidity quite efficiently when all things are good, but when a poorly designed stablecoin starts to depeg it creates severe losses for those who supplied the liquidity.

The future of DEX beyond AMMs

For more sophisticated DeFi protocols to emerge and expand the territory of the decentralized economy, there must be an on-chain order book infrastructure as their backbone, which enables a generalized form of exchanges between assets with a high degree of freedom.

In the case of Solana, powered by its high throughput, an on-chain order book DEX called “Serum” has already secured its dominant place in the ecosystem, becoming a necessary infrastructure that most of the DeFi protocols integrate with. Solana’s had-been leading perpetual swap protocol “Mango Market” wouldn’t have had-been so successful had there been no order book infrastructure like Serum.

For another example, the Dydx protocol has become the most successful decentralized perpetual futures platform by leveraging the order book system — although it’s off-chain. Many alternative on-chain perpetual futures protocols utilize AMMs as their exchange infrastructure, but most are far from successful.

It is undeniable that order book DEXs will eventually replace AMMs sooner or later, as smart contract platforms scale and gas costs are reduced. With the emergence of the on-chain order book DEX, a new era of DeFi will open.

Why on-chain

Off-chain order books require centralized operators to run the matching engine off-chain. This means that all kinds of typical risks of centralization apply to them. For example, if the operators get sanctioned by a government authority, the platform might not be able to be further maintained, or its users’ assets might get censored. Also, a malicious operator — or a hacker who compromised the security of the operator — can censor or manipulate users’ trading activities.

In addition, one of the most important merits of DeFi is that it is composable. Each DeFi protocol can leverage other DeFi protocols as its infrastructure, which creates a strong network effect between protocols. For example, one may combine a lending protocol and a DEX protocol to create a margin trading platform. A DEX aggregator can aggregate multiple on-chain DEX protocols to provide large liquidity with no liquidity of its own. An open maker order on an on-chain order book itself can be considered as a stand-alone asset that can be utilized in other protocols — e.g., borrowing USDC against a sell order on the order book. Conversely, off-chain or app-chain-based DEX protocols cannot provide such properties. Smart contracts cannot call off-chain functions. Positions on off-chain DEX protocols cannot be utilized in on-chain protocols.

In short, off-chain order books are inferior in terms of trustlessness, censorship resistance, and interoperability, therefore cannot replace AMM DEXs.

Why it is difficult to build an on-chain order book

Under the typical implementation of order books, each taker order transaction should process the settlement of an arbitrary number of counterparty orders that are matched with itself. This means that the computation cost of a taker order increases proportionately to the number of maker orders it is matched with. Because there’s no limit on this number, the gas cost of a taker order can grow very high — can even exceed the block gas limit, in which case the transaction will fail. For example, let’s say there are 100,000 sell orders of size 1 ETH at a price of 1,500 USDC. If someone tries to buy 50,000 ETH with 75,000,000 USDC, the transaction is likely to be rejected because of its high gas cost, even though there are enough counterparty orders to be matched with it. This is why Serum, a leading order book DEX protocol on Solana, has a parameter to limit the number of matching orders in its taker order interface.

Clober’s solution

We want to reduce the linear overhead of taker orders. To do so, we make taker orders only keep track of the “Total Claimable Amount,” which is the sum of taken orders at each price point, instead of processing all the matching orders. We then let market makers claim the proceed of their filled orders themselves by simply comparing the “Claim Range” of their order and the “Total Claimable Amount”. “Claim Range” is an interval representing the position of a maker order in the order queue at its price point. If the “Total Claimable Amount” is bigger or in between an order’s “Claim Range”, the order is fully or partially claimable.

The non-trivial part of this implementation is keeping all of the Claim Ranges up to date. For example, if my Claim Range is [10, 13] and an order with Claim Range [8, 10] is canceled, my order would need to be updated to [8, 11] and all orders behind mine would also need to be updated. If a canceling transaction had to process all the range updates, it would be too expensive and possible to fail. We can overcome this by adopting a data structure called “Segment Tree.”

A segment tree is a data structure that stores a list of numeric values, which enables efficient “range queries” — calculations on the partial sum of its subarrays. The complexities of insertion, deletion, and range query of the Segment Tree are all logarithmic. Leveraging the Segment Tree, we can keep track of the Claim Ranges of maker orders at each price point with low gas costs.

Based on this architecture, along with some additional optimizations, we were able to reduce the gas cost of both maker and taker orders, similar to that of a transaction on Uniswap.

For more information about our tech, please find our technical litepaper here.

Closing Remarks

AMMs, while possible, are not utilized in CeFi because of their poor performance in providing liquidity. They only exist in DeFi because of their passive market-making abilities, alleviating the need to constantly pay obsessive gas fees. However, as layer 2 technologies develop, the trend is projecting ever-lower gas fees, opening up a market for order books to replace swaps done on AMMs. Eventually, order books will become the preferred way of swapping assets, just like it always has been for CeFi.

Comments

All Comments

Recommended for you

  • American Bitcoin's Bitcoin reserves have increased by approximately 623 BTC in the past 7 days, bringing its current holdings to 4941 BTC.

    Emmett Gallic, a blockchain analyst who previously disclosed and analyzed the "1011 insider whale," posted on the X platform revealing updated data on the Bitcoin reserves of American Bitcoin, a crypto mining company supported by the Trump family. In the past seven days, they increased their holdings by about 623 BTC, of which approximately 80 BTC came from mining income and 542 BTC from strategic acquisitions in the open market. Currently, their total Bitcoin holdings have risen to 4,941 BTC, with a current market value of about 450 million USD.

  • The US spot Ethereum ETF saw a net outflow of $19.4 million yesterday.

    according to TraderT monitoring, the US spot Ethereum ETF had a net outflow of 19.4 million USD yesterday.

  • Listed companies, governments, ETFs, and exchanges collectively hold 5.94 million Bitcoins, representing 29.8% of the circulating supply.

    Glassnode analyzed the holdings of major types of Bitcoin holders as follows: Listed companies: about 1.07 million bitcoins, government agencies: about 620,000 bitcoins, US spot ETFs: about 1.31 million bitcoins, exchanges: about 2.94 million bitcoins. These institutions collectively hold about 5.94 million bitcoins, accounting for approximately 29.8% of the circulating supply, highlighting the trend of liquidity increasingly concentrating in institutions and custodians.

  • The Bank of Japan is reportedly planning further interest rate hikes; some officials believe the neutral interest rate will be higher than 1%.

    according to insiders, Bank of Japan officials believe that before the current rate hike cycle ends, interest rates are likely to rise above 0.75%, indicating that there may be more rate hikes after next week's increase. These insiders said that officials believe that even if rates rise to 0.75%, the Bank of Japan has not yet reached the neutral interest rate level. Some officials already consider 1% to still be below the neutral interest rate level. Insiders stated that even if the Bank of Japan updates its neutral rate estimates based on the latest data, it currently does not believe that this range will significantly narrow. Currently, the Bank of Japan's estimate for the nominal neutral interest rate range is about 1% to 2.5%. Insiders said that Bank of Japan officials also believe there may be errors in the upper and lower limits of this range itself. (Golden Ten)

  • OKX: Platform users can earn up to 4.10% annualized return by holding USDG.

    According to the official announcement, from 00:00 on December 11, 2025 to 00:00 on January 11, 2026 (UTC+8), users holding USDG in their OKX funding, trading, and lending accounts can automatically earn an annualized yield of up to 4.10% provided by the OKX platform, with the ability to withdraw or use it at any time, allowing both trading and wealth management simultaneously. Users can check their earnings anytime through the OKX APP (version 6.136.10 and above) - Assets - by clicking on USDG. Moving forward, the platform will continue to expand the application of USDG in more trading and wealth management scenarios.

  • The Federal Reserve will begin its Reserve Management Purchase (RMP) program today, purchasing $40 billion in Treasury bonds per month.

     according to the Federal Reserve Open Market Committee's decision on December 10, the Federal Reserve will start implementing the Reserve Management Purchase (RMP) program from December 12, purchasing a total of $40 billion in short-term Treasury securities in the secondary market.

  • Bitcoin treasury company Strategy's daily transaction volume has now surpassed that of payment giant Visa.

    according to market sources: the daily trading volume of Bitcoin treasury company Strategy (MSTR) has now surpassed the payment giant Visa.

  • The US spot Bitcoin ETF saw a net outflow of $78.35 million yesterday.

    according to Trader T's monitoring, the US spot Bitcoin ETF had a net outflow of $78.35 million yesterday.

  • JPMorgan Chase issues Galaxy short-term bonds on Solana network

     JPMorgan arranged and created, distributed, and settled a short-term bond on the Solana blockchain for Galaxy Digital Holdings LP, as part of efforts to enhance financial market efficiency using underlying cryptocurrency technology.

  • HSBC expects the Federal Reserve to refrain from cutting interest rates for the next two years.

    HSBC Securities predicts the Federal Reserve will maintain interest rates stable at the 3.5%-3.75% range set on Wednesday for the next two years. Previously, Federal Reserve policymakers lowered rates by 25 basis points with a split vote. The institution's U.S. economist Ryan Wang pointed out in a report on December 10 that Federal Reserve Chairman Jerome Powell was "open to the question of whether and when to further cut rates at next year's FOMC press conference." "We believe the FOMC will keep the federal funds rate target range unchanged at 3.50%-3.75% throughout 2026 and 2027, but as the economy evolves, as in the past, it is always necessary to pay close attention to the significant two-way risks facing this outlook."