@1inch/solidity-utils 2.2.25 → 2.2.27

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.
@@ -23,6 +23,25 @@ library SafeERC20 {
23
23
  bytes4 private constant _PERMIT_LENGTH_ERROR = 0x68275857; // SafePermitBadLength.selector
24
24
  uint256 private constant _RAW_CALL_GAS_LIMIT = 5000;
25
25
 
26
+ function safeBalanceOf(
27
+ IERC20 token,
28
+ address account
29
+ ) internal view returns(uint256 tokenBalance) {
30
+ bytes4 selector = IERC20.balanceOf.selector;
31
+ assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
32
+ mstore(0x00, selector)
33
+ mstore(0x04, account)
34
+ let success := staticcall(gas(), token, 0x00, 0x24, 0x00, 0x20)
35
+ tokenBalance := mload(0)
36
+
37
+ if or(iszero(success), lt(returndatasize(), 0x20)) {
38
+ let ptr := mload(0x40)
39
+ returndatacopy(ptr, 0, returndatasize())
40
+ revert(ptr, returndatasize())
41
+ }
42
+ }
43
+ }
44
+
26
45
  /// @dev Ensures method do not revert or return boolean `true`, admits call to non-smart-contract.
27
46
  function safeTransferFromUniversal(
28
47
  IERC20 token,
@@ -32,8 +51,7 @@ library SafeERC20 {
32
51
  bool permit2
33
52
  ) internal {
34
53
  if (permit2) {
35
- if (amount > type(uint160).max) revert Permit2TransferAmountTooHigh();
36
- safeTransferFromPermit2(token, from, to, uint160(amount));
54
+ safeTransferFromPermit2(token, from, to, amount);
37
55
  } else {
38
56
  safeTransferFrom(token, from, to, amount);
39
57
  }
@@ -74,8 +92,9 @@ library SafeERC20 {
74
92
  IERC20 token,
75
93
  address from,
76
94
  address to,
77
- uint160 amount
95
+ uint256 amount
78
96
  ) internal {
97
+ if (amount > type(uint160).max) revert Permit2TransferAmountTooHigh();
79
98
  bytes4 selector = IPermit2.transferFrom.selector;
80
99
  bool success;
81
100
  assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
@@ -287,8 +306,9 @@ library SafeERC20 {
287
306
  mstore(0, selector)
288
307
  mstore(4, amount)
289
308
  if iszero(call(gas(), weth, 0, 0, 0x24, 0, 0)) {
290
- returndatacopy(0, 0, returndatasize())
291
- revert(0, returndatasize())
309
+ let ptr := mload(0x40)
310
+ returndatacopy(ptr, 0, returndatasize())
311
+ revert(ptr, returndatasize())
292
312
  }
293
313
  }
294
314
  }
@@ -298,8 +318,9 @@ library SafeERC20 {
298
318
  if (to != address(this)) {
299
319
  assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
300
320
  if iszero(call(_RAW_CALL_GAS_LIMIT, to, amount, 0, 0, 0, 0)) {
301
- returndatacopy(0, 0, returndatasize())
302
- revert(0, returndatasize())
321
+ let ptr := mload(0x40)
322
+ returndatacopy(ptr, 0, returndatasize())
323
+ revert(ptr, returndatasize())
303
324
  }
304
325
  }
305
326
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1inch/solidity-utils",
3
- "version": "2.2.25",
3
+ "version": "2.2.27",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "repository": {