CoW Swap: Intents, MEV, and Batch Auctions

Low Fees and MEV-Resistant Trades: Made possible through intent-based architecture

Special thanks to Anna and Alex for feedback and input on CoW Swap and its novel design mechanisms

Key Takeaways

  • CoW Swap is an intent-based application that allows users to leverage signed messages to express their intent to trade (e.g. swap token A to token B)

  • batch auction mechanism is utilized, in which a network of solvers compete amongst each other to maximize user orders surplus, via Coincidence of Wants (CoWs) discovery and routing of trades to the best available liquidity on-chain

  • The unique architecture employed allows CoW Swap to offer interesting features including CoW Hooks and Time-Weighted Average Price (TWAP) orders based out of the new Composable CoW Framework

  • Additional benefits of using CoW Swap include MEV resistancelow fees / gasless orders and security by having solvers approve new contracts on your behalf

Introduction

Source: CoW Swap Dune Dashboard
Source: CoW Swap Dune Dashboard

Recently, CoW Swap has been gaining the hearts of traders, apparent from the constantly growing monthly trading volume. It’s well known for possessing an intent-based architecture, a narrative that has caught the attention of many with its user-friendly interface. However, under the hood, CoW Swap has a lot more than meets the eye. The CoW Swap team has been building non-stop, delivering prominent features, including (a) MEV Blocker (b) Limit Orders (c) Time-Weighted Average Price (TWAP) (d) CoW Hooks (e) Milkman ERC1271 orders and (f) Programmatic Orders.

This article will dive deep into the fundamentals of CoW Swap, explaining its architecture and the benefits brought about by it. We then end with an overview of the current protocol developments and what to expect from the protocol in the future.

What are AMMs?

To uncover the innovation driven by CoW Swap, one must understand automated market makers (AMM), a type of decentralized exchange (DEX) that allows users to trade one asset for another. AMMs use liquidity pools to match traders with liquidity for their trades, rather than a peer to peer approach typically used in traditional finance. For example, a user that wishes to swap ETH for USDC can do so in a ETH/USDC liquidity pool. Upon the swap, the ratio of ETH to USDC changes, to which the AMM will re-price the ETH remaining in the pool. To understand more about AMMs, you can refer to this link here.

AMMs typically require traders to submit a transaction from their wallet to be able to interact with the liquidity pools for swapping. As a result of this necessary interaction with the pools, AMMs settle trades in a sequential manner, based on the change in liquidity upon each swap. CoW Swap employs an intent based design which innovates on the traditional AMM design, connecting traders directly (when possible) with each other without using pools. Benefits of this innovation include lower fees and better execution prices, which will be explained in the later part. To understand the core innovations one must understand what intents are to begin with.

What are Intents?

Intents refer to the desired goal of a user, for example ‘I wish to swap USDC for ETH’. An intent-based protocol facilitates on-chain activities by abstracting the complex processes associated with it. A user can declare the end goal they wish to achieve ‘I wish to receive ETH’, and specify certain parameters ‘I wish to receive ETH by swapping USDC’. This message can then be signed to authorize sophisticated third-parties known as solvers to execute the intent, eventually delivering ETH to the user.

Here’s a visualization of an intent-based system:

Intent-based System
Intent-based System

Intents help make the process of achieving on-chain goals easier and less technical. Instead of going through a complex process to complete a transaction, a person can set their goal and some rules, and let others handle the technical details to make it happen. In practice a user can define the terms, and sign a message that other parties fulfill. This makes completing transactions on-chain simpler and more user-friendly, especially when multiple goals can be grouped together in one go, saving time and resources.

To learn more about intents, you can refer to this article here.

Introduction to CoW Swap

CoW Swap emerges as a premier example of intent-based applications, where users indicate their desired trade outcome, delegating the execution to third-party, permissionless agents called solvers. The core mechanism utilized by CoW Swap is known as batch auctions, which aggregates users’ intent (the orders they wish to carry out). Solvers compete to offer the most optimal execution route for these orders, which will maximize the user surplus (the amount of asset received by user after swap). The execution methods used by solvers can be a combination of both off-chain matching and on-chain swaps. Solvers are rewarded upon successful execution of orders within the batch auction.

The key difference between CoW Swap and other AMMs is the utilization of Coincidence of Wants (CoW), where overlapping user intents can be matched without being routed through a pool. This offers higher gas efficiencies and lower cost for users. In addition, given that user orders are not being routed through a public mempool, CoW Swap mitigates Maximal Extractable Value (MEV) problems, further contributing to a more optimized swap for users.

CoW Swap's Mechanism
CoW Swap's Mechanism

CoW Swap Transaction Execution Mechanism

Batch Auctions

CoW Swap’s batch auction mechanism aggregates orders and settles them together at once, in comparison to the traditional sequential execution of orders. Batch auction serves as the core pricing (price discovery) mechanism for CoW Swap. Orders are grouped together, where solvers (off-chain counterparties) compete to execute these orders either through off-chain matching or on-chain DEXs.

Solvers utilize advanced computations to customize trading routes for all orders in the batch auction, based on the user inputs (e.g. price, slippage tolerance etc.). Orders that fulfill Coincidence of Wants can be executed off-chain, while the remaining orders can be routed to other AMMs or DEX aggregators for execution. Thereafter, the settlement logic is passed on to protocols for execution, who are responsible in validating the execution legitimacy (approval of transaction etc.).

Let’s visualize the workflow of a batch auction:

  1. A group of 4 users on CoW Swap submitted their orders off-chain via intents

  2. These orders are aggregated into a batch and forwarded to the solver network

  3. Solvers compete to provide the most optimal execution:

    (a) They will use their respective algorithm to identify the best execution route possible

    (b) Coincidence of Wants: Where orders match, the trade will be executed off-chain directly between the traders

    (c) Remaining orders that did not managed to be matched will be settled on AMMs / DEX aggregators

  4. Solvers submit their settlement solutions to the protocol who then ranks them based on surplus maximization and proceeds to push on-chain the winning settlement

CoW Swap Batch Auctions
CoW Swap Batch Auctions

The main motivation of utilizing a solver network is to maximize the amount of assets that users can receive. This is achieved through the competition amongst solvers to source for the most optimal trading route with their fulfillment algorithm.

Solvers

Essentially, solvers compete to provide the best batch auction settlement by first identifying Coincidence of Wants within the batch. Thereafter, solvers will take note of any remaining trades that did not manage to be settled, and search through AMMs or DEX aggregators to settle them with the lowest slippage.

A detailed look into the workflow of solvers:

  1. At the start of a batch, all off-chain orders are considered for inclusion

  2. Selected off-chain orders will be aggregated into a batch auction by the protocol.

    Note: After a batch closes, no new orders will be included

  3. Solvers receive the orders in a batch and proceed to optimize the order with the goal of having their respective order settlement solution pushed on-chain

  4. The solution that offers the best clearing price, maxizming traders’ returns, will be selected

  5. Winning solver will receive rewards in the form of COW tokens which are granted by the protocol to incentive solver competition

    At the moment, the entirety of the fee charged to users is used to cover ethereum gas fees. That said, it's been proposed on the CoW DAO forum, that the protocol may experiment with different fee models

At this current stage of the protocol, CoW Swap utilizes an allow-list authentication contract to determine the addresses that qualify as solvers. In addition, an address can qualify as a solver if they provide a bond stated on CoW DAO CIP7 (CoW Improvement Proposal). Upon discovery of malicious behaviour (deliberately not providing users with the best execution route etc.), the bond will be slashed. Thus, this bond is meant to ensure that solvers are aligned with both CoW Swap and users. Nonetheless, most solvers do not have such a hefty amount of upfront capital. In these scenarios, solvers can be vouched by any existing bonding pool owner.

The competitive landscape of CoW Swap's solver network is rapidly evolving. Initially, DEX aggregators like 1inch and 0x dominated, settling over 50% of transactions. However, their market share has declined, now accounting for less than 4% of transactions. In contrast, advanced solvers such as Barter and Otex have risen to prominence, now handling the majority of solver volume.

Solver Landscape
Solver Landscape

Sophisticated solvers can source liquidity from intricate places, which are generally not accessible by DEX aggregators. This might’ve caused existing DEX aggregators’ market share to decline, tipping the scale in favor of independent solvers.

Now that we have understood the general concept of batch auctions and the role of solvers, let’s take a deeper look into Coincidence of Wants and how they play a critical role in CoW Swap.

Coincidence of Wants (CoWs)

For traditional finance incumbents and even non-crypto natives, it might be eye opening to see a protocol named “CoW” Swap, transacting hundreds of millions of dollars of digital asset volume. CoW refers to Coincidence of Wants, which is an economic phenomenon where two parties each hold an item the other wants, allowing them to carry out a direct exchange.

To understand this better, let’s take the example of Alice and Bob:

  • Alice wants to swap 1000 USDC to ETH

  • Bob wants to swap ETH into 1000 USDC

In the above scenario, it is clear that CoW exists. This allows for trades to be settled directly between Alice and Bob, without the need for external market makers or liquidity providers (LPs) to provide the liquidity for trade execution.

Depiction of Coincidence of Wants (CoWs)
Depiction of Coincidence of Wants (CoWs)

Coincidence of Wants can vary in their complexity, these figures are a good depiction of simple, batch and intermediate Coincidence of Wants.

Ring Trade

What happens when there are more than 2 orders involved in a batch, and there isn’t an exact Coincidence of Wants to allow for these orders to be settled directly amongst each other?

Instead of having to wait for an exact match between 2 parties, ring trades allow for liquidity to be shared amongst various parties as shown in the figure below.

From the figure above, it's clear that participants don't need to have exactly what the other party wants to complete a trade. They can leverage the broader network of participants in the batch auction to acquire the desired asset. On the contrary, execution of these 4 orders on traditional DEXs will take place in a sequential manner, exposing all participants to potential price slippages and MEV. We'll delve deeper into the concept of MEV later in the article.

It is important to note that every ring trade is considered as a Coincidence of Wants, but not every Coincidence of Wants is a ring trade.

CoW Swap Features

Now that we have understood CoW Swap’s core architecture, we can dive into the unique features made possible.

CoW Hooks

CoW Swap utilizes ‘hooks’, which are custom code attached to an order that can be executed before and/or after a trade. Hooks are useful because they can save users time and gas by turning multiple transactions or intents into a single intent.

This is the crux of CoW Swap’s intent-based architecture. CoW hooks make it possible for users to string together a series of complex actions, which may include bridging, staking, swapping, provision of liquidity and many more, and execute this series in a single transaction.

CoW Hook Architecture

  1. Pre-hooks

    Pre-hooks are intents that can be encoded into an order, and will be executed prior to a swap on CoW Swap.

    These actions are executed prior to an order’s signature being checked or tokens being sent from the user's address to CoW Swap.

  2. Post-hooks

    Post-hooks on the other hand, are actions that are executed after the swap has completed, where the swapped tokens have been transferred to the user's address.

CoW Swap Hooks
CoW Swap Hooks

Let’s take a look at a specific example, where a user stakes on Lido, after closing a loan position on Aave.

  1. Pre-hook: Close an open position on Aave by repaying the loan collateralized by USDC

  2. Swap: USDC will be converted to ETH through CoW Swap

  3. Post-hook: Stake ETH through Lido

Fees associated with hook execution are charged in the sell token of the swap, and cover 100% the execution costs. For example, when closing an open position on Aave, any additional fees will be paid in USDC. There is no need for users to hold onto additional ETH for the orders to be successful. This is beneficial as the process becomes more seamless, and prevents users from being unable to execute transactions due to lack of gas tokens.

CoW Hooks Use Cases

Some of the potential use cases made possible by CoW hooks include

  1. Repaying a debt → Staking

    As mentioned in the above example for pre-hooks and post-hooks

  2. NFT sniping → Selling the NFT → Swapping tokens

    Upon selling a sniped NFT, the amount received can be immediately swapped into the desired token. This reduces the asset volatility experienced by users

  3. Claiming airdrops

    Sell airdrop tokens, while using airdrop tokens as gas

  4. Automated LP position management

    a) Collect LP rewards

    b) Convert LP rewards into 50/50 of each asset in the LP pair

    c) Deposit both assets back into the liquidity pool to increase LP position

The image above shows that CoW hooks aren't just for DeFi activities, rather, they have a broad range of use cases. Various users, including NFT snipers and airdrop farmers, can also benefit from hooks. Over time, CoW hooks will likely introduce more nuanced and sophisticated use cases, catering to a wider range of users.

Time-Weighted Average Price (TWAP) Orders

What is TWAP?

Time-weighted average price (TWAP) is one of the most common algorithmic strategies used for executing trades. It is typically utilized when traders have a large order size and wish to reduce the impact on the market, as well as the slippage they suffer from it. For example, if a trader buys $1 million worth of $COW all at once, the price impact can be significantly high on AMMs due to the lack of liquidity. To prevent the price impact, a TWAP order would split the large order into smaller orders, which are executed over regular intervals, for a set period of time. Put simply, traders using TWAPs orders spread trades over time based on the average price in the TWAP calculation.

Mechanism of TWAP Orders [In Beta]

With CoW Swap, users can make a TWAP order by simply specifying the following metrics

  • Asset of choice (e.g. USDC/ETH)

    • Users choose the asset they wish to swap out of and the asset they wish to swap into
  • Total order size

    • Total amount to be swapped
  • Number of parts

    • This is the number of times the order will be split into
  • Duration

    • This refers to the length of time over which the order will be executed

The amount to be executed per swap can be calculated by total order size / Number of parts. And the intervals at which the swaps will be executed can be calculated by Duration / Number of parts.

CoW Swap’s TWAP Order Interface
CoW Swap’s TWAP Order Interface

In addition, users will also be able to specify the price protection. The TWAP order placed will not execute should the price of the asset drop beyond the percentage set for price protection. This is meant to protect the user’s capital and prevent them from buying into a potential black swan event (e.g. cascading liquidation) that could result in them entering a position with disadvantageous prices.

Benefits of TWAP Orders

There are multiple benefits that users can gain through TWAP orders:

  1. Reduced Price Impact

    Users typically have to pay a higher price when executing large orders on automated market makers (AMMs). This is due to the price impact of the order, where the inflow of large volume causes the price within the liquidity pool to spike up. In addition, big orders are also prone to sandwich attacks by MEV bots, essentially inflating the purchase price for users.

    With TWAP, the orders made each time are of smaller sizes. As apparent from the above figure shown for TWAP’s mechanism, instead of executing a $1000 order, it is split into 5 x $200 orders. This effectively reduces the price impact that users suffer, allowing them to swap at a fairer price.

  2. Reduced Slippage

    With bigger orders, users generally have to account for a higher slippage for the order to be filled. This is due to the price impact it brings to the market, which requires the slippage to account for the difference.

    With smaller orders, users can set a lower slippage. This allows them to execute the order at a price point closer to what they desire. In addition, it also helps them to reduce the amount lost to slippage, in turn receiving more of the desired assets.

  3. Increased Flexibility

    Users are able to customize the various metrics to decide how much they want to execute over each interval. In addition, since the order is submitted off-chain, users will be able to make changes to their TWAP orders based on market conditions, without incurring additional fees.

CoW Swap’s Unique Benefits

MEV-Resistance

Maximal extractable value (MEV) refers to the profit that validators can earn through arbitrage, which includes inclusion, exclusion and re-ordering of transaction sequence while building a block.

Often, MEV is seen as a negative externality as they result in users suffering from unfavorable prices or failed transactions. Broadly speaking, there are 3 types of MEV: (a) Front-running (b) Back-running (c) Sandwich Attacks:

  • Frontrunning: Attacker places a transaction before a targeted user’s transaction to benefit from the upcoming transaction.

  • Backrunning: Attacker places a transaction after a trade to benefit from the already placed transaction.

  • Sandwich Attack: Attacker places a transaction before and after a user's transaction to manipulate the asset price, thus profiting from arbitrage.

To understand more about MEV and examples, you can check out this article here.

With CoW Swap, there are 2 main mechanisms that minimizes the level of MEV users are exposed to:

  1. Coincidence of Wants: No Exposure to Transaction Order Manipulation

    Traditionally when trading on a DEX, users will submit their orders, which will be sent to a public mempool, which is where transactions sit before being confirmed by validators. This public mempool is heavily monitored by bots looking to profi from arbitrages. On CoW Swap, user orders are submitted and matched off-chain through solvers. Hence, the orders are not routed through a public mempool, preventing any other users from potentially front-running the order.

    Here’s an example of MEV that could occur in a typical DEX. Claire wishes to make a swap 10,000 USDC into ETH, a user that is monitoring the mempool will attempt to insert their own transaction (swap 10,000 USDC for ETH) before Claire. This increase in ETH demand will cause the ETH price to increase. When it’s time for Claire’s swap to execute, she will be faced with a higher ETH price, resulting in her receiving less ETH than what she originally had.

  2. Batch Auction: Uniform Clearing Price (UCP)

    Typically, orders on a DEX are executed in a sequential manner. This creates the opportunity for MEV as builders can re-order the transaction ordering to generate profits. However, this change in execution order results in users receiving different prices for their trades. For example, an order executed later might have to pay a higher price, causing the user to receive less assets than what would have been the original case.

    With CoW Swap’s batch auction, a mean settlement price will be calculated for all orders within a batch. Hence, there will be no MEV available for extraction since reordering of orders will be pointless.

    You can learn more details about the different types of MEV here.

Gasless Transactions and Low Fees

One other key value proposition is the fee optimization made available to users, which comes from various aspects:

  1. Off-Chain Signing

    Since the orders are submitted off-chain, there is no need for the users to pay gas with the chain native token. In addition, it is impossible for users to be faced with failed transactions, preventing them from paying unnecessary gas.

    In addition, since the orders are submitted off-chain, users are free to make as many orders as they wish, and are also able to cancel the orders as and when they want.

  2. Coincidence of Wants Transactions

    Through direct matching of transactions, there are no additional fees charged to the users, which would have been the case should users have traded on other DEXs such as Uniswap.

CoW Swap’s Future Outlook

CoW Swap has laid down plans to further decentralize the protocol in the future. One aspect in which they do so is through a permissionless solver model which encompasses 2 main components:

  1. Logic for solvers to be deemed suitable will be encoded into the smart contract

  2. Staking of assets by solvers to disincentivize malicious behavior

WIth a permissionless model, we can anticipate CoW Swap’s solver network to become highly robust. This eventually translates to better settlement for users, as the competition amongst solvers will strive to bring the best terms to users.

Conclusion

CoW Swap was one of the pioneers in experimenting on intent-based architecture and bringing it to the masses back in 2021. Since then, more projects have embarked on this field to optimize the various aspects. Anoma, is working on integrating intents into a chain. Propeller Heads, is working on fine-tuning the solver elements and searching for ways to make it more robust. With such a level of interest and research by the broader industry, it is certainly exciting to see how CoW Swap will continue to develop.

Sources

Investment Disclosure: The authors hold material positions in the assets discussed in this article. The content presented is for informational purposes only and should not be construed as financial or investment advice. Please perform your own due diligence before making any investment decisions.

Subscribe to Cookies Research
Receive the latest updates directly to your inbox.
Mint this entry as an NFT to add it to your collection.
Verification
This entry has been permanently stored onchain and signed by its creator.