@1inch/solidity-utils 2.0.11-test6 → 2.0.13
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/contracts/EthReceiver.sol +3 -1
- package/contracts/GasChecker.sol +4 -8
- package/contracts/OnlyWethReceiver.sol +20 -0
- package/contracts/Permitable.sol +6 -5
- package/contracts/libraries/AddressArray.sol +23 -17
- package/contracts/libraries/AddressSet.sol +5 -3
- package/contracts/libraries/RevertReasonForwarder.sol +14 -0
- package/contracts/libraries/RevertReasonParser.sol +6 -4
- package/contracts/libraries/UniERC20.sol +12 -6
- package/dist/src/index.js +5 -5
- package/dist/src/index.js.map +1 -1
- package/dist/src/prelude.js +2 -2
- package/dist/src/prelude.js.map +1 -1
- package/package.json +14 -16
|
@@ -4,8 +4,10 @@ pragma solidity ^0.8.0;
|
|
|
4
4
|
pragma abicoder v1;
|
|
5
5
|
|
|
6
6
|
abstract contract EthReceiver {
|
|
7
|
+
error EthDepositRejected();
|
|
8
|
+
|
|
7
9
|
receive() external payable {
|
|
8
10
|
// solhint-disable-next-line avoid-tx-origin
|
|
9
|
-
|
|
11
|
+
if (msg.sender == tx.origin) revert EthDepositRejected();
|
|
10
12
|
}
|
|
11
13
|
}
|
package/contracts/GasChecker.sol
CHANGED
|
@@ -3,17 +3,13 @@
|
|
|
3
3
|
pragma solidity ^0.8.0;
|
|
4
4
|
pragma abicoder v1;
|
|
5
5
|
|
|
6
|
-
import "@openzeppelin/contracts/utils/Strings.sol";
|
|
7
|
-
|
|
8
6
|
contract GasChecker {
|
|
9
|
-
|
|
7
|
+
error GasCostDiffers(uint256 expected, uint256 actual);
|
|
10
8
|
|
|
11
|
-
modifier checkGasCost(uint256
|
|
9
|
+
modifier checkGasCost(uint256 expected) {
|
|
12
10
|
uint256 gas = gasleft();
|
|
13
11
|
_;
|
|
14
|
-
gas -= gasleft();
|
|
15
|
-
if (
|
|
16
|
-
require (gas == expectedGasCost, string(abi.encodePacked("Gas cost differs: expected ", expectedGasCost.toString(), ", actual: ", gas.toString())));
|
|
17
|
-
}
|
|
12
|
+
unchecked { gas -= gasleft(); }
|
|
13
|
+
if (expected > 0 && gas != expected) revert GasCostDiffers(expected, gas);
|
|
18
14
|
}
|
|
19
15
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
|
|
3
|
+
pragma solidity ^0.8.0;
|
|
4
|
+
pragma abicoder v1;
|
|
5
|
+
|
|
6
|
+
abstract contract OnlyWethReceiver {
|
|
7
|
+
error EthDepositRejected();
|
|
8
|
+
|
|
9
|
+
// solhint-disable-next-line var-name-mixedcase
|
|
10
|
+
address internal immutable _WETH;
|
|
11
|
+
|
|
12
|
+
constructor(address weth) {
|
|
13
|
+
_WETH = weth;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
receive() external payable {
|
|
17
|
+
// solhint-disable-next-line avoid-tx-origin
|
|
18
|
+
if (msg.sender != _WETH) revert EthDepositRejected();
|
|
19
|
+
}
|
|
20
|
+
}
|
package/contracts/Permitable.sol
CHANGED
|
@@ -5,25 +5,26 @@ pragma abicoder v1;
|
|
|
5
5
|
|
|
6
6
|
import "@openzeppelin/contracts/token/ERC20/extensions/draft-IERC20Permit.sol";
|
|
7
7
|
import "./interfaces/IDaiLikePermit.sol";
|
|
8
|
+
import "./libraries/RevertReasonForwarder.sol";
|
|
8
9
|
|
|
9
10
|
contract Permitable {
|
|
10
11
|
error BadPermitLength();
|
|
11
|
-
error PermitFailed();
|
|
12
12
|
|
|
13
13
|
function _permit(address token, bytes calldata permit) internal virtual {
|
|
14
14
|
if (permit.length > 0) {
|
|
15
15
|
bool success;
|
|
16
|
-
bytes memory result;
|
|
17
16
|
if (permit.length == 32 * 7) {
|
|
18
17
|
// solhint-disable-next-line avoid-low-level-calls
|
|
19
|
-
(success,
|
|
18
|
+
(success,) = token.call(abi.encodePacked(IERC20Permit.permit.selector, permit));
|
|
20
19
|
} else if (permit.length == 32 * 8) {
|
|
21
20
|
// solhint-disable-next-line avoid-low-level-calls
|
|
22
|
-
(success,
|
|
21
|
+
(success,) = token.call(abi.encodePacked(IDaiLikePermit.permit.selector, permit));
|
|
23
22
|
} else {
|
|
24
23
|
revert BadPermitLength();
|
|
25
24
|
}
|
|
26
|
-
if (!success)
|
|
25
|
+
if (!success) {
|
|
26
|
+
RevertReasonForwarder.reRevert();
|
|
27
|
+
}
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
}
|
|
@@ -35,33 +35,39 @@ library AddressArray {
|
|
|
35
35
|
if (len > output.length) revert OutputArrayTooSmall();
|
|
36
36
|
if (len > 0) {
|
|
37
37
|
output[0] = address(uint160(lengthAndFirst));
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
unchecked {
|
|
39
|
+
for (uint i = 1; i < len; i++) {
|
|
40
|
+
output[i] = address(uint160(self._raw[i]));
|
|
41
|
+
}
|
|
40
42
|
}
|
|
41
43
|
}
|
|
42
44
|
return output;
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
function push(Data storage self, address account) internal returns(uint256) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
48
|
+
unchecked {
|
|
49
|
+
uint256 lengthAndFirst = self._raw[0];
|
|
50
|
+
uint256 len = lengthAndFirst >> 160;
|
|
51
|
+
if (len == 0) {
|
|
52
|
+
self._raw[0] = (1 << 160) + uint160(account);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
self._raw[0] = lengthAndFirst + (1 << 160);
|
|
56
|
+
self._raw[len] = uint160(account);
|
|
57
|
+
}
|
|
58
|
+
return len + 1;
|
|
54
59
|
}
|
|
55
|
-
return len + 1;
|
|
56
60
|
}
|
|
57
61
|
|
|
58
62
|
function pop(Data storage self) internal {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
unchecked {
|
|
64
|
+
uint256 lengthAndFirst = self._raw[0];
|
|
65
|
+
uint256 len = lengthAndFirst >> 160;
|
|
66
|
+
if (len == 0) revert PopFromEmptyArray();
|
|
67
|
+
self._raw[len - 1] = 0;
|
|
68
|
+
if (len > 1) {
|
|
69
|
+
self._raw[0] = lengthAndFirst - (1 << 160);
|
|
70
|
+
}
|
|
65
71
|
}
|
|
66
72
|
}
|
|
67
73
|
|
|
@@ -39,9 +39,11 @@ library AddressSet {
|
|
|
39
39
|
return false;
|
|
40
40
|
}
|
|
41
41
|
if (index < s.items.length()) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
unchecked {
|
|
43
|
+
address lastItem = s.items.at(s.items.length() - 1);
|
|
44
|
+
s.items.set(index - 1, lastItem);
|
|
45
|
+
s.lookup[lastItem] = index;
|
|
46
|
+
}
|
|
45
47
|
}
|
|
46
48
|
s.items.pop();
|
|
47
49
|
delete s.lookup[item];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
|
|
3
|
+
pragma solidity ^0.8.0;
|
|
4
|
+
pragma abicoder v1;
|
|
5
|
+
|
|
6
|
+
library RevertReasonForwarder {
|
|
7
|
+
function reRevert() internal pure {
|
|
8
|
+
// bubble up revert reason from latest external call
|
|
9
|
+
assembly { // solhint-disable-line no-inline-assembly
|
|
10
|
+
returndatacopy(0, 0, returndatasize())
|
|
11
|
+
revert(0, returndatasize())
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -16,6 +16,8 @@ library RevertReasonParser {
|
|
|
16
16
|
using StringUtil for uint256;
|
|
17
17
|
using StringUtil for bytes;
|
|
18
18
|
|
|
19
|
+
error InvalidRevertReason();
|
|
20
|
+
|
|
19
21
|
bytes4 constant private _ERROR_SELECTOR = bytes4(keccak256("Error(string)"));
|
|
20
22
|
bytes4 constant private _PANIC_SELECTOR = bytes4(keccak256("Panic(uint256)"));
|
|
21
23
|
|
|
@@ -42,8 +44,8 @@ library RevertReasonParser {
|
|
|
42
44
|
because of that we can't check for equality and instead check
|
|
43
45
|
that string length + extra 68 bytes is less than overall data length
|
|
44
46
|
*/
|
|
45
|
-
|
|
46
|
-
return string
|
|
47
|
+
if (data.length < 68 + bytes(reason).length) revert InvalidRevertReason();
|
|
48
|
+
return string.concat(prefix, "Error(", reason, ")");
|
|
47
49
|
}
|
|
48
50
|
// 36 = 4-byte selector + 32 bytes integer
|
|
49
51
|
else if (selector == _PANIC_SELECTOR && data.length == 36) {
|
|
@@ -53,8 +55,8 @@ library RevertReasonParser {
|
|
|
53
55
|
// 36 = 32 bytes data length + 4-byte selector
|
|
54
56
|
code := mload(add(data, 36))
|
|
55
57
|
}
|
|
56
|
-
return string
|
|
58
|
+
return string.concat(prefix, "Panic(", code.toHex(), ")");
|
|
57
59
|
}
|
|
58
|
-
return string
|
|
60
|
+
return string.concat(prefix, "Unknown(", data.toHex(), ")");
|
|
59
61
|
}
|
|
60
62
|
}
|
|
@@ -13,6 +13,10 @@ library UniERC20 {
|
|
|
13
13
|
using SafeMath for uint256;
|
|
14
14
|
using SafeERC20 for IERC20;
|
|
15
15
|
|
|
16
|
+
error NotEnoughValue();
|
|
17
|
+
error FromIsNotSender();
|
|
18
|
+
error ToIsNotThis();
|
|
19
|
+
|
|
16
20
|
IERC20 private constant _ETH_ADDRESS = IERC20(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE);
|
|
17
21
|
IERC20 private constant _ZERO_ADDRESS = IERC20(address(0));
|
|
18
22
|
|
|
@@ -41,9 +45,9 @@ library UniERC20 {
|
|
|
41
45
|
function uniTransferFrom(IERC20 token, address payable from, address to, uint256 amount) internal {
|
|
42
46
|
if (amount > 0) {
|
|
43
47
|
if (isETH(token)) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
48
|
+
if (msg.value < amount) revert NotEnoughValue();
|
|
49
|
+
if (from != msg.sender) revert FromIsNotSender();
|
|
50
|
+
if (to != address(this)) revert ToIsNotThis();
|
|
47
51
|
if (msg.value > amount) {
|
|
48
52
|
// Return remainder if exist
|
|
49
53
|
from.transfer(msg.value.sub(amount));
|
|
@@ -91,7 +95,7 @@ library UniERC20 {
|
|
|
91
95
|
if (success && data.length >= 96) {
|
|
92
96
|
(uint256 offset, uint256 len) = abi.decode(data, (uint256, uint256));
|
|
93
97
|
if (offset == 0x20 && len > 0 && len <= 256) {
|
|
94
|
-
return
|
|
98
|
+
return abi.decode(data, (string));
|
|
95
99
|
}
|
|
96
100
|
}
|
|
97
101
|
|
|
@@ -103,8 +107,10 @@ library UniERC20 {
|
|
|
103
107
|
|
|
104
108
|
if (len > 0) {
|
|
105
109
|
bytes memory result = new bytes(len);
|
|
106
|
-
|
|
107
|
-
|
|
110
|
+
unchecked {
|
|
111
|
+
for (uint i = 0; i < len; i++) {
|
|
112
|
+
result[i] = data[i];
|
|
113
|
+
}
|
|
108
114
|
}
|
|
109
115
|
return string(result);
|
|
110
116
|
}
|
package/dist/src/index.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// created from 'create-ts-index'
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
tslib_1.__exportStar(require("./asserts"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./permit"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./prelude"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./profileEVM"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./utils"), exports);
|
|
10
10
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,iCAAiC;;;AAEjC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,iCAAiC;;;AAEjC,oDAA0B;AAC1B,mDAAyB;AACzB,oDAA0B;AAC1B,uDAA6B;AAC7B,kDAAwB"}
|
package/dist/src/prelude.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.should = exports.config = exports.expect = exports.assert = exports.AssertionError = exports.Assertion = exports.ether = exports.time = exports.toBN = exports.constants = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const chai_1 =
|
|
5
|
+
const chai_1 = tslib_1.__importStar(require("chai"));
|
|
6
6
|
Object.defineProperty(exports, "Assertion", { enumerable: true, get: function () { return chai_1.Assertion; } });
|
|
7
7
|
Object.defineProperty(exports, "AssertionError", { enumerable: true, get: function () { return chai_1.AssertionError; } });
|
|
8
8
|
Object.defineProperty(exports, "assert", { enumerable: true, get: function () { return chai_1.assert; } });
|
|
@@ -10,7 +10,7 @@ Object.defineProperty(exports, "expect", { enumerable: true, get: function () {
|
|
|
10
10
|
Object.defineProperty(exports, "config", { enumerable: true, get: function () { return chai_1.config; } });
|
|
11
11
|
Object.defineProperty(exports, "should", { enumerable: true, get: function () { return chai_1.should; } });
|
|
12
12
|
require("chai-bn");
|
|
13
|
-
const chai_as_promised_1 =
|
|
13
|
+
const chai_as_promised_1 = tslib_1.__importDefault(require("chai-as-promised"));
|
|
14
14
|
const web3_utils_1 = require("web3-utils");
|
|
15
15
|
Object.defineProperty(exports, "toBN", { enumerable: true, get: function () { return web3_utils_1.toBN; } });
|
|
16
16
|
chai_1.default.use(chai_as_promised_1.default);
|
package/dist/src/prelude.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prelude.js","sourceRoot":"","sources":["../../src/prelude.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"prelude.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AK,EAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;AACnC,CAAC;AAFD,sBAEC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1inch/solidity-utils",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.13",
|
|
4
4
|
"main": "dist/src/index.js",
|
|
5
5
|
"types": "dist/src/index.d.ts",
|
|
6
6
|
"repository": {
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
"lint:ts:fix": "eslint . --fix --ext .ts",
|
|
21
21
|
"lint:sol": "solhint --max-warnings 0 \"contracts/**/*.sol\"",
|
|
22
22
|
"lint:sol:fix": "solhint --max-warnings 0 \"contracts/**/*.sol\" --fix",
|
|
23
|
-
"test": "hardhat test",
|
|
23
|
+
"test": "hardhat test --parallel",
|
|
24
|
+
"test:ci": "hardhat test",
|
|
24
25
|
"typecheck": "tsc --noEmit --skipLibCheck",
|
|
25
26
|
"typechain": "hardhat typechain"
|
|
26
27
|
},
|
|
@@ -33,41 +34,38 @@
|
|
|
33
34
|
"chai-as-promised": "7.1.1",
|
|
34
35
|
"chai-bn": "0.3.1",
|
|
35
36
|
"ethereumjs-util": "7.1.4",
|
|
36
|
-
"web3-utils": "1.7.
|
|
37
|
+
"web3-utils": "1.7.1"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
39
|
-
"@nomiclabs/hardhat-
|
|
40
|
-
"@nomiclabs/hardhat-truffle5": "2.0.4",
|
|
40
|
+
"@nomiclabs/hardhat-truffle5": "2.0.5",
|
|
41
41
|
"@nomiclabs/hardhat-web3": "2.0.0",
|
|
42
|
-
"@typechain/hardhat": "
|
|
42
|
+
"@typechain/hardhat": "6.0.0",
|
|
43
43
|
"@typechain/truffle-v5": "7.0.0",
|
|
44
44
|
"@types/chai": "4.3.0",
|
|
45
45
|
"@types/chai-as-promised": "7.1.5",
|
|
46
46
|
"@types/mocha": "9.1.0",
|
|
47
|
-
"@types/node": "17.0.
|
|
48
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
49
|
-
"@typescript-eslint/parser": "5.
|
|
47
|
+
"@types/node": "17.0.23",
|
|
48
|
+
"@typescript-eslint/eslint-plugin": "5.18.0",
|
|
49
|
+
"@typescript-eslint/parser": "5.18.0",
|
|
50
50
|
"create-ts-index": "^1.14.0",
|
|
51
51
|
"cross-spawn": "7.0.3",
|
|
52
52
|
"dotenv": "16.0.0",
|
|
53
|
-
"eslint": "8.
|
|
53
|
+
"eslint": "8.12.0",
|
|
54
54
|
"eslint-config-standard": "16.0.3",
|
|
55
|
-
"eslint-plugin-import": "2.
|
|
55
|
+
"eslint-plugin-import": "2.26.0",
|
|
56
56
|
"eslint-plugin-node": "11.1.0",
|
|
57
57
|
"eslint-plugin-promise": "6.0.0",
|
|
58
58
|
"eslint-plugin-standard": "5.0.0",
|
|
59
59
|
"eslint-plugin-typescript": "0.14.0",
|
|
60
|
-
"hardhat": "2.
|
|
61
|
-
"hardhat-deploy": "0.10.5",
|
|
60
|
+
"hardhat": "2.9.3",
|
|
62
61
|
"hardhat-gas-reporter": "1.0.8",
|
|
63
62
|
"rimraf": "3.0.2",
|
|
64
63
|
"shx": "0.3.4",
|
|
65
|
-
"solc": "0.8.11",
|
|
66
64
|
"solhint": "3.3.7",
|
|
67
65
|
"solidity-coverage": "0.7.20",
|
|
68
|
-
"ts-node": "10.
|
|
66
|
+
"ts-node": "10.7.0",
|
|
69
67
|
"typechain": "7.0.0",
|
|
70
|
-
"typescript": "4.
|
|
68
|
+
"typescript": "4.6.3"
|
|
71
69
|
},
|
|
72
70
|
"bin": {
|
|
73
71
|
"solidity-utils-docify": "utils/docify.utils.js"
|