From 8c0a5ad8f0213a8f84b2570c7e350f67e5ee117f Mon Sep 17 00:00:00 2001 From: Chris Jacobs Date: Tue, 7 Jan 2025 18:18:10 -0800 Subject: [PATCH] adjust protocol table apy to balance for overlapping tvl --- src/mainnet/processors/protocol/protocol.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/mainnet/processors/protocol/protocol.ts b/src/mainnet/processors/protocol/protocol.ts index 9383dde4..ac50c1b3 100644 --- a/src/mainnet/processors/protocol/protocol.ts +++ b/src/mainnet/processors/protocol/protocol.ts @@ -61,10 +61,6 @@ export const protocolProcessor = defineProcessor({ dailyStat.earningTVL = sumBigIntBy(dateDetails, 'earningTVL') dailyStat.tvl = sumBigIntBy(dateDetails, 'tvl') dailyStat.revenue = sumBigIntBy(dateDetails, 'revenue') - dailyStat.apy = - dailyStat.tvl === 0n - ? 0 - : dateDetails.reduce((acc, detail) => acc + detail.apy * Number(detail.tvl), 0) / Number(dailyStat.tvl) // Find overlapping TVL const superOETHbWrappedOETH = await ctx.store.findOne(StrategyBalance, { @@ -76,10 +72,19 @@ export const protocolProcessor = defineProcessor({ timestamp: 'desc', }, }) - const tvlAdjustment = -(superOETHbWrappedOETH?.balanceETH ?? 0n) + const superOETHbWrappedOethBalance = superOETHbWrappedOETH?.balanceETH ?? 0n + + // Adjust TVL for overlapping strategy balance. + dailyStat.tvl -= superOETHbWrappedOethBalance + dailyStat.apy = + dailyStat.tvl === 0n + ? 0 + : dateDetails.reduce((acc, detail) => { + // We lessen the OETH TVL for APY calculation since that APY is also included in Super OETHb. + const tvl = detail.id === 'OETH' ? detail.tvl - superOETHbWrappedOethBalance : detail.tvl + return acc + detail.apy * Number(tvl) + }, 0) / Number(dailyStat.tvl) - // Add the TVL adjustment - dailyStat.tvl += tvlAdjustment dailyStat.meta = { tvlAdjustments: superOETHbWrappedOETH ? [