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×(1P1Pmax)\Delta a = \Delta L \times \left(\frac{1}{\sqrt{P}} - \frac{1}{\sqrt{P_{\text{max}}}}\right) Δb=ΔL×(PPmin)\Delta b = \Delta L \times (\sqrt{P} - \sqrt{P_{\text{min}}})

LP Token Amount

Example from token B: Token B Amount=LP Token×(currentSqrtPriceminSqrtPrice)2128\text{Token B Amount} = \frac{\text{LP Token} × (\text{currentSqrtPrice} - \text{minSqrtPrice})}{2^{128}} so you can reverse: LP Token=Token B Amount×2128currentSqrtPriceminSqrtPrice\text{LP Token} = \frac{\text{Token B Amount} × 2^{128}}{\text{currentSqrtPrice} - \text{minSqrtPrice}}

Farming Rewards

The farming rewards are calculated as:
Reward per token=Elapsed Time×Reward Rate×2128Total Liquidity\text{Reward per token} = \frac{\text{Elapsed Time} \times \text{Reward Rate} \times 2^{128}}{\text{Total Liquidity}}
User reward=Position Liquidity×(Current Reward per TokenUser Last Reward per Token)192\text{User reward} = \text{Position Liquidity} \times (\text{Current Reward per Token} - \text{User Last Reward per Token}) \gg 192

Compounding Fee Mode

When a pool uses Compounding Fee Mode (collect_fee_mode = 2), it operates as a standard constant-product AMM with no concentrated price range. The pool reserves grow over time as a portion of trading fees are automatically reinvested.

Constant-Product Formula

The pool maintains the invariant: token_a_amount×token_b_amount=k\text{token\_a\_amount} \times \text{token\_b\_amount} = k where kk is a constant. Unlike the standard DAMM v2 concentrated liquidity formula, there is no sqrt_min_price or sqrt_max_price bound — liquidity spans the full price range.
Pools with layout_version == 1 track token_a_amount and token_b_amount directly in the pool state, enabling accurate reserve accounting for the compounding mechanism.

Fee Split Formulas

The protocol fee is first subtracted from the total trading fee. The compounding/claiming split then applies to the LP fee (after protocol fee is removed): protocol_fee=fs×protocol_fee_percent100\text{protocol\_fee} = f_s \times \frac{\text{protocol\_fee\_percent}}{100} lp_fee=fsprotocol_fee\text{lp\_fee} = f_s - \text{protocol\_fee} compounding_fee=lp_fee×compounding_fee_bps10000\text{compounding\_fee} = \text{lp\_fee} \times \frac{\text{compounding\_fee\_bps}}{10000} claiming_fee=lp_feecompounding_fee\text{claiming\_fee} = \text{lp\_fee} - \text{compounding\_fee} The compounding fee is added directly to the pool reserves, increasing kk over time and benefiting all LPs proportionally.

Price Impact

The price impact for a swap can be calculated as: Price Impact=New Sqrt PriceOld Sqrt PriceOld Sqrt Price\text{Price Impact} = \frac{|\text{New Sqrt Price} - \text{Old Sqrt Price}|}{\text{Old Sqrt Price}}