lp-mathlisted
Install: claude install-skill Serennity007/claude-trading-skills-67
# LP Math — AMM Liquidity Provision Mathematics
Automated Market Makers (AMMs) replace traditional orderbooks with liquidity pools. Instead of matching buyers and sellers, a mathematical formula determines prices based on reserve ratios. Liquidity providers (LPs) deposit both assets into a pool and earn fees from every trade.
Understanding the math behind AMMs is essential for:
- Evaluating whether providing liquidity is profitable after impermanent loss
- Estimating price impact before executing large trades
- Comparing capital efficiency across pool types (constant product vs concentrated)
- Calculating expected fee revenue for a given pool position
**Related skills**: See `impermanent-loss` for IL calculations, `yield-analysis` for LP yield modeling, `liquidity-analysis` for pool depth assessment.
---
## 1. Constant Product AMM (xy = k)
The foundational AMM model used by Raydium V4 and most Solana DEXes.
### Core Invariant
```
x * y = k
```
Where:
- `x` = reserve amount of token X (e.g., SOL)
- `y` = reserve amount of token Y (e.g., USDC)
- `k` = constant product (increases over time from fees)
### Spot Price
```
P = x / y (price of Y in terms of X)
P = y / x (price of X in terms of Y)
```
For a pool with 100 SOL and 10,000 USDC: price of SOL = 10,000 / 100 = 100 USDC.
### Trade Execution
When a trader swaps Δx of token X into the pool:
```python
# Output amount (before fees)
delta_y = y * delta_x / (x + delta_x)
# With fee (e.g., 0.3%)
delta_y_after_