diff --git a/src/utils/SignedWadMath.sol b/src/utils/SignedWadMath.sol index c743a58f..b77e1db4 100644 --- a/src/utils/SignedWadMath.sol +++ b/src/utils/SignedWadMath.sol @@ -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 {