Back
Challenge 3 - Exact In Swap Quote
MediumCPMMSwaps3 / 20

Challenge 3: Exact In Swap Quote

Now compute the output amount for an exact-in swap.

Formula

Starting from:

x * y = k

After adding x_in to the X reserve:

new_x = x + x_in
new_y = k / new_x
y_out = y - new_y

Task

Implement quote_exact_in.

Requirements

  • Do intermediate math in u128.
  • Return the final output as u64.
  • Round down naturally through integer division.

For the sample:

x = 1000
y = 2000
x_in = 100
k = 2_000_000
new_x = 1100
new_y = 1818
y_out = 182
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 3 - Exact In Swap Quote · CPMM Exercise | learn.sol