Skip to main content DAMM v2 is a constant product AMM that operates between a sqrt_min_price and a sqrt_max_price.
Liquidity Addition / Removal
When adding or removing liquidity, for a given liquidity delta ΔL, the required token amounts are calculated as:
Δ a = Δ L × ( 1 P − 1 P max ) \Delta a = \Delta L \times \left(\frac{1}{\sqrt{P}} - \frac{1}{\sqrt{P_{\text{max}}}}\right)
Δ a = Δ L × ( P 1 − P max 1 )
Δ b = Δ L × ( P − P min ) \Delta b = \Delta L \times (\sqrt{P} - \sqrt{P_{\text{min}}})
Δ b = Δ L × ( P − P min )
LP Token Amount
Example from token B:
Token B Amount = LP Token × ( currentSqrtPrice − minSqrtPrice ) 2 128 \text{Token B Amount} = \frac{\text{LP Token} × (\text{currentSqrtPrice} - \text{minSqrtPrice})}{2^{128}}
Token B Amount = 2 128 LP Token × ( currentSqrtPrice − minSqrtPrice )
so you can reverse:
LP Token = Token B Amount × 2 128 currentSqrtPrice − minSqrtPrice \text{LP Token} = \frac{\text{Token B Amount} × 2^{128}}{\text{currentSqrtPrice} - \text{minSqrtPrice}}
LP Token = currentSqrtPrice − minSqrtPrice Token B Amount × 2 128
Farming Rewards
The farming rewards are calculated as:
Reward per token = Elapsed Time × Reward Rate × 2 64 Total Liquidity \text{Reward per token} = \frac{\text{Elapsed Time} \times \text{Reward Rate} \times 2^{64}}{\text{Total Liquidity}}
Reward per token = Total Liquidity Elapsed Time × Reward Rate × 2 64
User reward = Position Liquidity × ( Current Reward per Token − User Last Reward per Token ) ≫ 64 \text{User reward} = \text{Position Liquidity} \times (\text{Current Reward per Token} - \text{User Last Reward per Token}) \gg 64
User reward = Position Liquidity × ( Current Reward per Token − User Last Reward per Token ) ≫ 64
Price Impact
The price impact for a swap can be calculated as:
Price Impact = ∣ New Sqrt Price − Old Sqrt Price ∣ Old Sqrt Price \text{Price Impact} = \frac{|\text{New Sqrt Price} - \text{Old Sqrt Price}|}{\text{Old Sqrt Price}}
Price Impact = Old Sqrt Price ∣ New Sqrt Price − Old Sqrt Price ∣