Back
Challenge 2 - Spot Price From Reserves
EasyCPMMPricing2 / 20

Challenge 2: Spot Price From Reserves

A CPMM does not store a price directly. The current spot price is implied by the reserve ratio.

Task

Implement spot_price_bps(x_reserve, y_reserve).

Requirements

  • Return the price of 1 unit of X in units of Y.
  • Scale the result by 10_000 so you can stay in integer math.
  • For x = 2_000 and y = 3_000, return 15_000.

That corresponds to:

3_000 / 2_000 = 1.5
1.5 * 10_000 = 15_000

Do multiplication before division when possible, or integer division will throw away precision too early.

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 2 - Spot Price From Reserves · CPMM Exercise | learn.sol