Skip to content

Commit

Permalink
📬 Multi purpose Receiver
Browse files Browse the repository at this point in the history
📬 ETH, ERC721 and ERC1155 receiver logic.
  • Loading branch information
z0r0z authored May 11, 2023
1 parent 17ccd5e commit 51c4e91
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions src/utils/Receiver.sol
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;
}
}

0 comments on commit 51c4e91

Please sign in to comment.