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
static async initialize(
lendingMarketId: string,
lendingMarketType: string,
client: SuiClient,
logPackageId?: boolean
): Promise<SuilendClient>
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:
const client = await SuilendClient.initialize(
LENDING_MARKET_ID,
LENDING_MARKET_TYPE,
suiClient,
true
);
getFeeReceivers
static async getFeeReceivers(
client: SuiClient,
lendingMarketId: string
): Promise<FeeReceivers<string>>
Retrieves fee receiver configuration for a lending market.
Parameters:
client
(SuiClient): Sui client instancelendingMarketId
(string): ID of the lending market
Returns: Promise<FeeReceivers>
createNewLendingMarket
static createNewLendingMarket(
registryId: string,
lendingMarketType: string,
transaction: Transaction
): TransactionResult
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
static async getObligationOwnerCaps(
ownerId: string,
lendingMarketTypeArgs: string[],
client: SuiClient
): Promise<ObligationOwnerCap<string>[]>
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
static async getObligation(
obligationId: string,
lendingMarketTypeArgs: string[],
client: SuiClient
): Promise<Obligation<string>>
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
static async getLendingMarketOwnerCapId(
ownerId: string,
lendingMarketTypeArgs: string[],
client: SuiClient
): Promise<string | null>
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
createObligation(transaction: Transaction): TransactionResult
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:
const tx = new Transaction();
const obligationOwnerCap = client.createObligation(tx);
depositLiquidityAndGetCTokens
async depositLiquidityAndGetCTokens(
ownerId: string,
coinType: string,
value: string,
transaction: Transaction
): Promise<TransactionResult>
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:
const tx = new Transaction();
const ctokens = await client.depositLiquidityAndGetCTokens(
userAddress,
"0x2::sui::SUI",
"1000000000", // 1 SUI
tx
);
depositIntoObligation
async depositIntoObligation(
ownerId: string,
coinType: string,
value: string,
transaction: Transaction,
obligationOwnerCapId: string | TransactionResult
): Promise<void>
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:
const tx = new Transaction();
await client.depositIntoObligation(
userAddress,
"0x2::sui::SUI",
"5000000000", // 5 SUI
tx,
obligationOwnerCapId
);
withdraw
async withdraw(
obligationOwnerCapId: string,
obligationId: string,
coinType: string,
value: string,
transaction: Transaction
): Promise<TransactionResult>
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
async withdrawAndSendToUser(
ownerId: string,
obligationOwnerCapId: string,
obligationId: string,
coinType: string,
value: string,
transaction: Transaction
): Promise<void>
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
async borrow(
obligationOwnerCapId: string,
obligationId: string,
coinType: string,
value: string,
transaction: Transaction
): Promise<TransactionResult>
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
async borrowAndSendToUser(
ownerId: string,
obligationOwnerCapId: string,
obligationId: string,
coinType: string,
value: string,
transaction: Transaction
): Promise<void>
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
async repayIntoObligation(
ownerId: string,
obligationId: string,
coinType: string,
value: string,
transaction: Transaction
): Promise<void>
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
async liquidate(
transaction: Transaction,
obligation: Obligation<string>,
repayCoinType: string,
withdrawCoinType: string,
repayCoinId: TransactionObjectInput
): Promise<TransactionResult>
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
async liquidateAndRedeem(
transaction: Transaction,
obligation: Obligation<string>,
repayCoinType: string,
withdrawCoinType: string,
repayCoinId: TransactionObjectInput
): Promise<void>
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
claimRewards(
ownerId: string,
obligationOwnerCapId: string,
rewards: ClaimRewardsReward[],
transaction: Transaction
): {
transaction: Transaction;
mergedCoinsMap: Record<string, TransactionObjectArgument>;
}
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
claimRewardsAndSendToUser(
ownerId: string,
obligationOwnerCapId: string,
rewards: ClaimRewardsReward[],
transaction: Transaction
): void
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
claimRewardsAndDeposit(
ownerId: string,
obligationOwnerCapId: string,
rewards: ClaimRewardsReward[],
transaction: Transaction
): void
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
async createReserve(
lendingMarketOwnerCapId: string,
transaction: Transaction,
pythPriceId: string,
coinType: string,
createReserveConfigArgs: CreateReserveConfigArgs
): Promise<void>
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
async addReward(
ownerId: string,
lendingMarketOwnerCapId: string,
reserveArrayIndex: bigint,
isDepositReward: boolean,
rewardCoinType: string,
rewardValue: string,
startTimeMs: bigint,
endTimeMs: bigint,
transaction: Transaction,
mergeCoins: boolean = true
): Promise<void>
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
cancelReward(
lendingMarketOwnerCapId: string,
reserveArrayIndex: bigint,
isDepositReward: boolean,
rewardIndex: bigint,
rewardCoinType: string,
transaction: Transaction
): void
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
closeReward(
lendingMarketOwnerCapId: string,
reserveArrayIndex: bigint,
isDepositReward: boolean,
rewardIndex: bigint,
rewardCoinType: string,
transaction: Transaction
): void
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
updateReserveConfig(
lendingMarketOwnerCapId: string,
transaction: Transaction,
coinType: string,
createReserveConfigArgs: CreateReserveConfigArgs
): void
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
async refreshAll(
transaction: Transaction,
obligation: Obligation<string>,
extraReserveArrayIndex?: bigint
): Promise<void>
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
findReserveArrayIndex(coinType: string): bigint
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
async getObligation(obligationId: string): Promise<Obligation<string>>
Retrieves obligation data using the client's lending market configuration.
Parameters:
obligationId
(string): ID of the obligation
Returns: Promise<Obligation>
Types and Interfaces
ClaimRewardsReward
interface ClaimRewardsReward {
reserveArrayIndex: bigint;
rewardIndex: bigint;
rewardCoinType: string;
side: Side;
}
CreateReserveConfigArgs
interface CreateReserveConfigArgs {
openLtvPct: number;
closeLtvPct: number;
maxCloseLtvPct: number;
borrowWeightBps: number;
depositLimitUsd: number;
borrowLimitUsd: number;
liquidationBonusBps: number;
maxLiquidationBonusBps: number;
badDebtLiquidationBonusBps: number;
minBorrowLimitUsd: number;
isolatedAsset: boolean;
openAttributedBorrowLimitUsd: number;
closeAttributedBorrowLimitUsd: number;
}
Side
enum Side {
DEPOSIT = "deposit",
BORROW = "borrow",
}
UiLendingMarket
interface UiLendingMarket {
name: string;
slug: string;
id: string;
type: string;
ownerCapId: string;
isHidden?: boolean;
}
Constants
Lending Markets
export const LENDING_MARKETS: UiLendingMarket[];
export const LENDING_MARKET_ID: string;
export const LENDING_MARKET_TYPE: string;
export const LENDING_MARKET_REGISTRY_ID: string;
export const ADMIN_ADDRESS: string;
Package Information
export const PACKAGE_ID: string;
export const PUBLISHED_AT: string;
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
try {
await client.depositIntoObligation(/* parameters */);
} catch (error) {
if (error.message.includes("insufficient funds")) {
// Handle insufficient funds
} else if (error.message.includes("obligation not found")) {
// Handle missing obligation
} else {
// Handle other errors
console.error("Unexpected error:", error);
}
}
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.