2021-02-05 18:33:49 +00:00
|
|
|
pragma solidity ^0.6.5;
|
2020-11-20 14:49:48 +00:00
|
|
|
|
|
|
|
import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol";
|
|
|
|
|
|
|
|
contract DSMath {
|
|
|
|
uint constant WAD = 10 ** 18;
|
|
|
|
uint constant RAY = 10 ** 27;
|
|
|
|
|
|
|
|
function add(uint x, uint y) internal pure returns (uint z) {
|
|
|
|
z = SafeMath.add(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
function sub(uint x, uint y) internal virtual pure returns (uint z) {
|
|
|
|
z = SafeMath.sub(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
function mul(uint x, uint y) internal pure returns (uint z) {
|
|
|
|
z = SafeMath.mul(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
function div(uint x, uint y) internal pure returns (uint z) {
|
|
|
|
z = SafeMath.div(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
function wmul(uint x, uint y) internal pure returns (uint z) {
|
|
|
|
z = SafeMath.add(SafeMath.mul(x, y), WAD / 2) / WAD;
|
|
|
|
}
|
|
|
|
|
|
|
|
function wdiv(uint x, uint y) internal pure returns (uint z) {
|
|
|
|
z = SafeMath.add(SafeMath.mul(x, WAD), y / 2) / y;
|
|
|
|
}
|
|
|
|
|
|
|
|
function rdiv(uint x, uint y) internal pure returns (uint z) {
|
|
|
|
z = SafeMath.add(SafeMath.mul(x, RAY), y / 2) / y;
|
|
|
|
}
|
|
|
|
|
|
|
|
function rmul(uint x, uint y) internal pure returns (uint z) {
|
|
|
|
z = SafeMath.add(SafeMath.mul(x, y), RAY / 2) / RAY;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|