Skip to content
Docs
Open app
Skip to Content

Unstake vSUI

Redeem vSUI for SUI instantly, after checking that the pool has enough liquidity.

  • @mysten/sui 2.39.1npm 3.0.1
  • TypeScript
  • Sui mainnet

stake_pool::unstake burns a Coin<CERT> and returns SUI as a Coin<SUI> at the current exchange rate. Redemption is instant while the pool holds enough SUI, which the stats API reports as maxInstantUnstake.

unstake.ts
import { Transaction, coinWithBalance, type TransactionObjectArgument } from '@mysten/sui/transactions';
import { VOLO } from './constants';

/** Appends an unstake call and returns the redeemed SUI coin. */
export function unstakeVsui(tx: Transaction, vsui: TransactionObjectArgument) {
  const [sui] = tx.moveCall({
    target: `${VOLO.packageId}::stake_pool::unstake`,
    arguments: [tx.object(VOLO.stakePool), tx.object(VOLO.metadata), tx.object('0x5'), vsui],
  });
  return sui;
}

/** Redeems `amount` vSUI base units from `owner` and sends the SUI back. */
export async function buildUnstake(owner: string, amount: bigint) {
  // Redemption is instant only while the pool holds enough SUI
  const response = await fetch('https://open-api.naviprotocol.io/api/volo/stats');
  const { data } = (await response.json()) as { data: { exchangeRate: number; maxInstantUnstake: string } };
  const expectedSui = (Number(amount) / 1e9) * data.exchangeRate;
  if (expectedSui > Number(data.maxInstantUnstake)) throw new Error('Not enough instant liquidity');

  const tx = new Transaction();
  tx.setSender(owner); // coinWithBalance selects and merges the owner's vSUI coins
  const vsui = coinWithBalance({ type: VOLO.vsuiType, balance: amount });
  const sui = unstakeVsui(tx, vsui);
  tx.transferObjects([sui], owner);
  return tx;
}

coinWithBalance selects and merges the owner’s vSUI coins at build time, which is why the transaction needs a sender. To unstake a vSUI coin produced earlier in the same PTB, pass that coin to unstakeVsui instead.

Rules

RuleDetail
MinimumEach unstake must be worth at least 0.1 SUI.
OutputAbout amount × exchangeRate SUI, less any unstake fee. Quote it exactly with get_amount_out.
FeesThe unstake fee is capped at 5% in the contract. Part of it can be returned to the pool for the remaining stakers.
LiquidityIf the pool cannot cover the amount, the call aborts with ENotEnoughSuiInSuiPool (40000). Unstake less, or try later.
Paused poolUnstaking aborts with EIncompatiblePaused (50002) while the pool is paused.
Entry variantunstake_entry does the same and transfers the SUI to the sender.

Users who only want to exit a position can also unstake in the Volo app.

On this page