Skip to content

Commit

Permalink
adjust protocol table apy to balance for overlapping tvl
Browse files Browse the repository at this point in the history
  • Loading branch information
apexearth committed Jan 8, 2025
1 parent fd76ba7 commit 8c0a5ad
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/mainnet/processors/protocol/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand All @@ -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
? [
Expand Down

0 comments on commit 8c0a5ad

Please sign in to comment.