
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
@cetusprotocol/farms-sdk
Advanced tools
The SDK provides a Farms module for managing farming positions, liquidity, and rewards in the Cetus ecosystem. This module enables users to perform various farming operations with flexibility in how they want to manage their positions.
To start using the Farms SDK, you first need to install it in your TypeScript project:
npm link: https://www.npmjs.com/package/@cetusprotocol/farms-sdk
npm install @cetusprotocol/farms-sdk
Import the SDK into the TypeScript file where you intend to use it:
import { CetusFarmsSDK } from '@cetusprotocol/farms-sdk'
Initialize the SDK with the required configuration parameters. This typically includes setting up the network environment.
If you would like to use the mainnet network and the official Sui rpc url, you can do so as follows:
const sdk = CetusFarmsSDK.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 = CetusFarmsSDK.createSDK({ env })
If you wish to set your own full node URL or SuiClient, you can do so as follows:
const sdk = CetusFarmsSDK.createSDK({ env, sui_client })
// or
const sdk = CetusFarmsSDK.createSDK({ env, full_rpc_url })
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)
pool_id: The ID of the farms poolposition_nft_id: The ID of the position NFTclmm_position_id: The ID of the CLMM positioncoin_type_a & coin_type_b: Coin type identifiers for the trading pairamount_a & amount_b: Amounts of coins to deposit/withdrawconst pool_data = await sdk.Farms.getFarmsPoolList()
const pool_id = 'YOUR_POOL_ID'
const pool_data = await sdk.Farms.getFarmsPool(pool_id)
const nft_list = await sdk.Farms.getOwnedFarmsPositionNFTList(wallet)
const position_nft_id = 'YOUR_POSITION_NFT_ID'
const nft_data = await sdk.Farms.getFarmsPositionNFT(position_nft_id)
const clmm_position_id = 'YOUR_CLMM_POSITION_ID'
const payload = sdk.Farms.depositPayload({
pool_id,
clmm_position_id,
})
const payload = await sdk.Farms.withdrawPayload({
pool_id,
position_nft_id,
})
const payload = await sdk.Farms.harvestPayload({
pool_id,
position_nft_id,
})
const clmm_pool_id = 'YOUR_CLMM_POOL_ID'
const coin_type_a = '0xac2afb455cbcdc2ff1a2e9bbb8aa4ccb4506a544b08c740886892a5cdf92f472::hasui::HASUI'
const coin_type_b = '0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI'
const farms_list = [
{
pool_id,
position_nft_id,
clmm_pool_id,
collect_fee: true,
collect_farms_rewarder: false,
clmm_rewarder_types: ['CLMM_REWARDER_TYPE_1'],
coin_type_a,
coin_type_b,
},
]
const clmm_list = [
{
pool_id,
pos_id: position_nft_id,
collect_fee: true,
rewarder_coin_types: ['CLMM_REWARDER_TYPE_1'],
coin_type_a,
coin_type_b,
},
]
const payload = await sdk.Farms.batchHarvestAndClmmFeePayload(farms_list, clmm_list)
const amount_a = 'AMOUNT_A'
const amount_b = 'AMOUNT_B'
const payload = await sdk.Farms.addLiquidityFixCoinPayload({
pool_id,
coin_type_a,
coin_type_b,
position_nft_id,
clmm_pool_id,
amount_a,
amount_b,
fix_amount_a: true,
collect_fee: true,
collect_rewarder: true,
clmm_rewarder_types: ['CLMM_REWARDER_TYPE_1'],
})
const min_amount_a = 'MIN_AMOUNT_A'
const min_amount_b = 'MIN_AMOUNT_B'
const liquidity = 'LIQUIDITY'
const payload = await sdk.Farms.removeLiquidityPayload({
pool_id,
coin_type_a,
coin_type_b,
position_nft_id,
clmm_pool_id,
min_amount_a,
min_amount_b,
collect_rewarder: true,
clmm_rewarder_types: [],
delta_liquidity: liquidity,
unstake: true,
close_position: false,
})
const payload = await sdk.Farms.claimFeeAndClmmReward({
pool_id,
position_nft_id,
})
the Cetus smart contract may return the following error codes:
| Module | Error Code | Description | Contract Methods |
|---|---|---|---|
| stable_farming::pool | 1 | Invalid CLMM Pool ID | collect_clmm_reward, collect_fee |
| stable_farming::pool | 2 | Pool Position Not Match | remove_liquidity, deposit,withdraw,harvest ,add_liquidity,add_liquidity_fix_coin |
| stable_farming::pool | 3 | Pool CLMM Pool Not Match | remove_liquidity, add_liquidity ,add_liquidity_fix_coin |
| stable_farming::pool | 4 | Rewarder Not Harvested | withdraw, |
| stable_farming::pool | 5 | Effective Range Error | check_effective_range |
| stable_farming::pool | 6 | Rewarder Not Exists | harvest |
| stable_farming::pool | 7 | Rewarder Already Exists | add_rewarder |
| stable_farming::pool | 8 | Pool Has No Rewarder | deposit |
| stable_farming::pool | 9 | Start Error | update_effective_tick_range |
| stable_farming::pool | 10 | Invalid Tick Range | calculate_position_share |
| stable_farming::pool | 11 | Invalid Sqrt Price | calculate_position_share |
| stable_farming::pool | 12 | Amount In Above Max Limit | add_liquidity_fix_coin_to_clmm,add_liquidity_to_clmm |
| stable_farming::pool | 15 | Amount Out Below Min Limit | remove_liquidity_from_clmm |
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.
MIT
FAQs
SDK for cetus farms
We found that @cetusprotocol/farms-sdk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.