AMM Basics
、
What is an Automated Market Maker (AMM)?
The Constant Product Formula
The Basic Principle
Code Implementation
// balance{0,1}Adjusted are the balances after the swap, accounting for the fee
uint balance0Adjusted = (balance0 * 10000 - (amount0In * fee * 4) / 5);
uint balance1Adjusted = (balance1 * 10000 - (amount1In * fee * 4) / 5);
// check that the product of the new balances is not less than the product of the old reserves
require(
balance0Adjusted * balance1Adjusted >=
uint(_reserve0) * uint(_reserve1) * (10000 ** 2),
"JAMM: K"
);