Skip to content

Commit

Permalink
Handle decreasing income index in EMAOracle.updateAndQuery(), minor u…
Browse files Browse the repository at this point in the history
…pdates
  • Loading branch information
ZeframLou committed May 20, 2021
1 parent f4b58f8 commit 9de3395
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion contracts/DInterest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ contract DInterest is
*/
uint256 internal constant EXTRA_PRECISION = 10**27;
/**
@dev used for funding.principalPerToken and deposit.interestRateMultiplierIntercept
@dev used for funding.principalPerToken
*/
uint256 internal constant ULTRA_PRECISION = 2**128;

Expand Down
11 changes: 9 additions & 2 deletions contracts/models/interest-oracle/EMAOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ contract EMAOracle is IInterestOracle, Initializable {
}

function updateAndQuery()
public
external
override
returns (bool updated, uint256 value)
{
Expand All @@ -67,6 +67,13 @@ contract EMAOracle is IInterestOracle, Initializable {
uint256 _emaStored = emaStored;

uint256 newIncomeIndex = moneyMarket.incomeIndex();
if (newIncomeIndex < _lastIncomeIndex) {
// Shouldn't revert (which would block execution)
// Assume no interest was accrued and use the last index as the new one
// which would push the EMA towards zero if there's e.g. an exploit
// in the underlying yield protocol
newIncomeIndex = _lastIncomeIndex;
}
uint256 incomingValue =
(newIncomeIndex - _lastIncomeIndex).decdiv(_lastIncomeIndex) /
timeElapsed;
Expand All @@ -83,7 +90,7 @@ contract EMAOracle is IInterestOracle, Initializable {
lastUpdateTimestamp = block.timestamp;
}

function query() public view override returns (uint256 value) {
function query() external view override returns (uint256 value) {
return emaStored;
}

Expand Down

0 comments on commit 9de3395

Please sign in to comment.