Skip to content

Commit

Permalink
Merge bdc767e into 7d42437
Browse files Browse the repository at this point in the history
  • Loading branch information
kamescg committed Oct 6, 2021
2 parents 7d42437 + bdc767e commit c25b8b2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
15 changes: 15 additions & 0 deletions contracts/libraries/ExtendedSafeCastLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,19 @@ library ExtendedSafeCastLib {
require(value <= type(uint208).max, "SafeCast: value doesn't fit in 208 bits");
return uint208(value);
}

/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
return uint224(value);
}
}
8 changes: 4 additions & 4 deletions contracts/libraries/TwabLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -364,15 +364,15 @@ library TwabLib {
*/
function _computeNextTwab(
ObservationLib.Observation memory _currentTwab,
uint256 _currentBalance,
uint224 _currentBalance,
uint32 _time
) private pure returns (ObservationLib.Observation memory) {
// New twab amount = last twab amount (or zero) + (current amount * elapsed seconds)
return
ObservationLib.Observation({
amount: (uint256(_currentTwab.amount) +
(_currentBalance * (_time.checkedSub(_currentTwab.timestamp, _time))))
.toUint208(),
amount: _currentTwab.amount +
_currentBalance *
(_time.checkedSub(_currentTwab.timestamp, _time)),
timestamp: _time
});
}
Expand Down

0 comments on commit c25b8b2

Please sign in to comment.