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×(P1−Pmax1)
Δb=ΔL×(P−Pmin)
LP Token Amount
Example from token B:
Token B Amount=2128LP Token×(currentSqrtPrice−minSqrtPrice)
so you can reverse:
LP Token=currentSqrtPrice−minSqrtPriceToken B Amount×2128
Farming Rewards
The farming rewards are calculated as:
Reward per token=Total LiquidityElapsed Time×Reward Rate×264
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=Old Sqrt Price∣New Sqrt Price−Old Sqrt Price∣