solidity-math-utils 2.1.1 → 2.2.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 +2 -2
- package/package.json +6 -6
- package/project/contracts/AdvancedMath.sol +1 -1
- package/project/contracts/AnalyticMath.sol +1 -1
- package/project/contracts/BondingCurve.sol +1 -1
- package/project/contracts/DynamicCurve.sol +1 -1
- package/project/contracts/FractionMath.sol +1 -1
- package/project/contracts/IntegralMath.sol +9 -21
- package/project/contracts/common/Uint256.sol +1 -1
package/README.md
CHANGED
|
@@ -321,8 +321,8 @@ The dynamic-curve method was conceived by [Bancor](https://github.com/bancorprot
|
|
|
321
321
|
|
|
322
322
|
### Prerequisites
|
|
323
323
|
|
|
324
|
-
- `node
|
|
325
|
-
- `yarn 1.22.22` or `npm 10.
|
|
324
|
+
- `node 22.21.0`
|
|
325
|
+
- `yarn 1.22.22` or `npm 10.9.4`
|
|
326
326
|
|
|
327
327
|
### Installation
|
|
328
328
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "solidity-math-utils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Solidity Mathematical Utilities",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
"verify": "hardhat coverage"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@nomiclabs/hardhat-truffle5": "2.0
|
|
22
|
-
"@nomiclabs/hardhat-web3": "2.
|
|
23
|
-
"decimal.js": "10.
|
|
24
|
-
"hardhat": "2.
|
|
25
|
-
"solidity-coverage": "0.8.
|
|
21
|
+
"@nomiclabs/hardhat-truffle5": "2.1.0",
|
|
22
|
+
"@nomiclabs/hardhat-web3": "2.1.0",
|
|
23
|
+
"decimal.js": "10.6.0",
|
|
24
|
+
"hardhat": "2.28.0",
|
|
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.
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
3
|
|
|
4
4
|
import "./common/Uint256.sol";
|
|
5
5
|
|
|
@@ -8,26 +8,11 @@ library IntegralMath {
|
|
|
8
8
|
* @dev Compute the largest integer smaller than or equal to the binary logarithm of `n`
|
|
9
9
|
*/
|
|
10
10
|
function floorLog2(uint256 n) internal pure returns (uint8) { unchecked {
|
|
11
|
-
uint8
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
// at most 8 iterations
|
|
15
|
-
while (n > 1) {
|
|
16
|
-
n >>= 1;
|
|
17
|
-
res += 1;
|
|
18
|
-
}
|
|
11
|
+
uint8 x = 0;
|
|
12
|
+
if (n > 0) {
|
|
13
|
+
assembly {x := not(clz(n))}
|
|
19
14
|
}
|
|
20
|
-
|
|
21
|
-
// exactly 8 iterations
|
|
22
|
-
for (uint8 s = 128; s > 0; s >>= 1) {
|
|
23
|
-
if (n >= 1 << s) {
|
|
24
|
-
n >>= s;
|
|
25
|
-
res |= s;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return res;
|
|
15
|
+
return x;
|
|
31
16
|
}}
|
|
32
17
|
|
|
33
18
|
/**
|
|
@@ -218,8 +203,11 @@ library IntegralMath {
|
|
|
218
203
|
uint8 zwhn = floorLog2(zwh);
|
|
219
204
|
while (xyhn > zwhn) {
|
|
220
205
|
uint8 n = xyhn - zwhn - 1;
|
|
206
|
+
uint256 zwhshl = zwh << n;
|
|
207
|
+
uint256 zwlshl = zwl << n;
|
|
208
|
+
uint256 zwlshr = zwl >> (256 - n);
|
|
221
209
|
res += 1 << n; // set `res = res + 2 ^ n`
|
|
222
|
-
(xyh, xyl) = sub512Ex(xyh, xyl,
|
|
210
|
+
(xyh, xyl) = sub512Ex(xyh, xyl, zwhshl | zwlshr, zwlshl); // set `xy = xy - zw * 2 ^ n`
|
|
223
211
|
xyhn = floorLog2(xyh);
|
|
224
212
|
}
|
|
225
213
|
}
|