Suilend SDK Types Reference
Table of Contents
Core Enums
Side
enum Side {
DEPOSIT = "deposit",
BORROW = "borrow",
}enum Side {
DEPOSIT = "deposit",
BORROW = "borrow",
}import { Side } from "@suilend/sdk";
const reward = {
reserveArrayIndex: 0n,
rewardIndex: 0n,
rewardCoinType: "0x2::sui::SUI",
side: Side.DEPOSIT, // or Side.BORROW
};enum Action {
DEPOSIT = "deposit",
WITHDRAW = "withdraw",
BORROW = "borrow",
REPAY = "repay",
}interface UiLendingMarket {
name: string; // Human-readable name
slug: string; // URL-friendly identifier
id: string; // On-chain object ID
type: string; // Type signature for the market
ownerCapId: string; // Owner capability object ID
isHidden?: boolean; // Whether to hide in UI
}const mainMarket: UiLendingMarket = {
name: "Main market",
slug: "main",
id: "0x84030d26d85eaa7035084a057f2f11f701b7e2e4eda87551becbc7c97505ece1",
type: "0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf::suilend::MAIN_POOL",
ownerCapId: "0xf7a4defe0b6566b6a2674a02a0c61c9f99bd012eed21bc741a069eaa82d35927",
};interface ObligationWithUnclaimedRewards {
id: string;
unclaimedRewards: {
rewardReserveArrayIndex: bigint;
rewardIndex: bigint;
rewardCoinType: string;
side: Side;
depositReserveArrayIndex: bigint;
}[];
}interface CreateReserveConfigArgs {
// Loan-to-Value ratios (percentages)
openLtvPct: number; // LTV for opening positions
closeLtvPct: number; // LTV for closing positions
maxCloseLtvPct: number; // Maximum LTV before liquidation
// Weight and limits
borrowWeightBps: number; // Borrow weight in basis points
depositLimitUsd: number; // Maximum deposit limit in USD
borrowLimitUsd: number; // Maximum borrow limit in USD
minBorrowLimitUsd: number; // Minimum borrow limit in USD
// Liquidation parameters
liquidationBonusBps: number; // Liquidation bonus in basis points
maxLiquidationBonusBps: number; // Maximum liquidation bonus
badDebtLiquidationBonusBps: number; // Bad debt liquidation bonus
// Asset isolation
isolatedAsset: boolean; // Whether asset is isolated
// Attributed borrow limits
openAttributedBorrowLimitUsd: number; // Open attributed borrow limit
closeAttributedBorrowLimitUsd: number; // Close attributed borrow limit
}const reserveConfig: CreateReserveConfigArgs = {
openLtvPct: 70,
closeLtvPct: 75,
maxCloseLtvPct: 80,
borrowWeightBps: 11000,
depositLimitUsd: 10000000,
borrowLimitUsd: 5000000,
liquidationBonusBps: 500,
maxLiquidationBonusBps: 1000,
badDebtLiquidationBonusBps: 2000,
minBorrowLimitUsd: 100,
isolatedAsset: false,
openAttributedBorrowLimitUsd: 1000000,
closeAttributedBorrowLimitUsd: 500000,
};interface CreateRateLimiterConfigArgs {
windowDurationMs: bigint; // Time window in milliseconds
maxOutflowPct: number; // Maximum outflow percentage
}interface ApiReserveAssetDataEvent {
id: number;
lendingMarketId: string;
coinType: string;
reserveId: string;
// Amounts
availableAmount: string;
supplyAmount: string;
borrowedAmount: string;
// USD estimates
availableAmountUsdEstimate: string;
supplyAmountUsdEstimate: string;
borrowedAmountUsdEstimate: string;
// Interest rates
borrowApr: string;
supplyApr: string;
// Token data
ctokenSupply: string;
cumulativeBorrowRate: string;
// Price data
price: string;
smoothedPrice: string;
priceLastUpdateTimestampS: number;
// Event metadata
timestamp: number;
digest: string;
eventIndex: number;
sender: string;
}interface ApiDepositEvent {
id: number;
lendingMarketId: string;
coinType: string;
reserveId: string;
obligationId: string;
ctokenAmount: string;
timestamp: number;
digest: string;
eventIndex: number;
sender: string;
}interface ApiWithdrawEvent {
id: number;
lendingMarketId: string;
coinType: string;
reserveId: string;
obligationId: string;
ctokenAmount: string;
timestamp: number;
digest: string;
eventIndex: number;
sender: string;
}interface ApiBorrowEvent {
id: number;
lendingMarketId: string;
coinType: string;
reserveId: string;
obligationId: string;
liquidityAmount: string;
originationFeeAmount: string;
timestamp: number;
digest: string;
eventIndex: number;
sender: string;
}interface ApiRepayEvent {
id: number;
lendingMarketId: string;
coinType: string;
reserveId: string;
obligationId: string;
liquidityAmount: string;
timestamp: number;
digest: string;
eventIndex: number;
sender: string;
}interface ApiLiquidateEvent {
id: number;
lendingMarketId: string;
repayReserveId: string;
withdrawReserveId: string;
obligationId: string;
repayAmount: string;
withdrawAmount: string;
protocolFeeAmount: string;
liquidatorBonusAmount: string;
timestamp: number;
digest: string;
eventIndex: number;
sender: string;
}interface ApiInterestUpdateEvent {
id: number;
lendingMarketId: string;
coinType: string;
reserveId: string;
cumulativeBorrowRate: string;
availableAmount: string;
borrowedAmount: string;
unclaimedSpreadFees: string;
ctokenSupply: string;
borrowInterestPaid: string;
spreadFee: string;
supplyInterestEarned: string;
borrowInterestPaidUsdEstimate: string;
protocolFeeUsdEstimate: string;
supplyInterestEarnedUsdEstimate: string;
timestamp: number;
digest: string;
eventIndex: number;
sender: string;
}interface ApiObligationDataEvent {
id: number;
lendingMarketId: string;
obligationId: string;
// Value calculations
depositedValueUsd: string;
allowedBorrowValueUsd: string;
unhealthyBorrowValueUsd: string;
superUnhealthyBorrowValueUsd: string;
unweightedBorrowedValueUsd: string;
weightedBorrowedValueUsd: string;
weightedBorrowedValueUpperBoundUsd: string;
// Status flags
borrowingIsolatedAsset: boolean;
badDebtUsd: string;
closable: boolean;
// JSON data (stringified objects)
depositsJson: string; // Array of deposit data
borrowsJson: string; // Array of borrow data
// Event metadata
timestamp: number;
digest: string;
eventIndex: number;
sender: string;
}interface ClaimRewardsReward {
reserveArrayIndex: bigint; // Index of the reserve
rewardIndex: bigint; // Index of the reward program
rewardCoinType: string; // Type of reward token
side: Side; // DEPOSIT or BORROW side
}const rewards: ClaimRewardsReward[] = [
{
reserveArrayIndex: 0n, // SUI reserve
rewardIndex: 0n, // First reward program
rewardCoinType: "0x2::sui::SUI",
side: Side.DEPOSIT,
},
{
reserveArrayIndex: 1n, // USDC reserve
rewardIndex: 0n,
rewardCoinType: "0x2::sui::SUI",
side: Side.BORROW,
},
];interface ApiClaimRewardEvent {
id: number;
lendingMarketId: string;
reserveId: string;
obligationId: string;
isDepositReward: boolean;
poolRewardId: string;
coinType: string;
liquidityAmount: string;
timestamp: number;
digest: string;
eventIndex: number;
sender: string;
}interface ApiMintEvent {
id: number;
lendingMarketId: string;
coinType: string;
reserveId: string;
liquidityAmount: string;
ctokenAmount: string;
timestamp: number;
digest: string;
eventIndex: number;
sender: string;
}interface ApiRedeemEvent {
id: number;
lendingMarketId: string;
coinType: string;
reserveId: string;
ctokenAmount: string;
liquidityAmount: string;
timestamp: number;
digest: string;
eventIndex: number;
sender: string;
}interface LendingMarket<T> {
id: string;
reserves: Reserve<T>[];
// ... additional fields from on-chain struct
}interface Obligation<T> {
id: string;
lendingMarketId: string;
deposits: DepositInfo[];
borrows: BorrowInfo[];
// ... additional fields from on-chain struct
}interface ObligationOwnerCap<T> {
id: string;
obligationId: string;
// ... additional fields from on-chain struct
}interface Reserve<T> {
id: string;
coinType: string;
config: ReserveConfig;
// ... additional fields from on-chain struct
}interface FeeReceivers<T> {
receivers: string[];
weights: bigint[];
// ... additional fields from on-chain struct
}type DownsampledApiReserveAssetDataEvent = ApiReserveAssetDataEvent & {
sampletimestamp: number;
};// From @mysten/sui/transactions
type TransactionObjectInput =
| string
| { digest: string; objectId: string; version: string };
type TransactionObjectArgument =
| { kind: "Input"; index: number }
| { kind: "Result"; index: number };
type TransactionResult = { kind: "Result"; index: number };// From lib/constants.ts
const WAD: BigNumber; // 10^18 for decimal precision
const msPerYear: number; // Milliseconds per year// Available lending markets
const LENDING_MARKETS: UiLendingMarket[];
// Default market (main market)
const LENDING_MARKET_ID: string;
const LENDING_MARKET_TYPE: string;
// Registry and admin
const LENDING_MARKET_REGISTRY_ID: string;
const ADMIN_ADDRESS: string;
// Package information
const PACKAGE_ID: string;
const PUBLISHED_AT: string;// Check if a coin type is SUI
function isSui(coinType: string): boolean {
const NORMALIZED_SUI_COINTYPE = normalizeStructTag("0x2::sui::SUI");
return normalizeStructTag(coinType) === NORMALIZED_SUI_COINTYPE;
}
// Normalize coin type for comparison
function normalizeStructTag(coinType: string): string {
// Implementation from @mysten/sui
}// Converting between string and bigint
const amount = "1000000000"; // 1 SUI in MIST
const amountBigInt = BigInt(amount);
const backToString = amountBigInt.toString();
// Using with reserves
const reserveIndex = 0n; // Note the 'n' suffix for bigint literalsimport {
SuilendClient,
Side,
ClaimRewardsReward,
CreateReserveConfigArgs,
LENDING_MARKET_ID,
} from "@suilend/sdk";
import { SuiClient } from "@mysten/sui/client";
import { Transaction } from "@mysten/sui/transactions";
async function exampleWithTypes() {
const suiClient = new SuiClient({ url: "https://fullnode.mainnet.sui.io" });
const suilendClient = await SuilendClient.initialize(
LENDING_MARKET_ID,
suiClient
);
// Using ClaimRewardsReward type
const rewards: ClaimRewardsReward[] = [
{
reserveArrayIndex: 0n,
rewardIndex: 0n,
rewardCoinType: "0x2::sui::SUI",
side: Side.DEPOSIT,
},
];
// Using Transaction type
const transaction = new Transaction();
// Call with properly typed parameters
suilendClient.claimRewards(
userAddress, // string
obligationCapId, // string
rewards, // ClaimRewardsReward[]
transaction // Transaction
);
}