solidity-math-utils 1.5.0 → 1.7.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
@@ -345,8 +345,8 @@ The dynamic-curve method was conceived by [Bancor](https://github.com/bancorprot
345
345
 
346
346
  ### Prerequisites
347
347
 
348
- - `node 12.20.0`
349
- - `yarn 1.22.10` or `npm 7.12.0`
348
+ - `node 16.13.0`
349
+ - `yarn 1.22.10` or `npm 8.1.0`
350
350
 
351
351
  ### Installation
352
352
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solidity-math-utils",
3
- "version": "1.5.0",
3
+ "version": "1.7.0",
4
4
  "description": "Solidity Mathematical Utilities",
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,14 +12,15 @@
12
12
  "project/contracts/*.sol"
13
13
  ],
14
14
  "scripts": {
15
- "build": "truffle compile",
16
- "test": "truffle test --bail",
17
- "verify": "truffle run coverage"
15
+ "build": "hardhat compile",
16
+ "test": "hardhat test --bail",
17
+ "verify": "hardhat coverage"
18
18
  },
19
19
  "devDependencies": {
20
+ "@nomiclabs/hardhat-truffle5": "2.0.6",
21
+ "@nomiclabs/hardhat-web3": "2.0.0",
20
22
  "decimal.js": "10.3.1",
21
- "solidity-coverage": "0.7.16",
22
- "truffle": "5.4.0",
23
- "web3": "1.4.0"
23
+ "hardhat": "2.9.6",
24
+ "solidity-coverage": "0.7.21"
24
25
  }
25
26
  }
@@ -1,12 +1,10 @@
1
1
  // SPDX-License-Identifier: SEE LICENSE IN LICENSE
2
- pragma solidity 0.8.10;
2
+ pragma solidity 0.8.14;
3
3
 
4
4
  import "./AnalyticMath.sol";
5
5
  import "./FractionMath.sol";
6
6
 
7
7
  contract AdvancedMath is AnalyticMath {
8
- using FractionMath for *;
9
-
10
8
  // Auto-generated via 'PrintLambertFactors.py'
11
9
  uint256 internal constant LAMBERT_CONV_RADIUS = 0x002f16ac6c59de6f8d5d6f63c1482a7c86;
12
10
  uint256 internal constant LAMBERT_POS2_SAMPLE = 0x0003060c183060c183060c183060c18306;
@@ -1,11 +1,9 @@
1
1
  // SPDX-License-Identifier: SEE LICENSE IN LICENSE
2
- pragma solidity 0.8.10;
2
+ pragma solidity 0.8.14;
3
3
 
4
4
  import "./IntegralMath.sol";
5
5
 
6
6
  contract AnalyticMath {
7
- using IntegralMath for *;
8
-
9
7
  uint8 internal constant MIN_PRECISION = 32;
10
8
  uint8 internal constant MAX_PRECISION = 127;
11
9
 
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: SEE LICENSE IN LICENSE
2
- pragma solidity 0.8.10;
2
+ pragma solidity 0.8.14;
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.10;
2
+ pragma solidity 0.8.14;
3
3
 
4
4
  import "./AdvancedMath.sol";
5
5
 
@@ -1,11 +1,9 @@
1
1
  // SPDX-License-Identifier: SEE LICENSE IN LICENSE
2
- pragma solidity 0.8.10;
2
+ pragma solidity 0.8.14;
3
3
 
4
4
  import "./IntegralMath.sol";
5
5
 
6
6
  library FractionMath {
7
- using IntegralMath for *;
8
-
9
7
  uint256 internal constant MAX_EXP_BIT_LEN = 4;
10
8
  uint256 internal constant MAX_EXP = 2 ** MAX_EXP_BIT_LEN - 1;
11
9
  uint256 internal constant MAX_UINT128 = type(uint128).max;
@@ -111,13 +109,13 @@ library FractionMath {
111
109
  * @return The estimated ratio denominator
112
110
  */
113
111
  function estimatedRatio(uint256 n, uint256 d, uint256 scale) private pure returns (uint256, uint256) { unchecked {
114
- uint256 x = MAX_VAL / scale; // `MAX_VAL >= scale` hence `x >= 1`
115
- if (x < n) {
116
- // `x < n <= MAX_VAL` hence `x < MAX_VAL` hence `x + 1` is safe
117
- // `x >= 1` hence `n / (x + 1) < MAX_VAL` hence `n / (x + 1) + 1` is safe
118
- uint256 y = n / (x + 1) + 1;
119
- n /= y; // we can now safely compute `n * scale`
112
+ uint256 x = MAX_VAL / scale;
113
+ if (n > x) {
114
+ // `n * scale` will overflow
115
+ uint256 y = (n - 1) / x + 1;
116
+ n /= y;
120
117
  d /= y;
118
+ // `n * scale` will not overflow
121
119
  }
122
120
 
123
121
  if (n < d) {
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: SEE LICENSE IN LICENSE
2
- pragma solidity 0.8.10;
2
+ pragma solidity 0.8.14;
3
3
 
4
4
  import "./common/Uint.sol";
5
5