-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
📬 ETH, ERC721 and ERC1155 receiver logic.
- Loading branch information
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.4; | ||
|
||
/// @notice ETH, ERC721 and ERC1155 receiver logic. | ||
contract Receiver { | ||
/// ----------------------------------------------------------------------- | ||
/// ERC165 Introspection | ||
/// ----------------------------------------------------------------------- | ||
|
||
function supportsInterface( | ||
bytes4 interfaceId | ||
) public view virtual returns (bool) { | ||
return | ||
// ERC165 interface ID for ERC165. | ||
interfaceId == this.supportsInterface.selector || | ||
// ERC165 Interface ID for ERC721TokenReceiver. | ||
interfaceId == this.onERC721Received.selector || | ||
// ERC165 Interface ID for ERC1155TokenReceiver. | ||
interfaceId == 0x4e2312e0; | ||
} | ||
|
||
/// ----------------------------------------------------------------------- | ||
/// ETH Receiver | ||
/// ----------------------------------------------------------------------- | ||
|
||
receive() external payable {} | ||
|
||
/// ----------------------------------------------------------------------- | ||
/// ERC721 Receiver | ||
/// ----------------------------------------------------------------------- | ||
|
||
function onERC721Received( | ||
address, | ||
address, | ||
uint256, | ||
bytes calldata | ||
) public payable virtual returns (bytes4) { | ||
return this.onERC721Received.selector; | ||
} | ||
|
||
/// ----------------------------------------------------------------------- | ||
/// ERC1155 Receiver | ||
/// ----------------------------------------------------------------------- | ||
|
||
function onERC1155Received( | ||
address, | ||
address, | ||
uint256, | ||
uint256, | ||
bytes calldata | ||
) public payable virtual returns (bytes4) { | ||
return this.onERC1155Received.selector; | ||
} | ||
|
||
function onERC1155BatchReceived( | ||
address, | ||
address, | ||
uint256[] calldata, | ||
uint256[] calldata, | ||
bytes calldata | ||
) public payable virtual returns (bytes4) { | ||
return this.onERC1155BatchReceived.selector; | ||
} | ||
} |