DLMM SDK

This SDK provides tools and utilities to interact with the Bean Spot DEX protocol on Monad, built upon the DLMM (Discrete Liquidity Market Maker) architecture inspired by the Liquidity Book model. It enables developers to simulate swaps, fetch bin-level liquidity data, compute fee structures, and integrate seamlessly with the spot pool logic on-chain.


1. Overview

  • Protocol: Bean

  • Architecture: Discrete Liquidity Market Maker (DLMM)

  • Chain: Monad

  • Package: @bean-exchange/spot-sdk

  • License: MIT

This SDK is designed for developers building:

  • Front-end dApps (swap UI, LP dashboards)

  • Trading bots / aggregators

  • Analytics / research tools

  • Automated liquidity strategies


2. Installation

Install the SDK via npm or yarn:

npm install @bean-exchange/spot-sdk
# or
yarn add @bean-exchange/spot-sdk

3. Building & Testing

Compile and run tests using standard workflows:

yarn          # install dependencies
yarn build    # compile source code
yarn test     # run unit tests (WIP)

4. Usage Example

import { Pool } from '@bean-exchange/spot-sdk'

const monUsdcPool = new Pool({
  token0: MON_ADDRESS,
  token1: USDC_ADDRESS,
  binStep: 5,
  baseFactor: 100,
  variableFeeControl: 2500
})

const price = monUsdcPool.getCurrentPrice()
const swapEstimate = monUsdcPool.simulateSwap(BigInt(1000e6), USDC_ADDRESS)
console.log(`Output MON: ${swapEstimate.outputAmount}`)

5. Core Classes & Interfaces

Pool

Represents a DLMM pool and provides utilities for:

  • price computation

  • swap simulation

  • fee calculation

  • liquidity distribution

Constructor:

new Pool({
  token0: Address,
  token1: Address,
  binStep: number,
  baseFactor: number,
  variableFeeControl: number
})

Key Methods:

  • getCurrentPrice(): BigNumber

  • simulateSwap(inputAmount: BigInt, tokenIn: Address): SwapResult

  • getLiquidityDistribution(): BinData[]

  • calculateFees(): FeeBreakdown

SwapResult

interface SwapResult {
  outputAmount: bigint
  feeAmount: bigint
  routeBins: number[]
}

BinData

interface BinData {
  binId: number
  price: number
  reserve0: bigint
  reserve1: bigint
}

FeeBreakdown

interface FeeBreakdown {
  baseFee: number
  variableFee: number
  totalFee: number
}

6. Fee Architecture

Total Fee = Base Fee + Variable Fee

Base Fee

BaseFee = baseFactor × binStep × 10

Ensures minimum compensation for LPs.

Variable Fee

VariableFee = ((volatilityAccumulator × binStep)^2 × variableFeeControl) / 100

Adapts to short-term volatility, compensates LPs during turbulent markets.


7. Volatility Management

Volatility Accumulator:

volatility = referenceVolatility + (currentBin - referenceBin) * 10_000

Decay Logic:

  • < filterTime → ignore update (anti-manipulation)

  • < decayTime → partial decay

  • > decayTime → full reset


8. Composition Fee

Applied to deposits that unbalance a bin:

CompositionFee = excessAmount × totalFee × (totalFee + 1)

Discourages single-token dumps into active bins.


9. Fee Distribution

  • Protocol Share: Configurable (max 25%)

  • LP Share: Remainder of fees

ProtocolFee = TotalFee × ProtocolShare / 10_000
LPFee = TotalFee - ProtocolFee

10. MIT License

This SDK is released under the MIT License.


11. Repository

For bug reports, contributions, or feature requests, please open an issue or submit a ticket on GitHub.

Last updated