Skip to content

Commit

Permalink
0 tvl case
Browse files Browse the repository at this point in the history
  • Loading branch information
rbajollari committed Oct 17, 2024
1 parent f13b997 commit 065a63f
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions contracts/mellowpricefeed/MellowPriceFeed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,19 @@ contract MellowPriceFeed is Initializable, AggregatorV3Interface {

IPriceOracle priceOracle = IPriceOracle(vault_.configurator().priceOracle());

uint256 tvlUSD = 0;
uint256 quoteValueUSD = 0;
answer = int256(10**priceFeedDecimals);
uint256 totalTvl = 0;
uint256 quoteValue = 0;
for (uint256 i = 0; i < tokens.length; i++) {
uint256 priceX96 = priceOracle.priceX96(vault, tokens[i]);
if (tokens[i] == quoteAsset) {
quoteValueUSD += FullMath.mulDivRoundingUp(totalAmounts[i], priceX96, vault_.Q96());
quoteValue += FullMath.mulDivRoundingUp(totalAmounts[i], priceX96, vault_.Q96());
}
tvlUSD += FullMath.mulDivRoundingUp(totalAmounts[i], priceX96, vault_.Q96());
totalTvl += FullMath.mulDivRoundingUp(totalAmounts[i], priceX96, vault_.Q96());
}

answer = 0;
if (tvlUSD != 0) {
answer = int256(quoteValueUSD) * int256(10**priceFeedDecimals) / int256(tvlUSD);
if (totalTvl != 0) {
answer = int256(FullMath.mulDiv(quoteValue, uint256(answer), totalTvl));
}

// These values are equal after chainlink’s OCR update
Expand Down

0 comments on commit 065a63f

Please sign in to comment.