-
Notifications
You must be signed in to change notification settings - Fork 261
Expand file tree
/
Copy pathSimpleForwarder.sol
More file actions
36 lines (32 loc) · 1.34 KB
/
SimpleForwarder.sol
File metadata and controls
36 lines (32 loc) · 1.34 KB
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.23;
import { Ownable } from "@openzeppelin-v5/contracts/access/Ownable.sol";
/**
* @title Forwards arbitrary calls
* @dev The purpose of this contract is to let accounts forward arbitrary calls,
* without themselves being the msg.sender from the perspective of the call target.
* This is necessary for security reasons if the calling account has privileged access anywhere.
*/
contract SimpleForwarder is Ownable {
constructor() Ownable(_msgSender()) {}
/**
* @dev Forwards a call for which msg.sender doesn't matter
* @param target The target contract to call
* @param data The call data
* Note: restricted to `onlyOwner` in order to minimize attack surface
*/
function forwardCall(address target, bytes calldata data)
external payable onlyOwner
returns (bool success, bytes memory returnData)
{
// solhint-disable-next-line avoid-low-level-calls
(success, returnData) = target.call{value: msg.value}(data);
}
/**
* @dev Allows to withdraw native tokens (ETH) which got stuck in this contract.
* This could happen if a call fails, but the caller doesn't revert the tx.
*/
function withdrawLostNativeTokens(address payable receiver) external onlyOwner {
receiver.transfer(address(this).balance);
}
}