How turbos-finance/turbos-clmm-sdk works
Project Type and Purpose
• This is a TypeScript SDK (open-source library) that provides a high-level facade for interacting with a Sui-based concentrated-liquidity AMM (CLMM).
• Its main goal is to expose modules like contract, trade, pool, nft, account, and math so that dApp developers can easily query on-chain data and build/execute transactions.
File Structure
• Top–level config for linting, formatting, CI/CD (.github, .husky, tsconfig.json, vitest.config.ts, tsup.config.ts).
• Source code under src/:
• src/constants: network & magic numbers
• src/lib: module implementations (account.ts, contract.ts, trade.ts, pool.ts, nft.ts, math.ts, etc.)
• src/utils: helper functions (bit-math, quote calculations, Sui-kit wrappers)
• src/sdk.ts: entry point, constructs TurbosSdk class exposing each module
• src/index.ts: package export aggregator
• Tests under test/ validate each module.
Extract Architecture Clues from README
• README shows instantiation patterns: TurbosSdk takes a Network enum or a JsonRpcProvider.
• Exposes methods: sdk.contract.getConfig(), sdk.trade.swap(), etc.
• Relies on @mysten/sui’s JsonRpcProvider to talk to testnet/mainnet.
Main Components & Their Relationships
a. Developer Application
• Imports TurbosSdk, passes network/provider, calls high-level methods.
b. TurbosSdk (Facade Layer)
• Holds references to all modules (contract, trade, pool, nft, account, math).
• Normalizes input parameters and delegates calls.
c. Modules (Business Logic Layer)
• Each module (in src/lib) contains functions that build RPC queries or transactions, call utils, use constants.
d. Utils & Constants (Helper Layer)
• Pure functions for bit math, fee/reward quotes, object validation.
• Centralized magic-numbers and network configurations.
e. Sui JsonRpcProvider (Infrastructure Layer)
• Underlying RPC client from @mysten/sui that sends JSON-RPC requests to the blockchain.
f. Sui Blockchain Nodes
• Remote testnet/mainnet nodes which process requests and return data or transaction confirmations.
Architectural Patterns & Principles
• Facade Pattern: TurbosSdk exposes a simplified interface over many modules.
• Layered Architecture: separation between SDK entrypoint, modules, utilities, and external provider.
• Single-Responsibility: each module focuses on one domain (trade, pool, etc.).
• Dependency Injection: provider can be passed in by consumer.
Key Details to Capture
• Facade entrypoint (src/sdk.ts) and how it wires modules.
• Each module’s reliance on provider and utils.
• Flow of data: high-level method call → module logic → provider RPC → blockchain → back.
• Configurable network/provider at SDK instantiation.