Back
Challenge 6 - Mutating Swap Reserves
MediumCPMMState Transition6 / 20

Challenge 6: Mutating Swap Reserves

Earlier challenges quoted output. Now mutate pool state.

Task

Implement apply_swap.

Rules

  • Fee = 30 bps.
  • Effective input = x_in * 9_970 / 10_000.
  • new_x = x + effective_input
  • k = x * y
  • new_y = k / new_x

Example

For x = 1000, y = 2000, x_in = 100:

  • effective input = 99
  • new_x = 1099
  • k = 2_000_000
  • new_y = 1_819

Return:

1099 1819
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 6 - Mutating Swap Reserves · CPMM Exercise | learn.sol