Saros
  • SAROS
  • SAROS DLMM
  • SAROS AMM
  • SAROS PERPS
  • SAROS MOBILE APP
  • SAROS DLMM
    • Onboarding and Guides
      • Saros DLMM: Introduction
      • Liquidity Lifecycle: Deployment, Management & Rebalancing
      • Permissionless Saros DLMM Pools
      • Understanding Your Risks as a Liquidity Provider on Saros DLMM
    • Shapes and Strategies
      • Liquidity Shapes
      • Getting Started with Basic Liquidity Strategies
      • Advanced Liquidity Strategies on Saros
      • Managing Out-of-Range Liquidity on Saros
      • Single-Sided Liquidity Strategies on Saros
    • Rewards
      • Concentrated Incentives (CI) on Saros
    • Technical Design
    • Technical Guides
      • Add liquidity
      • Create a pair
      • User Position
      • Swap tokens
      • Removing Liquidity
  • SAROS MOBILE APP
    • Mobile App
      • How to install Saros Super App
      • How to set up Saros Super App
      • How to add a new Hot Wallet
      • How to add View-only wallet
      • How to log in to Social Account
      • How to manage wallets
      • How to send or receive a token
      • How to send or receive NFTs
      • How to send multiple NFTs to an address
      • How to swap tokens
      • How to add a custom token
      • How to manage tokens
      • General Settings
      • How to use DApp browser
      • How to turn on Biometric and change Passcode
      • Migrate Ramper V2 on Super App
      • How to use Discover
      • How to buy crypto
    • Extension
      • How to install Saros Wallet Extension
      • How to set up Saros Extension Wallet
      • How to add a new Hot Wallet on Saros Extension
      • How to Add view-only wallet
      • How to manage wallets
      • How to send or receive a token
      • How to send or receive NFTs
      • How to add a custom token?
      • How to manage tokens
      • General settings
      • How to change the password?
      • Migrate Ramper V2 on Extension
      • How to log in to Social Account
      • How to use Discover
      • How to buy crypto
      • How to send multiple NFTs in one transaction with Multisend
      • How to Manage Notifications
      • How to swap on Saros Extension
      • Action on X
    • FAQs
  • SAROS AMM
    • SarosSwap
      • How To Swap on SarosSwap
    • SarosFarm
      • How to Add Liquidity
      • How to Remove Liquidity
      • How to Farm on SarosFarm
      • How to Claim the Reward
    • SarosStake
      • How to stake
      • How to unstake
      • How to harvest
    • SarosSnapShot
    • SarosPerpetual
      • Trading Basics
      • Getting Started
      • Deposit/Withdraw
      • Order Management
    • FAQs
      • Is Saros safe? Has Saros been audited?
      • Why did my transaction fail?
      • How to resolve the "No wallet" error when connecting wallet to Saros Finance
      • What is the difference between APY and APR?
      • How to get farming pool Txid
      • What are liquidity provider tokens?
      • When will you open more pools?
      • What wallets can I use with Saros? How do I connect my wallet to Saros?
      • My LP tokens aren’t showing up on the site or in my wallet?
      • How do I get airdrops?
      • Can I use Saros on my phone?
      • What is price impact?
      • What is slippage tolerance? How can I adjust it when swapping?
      • What fees do I pay when I exchange tokens?
      • Are there any fees associated with the SarosFarm?
      • How to calculate and distribute the reward on SarosFarm?
      • Can I withdraw my liquidity anytime?
      • Where can I check Saros Analytics?
      • I can't find an answer for my question. Where do I find an answer?
      • How could I report a bug?
      • How to check wallet information on Saros
    • Go to DEX
  • SAROS GARDEN
    • Introduction
    • How to stake on Saros Garden
    • How to unstake from Saros Garden
  • ALL ABOUT $SAROS
    • Saros Token ($SAROS)
  • INTEGRATION
    • Saros Super App
    • Saros DEX
  • Saros DLMM
  • LEGAL
    • TERMS OF SERVICE
    • Privacy Policy
  • AUDITS
    • SarosSwap
    • SarosFarm & SarosStake
  • OFFICIAL LINKS
    • Saros Community
    • Brand Assets
Powered by GitBook
On this page
  • Intro
  • 1. Concentrated Liquidity
  • 2. Liquidity Book
  • Liquidity Book Design
  • Product Architecture
  • User Interactions
  • Improvements
  1. SAROS DLMM

Technical Design

PreviousConcentrated Incentives (CI) on SarosNextTechnical Guides

Last updated 12 days ago

Intro

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.

1. Concentrated Liquidity

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.

2. Liquidity Book

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.

Liquidity Structure Example

Let’s take a deeper look into the design.

Liquidity Book Design

1. Reserve Pricing

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.

2. Bin Liquidity

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.

3. Bin Composition

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)

4. Market Aggregation

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.

5. Market Making

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.

Product Architecture

1. Market Definition

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].

2. Bin Price

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.

3. Liquidity Tracking

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.

4. Trade Routing

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.

5. Liquidity Tokens

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.

6. Market Parameters

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

7. Oracles

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.

User Interactions

1. Add / Remove Liquidity

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.

2. Swaps

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.

3. Swap fees

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.

4. Active Bin Composition Fee

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.

5. Protocol 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.

Improvements

1. Impermanent Loss (IL)

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.

2. Liquidity Depth

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.

Reserves Bonding Curve
Aggregate Liquidity Composition
Bin Index Tree
Fee Adjusted Per IL
Capital Efficiency Limits
Market Depth compared to Uni v3