solidity-math-utils 3.0.0 → 3.1.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
@@ -38,6 +38,9 @@ This module implements the following interface:
38
38
  - `function floorCbrt(uint256 n)` => `(uint256)`
39
39
  - `function ceilCbrt(uint256 n)` => `(uint256)`
40
40
  - `function roundDiv(uint256 n, uint256 d)` => `(uint256)`
41
+ - `function minFactor(uint256 x, uint256 y)` => `(uint256)`
42
+ - `function mulShrF(uint256 x, uint256 y, uint8 s)` => `(uint256)`
43
+ - `function mulShrC(uint256 x, uint256 y, uint8 s)` => `(uint256)`
41
44
  - `function mulDivF(uint256 x, uint256 y, uint256 z)` => `(uint256)`
42
45
  - `function mulDivC(uint256 x, uint256 y, uint256 z)` => `(uint256)`
43
46
  - `function mulDivR(uint256 x, uint256 y, uint256 z)` => `(uint256)`
@@ -98,7 +101,7 @@ This module implements the following interface:
98
101
  - `function poweredRatioExact(uint256 n, uint256 d, uint256 exp)` => `(uint256, uint256)`
99
102
  - `function poweredRatioQuick(uint256 n, uint256 d, uint256 exp)` => `(uint256, uint256)`
100
103
  - `function productRatio(uint256 xn, uint256 yn, uint256 xd, uint256 yd)` => `(uint256, uint256)`
101
- - `function reducedRatio(uint256 n, uint256 d, uint256 max)` => `(uint256, uint256)`
104
+ - `function reducedRatio(uint256 n, uint256 d, uint256 cap)` => `(uint256, uint256)`
102
105
  - `function normalizedRatio(uint256 n, uint256 d, uint256 scale)` => `(uint256, uint256)`
103
106
 
104
107
  ### Powered Ratio
@@ -127,7 +130,7 @@ Note that function `reducedRatio` is not meant to replace GCD, nor does it striv
127
130
 
128
131
  GCD is not being used here, because the time-complexity of this method depends on the bit-length of the input.
129
132
 
130
- The worst case is when the two input valus are consecutive Fibonacci numbers, in the case of `uint256` - F369 and F370, which yield 367 iterations.
133
+ The worst case is when the two input values are consecutive Fibonacci numbers, in the case of `uint256` - F369 and F370, which yield 367 iterations.
131
134
 
132
135
  Moreover, the main issue with using GCD for reducing an arbitrary ratio, is the fact that it doesn't even guarantee the desired reduction to begin with.
133
136
 
@@ -210,7 +213,7 @@ Function `solveExact` opts for accuracy and function `solveQuick` opts for perfo
210
213
 
211
214
  Each one of these functions computes a value of x which satisfies the equation x * (a / b) ^ x = c / d.
212
215
 
213
- A detailed description of how each one of these functions works can be found [here](readme/AdvancedMath.pdf).
216
+ A detailed description of how each one of these functions works can be found [here](readme/AdvancedMath.md).
214
217
 
215
218
  ### Module Customization
216
219
 
@@ -308,7 +311,7 @@ Output:
308
311
  - Return x / (x + 1) as the weight of the primary reserve token
309
312
  - Return 1 / (x + 1) as the weight of the secondary reserve token
310
313
 
311
- A detailed reasoning of this method can be found [here](readme/DynamicCurve.pdf).
314
+ A detailed reasoning of this method can be found [here](readme/DynamicCurve.md).
312
315
 
313
316
  If the rate-provider provides the rates for a common unit, for example:
314
317
  - P = 2 ==> 2 primary reserve tokens = 1 ether
@@ -335,7 +338,7 @@ The dynamic-curve method was conceived by [Bancor](https://github.com/bancorprot
335
338
  ### Prerequisites
336
339
 
337
340
  - `node 22.21.0`
338
- - `pnpm 8.9.2`
341
+ - `pnpm 12.23.0`
339
342
 
340
343
  ### Installation
341
344
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solidity-math-utils",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "Solidity Mathematical Utilities",
5
5
  "repository": {
6
6
  "type": "git",
@@ -21,7 +21,7 @@
21
21
  "@nomiclabs/hardhat-truffle5": "2.1.0",
22
22
  "@nomiclabs/hardhat-web3": "2.1.0",
23
23
  "decimal.js": "10.6.0",
24
- "hardhat": "2.28.6",
24
+ "hardhat": "2.30.0",
25
25
  "solidity-coverage": "0.8.17"
26
26
  }
27
27
  }
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: SEE LICENSE IN LICENSE
2
- pragma solidity ^0.8.34;
2
+ pragma solidity ^0.8.39;
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.34;
2
+ pragma solidity ^0.8.39;
3
3
 
4
4
  import "./IntegralMath.sol";
5
5
 
@@ -57,8 +57,8 @@ library AnalyticMath {
57
57
  * log(x) =
58
58
  * log(x) + log(2 ^ k) - log(2 ^ k) =
59
59
  * log(x) - log(2 ^ k) + log(2 ^ k) =
60
- * log(x / log(2 ^ k)) + log(2 ^ k) =
61
- * log(x / log(2 ^ k)) + k * log(2)
60
+ * log(x / 2 ^ k) + log(2 ^ k) =
61
+ * log(x / 2 ^ k) + k * log(2)
62
62
  */
63
63
  function fixedLog(uint256 x) internal pure returns (uint256) { unchecked {
64
64
  if (x < FIXED_1)
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: SEE LICENSE IN LICENSE
2
- pragma solidity ^0.8.34;
2
+ pragma solidity ^0.8.39;
3
3
 
4
4
  import "./AnalyticMath.sol";
5
5
  import "./IntegralMath.sol";
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: SEE LICENSE IN LICENSE
2
- pragma solidity ^0.8.34;
2
+ pragma solidity ^0.8.39;
3
3
 
4
4
  import "./AdvancedMath.sol";
5
5
  import "./FractionMath.sol";
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: SEE LICENSE IN LICENSE
2
- pragma solidity ^0.8.34;
2
+ pragma solidity ^0.8.39;
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.34;
2
+ pragma solidity ^0.8.39;
3
3
 
4
4
  import "./common/Uint256.sol";
5
5
 
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: SEE LICENSE IN LICENSE
2
- pragma solidity ^0.8.34;
2
+ pragma solidity ^0.8.39;
3
3
 
4
4
  function unsafeAdd(uint256 x, uint256 y) pure returns (uint256) { unchecked {
5
5
  return x + y;