forked from scroll-tech/scroll
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fallback.sol
36 lines (31 loc) · 1.32 KB
/
Fallback.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// SPDX-License-Identifier: MIT
pragma solidity =0.8.24;
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
contract Fallback is Ownable {
using SafeERC20 for IERC20;
/// @notice Withdraw stucked token from this contract.
/// @param _token The address of token to withdraw, use `address(0)` if withdraw ETH.
/// @param _amount The amount of token to withdraw.
/// @param _recipient The address of receiver.
function withdraw(
address _token,
uint256 _amount,
address _recipient
) external onlyOwner {
if (_token == address(0)) {
(bool _success, ) = _recipient.call{value: _amount}("");
require(_success, "transfer ETH failed");
} else {
IERC20(_token).safeTransfer(_recipient, _amount);
}
}
/// @notice Execute an arbitrary message.
/// @param _target The address of contract to call.
/// @param _data The calldata passed to target contract.
function execute(address _target, bytes calldata _data) external payable onlyOwner {
(bool _success, ) = _target.call{value: msg.value}(_data);
require(_success, "call failed");
}
}