Skip to content

policy: Implement "Max Slippage" Guard for Uniswap Trades #4

@akarlaraytu

Description

@akarlaraytu

📝 Context

DeFi agents often execute trades in low-liquidity pools. We need a safety policy to prevent the agent from getting "sandwiched" or losing money due to high slippage.

🎯 The Goal

Write a CSL policy that acts as a hard constraint for a trading bot.

Variables you can use:

  • price_impact (Float): The percentage impact on the pool (e.g., 2.5 for 2.5%).
  • slippage_tolerance (Float): The user's setting (e.g., 0.5).
  • is_verified_pool (Boolean): Whether the token contract is verified.

Requirements:

  1. BLOCK if price_impact is greater than slippage_tolerance.
  2. BLOCK if price_impact > 5.0 (Hard cap, even if user allows it).
  3. BLOCK if is_verified_pool is False.

📚 Resources

✅ Definition of Done

Submit a PR with: examples/community/defi_slippage_guard.csl

Metadata

Metadata

Assignees

No one assigned

    Labels

    DeFiFor DeFi Applicationsgood first issueGood for newcomerspolicyWriting CSL policies for business use

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions