-
Notifications
You must be signed in to change notification settings - Fork 25
/
TokenReceiverModule.sol
87 lines (73 loc) · 3.52 KB
/
TokenReceiverModule.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.20;
import {IERC1155Receiver} from "@openzeppelin/contracts/interfaces/IERC1155Receiver.sol";
import {IERC721Receiver} from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import {ExecutionManifest, ManifestExecutionFunction} from "../interfaces/IExecutionModule.sol";
import {ExecutionManifest, IExecutionModule} from "../interfaces/IExecutionModule.sol";
import {IModule} from "../interfaces/IModule.sol";
import {BaseModule} from "./BaseModule.sol";
/// @title Token Receiver Module
/// @author ERC-6900 Authors
/// @notice This module allows modular accounts to receive various types of tokens by implementing
/// required token receiver interfaces.
contract TokenReceiverModule is BaseModule, IExecutionModule, IERC721Receiver, IERC1155Receiver {
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
// ┃ Execution functions ┃
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
function onERC721Received(address, address, uint256, bytes calldata) external pure override returns (bytes4) {
return IERC721Receiver.onERC721Received.selector;
}
function onERC1155Received(address, address, uint256, uint256, bytes calldata)
external
pure
override
returns (bytes4)
{
return IERC1155Receiver.onERC1155Received.selector;
}
function onERC1155BatchReceived(address, address, uint256[] calldata, uint256[] calldata, bytes calldata)
external
pure
override
returns (bytes4)
{
return IERC1155Receiver.onERC1155BatchReceived.selector;
}
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
// ┃ Module interface functions ┃
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
/// @inheritdoc IModule
// solhint-disable-next-line no-empty-blocks
function onInstall(bytes calldata) external pure override {}
/// @inheritdoc IModule
// solhint-disable-next-line no-empty-blocks
function onUninstall(bytes calldata) external pure override {}
/// @inheritdoc IExecutionModule
function executionManifest() external pure override returns (ExecutionManifest memory) {
ExecutionManifest memory manifest;
manifest.executionFunctions = new ManifestExecutionFunction[](3);
manifest.executionFunctions[0] = ManifestExecutionFunction({
executionSelector: this.onERC721Received.selector,
skipRuntimeValidation: true,
allowGlobalValidation: false
});
manifest.executionFunctions[1] = ManifestExecutionFunction({
executionSelector: this.onERC1155Received.selector,
skipRuntimeValidation: true,
allowGlobalValidation: false
});
manifest.executionFunctions[2] = ManifestExecutionFunction({
executionSelector: this.onERC1155BatchReceived.selector,
skipRuntimeValidation: true,
allowGlobalValidation: false
});
manifest.interfaceIds = new bytes4[](2);
manifest.interfaceIds[0] = type(IERC721Receiver).interfaceId;
manifest.interfaceIds[1] = type(IERC1155Receiver).interfaceId;
return manifest;
}
/// @inheritdoc IModule
function moduleId() external pure returns (string memory) {
return "erc6900.token-receiver-module.1.0.0";
}
}