Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle missing reward tokens in the APRs #566

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading