Skip to content

getAllLbPairPositionsByUser fails with 'Cannot read properties of undefined (reading feeAmountXPerTokenStored)' #245

@fengtality

Description

@fengtality

Description

The DLMM.getAllLbPairPositionsByUser() method throws an error when trying to fetch positions for certain wallets:

Cannot read properties of undefined (reading 'feeAmountXPerTokenStored')

This appears to happen when the SDK tries to compute fees on positions where internal state properties are not initialized.

Steps to Reproduce

import { DLMM } from '@meteora-ag/dlmm';
import { Connection, PublicKey } from '@solana/web3.js';

const connection = new Connection('https://api.mainnet-beta.solana.com');
const wallet = new PublicKey('DRpaJDurGtinzUPWSYnripFsJTBXm4HG7AC3LSgJNtNB');

const allPositions = await DLMM.getAllLbPairPositionsByUser(connection, wallet);

Expected Behavior

The method should successfully return all positions for the wallet, or handle positions with missing fee state gracefully.

Actual Behavior

The method throws an error and crashes:

Cannot read properties of undefined (reading 'feeAmountXPerTokenStored')

Environment

  • SDK Version: Latest (as of October 2025)
  • Network: Solana Mainnet-Beta
  • Connection: Standard RPC

Root Cause Analysis

The error suggests that the SDK is trying to access computed fee getters (likely positionData.feeX or positionData.feeY) which internally reference feeAmountXPerTokenStored. This property doesn't exist or isn't initialized for all positions returned by the batch fetch.

Suggested Fix

  1. Add null/undefined checks before accessing fee-related computed properties
  2. Make fee getters return null or 0 when internal state isn't initialized rather than throwing
  3. Add try-catch blocks around fee computations during position parsing

Workaround

Currently, there's no clean workaround other than:

  • Catching the error and handling it gracefully by returning empty results
  • Manually fetching position accounts using connection.getProgramAccounts() and parsing them without the SDK

Impact

This bug prevents users from fetching all positions for certain wallets, making the batch position fetching functionality unusable in production environments where you can't control which wallets will be queried.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions