Get Single Position
Fetch comprehensive data for a specific position NFT including metadata, associated pair information, and token types. This method retrieves the on-chain position object with all its properties.
Prerequisites
Before fetching position data:
Have a valid position ID (object address)
Initialize the SDK with network connection
Understand position NFT structure in DLMM
Basic Usage
const positionId = "0x123...abc";
// Fetch position details
const position = await sdk.Position.getLbPosition(positionId);
console.log("Position details:", {
id: position.id,
pairId: position.pair_id,
tokenX: position.tokenXType,
tokenY: position.tokenYType,
name: position.name
});
Method Signature
async getLbPosition(positionId: string): Promise<LBPosition>
Parameters
positionId
: The object ID of the position NFT
Returns
LBPosition
object:
interface LBPosition {
id: string; // Position NFT address
tokenXType: string; // Full type of token X
tokenYType: string; // Full type of token Y
pair_id: string; // Associated pair address
name: string; // NFT name (e.g., "Alphafi DLMM Position")
description: string; // NFT description
url: string; // NFT image URL
index: string; // Position index in the pair
version: string; // Object version
}
Understanding Position Data
NFT Metadata
const position = await sdk.Position.getLbPosition(positionId);
// NFT display properties
console.log("NFT Name:", position.name);
console.log("Description:", position.description);
console.log("Image URL:", position.url);
// Position specifics
console.log("Position Index:", position.index);
console.log("Pair ID:", position.pair_id);
Token Information
const position = await sdk.Position.getLbPosition(positionId);
// Extract token symbols from types
const tokenXSymbol = position.tokenXType.split("::").pop();
const tokenYSymbol = position.tokenYType.split("::").pop();
console.log(`Position holds: ${tokenXSymbol}/${tokenYSymbol}`);
Complete Position Analysis
// Get position and its associated data
const positionId = "0x123...";
const position = await sdk.Position.getLbPosition(positionId);
// Get the pair for additional context
const pair = await sdk.Pair.getPair(position.pair_id);
// Get bins to see liquidity distribution
const bins = await sdk.Position.getPositionBins(pair, positionId);
// Get current value
const amounts = await sdk.Position.getPositionBinsAmount(pair, positionId);
console.log("Position analysis:", {
pair: `${position.tokenXType}/${position.tokenYType}`,
activeBins: bins.length,
binRange: bins.length > 0 ? [bins[0].id, bins[bins.length - 1].id] : [],
currentPrice: getPriceFromBinId(pair.parameters.active_id, Number(pair.binStep))
});
Error Handling
try {
const position = await sdk.Position.getLbPosition(invalidId);
} catch (error) {
if (error.message.includes("Position not found")) {
console.error("Position does not exist");
} else if (error.message.includes("Invalid")) {
console.error("Invalid position ID format");
}
}
Verify Position Ownership
// Check if position belongs to current user
const position = await sdk.Position.getLbPosition(positionId);
const userPositions = await sdk.Position.getLbPositions([]);
const isOwner = userPositions.some(p => p.id === positionId);
console.log("User owns this position:", isOwner);
Position State Checks
const position = await sdk.Position.getLbPosition(positionId);
const pair = await sdk.Pair.getPair(position.pair_id);
// Check if position has liquidity
const bins = await sdk.Position.getPositionBins(pair, positionId);
const hasLiquidity = bins.length > 0;
// Check if pair is still active
const pairActive = BigInt(pair.reserveX) > 0n || BigInt(pair.reserveY) > 0n;
console.log("Position state:", {
hasLiquidity,
pairActive,
binCount: bins.length
});
Common Use Cases
Position Details Page: Display complete position information
Pre-transaction Validation: Verify position before operations
Position Migration: Get data before moving to new strategies
Analytics: Track individual position performance
Related Topics
Get User Positions - List all user positions
Get Position Bins - View liquidity in bins
Position Value - Calculate position worth
Remove Liquidity Overview - Withdraw from position
Last updated