Skip to content
Docs
Open app
Skip to Content

Liquid staking Move API

Move types, public functions and events in the liquid staking package.

Volo Staking API Reference

Source Code: https://github.com/Sui-Volo/volo-smart-contracts/tree/main/liquid_staking

V2 mainnet package: 0x68d22cf8bdbcd11ecba1e094922873e4080d4d11133e2443fddda0bfd11dae20

The vSUI coin type ends in ::cert::CERT. Check the deployment table for the original package ID and deployed version before integrating. For live pool data and tested stake and unstake PTBs, see Liquid Staking.


Table of Contents

  1. Data Structures
  2. User Functions
  3. View Functions
  4. Admin Functions
  5. Operator Functions
  6. Events
  7. Constants & Error Codes

1. Data Structures

StakePool

public struct StakePool has key, store {
    id: UID,
    fee_config: FeeConfig,
    fees: Balance<SUI>,
    boosted_balance: Balance<SUI>,
    boosted_reward_amount: u64,
    accrued_reward_fees: u64,
    validator_pool: ValidatorPool,
    manage: Manage,
    extra_fields: Bag
}
FieldTypeDescription
fee_configFeeConfigFee configuration
feesBalance<SUI>Accumulated protocol fees (stake + unstake fees)
boosted_balanceBalance<SUI>Deposited boosted reward balance
boosted_reward_amountu64Amount to distribute per epoch
accrued_reward_feesu64Accumulated reward fees (not yet collected)
validator_poolValidatorPoolValidator management
manageManageVersion and pause state

ValidatorPool

public struct ValidatorPool has store {
    sui_pool: Balance<SUI>,
    validator_infos: vector<ValidatorInfo>,
    total_sui_supply: u64,
    last_refresh_epoch: u64,
    total_weight: u64,
    manage: Manage,
    extra_fields: Bag
}
FieldTypeDescription
sui_poolBalance<SUI>Buffer for stake/unstake operations
validator_infosvector<ValidatorInfo>All validator information
total_sui_supplyu64Total SUI managed (sui_pool + all stakes)
last_refresh_epochu64Last epoch when pool was refreshed
total_weightu64Sum of all validator weights

ValidatorInfo

public struct ValidatorInfo has store {
    staking_pool_id: ID,
    validator_address: address,
    active_stake: Option<FungibleStakedSui>,
    inactive_stake: Option<StakedSui>,
    exchange_rate: PoolTokenExchangeRate,
    total_sui_amount: u64,
    assigned_weight: u64,
    last_refresh_epoch: u64,
    extra_fields: Bag
}
FieldTypeDescription
staking_pool_idIDValidator's staking pool ID
validator_addressaddressValidator address
active_stakeOption<FungibleStakedSui>Active stake (earning rewards)
inactive_stakeOption<StakedSui>Inactive stake (first epoch)
exchange_ratePoolTokenExchangeRateCurrent exchange rate
total_sui_amountu64Total SUI staked to this validator
assigned_weightu64Weight for allocation

FeeConfig

public struct FeeConfig has store {
    stake_fee_bps: u64,
    unstake_fee_bps: u64,
    reward_fee_bps: u64,
    unstake_fee_redistribution_bps: u64,
    extra_fields: Bag
}
FieldTypeMax ValueDescription
stake_fee_bpsu64500 (5%)Fee on staking
unstake_fee_bpsu64500 (5%)Fee on unstaking
reward_fee_bpsu6410000 (100%)Performance fee on rewards
unstake_fee_redistribution_bpsu6410000 (100%)Portion of unstake fee returned to pool

Metadata<CERT>

public struct Metadata<phantom T> has key, store {
    id: UID,
    version: u64,
    total_supply: Supply<T>,
}

Shared object storing the vSUI minting authority.


Capability Structs

public struct AdminCap has key, store { id: UID }
public struct OperatorCap has key, store { id: UID }

2. User Functions

stake_entry

Stake SUI and receive vSUI.

public entry fun stake_entry(
    self: &mut StakePool,
    metadata: &mut Metadata<CERT>,
    system_state: &mut SuiSystemState,
    sui: Coin<SUI>,
    ctx: &mut TxContext
)

Parameters:

NameTypeDescription
self&mut StakePoolThe stake pool object
metadata&mut Metadata<CERT>vSUI metadata (shared object)
system_state&mut SuiSystemStateSui system state (0x5)
suiCoin<SUI>SUI coin to stake

Requirements:

  • Pool must not be paused
  • SUI amount >= 0.1 SUI (100,000,000 MIST)

Emits: StakeEventExt

TypeScript Example:

import { Transaction } from '@mysten/sui/transactions';

const PACKAGE_ID = '0x68d22cf8bdbcd11ecba1e094922873e4080d4d11133e2443fddda0bfd11dae20';
const STAKE_POOL = '<STAKE_POOL_OBJECT_ID>';
const CERT_METADATA = '<CERT_METADATA_OBJECT_ID>';
const SUI_SYSTEM_STATE = '0x5';

async function stake(suiAmount: bigint) {
    const tx = new Transaction();
    const [coin] = tx.splitCoins(tx.gas, [suiAmount]);

    tx.moveCall({
        target: `${PACKAGE_ID}::stake_pool::stake_entry`,
        arguments: [
            tx.object(STAKE_POOL),
            tx.object(CERT_METADATA),
            tx.object(SUI_SYSTEM_STATE),
            coin,
        ],
    });

    return tx;
}

stake

Non-entry version that returns the minted vSUI.

public fun stake(
    self: &mut StakePool,
    metadata: &mut Metadata<CERT>,
    system_state: &mut SuiSystemState,
    sui: Coin<SUI>,
    ctx: &mut TxContext
): Coin<CERT>

Returns: Coin<CERT> - The minted vSUI coin


unstake_entry

Redeem vSUI for SUI.

public entry fun unstake_entry(
    self: &mut StakePool,
    metadata: &mut Metadata<CERT>,
    system_state: &mut SuiSystemState,
    cert: Coin<CERT>,
    ctx: &mut TxContext
)

Parameters:

NameTypeDescription
certCoin<CERT>vSUI coin to redeem

Requirements:

  • Pool must not be paused
  • vSUI amount >= 0.1 SUI equivalent

Emits: UnstakeEventExt

TypeScript Example:

async function unstake(vsuiObjectId: string) {
    const tx = new Transaction();

    tx.moveCall({
        target: `${PACKAGE_ID}::stake_pool::unstake_entry`,
        arguments: [
            tx.object(STAKE_POOL),
            tx.object(CERT_METADATA),
            tx.object(SUI_SYSTEM_STATE),
            tx.object(vsuiObjectId),
        ],
    });

    return tx;
}

unstake

Non-entry version that returns the redeemed SUI.

public fun unstake(
    self: &mut StakePool,
    metadata: &mut Metadata<CERT>,
    system_state: &mut SuiSystemState,
    lst: Coin<CERT>,
    ctx: &mut TxContext
): Coin<SUI>

Returns: Coin<SUI> - The redeemed SUI coin


delegate_stake_entry

Stake SUI with a preferred validator.

public entry fun delegate_stake_entry(
    self: &mut StakePool,
    metadata: &mut Metadata<CERT>,
    system_state: &mut SuiSystemState,
    sui: Coin<SUI>,
    v_address: address,
    ctx: &mut TxContext
)

Parameters:

NameTypeDescription
v_addressaddressPreferred validator address

Emits: DelegateStakeEvent

Note: This function behaves identically to stake_entry but additionally emits a DelegateStakeEvent with the validator address. The backend uses this event to adjust validator weights.


rebalance

Rebalance stakes across validators according to weights. This is a permissionless function.

public fun rebalance(
    self: &mut StakePool,
    metadata: &mut Metadata<CERT>,
    system_state: &mut SuiSystemState,
    ctx: &mut TxContext
)

Emits: RebalanceEvent

TypeScript Example:

async function rebalance() {
    const tx = new Transaction();

    tx.moveCall({
        target: `${PACKAGE_ID}::stake_pool::rebalance`,
        arguments: [
            tx.object(STAKE_POOL),
            tx.object(CERT_METADATA),
            tx.object(SUI_SYSTEM_STATE),
        ],
    });

    return tx;
}

refresh

Update pool state if epoch has changed. Called automatically by stake/unstake.

public fun refresh(
    self: &mut StakePool,
    metadata: &Metadata<CERT>,
    system_state: &mut SuiSystemState,
    ctx: &mut TxContext
): bool

Returns: bool - true if epoch rolled over and state was updated

Emits: EpochChangedEvent (if epoch changed)


3. View Functions

get_ratio

Returns how many vSUI you get per 1 SUI (in 1e9 precision).

public fun get_ratio(self: &StakePool, metadata: &Metadata<CERT>): u64

Returns: Ratio in 1e9 precision

Example: If returns 950_000_000, then 1 SUI = 0.95 vSUI


get_ratio_reverse

Returns how many SUI you get per 1 vSUI (in 1e9 precision).

public fun get_ratio_reverse(self: &StakePool, metadata: &Metadata<CERT>): u64

Returns: Ratio in 1e9 precision

Example: If returns 1_052_631_579, then 1 vSUI ≈ 1.053 SUI


publish_ratio

Emit ratio in V1 format (1e18 precision) for compatibility.

public fun publish_ratio(self: &StakePool, metadata: &Metadata<CERT>)

get_amount_out

Calculate output amount after fees.

public fun get_amount_out(
    self: &StakePool,
    metadata: &Metadata<CERT>,
    amount_in: u64,
    sui2lst: bool
): u64

Parameters:

NameTypeDescription
amount_inu64Input amount in MIST
sui2lstbooltrue for SUI→vSUI, false for vSUI→SUI

Returns: Output amount after fees


sui_amount_to_lst_amount

Convert SUI amount to vSUI amount (no fees).

public fun sui_amount_to_lst_amount(
    self: &StakePool,
    metadata: &Metadata<CERT>,
    sui_amount: u64
): u64

lst_amount_to_sui_amount

Convert vSUI amount to SUI amount (no fees).

public fun lst_amount_to_sui_amount(
    self: &StakePool,
    metadata: &Metadata<CERT>,
    lst_amount: u64
): u64

total_sui_supply

Returns total SUI managed by the pool.

public fun total_sui_supply(self: &StakePool): u64

total_lst_supply

Returns total vSUI supply.

public fun total_lst_supply(metadata: &Metadata<CERT>): u64

validator_pool

Get reference to validator pool.

public fun validator_pool(self: &StakePool): &ValidatorPool

fee_config

Get reference to fee configuration.

public fun fee_config(self: &StakePool): &FeeConfig

total_fees

Returns total accumulated fees (stake fees + unstake fees + reward fees).

public fun total_fees(self: &StakePool): u64

accrued_reward_fees

Returns accumulated reward fees not yet collected.

public fun accrued_reward_fees(self: &StakePool): u64

boosted_balance

Returns remaining boosted reward balance.

public fun boosted_balance(self: &StakePool): u64

ValidatorPool View Functions

public fun sui_pool(self: &ValidatorPool): &Balance<SUI>
public fun validators(self: &ValidatorPool): &vector<ValidatorInfo>
public fun total_weight(self: &ValidatorPool): u64
public fun validator_weights(self: &ValidatorPool): VecMap<address, u64>
public fun validator_stake_amounts(self: &ValidatorPool): (VecMap<address, u64>, VecMap<address, u64>)
public fun total_sui_supply(self: &ValidatorPool): u64
public fun last_refresh_epoch(self: &ValidatorPool): u64
public fun find_validator_index_by_address(self: &ValidatorPool, addr: address): Option<u64>

FeeConfig View Functions

public fun stake_fee_bps(fees: &FeeConfig): u64
public fun unstake_fee_bps(fees: &FeeConfig): u64
public fun reward_fee_bps(fees: &FeeConfig): u64
public fun unstake_fee_redistribution_bps(fees: &FeeConfig): u64

4. Admin Functions

All admin functions require AdminCap.

set_paused

Pause or unpause the pool.

public fun set_paused(self: &mut StakePool, _: &AdminCap, paused: bool)

Emits: SetPausedEvent


migrate_version

Migrate pool to current version.

public fun migrate_version(self: &mut StakePool, _: &AdminCap)

update_stake_fee

Update stake fee.

public fun update_stake_fee(self: &mut StakePool, _: &AdminCap, fee: u64)

Parameters:

  • fee: Fee in BPS (max 500)

Emits: FeeUpdateEvent


update_unstake_fee

Update unstake fee.

public fun update_unstake_fee(self: &mut StakePool, _: &AdminCap, fee: u64)

Parameters:

  • fee: Fee in BPS (max 500)

Emits: FeeUpdateEvent


update_reward_fee

Update reward fee (performance fee).

public fun update_reward_fee(self: &mut StakePool, _: &AdminCap, fee: u64)

Parameters:

  • fee: Fee in BPS (max 10000)

Emits: FeeUpdateEvent


update_unstake_fee_redistribution

Update unstake fee redistribution percentage.

public fun update_unstake_fee_redistribution(self: &mut StakePool, _: &AdminCap, fee: u64)

Parameters:

  • fee: Percentage in BPS (max 10000)

Emits: FeeUpdateEvent


update_boosted_reward_amount

Set the amount of boosted rewards to distribute per epoch.

public fun update_boosted_reward_amount(self: &mut StakePool, _: &AdminCap, amount: u64)

Emits: BoostedRewardAmountUpdateEvent


collect_fees

Collect accumulated protocol fees.

public fun collect_fees(
    self: &mut StakePool,
    metadata: &mut Metadata<CERT>,
    system_state: &mut SuiSystemState,
    _: &AdminCap,
    ctx: &mut TxContext
): Coin<SUI>

Returns: Coin<SUI> - All accumulated fees

Emits: CollectFeesEvent


mint_operator_cap

Mint a new OperatorCap.

public fun mint_operator_cap(
    self: &mut StakePool,
    _: &AdminCap,
    recipient: address,
    ctx: &mut TxContext
)

Emits: MintOperatorCapEvent


5. Operator Functions

All operator functions require OperatorCap.

set_validator_weights

Set validator weight allocation.

public fun set_validator_weights(
    self: &mut StakePool,
    metadata: &mut Metadata<CERT>,
    system_state: &mut SuiSystemState,
    _: &OperatorCap,
    validator_weights: VecMap<address, u64>,
    ctx: &mut TxContext
)

Parameters:

NameTypeDescription
validator_weightsVecMap<address, u64>Map of validator address to weight

Constraints:

  • Maximum 50 validators
  • Total weight <= 10,000

Emits: ValidatorWeightsUpdateEvent

TypeScript Example:

import { bcs } from '@mysten/sui/bcs';

async function setValidatorWeights(weights: [string, number][]) {
    const tx = new Transaction();

    // Serialize VecMap as vector of (address, u64) tuples
    const serialized = bcs.vector(
        bcs.tuple([bcs.Address, bcs.u64()])
    ).serialize(weights);

    tx.moveCall({
        target: `${PACKAGE_ID}::stake_pool::set_validator_weights`,
        arguments: [
            tx.object(STAKE_POOL),
            tx.object(CERT_METADATA),
            tx.object(SUI_SYSTEM_STATE),
            tx.object(OPERATOR_CAP),
            tx.pure(serialized),
        ],
    });

    return tx;
}

// Usage
const weights: [string, number][] = [
    ['0xvalidator1...', 5000],
    ['0xvalidator2...', 3000],
    ['0xvalidator3...', 2000],
];
await setValidatorWeights(weights);

deposit_boosted_balance

Deposit SUI as boosted rewards.

public fun deposit_boosted_balance(
    self: &mut StakePool,
    _: &OperatorCap,
    coin: &mut Coin<SUI>,
    amount: u64,
    ctx: &mut TxContext
)

Parameters:

NameTypeDescription
coin&mut Coin<SUI>SUI coin to deposit from
amountu64Amount to deposit

Emits: DepositBoostedBalanceEvent


6. Events

StakeEventExt

public struct StakeEventExt has copy, drop {
    sui_amount_in: u64,      // SUI staked
    lst_amount_out: u64,     // vSUI received
    fee_amount: u64          // Stake fee charged
}

UnstakeEventExt

public struct UnstakeEventExt has copy, drop {
    lst_amount_in: u64,          // vSUI burned
    sui_amount_out: u64,         // SUI received
    fee_amount: u64,             // Unstake fee (to protocol)
    redistribution_amount: u64   // Unstake fee (returned to pool)
}

EpochChangedEvent

public struct EpochChangedEvent has copy, drop {
    old_sui_supply: u64,         // Previous total SUI
    new_sui_supply: u64,         // New total SUI (after rewards)
    boosted_reward_amount: u64,  // Boosted rewards distributed
    lst_supply: u64,             // Current vSUI supply
    reward_fee: u64              // Reward fee charged
}

DelegateStakeEvent

public struct DelegateStakeEvent has copy, drop {
    v_address: address,      // Preferred validator
    sui_amount_in: u64,      // SUI staked
    lst_amount_out: u64      // vSUI received
}

ValidatorWeightsUpdateEvent

public struct ValidatorWeightsUpdateEvent has copy, drop {
    validator_weights: VecMap<address, u64>
}

RebalanceEvent

public struct RebalanceEvent has copy, drop {
    is_epoch_rolled_over: bool,  // Whether epoch changed
    sender: address              // Who triggered rebalance
}

FeeUpdateEvent

public struct FeeUpdateEvent has copy, drop {
    field: String,       // Fee field name
    old_value: u64,      // Previous value
    new_value: u64       // New value
}

CollectFeesEvent

public struct CollectFeesEvent has copy, drop {
    amount: u64          // Total fees collected
}

SetPausedEvent

public struct SetPausedEvent has copy, drop {
    paused: bool
}

MintOperatorCapEvent

public struct MintOperatorCapEvent has copy, drop {
    recipient: address
}

DepositBoostedBalanceEvent

public struct DepositBoostedBalanceEvent has copy, drop {
    before_balance: u64,
    after_balance: u64
}

BoostedRewardAmountUpdateEvent

public struct BoostedRewardAmountUpdateEvent has copy, drop {
    old_value: u64,
    new_value: u64
}

7. Constants & Error Codes

Constants

These are V2 contract constants. The staking interface can enforce a higher minimum.

ConstantValueDescription
SUI_MIST1,000,000,0001 SUI in MIST
MIN_STAKE_AMOUNT100,000,000Minimum stake/unstake (0.1 SUI)
MIN_STAKE_THRESHOLD1,000,000,000Minimum stake per validator (1 SUI)
MAX_VALIDATORS50Maximum validators
MAX_TOTAL_WEIGHT10,000Maximum sum of weights
DEFAULT_WEIGHT100Default weight for new validators
MAX_STAKE_FEE_BPS500Maximum stake fee (5%)
MAX_UNSTAKE_FEE_BPS500Maximum unstake fee (5%)
MAX_BPS10,000Maximum reward fee (100%)
BPS_MULTIPLIER10,000Basis points multiplier
VERSION2Current contract version
ACCEPTABLE_MIST_ERROR10Allowed rounding error

Error Codes

ModuleCodeNameDescription
fee_config20001EInvalidFeeFee exceeds maximum
stake_pool30000EZeroMintAmountCannot mint zero vSUI
stake_pool30001ERatioRatio invariant violated
stake_pool30002EZeroSupplyZero supply error
stake_pool30003EUnderMinAmountBelow minimum amount
validator_pool40000ENotEnoughSuiInSuiPoolInsufficient SUI
validator_pool40001ENotActiveValidatorValidator not active
validator_pool40002ETooManyValidatorsExceeds max validators
validator_pool40003EValidatorAlreadyExistsValidator exists
validator_pool40004EValidatorNotFoundValidator not found
validator_pool40005EInvalidValidatorWeightInvalid weight
validator_pool40006EInvalidValidatorWeightSumWeight sum mismatch
validator_pool40007EInvalidValidatorSizeInvalid validator size
validator_pool40008EMaxTotalWeightTotal weight exceeds max
validator_pool40009ETotalSuiSupplyChangedSupply changed unexpectedly
manage50001EIncompatibleVersionVersion mismatch
manage50002EIncompatiblePausedPool is paused
cert1E_INCOMPATIBLE_VERSIONMetadata version mismatch

On this page