Suilend SDK Guide

A TypeScript SDK for interacting with the Suilend lending protocol on the Sui blockchain. This SDK provides a complete interface for lending, borrowing, liquidity mining, and administrative operations.

npm version TypeScript

Table of Contents

  • [Installation]

  • [Quick Start]

  • [Architecture Overview]

  • [Core Concepts]

  • [API Reference]

  • [Examples]

  • [Generated Code]

  • [Types and Enums]

  • [Contributing]

  • [Support]

Installation

npm install @suilend/sdk

Peer Dependencies

The SDK requires the following peer dependencies:

Quick Start

Architecture Overview

The Suilend SDK is organized into several core modules:

Core Modules

  • Client (SuilendClient): Main interface for all lending operations

  • API: Event fetching and blockchain data retrieval

  • Parsers: Data structure parsing and validation utilities

  • Swap: DEX integration for token swapping operations

  • Utils: General utilities and helper functions

  • Generated: Auto-generated code from on-chain smart contracts

Key Components

Core Concepts

Lending Markets

Lending markets are the primary containers for reserves and obligations. Each market has:

  • A unique market ID

  • A specific coin type (collateral type)

  • Multiple reserves for different assets

  • Associated obligations for users

Reserves

Reserves represent individual asset pools within a lending market:

  • Store deposited liquidity

  • Track borrowing activity

  • Manage interest rates and rewards

  • Issue cTokens (claim tokens) to depositors

Obligations

Obligations represent user positions within a lending market:

  • Track deposited collateral (cTokens)

  • Track borrowed amounts

  • Calculate health ratios

  • Manage liquidation risk

cTokens (Claim Tokens)

cTokens represent ownership of deposited assets:

  • Earned when depositing into reserves

  • Accrue value over time through interest

  • Can be redeemed for underlying assets

  • Used as collateral for borrowing

API Reference

SuilendClient

The main client class for interacting with Suilend protocol.

Initialization

Core Operations

Deposit Operations

Withdrawal Operations

Borrowing Operations

Liquidation Operations

Reward Operations

Administrative Operations

Data Retrieval

Events API

The SDK provides comprehensive event parsing for tracking protocol activity:

Swap Integration

The SDK includes DEX aggregation capabilities:

Examples

Complete Lending Flow

Administrative Example

Generated Code

The SDK includes auto-generated TypeScript bindings for all on-chain smart contract functions and data structures. These are located in the _generated directory and provide:

  • Function bindings: Direct access to all smart contract functions

  • Struct definitions: TypeScript interfaces for all on-chain data structures

  • Type safety: Full type checking for all blockchain interactions

The generated code is organized by package and module:

  • suilend/: Core Suilend protocol functions and structs

  • _dependencies/: External dependencies (Sui framework, Pyth, etc.)

  • _framework/: Framework utilities and loaders

Types and Enums

Core Enums

Key Interfaces

Configuration

Environment Variables

The SDK behavior can be configured using environment variables:

  • NEXT_PUBLIC_SUILEND_USE_BETA_MARKET: Set to "true" to use beta market endpoints

Constants

Error Handling

The SDK uses standard JavaScript Error objects and blockchain-specific errors from the Sui SDK. Always wrap SDK calls in try-catch blocks:

Performance Considerations

  • Batch operations: Use transactions to batch multiple operations

  • Refresh cycles: Call refreshAll() to update obligation state before operations

  • Gas optimization: Merge coins when possible to reduce transaction complexity

Contributing

  1. Fork the repository

  2. Create a feature branch

  3. Make your changes

  4. Add tests if applicable

  5. Submit a pull request

Support

  • Documentation: This README and inline code documentation

  • Discord: Join our #dev-support channel

  • Issues: Report bugs on GitHub Issues

License

MIT License - see LICENSE file for details.