# Remove All Liquidity

Withdraw all liquidity from a position in a single transaction while keeping the position NFT active. Useful for complete exits without burning the NFT.

### Prerequisites

* Position ID with active liquidity
* Understanding this keeps NFT alive
* Gas for transaction execution
* Consider `removeAndClosePosition` if burning NFT

### Basic Usage

```typescript
// Get all bins for the position
const bins = await sdk.Position.getPositionBins(pair, positionId);
const allBinIds = bins.map(bin => bin.id);

// Remove from all bins at once
const tx = await sdk.Pair.removeLiquidity(pair, {
  positionId: "0x123...abc",
  binIds: allBinIds
});

await sdk.fullClient.signAndExecuteTransaction({
  transaction: tx,
  signer: keypair
});
```

### Complete Withdrawal Pattern

```typescript
async function removeAllLiquidity(pair: LBPair, positionId: string) {
  // Fetch current bins
  const bins = await sdk.Position.getPositionBins(pair, positionId);
  
  if (bins.length === 0) {
    console.log("Position already empty");
    return;
  }
  
  // Remove all liquidity
  const tx = await sdk.Pair.removeLiquidity(pair, {
    positionId,
    binIds: bins.map(b => b.id)
  });
  
  return await sdk.fullClient.signAndExecuteTransaction({
    transaction: tx,
    signer: keypair
  });
}
```

### Preview Total Returns

```typescript
// Calculate what you'll receive
const amounts = await sdk.Position.getPositionBinsAmount(pair, positionId);

const totals = amounts.reduce((sum, bin) => ({
  tokenX: sum.tokenX + bin.amountX,
  tokenY: sum.tokenY + bin.amountY
}), { tokenX: 0n, tokenY: 0n });

console.log("Total withdrawal:", {
  tokenX: formatUnits(totals.tokenX, 18),
  tokenY: formatUnits(totals.tokenY, 6)
});
```

### Remove All vs Close Position

#### Remove All Liquidity

```typescript
// Keeps position NFT alive
await sdk.Pair.removeLiquidity(pair, {
  positionId,
  binIds: allBinIds
});
// ✅ NFT still exists (empty)
// ✅ Can add liquidity again
// ❌ Two transactions if closing later
```

#### Remove AND Close

```typescript
// One transaction - removes all + burns NFT
await sdk.Pair.removeAndClosePosition(pair, positionId);
// ✅ Single transaction
// ✅ Clean exit
// ❌ Need new NFT to re-enter
```

### Common Use Cases

#### Temporary Exit

```typescript
// Market uncertainty - exit but keep position
const bins = await sdk.Position.getPositionBins(pair, positionId);
await sdk.Pair.removeLiquidity(pair, {
  positionId,
  binIds: bins.map(b => b.id)
});
// Can re-enter later with same NFT
```

#### Fee Collection

```typescript
// Remove all to collect fees, then re-add
// Step 1: Remove everything
await removeAllLiquidity(pair, positionId);

// Step 2: Add back with new distribution
await sdk.Pair.addLiquidity(pair, {
  positionId,  // Same position
  // ... new parameters
});
```

### What You Receive

* All tokens from all bins
* Accumulated trading fees
* Based on current bin reserves
* Single transfer to your wallet

### Error Handling

```typescript
try {
  const bins = await sdk.Position.getPositionBins(pair, positionId);
  
  if (bins.length === 0) {
    throw new Error("No liquidity to remove");
  }
  
  await sdk.Pair.removeLiquidity(pair, {
    positionId,
    binIds: bins.map(b => b.id)
  });
  
} catch (error) {
  console.error("Removal failed:", error);
}
```

### Related Topics

* [Close Position](/integration/dlmm/typescript-sdk/position-management/close-position.md) - Remove + burn NFT
* [Calculate Output Amounts](/integration/dlmm/typescript-sdk/remove-liquidity/calculate-output-amounts.md) - Preview returns
* [Remove from Specific Bins](/integration/dlmm/typescript-sdk/remove-liquidity/remove-from-specific-bins.md) - Partial removal
* [Add to Existing Position](/integration/dlmm/typescript-sdk/add-liquidity/add-to-existing-position.md) - Re-add later


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ferra.ag/integration/dlmm/typescript-sdk/remove-liquidity/remove-all-liquidity.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
