mirror of
				https://github.com/Instadapp/dsa-connectors-2.0.git
				synced 2024-07-29 21:57:39 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			56 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Solidity
		
	
	
	
	
	
			
		
		
	
	
			56 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Solidity
		
	
	
	
	
	
| //SPDX-License-Identifier: MIT
 | |
| pragma solidity ^0.8.2;
 | |
| 
 | |
| import {SafeMath} from "@openzeppelin/contracts/utils/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 pure virtual 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;
 | |
|     }
 | |
| 
 | |
|     function toInt(uint x) internal pure returns (int y) {
 | |
|         y = int(x);
 | |
|         require(y >= 0, "int-overflow");
 | |
|     }
 | |
| 
 | |
|     function toUint(int256 x) internal pure returns (uint256) {
 | |
|         require(x >= 0, "int-overflow");
 | |
|         return uint256(x);
 | |
|     }
 | |
| 
 | |
|     function toRad(uint wad) internal pure returns (uint rad) {
 | |
|         rad = mul(wad, 10 ** 27);
 | |
|     }
 | |
| }
 | 
