From 78c08a4b8111a43c9ee4f8efb386b844d60e4a2b Mon Sep 17 00:00:00 2001 From: Gowtham Sundaresan <131300352+gowthamsundaresan@users.noreply.github.com> Date: Tue, 21 Jan 2025 14:11:40 +0530 Subject: [PATCH] fix: prevent unsupported strategies leaking into rewards object (#328) --- .../api/src/routes/operators/operatorController.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/api/src/routes/operators/operatorController.ts b/packages/api/src/routes/operators/operatorController.ts index 9a81bcee..d44b8a38 100644 --- a/packages/api/src/routes/operators/operatorController.ts +++ b/packages/api/src/routes/operators/operatorController.ts @@ -595,6 +595,14 @@ async function calculateOperatorApy(operator: any) { // Iterate through each strategy and calculate all its rewards for (const strategyAddress of avs.avs.restakeableStrategies) { + // Omit strategy where the Operator doesn't have shares + if ( + !operator.shares.find( + (share) => share.strategyAddress.toLowerCase() === strategyAddress.toLowerCase() + ) + ) + continue + const strategyTvl = tvlStrategiesEth[strategyAddress.toLowerCase()] || 0 if (strategyTvl === 0) continue @@ -677,7 +685,7 @@ async function calculateOperatorApy(operator: any) { avsApyMap.set(avs.avs.address, { avsAddress: avs.avs.address, - maxApy: avs.avs.maxApy, + maxApy: Math.max(...Array.from(strategyApyMap.values()).map((data) => data.apy)), strategyApys: Array.from(strategyApyMap.entries()).map(([strategyAddress, data]) => ({ strategyAddress, apy: data.apy,