Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions docs/cow-amm/README.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
sidebar_position: 0
sidebar_label: "About CoW AMM"
---

# CoW AMM: The First MEV-capturing AMM

CoW AMM protects LPs from LVR so they can provide liquidity with less risk and more return. CoW AMM achieves close to 5% more in TVL compared to reference pools, protects millions from LVR, and has captured over $100,000 in surplus for LPs to date.
Expand Down
14 changes: 9 additions & 5 deletions docs/cow-protocol/README.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
sidebar_position: 0
sidebar_label: "About CoW Protocol"
---

# CoW Protocol

CoW Protocol is a meta-DEX aggregation protocol that leverages [trade intents](/cow-protocol/concepts/introduction/intents) and [fair combinatorial batch auctions](/cow-protocol/concepts/introduction/fair-combinatorial-auction) to find users better prices for trading crypto assets.
Expand All @@ -18,8 +23,7 @@ Liquidity sources include:

The wide range of liquidity that solvers tap into 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](/category/concepts).**

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

**To dive into the technical details, see [Technical reference](/category/technical-reference).**
**Use the sidebar to navigate through:**
- **Concepts** - Learn about the fundamental concepts behind CoW Protocol
- **Tutorials** - Step-by-step guides for using CoW Protocol
- **Technical Reference** - APIs, SDKs, and smart contract documentation
9 changes: 9 additions & 0 deletions docs/cow-protocol/apis/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"label": "API",
"position": 6,
"collapsible": true,
"collapsed": true,
"link": {
"type": "generated-index"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
sidebar_position: 2
---

import {SwaggerDoc} from '../../../../src/components/swagger-doc/SwaggerDoc';
import {SwaggerDoc} from '../../../src/components/swagger-doc/SwaggerDoc';

# Driver API

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
sidebar_position: 1
---

import {SwaggerDoc} from '../../../../src/components/swagger-doc/SwaggerDoc';
import {SwaggerDoc} from '../../../src/components/swagger-doc/SwaggerDoc';

# Order book API

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
sidebar_position: 3
---

import {SwaggerDoc} from '../../../../src/components/swagger-doc/SwaggerDoc';
import {SwaggerDoc} from '../../../src/components/swagger-doc/SwaggerDoc';

# Solver API

Expand Down
2 changes: 1 addition & 1 deletion docs/cow-protocol/concepts/flash-loans/integrators.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sidebar_position: 2

# How to specify an order with flash loan

The flash loan is encoded into the [appData](/cow-protocol/reference/core/intents/app-data)'s metadata as an optional object. This information serves as a hint for the solver, but the solver ultimately can decide for a different approach in order to make the operation more optimal.
The flash loan is encoded into the [appData](/cow-protocol/reference/intents/app-data)'s metadata as an optional object. This information serves as a hint for the solver, but the solver ultimately can decide for a different approach in order to make the operation more optimal.

It is important to ensure that the flash loan gas overhead is added to the slippage tolerance when creating the order.

Expand Down
2 changes: 1 addition & 1 deletion docs/cow-protocol/concepts/introduction/intents.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Solvers not only scan all available on-chain liquidity (similar to a DEX aggrega
The intent-based architecture of CoW Protocol also provides a number of technical benefits:

- Enabling [solvers](./solvers) to execute all sorts of transactions (not just trades) based on specific instructions and on-chain conditions. This powers products like [CoW Hooks](../order-types/cow-hooks) and [Programmatic Orders](../order-types/programmatic-orders)
- Establishing additional rules for the way orders settle on-chain, such as guaranteeing that the trade is settled at [EBBO](/cow-protocol/reference/core/definitions#ebbo) (Ethereum best bid and offer, guaranteeing that the baseline price for the trade is what on-chain AMMs offer) and uniform clearing prices (where trades with the same token pair in the same batch are cleared at the same price)
- Establishing additional rules for the way orders settle on-chain, such as guaranteeing that the trade is settled at [EBBO](/cow-protocol/reference/definitions#ebbo) (Ethereum best bid and offer, guaranteeing that the baseline price for the trade is what on-chain AMMs offer) and uniform clearing prices (where trades with the same token pair in the same batch are cleared at the same price)
- Allowing users to pay gas fees in their *sell token* without needing to hold the chain-native token (like ETH) in their wallet
- Eliminating fees for failed transactions
- Allowing users to place multiple orders at once
Expand Down
8 changes: 4 additions & 4 deletions docs/cow-protocol/concepts/introduction/solvers.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ CoW Protocol delivers optimal price outcomes by leveraging an open solver compet
Solvers are bonded third parties that execute trades on behalf of users through an [intent-based delegated execution model](intents).

Once a user submits an [intent](intents), the protocol groups it alongside other intents in a batch auction.
As soon as a batch is "closed for orders", meaning that it stops considering new orders, the protocol runs a [competition](/cow-protocol/reference/core/auctions) where solvers submit solutions for the intents in the batch.
As soon as a batch is "closed for orders", meaning that it stops considering new orders, the protocol runs a [competition](/cow-protocol/reference/auctions) where solvers submit solutions for the intents in the batch.

Whichever solver offers the best [solution](/cow-protocol/reference/core/auctions/the-problem#solution) for the batch auction (defined as the solver that provides the most surplus to user orders) gets to execute the orders.
Whichever solver offers the best [solution](/cow-protocol/reference/auctions/the-problem#solution) for the batch auction (defined as the solver that provides the most surplus to user orders) gets to execute the orders.

Solvers are compensated in COW tokens for settling batches, incentivizing them to compete to find better prices and win the right to execute user intents.

## How Solvers Work

Solvers can move tokens on behalf of the user using the `ERC-20` approvals that the user granted to the [vault relayer](/cow-protocol/reference/contracts/core/vault-relayer) contract.
The [settlement](/cow-protocol/reference/contracts/core/settlement) contract, meanwhile, verifies the signature of the user's intent and ensures that execution happens according to the limit price and quantity specified by the user.
Solvers can move tokens on behalf of the user using the `ERC-20` approvals that the user granted to the [vault relayer](/cow-protocol/contracts/core/vault-relayer) contract.
The [settlement](/cow-protocol/contracts/core/settlement) contract, meanwhile, verifies the signature of the user's intent and ensures that execution happens according to the limit price and quantity specified by the user.

Anyone with some DeFi knowledge and ability to code an optimizations algorithm can create a solver.
2 changes: 1 addition & 1 deletion docs/cow-protocol/concepts/order-types/cow-hooks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ These are actions that execute after the swap, taking advantage of trade proceed

## Getting started

To get started with writing a CoW Hook, check out [our technical documentation](/cow-protocol/reference/core/intents/hooks). You can also [read more about CoW Hooks on our blog](https://blog.cow.fi/cow-hooks-you-are-in-control-480ccb40044a) or through our tutorials — [here](https://www.youtube.com/watch?v=FT36lWtC1Oc) and [here](https://www.youtube.com/watch?v=29OaasbqY_g).
To get started with writing a CoW Hook, check out [our technical documentation](/cow-protocol/reference/intents/hooks). You can also [read more about CoW Hooks on our blog](https://blog.cow.fi/cow-hooks-you-are-in-control-480ccb40044a) or through our tutorials — [here](https://www.youtube.com/watch?v=FT36lWtC1Oc) and [here](https://www.youtube.com/watch?v=29OaasbqY_g).
2 changes: 1 addition & 1 deletion docs/cow-protocol/concepts/order-types/limit-orders.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ CoW Protocol's limit orders provide more flexibility and better prices than othe

## Getting started

Wanting to place a limit order? Check out our [limit order tutorial](/cow-protocol/tutorials/cow-swap/limit). You can also [read about limit orders on our blog.](https://blog.cow.fi/the-cow-has-no-limits-342e7eae8794)
Wanting to place a limit order? Check out our [limit order tutorial](/cow-swap/limit). You can also [read about limit orders on our blog.](https://blog.cow.fi/the-cow-has-no-limits-342e7eae8794)
2 changes: 1 addition & 1 deletion docs/cow-protocol/concepts/order-types/market-orders.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ If the solvers are able to find optimizations within the batch auction your orde

## Getting started

Wanting to make a market order? Check out our [market order tutorial](/cow-protocol/tutorials/cow-swap/swap).
Wanting to make a market order? Check out our [market order tutorial](/cow-swap/swap).
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ Thanks to the Programmatic Order Framework, users can automate everything from c

## Getting started

To start developing with the Programmatic Order Framework, check out our [technical documentation](/cow-protocol/reference/contracts/periphery/composable-cow). You can also read more about programmatic orders [on our blog](https://blog.cow.fi/introducing-the-programmatic-order-framework-from-cow-protocol-088a14cb0375).
To start developing with the Programmatic Order Framework, check out our [technical documentation](/cow-protocol/contracts/periphery/composable-cow). You can also read more about programmatic orders [on our blog](https://blog.cow.fi/introducing-the-programmatic-order-framework-from-cow-protocol-088a14cb0375).
2 changes: 1 addition & 1 deletion docs/cow-protocol/concepts/order-types/twap-orders.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ There are also several requirements for placing TWAP orders through CoW Protocol

## Getting started

Wanting to place a TWAP order? Check out our [TWAP order tutorial](/cow-protocol/tutorials/cow-swap/twap). You can also [read about TWAP on our blog.](https://blog.cow.fi/cow-swap-launches-twap-orders-d5583135b472)
Wanting to place a TWAP order? Check out our [TWAP order tutorial](/cow-swap/twap). You can also [read about TWAP on our blog.](https://blog.cow.fi/cow-swap-launches-twap-orders-d5583135b472)
9 changes: 9 additions & 0 deletions docs/cow-protocol/contracts/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"position": 5,
"label": "Contracts",
"collapsible": true,
"collapsed": true,
"link": {
"type": "generated-index"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Core contracts of CoW Protocol are those that are necessary for the protocol to

The goal of the protocol is to bundle multiple user orders together to minimize fees deriving from using external liquidity sources and stave off maximal extractable value.

User orders are signed off-chain and sent to the protocol. [Solvers compete in an auction](../core/auctions/rewards) to settle the orders. Orders without a direct match are settled by the solver using on-chain liquidity sources through the use of _interactions_.
User orders are signed off-chain and sent to the protocol. [Solvers compete in an auction](../reference/auctions/rewards) to settle the orders. Orders without a direct match are settled by the solver using on-chain liquidity sources through the use of _interactions_.

A settlement is a list of orders traded together, their prices, and the on-chain interactions necessary to retrieve external liquidity.

Expand All @@ -36,7 +36,7 @@ CoW Protocol contracts are deployed using deterministic addresses. This means th

:::caution

Take care when [signing](../core/signing-schemes), ensuring that the `EIP-712` domain separator is specified correctly.
Take care when [signing](../reference/signing-schemes), ensuring that the `EIP-712` domain separator is specified correctly.

:::

Expand Down Expand Up @@ -80,7 +80,7 @@ If developing smart contracts that create orders, make sure at a contract level

### `ERC-1271` Replayability

The security of [`ERC-1271`](../core/signing-schemes#erc-1271) signatures depend on the developers' implementation of the _signing smart contract_.
The security of [`ERC-1271`](../reference/signing-schemes#erc-1271) signatures depend on the developers' implementation of the _signing smart contract_.
Different smart contract wallets sign and verify messages very differently from each other.

There's a known issue in some smart-contract wallet implementations that should be known before using `ERC-1271` signatures on CoW Protocol.
Expand All @@ -105,7 +105,7 @@ Signatures from a Safe wallet aren't replayable and don't require any special ha

You are still able to create `ERC-1271` orders from any wallet.

The CoW Protocol API allows you to specify some signed [metadata](../core/intents/app-data) in the order. This metadata can be sent along when creating an order on the CoW Protocol API.
The CoW Protocol API allows you to specify some signed [metadata](../reference/intents/app-data) in the order. This metadata can be sent along when creating an order on the CoW Protocol API.

The signer property in the `metadata` is used by the CoW Protocol API to check that the signature is meant for the specified wallet.
If this doesn't match the order origin, the order is rejected.
Expand All @@ -123,7 +123,7 @@ Once your order is created, the metadata will be permanently stored in the datab
If your signature is valid before your order is submitted and you want to make sure that the no one uses it before your order is submitted on the API, you can send the metadata to the API in advance.
Then, any incoming order with the same app data hash will be rejected if the smart contract wallet doesn't match.

The metadata can be sent in advance to the [API](/cow-protocol/reference/apis/orderbook) using the `PUT` method `/app_data/{app_data_hash}`.
The metadata can be sent in advance to the [API](/cow-protocol/apis/orderbook) using the `PUT` method `/app_data/{app_data_hash}`.

:::caution

Expand All @@ -140,9 +140,9 @@ Therefore, any signatures for a chain on which the `GPv2Settlement` contract has

### Loss of surplus if `ERC-1271` order allows arbitrary app data

An adversary can manipulate vulnerable [`ERC-1271`](../core/signing-schemes#erc-1271) orders, thereby transferring part of the expected surplus from the user order to an address that the adversary controls.
An adversary can manipulate vulnerable [`ERC-1271`](../reference/signing-schemes#erc-1271) orders, thereby transferring part of the expected surplus from the user order to an address that the adversary controls.

This applies to all `ERC-1271` orders where the [app data](/cow-protocol/reference/core/intents/app-data) field can be changed by an adversary in a way that keeps the signature valid for that order (for example, because `isValidSignature` ignores the `appData` field in the order).
This applies to all `ERC-1271` orders where the [app data](/cow-protocol/reference/intents/app-data) field can be changed by an adversary in a way that keeps the signature valid for that order (for example, because `isValidSignature` ignores the `appData` field in the order).

All `ERC-1271` smart-contract order types that can be found in these docs are not affected by this vulnerability.
However, custom smart-contract order implementations may be affected: as usual, users should exercise caution when trading through unvetted smart-contract orders.
Expand All @@ -155,7 +155,7 @@ Possibly the easiest way to avoid being affected by this issue is:

But as long as untrusted parties cannot manipulate the app data of a valid `ERC-1271` order, an implementation is not affected.

The mechanism that allows surplus extraction from arbitrary app data possible is [partner fees](/governance/fees/partner-fee).
The mechanism that allows surplus extraction from arbitrary app data possible is [partner fees](/cow-dao/fees/partner-fee).
Partner fees are encoded in the app data struct and are accounted for once the order is included in the settlement.

From the perspective of the API, two orders with the same parameters and the same owner but different app data are two different valid orders.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Interactions allow solvers to execute arbitrary calls to any on-chain contract.
<details open>
<summary>Protocol fee collection</summary>

Interactions are also used for accounting / bookkeeping purposes as well. As trades are executed, the Protocol collects a fee from each trade and stores this in the settlement contract (known as <em><a href="/cow-protocol/reference/core/definitions#buffers">internal buffers</a></em>). At regular intervals, the Protocol withdraws the fees from the settlement contract to the Protocol's treasury Safe.
Interactions are also used for accounting / bookkeeping purposes as well. As trades are executed, the Protocol collects a fee from each trade and stores this in the settlement contract (known as <em><a href="/cow-protocol/reference/definitions#buffers">internal buffers</a></em>). At regular intervals, the Protocol withdraws the fees from the settlement contract to the Protocol's treasury Safe.

</details>

Expand All @@ -67,7 +67,7 @@ Allowing interactions by solvers, creates the possibility of malicious solvers t
The `GPV2Order.Data` is the one of the most important data structures in the Protocol. It:

- defines the parameters of an order
- is the basis of which the order digest is determined using `EIP-712` and subsequently [signed](../../core/signing-schemes) by the user
- is the basis of which the order digest is determined using `EIP-712` and subsequently [signed](../../reference/signing-schemes) by the user

In code, it is defined as:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ id: composable-cow

# ComposableCoW

ComposableCoW is a framework for smoothing the developer experience when building conditional orders on CoW Protocol. Conditional orders are a subset of [`ERC-1271`](../../core/signing_schemes.mdx#erc-1271) smart contract orders. It allows one to create conditional orders that:
ComposableCoW is a framework for smoothing the developer experience when building conditional orders on CoW Protocol. Conditional orders are a subset of [`ERC-1271`](../../reference/signing-schemes#erc-1271) smart contract orders. It allows one to create conditional orders that:

1. Can be used to generate multiple discrete order (self-expressing)
2. Assess a proposed order against a set of conditions (self-validating)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ slug: eth-flow

# Eth-flow

As CoW Protocol only [supports `ERC-20 tokens`](../../core/tokens), this means that if a user wants to sell `ETH` on CoW Protocol, they need to:
As CoW Protocol only [supports `ERC-20 tokens`](../../reference/tokens), this means that if a user wants to sell `ETH` on CoW Protocol, they need to:

1. Convert their `ETH` into `WETH`
2. Approve the [vault relayer](../core/vault-relayer) for spending their `WETH`
Expand All @@ -15,7 +15,7 @@ This process is time-consuming and potentially costly for the user and is why we

## Architecture

An intermediary smart contract is used to wrap `ETH` into `WETH` and create an intent on behalf of the user. This contract then expresses the users' intent to trade on CoW Protocol using an [`ERC-1271`](../../core/signing-schemes#erc-1271)-signed intent.
An intermediary smart contract is used to wrap `ETH` into `WETH` and create an intent on behalf of the user. This contract then expresses the users' intent to trade on CoW Protocol using an [`ERC-1271`](../../reference/signing-schemes#erc-1271)-signed intent.

```mermaid
sequenceDiagram
Expand Down Expand Up @@ -101,7 +101,7 @@ The user intent described below is not a valid intent for the settlement contrac

### Contract order signing

The contract order uses [`ERC-1271`](../../core/signing-schemes#erc-1271) signatures.
The contract order uses [`ERC-1271`](../../reference/signing-schemes#erc-1271) signatures.

The `signature` is empty, since all information needed to verify the order can be found on-chain.

Expand Down
Loading