← Code LabSolidity0/50 solved · 0%
DeFi · hard

44. Constant-product AMM

Uniswap V2 swap formula.

Implement `getAmountOut(uint256 amountIn, uint256 reserveIn, uint256 reserveOut)` using `x * y = k` with a 0.3% fee: `amountInWithFee = amountIn * 997`, output = `amountInWithFee * reserveOut / (reserveIn * 1000 + amountInWithFee)`.
Required in your answer: amountIn * 997* reserveOutreserveIn * 1000 + amountInWithFee