@cetusprotocol/vaults-sdk

中文文档
1.7.7发布于 2026/09/20Apache-2.0TypeScriptES Module零依赖近 30 天下载 2492

SDK for cetus vaults

原始使用文档
文档目录15 节
  1. Getting Started
  2. How to Use the Vaults SDK ?
  3. Installation
  4. Setup
  5. Initializing the SDK
  6. Usage
  7. 1. Get Vaults by Owner Address
  8. 2. Get Vault by ID
  9. 3. Get Vault Asset
  10. 4. Deposit Operations
  11. 5. Withdraw Operations
  12. 6. Vest Operations
  13. 7. Contract Error Codes
  14. More About Cetus
  15. License

@cetusprotocol/vaults-sdk

The SDK provides a Vaults module for automated liquidity management. This module enables users to automatically manage their liquidity positions, including timely reinvestment of fees and rewards, as well as rebalancing when necessary. When users deposit tokens into Vaults, these tokens are used to provide liquidity within the positions held by Vaults, and LP tokens are minted to represent their share of the liquidity.

Getting Started

How to Use the Vaults SDK ?

Installation

To start using the Vaults SDK, you first need to install it in your TypeScript project:

npm link: https://www.npmjs.com/package/@cetusprotocol/vaults-sdk

npm install @cetusprotocol/vaults-sdk

Setup

Import the SDK into the TypeScript file where you intend to use it:

import { CetusVaultsSDK } from '@cetusprotocol/vaults-sdk'

Initializing the SDK

Initialize the SDK with the required configuration parameters. This typically includes setting up the network and API keys, if needed.

If you would like to use the mainnet network and the official Sui rpc url, you can do so as follows:

const sdk = CetusVaultsSDK.createSDK()

If you wish to set your own full node URL or network (You have the option to select either 'mainnet' or 'testnet' for the network), you can do so as follows:

const env = 'mainnet'
const full_rpc_url = 'YOUR_FULL_NODE_URL'
const wallet = 'YOUR_WALLET_ADDRESS'

const sdk = CetusVaultsSDK.createSDK({ env })

If you wish to set your own full node URL or SuiGrpcClient, you can do so as follows:

const sdk = CetusVaultsSDK.createSDK({ env, sui_client })
// or
const sdk = CetusVaultsSDK.createSDK({ env, full_rpc_url })

Usage

After linking your wallet, if you need use your wallet address to do something, you should set it by sdk.setSenderAddress.

const wallet = 'YOUR_WALLET_ADDRESS'

sdk.setSenderAddress(wallet)

if you need to change your rpc url, you can do so as follows:

const new_rpc_url = 'YOUR_NEW_FULL_NODE_URL'

sdk.updateFullRpcUrl(new_rpc_url)

1. Get Vaults by Owner Address

This method retrieves all vaults associated with a specific owner address.

const owner = '0x...'
const vaults_result = await sdk.Vaults.getOwnerVaultsBalance(owner)

// result
[
  {
    vault_id: '0x5732b81e659bd2db47a5b55755743dde15be99490a39717abc80d62ec812bcb6',
    clmm_pool_id: '0x6c545e78638c8c1db7a48b282bb8ca79da107993fcb185f75cedc1f5adb2f535',
    owner: '0x...',
    lp_token_type: '0xb490d6fa9ead588a9d72da07a02914da42f6b5b1339b8118a90011a42b67a44f::lp_token::LP_TOKEN',
    lp_token_balance: '739242144247',
    liquidity: '799210772591',
    tick_lower_index: 100,
    tick_upper_index: 394,
    amount_a: '5514867803',
    amount_b: '6197505499',
    coin_type_a: '0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT',
    coin_type_b: '0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI'
  },
  // ...more vaults
]

2. Get Vault by ID

This method retrieves detailed information about a specific vault.

const vault_id = 'YOUR_VAULT_ID'

const vault = await sdk.Vaults.getVault(vault_id)

3. Get Vault Asset

This method retrieves the LP token balance for a specific vault.

const ft_asset = await sdk.getOwnerCoinBalances('0x0..', vault?.lp_token_type)

4. Deposit Operations

Deposit liquidity into vaults. Users can deposit coinA and coinB, and the associated LP Token will be minted to the user.

const input_amount = toDecimalsAmount(3, 9).toString()
const InputType = {
  Both: 'both',
  OneSide: 'oneSide',
}

// Calculate deposit amount
const result = await sdk.Vaults.calculateDepositAmount({
  vault_id,
  fix_amount_a: false,
  input_amount,
  slippage: 0.01,
  side: InputType.OneSide,
})
// Build and send transaction
const tx = new Transaction()
const params: DepositParams = {
  vault_id,
  slippage: 0.01,
  deposit_result: result,
  coin_object_b: VaultsUtils.buildCoinWithBalance(
    BigInt(input_amount),
    '0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI',
    tx
  ),
  return_lp_token: true,
}
const lp_coin = await sdk.Vaults.deposit(params, tx)
if (lp_coin) {
  tx.transferObjects([lp_coin], '0x0..')
}

5. Withdraw Operations

Withdraw liquidity from vaults. Users can withdraw their LP tokens and receive the underlying assets.

/**
 * @param {Object} params - The parameters for the calculateWithdrawAmount function.
 * @param {string} params.vault_id - The ID of the vault.
 * @param {boolean} params.fix_amount_a - Whether to fix the amount of token A. If true, the input_amount represents token A amount; if false, it represents token B amount.
 * @param {string} params.input_amount - The input amount. If is_ft_input is true, this is the LP token amount; if false, this is the token amount (either A or B based on fix_amount_a).
 * @param {number} params.slippage - The slippage percentage (eg: 0.01 = 1%)
 * @param {boolean} params.is_ft_input - Whether the input is LP token. If true, input_amount is LP token amount; if false, input_amount is token amount.
 * @param {InputType} params.side - The withdrawal type. Both for withdrawing both tokens, OneSide for withdrawing a single token.
 * @param {string} params.max_ft_amount - The amount of LP tokens held by the user. In OneSide mode, this value is used to balance the withdrawal amount.
 */
const result = await sdk.Vaults.calculateWithdrawAmount({
  vault_id,
  fix_amount_a: true,
  input_amount: '1000000000',
  slippage: 0.01,
  is_ft_input: false,
  side: InputType.Both,
  max_ft_amount: '',
})

/**
 * @param {Object} params - The parameters for the withdraw function.
 * @param {string} params.vault_id - The ID of the vault.
 * @param {number} params.slippage - The slippage percentage (0-1).
 * @param {string} params.ft_amount - The amount of LP tokens to burn.
 * @param {string} params.return_coin - Optional. If set to true, returns the coin object. The user needs to handle it.
 */
const tx = new Transaction()
const { return_coin_a, return_coin_b } = await sdk.Vaults.withdraw(
  {
    vault_id,
    slippage: 0.01,
    ft_amount: result.burn_ft_amount,
    return_coin: true,
  },
  tx
)
if (return_coin_a) {
  tx.transferObjects([return_coin_a], sdk.senderAddress)
}
if (return_coin_b) {
  tx.transferObjects([return_coin_b], sdk.senderAddress)
}

const send_key_pair = 'THE_KEY_PAIR_GENERATED_BY_YOUR_PRIVATE_KEY'

const tx_result = await sdk.fullClient.sendTransaction(send_key_pair, payload)

6. Vest Operations

6.1 Get Vault's Vest Information List

Get vest information for multiple vaults.

const vestInfoList = await sdk.Vest.getVaultsVestInfoList([vaultId])

6.2 Get Single Vault's Vest Information

Get vest information for a specific vault.

async getVaultsVestInfo(vault_id: string, force_refresh = true): Promise<VaultsVestInfo>

6.3 Get User's Vault Vest NFT List

Get all Vault Vest NFTs owned by the specified address. Each NFT contains the following information:

  • id: NFT ID
  • index: Index
  • vault_id: Vault ID
  • lp_amount: LP token amount
  • redeemed_amount: Redeemed amount
  • impaired_a: Token A impairment
  • impaired_b: Token B impairment
  • period_infos: Period information
  • url: NFT URL
  • name: NFT name
  • vester_id: Vester ID
const vestNFTList = await sdk.Vest.getOwnerVaultVestNFT(senderAddress)

6.4 Build Redeem Transaction

Build the redeem transaction payload. Parameter description:

  • options: Array of redeem options, each option contains:
    • vault_id: Vault ID
    • vesting_nft_id: Vesting NFT ID
    • period: Period
    • coin_type_a: Token A type
    • coin_type_b: Token B type
  • tx: Optional transaction object
 const vestInfo = await sdk.Vest.getVaultsVestInfo(vaultId)
const tx = await sdk.Vest.buildRedeemPayload([
  {
    vault_id: vaultId,
    vesting_nft_id: '0x...',
    period: 1,
    coin_type_a: vestInfo.coin_type_a,
    coin_type_b: vestInfo.coin_type_b,
  }
])

// Execute transaction
const transferTxn = await sdk.FullClient.executeTx(send_key_pair, tx, false)

7. Contract Error Codes

the Cetus smart contract may return the following error codes:

ModuleError CodeDescriptionContract Methods
vaults::vaults1Amount out below min limitremove
vaults::vaults2Position size errordeposit,remove,reinvest,migrate_liquidity,rebalance,collect_fee,harvest,collect_rewarder,get_position_amounts
vaults::vaults3Package version deprecatedchecked_package_version
vaults::vaults4Token amount overflowdeposit
vaults::vaults5Token amount is zeroremove,deposit
vaults::vaults6Pool is pausedtake_harvest_asset_by_amount
vaults::vaults7Invalid coin typemigrate_liquidity
vaults::vaults8Rebalance add liquidity errorremove
vaults::vaults9Token amount not enoughremove
vaults::vaults10Invalid protocol fee rateupdate_protocol_fee_rate
vaults::vaults11No protocol fee claim permissioncheck_protocol_fee_claim_role
vaults::vaults12No operation manager permissioncheck_reinvest_role,check_operation_role
vaults::vaults13No pool manager permissioncheck_pool_manager_role
vaults::vaults14Treasury cap illegalcreate_vault
vaults::vaults15Wrong package versionupdate_package_version
vaults::vaults16Quota reacheddeposit
vaults::vaults17Vault not runningcollect_rewarder,harvest,collect_fee,migrate_liquidity,reinvest ,remove,deposit
vaults::vaults18Vault not rebalancingrebalance
vaults::vaults19Quota type name errorcalculate_updated_quota
vaults::vaults20Same coin typenew_pool_key
vaults::vaults21Invalid coin type sequenceadd_oracle_pool
vaults::vaults22Coin pair existedreinvest_harvest_assets,flash_loan ,update_slippage,remove_oracle_pool
vaults::vaults23Coin pair non-existedflash_loan
vaults::vaults24Incorrect flash loan amountrepay_flash_loan
vaults::vaults25Incorrect repayflash_loan
vaults::vaults26Oracle pool errorrebalance
vaults::vaults27Flashloan count non-zerorebalance
vaults::vaults28Finish rebalance threshold not matchrebalance
vaults::vaults29Harvest asset not enoughtake_harvest_asset_by_amount
vaults::vaults30Invalid vault operationreinvest_harvest_assets

More About Cetus

Use the following links to learn more about Cetus:

Learn more about working with Cetus in the Cetus Documentation.

Join the Cetus community on Cetus Discord.

License

MIT

版本与发布记录

@cetusprotocol/vaults-sdk 共发布 150 个版本,首次发布于 2024/09/26;过去 12 个月发布了 39 个版本。

版本发布日期距今
1.7.7latest2026/09/201 个月前
0.0.0-experimental-20260920105550experimental2026/09/201 个月前
0.0.0-experimental-202609201012582026/09/201 个月前
1.7.62026/08/182 个月前
0.0.0-experimental-202608181437372026/08/182 个月前
1.7.52026/07/273 个月前

关于 @cetusprotocol/vaults-sdk 的常见问题

@cetusprotocol/vaults-sdk 是什么?

SDK for cetus vaults

如何安装 @cetusprotocol/vaults-sdk?

在项目目录运行 npm install @cetusprotocol/vaults-sdk,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@mysten/sui(>=2.28.0)、@cetusprotocol/farms-sdk(*)、@cetusprotocol/common-sdk(*)、@cetusprotocol/sui-clmm-sdk(*)、@cetusprotocol/aggregator-sdk(*)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@cetusprotocol/vaults-sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@cetusprotocol/vaults-sdk 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@cetusprotocol/vaults-sdk 可以商用吗?

@cetusprotocol/vaults-sdk 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@cetusprotocol/vaults-sdk 的下载量有多少?

根据 npm 官方下载统计,@cetusprotocol/vaults-sdk 在 2026/10/10 – 2026/11/08 这 30 天内被下载 2,492 次,日均约 83 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cetusprotocol/vaults-sdk 还在维护吗?

最新版本 1.7.7 发布于 2026/09/20(1 个月前);至今共发布 150 个版本,其中过去 12 个月发布了 39 个;首次发布于 2024/09/26。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。