solidity-math-utils 1.7.0 → 1.9.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/README.md CHANGED
@@ -5,7 +5,7 @@ This package consists of the following modules:
5
5
  - [FractionMath](#fractionmath) - a set of functions, each of which returning a rational result
6
6
  - [AnalyticMath](#analyticmath) - a set of exponential and logarithmic functions
7
7
  - [AdvancedMath](#advancedmath) - a function for solving xA^x = B, given rational values of A and B
8
- - [BodningCurve](#bodningcurve) - a set of functions implementing the bonding-curve mechanism
8
+ - [BondingCurve](#bondingcurve) - a set of functions implementing the bonding-curve mechanism
9
9
  - [DynamicCurve](#dynamiccurve) - a function for equalizing the weights in a bonding-curve model
10
10
 
11
11
  ### Class Hierarchy
@@ -20,7 +20,7 @@ AnalyticMath < - - - - AdvancedMath
20
20
  | |
21
21
  | |
22
22
  | |
23
- BodningCurve DynamicCurve
23
+ BondingCurve DynamicCurve
24
24
  ```
25
25
 
26
26
  Note that some of these modules are implemented as `library`, while others are implemented as `contract`.
@@ -231,7 +231,7 @@ The full customization manual can be found [here](#customization).
231
231
 
232
232
  <br/><br/>
233
233
 
234
- ## BodningCurve
234
+ ## BondingCurve
235
235
 
236
236
  This module is implemented as a contract, because a library cannot extend (inherit) a contract.
237
237
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solidity-math-utils",
3
- "version": "1.7.0",
3
+ "version": "1.9.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",
@@ -17,10 +18,10 @@
17
18
  "verify": "hardhat coverage"
18
19
  },
19
20
  "devDependencies": {
20
- "@nomiclabs/hardhat-truffle5": "2.0.6",
21
+ "@nomiclabs/hardhat-truffle5": "2.0.7",
21
22
  "@nomiclabs/hardhat-web3": "2.0.0",
22
- "decimal.js": "10.3.1",
23
- "hardhat": "2.9.6",
24
- "solidity-coverage": "0.7.21"
23
+ "decimal.js": "10.4.3",
24
+ "hardhat": "2.12.4",
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.14;
2
+ pragma solidity 0.8.17;
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.14;
2
+ pragma solidity 0.8.17;
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.14;
2
+ pragma solidity 0.8.17;
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.14;
2
+ pragma solidity 0.8.17;
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.14;
2
+ pragma solidity 0.8.17;
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.14;
2
+ pragma solidity 0.8.17;
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.17;
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
+ }}