Back
Challenge 5 - Slippage Protected Swap
MediumCPMMSlippage5 / 20

Challenge 5: Slippage Protected Swap

This is the first mini end-to-end CPMM exercise.

Task

Implement protected_swap_output.

Flow

  1. Apply the 30 bps fee.
  2. Use the exact-in constant-product quote.
  3. Compare the result to min_out.
  4. If the quote is too small, reject the trade.

Sample Walkthrough

With:

x = 1000
y = 2000
x_in = 100
min_out = 180

You should:

  • fee-adjust 100 to 99
  • compute output using new_x = 1099
  • get 181
  • accept because 181 >= 180

Important

Round down during division. Conservative rounding is safer for AMM math.

LanguageRust
Loading editor...
Run works without login. Submit requires sign-in so completion can be saved.
Run cases to compare your output against each configured input. Submit saves progress only when every case passes.
    Challenge 5 - Slippage Protected Swap · CPMM Exercise | learn.sol