@1inch/solidity-utils 2.0.20 → 2.0.23

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.
@@ -3,18 +3,19 @@
3
3
  pragma solidity ^0.8.0;
4
4
  pragma abicoder v1;
5
5
 
6
+ import "./interfaces/IWETH.sol";
7
+
6
8
  abstract contract OnlyWethReceiver {
7
9
  error EthDepositRejected();
8
10
 
9
- // solhint-disable-next-line var-name-mixedcase
10
- address internal immutable _WETH;
11
+ IWETH internal immutable _WETH; // solhint-disable-line var-name-mixedcase
11
12
 
12
- constructor(address weth) {
13
+ constructor(IWETH weth) {
13
14
  _WETH = weth;
14
15
  }
15
16
 
16
17
  receive() external payable {
17
18
  // solhint-disable-next-line avoid-tx-origin
18
- if (msg.sender != _WETH) revert EthDepositRejected();
19
+ if (msg.sender != address(_WETH)) revert EthDepositRejected();
19
20
  }
20
21
  }
@@ -69,13 +69,7 @@ library UniERC20 {
69
69
  function uniApprove(IERC20 token, address to, uint256 amount) internal {
70
70
  if (isETH(token)) revert ApproveCalledOnETH();
71
71
 
72
- // solhint-disable-next-line avoid-low-level-calls
73
- (bool success, bytes memory returndata) = address(token).call(abi.encodeWithSelector(token.approve.selector, to, amount));
74
-
75
- if (!success || (returndata.length > 0 && !abi.decode(returndata, (bool)))) {
76
- _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, to, 0));
77
- _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, to, amount));
78
- }
72
+ token.forceApprove(to, amount);
79
73
  }
80
74
 
81
75
  function _uniDecode(IERC20 token, string memory lowerCaseSignature, string memory upperCaseSignature) private view returns(string memory) {
@@ -100,34 +94,19 @@ library UniERC20 {
100
94
  }
101
95
 
102
96
  if (success && data.length == 32) {
103
- uint len = 0;
97
+ uint256 len = 0;
104
98
  while (len < data.length && data[len] >= 0x20 && data[len] <= 0x7E) {
105
99
  len++;
106
100
  }
107
101
 
108
102
  if (len > 0) {
109
- bytes memory result = new bytes(len);
110
- unchecked {
111
- for (uint i = 0; i < len; i++) {
112
- result[i] = data[i];
113
- }
103
+ assembly { // solhint-disable-line no-inline-assembly
104
+ mstore(data, len)
114
105
  }
115
- return string(result);
106
+ return string(data);
116
107
  }
117
108
  }
118
109
 
119
110
  return StringUtil.toHex(address(token));
120
111
  }
121
-
122
- function _callOptionalReturn(IERC20 token, bytes memory data) private {
123
- // solhint-disable-next-line avoid-low-level-calls
124
- (bool success, bytes memory result) = address(token).call(data);
125
- if (!success) {
126
- RevertReasonForwarder.reRevert();
127
- }
128
-
129
- if (result.length > 0) { // Return data is optional
130
- if (!abi.decode(result, (bool))) revert ERC20OperationFailed();
131
- }
132
- }
133
112
  }
@@ -0,0 +1,31 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity ^0.8.0;
4
+
5
+ import "@openzeppelin/contracts/access/Ownable.sol";
6
+ import "@openzeppelin/contracts/token/ERC20/extensions/draft-ERC20Permit.sol";
7
+
8
+ contract TokenCustomDecimalsMock is ERC20Permit, Ownable {
9
+ uint8 internal immutable _decimals;
10
+
11
+ constructor(string memory name, string memory symbol, uint256 amount, uint8 decimals_) ERC20(name, symbol) ERC20Permit(name) {
12
+ _mint(msg.sender, amount);
13
+ _decimals = decimals_;
14
+ }
15
+
16
+ function mint(address account, uint256 amount) external onlyOwner {
17
+ _mint(account, amount);
18
+ }
19
+
20
+ function burn(address account, uint256 amount) external onlyOwner {
21
+ _burn(account, amount);
22
+ }
23
+
24
+ function decimals() public view virtual override returns (uint8) {
25
+ return _decimals;
26
+ }
27
+
28
+ function getChainId() external view returns(uint256) {
29
+ return block.chainid;
30
+ }
31
+ }
@@ -0,0 +1,21 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity ^0.8.0;
4
+ pragma abicoder v1;
5
+
6
+ import "@openzeppelin/contracts/access/Ownable.sol";
7
+ import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
8
+
9
+
10
+ contract TokenMock is ERC20, Ownable {
11
+ // solhint-disable-next-line no-empty-blocks
12
+ constructor(string memory name, string memory symbol) ERC20(name, symbol) {}
13
+
14
+ function mint(address account, uint256 amount) external onlyOwner {
15
+ _mint(account, amount);
16
+ }
17
+
18
+ function burn(address account, uint256 amount) external onlyOwner {
19
+ _burn(account, amount);
20
+ }
21
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1inch/solidity-utils",
3
- "version": "2.0.20",
3
+ "version": "2.0.23",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "repository": {
@@ -87,6 +87,7 @@
87
87
  "./utils",
88
88
  "contracts/*.sol",
89
89
  "contracts/interfaces",
90
- "contracts/libraries"
90
+ "contracts/libraries",
91
+ "contracts/mocks"
91
92
  ]
92
93
  }