Types Reference

This document provides a comprehensive reference for all types, interfaces, and enums used in the Suilend SDK.

Table of Contents

Core Enums

Side

Represents the side of a lending operation for rewards and positions.


enum Side {

DEPOSIT = "deposit",

BORROW = "borrow",

}

Usage:


import { Side } from "@suilend/sdk";

  

const reward = {

reserveArrayIndex: 0n,

rewardIndex: 0n,

rewardCoinType: "0x2::sui::SUI",

side: Side.DEPOSIT, // or Side.BORROW

};

Action

Represents different types of lending actions.


enum Action {

DEPOSIT = "deposit",

WITHDRAW = "withdraw",

BORROW = "borrow",

REPAY = "repay",

}

Client Types

UiLendingMarket

Represents a lending market configuration for UI purposes.


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

}

Example:


const mainMarket: UiLendingMarket = {

name: "Main market",

slug: "main",

id: "0x84030d26d85eaa7035084a057f2f11f701b7e2e4eda87551becbc7c97505ece1",

type: "0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf::suilend::MAIN_POOL",

ownerCapId:

"0xf7a4defe0b6566b6a2674a02a0c61c9f99bd012eed21bc741a069eaa82d35927",

};

ObligationWithUnclaimedRewards

Represents an obligation with associated unclaimed rewards.


interface ObligationWithUnclaimedRewards {

id: string;

unclaimedRewards: {

rewardReserveArrayIndex: bigint;

rewardIndex: bigint;

rewardCoinType: string;

side: Side;

depositReserveArrayIndex: bigint;

}[];

}

Configuration Types

CreateReserveConfigArgs

Configuration parameters for creating a new reserve.


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

}

Example:


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,

};

CreateRateLimiterConfigArgs

Configuration for rate limiting functionality.


interface CreateRateLimiterConfigArgs {

windowDurationMs: bigint; // Time window in milliseconds

maxOutflowPct: number; // Maximum outflow percentage

}

Event Types

ApiReserveAssetDataEvent

Event data for reserve asset updates.


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;

}

ApiDepositEvent

Event data for deposit operations.


interface ApiDepositEvent {

id: number;

lendingMarketId: string;

coinType: string;

reserveId: string;

obligationId: string;

ctokenAmount: string;

timestamp: number;

digest: string;

eventIndex: number;

sender: string;

}

ApiWithdrawEvent

Event data for withdrawal operations.


interface ApiWithdrawEvent {

id: number;

lendingMarketId: string;

coinType: string;

reserveId: string;

obligationId: string;

ctokenAmount: string;

timestamp: number;

digest: string;

eventIndex: number;

sender: string;

}

ApiBorrowEvent

Event data for borrow operations.


interface ApiBorrowEvent {

id: number;

lendingMarketId: string;

coinType: string;

reserveId: string;

obligationId: string;

liquidityAmount: string;

originationFeeAmount: string;

timestamp: number;

digest: string;

eventIndex: number;

sender: string;

}

ApiRepayEvent

Event data for repay operations.


interface ApiRepayEvent {

id: number;

lendingMarketId: string;

coinType: string;

reserveId: string;

obligationId: string;

liquidityAmount: string;

timestamp: number;

digest: string;

eventIndex: number;

sender: string;

}

ApiLiquidateEvent

Event data for liquidation operations.


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;

}

ApiInterestUpdateEvent

Event data for interest rate updates.


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;

}

ApiObligationDataEvent

Event data for obligation state updates.


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;

}

Reward Types

ClaimRewardsReward

Specification for claiming a specific reward.


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

}

Example:


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,

},

];

ApiClaimRewardEvent

Event data for reward claims.


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;

}

ApiMintEvent

Event data for cToken minting (when depositing to reserves).


interface ApiMintEvent {

id: number;

lendingMarketId: string;

coinType: string;

reserveId: string;

liquidityAmount: string;

ctokenAmount: string;

timestamp: number;

digest: string;

eventIndex: number;

sender: string;

}

ApiRedeemEvent

Event data for cToken redemption (when withdrawing from reserves).


interface ApiRedeemEvent {

id: number;

lendingMarketId: string;

coinType: string;

reserveId: string;

ctokenAmount: string;

liquidityAmount: string;

timestamp: number;

digest: string;

eventIndex: number;

sender: string;

}

Generated Types

The SDK includes many generated types from on-chain smart contracts. These are located in the _generated directory.

Key Generated Interfaces

LendingMarket


interface LendingMarket<T> {

id: string;

reserves: Reserve<T>[];

// ... additional fields from on-chain struct

}

Obligation


interface Obligation<T> {

id: string;

lendingMarketId: string;

deposits: DepositInfo[];

borrows: BorrowInfo[];

// ... additional fields from on-chain struct

}

ObligationOwnerCap


interface ObligationOwnerCap<T> {

id: string;

obligationId: string;

// ... additional fields from on-chain struct

}

Reserve


interface Reserve<T> {

id: string;

coinType: string;

config: ReserveConfig;

// ... additional fields from on-chain struct

}

FeeReceivers


interface FeeReceivers<T> {

receivers: string[];

weights: bigint[];

// ... additional fields from on-chain struct

}

Utility Types

DownsampledApiReserveAssetDataEvent

Extended reserve asset data with sampling information.


type DownsampledApiReserveAssetDataEvent = ApiReserveAssetDataEvent & {

sampletimestamp: number;

};

Transaction Types

These are re-exported from @mysten/sui:


// 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 };

Constants

Precision Constants


// From lib/constants.ts

const WAD: BigNumber; // 10^18 for decimal precision

const msPerYear: number; // Milliseconds per year

Market Constants


// 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;

Type Guards and Utilities

Common Type Checks


// 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

}

Working with BigInt

Many amounts in the SDK are represented as bigint or string representations of large numbers:


// 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 literals

Example Type Usage


import {

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

);

}