Back
Challenge 1 - Constant Product Invariant
EasyCPMMAMM Math1 / 20

Challenge 1: Constant Product Invariant

A constant-product market maker tracks the relationship:

x * y = k

Where:

  • x is token A reserve
  • y is token B reserve
  • k is the pool invariant

Task

Implement constant_product.

Requirements

  • Accept two u64 reserves.
  • Return a u128.
  • Cast before multiplying so large values do not overflow u64 math.

On Solana, token math often starts with u64 amounts but intermediate math must use wider types.

Hint

(x_reserve as u128) * (y_reserve as u128)
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 1 - Constant Product Invariant · CPMM Exercise | learn.sol