-
Notifications
You must be signed in to change notification settings - Fork 261
Expand file tree
/
Copy pathForwarderBase.sol
More file actions
54 lines (44 loc) · 1.9 KB
/
ForwarderBase.sol
File metadata and controls
54 lines (44 loc) · 1.9 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// SPDX-License-Identifier: AGPLv3
pragma solidity ^0.8.23;
import { BatchOperation, ISuperfluid } from "../interfaces/superfluid/ISuperfluid.sol";
import { CallUtils } from "../libs/CallUtils.sol";
abstract contract ForwarderBase {
ISuperfluid internal immutable _host;
constructor(ISuperfluid host) {
_host = host;
}
// compiles the calldata of a single operation for the host invocation and executes it
function _forwardBatchCall(address target, bytes memory callData, bytes memory userData) internal returns (bool) {
ISuperfluid.Operation[] memory ops = new ISuperfluid.Operation[](1);
ops[0] = ISuperfluid.Operation(
BatchOperation.OPERATION_TYPE_SUPERFLUID_CALL_AGREEMENT, // type
address(target), // target
abi.encode( // data
callData, userData)
);
return _forwardBatchCall(ops);
}
// helper defaulting to msg.sender as the sender and 0 value to forward
function _forwardBatchCall(ISuperfluid.Operation[] memory ops) internal returns (bool) {
return _forwardBatchCallWithSenderAndValue(ops, msg.sender, 0);
}
function _forwardBatchCallWithSenderAndValue(
ISuperfluid.Operation[] memory ops,
address msgSender,
uint256 valueToForward
)
internal
returns (bool)
{
bytes memory fwBatchCallData = abi.encodeCall(_host.forwardBatchCall, (ops));
// https://eips.ethereum.org/EIPS/eip-2771
// we encode the msgSender as the last 20 bytes per EIP-2771 to extract the original txn signer later on
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returnedData) = address(_host)
.call{value: valueToForward}(abi.encodePacked(fwBatchCallData, msgSender));
if (!success) {
CallUtils.revertFromReturnedData(returnedData);
}
return true;
}
}