# Implementation - COW AMM

## **Overview**

CowSwap has introduced a new approach to trading: A delegated trading model through an `Order Flow Auction` that runs on `batch auctions`to find the best settlement for all the trades. In batch auctions, traders submit their intent to trade a token pair without settling their trades directly on-chain. Solvers handle transaction creation, allowing traders to avoid fine-tuning parameters like liquidity pools and slippage. This approach provides better prices and MEV protection.&#x20;

### **Auction Mechanics**

In the CowSwap auction, solvers compete to propose optimal solutions for executing the batch trades. These solutions may involve leveraging external liquidity sources such as existing automated market makers (AMMs) or collaborating with private market makers to access otherwise unavailable liquidity. Additionally, solvers may explore internal liquidity within the batch, facilitating direct trades between participants seeking complementary assets.

### Price Improvement

Price improvement refers to securing the best possible price for a trade. CoW Swap brings to decentralized trading, the concept of `surplus`, to ensure traders get optimal prices. When a trader submits a signed order, it goes to an off-chain orderbook and into a `batch auction`. Solvers then search all available on-chain liquidity to determine the best clearing price.

CoW Swap improves pricing by batching orders and establishing a `uniform clearing price`, creating a more liquid environment. Coincidences of Wants (CoWs) enable direct peer-to-peer transactions, bypassing intermediary AMM pools, reducing slippage, and avoiding additional fees.

In the trading UI, CoW Swap quotes the minimum price a trader will receive, often providing price surplus by delivering more of the desired tokens. This method enhances trading efficiency and benefits traders with better prices

## The CoW AMM

A Cow Automated Market Maker (COW AMM) is a specialized type of market maker integrated directly within CowSwap's batch trading system. Unlike traditional market makers, COW AMM operates exclusively within CowSwap's batch environment, offering continuous liquidity to traders participating in batch auctions. The integration of a COW AMM within CowSwap's batch trading system significantly enhances liquidity provision and trading efficiency.&#x20;

COW AMM behaves like any other trader within the batch, submitting trade intentions alongside other participants. However, it differs in that it functions as a permanent liquidity provider, always available to facilitate trades within the batch. While a standard limit order is executed and disappears, a COW AMM remains active, continuously providing liquidity for subsequent trades. Similar to other traders within the batch, a COW AMM is subject to competition among solvers bidding for the right to execute trades. Solvers must compete to access the COW AMM, offering proposals that maximize surplus for traders. The solver offering the most surplus wins the opportunity to trade with the COW AMM.

### Defining Surplus in CoW AMM

Surplus, in the context of the COW AMM, is determined by the impact of a solver's proposed trade on the AMM curve. Specifically, it measures how much a proposed trade shifts the AMM curve upwards. By accepting a solver's proposal, CowSwap effectively moves to a higher liquidity curve relative to the AMM's current position. Therefore, surplus in COW AMM is quantified by the degree to which a proposed trade enhances liquidity within the batch.

### **Benefits for Liquidity Providers**

Liquidity providers (LPs) on CoW Swap enjoy two main benefits:

1. **Elimination of Impermanent Loss (IL)**: The automated market maker (AMM) is rebalanced using external liquidity when the local price deviates from external markets (e.g., Uniswap). Solvers compete to ensure trades occur at or near the correct price, eliminating impermanent loss. This creates a passive investment strategy where an LP's wealth remains equally balanced between the two AMM assets.
2. **Surplus as Fees**: The AMM can match trades within the batch, earning surplus akin to fees in traditional AMMs. This occurs when another trader in the batch trades the same token, allowing the AMM to earn surplus from these internal trades.

### Current Implementation of CoW AMM

The COW AMM is live, and anyone can deploy one, though it requires setting up a multisig safe dedicated to running the AMM. There are two methods for deployment:

1. **Documentation**: Detailed instructions are available[ here.](https://docs.cow.fi/cow-protocol/tutorials/cow-amm-deployer)
2. **Safe App**: The COW Deployer app can be used on Ethereum or the Gnosis Chain

### Limitations and Requirements

* **Single LP and Token Pair**: Each COW AMM supports only one liquidity provider and one token pair, making it suitable for DAOs or large investors on Ethereum due to gas costs. On the Gnosis Chain, it's more accessible to everyone due to negligible fees.
* **Oracle Specification**: Deployers must specify an oracle. The system uses the oracle price to compare with the local AMM price. When discrepancies arise, it generates a trade order to align the local price with the oracle price. Solvers then execute these trades to maintain price equilibrium.

### **Next Steps for CoW AMM Development**

The next phase of CoW AMM development involves several key initiatives:

1. **Enhanced Solver Access to Liquidity**: Enabling solvers to access CoW AMM liquidity more freely will reduce reliance on the oracle and allow for better matching of user orders. This will result in increased surplus and fees for CoW AMMs.
2. **Introduction of Multi-Tokens CoW AMM**: Implementation of multi-tokens CoW AMM will enable more sophisticated investment strategies. This expansion beyond single-token pairs will offer users greater diversification and investment flexibility.
3. **Concentrated Liquidity**: Concentrating liquidity within CoW AMMs will lead to higher fee generation. However, this may come at the expense of some tracking error in the investment strategy.
4. **Multi-Liquidity Providers (LPs) CoW AMM**: Exploring the possibility of incorporating multiple LPs into CoW AMMs will further enhance liquidity provision and trading efficiency.
