Skip to content

Commit

Permalink
MEX-514: return 0 APR for stakings with no rewards
Browse files Browse the repository at this point in the history
Signed-off-by: Claudiu Lataretu <[email protected]>
  • Loading branch information
claudiulataretu committed Sep 12, 2024
1 parent f3dbd68 commit fcb34fd
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/modules/staking/services/staking.compute.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,20 @@ export class StakingComputeService {
additionalUserStakeAmount = '0',
additionalUserEnergy = '0',
): Promise<number> {
const [produceRewardsEnabled, accumulatedRewards, rewardsCapacity] =
await Promise.all([
this.stakingAbi.produceRewardsEnabled(scAddress),
this.stakingAbi.accumulatedRewards(scAddress),
this.stakingAbi.rewardCapacity(scAddress),
]);

if (
!produceRewardsEnabled ||
new BigNumber(accumulatedRewards).isEqualTo(rewardsCapacity)
) {
return 0;
}

const [currentWeek, boostedRewardsPerWeek] = await Promise.all([
this.weekTimeKeepingAbi.currentWeek(scAddress),
this.computeBoostedRewardsPerWeek(
Expand Down Expand Up @@ -652,6 +666,20 @@ export class StakingComputeService {
userAddress: string,
additionalUserStakeAmount = '0',
): Promise<number> {
const [produceRewardsEnabled, accumulatedRewards, rewardsCapacity] =
await Promise.all([
this.stakingAbi.produceRewardsEnabled(scAddress),
this.stakingAbi.accumulatedRewards(scAddress),
this.stakingAbi.rewardCapacity(scAddress),
]);

if (
!produceRewardsEnabled ||
new BigNumber(accumulatedRewards).isEqualTo(rewardsCapacity)
) {
return 0;
}

const [boostedRewardsPerWeek, boostedYieldsFactors] = await Promise.all(
[
this.computeBoostedRewardsPerWeek(
Expand Down

0 comments on commit fcb34fd

Please sign in to comment.