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 withlendingMarketType(string): The type signature of the lending marketclient(SuiClient): Initialized Sui client instancelogPackageId(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 instancelendingMarketId(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 registrylendingMarketType(string): Type signature for the new markettransaction(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 ownerlendingMarketTypeArgs(string[]): Type arguments for the lending marketclient(SuiClient): Sui client instance
Returns: Promise<ObligationOwnerCap[]>
getObligation
Retrieves obligation data by ID.
Parameters:
obligationId(string): ID of the obligationlendingMarketTypeArgs(string[]): Type arguments for the lending marketclient(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 ownerlendingMarketTypeArgs(string[]): Type arguments for the lending marketclient(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 depositorcoinType(string): Type of the coin being depositedvalue(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 depositorcoinType(string): Type of the coin being depositedvalue(string): Amount to deposittransaction(Transaction): Transaction to modifyobligationOwnerCapId(string | TransactionResult): Obligation owner capability
Example:
withdraw
Withdraws collateral from an obligation.
Parameters:
obligationOwnerCapId(string): ID of the obligation owner capabilityobligationId(string): ID of the obligationcoinType(string): Type of coin to withdrawvalue(string): Amount to withdrawtransaction(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 toobligationOwnerCapId(string): ID of the obligation owner capabilityobligationId(string): ID of the obligationcoinType(string): Type of coin to withdrawvalue(string): Amount to withdrawtransaction(Transaction): Transaction to modify
borrow
Borrows tokens against collateral in an obligation.
Parameters:
obligationOwnerCapId(string): ID of the obligation owner capabilityobligationId(string): ID of the obligationcoinType(string): Type of coin to borrowvalue(string): Amount to borrowtransaction(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 toobligationOwnerCapId(string): ID of the obligation owner capabilityobligationId(string): ID of the obligationcoinType(string): Type of coin to borrowvalue(string): Amount to borrowtransaction(Transaction): Transaction to modify
repayIntoObligation
Repays borrowed amount into an obligation.
Parameters:
ownerId(string): Address of the repayerobligationId(string): ID of the obligationcoinType(string): Type of coin being repaidvalue(string): Amount to repaytransaction(Transaction): Transaction to modify
liquidate
Liquidates an unhealthy obligation.
Parameters:
transaction(Transaction): Transaction to modifyobligation(Obligation): The obligation to liquidaterepayCoinType(string): Type of coin used for repaymentwithdrawCoinType(string): Type of collateral to receiverepayCoinId(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 modifyobligation(Obligation): The obligation to liquidaterepayCoinType(string): Type of coin used for repaymentwithdrawCoinType(string): Type of collateral to receiverepayCoinId(TransactionObjectInput): Coin object used for repayment
Reward Operations
claimRewards
Claims multiple rewards from liquidity mining programs.
Parameters:
ownerId(string): Address of the reward claimerobligationOwnerCapId(string): ID of the obligation owner capabilityrewards(ClaimRewardsReward[]): Array of rewards to claimtransaction(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 toobligationOwnerCapId(string): ID of the obligation owner capabilityrewards(ClaimRewardsReward[]): Array of rewards to claimtransaction(Transaction): Transaction to modify
claimRewardsAndDeposit
Claims rewards and automatically deposits them back into the protocol.
Parameters:
ownerId(string): Address of the userobligationOwnerCapId(string): ID of the obligation owner capabilityrewards(ClaimRewardsReward[]): Array of rewards to claimtransaction(Transaction): Transaction to modify
Administrative Operations
createReserve
Creates a new reserve in the lending market.
Parameters:
lendingMarketOwnerCapId(string): ID of the lending market owner capabilitytransaction(Transaction): Transaction to modifypythPriceId(string): Pyth price feed ID for the assetcoinType(string): Type of the coin for the reservecreateReserveConfigArgs(CreateReserveConfigArgs): Configuration for the reserve
addReward
Adds a liquidity mining reward to a reserve.
Parameters:
ownerId(string): Address of the reward providerlendingMarketOwnerCapId(string): ID of the lending market owner capabilityreserveArrayIndex(bigint): Index of the reserve in the marketisDepositReward(boolean): Whether this is a deposit or borrow rewardrewardCoinType(string): Type of coin being provided as rewardrewardValue(string): Amount of reward tokensstartTimeMs(bigint): Start time in millisecondsendTimeMs(bigint): End time in millisecondstransaction(Transaction): Transaction to modifymergeCoins(boolean): Whether to merge coins for gas optimization
cancelReward
Cancels an active reward program.
Parameters:
lendingMarketOwnerCapId(string): ID of the lending market owner capabilityreserveArrayIndex(bigint): Index of the reserveisDepositReward(boolean): Whether this is a deposit or borrow rewardrewardIndex(bigint): Index of the reward to cancelrewardCoinType(string): Type of reward cointransaction(Transaction): Transaction to modify
closeReward
Closes a completed reward program and claims remaining tokens.
Parameters:
lendingMarketOwnerCapId(string): ID of the lending market owner capabilityreserveArrayIndex(bigint): Index of the reserveisDepositReward(boolean): Whether this is a deposit or borrow rewardrewardIndex(bigint): Index of the reward to closerewardCoinType(string): Type of reward cointransaction(Transaction): Transaction to modify
updateReserveConfig
Updates the configuration of an existing reserve.
Parameters:
lendingMarketOwnerCapId(string): ID of the lending market owner capabilitytransaction(Transaction): Transaction to modifycoinType(string): Type of coin for the reserve to updatecreateReserveConfigArgs(CreateReserveConfigArgs): New configuration
Utility Methods
refreshAll
Refreshes price feeds and obligation state before performing operations.
Parameters:
transaction(Transaction): Transaction to modifyobligation(Obligation): Obligation to refreshextraReserveArrayIndex(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
Network Errors: Connection issues with Sui RPC
Transaction Errors: Invalid transaction parameters or execution failures
Insufficient Funds: Not enough tokens for the requested operation
Invalid Obligations: Obligation not found or access denied
Liquidation Errors: Obligation not eligible for liquidation
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.