Skip to content

Commit

Permalink
chore: concepts (#256)
Browse files Browse the repository at this point in the history
# Description

wip: concepts

## Related Issues

Fixes #63
Fixes #92 
Fixes #95 
Fixes #61 
Fixes #56 
Fixes #131 
Fixes #96
Fixes #75

---------

Co-authored-by: mfw78 <[email protected]>
  • Loading branch information
marshymarsh and mfw78 authored Dec 31, 2023
1 parent deca94c commit 84aa439
Show file tree
Hide file tree
Showing 74 changed files with 501 additions and 328 deletions.
6 changes: 3 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sidebar_position: 1

CoW DAO is on a mission to innovate the most user-protective products in Ethereum. 

Currently, CoW DAOs two main products are [**CoW Protocol**](cow-protocol) and [**MEV Blocker**](https://mevblocker.io), which it supports with development and marketing resources – including the [CoW Grants Program](governance/grants), the [CoW Protocol Explorer](cow-protocol/tutorials/cow-explorer), and the [CoW Swap frontend](cow-protocol/tutorials/cow-swap).
Currently, CoW DAO's two main products are [**CoW Protocol**](cow-protocol) and [**MEV Blocker**](https://mevblocker.io), which it supports with development and marketing resources – including the [CoW Grants Program](governance/grants), the [CoW Protocol Explorer](cow-protocol/tutorials/cow-explorer), and the [CoW Swap frontend](cow-protocol/tutorials/cow-swap).

## What is [CoW Protocol](cow-protocol)

Expand All @@ -21,9 +21,9 @@ MEV Blocker is an RPC endpoint designed to protect user transactions from MEV (M

CoW DAO is of its community, by its community, and for its community. CoW DAO uses a [decentralized governance model](governance) to ensure that the community has full control over the direction of the protocol.

## How to use CoW DAOs documentation
## How to use CoW DAO's documentation

CoW DAOs documentation follows a "Concepts", "Procedures", "Technical Reference" methodology. For example when a user wants to learn:
CoW DAO's documentation follows a "Concepts", "Procedures", "Technical Reference" methodology. For example when a user wants to learn:

- **_What_** something is (example: batch auctions) → see [Concepts](cow-protocol/concepts)
- **_How_** to do something (example: create an order) → see [Tutorials](cow-protocol/tutorials)
Expand Down
25 changes: 15 additions & 10 deletions docs/cow-protocol/README.mdx
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
# CoW Protocol

CoW Protocol matches users' trade intents via batch auctions from a variety of on-chain liquidity sources and private market makers.
CoW Protocol is a meta-DEX aggregation protocol that leverages [trade intents](cow-protocol/concepts/introduction/intents) and [batch auctions](cow-protocol/concepts/introduction/batch-auctions) to find users better prices for crypto trades.

When matching intents, CoW Protocol first seeks a _Coincidence of Wants_ (CoW) within the existing batch to offer an even better price than any pool/market maker can. If no CoW is found, CoW Protocol solvers then seek to find the best price for a trade from available on-chain and off-chain liquidity.
![What is CoW Protocol](/img/what-is-cow-protocol.png)

On-chain liquidity sources include:
- AMMs (e.g. Uniswap, Sushiswap, Balancer, Curve, etc)
- DEX Aggregators (e.g. 1inch, Paraswap, Matcha, etc)
- Private Market Makers (e.g. 0x, Hashflow, Bebop, etc)
The protocol relies on third parties known as "[solvers](cow-protocol/concepts/introduction/solvers)" to find the best execution paths for trade intents — signed messages that specify conditions for executing transaction on Ethereum and EVM-compatable chains.

Therefore, CoW Protocol is essentially an aggregator of aggregators.
Upon first receiving a user intent, the protocol groups it alongside other pending intents in a [batch](cow-protocol/concepts/introduction/batch-auctions). When executing trade intents, solvers first try to find a [*Coincidence of Wants (CoW)](cow-protocol/concepts/introduction/coincidence-of-wants)* within the existing batch to offer an optimal price over any on-chain market maker. If the protocol does not find a CoW, the solvers search all available on-chain and off-chain liquidity to find the best price for a set of trade intents within a batch.

To learn more about the concepts CoW Protocol makes use of, see [Concepts](cow-protocol/concepts).
Liquidity sources include:

For more info on how to use CoW Protocol or CoW Swap, see [Tutorials](cow-protocol/tutorials).
- AMMs (e.g. Uniswap, Sushiswap, Balancer, Curve, etc.)
- DEX Aggregators (e.g. 1inch, Paraswap, Matcha, etc.)
- Private Market Makers (e.g. 0x, Hashflow, Bebop, etc.)

To dive into the technical details, see [Technical reference](cow-protocol/reference).
This delegated trade execution architecture makes CoW Protocol a meta-DEX aggregator, or an aggregator of aggregators.

**To learn more about the concepts CoW Protocol makes use of, see [Concepts](cow-protocol/concepts).**

**For more info on how to use CoW Protocol or CoW Swap, see [Tutorials](cow-protocol/tutorials).**

**To dive into the technical details, see [Technical reference](cow-protocol/reference).**
7 changes: 0 additions & 7 deletions docs/cow-protocol/concepts/batch-auctions/mev-protection.md

This file was deleted.

4 changes: 4 additions & 0 deletions docs/cow-protocol/concepts/benefits/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"position": 4,
"label": "Benefits"
}
13 changes: 13 additions & 0 deletions docs/cow-protocol/concepts/benefits/additional-benefits.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
sidebar_position: 4
---

# Additional benefits

CoW Protocol's [intent-based trading model](../introduction/intents) provides a number of benefits, including support for expressing any intent, MEV protection, and price improvement. There are also a handful of additional benefits unique to CoW Protocol thanks to its specific architecture:

- Gasless trades (users pay settlement fees in their sell token; settlement fees can be lower than gas fees if the trade is included in a batch)
- No fees for failed or cancelled orders (most exchanges make users pay gas fees regardless of whether their order executes or not)
- Order settlement at Ethereum Best Bid Offer or better
- Support for placing multiple orders at once
- Slippage protection on all orders
21 changes: 21 additions & 0 deletions docs/cow-protocol/concepts/benefits/mev-protection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
sidebar_position: 2
---

# MEV protection

One of the main benefits of CoW Protocol is comprehensive MEV protection for every order.

There are three main features that protect users from MEV:

- **Uniform Clearing Prices**: If the same token pair (such as ETH-USDC) is traded multiple times in the same [batch](../introduction/batch-auctions), the assets will clear for the same market prices for each trade.
This mechanism is called a "uniform clearing price" and it makes transaction order irrelevant, so MEV bots cannot re-order trades in order to extract a profit.
Uniform clearing prices enable the Ethereum DeFi ecosystem to establish consistent prices for identical token pairs within the same block, addressing the inconsistency caused by the design of Constant Function Market Makers (CFMMs) like traditional Uniswap liquidity pools.
- **Delegated Trade Execution**: On CoW Protocol, bonded third parties known as [solvers](../introduction/solvers) execute trades on behalf of users.
This means that users are never directly exposed to MEV on-chain (though the solvers may be).
The winning solver is required to give users the price they signed or greater, meaning that solvers take on all price risk from potential MEV attacks.
Solvers are professional parties, so they calculate the optimal slippage for each trade and match liquidity off-chain through CoWs or private market makers when possible in order to reduce MEV risk.
- **MEV Blocker Integration:** As a final defense against MEV, CoW Protocol utilizes [MEV Blocker](https://mevblocker.io/) for all order settlements on Ethereum.
MEV Blocker is an RPC endpoint that bypasses the public mempool, protecting orders from MEV exploitation

Read more about CoW Protocol's unparalleled MEV protection [on our blog](https://blog.cow.fi/how-cow-swap-solves-the-mev-problem-fd35b0127390).
19 changes: 19 additions & 0 deletions docs/cow-protocol/concepts/benefits/price-improvement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
sidebar_position: 3
---

# Price improvement

In addition to [MEV protection](./mev-protection), another major benefit of CoW Protocol is optimal price execution that leads to price improvement and order surplus.

All orders on CoW Protocol have the ability to capture surplus.
This means that if there is a positive difference between the quote you receive before placing your order and the price that the order executes at, you will receive the difference as surplus.
CoW Protocol even offers surplus on [limit orders](../order-types/limit-orders) and [TWAP orders](../order-types/twap-orders)!

When orders do not receive significant price surplus, [solvers](./introduction/solvers) still find the optimal execution path for each trade across all available on-chain and off-chain liquidity.
With CoW Protocol, users can receive better prices than they would on another DEX or DEX aggregator thanks to:

- **Efficient Order Routing:** Solvers search all available on-chain liquidity to get the best rates for the trades in a batch at the time the orders are executed.
Sometimes a solver will split a trade between multiple liquidity sources to reduce price impact.
- **Private Off-Chain Liquidity**: Solvers may also have access to private market maker liquidity that provides better prices that on-chain liquidity and is not indexed by other DEXs or aggregators.
- **Coincidence of Wants**: Peer-to-peer [Coincidences of Wants](../how-it-works/coincidence-of-wants) match traders against each other and give better prices because they cost less in gas and avoid liquidity provider fees charged by AMMs.
13 changes: 13 additions & 0 deletions docs/cow-protocol/concepts/benefits/trade-any-intent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
sidebar_position: 1
---

# Trade any intent

CoW Protocol allows users to express any type of trade intent on Ethereum and EVM-compatable chains, leveraging [solvers](../introduction/solvers) to execute the transactions through the most optimal route.

The protocol supports any order logic which includes standard market and limit orders, but also advanced order types such as [TWAP](../order-types/twap-orders). Thanks to ERC-1271, smart contracts can also submit intents, paving the way for the [Programmatic Order Framework](../order-types/programmatic-orders) and contracts like [Milkman](../order-types/milkman-orders).

Finally, intents aren't limited to trading alone. [CoW Hooks](../order-types/cow-hooks) allow users to specify any set of Ethereum actions that they would like the solvers to execute before or after a trade.

So whether you want to create an automated trading strategy that runs based on on-chain conditions, bridge & swap all in a single intent, or just place a simple market order, CoW Protocol has got you covered.
4 changes: 4 additions & 0 deletions docs/cow-protocol/concepts/how-it-works/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"position": 2,
"label": "How it works"
}
53 changes: 53 additions & 0 deletions docs/cow-protocol/concepts/how-it-works/coincidence-of-wants.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
sidebar_position: 2
---

# Coincidence of Wants

**CoW (Coincidence of Wants)**: Thanks to CoW Protocol's batching mechanism, users can make peer-to-peer swaps in cases where they're trading the same assets.

For example, if one trader in a batch wants to sell \$2,000 of DAI for 0.5 ETH and another trader in the same batch wants to sell 0.5 ETH for $2,000 DAI, CoW Protocol's solvers will match both traders together so they can swap assets without tapping into on-chain liquidity - saving them from incurring liquidity provider fees.

CoWs allow users to bypass liquidity provider (LP) fees and also reduce gas fees since orders only interact with CoW Protocol's smart contracts.

CoWs can be full or partial. In a partial CoW, only one of the trades in a batch is completely filled with opposing liquidity, and solvers must source liquidity to fill the rest of the other trade.

## Types of CoWs


### Simple

![Simple CoW](/img/concepts/simple-cow.png)

A simple CoW is where two traders are each selling what the other is buying.
They swap assets with each other instead of interacting with AMM liquidity pools.
Simple CoWs can be either *complete*, where each trader is trading exactly the same amount that the other needs, or they can be *partial* where two traders are trading opposite assets but only one can have their full liquidity met through a CoW.
In the latter case, the rest of the trade goes on-chain to finish filling.

### Batching

![Batching CoW](/img/concepts/batching-cow.png)

Often, a batch auction contains multiple intents from different users who all want to perform the same trade.
Instead of sending their trades individually one by one, solvers can batch all of the intents together and execute them as a single trade on-chain.
Although a batching CoW goes on-chain, this optimization reduces gas fees, as users trades interact with AMM smart contracts fewer times.

### Intermediate

![Intermediate CoW](/img/concepts/intermediate-cow.png)

An intermediate CoW occurs when there are "intermediate" trades that can be settled peer-to-peer.
For example, if one party is trading CRV for USDT and another party is trading USDT for COW, the trades may require an intermediate "ETH" trade.
The first trader may need to go from CRV to ETH and then ETH to USDT.
The second trader may need to go USDT to ETH and then ETH to COW.
In this example, the ETH to USDT trade of the first trader and USDT to ETH trade of the second trader can be filled peer-to-peer as a CoW.

### Multidimensional (Ring)

![Multidimensional CoW](/img/concepts/ring-cow.png)

A multidimensional CoW consists of three or more users and shares liquidity between each of their trades.
It often includes multiple assets and relies on the solvers to find the optimal path from each user to the next in order to maximize off-chain liquidity utilization.

While some orders are filled entirely through a CoW, many are only partially filled peer-to-peer.
In these latter cases, solvers automatically go on-chain to source the rest of the liquidity necessary to finish filling the order.
26 changes: 26 additions & 0 deletions docs/cow-protocol/concepts/how-it-works/flow-of-an-order.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
sidebar_position: 1
---

# Flow of an order

Rather than creating executable on-chain transactions, CoW Protocol users submit their orders as signed [*intent to trade*](../introduction/intents-to-trade) messages.
This allows solvers to find the optimal execution path for the batch of orders before committing them on-chain.

Let's bring all of our main concepts together by taking a look at the flow of an order through CoW Protocol.

![Flow of an order through CoW Protocol](/img/concepts/flow-of-an-order.png)

There are 4 main steps to an order on CoW Protocol:

1. Users express their trade intents by signing messages that specify the assets and amounts they want to trade, alongside other parameters.
2. The protocol gathers the intents of multiple users into a [batch auction](../introduction/batch-auctions).
3. Solvers have a set amount of time to propose settlements for the batch. The solver that is able to generate the highest amount of surplus for the batch is declared the winner.
4. The winning solver executes a single transaction on-chain, settling all orders in the batch on behalf of the users.

Once the winning solver executes the batch's orders on-chain, users receive their tokens.

The competition between solvers in a batch auction ensures that users (including traders, DAOs, smart contracts, and bots) always receive the best prices for their trades.

Letting solvers do the heavy lifting means users don't have to worry about finding the best liquidity pool, setting the right gas price, or picking the optimal slippage tolerance for their trades.
Solvers are also experts at avoiding MEV so users can rest assured their orders are protected from MEV bots that exploit their price through frontrunning and sandwich attacks.
38 changes: 38 additions & 0 deletions docs/cow-protocol/concepts/how-it-works/protocol-vs-swap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
sidebar_position: 3
---

# CoW Protocol vs. CoW Swap

While the two are intertwined, there are important differences between CoW Protocol and CoW Swap.

![CoW Protocol vs. CoW Swap](/img/concepts/protocol-vs-swap.png)

## CoW Protocol

CoW Protocol is a trading protocol that leverages [intents](../introduction/intents) and [batch auctions](../introduction/batch-auctions) to find optimal prices and protect orders from Maximal Extractable Value (MEV).

The protocol groups orders together into batches and relies on a competition between third parties, known as [solvers](../introduction/solvers), to find the best execution price for each batch.

Solvers search all available on-chain liquidity and even tap off-chain private inventory to fill orders.
If two orders in a batch are swapping opposite assets, solvers match them together in a peer-to-peer [*Coincidence of Wants (CoW)*](cow-protocol/concepts/how-it-works/coincidence-of-wants) trade.

Once they have found their solutions, solvers compete to win the right to settle a batch of orders.
The protocol runs a solver competition and picks the "winning" solver to settle each batch of orders, defined as the solver that can maximize surplus for traders.
Solvers typically win the competition by finding the best combination of on- and off-chain liquidity sources, the most optimal CoW, the most efficient technical execution, or a combination of these in a single settlement.

## CoW Swap

CoW Swap was the first trading interface built on top of CoW Protocol and is currently the most popular way for users to trade with CoW Protocol.

Other trading apps and dApps, like Balancer, have also integrated CoW Protocol natively within their trading interfaces and advanced traders often place trades directly through the protocol.

The UI of CoW Swap includes some unique features, such as:

- Wallet history
- User token balances
- Games
- The legendary "Moo" sound
- Fortune cookies

CoW Swap works with many popular wallets, including [Rabby](https://rabby.io/), [MetaMask](https://metamask.io/), [Trust Wallet](https://trustwallet.com/), [Safe](https://safe.global/), [Trezor](https://trezor.io/), [Ledger](https://www.ledger.com/), and any wallet supporting [WalletConnect v2](https://walletconnect.com/).
Loading

0 comments on commit 84aa439

Please sign in to comment.