Skip to content

Commit

Permalink
Merge pull request #18 from Gearbox-protocol/dc_fix
Browse files Browse the repository at this point in the history
fix: accrued interest and fees computed all time
  • Loading branch information
0xmikko authored Mar 2, 2024
2 parents 701121f + b15d268 commit 31349a1
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions contracts/data/DataCompressorV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -254,22 +254,29 @@ contract DataCompressorV3 is IDataCompressorV3, ContractsRegisterTrait, LinearIn
// uint256 quotedTokensMask;
// address[] quotedTokens;

try creditManager.calcDebtAndCollateral(_creditAccount, CollateralCalcTask.DEBT_COLLATERAL) returns (
CollateralDebtData memory collateralDebtData
) {
result.accruedInterest = collateralDebtData.accruedInterest;
result.accruedFees = collateralDebtData.accruedFees;
result.totalDebtUSD = collateralDebtData.totalDebtUSD;
result.totalValueUSD = collateralDebtData.totalValueUSD;
result.twvUSD = collateralDebtData.twvUSD;
result.healthFactor = collateralDebtData.totalDebtUSD != 0
? collateralDebtData.twvUSD * PERCENTAGE_FACTOR / collateralDebtData.totalDebtUSD
: type(uint16).max;
result.totalValue = collateralDebtData.totalValue;
result.isSuccessful = true;
} catch {
result.priceFeedsNeeded = _getPriceFeedFailedList(_cm, result.balances);
result.isSuccessful = false;
for (uint256 i = 0; i < 2;) {
try creditManager.calcDebtAndCollateral(
_creditAccount, i == 0 ? CollateralCalcTask.DEBT_ONLY : CollateralCalcTask.DEBT_COLLATERAL
) returns (CollateralDebtData memory collateralDebtData) {
result.accruedInterest = collateralDebtData.accruedInterest;
result.accruedFees = collateralDebtData.accruedFees;

result.totalDebtUSD = collateralDebtData.totalDebtUSD;
result.totalValueUSD = collateralDebtData.totalValueUSD;
result.twvUSD = collateralDebtData.twvUSD;
result.healthFactor = collateralDebtData.totalDebtUSD != 0
? collateralDebtData.twvUSD * PERCENTAGE_FACTOR / collateralDebtData.totalDebtUSD
: type(uint16).max;
result.totalValue = collateralDebtData.totalValue;
result.isSuccessful = true;
} catch {
result.priceFeedsNeeded = _getPriceFeedFailedList(_cm, result.balances);
result.isSuccessful = false;
}

unchecked {
++i;
}
}

(result.debt, result.cumulativeIndexLastUpdate, result.cumulativeQuotaInterest,,,, result.since,) =
Expand Down

0 comments on commit 31349a1

Please sign in to comment.