For the complete documentation index, see llms.txt. This page is also available as Markdown.

Collect Yield

Calculate and claim accumulated rewards and fees from their DLMM positions

Rewards Management

getPositionRewards(pair, positionId, binIds)

Calculate pending reward amounts for a position across all rewarders.

Parameters:

  • pair: LBPair - The LBPair containing the position

  • positionId: string - ID of the position to check rewards for

  • binIds: number[] - Array of bin IDs to calculate rewards for

Returns: Promise<PositionReward[]>

Example:

const rewards = await ferraSDK.Position.getPositionRewards(pair, "0x123...", [1, 2, 3]);
rewards.forEach(reward => {
  console.log(`Pending ${reward.amount} of ${reward.coinType}`);
});

getPositionRewardsV2(pair, positionId, binIds)

Updated version of rewards calculation with improved performance.

Parameters: Same as V1 Returns: Promise<PositionReward[]>

claimPositionRewards(pair, positionId, binIds, tx?)

Claim all pending rewards for a position and transfer to sender.

Parameters:

  • pair: LBPair - The LBPair containing the position

  • positionId: string - ID of the position to claim rewards for

  • binIds: number[] - Array of bin IDs to claim rewards from

  • tx?: Transaction - Optional existing transaction to add operations to

Returns: Promise<Transaction>

Example:

claimPositionRewardsV2(pair, positionId, binIds, tx?)

Updated version of reward claiming with optimized transaction structure.

Parameters: Same as V1 Returns: Promise<Transaction>

Fees Management

getPositionFees(pair, positionId, binIds)

Calculate pending fee amounts for specific bins of a position.

Parameters:

  • pair: LBPair - The LBPair containing the position

  • positionId: string - ID of the position to check fees for

  • binIds: number[] - Array of bin IDs to calculate fees for

Returns: Promise<[PositionReward, PositionReward] | null>

Returns a tuple of [tokenX fees, tokenY fees] or null if no fees found.

Example:

getPositionFeesV2(pair, positionId, binIds)

Updated version of fee calculation with improved accuracy.

Parameters: Same as V1 Returns: Promise<[PositionReward, PositionReward] | null>

claimPositionFee(pair, positionId, binIds, tx?)

Claim accumulated fees for specific bins of a position.

Parameters:

  • pair: LBPair - The LBPair containing the position

  • positionId: string - ID of the position to claim fees for

  • binIds: number[] - Array of bin IDs to claim fees from

  • tx?: Transaction - Optional existing transaction to add operations to

Returns: Promise<Transaction>

Example:

claimPositionFeeV2(pair, positionId, binIds, tx?)

Updated version of fee claiming with optimized batching.

Parameters: Same as V1 Returns: Promise<Transaction>

Data Types

PositionReward

V2 Methods

The module provides V2 versions of key methods that offer:

  • Improved Performance: Optimized transaction structures

  • Better Accuracy: Enhanced calculation algorithms

  • Gas Optimization: Reduced transaction costs

When to use V2:

  • For new integrations, prefer V2 methods

  • V2 methods are backward compatible

  • Better suited for high-volume operations

Transaction Batching

The module implements intelligent batching for large operations:

This prevents transaction size limits and optimizes gas usage.

Error Handling

Common Errors

  1. "Invalid sender address": SDK sender address not configured

  2. "Position not found": Position ID doesn't exist

  3. "Position is not match with pair id": Position doesn't belong to specified pair

Performance Optimization

Caching Strategy

The module uses internal caching to optimize performance:

RPC Batching

Uses RpcBatcher for efficient data fetching:

Troubleshooting

Debug Checklist

  1. Verify sender address is set: sdk.senderAddress

  2. Check position exists: Use getLbPosition(positionId)

  3. Validate bin IDs: Ensure bins belong to the position

  4. Test with small amounts first: Avoid large transaction failures

Common Solutions

  • Gas estimation failures: Use V2 methods for better optimization

  • Empty rewards: Position may not have accumulated rewards yet

  • Transaction timeouts: Reduce batch sizes or split operations

Last updated