@1inch/solidity-utils 2.2.14 → 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.
|
@@ -6,8 +6,10 @@ pragma abicoder v1;
|
|
|
6
6
|
type Address is uint256;
|
|
7
7
|
|
|
8
8
|
library AddressLib {
|
|
9
|
+
uint256 private constant _LOW_160_BIT_MASK = (1 << 160) - 1;
|
|
10
|
+
|
|
9
11
|
function get(Address a) internal pure returns (address) {
|
|
10
|
-
return address(uint160(Address.unwrap(a)));
|
|
12
|
+
return address(uint160(Address.unwrap(a) & _LOW_160_BIT_MASK));
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
function getFlag(Address a, uint256 flag) internal pure returns (bool) {
|
|
@@ -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
|
}
|