LP Rewards
LP Profit Calculation
This document explains how profits are calculated for Liquidity Providers (LPs) in Raydium Constant Product Market Maker (CPMM) pools.
Overview
The profit calculation determines how much value an LP position has gained since initial deposit, accounting for price changes in the underlying tokens and potential previous liquidations. The calculation allows LPs to extract just their profits while keeping their principal invested.
Mathematical Model
Key Variables
- \(R_q\): Quote token reserve (Token A)
- \(R_b\): Base token reserve (Token B)
- \(L_{total}\): Total LP tokens in circulation
- \(L_{user}\): User's LP tokens
- \(P_{current} = \frac{R_b}{R_q}\): Current price of Token A in terms of Token B
- \(P_{initial} = \frac{B_{initial}}{A_{initial}}\): Initial price when LP position was created
Initial Value Calculation
When an LP first deposits tokens into the pool, the initial value per LP token is calculated as:
Where:
- \(A_{initial}\): Initial amount of Token A deposited
- \(B_{initial}\): Initial amount of Token B deposited
- \(L_{initial}\): Initial LP tokens received
Current Value Calculation
The current value of the LP position is calculated based on the user's share of the pool:
-
Calculate user's share percentage: \(S_{user} = \frac{L_{user}}{L_{total}} \times 100\)
-
Calculate user's tokens in the pool:
- Token A share: \(A_{user} = \frac{S_{user} \times R_q}{100}\)
-
Token B share: \(B_{user} = \frac{S_{user} \times R_b}{100}\)
-
Calculate current value in base currency: \(V_{current} = A_{user} \times P_{current} + B_{user}\)
Profit Calculation
The profit is calculated as the difference between the current value and the adjusted initial value:
-
Adjusted initial value: \(V_{initialAdjusted} = L_{user} \times V_{initialPerLP}\) (This accounts for any previous liquidations by considering only the remaining LP tokens)
-
Profit in base currency: \(Profit = V_{current} - V_{initialAdjusted}\)
LP Tokens for Profit Extraction
If the profit is positive, we calculate how many LP tokens can be liquidated to extract just the profit:
-
Calculate profit ratio: \(R_{profit} = \frac{Profit}{V_{current}}\)
-
LP tokens to liquidate for profit: \(L_{profit} = L_{user} \times R_{profit}\)
-
Estimate tokens received when liquidating profit tokens:
- Token A: \(A_{profit} = \frac{L_{profit}}{L_{total}} \times R_q\)
- Token B: \(B_{profit} = \frac{L_{profit}}{L_{total}} \times R_b\)
Example
Consider an LP who deposited 100 Token A and 200 Token B when the price was 2 B per A:
- They received 1000 LP tokens initially
- Now the pool has 10,000 Token A, 30,000 Token B, and 50,000 total LP tokens
- Current price is 3 B per A
- Their LP tokens represent 2% of the pool (1000/50000)
- Their current tokens in the pool are 200 Token A and 600 Token B
- Current value is 200×3 + 600 = 1200 Token B
- Initial value per LP was (100×2 + 200)/1000 = 0.4 Token B
- Adjusted initial value is 1000×0.4 = 400 Token B
- Profit is 1200 - 400 = 800 Token B
- Profit ratio is 800/1200 = 2/3
- LP tokens to liquidate for profit: 1000×(2/3) = 667 LP tokens
- When liquidating these tokens, they would receive approximately 133 Token A and 400 Token B