Constant Product Automated Market Maker
A Constant Product Automated Market Maker (AMM) is a type of decentralized exchange mechanism used in decentralized finance (DeFi) platforms. It allows users to trade cryptocurrencies directly from their wallets without the need for a traditional order book or centralized intermediary.
Constant Product Formula
A constant product AAM is an AMM where the price of the tokens are determined by the equation
Where:
- = amount of token A
- = amount of taken B
- a constant product
Mechanisms
Swap Function: Calculating for ?
For example, if we are going to sell Token A and buy Token B, we can write it as:
Now we have the two equations
Solving for gives us:
Thus, the amount of Token B you receive () when you sell an amount of Token A () is determined by the current reserves of both tokens in the liquidity pool.
Add Liquidity Function: Balancing and ?
Adding liquidity to the pool requires maintaining the price ratio, which means the amounts added must satisfy:
Share Calculation in Add Liquidity: Minting New Shares
The share calculation is pivotal for fair distribution: