As the liquidity pool is traded upon, liquidity providers will begin to accrual fees and rewards. Follow the following steps to see how much you are owe and how to collect them.
Whirlpool Client
The collect_fees and rewards functionality is coming to WhirlpoolClient soon!
The Manual Way
Get a quick quote on outstanding fees and rewards
There are use-cases where users would like to check the outstanding values before deciding to perform an on-chain update and harvest. In these cases, use the provided collectFeesQuote and collectRewardsQuote in the Typescript SDK.
// Fetching necessary on-chain account data.constwhirlpool=awaitfetcher.getPool(whirlpoolAddress);constposition=awaitfetcher.getPosition(positionAddress)// Fetching tick array. Note that you may have to fetch two of them// if the upper and lower ticks live on different tick arrays.consttickArrayAddress=TickUtil.getPdaWithTickIndex(tickLowerIndex,...);consttickArray=awaitfetcher.getTickArray(tickArrayAddress);// Get the individual TickData on each tickIndex from the fetched TickArrayconstlowerTick=TickUtil.getTickFromTickArrayData(tickArrayData, tickLowerIndex, tickSpacing);constupperTick=TickUtil.getTickFromTickArrayData(tickArrayData, tickUpperIndex, tickSpacing);constfeeQuote=collectFeesQuote({ whirlpool, position, tickLower: lowerTick, tickUpper: upperTick,});constfeesInTokenA=feeQuote.feeOwedA;constfeesInTokenB=feeQuote.feeOwedB;constrewardQuote=collectRewardsQuote({ whirlpool, position, tickLower: lowerTick, tickUpper: upperTick,});constrewardsInReward0= rewardQuote[0].toNumber();constrewardsInReward1= rewardQuote[1].toNumber();constrewardsInReward2= rewardQuote[2].toNumber();
Update on-chain position with the latest accrued fees
Before you fetch your owed fees, you must update the on-chain position with the latest values by calling increase_liquidity or decrease_liquidity. Alternatively, you can call update_fee_and_rewards to update without modifying liquidity.
If this step is skipped, the collect instructions will only fetch the last updated values of the position. In many cases, this will be 0.