Collect Yield
Calculate and claim accumulated rewards and fees from their DLMM positions
Rewards Management
getPositionRewards(pair, positionId, binIds)
getPositionRewards(pair, positionId, binIds)Calculate pending reward amounts for a position across all rewarders.
Parameters:
pair: LBPair- The LBPair containing the positionpositionId: string- ID of the position to check rewards forbinIds: 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)
getPositionRewardsV2(pair, positionId, binIds)Updated version of rewards calculation with improved performance.
Parameters: Same as V1 Returns: Promise<PositionReward[]>
claimPositionRewards(pair, positionId, binIds, tx?)
claimPositionRewards(pair, positionId, binIds, tx?)Claim all pending rewards for a position and transfer to sender.
Parameters:
pair: LBPair- The LBPair containing the positionpositionId: string- ID of the position to claim rewards forbinIds: number[]- Array of bin IDs to claim rewards fromtx?: Transaction- Optional existing transaction to add operations to
Returns: Promise<Transaction>
Example:
claimPositionRewardsV2(pair, positionId, binIds, tx?)
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)
getPositionFees(pair, positionId, binIds)Calculate pending fee amounts for specific bins of a position.
Parameters:
pair: LBPair- The LBPair containing the positionpositionId: string- ID of the position to check fees forbinIds: 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)
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?)
claimPositionFee(pair, positionId, binIds, tx?)Claim accumulated fees for specific bins of a position.
Parameters:
pair: LBPair- The LBPair containing the positionpositionId: string- ID of the position to claim fees forbinIds: number[]- Array of bin IDs to claim fees fromtx?: Transaction- Optional existing transaction to add operations to
Returns: Promise<Transaction>
Example:
claimPositionFeeV2(pair, positionId, binIds, tx?)
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
"Invalid sender address": SDK sender address not configured
"Position not found": Position ID doesn't exist
"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
Verify sender address is set:
sdk.senderAddressCheck position exists: Use
getLbPosition(positionId)Validate bin IDs: Ensure bins belong to the position
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