dsa-connectors-old/contracts/common/math.sol

42 lines
1.1 KiB
Solidity
Raw Permalink Normal View History

2020-05-02 09:40:50 +00:00
pragma solidity ^0.6.0;
import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol";
2020-05-02 09:40:50 +00:00
contract DSMath {
uint constant WAD = 10 ** 18;
uint constant RAY = 10 ** 27;
2020-05-02 09:40:50 +00:00
function add(uint x, uint y) internal pure returns (uint z) {
2020-07-02 04:56:47 +00:00
z = SafeMath.add(x, y);
}
2020-05-02 09:40:50 +00:00
function sub(uint x, uint y) internal virtual pure returns (uint z) {
2020-07-02 04:56:47 +00:00
z = SafeMath.sub(x, y);
}
2020-05-05 01:54:10 +00:00
function mul(uint x, uint y) internal pure returns (uint z) {
2020-07-02 04:56:47 +00:00
z = SafeMath.mul(x, y);
}
2020-05-02 09:40:50 +00:00
function div(uint x, uint y) internal pure returns (uint z) {
2020-07-02 04:56:47 +00:00
z = SafeMath.div(x, y);
}
2020-05-02 09:40:50 +00:00
function wmul(uint x, uint y) internal pure returns (uint z) {
z = SafeMath.add(SafeMath.mul(x, y), WAD / 2) / WAD;
}
2020-05-02 09:40:50 +00:00
function wdiv(uint x, uint y) internal pure returns (uint z) {
z = SafeMath.add(SafeMath.mul(x, WAD), y / 2) / y;
}
2020-05-02 09:40:50 +00:00
function rdiv(uint x, uint y) internal pure returns (uint z) {
z = SafeMath.add(SafeMath.mul(x, RAY), y / 2) / y;
}
2020-05-02 14:33:39 +00:00
function rmul(uint x, uint y) internal pure returns (uint z) {
z = SafeMath.add(SafeMath.mul(x, y), RAY / 2) / RAY;
}
2020-05-02 14:33:39 +00:00
}