Skip to main content
This reference provides authoritative type definitions for all interfaces, types, and enums in the DLMM TypeScript SDK. All types are from the actual SDK source code.
SDK Version: v1.3.2 | Package: @saros-finance/dlmm-sdk | TypeScript: 5.8.3+

Core SDK Types

ILiquidityBookConfig

Primary configuration interface for DLMM SDK initialization.
interface ILiquidityBookConfig {
  /** Network mode selection */
  mode: MODE;
  
  /** Optional connection configuration */
  options?: {
    /** Custom RPC URL */
    rpcUrl: string;
    /** Transaction commitment level or full config */
    commitmentOrConfig?: Commitment | ConnectionConfig;
  };
}
Usage:
const config: ILiquidityBookConfig = {
  mode: MODE.MAINNET,
  options: {
    rpcUrl: "https://api.mainnet-beta.solana.com",
    commitmentOrConfig: "confirmed"
  }
};

MODE

Network environment enumeration.
enum MODE {
  TESTNET = "testnet",
  DEVNET = "devnet", 
  MAINNET = "mainnet"
}

Trading Parameter Types

GetTokenOutputParams

Parameters for quote calculations.
interface GetTokenOutputParams {
  /** Pool address */
  pair: PublicKey;
  
  /** Base token mint */
  tokenBase: PublicKey;
  
  /** Quote token mint */
  tokenQuote: PublicKey;
  
  /** Input amount in token base units */
  amount: bigint;
  
  /** Swap direction: true = base→quote, false = quote→base */
  swapForY: boolean;
  
  /** Input precision: true = exact input, false = exact output */
  isExactInput: boolean;
  
  /** Base token decimals */
  tokenBaseDecimal: number;
  
  /** Quote token decimals */
  tokenQuoteDecimal: number;
  
  /** Slippage tolerance percentage */
  slippage: number;
}

GetTokenOutputResponse

Quote calculation results.
interface GetTokenOutputResponse {
  /** Required input amount */
  amountIn: bigint;
  
  /** Expected output amount */
  amountOut: bigint;
  
  /** Price impact percentage */
  priceImpact: number;
  
  /** Amount with slippage adjustment */
  amount: bigint;
  
  /** Offset amount for slippage protection */
  otherAmountOffset: bigint;
}

SwapParams

Parameters for swap transaction creation.
interface SwapParams {
  /** X token mint address */
  tokenMintX: PublicKey;
  
  /** Y token mint address */
  tokenMintY: PublicKey;
  
  /** Swap amount in token units */
  amount: bigint;
  
  /** Minimum output offset from quote */
  otherAmountOffset: bigint;
  
  /** Swap direction */
  swapForY: boolean;
  
  /** Input precision type */
  isExactInput: boolean;
  
  /** Pool address */
  pair: PublicKey;
  
  /** Hook program address */
  hook: PublicKey;
  
  /** Transaction payer */
  payer: PublicKey;
}

Position Management Types

CreatePositionParams

Parameters for creating new liquidity positions.
interface CreatePositionParams {
  /** Position creator and transaction payer */
  payer: PublicKey;
  
  /** Left bin boundary (relative to active bin) */
  relativeBinIdLeft: number;
  
  /** Right bin boundary (relative to active bin) */
  relativeBinIdRight: number;
  
  /** Target pool address */
  pair: PublicKey;
  
  /** Bin array index for position */
  binArrayIndex: number;
  
  /** Position NFT mint address */
  positionMint: PublicKey;
  
  /** Transaction to append instructions to */
  transaction: Transaction;
}

PositionInfo

Position data structure returned by queries.
interface PositionInfo {
  /** Pool address */
  pair: string;
  
  /** Position NFT mint */
  positionMint: string;
  
  /** Position account address */
  position: string;
  
  /** Liquidity shares per bin */
  liquidityShares: string[];
  
  /** Lower bin boundary ID */
  lowerBinId: number;
  
  /** Upper bin boundary ID */
  upperBinId: number;
  
  /** Reserved space array */
  space: number[];
}

AddLiquidityIntoPositionParams

Parameters for adding liquidity to existing positions.
interface AddLiquidityIntoPositionParams {
  /** Position NFT mint */
  positionMint: PublicKey;
  
  /** Liquidity provider wallet */
  payer: PublicKey;
  
  /** Pool address */
  pair: PublicKey;
  
  /** Transaction to modify */
  transaction: Transaction;
  
  /** Liquidity distribution across bins */
  liquidityDistribution: Distribution[];
  
  /** Y token amount to add */
  amountY: number;
  
  /** X token amount to add */
  amountX: number;
  
  /** Lower bin array address */
  binArrayLower: PublicKey;
  
  /** Upper bin array address */
  binArrayUpper: PublicKey;
}

Distribution

Liquidity distribution configuration for individual bins.
interface Distribution {
  /** Bin ID relative to position center */
  relativeBinId: number;
  
  /** X token distribution amount */
  distributionX: number;
  
  /** Y token distribution amount */
  distributionY: number;
}

RemoveMultipleLiquidityParams

Parameters for bulk liquidity removal operations.
interface RemoveMultipleLiquidityParams {
  /** List of positions to process */
  maxPositionList: {
    /** Position account address */
    position: string;
    /** Start bin ID */
    start: number;
    /** End bin ID */
    end: number;
    /** Position NFT mint */
    positionMint: string;
  }[];
  
  /** Transaction payer */
  payer: PublicKey;
  
  /** Removal type selection */
  type: "removeBoth" | "removeBaseToken" | "removeQuoteToken";
  
  /** Pool address */
  pair: PublicKey;
  
  /** X token mint */
  tokenMintX: PublicKey;
  
  /** Y token mint */
  tokenMintY: PublicKey;
  
  /** Current active bin ID */
  activeId: number;
}

RemoveMultipleLiquidityResponse

Results from bulk liquidity removal.
interface RemoveMultipleLiquidityResponse {
  /** Array of removal transactions */
  txs: Transaction[];
  
  /** Account creation transaction (if needed) */
  txCreateAccount?: Transaction;
  
  /** Account closure transaction (if needed) */
  txCloseAccount?: Transaction;
  
  /** List of positions that were fully closed */
  positionClosed?: Record<string, string>[];
}

Pool and Pair Types

Pair

Complete pair/pool data structure from on-chain account.
interface Pair {
  /** PDA bump seed */
  bump: number[];
  
  /** Liquidity book configuration address */
  liquidityBookConfig: string;
  
  /** Bin step (price step) configuration */
  binStep: number;
  
  /** Bin step seed array */
  binStepSeed: number[];
  
  /** X token mint address */
  tokenMintX: string;
  
  /** Y token mint address */
  tokenMintY: string;
  
  /** Static fee configuration */
  staticFeeParameters: {
    /** Base fee factor */
    baseFactor: number;
    /** Fee filter period */
    filterPeriod: number;
    /** Fee decay period */
    decayPeriod: number;
    /** Fee reduction factor */
    reductionFactor: number;
    /** Variable fee control */
    variableFeeControl: number;
    /** Maximum volatility accumulator */
    maxVolatilityAccumulator: number;
    /** Protocol fee share */
    protocolShare: number;
    /** Reserved space */
    space: [number, number];
  };
  
  /** Current active bin ID */
  activeId: number;
  
  /** Dynamic fee parameters */
  dynamicFeeParameters: {
    /** Last update timestamp */
    timeLastUpdated: BN;
    /** Volatility accumulator */
    volatilityAccumulator: number;
    /** Volatility reference */
    volatilityReference: number;
    /** ID reference */
    idReference: number;
    /** Reserved space */
    space: [number, number, number, number];
  };
  
  /** Protocol fees in X token */
  protocolFeesX: string;
  
  /** Protocol fees in Y token */
  protocolFeesY: string;
  
  /** Hook program address (nullable) */
  hook: null | string;
}

PoolMetadata

Pool metadata for external integrations.
interface PoolMetadata {
  /** Pool address */
  poolAddress: string;
  
  /** Base token mint */
  baseMint: string;
  
  /** Base token reserve amount */
  baseReserve: string;
  
  /** Quote token mint */
  quoteMint: string;
  
  /** Quote token reserve amount */
  quoteReserve: string;
  
  /** Trading fee rate */
  tradeFee: number;
  
  /** Additional metadata */
  extra: {
    /** Hook address (optional) */
    hook?: string;
    /** Quote token decimals */
    tokenQuoteDecimal: number;
    /** Base token decimals */
    tokenBaseDecimal: number;
  };
}

CreatePairWithConfigParams

Parameters for creating new DLMM pools.
interface CreatePairWithConfigParams {
  /** Base token configuration */
  tokenBase: {
    /** Token decimal places */
    decimal: number;
    /** Token mint address */
    mintAddress: string;
  };
  
  /** Quote token configuration */
  tokenQuote: {
    /** Token decimal places */
    decimal: number;
    /** Token mint address */
    mintAddress: string;
  };
  
  /** Bin step (price step between bins) */
  binStep: number;
  
  /** Initial exchange rate price */
  ratePrice: number;
  
  /** Pool creator and payer */
  payer: PublicKey;
}

Bin Array Types

GetBinArrayParams

Parameters for bin array operations.
interface GetBinArrayParams {
  /** Bin array index number */
  binArrayIndex: number;
  
  /** Pool address */
  pair: PublicKey;
  
  /** Payer address (optional) */
  payer?: PublicKey;
  
  /** Transaction to modify (optional) */
  transaction?: Transaction;
}

GetBinsArrayInfoParams

Parameters for bin array information queries.
interface GetBinsArrayInfoParams {
  /** Target bin array index */
  binArrayIndex: number;
  
  /** Pool address */
  pair: PublicKey;
  
  /** Query executor address */
  payer: PublicKey;
}

GetBinsReserveParams

Parameters for bin reserve information queries.
interface GetBinsReserveParams {
  /** Position account address */
  position: PublicKey;
  
  /** Pool address */
  pair: PublicKey;
  
  /** Query executor address */
  payer: PublicKey;
}

GetBinsReserveResponse

Response structure for bin reserve queries.
interface GetBinsReserveResponse {
  /** X token reserve in bin */
  reserveX: string | number;
  
  /** Y token reserve in bin */
  reserveY: string | number;
  
  /** Total liquidity supply in bin */
  totalSupply: string | number;
  
  /** User's liquidity share */
  liquidityShare: BN;
  
  /** Bin identifier */
  binId: number;
  
  /** Position within bin array */
  binPosistion: number;
}

ReserveParams

Reserve information for calculations.
interface ReserveParams {
  /** Bin identifier */
  binId: number;
  
  /** X token reserve */
  reserveX: string | number;
  
  /** Y token reserve */
  reserveY: string | number;
  
  /** Liquidity share amount */
  liquidityShare: string | number;
}

Configuration Types

LiquidityBookConfig

Detailed configuration parameters for liquidity book operations.
type LiquidityBookConfig = {
  /** Base fee factor */
  baseFactor: number;
  
  /** Bin step configuration */
  binStep: number;
  
  /** Active bin ID */
  activeId: number;
  
  /** Bin array size */
  binArraySize: number;
  
  /** Bin array index */
  binArrayIndex: number;
  
  /** Maximum basis points */
  maxBasisPoints: number;
  
  /** Filter period for fees */
  filterPeriod: number;
  
  /** Fee decay period */
  decayPeriod: number;
  
  /** Fee reduction factor */
  reductionFactor: number;
  
  /** Variable fee control */
  variableFeeControl: number;
  
  /** Maximum volatility accumulator */
  maxVolatilityAccumulator: number;
  
  /** Protocol share percentage */
  protocolShare: number;
  
  /** Start time */
  startTime: number;
  
  /** Rewards duration */
  rewardsDuration: number;
  
  /** Rewards per second */
  rewardsPerSecond: number;
};

Bin

Individual bin data structure.
type Bin = {
  /** X token reserves */
  reserveX: number;
  
  /** Y token reserves */
  reserveY: number;
  
  /** Total liquidity supply */
  totalSupply: number;
};

BinArray

Bin array structure with metadata.
type BinArray = {
  /** Array of bins */
  bins: Bin[];
  
  /** Array index number */
  index: number;
};

Fee Parameter Types

StaticFeeParameters

Static fee configuration structure.
type StaticFeeParameters = {
  /** Base fee factor */
  baseFactor: number;
  
  /** Fee filter period */
  filterPeriod: number;
  
  /** Fee decay period */
  decayPeriod: number;
  
  /** Fee reduction factor */
  reductionFactor: number;
  
  /** Variable fee control parameter */
  variableFeeControl: number;
  
  /** Maximum volatility accumulator */
  maxVolatilityAccumulator: number;
  
  /** Protocol fee share */
  protocolShare: number;
  
  /** Reserved space */
  space: Uint8Array;
};

DynamicFeeParameters

Dynamic fee configuration that changes based on volatility.
type DynamicFeeParameters = {
  /** Last update timestamp */
  timeLastUpdated: bigint;
  
  /** Current volatility accumulator */
  volatilityAccumulator: number;
  
  /** Volatility reference value */
  volatilityReference: number;
  
  /** Reference bin ID */
  idReference: number;
  
  /** Reserved space */
  space: Uint8Array;
};

PairInfo

Complete pair information structure.
type PairInfo = {
  /** PDA bump array */
  bump: Uint8Array;
  
  /** Liquidity book configuration */
  liquidityBookConfig: PublicKey;
  
  /** Bin step size */
  binStep: number;
  
  /** Bin step seed */
  binStepSeed: Uint8Array;
  
  /** X token mint */
  tokenMintX: PublicKey;
  
  /** Y token mint */
  tokenMintY: PublicKey;
  
  /** Static fee parameters */
  staticFeeParameters: StaticFeeParameters;
  
  /** Current active bin ID */
  activeId: number;
  
  /** Dynamic fee parameters */
  dynamicFeeParameters: DynamicFeeParameters;
  
  /** Protocol fees in X token */
  protocolFeesX: BN;
  
  /** Protocol fees in Y token */
  protocolFeesY: BN;
  
  /** Hook program (nullable) */
  hook: PublicKey | null;
};

User Interface Types

UserPositionsParams

Parameters for user position queries.
interface UserPositionsParams {
  /** User wallet address */
  payer: PublicKey;
  
  /** Pool address to query */
  pair: PublicKey;
}

GetUserVaultInfoParams

Parameters for user vault account operations.
interface GetUserVaultInfoParams {
  /** Token mint address */
  tokenAddress: PublicKey;
  
  /** User wallet address */
  payer: PublicKey;
  
  /** Transaction to modify (optional) */
  transaction?: Transaction;
}

Liquidity Shape Enumerations

LiquidityShape

Liquidity distribution patterns.
enum LiquidityShape {
  /** Single price point liquidity */
  Spot = "Spot",
  
  /** Curved distribution */
  Curve = "Curve",
  
  /** Bid-ask spread distribution */
  BidAsk = "BidAsk"
}

RemoveLiquidityType

Liquidity removal options.
enum RemoveLiquidityType {
  /** Remove both tokens proportionally */
  Both = "removeBoth",
  
  /** Remove only base token */
  BaseToken = "removeBaseToken",
  
  /** Remove only quote token */
  QuoteToken = "removeQuoteToken"
}

Constants and Configuration

Network Configuration

const CONFIG = {
  [MODE.TESTNET]: { rpc: "https://api.testnet.solana.com" },
  [MODE.DEVNET]: { rpc: "https://api.devnet.solana.com" },
  [MODE.MAINNET]: { rpc: "https://api.mainnet-beta.solana.com" }
};

DLMM Constants

// Core protocol constants
const BIN_ARRAY_SIZE = 256;
const MAX_BASIS_POINTS = 10_000;
const SCALE_OFFSET = 64;
const PRECISION = 1_000_000_000;
const VARIABLE_FEE_PRECISION = 100_000_000_000;
const BASIS_POINT_MAX = 10_000;

// Gas and performance
const UNIT_PRICE_DEFAULT = 1_000_000;
const CCU_LIMIT = 400_000;

// Position management
const FIXED_LENGTH = 16;

// Native SOL wrapper
const WRAP_SOL_ADDRESS = "So11111111111111111111111111111111111111112";

Supported Bin Steps

// Available bin step configurations
const SUPPORTED_BIN_STEPS = [1, 2, 5, 10, 20, 50, 100, 200, 250];

// Each bin step has corresponding fee parameters:
// - baseFactor: Base fee component
// - filterPeriod: Fee adjustment filter period
// - decayPeriod: Fee decay time
// - reductionFactor: Fee reduction factor
// - variableFeeControl: Variable fee control parameter
// - maxVolatilityAccumulator: Maximum volatility
// - protocolShare: Protocol fee share (typically 2000 = 20%)

Generic and Utility Types

Solana Integration Types

// Re-exported from @solana/web3.js
type PublicKey = import("@solana/web3.js").PublicKey;
type Transaction = import("@solana/web3.js").Transaction;
type Commitment = import("@solana/web3.js").Commitment;
type ConnectionConfig = import("@solana/web3.js").ConnectionConfig;

// Re-exported from @coral-xyz/anchor
type BN = import("@coral-xyz/anchor").BN;

Anchor Integration Types

// Anchor Wallet interface
interface AnchorWallet {
  publicKey: PublicKey;
  signTransaction(tx: Transaction): Promise<Transaction>;
  signAllTransactions(txs: Transaction[]): Promise<Transaction[]>;
}

Type Guards and Utilities

Type Safety Helpers

// Check if value is valid PublicKey
function isValidPublicKey(value: any): value is PublicKey {
  return value instanceof PublicKey;
}

// Check if pair has active liquidity
function hasActiveLiquidity(pair: Pair): boolean {
  return pair.activeId > 0;
}

// Check if position is within range
function isPositionInRange(position: PositionInfo, activeId: number): boolean {
  return activeId >= position.lowerBinId && activeId <= position.upperBinId;
}

// Validate swap parameters
function isValidSwapParams(params: SwapParams): boolean {
  return params.amount > 0n && 
         params.otherAmountOffset >= 0n &&
         isValidPublicKey(params.pair);
}

Amount Conversion Utilities

// Convert UI amount to token base units
function toTokenAmount(uiAmount: number, decimals: number): bigint {
  return BigInt(Math.floor(uiAmount * Math.pow(10, decimals)));
}

// Convert token base units to UI amount
function fromTokenAmount(amount: bigint, decimals: number): number {
  return Number(amount) / Math.pow(10, decimals);
}

// Format USD amounts consistently
function formatUSD(amount: string | number): string {
  return new Intl.NumberFormat('en-US', {
    style: 'currency',
    currency: 'USD',
    minimumFractionDigits: 2,
    maximumFractionDigits: 2
  }).format(Number(amount));
}

Error Type Patterns

Error Handling Types

// Standard error structure
interface DLMMError extends Error {
  code: string;
  details?: any;
  retryable: boolean;
}

// Common error types thrown by SDK methods
type CommonErrors = 
  | 'Pair not found'
  | 'Swap crosses too many bins – quote aborted.'
  | 'No valid bin arrays found for the pair'
  | 'Bin not found'
  | 'Bin array index mismatch';

Complete Import Example

Production Setup

import { 
  // Core SDK
  LiquidityBookServices,
  
  // Configuration
  ILiquidityBookConfig,
  MODE,
  
  // Trading
  GetTokenOutputParams,
  GetTokenOutputResponse,
  SwapParams,
  
  // Position management
  CreatePositionParams,
  PositionInfo,
  AddLiquidityIntoPositionParams,
  Distribution,
  RemoveMultipleLiquidityParams,
  RemoveMultipleLiquidityResponse,
  
  // Pool types
  Pair,
  PoolMetadata,
  CreatePairWithConfigParams,
  
  // Bin management
  GetBinArrayParams,
  GetBinsArrayInfoParams,
  GetBinsReserveParams,
  GetBinsReserveResponse,
  ReserveParams,
  
  // Enums
  LiquidityShape,
  RemoveLiquidityType,
  
  // Utilities
  GetUserVaultInfoParams,
  UserPositionsParams
} from '@saros-finance/dlmm-sdk';

// Solana dependencies
import { PublicKey, Transaction } from '@solana/web3.js';
import { BN } from '@coral-xyz/anchor';

Type Compatibility

Version Support Matrix

Typev1.3.2v1.3.0v1.2.xNotes
ILiquidityBookConfig✅ Current✅ Compatible✅ CompatibleStable since v1.0
SwapParams✅ Current✅ Compatible⚠️ Different signaturev1.3: Added hook parameter
Pair✅ Current✅ Compatible❌ Missing fieldsv1.2: Added dynamic fees
PositionInfo✅ Current✅ Compatible✅ CompatibleStable interface

Reference Documentation

Getting Started (Tutorials)

Solve Problems (How-To Guides)

Understanding Concepts (Explanation)

Understanding Concepts (Explanation)