AMM Logic
Introduction
The Constant Product Formula
Core Invariant
x * y = kHow It Works
Price Determination
Swap Formulas
Swap Asset In (swapAssetIn)
Swap Asset Out (swapAssetOut)
Rounding Strategy
LP Token Calculations
Initial LP Tokens (ammLPTokens)
LP Tokens for Deposit (lpTokensOut)
Proportional Deposit (Both Assets)
Single Asset Deposit
Assets Required for LP Tokens (ammAssetIn)
LP Tokens to Burn (lpTokensIn)
Assets for LP Token Burn (ammAssetOut)
Fee Calculations
Fee Multipliers
Fee Ranges
Auction Slot Discount
Quality and Price Calculations
Spot Price Quality
Quality Matching with CLOB
Precision and Overflow Handling
Number Type
Precision Amendments
Amendment
Fix
Rounding Strategies
Invariant Checking
Worked Examples
Example 1: Simple Swap
Example 2: LP Token Minting
Example 3: Single Asset Deposit
Summary
References to Source Code
Cross-References
Last updated

