From 05c4d20efc9e5eb0806d9a89e61401dfdecd9802 Mon Sep 17 00:00:00 2001 From: gmbronco <83549293+gmbronco@users.noreply.github.com> Date: Wed, 31 Jan 2024 18:59:10 +0100 Subject: [PATCH] fix: handle missing reward tokens in the APRs --- balancer-js/src/modules/pools/apr/apr.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/balancer-js/src/modules/pools/apr/apr.ts b/balancer-js/src/modules/pools/apr/apr.ts index a549aeed0..f639625f9 100644 --- a/balancer-js/src/modules/pools/apr/apr.ts +++ b/balancer-js/src/modules/pools/apr/apr.ts @@ -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; } @@ -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