Skip to content

Commit

Permalink
Merge pull request #65 from MeteoraAg/fix-getClaimableReward-returnin…
Browse files Browse the repository at this point in the history
…g-extra-key

Fix/get claimable reward returning extra key
  • Loading branch information
00xSam authored Dec 22, 2023
2 parents d8df3fc + 6173220 commit 7cf573f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion ts-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mercurial-finance/farming-sdk",
"version": "1.0.15",
"version": "1.0.16",
"description": "",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down
35 changes: 18 additions & 17 deletions ts-client/src/farm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,17 @@ export class PoolFarmImpl {

const chunkedClaimAllTx = chunks(claimAllTxs, MAX_CLAIM_ALL_ALLOWED);

const { blockhash, lastValidBlockHeight } =
await connection.getLatestBlockhash("confirmed");
return Promise.all(
chunkedClaimAllTx.map(async (claimAllTx) => {
return new Transaction({
feePayer: owner,
...(await program.provider.connection.getLatestBlockhash(
"finalized"
)),
blockhash,
lastValidBlockHeight,
})
.add(...claimAllTx)
.add(ComputeBudgetProgram.setComputeUnitLimit({ units: 1_400_000 }));
.add(ComputeBudgetProgram.setComputeUnitLimit({ units: 1_400_000 }))
.add(...claimAllTx);
})
);
}
Expand Down Expand Up @@ -462,18 +463,18 @@ export class PoolFarmImpl {
onChainTime < rewardDurationEnd ? onChainTime : rewardDurationEnd;
const { a, b } = rewardPerToken(poolState, lastTimeRewardApplicable);

const rewardA = userState
? userState.balanceStaked
.mul(a.sub(userState.rewardAPerTokenComplete))
.div(new BN(1_000_000_000))
.add(userState.rewardAPerTokenPending)
: new BN(0);
const rewardB = userState
? userState.balanceStaked
.mul(b.sub(userState.rewardBPerTokenComplete))
.div(new BN(1_000_000_000))
.add(userState.rewardBPerTokenPending)
: new BN(0);
if (!userState || !poolState) return accValue;

const rewardA: BN = userState.balanceStaked
.mul(a.sub(userState.rewardAPerTokenComplete))
.div(new BN(1_000_000_000))
.add(userState.rewardAPerTokenPending);
const rewardB: BN = userState.balanceStaked
.mul(b.sub(userState.rewardBPerTokenComplete))
.div(new BN(1_000_000_000))
.add(userState.rewardBPerTokenPending);

if (rewardA.isZero() && rewardB.isZero()) return accValue;
accValue.set(farmMint, {
rewardA,
rewardB,
Expand Down

0 comments on commit 7cf573f

Please sign in to comment.