Close Position

Remove all remaining liquidity and burn the position NFT in a single transaction. This method efficiently withdraws all tokens and fees before permanently closing the position.

Prerequisites

Before closing a position:

  • Own the position NFT you want to close

  • Have sufficient gas for transaction

  • Understand this action is irreversible

  • Consider claiming fees first if needed separately

Basic Usage

// Get the pair
const pair = await sdk.Pair.getPair(pairAddress);
const positionId = "0x123...abc";

// Remove all liquidity and close position
const tx = await sdk.Pair.removeAndClosePosition(pair, positionId);

// Execute transaction
const result = await sdk.fullClient.signAndExecuteTransaction({
  transaction: tx,
  signer: keypair
});

console.log("Position closed:", result.digest);

Method Signature

Parameters

  • pair: The LBPair where position exists

  • positionId: Position NFT to close

  • tx: Optional existing transaction to append to

Returns

  • Transaction that removes liquidity and burns NFT

  • Tokens are automatically sent to sender

How It Works

The method performs these steps automatically:

  1. Fetch position bins - Identifies all bins with liquidity

  2. Remove liquidity - Withdraws from all active bins

  3. Collect fees - Claims accumulated trading fees

  4. Close position - Burns the position NFT

  5. Transfer tokens - Sends all tokens to owner

Complete Example

Handling Empty Positions

Batch Operations

Alternative Approaches

Manual Two-Step Process

Partial Withdrawal Before Closing

What Happens to Your Assets

When closing a position:

  • Liquidity tokens are burned

  • Token X and Y are returned based on current bin reserves

  • Accumulated fees are included in the withdrawal

  • Position NFT is permanently destroyed

  • All assets are sent to transaction sender

Common Use Cases

  1. Exit Strategy: Complete withdrawal from a pool

  2. Position Migration: Close old positions before creating new ones

  3. Portfolio Cleanup: Remove empty or underperforming positions

  4. Emergency Exit: Quick withdrawal of all funds

Error Handling

Last updated