-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix the SimpleForwarder by simplifying it
- Loading branch information
Showing
1 changed file
with
7 additions
and
13 deletions.
There are no files selected for viewing
20 changes: 7 additions & 13 deletions
20
packages/ethereum-contracts/contracts/utils/SimpleForwarder.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,28 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.23; | ||
|
||
import { Ownable } from "@openzeppelin/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 { | ||
contract SimpleForwarder { | ||
/** | ||
* @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 | ||
* If forwarded native tokens aren't "consumed" by the target, they are sent back to the caller. | ||
* This will make the transaction revert if neither the target nor the caller take them. | ||
*/ | ||
function forwardCall(address target, bytes calldata data) | ||
external payable onlyOwner | ||
external payable | ||
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); | ||
if (address(this).balance != 0) { | ||
msg.sender.transfer(address(this).balance); | ||
} | ||
} | ||
} |