# Calculate Homora V2 pending rewards ## MasterChef We calculate the rewards depending on dex and their staking contract version. The concept is that we get - `collateralSize`, `collId` from `homoraBank.positionInfo(positionId)` - `entryRewardPerShare` from the last 240 bits of `collId` - `poolInfo` / `userInfo` from `masterChefContract.poolInfo(pool.pid, pool.wTokenAddress)` - `pendingReward` / `pendingToken` / `pending…` from `masterChefContract.pendingReward(pool.pid, pool.wTokenAddress)` Then we calculate reward by ```javascript const pendingRewardsPerShare = pendingRewards.times('1e18').div(poolInfo.amount) const rewardAmount = collateralSize .times(accRewardPerShare.minus(entryRewardPerShare).plus(pendingRewardsPerShare)) .div(`1e${rewardDecimals}`) .div('1e12') // Depending on each dex ``` ### Example ```typescript case WTokenType.WMasterChefJoeV3: const [_accJoePerShare, _userInfo, _pendingTokens, joeDecimals] = await makeMulticall([ wMasterChefJoeV3Contract.methods.accJoePerShare(), masterChefJoeV3Contract.methods.userInfo(pool.pid, pool.wTokenAddress), masterChefJoeV3Contract.methods.pendingTokens(pool.pid, pool.wTokenAddress), rewardErc20Contract.methods.decimals(), ]) const accJoePerShare = new BigNumber(_accJoePerShare) const userPendingJoe = new BigNumber(_pendingTokens?.pendingJoe).times('1e18').div(_userInfo?.amount) rewardAmount = collSize .times(accJoePerShare.minus(entryRewardPerShare).plus(userPendingJoe)) .div('1e18') .div(`1e${joeDecimals}`) ``` ## Curve ```javascript const wLiquidityGaugeContract = contractService.getContract(wLiquidityGaugeJson.abi, pool.wTokenAddress) const { accCrvPerShare } = await wLiquidityGaugeContract.methods.gauges(pool.pid, pool.gid).call() const rewardAmount = collateralSize .times(accCrvPerShare.minus(entryRewardPerShare)) .div(`1e${crvDecimals}`) .div('1e18') ```