DEFI/DEX Aggregators: An Introduction to Liquidity Optimisation

Aw Kai Shin
9 min readJan 28, 2023

--

Lars Kienle

Societies are created and destroyed on the back of liquidity flows. A society with a healthy and functioning liquidity backbone enables value to flow towards its most optimal use case. Such capital efficiency enables network value to be compounded as all participants are incentivised towards the same goal of making trades as seamless as possible. This trading convenience consists of 3 key factors:

  • Price: Am I able to find someone else who is willing to buy/sell at my desired price?
  • Quantity: Even if I find someone willing to match my price, do they have enough units of the asset that I’m trading for?
  • Time: How fast can the trade be done? Will the price/quantity change while the trade is taking place?

At the core of every trade lies a deceptively simple task of matching a buyer’s expectation with a seller’s expectation. In almost all cases, more liquidity is the answer to this question as it ensures a myriad of trade options are always available at any point in time. DEX aggregators were created with the specific goal of optimising liquidity flows and is made possible due to the open and composable nature of DeFi.

Note: This article dives specifically into off-chain aggregators which have recently gained more traction than their on-chain counterparts.

DEX ≠ DEX Aggregator: Merging Fractured Liquidity

To avoid commingling concepts, it is crucial that DEX aggregators are not confused with DEXes. Decentralised exchanges (DEXes) enables peer-to-peer trading of tokens without the custodial requirements of a middleman (i.e. a trusted third-party has to hold both assets to successfully facilitate a trade). While the intricacies of DEXes are not within the scope of this article, it is important to understand how trading liquidity is generated. You can refer to this article if you would like a deeper dive on DEXes.

There are two flavours of DEXes which are differentiated by their trade matching mechanism: order book or automated market maker.

Order book DEXes

Order book DEXes matches trades by aggregating all user specified buy and sell orders for an asset into an order book list. Through the creation of a buy and sell order list, potential trades can be identified through comparing matching buy and sell orders. In this case, liquidity is generated through the submission of potential trade orders which are executed when a matching trade is found.

Specific to DeFi order book implementations, such DEXes will usually require users to commit to their order by signing a transaction which is only submitted to the network upon the DEX smart contract receiving a matching order. This ensures that funds can’t be double-spent while avoiding the hefty gas fees required for constant manual adjustment of orders. Critically, order book DEX liquidity relies on having a deep order book consisting of user defined orders.

Automatic Market Maker (AMM) DEXes

Per its namesake, AMM DEXes maintains a liquidity pool of assets against which trades can be made automatically along a pricing curve. Asset holders are incentivised to provide their tokens to the liquidity pool in exchange for a portion of the trading fees. In this case, AMM liquidity is generated when token holders lock their tokens in a liquidity pool in exchange for a percentage return on their assets. Generally speaking, the more liquidity locked in a pool, the larger the pool size relative to a trade which results in less slippage.

In the pursuit of greater capital efficiency, many AMMs have also implemented their own price curve formulas that enable more fine-grained tuning of liquidity flows. These specialised price curves enable users or the protocol to concentrate liquidity within a particular price interval based on specific use cases. Critically, the price curve is bounded by the pool’s total liquidity and therefore AMM DEX liquidity is heavily reliant on liquidity provider incentives.

Fractured Liquidity

While DEXes managed to achieve the non-trivial goal of facilitating secured and pseudonymous peer-to-peer transactions, a more socioeconomic challenge arose due to the open and permissionless nature of DeFi. Given that public smart contract code could easily be copied and tweaked, liquidity for the same asset pairs were fractured across various DEXes for a myriad of reasons:

  • Transaction Costs: The network fees (gas) that was required to confirm a transaction could make smaller volume trades unprofitable. Users who prioritise lower fees might migrate their trades to DEXes on a chain with lower transaction fees.
  • Yield Optimisation: As hinted above, various AMM DEXes implement customised pricing curves in an effort to maximise a liquidity provider’s risk-adjusted returns. Liquidity providers have different risk profiles resulting in each provider having a preferred DEX implementation. This is less significant for order book DEXes as users define their own risk levels through manual market making.
  • Information Asymmetry: Given DeFi ecosystem maturity, information on the best rates are not easily available resulting in more partially informed decisions.
  • UX Familiarity: Doing your own research (DYOR) takes a significant amount of time and hence users will tend to gravitate towards dapps which they are more familiar with, even if the rates offered are objectively sub-par.
  • Ecosystem Considerations: DEXes forms a part of a larger DeFi ecosystem hence there are other non-DEX specific considerations such as preferred tokens, integration with other DeFi primitives, etc.

Due to the above reasons, liquidity tends to be fractured across individual DEXes resulting in less optimal trades and yields. For order book DEXes, the splitting of trade orders results in shallower book depth and therefore less likelihood that a pending order will be matched. For AMM DEXes, the splitting of liquidity meant that the relative size of a trade against a liquidity pool was larger, resulting in greater slippage. Consequently, there exists a strong incentive for DEXes to engage in anti-competitive behaviour in the short term which goes against the goal of a decentralised and open DeFi ecosystem.

Connecting Siloed Liquidity

DEX aggregators are a demand-side solution that was created with the purpose of connecting siloed liquidity across various DEXes. This is achieved through splitting and rerouting trades across various DEXes to achieve the best swap rates given the network conditions. By aggregating liquidity across DEXes, aggregators provide users with a convenient entry point to explore and compare rates in an objective manner.

An aggregator’s competitive edge comes from its ability to efficiently calculate the best trade route taking into account swap rates, slippage, and gas fees. Critically, this trade route optimisation necessitates programmatically routing trades towards the most capitally efficient liquidity sources which encourages greater market stability through competition.

DEX Aggregators: How It Works

DEX aggregators are made possible due to the open and composable nature of DeFi whereby standard interfaces enable liquidity to be queried and trades to be executed directly with a DEX smart contract. Through integration with a myriad of DEX smart contracts, aggregators are able to function as an optimisation layer between the DEX smart contract and incoming trade requests. The centralised equivalent would be similar to a brokerage/OTC rerouting trades across multiple exchanges.

The basic concept behind aggregators is quite simple and consists of the following generalised steps:

  1. User submits a swap request to the aggregator endpoint.
  2. The aggregator queries the connected DEXes for liquidity data on the specified trading pair. Note that token standards (i.e. ERC20) ensures token interoperability across DEXes.
  3. Based on the trade volume, the aggregator will calculate the best route for the trade using the aggregated liquidity data. Trades might even be split if the potential slippage outweighs the gas costs.
  4. Bundle the trade route(s) as an unsigned transaction pending the user’s approval.
  5. User views the finalised trade route and submits a signed transaction to the network, using a network provider of their choice (ie. alchemy, infura, self-hosted node).
  6. An aggregator smart contract atomically executes the signed transaction, debiting the user’s input token.
  7. User receives the output token in their account.

In keeping with DeFi composability, notice that aggregators do not specify a particular user interface implementation nor infrastructure communication channels (i.e. providers). While many aggregator teams have implemented their own user interface (eg. Kyberswap, 1inch, Matcha) for users to view and submit trades, the aggregator endpoint can be easily triggered from any web application. Aggregators can therefore be seamlessly integrated with applications demanding the best token swap rates without the overhead of managing multiple liquidity sources.

Note that the bundled transactions should also be atomically executed by the network. This ensures that trades with multiple routes do not get partially settled which could result in an overall disadvantageous position as the network condition dynamically changes. Transaction atomicity provides greater assurances around the final swap price which would always be within the user consented interval.

A key aspect to this flow is that users are given the final option to consent to the suggested route as the bundled transaction requires their signature. While aggregators return all the details of the trade (ie. route, splits, final price), application developers are still responsible for displaying such information to the user in a way that best suites their target user. Nonetheless, having an application which provides transparent and easily understandable data will likely result in the application having a competitive edge as this aligns with the optimal UX.

The Future of DEX Aggregators

At the aggregator level, the most successful aggregators will be determined by the following core competitive factors:

  • Total Connected Liquidity: A key supply-side factor which enables the aggregation of potential liquidity sources. Market forces will drive increased DEX and aggregator interoperability as their incentives are aligned — connected DEXes increase their potential trade origination sources while aggregators increase their potential liquidity sources.
  • Algorithmic Efficiency: Aggregators whose routing algorithms are able to consistently compute the best swap rates will have a significant market advantage, with all else being equal. As the best routes require objectively sourcing the best liquidity (i.e. the most capital efficient), DEXes are forced to compete based on actual spreads as more trades are routed via the aggregator.
  • Application/bot Integration: A key demand-side factor that enables traders to conveniently access the best swap rates. As most users will be submitting trades via an application interface, the extent to which aggregators can be seamlessly integrated with other third-party applications will be crucial to its adoption. Applications are able to source the best liquidity with the lowest development overhead while aggregators increase their potential trade origination sources.

While aggregators specialise in connecting fractured liquidity across DEXes, it must be noted that this only applies to DEXes on the same chain (i.e. Ethereum, BNB, Optimism). The increased complexity and gas required for cross-chain (i.e. transfers between chains) transactions will likely result in sub-optimal rates. Given the hyper-competitive environment, most aggregators will likely pursue a multi-chain strategy whereby the aggregator code is deployed onto multiple chains. This widens the aggregator’s reach while also enabling aggregator teams to focus on their core value-add: getting the best swap rates.

As the DeFi ecosystem matures, aggregators will continue to play an increasingly important role as liquidity optimisation hubs. At a transaction level, an aggregator’s value scales exponentially with trade volume as slippage is greatly reduced. Consequently, aggregators also ensures stability at the network level as a result of objectively sourcing the best liquidity sources. Critically, through an alignment of incentives, aggregators introduces healthy competition into the DeFi space which bodes well for the future of DeFi as a whole.

Thanks for staying till the end. Would love to hear your thought/comments so do drop a comment. I’m active on twitter @AwKaiShin if you would like to receive more digestible tidbits of crypto-related info or visit my personal website if you would like my services :)

--

--

Aw Kai Shin

Web3, Crypto & Blockchain: Building a More Equitable Web | Technical Writer @FactorDAO | www.awkaishin.com