Skip to content

Commit

Permalink
✨ toDaysWadUnsafe/fromDaysWadUnsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
transmissions11 committed Sep 8, 2022
1 parent 3342f4f commit e10aa1b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/utils/SignedWadMath.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@ function toWadUnsafe(uint256 x) pure returns (int256 r) {
}
}

/// @dev Takes an integer amount of seconds and converts it to a wad amount of days.
/// @dev Will not revert on overflow, only use where overflow is not possible.
/// @dev Not meant for negative second amounts, it assumes x is positive.
function toDaysWadUnsafe(uint256 x) pure returns (int256 r) {
assembly {
// Multiply x by 1e18 and then divide it by 86400.
r := div(mul(x, 1000000000000000000), 86400)
}
}

/// @dev Takes a wad amount of days and converts it to an integer amount of seconds.
/// @dev Will not revert on overflow, only use where overflow is not possible.
/// @dev Not meant for negative day amounts, it assumes x is positive.
function fromDaysWadUnsafe(int256 x) pure returns (uint256 r) {
assembly {
// Multiply x by 86400 and then divide it by 1e18.
r := div(mul(x, 86400), 1000000000000000000)
}
}

/// @dev Will not revert on overflow, only use where overflow is not possible.
function unsafeWadMul(int256 x, int256 y) pure returns (int256 r) {
assembly {
Expand Down

0 comments on commit e10aa1b

Please sign in to comment.