-
Notifications
You must be signed in to change notification settings - Fork 261
Expand file tree
/
Copy pathERC2771Forwarder.sol
More file actions
33 lines (29 loc) · 1.23 KB
/
ERC2771Forwarder.sol
File metadata and controls
33 lines (29 loc) · 1.23 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
// SPDX-License-Identifier: AGPLv3
pragma solidity ^0.8.23;
import { Ownable } from "@openzeppelin-v5/contracts/access/Ownable.sol";
/**
* @title Forwards calls preserving the original msg.sender according to ERC-2771
*/
contract ERC2771Forwarder is Ownable {
constructor() Ownable(_msgSender()) {}
/**
* @dev Forwards a call passing along the original msg.sender encoded as specified in ERC-2771.
* @param target The target contract to call
* @param msgSender The original msg.sender passed along by the trusted contract owner
* @param data The call data
*/
function forward2771Call(address target, address msgSender, bytes memory 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}(abi.encodePacked(data, msgSender));
}
/**
* @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);
}
}