Use this file to discover all available pages before exploring further.
DAMM v2 is designed around constant-product liquidity. The formulas below explain the product math and the implementation details users most often need to reason about. On-chain values use integer math, so rounding matters.
The basic AMM idea is simple:x×y=kx 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.
DAMM v2 stores price as a square-root price:P=token A amounttoken B amountThis 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.
In concentrated liquidity mode, a DAMM v2 pool has a fixed lower and upper square-root price:Pmin≤P≤PmaxFor a liquidity amount L, the token amounts are:ΔA=L×(P1−Pmax1)ΔB=L×(P−Pmin)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.
In compounding mode, DAMM v2 uses full-range constant-product liquidity and prices the pool from reserves:token A reserve×token B reserve=kP=token A reservetoken B reserveAt initialization, compounding mode derives reserves from liquidity and square-root price:A0=⌈PL⌉B0=⌈2128L×P⌉The first position receives:Lposition=L−(100≪64)because 100 << 64 is kept as dead liquidity in the pool.
DAMM v2 fee rates are stored as numerators over 1,000,000,000:Total Fee Numerator=min(Base Fee Numerator+Dynamic Fee Numerator,Pool Fee Cap)For fees taken from an amount that already includes the fee, the program rounds the fee up:Trading Fee=⌈1,000,000,000Included Amount×Fee Numerator⌉For fees added to an amount that excludes the fee:Included Amount=⌈1,000,000,000−Fee NumeratorExcluded Amount×1,000,000,000⌉After the trading fee is calculated, DAMM v2 splits it:Protocol Fee=⌊Trading Fee×100Protocol Fee Percent⌋LP Fee Before Compounding=Trading Fee−Protocol FeeIf the pool uses compounding mode, the LP fee can be split again:Compounding Fee=⌊LP Fee Before Compounding×10,000Compounding Fee Bps⌋Claimable Fee=LP Fee Before Compounding−Compounding FeeIf a referral is present, the referral fee is taken from the protocol fee:Referral Fee=⌊Protocol Fee×100Referral Fee Percent⌋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 fees use a volatility accumulator. When price changes quickly, the accumulator rises. When the market calms down, it decays.Dynamic Fee Numerator=⌈100,000,000,000(Volatility Accumulator×Bin Step)2×Variable Fee Control⌉In the current implementation, dynamic fee bin_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.
DAMM v2 liquidity mining distributes reward tokens by position liquidity:Reward Per Liquidity=Total Pool LiquidityElapsed Time×Reward RatePosition Reward=Position Liquidity×Reward Per Liquidity Since Last CheckpointThis 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 by 2^64, while reward-per-liquidity accounting is accumulated with a 2^128 liquidity scale. Integer division truncates fractional rewards.