Constant Product Swap
Fundamental
AMM
30 Lynx342 solvers
Solution.sol
Loading editor...
Test Results
Run tests to see your results here.
Instructions
Implement the core swap function for a constant-product automated market maker (AMM).
Your contract maintains two token reserves. When a user swaps token A for token B, the product of the reserves must remain constant (minus fees).
Your task:
1. Calculate the output amount using the constant product formula: x * y = k
2. Apply a 0.3% swap fee on the input amount
3. Update the reserves after the swap
4. Emit the Swap event with the correct values
Constraints: - The output amount must never be zero - Reserves must stay positive after every swap - The function should revert with descriptive errors on invalid input
Hints (0/3)
Test Results
Run tests to see your results here.
Reward
30 Lynx
Pass all tests before submitting.