$ show MeteoraAg/dlmm-sdk
This repository is the Meteora DLMM (Dynamic Liquidity Market Maker) SDK, a comprehensive multi-language toolkit for interacting with the Meteora concentrated liquidity AMM protocol on Solana. The system includes a Rust core library (`commons/`) with swap quoting, fee calculation, PDA derivation, and math utilities; a TypeScript client (`ts-client/`) that provides a high-level `DLMM` class for pool interaction, liquidity management, rebalancing, and limit orders; a Rust CLI for admin and user operations; a Python client that wraps the TypeScript SDK via a REST API; and a market-making bot example. The on-chain program is defined in IDL files with over 50 instructions supporting multiple pool types (permissionless, permissioned, customizable), Token-2022 with transfer hooks, and advanced features like volatility-based dynamic fees and oracle TWAP. Architecturally, the SDK is layered: the Rust `commons` crate contains the core business logic and is reused by the CLI and market-making bot, while the TypeScript client reimplements much of this logic for off-chain use. The CLI serves as a reference implementation for all protocol operations. The market-making bot demonstrates automated position rebalancing using configurable strategies. The Python client is a thin wrapper that delegates to a TypeScript server, making it less independent. The codebase is heavily tested with Rust integration tests and TypeScript unit tests, including property-based tests for bid-ask math and Token-2022 compatibility. The primary data flows are: user requests (swap, add/remove liquidity, claim fees) go through the client SDK, which constructs and signs transactions for the Meteora DLMM on-chain program. The SDK computes quotes off-chain, simulates rebalancing, and derives required accounts. The market-making bot periodically fetches pool state, evaluates active price drift, and executes rebalancing transactions. The codebase demonstrates strong engineering practices with clear separation of concerns, reusable math utilities, and consistent patterns across languages.
The LLM identified 4 files worth highlighting for reuse:
Implements the core swap quoting engine for both exact-in and exact-out trades. It handles per-bin fill across multiple liquidity sources (MM, processed limit orders, open limit orders), splits fees with limit order placers, and integrates the volatility accumulator for dynamic fee calculation. The module is self-contained, relies only on common math and account structures, and could be extracted to power any bin-based AMM with minimal changes.
Defines the abstract base class and concrete implementations (Spot, Curve, BidAsk) for liquidity distribution strategies. These classes compute per-bin amounts based on strategy parameters and are used for position initialization and rebalancing. The design is clean, extensible, and reusable across different pool types, and it demonstrates non-obvious optimization for concentrated liquidity allocation.
Provides a U512-based bitmap extension to efficiently track and iterate over initialized bin arrays. This avoids scanning all possible bin arrays, significantly reducing account fetching overhead. The pattern is isolated and could be reused in any SOLANA program or client that needs to maintain a sparse set of indexed items.
Contains high-precision fixed-point arithmetic functions (mulDiv, shlDiv, safeMulShrCast) used throughout the SDK for fee calculations, price conversions, and liquidity amounts. These functions are parameterized with rounding modes and are independent of the rest of the codebase, making them directly reusable in other Solana SDKs or DeFi applications.