How CoWs Will Save DeFi Swaps

Passie Intelligence
20 min readSep 21, 2023

CoW Protocol is a fully permissionless trading protocol that leverages batch auctions as its price-finding mechanism. It enables batch auctions to maximize liquidity via Coincidence of Wants (CoWs) in addition to tapping all available on-chain liquidity whenever needed.

What is a CoW?

A CoW is a settlement that shares liquidity across all orders that have matching limit prices. For example, if there are two orders, one to buy 1 ETH for 100 USDC and another to sell 1 ETH for 100 USDC, these orders can be settled as a CoW without the need for an external market maker. This is because the two orders have matching limit prices, so they can be exchanged directly between the two parties.

How does the CoW Protocol work?

CoW Protocol works by first collecting user orders into batches. These batches are then auctioned off to solvers, who compete to find the best possible price for the batch. The solver that offers the best price is awarded the right to settle the batch.

If the solver can settle the batch as a CoW, then they will be able to offer a better price to the users than if they had to use an external market maker. This is because CoWs can take advantage of the natural order book liquidity that exists between users.

In addition to CoWs, CoW Protocol can also tap all available on-chain liquidity whenever needed. This means that it can always offer the best possible price to users, regardless of the size or depth of the order book.

Batch auctions are a type of auction where multiple orders are auctioned off together. This allows for more efficient price discovery and can lead to better prices for traders.

Coincidence of Wants (CoWs) are settlements that share liquidity across all orders that have matching limit prices. This means that if two traders are both trying to buy the same token, they can be matched together and their orders can be settled without the need for an external liquidity provider.

CoW Protocol uses batch auctions and CoWs to provide several advantages over traditional trading protocols, including:

Better prices: CoW Protocol can often find better prices for traders than traditional AMMs or DEX aggregators. This is because it can tap into a wider range of liquidity sources and can take advantage of CoWs.

Reduced gas fees: Batch auctions can significantly reduce gas fees for traders. This is because multiple orders can be settled in a single transaction.

Improved MEV protection: CoW Protocol uses a unique mechanism to protect traders from Miner Extractable Value (MEV). MEV is a type of transaction fee that miners can extract by strategically ordering transactions. CoW Protocol’s mechanism prevents miners from front-running or sandwiching traders’ orders.

Let’s explore some key features of the CoW protocol.

Batch auctions

Batch auctions are a price-finding mechanism in the CoW protocol. They are used to aggregate and settle orders in a way that maximizes liquidity and minimizes fees for traders.

In a batch auction, orders are submitted off-chain and are not immediately executed. Instead, they are collected and aggregated into batches. Once a batch is full, it is opened for settlement. Solvers compete to submit the best settlement solution for the batch. The solver with the best solution is awarded the fees for the batch.

The settlement solution is a set of instructions that tells the protocol how to execute the orders in the batch. The solver must take into account the liquidity of the assets involved, the fees, and the preferences of the traders.

How do batch auctions work?

  1. Users submit their orders to the CoW protocol.
  2. The orders are grouped into batches.
  3. A solver is chosen to solve the batch auction.
  4. The solver finds the best possible way to match the orders and maximize the traders’ surplus.
  5. The solver submits its solution to the CoW protocol.
  6. The solution is executed and the orders are matched.

Example of how batch auctions work

Let’s say there are two users, Alice and Bob. Alice wants to buy 1 ETH for 100 USDC, and Bob wants to sell 1 ETH for 105 USDC. These two orders could be matched in a batch auction.

The solver would first need to determine the best way to match the orders. It could do this by looking at the prices of ETH and USDC on other exchanges, or by using a more complex algorithm.

Once the solver has determined the best way to match the orders, it will submit its solution to the CoW protocol. The solution would then be executed and the orders would be matched.

In this example, the solver would likely match the orders for 100 USDC per ETH. This is because the difference between Alice’s price and Bob’s price is small, and the solver would want to maximize the traders’ surplus.

Benefits of batch auctions

Batch auctions offer several benefits over traditional order book-based exchanges. These benefits include:

● Liquidity: Batch auctions can aggregate orders from different users, which can improve liquidity.

● Efficiency: Batch auctions can be more efficient than traditional order book-based exchanges, as they can match orders more quickly and accurately.

● Cost savings: Batch auctions can save users money on fees, as they can be more efficient and can aggregate orders from different users.

This stands in stark contrast to the traditional liquidity model that Uniswap uses. Uniswap uses a constant product automated market maker (AMM) model, while CoW Protocol uses a batch auction model.

In an AMM model, liquidity providers deposit tokens into a pool and set a price range for those tokens. Traders can then swap tokens from the pool at the current market price, which is determined by the ratio of the tokens in the pool. The AMM model is simple to use and provides liquidity for traders even when there is no counterparty willing to trade. However, it can be susceptible to front-running attacks, where traders can take advantage of the knowledge of pending trades to profit.

In a batch auction model, orders are grouped together and then settled in a single round. This allows for more efficient use of liquidity and can lead to better prices for traders. However, batch auctions can be more complex to implement and can require more gas fees.

Here is a comparison of the pros and cons of batch auctions used by the CoW Protocol and the traditional AMM liquidity model used by Uniswap:

Batch auctions

Pros:

Lower trading fees: Batch auctions allow CoW Protocol to aggregate orders and execute them together, which can lead to lower trading fees for users.

Reduced MEV: Batch auctions can help to reduce MEV, which is a type of frontrunning attack that can exploit the order book of an AMM.

Improved liquidity: Batch auctions can help to improve liquidity on CoW Protocol by matching orders that would otherwise not be matched on a traditional AMM.

Cons:

Higher latency: Batch auctions can have higher latency than traditional AMM since orders are not executed immediately.

Less flexibility: Batch auctions are less flexible than traditional AMMs since they cannot be used to trade small amounts of tokens.

Traditional AMM liquidity model

Pros:

High liquidity: Traditional AMMs have high liquidity since they can be used to trade any amount of tokens.

Low latency: Traditional AMMs have low latency since orders are executed immediately.

More flexible: Traditional AMMs are more flexible than batch auctions since they can be used to trade small amounts of tokens.

Cons:

Higher trading fees: Traditional AMMs can have higher trading fees than batch auctions since they do not aggregate orders.

More susceptible to MEV: Traditional AMMs are more susceptible to MEV attacks than batch auctions.

Overall, batch auctions offer several advantages over the traditional AMM liquidity model, including lower trading fees, reduced MEV, and improved liquidity. However, they also have some disadvantages, such as higher latency and less flexibility.

Here is a more detailed explanation of the pros and cons of each approach:

Batch auctions

Batch auctions work by collecting orders into batches and then executing them all at once. This can help to reduce frontrunning and sandwich attacks, as it is not possible for miners to frontrun a batch of orders. Batch auctions can also achieve lower spreads than AMMs, as they can match orders with opposite wants together. Additionally, batch auctions can be more efficient than AMMs, as they reduce the number of transactions needed to execute a trade.

However, batch auctions also have some disadvantages. One disadvantage is that they can be less liquid than AMMs. This is because there is less incentive for liquidity providers to provide liquidity to a batch auction, as they cannot earn fees on every trade. Additionally, batch auctions can be more complex to implement than AMMs.

Traditional AMM liquidity model

The traditional AMM liquidity model works by creating a liquidity pool for each asset pair. Liquidity providers can add their tokens to the liquidity pool in exchange for a share of the fees generated by the pool. When a trader wants to trade an asset, they do so by adding or removing liquidity from the pool. The price of the asset is then determined by the ratio of the tokens in the pool.

The traditional AMM liquidity model is simple to implement and understand. It is also liquid, as there is always liquidity available for traders to trade. Additionally, the AMM liquidity model can be used to trade any asset pair.

However, the traditional AMM liquidity model also has some disadvantages. One disadvantage is that it can be vulnerable to frontrunning and sandwich attacks. This is because miners can see the orders that are being placed in the liquidity pool and can then frontrun or sandwich those orders. Additionally, AMMs can have high spreads, especially for illiquid assets. Finally, liquidity providers in AMMs can incur an impermanent loss, which is the loss of value that can occur when the price of the assets in the liquidity pool changes.

When a user places an order on CoW Protocol, it is not immediately executed on-chain. Instead, it is stored off-chain in a queue. Periodically, the orders in the queue are collected and aggregated into batches. A solver then competes to find the best way to settle the batch of orders. The winning solver’s solution is executed on-chain, and the orders in the batch are settled.

CoW Protocol uses a batch auction mechanism to establish the same price of any token pair in the same block. Here’s how it works:

● Traders submit their orders to the CoW Protocol.

● The orders are batched together into groups of similar trades.

● A solver is then used to find the best price for each batch of trades.

● The trades in each batch are then settled at the same price.

The batch auction mechanism ensures that all traders get the same price for the same token pair in the same block, regardless of the order in which their orders were submitted. This is because the solver is not able to see the order in which the orders were submitted.

Compared to the traditional AMM liquidity model which makes use of CFMM (Constant Function Market Maker). — which is a type of AMM that uses a constant function to determine the price of assets. The same trade of the same token pair can have different prices in the same block on a DEX that uses a CFMM. The reason for this is that CFMMs process transactions in sequential order. This means that the order in which the trades arrive at the pool matters. If two trades of the same token pair arrive at the pool in different orders, they will have different prices. Front-running is when a miner sees a trade that is about to be submitted to the pool and then submits a higher-priority trade that takes advantage of the first trade. Sandwiching is when a miner submits two trades that are both designed to profit from the same trade.

The CoW Protocol solves this problem by using a batch auction mechanism. In a batch auction, all of the trades in a batch are processed simultaneously. This means that the order in which the trades arrive at the pool does not matter. All of the trades in the batch will have the same price.

This makes it much more difficult for miners to extract MEV. As a result, the CoW Protocol can help to ensure that all traders get the same price for the same token pairs in the same block.

Coincidence of Wants

Coincidence of wants (also known as double coincidence of wants) is an economic phenomenon where two parties each hold an item that the other wants, so they exchange these items directly without any monetary medium. In other words, both parties must be willing to trade the assets they have for the assets they want. For example, let’s say that Alice has a car and Bob has a house. If Alice wants a house and Bob wants a car, they can trade their possessions directly without the need for money. This is because they have a coincidence of wants.

How does CoW work in cryptocurrency trading?

Coincidence of Wants (CoWs) is a mechanism for settling cryptocurrency trades without the need for an external liquidity provider. It does this by sharing liquidity across all orders that have matching limit prices.

To understand how CoWs work, let’s consider an example. Suppose there are two traders, Alice and Bob, who want to trade the same cryptocurrency. Alice wants to buy 100 tokens, and Bob wants to sell 100 tokens. Their limit prices are both $10 per token. In a traditional cryptocurrency exchange, Alice would need to find a liquidity provider who is willing to sell 100 tokens at $10 per token. If there is no such liquidity provider, then Alice’s trade will not be able to be settled. With CoWs, Alice and Bob can be matched together and their orders can be settled without the need for an external liquidity provider. This is because their limit prices match, so they are both willing to trade at the same price.

The CoW protocol works by first finding all orders that have matching limit prices. In this case, there is only one order that matches Alice and Bob’s orders. This order is called the “matching order”.

The CoW protocol then splits the matching order into two smaller orders: one for Alice and one for Bob. The amount of tokens in each order is equal to the amount of tokens that the trader is willing to buy or sell. The two smaller orders are then settled directly between Alice and Bob. This means that Alice sends Bob $1000, and Bob sends Alice 100 tokens.

In this case, Meredith wants to trade her DAI for ETH, and Eli wants to trade his ETH for DAI.

It’s easier to find Coincidences of Wants by batching trades in Batch Auctions. Invariably, Batch Auctions fuel better CoW and ring trades (which is CoW to nth order). CoW protocol can settle trades internally by CoWs, it can also tap into on-chain AMMs if need be.

Coincidence of Wants maximizes liquidity between two-dimensional orderbook, i.e. between two tokens, or two persons. While ring trades maximizes liquidity on a multidimensional level — between different tokens and/or person. This means that ring trades can find CoW between more than 2 tokens or two persons. Ring trades reduce the need to interact with multiple AMM pools because different token pairs can be matched within the same Batch Auction. In the above example of Meredith and Eli, if Eli didn’t have the ETH Meredith requires, liquidity would need to be accessed from an AMM pool, supplying Meredith with her ETH.

Let’s look at an example below to further illustrate this concept.

Eli wants to trade his ETH for DAI. So he sends it to Edith, who gives her USDT to Lily who gives her COW to Chow, and finally, Chow gives his DAI to Eli. In this scenario, Eli’s trade is settled by going through a three-party Coincidence of Wants ring trade. This logic is also applicable to the other 3 participants.

  1. Edith gets ETH from Eli although she doesn’t have the asset he’s willing to trade for (DAI).
  2. Lily uses Chow, Eli, and Edith to trade COW for USDT.
  3. Chow uses Eli, Edith, and Chow for his DAI to COW trade.

The above example could have been a four-party or five-party Coincidence of Wants ring trades. Ring trades are to the nth-party Coincidence of Wants. To put it in simpler terms, ring trades are multiple CoWs. So while every ring trade is a CoW, not every CoW is a ring trade.

To close out this section, Batch Auctions which are tailored towards Coincidence of Wants via CoW protocol offers better execution price for trades, and batching transactions results in lower spreads.

Signed Orders

CoW protocol offers gas-less transactions. This is in stark contrast to how regular AMMs function. First of all, let me give you a refresher as to how regular transactions work in AMMs where it costs gas.

Regular transactions in AMMs work by interacting with the smart contracts that govern the AMM. When a user wants to trade, they need to send a transaction to the AMM’s smart contract. The transaction needs to specify the amount of the asset that the user wants to trade, as well as the price at which they want to trade it. The AMM’s smart contract will then execute the trade by interacting with the AMM’s liquidity pools. Liquidity pools are collections of assets that are locked into the AMM. Users can provide liquidity to the AMM by depositing assets into the liquidity pools.

When the AMM executes a trade, it takes the assets from the liquidity pools and gives them to the users who are trading. The AMM also charges a trading fee for each trade that it executes. This trading fee is used to reward the liquidity providers. The gas fee for regular transactions in AMMs is paid to the Ethereum network. The gas fee is determined by the complexity of the transaction and the current network conditions.

Example:

Alice wants to trade 1 ETH for 100 DAI on the Uniswap AMM. She creates a transaction that specifies the following:

● Amount of ETH to trade: 1 ETH

● Price: 100 DAI/ETH

She then sends the transaction to the Uniswap smart contract. The Uniswap smart contract executes the trade by interacting with the Uniswap liquidity pools. It takes 1 ETH from the ETH liquidity pool and gives it to Alice. It also takes 100 DAI from the DAI liquidity pool and gives it to Bob.

The Uniswap smart contract also charges a trading fee for the trade. This trading fee is used to reward the liquidity providers.

Let’s now explore the novel concept CoW is championing — signed orders aka gas-free transactions. For users to trade, the CoW protocol doesn’t need to execute transactions. Let me explain. The CoW protocol is composed of two main parts; an allowance manager and a settlement smart contract. The protocol enables gas-free transactions to users using both contracts as it makes use of off-chain orders submitted via signed messages. Recall, that when we discussed Batch Auctions, we said the transactions are sent off-chain. The transactions in Batch Auctions are first signed orders.

Let’s explore how both the allowance manager and settlement smart contract function. Relayers can execute transactions on users’ behalf. Hence, to partake in off-chain orders, users must first approve the vault relayer contracts to execute the signed orders on their behalf. Despite it being a gas-free transaction, you’d have to pay a gas fee for token approval. This is the only transaction where you have to pay a gas fee. Of course, you’d have to pay gas fees to unapprove token spending on your behalf. Once you have done token approval, i.e. give the protocol the ability to spend your tokens executing trades on your behalf, you can now send signed orders via messages off-chain that contain the trade details such as limit price, amount, timestamp, and so on. This is analogous to how the lighting network works. You execute a transaction on the Bitcoin network by opening a channel, you can now make multiple transactions off-chain (in the channel). To close the channel, you’d have to execute another on-chain transaction. Essentially, you can have millions of transactions, with only two being on-chain.

Batch Auctions allow the CoW protocol to work with signed messages. Essentially, what’s being matched in batch auctions is signed orders or intents. The solver adds the signed orders into a batch while checking the order of submission, it also performs CoW or ring trades in the process. Afterwards, the solver sends the batch to the settlement smart contract, which first confirms with the allowance manager to check if approval has been given for the signed order. If approval is given, it then executes the trade on the user’s behalf. It’s at that point the signed order turns into a trade. Users can be guaranteed that transactions they don’t approve via the allowance manager contract will not be executed by the settlement smart contract. Just to make something clear, you’d pay gas fees in the form of LP if your trade is settled by tapping liquidity from on-chain AMMs. So the gas-free transactions are only applicable if your trade can be settled using CoWs or ring trades. As CoW scales, there’d be less need to source liquidity from on-chain AMMs, leading to more gas-free transactions.

To summarize.

● Only funds approved and have a signed order to be sold for another token can be spent.

● Signed orders do expire, and can be canceled but can’t be replayed — this means that there’s no going back once a signed order has been executed.

● Characteristics of the signed order such as limit price, amount of token to be sold etcetera. Will always be satisfied.

● Batch auction settlement is done by only solvers subject to slashing to enable honest practices.

Benefits of Signed Orders

● Gas-free transactions: Users are not charged any gas fees for their trades when using signed orders. This can be a significant savings, especially for users who are making frequent trades.

● Faster trade execution: Signed orders can be executed much faster than traditional on-chain orders, as they do not have to wait for the next block to be mined.

● Improved scalability: CoW Protocol can handle a much higher volume of trades than traditional DEXs, as the solvers can execute multiple orders in a single batch auction.

Challenges of Signed Orders

● Security: Signed orders must be properly secured to prevent them from being tampered with or forged.

● Centralization: The relayer contract is a central point of failure, as it is responsible for executing signed orders on behalf of users.

CoW Swap

CoW Swap is the implementation of everything we have just discussed. It’s the first DEX built on top of the CoW protocol offering gas-free transactions. While CoW Swap has a similar UI as every DEX out there, there are differences between CoW Swap and regular DEXs like Uniswap for instance.

● The most differentiating factor is that CoW Swap makes use of signed orders which enable gas-less transactions. If the price moves against your order, or for any other reason the transaction fails, the order will expire and you won’t have spent gas for nothing. Whereas on UniSwap you’d still spend the gas fees, regardless of your transaction not going through.

● CoW Swap can settle orders across various pools like Uniswap, Paraswap, Sushiswap etcetera. This is in stark contrast to Uniswap where trades can only be settled using Uniswap’s pool.

● CoW Swap enables users to trade among themselves in a peer-to-peer fashion when there are CoWs or ring trades. Removing the need for using liquidity pools and paying liquidity providers’ fees.

CoW Swap connects to all on-chain liquidity across various protocols and doesn’t make use of liquidity providers unless there isn’t a CoW, then the trade has to be settled by accessing on-chain liquidity. Now, here’s the interesting bit, trades settled by tapping into external liquidity cost a fee. Interested market participants can observe the order book and place counter orders to create a CoW, averting the need to access external liquidity.

Also, creating or cancellation of orders doesn’t cost the user anything. If upon canceling, the solution hasn’t been mined, the order will be canceled and the trade will not execute.

CoW Swap supports a host of wallets, mostly EOA wallets like MetaMask, Trustwallet etcetera. Or you can use WalletConnect to import your favorite wallet. Currently, CoW Swap is yet to support smart contract wallets, due to some technical issues. For instance, Smart Contract wallets like Argent or Gnosis Safe will require you to sign an on-chain transaction to place an order. This takes away the gasless nature of CoW Swap. This in my opinion is a huge bottleneck, as the entire crypto industry is gearing towards an AA-induced future, where SC wallets are the thing. I believe the team is working towards this, and soon we’ll get feedback. However, not all EOA wallets are supported. Your wallet should have implemented the EIP-712 standards necessary to sign.

Closing Thoughts

The CoW protocol is a novel and innovative approach to decentralized finance. It introduces several new concepts, such as Batch Auctions, CoWs, Signed Orders, and CoW Swap, which have the potential to revolutionize the way that financial markets operate.

One of the key benefits of the CoW protocol is that it eliminates the need for intermediaries, such as centralized exchanges, or liquidity providers. This makes it more secure and efficient, as users can trade directly with each other without having to trust a third party. Another key benefit of the CoW protocol is that it is very flexible. It can be used to trade a wide variety of assets, including cryptocurrencies, stocks, and commodities. It can also be used to create complex financial products, such as derivatives.

Overall, the CoW protocol is a promising new technology with the potential to have a significant impact on the financial industry. However, it is still under development, and some challenges need to be addressed before it can be widely adopted.

One challenge is that the CoW protocol is still complex and difficult to use. This is a barrier to entry for new users, and it could limit the adoption of the protocol. Another challenge is that the CoW protocol is still relatively new and untested. This means that there is a risk of bugs and security vulnerabilities. Despite these challenges, the CoW protocol is a promising new technology with the potential to revolutionize the way that financial markets operate. The team behind the protocol is actively working to address the challenges mentioned above, and they are committed to making the CoW protocol more accessible and secure.

In the long term, the CoW protocol could have a significant impact on the financial industry. It could make financial markets more efficient and accessible, and it could lead to the development of new and innovative financial products and services.

Additional Thoughts

In addition to the general points made above, there are a few other specific thoughts that I would like to share about the CoW protocol.

First, I think that the CoW protocol has the potential to be very disruptive to the traditional financial industry. By eliminating the need for intermediaries, the CoW protocol could make financial markets more accessible and affordable for everyone. This could lead to a more equitable and inclusive financial system.

Second, I think that the CoW protocol could help to reduce the risk of fraud and manipulation in financial markets. By allowing users to trade directly with each other, the CoW protocol reduces the number of opportunities for fraudsters and manipulators to operate. This could make financial markets more fair and transparent.

Finally, I think that the CoW protocol could lead to the development of new and innovative financial products and services. The flexibility of the CoW protocol makes it possible to create new financial products that are not possible with traditional financial systems. This could lead to a more efficient and innovative financial industry.

Overall, I am very excited about the potential of the CoW protocol. I believe that it has the potential to revolutionize the way that financial markets operate.

--

--

Passie Intelligence

Crypto Researcher II Onchain Analyst II Researching Finance and Tech II