Constant Product
The basic AMM idea is simple:x is the token A reserve, y is the token B reserve, and k is the pool’s liquidity invariant. In compounding mode this is reserve-based. In concentrated mode, the same idea is bounded by the pool’s configured square-root price range.
Price and Square-Root Price
DAMM v2 stores price as a square-root price: This format makes liquidity math more precise and efficient on-chain. Product users can still think of it as the pool price expressed in a form that is easier for the program to update during swaps and liquidity changes.Concentrated Liquidity
In concentrated liquidity mode, a DAMM v2 pool has a fixed lower and upper square-root price: For a liquidity amountL, the token amounts are:
The program rounds required deposit amounts up and withdrawal or swap output amounts down. Token A calculations also guard against values larger than u64::MAX.
Compounding Liquidity
In compounding mode, DAMM v2 uses full-range constant-product liquidity and prices the pool from reserves: At initialization, compounding mode derives reserves from liquidity and square-root price: The first position receives: because100 << 64 is kept as dead liquidity in the pool.
Trading Fees
DAMM v2 fee rates are stored as numerators over1,000,000,000:
For fees taken from an amount that already includes the fee, the program rounds the fee up:
For fees added to an amount that excludes the fee:
After the trading fee is calculated, DAMM v2 splits it:
If the pool uses compounding mode, the LP fee can be split again:
If a referral is present, the referral fee is taken from the protocol fee:
DAMM v2’s default protocol fee percent is 20, and the referral fee percent is 20 of the protocol fee when a referral account is used.
Dynamic Fee
Dynamic fees use a volatility accumulator. When price changes quickly, the accumulator rises. When the market calms down, it decays. In the current implementation, dynamic feebin_step must be 1 bps and bin_step_u128 must match the default 1 bps fixed-point value. filter_period must be lower than decay_period, and both variable_fee_control and max_volatility_accumulator are capped at 0xffffff.
Liquidity Mining Rewards
DAMM v2 liquidity mining distributes reward tokens by position liquidity: This means LPs earn rewards in proportion to their share of pool liquidity. Unlocked, vesting, and permanently locked liquidity can all count toward rewards because the position’s total liquidity is used for reward accounting. The reward rate is stored as a fixed-point value scaled by2^64, while reward-per-liquidity accounting is accumulated with a 2^128 liquidity scale. Integer division truncates fractional rewards.
