The formula of the invariant function used to determine the AMM execution price of each liquidity pool:
Consider an AMM trading pair involving Security Token R and UT (Either Fiat Currency Token or Stable Coin Token). Initially, the liquidity pools contain amounts A and B of R and UT, respectively. Within a specific block, the AMM smart contract receives sell orders for x amount of R from some traders, while other traders spend y UT to buy R.
The execution price of all orders in this block is determined by the formula:
Notes: For ease of understanding, this illustration does not factor in any applicable transaction fees. However, it's worth mentioning that transaction fees have a minimal impact on the executed price.
Purpose:
- Efficient Price Discovery: The formula facilitates quick and accurate price discovery for executed trades, enhancing market efficiency.
- Automatic Price Adjustment: The constant product formula automatically adjusts the price of tokens in the pool based on the demand and supply. As one token is bought, its price increases, and as it is sold, its price decreases.
- Liquidity Provision: Liquidity providers contribute to the pool by depositing an equivalent value of both tokens. The constant product formula helps ensure that the liquidity pool always has a balanced value of both tokens.
Benefits:
- No Order Book: Unlike traditional exchanges with order books, AMM using the constant product model do not require order matching. This simplicity makes it easy for users to trade and provide liquidity.
- Continuous Liquidity: The AMM model ensures continuous liquidity, as traders can always execute a trade at the prevailing market price. This can be particularly advantageous in markets with lower trading volumes.
- Accessibility: AMMs are accessible to anyone with a compatible wallet, allowing for broader participation in token trading and liquidity provision.
Risks:
- Front-Running: Malicious actors may attempt to front-run transactions.
- Impermanent Loss: Liquidity providers may experience impermanent loss, which occurs when the relative prices of the two tokens in the pool change. It is called "impermanent" because the loss is realized only if the liquidity provider decides to withdraw their funds.
- Slippage: Due to the constant product formula, larger trades can experience slippage, where the execution price deviates from the expected price. This can be a concern for traders looking to execute large orders without impacting the market price.
Risk Mitigations:
-
Aggregation Process Control Logic:
- Implemented aggregation process control logic in the smart contract.
- Aggregates all buy/sell orders received within a block and calculates a unified price using the formula.
- By applying this logic, front-runners gain no advantage but incur transaction costs, effectively discouraging such behavior.
-
Transaction Monitoring for Market Manipulation:
- Implemented robust transaction monitoring for AMM transactions.
- Identifies, controls, and prevents market manipulation attempts.
- Enhances the security and integrity of the trading environment by actively monitoring and responding to suspicious activities.
-
Transaction Size Limitation:
- The AMM smart contract enforces a maximum transaction size (e.g., 2% of the pool size).
- Mitigates slippage risks associated with large-volume transactions, ensuring more stable and predictable execution prices.
-
Circuit Break Mechanism:
- Integrated a circuit break mechanism into the AMM smart contract.
- Acts as a safeguard against large price vulnerabilities and sudden market fluctuations.
- Enhances overall system resilience by temporarily pausing trading activities in response to abnormal conditions.
-
Transaction Fee Sharing Mechanism:
- Implemented a transaction fee-sharing mechanism for liquidity providers within the Automated Market Maker (AMM) protocol. By sharing transaction fees, the impact of impermanent loss is reduced, providing an additional incentive for liquidity providers.