@1inch/solidity-utils 2.2.15 → 2.2.16

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.
@@ -7,6 +7,7 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
7
7
  import "@openzeppelin/contracts/token/ERC20/extensions/draft-IERC20Permit.sol";
8
8
  import "../interfaces/IDaiLikePermit.sol";
9
9
  import "../interfaces/IPermit2.sol";
10
+ import "../interfaces/IWETH.sol";
10
11
  import "../libraries/RevertReasonForwarder.sol";
11
12
 
12
13
  /// @title Implements efficient safe methods for ERC20 interface.
@@ -252,4 +253,44 @@ library SafeERC20 {
252
253
  }
253
254
  }
254
255
  }
256
+
257
+ function safeDeposit(IWETH weth, uint256 amount) internal {
258
+ if (amount > 0) {
259
+ bytes4 selector = IWETH.deposit.selector;
260
+ /// @solidity memory-safe-assembly
261
+ assembly { // solhint-disable-line no-inline-assembly
262
+ mstore(0, selector)
263
+ if iszero(call(gas(), weth, amount, 0, 4, 0, 0)) {
264
+ returndatacopy(0, 0, returndatasize())
265
+ revert(0, returndatasize())
266
+ }
267
+ }
268
+ }
269
+ }
270
+
271
+ function safeWithdraw(IWETH weth, uint256 amount) internal {
272
+ bytes4 selector = IWETH.withdraw.selector;
273
+ /// @solidity memory-safe-assembly
274
+ assembly { // solhint-disable-line no-inline-assembly
275
+ mstore(0, selector)
276
+ mstore(4, amount)
277
+ if iszero(call(gas(), weth, 0, 0, 0x24, 0, 0)) {
278
+ returndatacopy(0, 0, returndatasize())
279
+ revert(0, returndatasize())
280
+ }
281
+ }
282
+ }
283
+
284
+ function safeWithdrawTo(IWETH weth, uint256 amount, address to) internal {
285
+ safeWithdraw(weth, amount);
286
+ if (to != address(this)) {
287
+ /// @solidity memory-safe-assembly
288
+ assembly { // solhint-disable-line no-inline-assembly
289
+ if iszero(call(gas(), to, amount, 0, 0, 0, 0)) {
290
+ returndatacopy(0, 0, returndatasize())
291
+ revert(0, returndatasize())
292
+ }
293
+ }
294
+ }
295
+ }
255
296
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1inch/solidity-utils",
3
- "version": "2.2.15",
3
+ "version": "2.2.16",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "repository": {