Skip to content

Create slippage-protection.mdx #472

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 174 additions & 0 deletions docs/cow-protocol/tutorials/cow-swap/slippage-protection.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
---
sidebar_position: 4
---

Slippage Protection and Risk Management in CoW Protocol
=======================================================

Overview
--------

This section explains an important aspect of CoW Protocol that affects all users: the relationship between slippage tolerance, solver bonds, and risk management. Understanding these concepts is crucial for safely using CoW Protocol, especially when placing large orders or implementing automated trading systems.

ELI5: Slippage Protection Simplified
------------------------------------

**What is slippage?**
Slippage is when you expect to get one price for your trade, but you end up getting a different (usually worse) price.

**How does CoW Protocol handle slippage?**
CoW Protocol has "solvers" who find the best prices for your trades. These solvers put down a security deposit (called a "bond") of approximately $1.5 million to guarantee they'll do a good job.

**The important part:**
If you set a very high slippage tolerance on a large trade, and that tolerance amount is worth more than the solver's bond, there's a risk the solver might give you a bad price on purpose and run away with the difference. This is because they could make more money by cheating than they would lose from their bond.

**What to do:**
Break large trades into smaller pieces, use reasonable slippage settings, or use tools like TWAP (Time-Weighted Average Price) for large orders.

Detailed Explanation
--------------------

### How Slippage Protection Works in CoW Protocol

CoW Protocol employs a unique architecture where "solvers" compete to find the best execution prices for users. These solvers must post a bond (approximately $1.5 million in value, consisting of stablecoins and COW tokens) that can be slashed if they engage in malicious behavior.

This bond serves as both a security measure and an economic incentive mechanism to ensure solvers act in the best interest of users. However, it also creates an upper boundary for the protocol's native slippage protection.

### The Risk Model

Slippage protection in CoW Protocol is implemented through a combination of economic incentives, governance mechanisms, and technical safeguards:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section reads weirdly to me:

Slippage protection [...] is implemented [...] by:
1. Having a bond (ok)
2. Allowing execution of orders at any signed price (what?)
3. Large orders are at risk (what?)
4. Security mechanisms (ok)

I'd try to separate the parts "what are the risks for the user, what the user should be careful about" and "what we do to mitigate those risks".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking forward: it looks like the former is part of "Safe Usage Guidelines" and the latter is part of "Recommendations," with some repeating content. Maybe this section can be dropped?


1. Solver bonds as security measure - Solvers post significant bonds (approximately $1.5 million in value) that can be slashed in case of malicious behavior.

2. Economic considerations - When a user places an order with a certain slippage tolerance, they're essentially allowing execution at any price within that range.

3. Risk awareness - For particularly large orders with high slippage tolerance, users should be aware that:

- The potential value at risk is tied to both order size and slippage settings

- Additional precautions become increasingly important as order values grow

5. Security layers - The protocol employs multiple protective mechanisms:
Comment on lines +45 to +51
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note the skip between 3 and 5.


- On-chain limit price enforcement

- Off-chain monitoring systems

- Governance-based oversight

- Slashing procedures

This multi-layered approach provides robust protection for most trading scenarios, though users executing exceptionally large trades should implement additional risk management practices.

### Practical Implications

- For small to medium trades: The solver bond offers strong protection as the potential gain from exploiting slippage doesn't exceed the bond value.

- For large trades: If the potential slippage value exceeds the solver bond, users need to implement additional protection measures.

- For treasury managers and institutional users: Understanding this model is critical when implementing automated trading systems or managing large portfolios through CoW Protocol.

### Safe Usage Guidelines

To safely use CoW Protocol for all trade sizes:

1. Manage slippage settings - Use reasonable slippage tolerances proportional to your trade size.

2. Break up large trades - Split substantial orders into smaller batches to ensure potential slippage remains below the solver bond value.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For clarity. Having 1 large order or 10 small orders that sum up to the same parameters of the large one is basically the same in terms of risks if they are all active at the same time.

Suggested change
2. Break up large trades - Split substantial orders into smaller batches to ensure potential slippage remains below the solver bond value.
2. Break up large trades - Execute substantial orders in smaller batches one after the other to ensure potential slippage remains below the solver bond value.


3. Use TWAP functionality - For large orders, CoW Protocol's Time-Weighted Average Price (TWAP) feature can automatically spread execution across multiple batches.

4. Consider additional safeguards - For specialized applications (like ZRM-based treasury management), implement additional validation logic like:

- Maximum sell amount limits per token

- Integration with external price oracles

- Custom slippage validation mechanisms

Technical Implementation Details
--------------------------------

### The Solver Bond Mechanism

Solver bonds on CoW Protocol are implemented through dedicated bonding pools, which contain:

- Approximately $500,000 in yield-bearing stablecoins

- 1,500,000 COW tokens

- For reduced bonding pools: $50,000-100,000 in stablecoins/ETH and 500,000-1,000,000 COW tokens

These bonds are managed through dedicated Gnosis Safes, with specific rules for creation, management, and dissolution outlined in the protocol documentation.

### Slippage Accounting

CoW Protocol implements what's called "slippage accounting" where:

1. Token imbalances within the settlement contract resulting from a settlement are assigned to the corresponding solver.

2. This creates a direct financial responsibility for solvers managing token balances in the protocol.

3. Legitimate use of internal buffers is allowed to replace AMM interactions and save on gas costs, but systematic abuse is prohibited.

### Enforcement Mechanisms

The protocol employs multiple layers of protection:

1. Smart contract constraints - Such as limit price validation.

2. Off-chain protocol rules - Including uniform clearing prices.

3. Governance rules - Including monitoring for EBBO violations, objective function inflation, illegal buffer use, and pennying/overbidding.

4. Slashing procedures - In case of violations, solvers face a structured process for reimbursement or bond slashing through CoW DAO governance.

### Risk Calculation Example

For a practical understanding, consider this calculation:

If a trade involves selling 1,000 ETH, and the user sets a 1% slippage tolerance:

- At an ETH price of $3,000, the total order value is $3,000,000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ something $ is interpreted as math and is displayed weirdly.

image

This appears to work for escaping it:

Suggested change
- At an ETH price of $3,000, the total order value is $3,000,000
- At an ETH price of \$3,000, the total order value is \$3,000,000

You may want to use \$ instead of $ everywhere in the document to avoid missing it, but it's also ok to only fix the issue where it's encountered.


- The 1% slippage tolerance represents $30,000 of potential value

- This is well below the solver bond value (~$1.5 million), providing adequate protection

However, if selling 100,000 ETH with 2% slippage:

- Total order value: $300,000,000

- Potential slippage value: $6,000,000

- This exceeds the solver bond, creating potential risk

Recommendations
---------------

1. For DeFi users: Be mindful of slippage settings, especially for large trades. Consider splitting larger trades into multiple smaller ones.

2. For developers: When building on CoW Protocol or implementing trading systems:

- Implement additional validation logic for large trades

- Consider custom slippage management for different token types and market conditions

- Use TWAP for large order execution

4. For treasury managers: When setting up systems like Zodiac Role Modifiers:
Comment on lines +151 to +159
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note the skip between 2 and 4.


- Include maximum order size limits

- Implement additional price validation where possible

- Consider segregating permissions for different trade sizes

Conclusion
----------

Understanding slippage risk in CoW Protocol is important for all users, particularly those handling large trades. The protocol employs multiple layers of protection including solver bonds, monitoring systems, and governance mechanisms to ensure fair trade execution.

For everyday users, the existing protections provide robust security for typical trading activity. For institutional users, treasury managers, and those handling exceptionally large trades, implementing additional risk management practices is recommended as a prudent approach.

By taking appropriate precautions based on trade size and context, users can confidently leverage CoW Protocol's innovative batch auction mechanism while effectively managing slippage risk.