-
Notifications
You must be signed in to change notification settings - Fork 27
/
AdventureERC721C.sol
108 lines (92 loc) · 3.59 KB
/
AdventureERC721C.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "../utils/CreatorTokenBase.sol";
import "../adventures/AdventureERC721.sol";
/**
* @title AdventureERC721C
* @author Limit Break, Inc.
* @notice Extends Limit Break's AdventureERC721 implementation with Creator Token functionality, which
* allows the contract owner to update the transfer validation logic by managing a security policy in
* an external transfer validation security policy registry. See {CreatorTokenTransferValidator}.
*/
abstract contract AdventureERC721C is AdventureERC721, CreatorTokenBase {
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(ICreatorToken).interfaceId || super.supportsInterface(interfaceId);
}
/// @dev Ties the adventure erc721 _beforeTokenTransfer hook to more granular transfer validation logic
function _beforeTokenTransfer(
address from,
address to,
uint256 firstTokenId,
uint256 batchSize) internal virtual override {
uint256 tokenId;
for (uint256 i = 0; i < batchSize;) {
tokenId = firstTokenId + i;
if(blockingQuestCounts[tokenId] > 0) {
revert AdventureERC721__AnActiveQuestIsPreventingTransfers();
}
if(transferType == TRANSFERRING_VIA_ERC721) {
_validateBeforeTransfer(from, to, tokenId);
}
unchecked {
++i;
}
}
}
/// @dev Ties the adventure erc721 _afterTokenTransfer hook to more granular transfer validation logic
function _afterTokenTransfer(
address from,
address to,
uint256 firstTokenId,
uint256 batchSize) internal virtual override {
for (uint256 i = 0; i < batchSize;) {
_validateAfterTransfer(from, to, firstTokenId + i);
unchecked {
++i;
}
}
}
}
/**
* @title AdventureERC721CInitializable
* @author Limit Break, Inc.
* @notice Initializable implementation of the AdventureERC721C contract to allow for EIP-1167 clones.
*/
abstract contract AdventureERC721CInitializable is AdventureERC721Initializable, CreatorTokenBase {
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(ICreatorToken).interfaceId || super.supportsInterface(interfaceId);
}
/// @dev Ties the adventure erc721 _beforeTokenTransfer hook to more granular transfer validation logic
function _beforeTokenTransfer(
address from,
address to,
uint256 firstTokenId,
uint256 batchSize) internal virtual override {
uint256 tokenId;
for (uint256 i = 0; i < batchSize;) {
tokenId = firstTokenId + i;
if(blockingQuestCounts[tokenId] > 0) {
revert AdventureERC721__AnActiveQuestIsPreventingTransfers();
}
if(transferType == TRANSFERRING_VIA_ERC721) {
_validateBeforeTransfer(from, to, tokenId);
}
unchecked {
++i;
}
}
}
/// @dev Ties the adventure erc721 _afterTokenTransfer hook to more granular transfer validation logic
function _afterTokenTransfer(
address from,
address to,
uint256 firstTokenId,
uint256 batchSize) internal virtual override {
for (uint256 i = 0; i < batchSize;) {
_validateAfterTransfer(from, to, firstTokenId + i);
unchecked {
++i;
}
}
}
}