Skip to content

Preamble: A free economy

The ideal DEX


1. Freedom to list & trade any tokens Between order book and AMM swap ALO model
2. Finding & supercharging idle liquidity Liquidity Mechanic Risk, reward and being the “House Dealer”
3. Freedom against censorship Conclusion

Author: Danny Lim, Shin Liang Chin, Clarence Soh.


Preamble: A free economy

I recently spent a week on the beautiful island of Hong Kong, criss-crossing its island and Hong Kong mainland, marvelling at how this island plays an outsized financial influence.

Today we generally accept without much thought that there can be no other outcome – that Hong Kong has always been destined to be a financial powerhouse. If you stop and put down your smartphone and think critically, Hong Kong odds of a financial powerhouse would be like Leicester winning the premier league – once in a lifetime. (sorry Leicester fans, good luck in the championship). Hong Kong wasn’t even the island the British Empire initially wanted – Hong Kong was too much rock, hilly and with nothing going on.

How did Hong Kong go against all odds then? The catalyst has been its ability to allow free flow of goods, and subsequently the inflow of capital. With mainland China and much of East Asia closed off, Hong Kong became the place to trade freely and monies from all over East Asia flowed in. People would trade anything – gold inlets, tea leaves, foreign currency, basically anything. Hong Kong has consistently ranked top as the freest economy, time and again, it is these free flow of goods that made Hong Kong rich. The hardworking people played a part – certainly.

Figure: Fraser institute ranks Hong Kong as the freest economy (again) for 2022.
Image: Same place in 1940s, image from
Image: Same place today

How can a crypto trading platform become a powerhouse? Let’s explore the criteria in this article.

The ideal DEX

We are interested in exploring how a DEX can become an ideal player in the market through a free economy system. One that is profitable for its owners but also a force for economic good.

In order to understand about DEX we need to revisit CEX. Today’s CEXes charge an arm and a leg for token listing, which translates to high barriers to entry, and trades are often frontrun by exchanges (think Alameda and FTX). Traders are already at the losing end from the beginning because in-house traders have moved the needle.The chinese word for “moving the candlestick” is emotionally striking – 插针, which also means to strike a needle – often into the hearts of exchange users.

Hence it is important to build a profitable DEX but also one that is net economic good for its users – the ideal DEX. The ideal DEX is similar to an ideal economy market , it needs to have three elements.

1 Freedom For Participants To participate – to list and trade, preferably anyone can.

2 Bringing in the asset and money flow aka Supercharging Liquidity.

3 Censorship Resistant, having full control.

Image: three items to be an ideal crypto exchange

1.Freedom to list & trade any tokens


Going back to Hong Kong’s analogy, if you ever visit Hong Kong’s (in)famous building Chung King Mansion, you see shops trade and barter all sorts, from handphones, to crypto to forex. There are hundreds of buildings like this in Hong Kong and hence a microcosm of Hong Kong itself. Hong Kong became a place where anything and everything got traded.


Image: a street nearby Chung King Mansion (Fabian Bittner / Getty Images)

The freedom of listing, trading and utilising derivatives is at the core of an ideal DEX. To realise this vision, the system must first embrace the freedom of listing. Just as Uniswap did for spot trading in 2018, an ideal DEX extends this concept to spot and/or perpetual trading. The freedom is intended for everything – “listing”, “trading’ and “market-making”.

The entire process mirrors that of Uniswap. A liquidity provider gains the freedom to list any desired perpetual pair by injecting funds and configuring parameters. Trading fees, funding fees, as well as trading profits and losses, are equitably distributed among all liquidity providers.


Between order book and AMM swap

In the section above, we talked about freedom to list tokens permissionless. But obviously most DEX are orderbook (not AMM) and, in your truly own MarginX’s case, we are perpetual (not spot).

As traders know, an order book matching system allows anyone to place their orders —be it market or limit, maker or taker—ensuring that the counterparty is not exclusive to a pool like Uniswap’s AMM model. The order book model fosters individual strategy deployment, providing participants with flexibility. Another rationale for adopting the order book model is the pliability of the price spread (price gap). Considering the heightened volatility and occasional liquidity constraints in exotic trading pairs, liquidity providers demand increased returns commensurate with the associated risks. This, in turn, translates to larger bid-ask price differences in harmony with market dynamics. This is especially important for exotic pairs or pairs in its early stage of price-discovery.

Hence our conclusion:

“AMM pool model is quick to deploy, does liquidity-pooling; limit order book model offers much more flexibility for sophisticated users and prevents large price gaps. Each its own and the combined strength of both models can be overwhelming. We call it the ALO model, AMM combined with LO (limit order).”


ALO model


We believe this novel ALO (Automated Limit Orderbook) model is critical to the freedom to list any tokens, as it provides the liquidity and fast deployment of AMM, and also keep the sophisticated features of ALO, including a prevention of unnatural price discovery that plagues AMM.

In a typical perpetual exchange, stablecoins act as the reserves for opening short positions, X (traders borrow X to short). The cryptocurrency acts as the reserves for long positions, Y (traders buy Y to long). The total liquidity provided is thus X . Y = k similar to an AMM. While AMM provides continuous liquidity in the form of X . Y = k it also suffers from pliability of the price spread because when X is being massively bought to near zero tokens available, the price of Y will go to ka-ching! Infinite dollar as is X . Y = k. Hence we want to translate AMM into limit order but minus pliability of price spread.

Figure: ALO model creates a orderbook alongside market participants

The first move in translating AMMs to LOBs lies in addressing the temporal aspect. While AMMs provide continuous liquidity, LOBs rely on limit orders placed on the orderbook, which can expire over time, leading to a mismatch between the provided liquidity and the current supply and demand dynamics. Additionally, AMMs utilize the full reserve to determine prices, making it impractical to buy the entire reserve due to the constraint of the equation X . Y = k. In contrast, LOBs use discrete price levels for orders, allowing for the possibility of exhausting the entire liquidity with a single trade.

ALO model

  1. Partially deploys X . Y = k onto orderbook
  2. Refreshes X . Y = k periodically and whenever trades happen

If you are interested in the mathematics behind it, read our 5-pager ALO research paper.


2.Finding & supercharging idle liquidity 


In order for the ALO model to work we need liquidity such as LP tokens, stables, etc and turn them into positions in a liquidity pool, this is done first by collaterizing them into a MakerDAO-like mechanism and drawing out stables to open the positions in the liquidity pool. 

Users can provide liquidity for diverse sets of tokens by depositing stablecoins, LP tokens. Thus providing the opportunity to function as a “house dealer” thus sharing trading fees of an exchange. Probabilistically this means profit-generation for liquidity providers as is the case of GMX’s model or any casino with house advantage.

Liquidity Mechanic

The mechanics of our smart contract involve the integration of two key pools:

Figure: two important pools in supercharging liquidity and profit for LPs

Liquidity Pools: This pool is composed of funds contributed by market participants to open long and shorts, the positions are unfilled.

Position Pools: This pool encompasses all accumulated filled position sizes, both long and short, that have arisen during trading activities.

Market participants inject funds into liquidity pools via smart contracts. The smart contract undertakes the task of generating limit orders on both the bid and ask sides. This generation process adheres to the formula: X . Y = k  (or alternately y = ax + b), in alignment with the guidance provided by the oracle price. The cumulative sum of these orders forms a quadratic curve, which is similar to conventional liquid trading pairs.

The X . Y = k formula serves the purpose of determining the depth of the order book as well as the spread. These determinations are established based on the equilibrium of the liquidity pool’s balance. The liquidity pool then deploys a series of limit orders onto the market book per the ALO model. As a limit order gets executed, the associated margin for that specific order becomes immobilised, transforming it into a position within the Position pools. To eventually regain the locked margin along with potential profit or loss, these positions must be closed.

To optimise the capital deployment timeline and enhance utility, the Position pools will take action. Specifically, they will initiate a close position limit order using a designated margin on the opposite side. For instance, if the initial position was a long one, the Position pools will promptly generate a short position order. This strategic manoeuvre aims to efficiently manage the position and associated resources, thus streamlining the overall trading process. 

If I have not bore you by now, our 5-pager ALO research paper might just do it (or the paper might make you realise how revolutionary ALO model is)

image:if the initial position was a long one, the Position pools will promptly generate a short position order

Risk, reward and being the “House Dealer”

Liquidity providers play a crucial role in the ecosystem. In exchange for their participation, the liquidity pool becomes eligible to receive a share of various fees, including trading fees, liquidation fees, and funding rate commissions. These accumulated fees are then distributed proportionally among all participants.


Here’s a breakdown of potential scenarios:

    • Trading gain + Fees: The liquidity providers experience and trading gain, and the earned fees further enhance their overall profit.
    • Fees > Trading Loss: In this case, the fees earned by the liquidity pool outweigh any trading loss incurred, resulting in a net gain for the liquidity providers.
    • Fees = Trading Loss: The earned fees cover the trading loss, ensuring that liquidity providers don’t face any net loss.
    • Fees < Trading Loss: If the accumulated fees fall short of compensating for the trading loss, liquidity providers experience a net loss.

The relationship between fees and trading gain/loss underscores the intricate interplay of risks and rewards that liquidity providers navigate within the ecosystem. It’s important for liquidity providers to carefully assess their risk tolerance and potential for profit when participating in such arrangements.



3.Freedom against censorship 


Last but not least factor to a true DEX is tamper proof. Aka the “D” in Dexes. 

Censorship resistant is the degree to which a system is tamper proof. That is, a censorship-resistant system means a third party cannot modify or remove content created by someone else, in this case the someone is DEX and the removal is any malicious third party. Censorship resistance will allow a new breed of assets to be listed, say an AI DAO token that is not yet known how to be classified.

In order to achieve censorship resistance, we need the order book to be on-chain even for orders not executed, and that will prevent frontrunning. We believe in the near future all competitive dexes will have most elements on chain, including the entire order matching engine and settlement process are conducted on-chain.


As I depart from Hong Kong West Kowloon train station to mainland China, it has dawned to me that while the island is still super rich, its unique proposition as the uber mega rich has slowly been partially usurped by its neighbour – such that in 2023 till date is the worst year of HKEX listing for many years. Back in the merry days, Hong Kong had the world’s biggest IPO exchange, companies like HSBC, Manchester United (you should know by now I am a football fan) shunned NYSE and LSE for Hong Kong’s HKEX.

It is a lesson to know that of all the three ideal economy items 1, 2 and 3. Hong Kong has possibly lost its competitive advantage in two. Hong Kong will certainly rebound, and it has its own mega supporter in kingly people like Arthur Hayes, which myself is a mega fan of. The current CEXes and DEXes will be tested vigorously in the next bull market and if they do not build themselves a profitable business that creates net business good, which is said item 1, 2 and 3. There will be a challenging moment.

Yours truly is a core contributor of Margin X which is a perpetual DEX, I reckon we will be faithfully adopting all three items coupled with our novel ALO model. Strap on and we’ll see you in the next moon ride.