Skip to content

Commit

Permalink
fix: handle missing reward tokens in the APRs
Browse files Browse the repository at this point in the history
  • Loading branch information
gmbronco committed Jan 31, 2024
1 parent 87717cd commit 05c4d20
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions balancer-js/src/modules/pools/apr/apr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,15 @@ export class PoolApr {

const balReward = bal && gauge.rewardTokens[bal];
if (balReward) {
const reward = await this.rewardTokenApr(bal, balReward);
const totalSupplyUsd = gauge.totalSupply * bptPriceUsd;
const rewardValue = reward.value / totalSupplyUsd;
return Math.round(10000 * rewardValue);
let reward: { address: string; value: number };
try {
reward = await this.rewardTokenApr(bal, balReward);
const totalSupplyUsd = gauge.totalSupply * bptPriceUsd;
const rewardValue = reward.value / totalSupplyUsd;
return Math.round(10000 * rewardValue);
} catch (e) {
return 0;
}
} else {
return 0;
}
Expand Down Expand Up @@ -347,7 +352,12 @@ export class PoolApr {
const rewards = rewardTokenAddresses.map(async (tAddress) => {
/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */
const data = gauge!.rewardTokens![tAddress];
return this.rewardTokenApr(tAddress, data);
try {
const reward = await this.rewardTokenApr(tAddress, data);
return reward;
} catch (e) {
return { address: tAddress, value: 0 };
}
});

// Get the gauge totalSupplyUsd
Expand Down

0 comments on commit 05c4d20

Please sign in to comment.