Use this file to discover all available pages before exploring further.
DLMM’s math is built around a simple product idea: each pool is a ladder of price bins, and each bin behaves like its own tiny market at a fixed price.
The program performs integer arithmetic with fixed-point values and explicit rounding. This page shows the conceptual formula first, then calls out the important rounding or unit behavior where it matters.
Every DLMM pool has a bin step, measured in basis points. The bin step defines the percentage difference between one bin and the next.Pi=(1+10,000bin step)iWhere:
P_i is the price of bin i
i is the bin ID
bin step is the pool’s configured step size
The program computes this as get_price_from_id(bin_id, bin_step) and returns the result in Q64.64 fixed-point form.Example: if the bin step is 25 basis points, each neighboring bin is approximately 0.25% apart. Moving from bin 0 to bin 1 multiplies the price by 1.0025.
Inside a bin, DLMM uses a constant-sum style liquidity value:L=P⋅x+yWhere:
L is the bin liquidity value
P is the bin price
x is the amount of token X
y is the amount of token Y
This fixed-price bin design is what creates zero price impact inside a single bin. Price changes when the available output liquidity in the active bin is consumed and the swap moves to another bin.
For a swap from token X to token Y, the output amount is:amount outY=⌊amount inX⋅P⌋For a swap from token Y to token X, the output amount is:amount outX=⌊Pamount inY⌋The inverse formulas are used when the program needs to know the required input for a desired output:amount inX=⌈Pamount outY⌉amount inY=⌈amount outX⋅P⌉The program rounds output amounts down and rounds required input amounts according to the swap path. This protects the pool from giving out more token than the bin can support.
DLMM trading fees have a base fee and an optional variable fee:total fee rate=min(base fee rate+variable fee rate,MAX_FEE_RATE)MAX_FEE_RATE is 100,000,000 in 1e9 precision, or 10%.
The base fee is configured through pool fee parameters:base fee rate=base factor×bin step×10×10base fee power factorThis value is stored in 1e9 precision.Product intuition: a larger bin step often pairs with a larger base fee because each bin represents a larger price movement. A smaller bin step is usually used for tighter markets where LPs expect smaller price changes.
The variable fee is DLMM’s volatility-aware fee. In the program, it is calculated as:variable fee rate=⌈100,000,000,000variable fee control×(volatility accumulator×bin step)2⌉If variable fee control is 0, the variable fee is 0.The volatility accumulator updates from bin movement:volatility accumulator=min(volatility reference+∣index reference−active id∣×10,000,max volatility accumulator)The volatility reference decays based on elapsed time:
The program supports two common fee calculations.When the fee is part of the amount already provided by the trader:fee amount=⌈1,000,000,000amount with fee×total fee rate⌉amount excluding fee=amount with fee−fee amountWhen the fee must be added on top of an amount that does not include fees:fee amount=⌈1,000,000,000−total fee rateamount excluding fee×total fee rate⌉amount including fee=amount excluding fee+fee amountWhich form is used depends on the swap direction and the pool’s Collect Fee Mode.
How a bin’s trading fee is distributed depends on the pool’s function mode:
Pool mode
Liquidity sources
Limit-order fee path
Liquidity mining
MM positions only
No
Limit order
MM positions and/or limit orders
Yes
Both modes use the same protocol share for MM liquidity and the same referral host fee rule. Limit-order pools add an extra split when limit-order liquidity contributes to the fill.
These rates apply to how the trading fee is shared among recipients. They are separate from the pool’s base fee, variable fee, and total fee cap.
For any fill that comes from MM positions, the MM slice of the trading fee is split by the pool’s protocol share:
Pool type
Protocol
LP
Standard pool
10% (protocol share = 1,000 bps)
90%
Launch Pool
20% (ILM_PROTOCOL_SHARE = 2,000 bps)
80%
protocol fee=⌊10,000trading fee×protocol share⌋LP fee=trading fee−protocol feeOn limit-order pools, replace trading fee with total MM fee when the fill also includes limit-order liquidity (see below).
When a swap passes a referral account, the host receives 20% of the applicable protocol fee (HOST_FEE_BPS = 2,000 bps). The rest stays as protocol treasury fee.host fee=⌊10,000protocol fee×2,000⌋protocol fee remainder=protocol fee−host feeWithout a referral account, host fee = 0 and protocol fee remainder = protocol fee.On limit-order pools with mixed fills, host fee can also include a capped share from the limit-order protocol slice (see below).
Liquidity mining pools do not support limit orders. Every swap fill is MM liquidity, so the entire trading fee uses the MM formulas above with no liquidity-source split.trading fee=LP fee+protocol fee remainder+host fee
Limit-order pools can fill from MM positions, limit orders, or both in the same bin. The program first assigns the trading fee by liquidity source, then applies the recipient splits above.By liquidity source (rounding favors MM):total MM fee=⌈trading fee×total amount inMM amount in⌉total limit order fee=trading fee−total MM feeMM slice — split with protocol share as in the table above:MM protocol fee=⌊10,000total MM fee×protocol share⌋MM LP fee=total MM fee−MM protocol feeLimit-order slice — always 50% / 50% via LIMIT_ORDER_FEE_SHARE (5,000 bps), independent of pool type:limit order participant fee=⌊10,000total limit order fee×5,000⌋limit order protocol fee=total limit order fee−limit order participant feeReferral host fee — 20% of MM protocol fee, plus a capped share from the limit-order protocol slice:host fee on limit order=min10,000⌊10,000total limit order fee×protocol share⌋×2,000,limit order protocol feehost fee=⌊10,000MM protocol fee×2,000⌋+host fee on limit orderprotocol fee remainder=MM protocol fee+limit order protocol fee−host feeWhen a swap fills only MM liquidity, total limit order fee = 0 and the limit-order paths above are zero — the result matches a liquidity mining pool.trading fee=MM LP fee+limit order participant fee+protocol fee remainder+host fee
When a user deposits into a bin, the program first computes the liquidity value of the deposit:Lin=P⋅xin+yinIf the bin has no existing liquidity supply, the new liquidity share equals the deposit liquidity:liquidity share=LinIf the bin already has liquidity, the new share is:liquidity share=⌊LbinLin×existing liquidity supply⌋Where:
L_in is the liquidity value of the user’s deposit
L_bin is the existing liquidity value of the bin before the deposit
existing liquidity supply is the bin’s current share supply
Those shares determine the position’s proportional claim on bin liquidity, fees, and eligible rewards.
When liquidity is removed from a bin, token amounts are returned pro rata:amount outX=⌊bin liquidity supplyliquidity share removed×bin amountX⌋amount outY=⌊bin liquidity supplyliquidity share removed×bin amountY⌋
When adding liquidity to the active bin of a bin that already has liquidity, the program may charge a composition fee if the deposit changes the bin composition in a way that resembles a swap.The composition fee is based on the token delta and the current total fee rate:composition fee=⌊1,000,000,0002Δamount×total fee rate×(1,000,000,000+total fee rate)⌋The protocol share is then taken from the composition fee using the same protocol-fee formula:composition protocol fee=⌊10,000composition fee×protocol share⌋No composition fee is charged when depositing into an empty bin or a non-active bin.
For reward-enabled pools, rewards are tracked per token of liquidity for eligible bins.The reward emission rate is funded over a reward duration. If a reward is funded while a previous reward period is still active, the program includes the remaining unvested reward amount in the new rate calculation:reward rate=reward durationnew funded amount+remaining reward amountIf the funder chooses to carry forward ineligible rewards from empty-liquidity time, that carry-forward amount is also included in the new funded amount. In the program, reward_rate is stored in fixed-point precision. On active-bin reward updates, the per-token reward increment is:Δreward per token=⌊active bin liquidity supplyseconds elapsed×reward rate⌋If the active bin has no liquidity, the program records the elapsed empty-liquidity time instead of assigning rewards to LPs. During v2 swaps, accumulated rewards can also be split across crossed bins with liquidity, up to the program’s reward-bin split limit.
Some swap flows can include a maximum price impact limit. The program computes a guard price from the active bin price:For X to Y swaps:minimum price=Pactive×10,00010,000−max price impact bpsFor Y to X swaps:maximum effective price=Pactive×10,000−max price impact bps10,000This protects users from swaps that would move too far from their expected active-bin price.