> ## Documentation Index
> Fetch the complete documentation index at: https://developers.jup.ag/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Withdraw Staked SOL

> Withdraw pool tokens from vault, then burn them via Single Pool to receive stake back.

> [!NOTE]
>
> These flows use many instructions. If you hit compute limits, add `ComputeBudgetProgram.setComputeUnitLimit({ units: 1_000_000 })` (or higher) as the first instruction in your transaction.

Withdraw pool tokens from a [Native Staked Vault](https://developers.jup.ag/docs/lend/advanced/native-staked-vault.md), then burn them via the Single Pool program to receive your stake back.

**Flow:**

1. [Withdraw](https://developers.jup.ag/docs/lend/borrow/withdraw.md) pool tokens from vault via `getOperateIx` (negative colAmount)
2. Burn pool tokens with `SinglePoolProgram.withdraw` → receive stake account

***

## Withdraw

## 1. Import Dependencies

```bash theme={null}
npm install @solana/web3.js @solana/spl-single-pool-classic bn.js @jup-ag/lend @jup-ag/lend-read
```

```typescript theme={null}
import { SinglePoolProgram, findPoolAddress } from "@solana/spl-single-pool-classic";
import {
  Connection, Keypair, PublicKey,
  TransactionMessage, VersionedTransaction,
} from "@solana/web3.js";
import BN from "bn.js";
import { getOperateIx, MAX_WITHDRAW_AMOUNT } from "@jup-ag/lend/borrow";
```

## 2. Withdraw Pool Tokens from Vault

Use `getOperateIx` with `MAX_WITHDRAW_AMOUNT` to withdraw all collateral. As with a regular withdraw, this only succeeds if the resulting position stays within LTV, so [repay](https://developers.jup.ag/docs/lend/borrow/repay.md) debt first if needed.

```typescript theme={null}
const { ixs: operateIxs, addressLookupTableAccounts } = await getOperateIx({
  vaultId,
  positionId: userPositionId,
  colAmount: MAX_WITHDRAW_AMOUNT,
  debtAmount: new BN(0),
  connection,
  signer,
});
instructions.push(...operateIxs);
```

## 3. Burn Pool Tokens and Receive Stake

Use `SinglePoolProgram.withdraw` to burn pool tokens and receive a new stake account.

```typescript theme={null}
const SINGLE_POOL_PROGRAM_ID = new PublicKey("SVSPxpvHdN29nkVg9rPapPNDddN5DipNLRUFhyjFThE");
const pool = await findPoolAddress(SINGLE_POOL_PROGRAM_ID, voteAccount);
const newStakeAccount = Keypair.generate();

const withdrawIxs = await SinglePoolProgram.withdraw({
  connection,
  pool,
  userWallet: signer,
  userStakeAccount: newStakeAccount.publicKey,
  tokenAmount: tokenAmount.toNumber(),
  createStakeAccount: true,
});
instructions.push(...withdrawIxs.instructions);
```

## 4. Assemble and Execute the Transaction

Build a v0 message, sign with user keypair and new stake account keypair.

```typescript theme={null}
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash();
const message = new TransactionMessage({
  payerKey: signer,
  recentBlockhash: blockhash,
  instructions,
}).compileToV0Message(addressLookupTableAccounts ?? []);

const tx = new VersionedTransaction(message);
tx.sign([userKeypair, newStakeAccount]);

const signature = await connection.sendTransaction(tx, {
  skipPreflight: false, maxRetries: 3, preflightCommitment: "confirmed",
});
console.log("Withdraw successful:", signature);
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.