Skip to content

Commit

Permalink
avoid apy calculation on tokens with no deposits
Browse files Browse the repository at this point in the history
  • Loading branch information
soilking committed Oct 10, 2024
1 parent 6880600 commit 172838f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion projects/subgraph-beanstalk/src/utils/Yield.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export function updateSiloVAPYs(protocol: Address, timestamp: BigInt, window: i3
}
}

let calculatedTokens: Address[] = [];
let apys: BigDecimal[][] = [];

// Chooses which apy calculation to use
Expand All @@ -126,6 +127,7 @@ export function updateSiloVAPYs(protocol: Address, timestamp: BigInt, window: i3
silo.stalk,
silo.grownStalkPerSeason
);
calculatedTokens.push(toAddress(whitelistSettings[i].id));
apys.push(tokenAPY);
}
} else {
Expand Down Expand Up @@ -162,6 +164,12 @@ export function updateSiloVAPYs(protocol: Address, timestamp: BigInt, window: i3
const depositedAsset = depositedAssets.splice(depositedIndex, 1)[0];
const depositedBdv = toDecimal(depositedAsset.depositedBDV);

if (depositedBdv == ZERO_BD) {
// Do not calculate yields on tokens with no deposits
continue;
}
calculatedTokens.push(toAddress(whitelistSettings[i].id));

const germinating = getGerminatingBdvs(Address.fromBytes(whitelistSettings[i].id));

if (gaugeSettings[i] !== null) {
Expand Down Expand Up @@ -213,7 +221,7 @@ export function updateSiloVAPYs(protocol: Address, timestamp: BigInt, window: i3

// Save the apys
for (let i = 0; i < apys.length; ++i) {
let tokenYield = loadTokenYield(Address.fromBytes(whitelistSettings[i].id), t, window);
let tokenYield = loadTokenYield(calculatedTokens[i], t, window);
tokenYield.beanAPY = apys[i][0];
tokenYield.stalkAPY = apys[i][1];
tokenYield.createdAt = timestamp;
Expand Down

0 comments on commit 172838f

Please sign in to comment.