Technical Design
Last updated
Last updated
Saros DLMM runs on Liquidity Book (courtesy of LFJ).
Liquidity Book core enables the creation of unique and dynamic liquidity structures for a paired asset market, as liquidity is pooled in constant price bins which are aggregated to establish a market.
The mechanism makes it fast and seamless for anyone to trade directly on Solana - no middlemen, just pure DeFi power.
Uniswap v3 introduced concentrated liquidity, allowing liquidity providers to allocate reserves within specific price ranges, aggregated via a constant function formula.
Curve v1 and v2 similarly concentrate liquidity around a peg price, with v2 using a dynamic peg via an internal price oracle.
In general, these constant function models limit tailored market-making strategies.
The Liquidity Book (LB) organizes liquidity for an asset pair into discrete price bins, where deposited reserves are traded at each bin's fixed exchange rate. The market is formed by combining all these bins, with liquidity contributions from various participants.
Let’s take a deeper look into the design.
Following AMM convention, price (P) is defined as the rate of change in Y reserves per change in X reserves. Price represents the value of the base asset (X) denominated in the quote asset (Y) terms.
Liquidity (L) is the nominal value of reserves in a discrete bin, denominated in the quoted asset, and conserved as reserve composition changes. Liquidity (L) is defined to be the nominal value of reserves deposited into a discrete bin and is denominated in the quote asset. Liquidity is conserved as the bin’s reserve composition changes and can be described in Eq 2.2 as the value sum of its composite assets.
Each bin operates as a constant sum market with a unique bonding curve, defined by a static price and dynamic liquidity reserves. The y-intercept in the figure below shows total liquidity (L), with the slope set by the bin’s price.
The reserve composition in a liquidity bin is independent of price and liquidity. A composition factor (c), defined as the percentage of bin liquidity held as Y reserves, describes available reserves and is bounded between 0 and 1.
Asset reserves of each liquidity bin can be fully described by bin liquidity (L) and composition (c)
Combining liquidity bins for an asset pair forms the market. As market prices shift, bin reserves transition between X and Y assets. Bins priced below the market hold only Y, while those above hold only X. The market price is set by the lowest-priced bin containing X reserves.
Discrete liquidity bins enable liquidity providers to tailor liquidity structures to their goals, predictions, and risk profiles. Providers can focus liquidity around specific price points or spreads and adjust individual bins without affecting others.
The liquidity book design supports precise range and depth adjustments for effective market making.
The market price range is limited to (2⁻¹²⁸, 2¹²⁸) and divided into bins based on a bin step (s).
Smaller bin steps create more bins. A market is defined by the (X, Y, s) set. The total number of bins is 2*Nb, where Nb is the maximum number of bins between price parity and the maximum price for a given bin step.
The maximum number of bins is capped below 2²⁴, with half assigned below and half above price parity. In a market with the maximum bins, the parity bin identifier is 2²³, denoted as constant b. Each bin receives a positive integer identifier (i) ranging from [b - Nb, b + Nb].
The price prescribed to each bin is a function of the pair’s bin step (s) and the bin’s identifier (i). The bin step parameter determines the constant percentage increase or decrease in price between each incremental bin.
Liquidity bins are indexed in a tree structure using three nested 256-bit arrays. Each bin is assigned a location path in the arrays, with non-zero values indicating bins containing liquidity.
This tree enables efficient liquidity state searches during swaps and external monitoring.
The LB router will provide added security and slippage checks for swaps and liquidity deposits/withdrawals. Swaps will also be routed through legacy AMM pairs when better pricing is found.
The LB protocol introduces LBToken, a new liquidity token standard tailored for its numerous bins. Liquidity (L) in LB markets is valued uniformly in Y terms, independent of bin state, making it composable across bins.
Each market has fee rate parameters, detailed in next sections, initially set based on the chosen bin step. Markets can only be created with bin steps linked to predefined fee parameters in the factory. These parameters can be adjusted post-initialization
Saros DLMM markets feature an oracle that logs
timestamp
cumulativeID
cumulativeAccumulator
cumulativeBinCrossed
These cumulative values help track changes over time, providing market price and volatility/fee metrics for algorithmic trading and liquidity provision. The sampleLifetime, set at market creation, determines the sampling rate, and users can increase the oracle sample size as needed.
Adding or removing liquidity from an active bin maintains the price (P) and composition (c). The required amounts of reserve X and Y for a liquidity adjustment.
For all ‘inactive’ liquidity bins, liquidity can be added exclusively in reserve X or reserve Y as determined by the composition bounds.
Liquidity added to an active bin is automatically swapped if it mismatches the bin’s composition, incurring a fee. Attempts to add liquidity to inactive bins that don’t align with the bin’s composition will fail.
Exchanging reserves in a liquidity bin preserves liquidity and price, altering only the reserve composition. Reserves are swapped, with composition staying within [0,1].
The reserves that are available in the liquidity bin until the composition bounds are reached can be calculated:
When a swap exceeds the liquidity in a bin, it depletes each consecutive bin’s liquidity before moving to the next adjacent bin with available liquidity.
The protocol collects fees to reward liquidity providers for trading activity. The total swap fee (fs) includes a base fee (fb) and a variable fee (fv) based on price volatility.
Fees are applied to the swap amount in each bin, distributed proportionally to providers after a protocol share, and held separately for providers to claim. The total fee for a swap across n bins is calculated:
Base fee
The base fee represents the minimum rate for all swaps. The base fee rate (fb) is a function of the bin step (s) and is scaled by a baseFactor (B)
Variable fee
The variable fee (fv) is designed to compensate liquidity providers for instantaneous volatility and incentivize liquidity providers to actively manage liquidity around a moving price. The variable fee is calculated per bin (k)
Instantaneous volatility is tracked by the volatility accumulator variable (va). The variableFeeControl parameter (A) scales the variable fee component based on expected market dynamics.
Volatility Accumulator
Volatility is based on bin changes over time, with each change reflecting a fixed price movement set by the bin step.
A volatility accumulator (va) measures bin crossovers across transactions, using the number of crossovers (k), a reference bin index (ir), the starting active bin (ik=0), and a reference volatility value (vr)
Where the reference values are calculated at the beginning of each transaction and depend on time elapsed since the last transaction (t)
The volatility accumulator calculates the bin distance from the swap bin to a reference bin, adding a carryover volatility (vr). The reference bin updates to the current bin if no transactions occur for a period exceeding the filterPeriod (tf).
Reference volatility updates based on transaction frequency, decaying by the reductionFactor R when time exceeds tf, or resetting to 0 when exceeding the decayPeriod (td). A maxAccumulator parameter (vmax) limits the accumulator to prevent excessive fees.
Liquidity added to the active bin is automatically swapped across reserves if its composition differs from the bin’s. The swap amount ensures the bin’s assets match those from a prior swap, incurring a fee similar to the current market swap fee.
A portion of swap fees, set by the protocolShare parameter, is retained by the protocol (fp). Each market has its own protocolShare to manage fee distribution. Remaining fees are distributed to liquidity providers.
Variable fees compensate liquidity providers for IL caused by price volatility, with the volatility accumulator adjusting fees to market conditions. Providers can outperform expected payoffs due to the accumulator’s time decay, as shown in below figure.
However, tracking errors occur during highly volatile events due to significant nominal price changes, as the accumulator relies on bin steps.
Enhancing the DEX capital efficiency increases market depth for a given capital amount. Capital efficiency is the reduction in capital needed to match v1 liquidity.
For Saros DLMM, equivalent liquidity aligns the price impact of a v1 swap with a single bin step. The efficiency equation is provided, with maximum efficiency limits for each market and bin step.
From the above figure, capital efficiency is similar to Uniswap v3 (v3). An evenly distributed LB position approximates a v3 position.
If liquidity is equally spread across bins in X tokens, the swap value difference between LB and v3 is calculated, and can be plotted for positions with varying price ranges and bin steps.
The figure shows that position price range impacts market depth more than bin structure.
For positions spanning at least two bins, depth differences across bin steps are minimal. With the specified distribution, LB’s market depth is within 1% of Uniswap v3 for positions under a 60% price range.
Depth differences, mainly due to liquidity distribution compared to v3’s geometric sequence, are only significant for large-range positions, highlighting the value of LB’s flexible liquidity distribution.