Suilend SDK API Reference

This document provides detailed API reference for all public methods and interfaces in the Suilend SDK.

Table of Contents

  • [SuilendClient]

  • [Static Methods]

  • [Instance Methods]

  • [Types and Interfaces]

  • [Constants]

  • [Error Handling]

SuilendClient

The main client class that provides all functionality for interacting with Suilend lending markets.

Constructor

constructor(lendingMarket: LendingMarket<string>, client: SuiClient)

Note: Use the static initialize() method instead of calling the constructor directly.

Static Methods

initialize

Initializes a new SuilendClient instance.

Parameters:

  • lendingMarketId (string): The ID of the lending market to interact with

  • lendingMarketType (string): The type signature of the lending market

  • client (SuiClient): Initialized Sui client instance

  • logPackageId (boolean, optional): Whether to log the package ID during initialization

Returns: Promise

Example:

getFeeReceivers

Retrieves fee receiver configuration for a lending market.

Parameters:

  • client (SuiClient): Sui client instance

  • lendingMarketId (string): ID of the lending market

Returns: Promise<FeeReceivers>

createNewLendingMarket

Creates a new lending market in the specified registry.

Parameters:

  • registryId (string): ID of the lending market registry

  • lendingMarketType (string): Type signature for the new market

  • transaction (Transaction): Transaction to add the creation call to

Returns: TransactionResult

getObligationOwnerCaps

Retrieves all obligation owner capabilities for a given owner.

Parameters:

  • ownerId (string): Address of the obligation owner

  • lendingMarketTypeArgs (string[]): Type arguments for the lending market

  • client (SuiClient): Sui client instance

Returns: Promise<ObligationOwnerCap[]>

getObligation

Retrieves obligation data by ID.

Parameters:

  • obligationId (string): ID of the obligation

  • lendingMarketTypeArgs (string[]): Type arguments for the lending market

  • client (SuiClient): Sui client instance

Returns: Promise<Obligation>

getLendingMarketOwnerCapId

Retrieves the lending market owner capability ID for a given owner.

Parameters:

  • ownerId (string): Address of the potential market owner

  • lendingMarketTypeArgs (string[]): Type arguments for the lending market

  • client (SuiClient): Sui client instance

Returns: Promise<string | null>

Instance Methods

Core Operations

createObligation

Creates a new obligation in the lending market.

Parameters:

  • transaction (Transaction): Transaction to add the creation call to

Returns: TransactionResult representing the obligation owner capability

Example:

depositLiquidityAndGetCTokens

Deposits liquidity into a reserve and receives cTokens in return.

Parameters:

  • ownerId (string): Address of the depositor

  • coinType (string): Type of the coin being deposited

  • value (string): Amount to deposit (in smallest denomination)

  • transaction (Transaction): Transaction to add the deposit call to

Returns: Promise representing the minted cTokens

Example:

depositIntoObligation

Deposits tokens into an obligation as collateral.

Parameters:

  • ownerId (string): Address of the depositor

  • coinType (string): Type of the coin being deposited

  • value (string): Amount to deposit

  • transaction (Transaction): Transaction to modify

  • obligationOwnerCapId (string | TransactionResult): Obligation owner capability

Example:

withdraw

Withdraws collateral from an obligation.

Parameters:

  • obligationOwnerCapId (string): ID of the obligation owner capability

  • obligationId (string): ID of the obligation

  • coinType (string): Type of coin to withdraw

  • value (string): Amount to withdraw

  • transaction (Transaction): Transaction to modify

Returns: Promise representing the withdrawn cTokens

withdrawAndSendToUser

Withdraws collateral and automatically sends underlying tokens to user.

Parameters:

  • ownerId (string): Address to send withdrawn tokens to

  • obligationOwnerCapId (string): ID of the obligation owner capability

  • obligationId (string): ID of the obligation

  • coinType (string): Type of coin to withdraw

  • value (string): Amount to withdraw

  • transaction (Transaction): Transaction to modify

borrow

Borrows tokens against collateral in an obligation.

Parameters:

  • obligationOwnerCapId (string): ID of the obligation owner capability

  • obligationId (string): ID of the obligation

  • coinType (string): Type of coin to borrow

  • value (string): Amount to borrow

  • transaction (Transaction): Transaction to modify

Returns: Promise representing the borrowed tokens

borrowAndSendToUser

Borrows tokens and automatically sends them to the user.

Parameters:

  • ownerId (string): Address to send borrowed tokens to

  • obligationOwnerCapId (string): ID of the obligation owner capability

  • obligationId (string): ID of the obligation

  • coinType (string): Type of coin to borrow

  • value (string): Amount to borrow

  • transaction (Transaction): Transaction to modify

repayIntoObligation

Repays borrowed amount into an obligation.

Parameters:

  • ownerId (string): Address of the repayer

  • obligationId (string): ID of the obligation

  • coinType (string): Type of coin being repaid

  • value (string): Amount to repay

  • transaction (Transaction): Transaction to modify

liquidate

Liquidates an unhealthy obligation.

Parameters:

  • transaction (Transaction): Transaction to modify

  • obligation (Obligation): The obligation to liquidate

  • repayCoinType (string): Type of coin used for repayment

  • withdrawCoinType (string): Type of collateral to receive

  • repayCoinId (TransactionObjectInput): Coin object used for repayment

Returns: Promise representing the liquidation bonus

liquidateAndRedeem

Liquidates an obligation and automatically redeems cTokens for underlying assets.

Parameters:

  • transaction (Transaction): Transaction to modify

  • obligation (Obligation): The obligation to liquidate

  • repayCoinType (string): Type of coin used for repayment

  • withdrawCoinType (string): Type of collateral to receive

  • repayCoinId (TransactionObjectInput): Coin object used for repayment

Reward Operations

claimRewards

Claims multiple rewards from liquidity mining programs.

Parameters:

  • ownerId (string): Address of the reward claimer

  • obligationOwnerCapId (string): ID of the obligation owner capability

  • rewards (ClaimRewardsReward[]): Array of rewards to claim

  • transaction (Transaction): Transaction to modify

Returns: Object containing the modified transaction and merged coins map

claimRewardsAndSendToUser

Claims rewards and automatically sends them to the user.

Parameters:

  • ownerId (string): Address to send rewards to

  • obligationOwnerCapId (string): ID of the obligation owner capability

  • rewards (ClaimRewardsReward[]): Array of rewards to claim

  • transaction (Transaction): Transaction to modify

claimRewardsAndDeposit

Claims rewards and automatically deposits them back into the protocol.

Parameters:

  • ownerId (string): Address of the user

  • obligationOwnerCapId (string): ID of the obligation owner capability

  • rewards (ClaimRewardsReward[]): Array of rewards to claim

  • transaction (Transaction): Transaction to modify

Administrative Operations

createReserve

Creates a new reserve in the lending market.

Parameters:

  • lendingMarketOwnerCapId (string): ID of the lending market owner capability

  • transaction (Transaction): Transaction to modify

  • pythPriceId (string): Pyth price feed ID for the asset

  • coinType (string): Type of the coin for the reserve

  • createReserveConfigArgs (CreateReserveConfigArgs): Configuration for the reserve

addReward

Adds a liquidity mining reward to a reserve.

Parameters:

  • ownerId (string): Address of the reward provider

  • lendingMarketOwnerCapId (string): ID of the lending market owner capability

  • reserveArrayIndex (bigint): Index of the reserve in the market

  • isDepositReward (boolean): Whether this is a deposit or borrow reward

  • rewardCoinType (string): Type of coin being provided as reward

  • rewardValue (string): Amount of reward tokens

  • startTimeMs (bigint): Start time in milliseconds

  • endTimeMs (bigint): End time in milliseconds

  • transaction (Transaction): Transaction to modify

  • mergeCoins (boolean): Whether to merge coins for gas optimization

cancelReward

Cancels an active reward program.

Parameters:

  • lendingMarketOwnerCapId (string): ID of the lending market owner capability

  • reserveArrayIndex (bigint): Index of the reserve

  • isDepositReward (boolean): Whether this is a deposit or borrow reward

  • rewardIndex (bigint): Index of the reward to cancel

  • rewardCoinType (string): Type of reward coin

  • transaction (Transaction): Transaction to modify

closeReward

Closes a completed reward program and claims remaining tokens.

Parameters:

  • lendingMarketOwnerCapId (string): ID of the lending market owner capability

  • reserveArrayIndex (bigint): Index of the reserve

  • isDepositReward (boolean): Whether this is a deposit or borrow reward

  • rewardIndex (bigint): Index of the reward to close

  • rewardCoinType (string): Type of reward coin

  • transaction (Transaction): Transaction to modify

updateReserveConfig

Updates the configuration of an existing reserve.

Parameters:

  • lendingMarketOwnerCapId (string): ID of the lending market owner capability

  • transaction (Transaction): Transaction to modify

  • coinType (string): Type of coin for the reserve to update

  • createReserveConfigArgs (CreateReserveConfigArgs): New configuration

Utility Methods

refreshAll

Refreshes price feeds and obligation state before performing operations.

Parameters:

  • transaction (Transaction): Transaction to modify

  • obligation (Obligation): Obligation to refresh

  • extraReserveArrayIndex (bigint, optional): Additional reserve to refresh

findReserveArrayIndex

Finds the array index of a reserve by coin type.

Parameters:

  • coinType (string): Type of coin to find

Returns: bigint representing the reserve array index

Throws: Error if reserve is not found

getObligation

Retrieves obligation data using the client's lending market configuration.

Parameters:

  • obligationId (string): ID of the obligation

Returns: Promise<Obligation>

Types and Interfaces

ClaimRewardsReward

CreateReserveConfigArgs

Side

UiLendingMarket

Constants

Lending Markets

Package Information

Error Handling

The SDK methods can throw various types of errors:

Common Error Types

  1. Network Errors: Connection issues with Sui RPC

  2. Transaction Errors: Invalid transaction parameters or execution failures

  3. Insufficient Funds: Not enough tokens for the requested operation

  4. Invalid Obligations: Obligation not found or access denied

  5. Liquidation Errors: Obligation not eligible for liquidation

  6. Configuration Errors: Invalid reserve or market configuration

Error Handling Best Practices

Rate Limiting

When making multiple API calls, be aware of potential rate limiting from:

  • Sui RPC endpoints

  • Pyth price feed services

  • Internal protocol rate limiters

Implement appropriate retry logic and backoff strategies for production applications.