Back
Challenge 10 - Invariant Does Not Decrease
MediumCPMMInvariant10 / 20

Challenge 10: Invariant Does Not Decrease

A fee-charging CPMM should not end a valid swap with a smaller invariant.

Task

Implement invariant_ok.

Rules

  • Do multiplication in u128.
  • Return true if the new invariant is greater than or equal to the old one.

Example

Compare:

  • old state: (1000, 2000)
  • new state: (1099, 1819)

You should find that the new invariant is slightly larger because fees stayed inside the pool.

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 10 - Invariant Does Not Decrease · CPMM Exercise | learn.sol