generated from NomicFoundation/hardhat-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 9
/
ERC721TokenboundMech.sol
35 lines (29 loc) · 986 Bytes
/
ERC721TokenboundMech.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
//SPDX-License-Identifier: LGPL-3.0
pragma solidity ^0.8.12;
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "./base/TokenboundMech.sol";
/**
* @dev A Mech that is operated by the holder of an ERC721 non-fungible token
*/
contract ERC721TokenboundMech is TokenboundMech {
function isOperator(address signer) public view override returns (bool) {
(, address tokenContract, uint256 tokenId) = token();
return
IERC721(tokenContract).ownerOf(tokenId) == signer &&
signer != address(0);
}
function onERC721Received(
address,
address,
uint256 receivedTokenId,
bytes calldata
) external view override returns (bytes4) {
(, address boundTokenContract, uint256 boundTokenId) = token();
if (
msg.sender == boundTokenContract && receivedTokenId == boundTokenId
) {
revert OwnershipCycle();
}
return 0x150b7a02;
}
}