solidity-math-utils 1.8.0 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solidity-math-utils",
3
- "version": "1.8.0",
3
+ "version": "1.10.0",
4
4
  "description": "Solidity Mathematical Utilities",
5
5
  "repository": {
6
6
  "type": "git",
@@ -9,7 +9,8 @@
9
9
  "author": "Barak Manos",
10
10
  "license": "SEE LICENSE IN https://raw.githubusercontent.com/bancorprotocol/contracts-solidity/master/LICENSE",
11
11
  "files": [
12
- "project/contracts/*.sol"
12
+ "project/contracts/*.sol",
13
+ "project/contracts/common/*.sol"
13
14
  ],
14
15
  "scripts": {
15
16
  "build": "hardhat compile",
@@ -19,8 +20,8 @@
19
20
  "devDependencies": {
20
21
  "@nomiclabs/hardhat-truffle5": "2.0.7",
21
22
  "@nomiclabs/hardhat-web3": "2.0.0",
22
- "decimal.js": "10.4.0",
23
- "hardhat": "2.11.1",
24
- "solidity-coverage": "0.8.1"
23
+ "decimal.js": "10.4.3",
24
+ "hardhat": "2.14.0",
25
+ "solidity-coverage": "0.8.2"
25
26
  }
26
27
  }
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: SEE LICENSE IN LICENSE
2
- pragma solidity 0.8.16;
2
+ pragma solidity 0.8.20;
3
3
 
4
4
  import "./AnalyticMath.sol";
5
5
  import "./FractionMath.sol";
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: SEE LICENSE IN LICENSE
2
- pragma solidity 0.8.16;
2
+ pragma solidity 0.8.20;
3
3
 
4
4
  import "./IntegralMath.sol";
5
5
 
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: SEE LICENSE IN LICENSE
2
- pragma solidity 0.8.16;
2
+ pragma solidity 0.8.20;
3
3
 
4
4
  import "./AnalyticMath.sol";
5
5
 
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: SEE LICENSE IN LICENSE
2
- pragma solidity 0.8.16;
2
+ pragma solidity 0.8.20;
3
3
 
4
4
  import "./AdvancedMath.sol";
5
5
 
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: SEE LICENSE IN LICENSE
2
- pragma solidity 0.8.16;
2
+ pragma solidity 0.8.20;
3
3
 
4
4
  import "./IntegralMath.sol";
5
5
 
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: SEE LICENSE IN LICENSE
2
- pragma solidity 0.8.16;
2
+ pragma solidity 0.8.20;
3
3
 
4
4
  import "./common/Uint.sol";
5
5
 
@@ -0,0 +1,34 @@
1
+ // SPDX-License-Identifier: SEE LICENSE IN LICENSE
2
+ pragma solidity 0.8.20;
3
+
4
+ uint256 constant MAX_VAL = type(uint256).max;
5
+
6
+ // reverts on overflow
7
+ function safeAdd(uint256 x, uint256 y) pure returns (uint256) {
8
+ return x + y;
9
+ }
10
+
11
+ // does not revert on overflow
12
+ function unsafeAdd(uint256 x, uint256 y) pure returns (uint256) { unchecked {
13
+ return x + y;
14
+ }}
15
+
16
+ // does not revert on overflow
17
+ function unsafeSub(uint256 x, uint256 y) pure returns (uint256) { unchecked {
18
+ return x - y;
19
+ }}
20
+
21
+ // does not revert on overflow
22
+ function unsafeMul(uint256 x, uint256 y) pure returns (uint256) { unchecked {
23
+ return x * y;
24
+ }}
25
+
26
+ // does not overflow
27
+ function mulModMax(uint256 x, uint256 y) pure returns (uint256) { unchecked {
28
+ return mulmod(x, y, MAX_VAL);
29
+ }}
30
+
31
+ // does not overflow
32
+ function mulMod(uint256 x, uint256 y, uint256 z) pure returns (uint256) { unchecked {
33
+ return mulmod(x, y, z);
34
+ }}