@bananapus/721-hook-v6 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gas-snapshot +152 -0
- package/LICENSE +21 -0
- package/README.md +253 -0
- package/SKILLS.md +140 -0
- package/docs/book.css +13 -0
- package/docs/book.toml +12 -0
- package/docs/solidity.min.js +74 -0
- package/docs/src/README.md +253 -0
- package/docs/src/SUMMARY.md +38 -0
- package/docs/src/src/JB721TiersHook.sol/contract.JB721TiersHook.md +645 -0
- package/docs/src/src/JB721TiersHookDeployer.sol/contract.JB721TiersHookDeployer.md +99 -0
- package/docs/src/src/JB721TiersHookProjectDeployer.sol/contract.JB721TiersHookProjectDeployer.md +288 -0
- package/docs/src/src/JB721TiersHookStore.sol/contract.JB721TiersHookStore.md +1096 -0
- package/docs/src/src/README.md +11 -0
- package/docs/src/src/abstract/ERC721.sol/abstract.ERC721.md +430 -0
- package/docs/src/src/abstract/JB721Hook.sol/abstract.JB721Hook.md +309 -0
- package/docs/src/src/abstract/README.md +5 -0
- package/docs/src/src/interfaces/IJB721Hook.sol/interface.IJB721Hook.md +29 -0
- package/docs/src/src/interfaces/IJB721TiersHook.sol/interface.IJB721TiersHook.md +203 -0
- package/docs/src/src/interfaces/IJB721TiersHookDeployer.sol/interface.IJB721TiersHookDeployer.md +25 -0
- package/docs/src/src/interfaces/IJB721TiersHookProjectDeployer.sol/interface.IJB721TiersHookProjectDeployer.md +64 -0
- package/docs/src/src/interfaces/IJB721TiersHookStore.sol/interface.IJB721TiersHookStore.md +265 -0
- package/docs/src/src/interfaces/IJB721TokenUriResolver.sol/interface.IJB721TokenUriResolver.md +12 -0
- package/docs/src/src/interfaces/README.md +9 -0
- package/docs/src/src/libraries/JB721Constants.sol/library.JB721Constants.md +14 -0
- package/docs/src/src/libraries/JB721TiersRulesetMetadataResolver.sol/library.JB721TiersRulesetMetadataResolver.md +68 -0
- package/docs/src/src/libraries/JBBitmap.sol/library.JBBitmap.md +82 -0
- package/docs/src/src/libraries/JBIpfsDecoder.sol/library.JBIpfsDecoder.md +61 -0
- package/docs/src/src/libraries/README.md +7 -0
- package/docs/src/src/structs/JB721InitTiersConfig.sol/struct.JB721InitTiersConfig.md +27 -0
- package/docs/src/src/structs/JB721Tier.sol/struct.JB721Tier.md +59 -0
- package/docs/src/src/structs/JB721TierConfig.sol/struct.JB721TierConfig.md +60 -0
- package/docs/src/src/structs/JB721TiersHookFlags.sol/struct.JB721TiersHookFlags.md +26 -0
- package/docs/src/src/structs/JB721TiersMintReservesConfig.sol/struct.JB721TiersMintReservesConfig.md +16 -0
- package/docs/src/src/structs/JB721TiersRulesetMetadata.sol/struct.JB721TiersRulesetMetadata.md +20 -0
- package/docs/src/src/structs/JB721TiersSetDiscountPercentConfig.sol/struct.JB721TiersSetDiscountPercentConfig.md +16 -0
- package/docs/src/src/structs/JBBitmapWord.sol/struct.JBBitmapWord.md +19 -0
- package/docs/src/src/structs/JBDeploy721TiersHookConfig.sol/struct.JBDeploy721TiersHookConfig.md +34 -0
- package/docs/src/src/structs/JBLaunchProjectConfig.sol/struct.JBLaunchProjectConfig.md +23 -0
- package/docs/src/src/structs/JBLaunchRulesetsConfig.sol/struct.JBLaunchRulesetsConfig.md +22 -0
- package/docs/src/src/structs/JBPayDataHookRulesetConfig.sol/struct.JBPayDataHookRulesetConfig.md +51 -0
- package/docs/src/src/structs/JBPayDataHookRulesetMetadata.sol/struct.JBPayDataHookRulesetMetadata.md +66 -0
- package/docs/src/src/structs/JBQueueRulesetsConfig.sol/struct.JBQueueRulesetsConfig.md +21 -0
- package/docs/src/src/structs/JBStored721Tier.sol/struct.JBStored721Tier.md +42 -0
- package/docs/src/src/structs/README.md +18 -0
- package/foundry.lock +11 -0
- package/foundry.toml +22 -0
- package/package.json +31 -0
- package/remappings.txt +1 -0
- package/script/Deploy.s.sol +140 -0
- package/script/helpers/Hook721DeploymentLib.sol +81 -0
- package/slither-ci.config.json +10 -0
- package/sphinx.lock +476 -0
- package/src/JB721TiersHook.sol +765 -0
- package/src/JB721TiersHookDeployer.sol +114 -0
- package/src/JB721TiersHookProjectDeployer.sol +413 -0
- package/src/JB721TiersHookStore.sol +1195 -0
- package/src/abstract/ERC721.sol +484 -0
- package/src/abstract/JB721Hook.sol +279 -0
- package/src/interfaces/IJB721Hook.sol +21 -0
- package/src/interfaces/IJB721TiersHook.sol +135 -0
- package/src/interfaces/IJB721TiersHookDeployer.sol +22 -0
- package/src/interfaces/IJB721TiersHookProjectDeployer.sol +76 -0
- package/src/interfaces/IJB721TiersHookStore.sol +220 -0
- package/src/interfaces/IJB721TokenUriResolver.sol +10 -0
- package/src/libraries/JB721Constants.sol +7 -0
- package/src/libraries/JB721TiersRulesetMetadataResolver.sol +44 -0
- package/src/libraries/JBBitmap.sol +57 -0
- package/src/libraries/JBIpfsDecoder.sol +95 -0
- package/src/structs/JB721InitTiersConfig.sol +20 -0
- package/src/structs/JB721Tier.sol +39 -0
- package/src/structs/JB721TierConfig.sol +40 -0
- package/src/structs/JB721TiersHookFlags.sol +17 -0
- package/src/structs/JB721TiersMintReservesConfig.sol +9 -0
- package/src/structs/JB721TiersRulesetMetadata.sol +12 -0
- package/src/structs/JB721TiersSetDiscountPercentConfig.sol +9 -0
- package/src/structs/JBBitmapWord.sol +11 -0
- package/src/structs/JBDeploy721TiersHookConfig.sol +25 -0
- package/src/structs/JBLaunchProjectConfig.sol +18 -0
- package/src/structs/JBLaunchRulesetsConfig.sol +17 -0
- package/src/structs/JBPayDataHookRulesetConfig.sol +44 -0
- package/src/structs/JBPayDataHookRulesetMetadata.sol +46 -0
- package/src/structs/JBQueueRulesetsConfig.sol +13 -0
- package/src/structs/JBStored721Tier.sol +24 -0
- package/test/721HookAttacks.t.sol +396 -0
- package/test/E2E/Pay_Mint_Redeem_E2E.t.sol +944 -0
- package/test/invariants/TierLifecycleInvariant.t.sol +187 -0
- package/test/invariants/TieredHookStoreInvariant.t.sol +81 -0
- package/test/invariants/handlers/TierLifecycleHandler.sol +262 -0
- package/test/invariants/handlers/TierStoreHandler.sol +155 -0
- package/test/unit/JB721TiersRulesetMetadataResolver.t.sol +141 -0
- package/test/unit/JBBitmap.t.sol +169 -0
- package/test/unit/JBIpfsDecoder.t.sol +131 -0
- package/test/unit/M6_TierSupplyCheck.t.sol +220 -0
- package/test/unit/adjustTier_Unit.t.sol +1740 -0
- package/test/unit/deployer_Unit.t.sol +103 -0
- package/test/unit/getters_constructor_Unit.t.sol +548 -0
- package/test/unit/mintFor_mintReservesFor_Unit.t.sol +443 -0
- package/test/unit/pay_Unit.t.sol +1537 -0
- package/test/unit/redeem_Unit.t.sol +459 -0
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/ERC721.sol)
|
|
3
|
+
|
|
4
|
+
pragma solidity 0.8.23;
|
|
5
|
+
|
|
6
|
+
import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
|
|
7
|
+
import {IERC721Receiver} from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
|
|
8
|
+
import {IERC721Metadata} from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";
|
|
9
|
+
import {Context} from "@openzeppelin/contracts/utils/Context.sol";
|
|
10
|
+
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
|
|
11
|
+
import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
|
|
12
|
+
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
|
|
13
|
+
import {IERC721Errors} from "@openzeppelin/contracts/interfaces/draft-IERC6093.sol";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
|
|
17
|
+
* the Metadata extension, but not including the Enumerable extension, which is available separately as
|
|
18
|
+
* {ERC721Enumerable}.
|
|
19
|
+
*/
|
|
20
|
+
abstract contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Errors {
|
|
21
|
+
using Strings for uint256;
|
|
22
|
+
|
|
23
|
+
// Token name
|
|
24
|
+
string private _name;
|
|
25
|
+
|
|
26
|
+
// Token symbol
|
|
27
|
+
string private _symbol;
|
|
28
|
+
|
|
29
|
+
mapping(uint256 tokenId => address) internal _owners;
|
|
30
|
+
|
|
31
|
+
mapping(address owner => uint256) private _balances;
|
|
32
|
+
|
|
33
|
+
mapping(uint256 tokenId => address) private _tokenApprovals;
|
|
34
|
+
|
|
35
|
+
mapping(address owner => mapping(address operator => bool)) private _operatorApprovals;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
|
|
39
|
+
*/
|
|
40
|
+
function _initialize(string memory name_, string memory symbol_) internal {
|
|
41
|
+
_name = name_;
|
|
42
|
+
_symbol = symbol_;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @dev See {IERC165-supportsInterface}.
|
|
47
|
+
*/
|
|
48
|
+
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
|
|
49
|
+
return interfaceId == type(IERC721).interfaceId || interfaceId == type(IERC721Metadata).interfaceId
|
|
50
|
+
|| super.supportsInterface(interfaceId);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @dev See {IERC721-balanceOf}.
|
|
55
|
+
*/
|
|
56
|
+
function balanceOf(address owner) public view virtual returns (uint256) {
|
|
57
|
+
if (owner == address(0)) {
|
|
58
|
+
revert ERC721InvalidOwner(address(0));
|
|
59
|
+
}
|
|
60
|
+
return _balances[owner];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @dev See {IERC721-ownerOf}.
|
|
65
|
+
*/
|
|
66
|
+
function ownerOf(uint256 tokenId) public view virtual returns (address) {
|
|
67
|
+
return _requireOwned(tokenId);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @dev See {IERC721Metadata-name}.
|
|
72
|
+
*/
|
|
73
|
+
function name() public view virtual returns (string memory) {
|
|
74
|
+
return _name;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @dev See {IERC721Metadata-symbol}.
|
|
79
|
+
*/
|
|
80
|
+
function symbol() public view virtual returns (string memory) {
|
|
81
|
+
return _symbol;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @dev See {IERC721Metadata-tokenURI}.
|
|
86
|
+
*/
|
|
87
|
+
function tokenURI(uint256 tokenId) public view virtual returns (string memory) {
|
|
88
|
+
_requireOwned(tokenId);
|
|
89
|
+
|
|
90
|
+
string memory baseURI = _baseURI();
|
|
91
|
+
return bytes(baseURI).length > 0 ? string.concat(baseURI, tokenId.toString()) : "";
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
|
|
96
|
+
* token will be the concatenation of the `baseURI` and the `tokenId`. Empty
|
|
97
|
+
* by default, can be overridden in child contracts.
|
|
98
|
+
*/
|
|
99
|
+
function _baseURI() internal view virtual returns (string memory) {
|
|
100
|
+
return "";
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* @dev See {IERC721-approve}.
|
|
105
|
+
*/
|
|
106
|
+
function approve(address to, uint256 tokenId) public virtual {
|
|
107
|
+
_approve(to, tokenId, _msgSender());
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @dev See {IERC721-getApproved}.
|
|
112
|
+
*/
|
|
113
|
+
function getApproved(uint256 tokenId) public view virtual returns (address) {
|
|
114
|
+
_requireOwned(tokenId);
|
|
115
|
+
|
|
116
|
+
return _getApproved(tokenId);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @dev See {IERC721-setApprovalForAll}.
|
|
121
|
+
*/
|
|
122
|
+
function setApprovalForAll(address operator, bool approved) public virtual {
|
|
123
|
+
_setApprovalForAll(_msgSender(), operator, approved);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* @dev See {IERC721-isApprovedForAll}.
|
|
128
|
+
*/
|
|
129
|
+
function isApprovedForAll(address owner, address operator) public view virtual returns (bool) {
|
|
130
|
+
return _operatorApprovals[owner][operator];
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* @dev See {IERC721-transferFrom}.
|
|
135
|
+
*/
|
|
136
|
+
function transferFrom(address from, address to, uint256 tokenId) public virtual {
|
|
137
|
+
if (to == address(0)) {
|
|
138
|
+
revert ERC721InvalidReceiver(address(0));
|
|
139
|
+
}
|
|
140
|
+
// Setting an "auth" arguments enables the `_isAuthorized` check which verifies that the token exists
|
|
141
|
+
// (from != 0). Therefore, it is not needed to verify that the return value is not 0 here.
|
|
142
|
+
address previousOwner = _update(to, tokenId, _msgSender());
|
|
143
|
+
if (previousOwner != from) {
|
|
144
|
+
revert ERC721IncorrectOwner(from, tokenId, previousOwner);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* @dev See {IERC721-safeTransferFrom}.
|
|
150
|
+
*/
|
|
151
|
+
function safeTransferFrom(address from, address to, uint256 tokenId) public {
|
|
152
|
+
safeTransferFrom(from, to, tokenId, "");
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* @dev See {IERC721-safeTransferFrom}.
|
|
157
|
+
*/
|
|
158
|
+
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public virtual {
|
|
159
|
+
transferFrom(from, to, tokenId);
|
|
160
|
+
_checkOnERC721Received(from, to, tokenId, data);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* @dev Returns the owner of the `tokenId`. Does NOT revert if token doesn't exist
|
|
165
|
+
*
|
|
166
|
+
* IMPORTANT: Any overrides to this function that add ownership of tokens not tracked by the
|
|
167
|
+
* core ERC721 logic MUST be matched with the use of {_increaseBalance} to keep balances
|
|
168
|
+
* consistent with ownership. The invariant to preserve is that for any address `a` the value returned by
|
|
169
|
+
* `balanceOf(a)` must be equal to the number of tokens such that `_ownerOf(tokenId)` is `a`.
|
|
170
|
+
*/
|
|
171
|
+
function _ownerOf(uint256 tokenId) internal view virtual returns (address) {
|
|
172
|
+
return _owners[tokenId];
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* @dev Returns the approved address for `tokenId`. Returns 0 if `tokenId` is not minted.
|
|
177
|
+
*/
|
|
178
|
+
function _getApproved(uint256 tokenId) internal view virtual returns (address) {
|
|
179
|
+
return _tokenApprovals[tokenId];
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* @dev Returns whether `spender` is allowed to manage `owner`'s tokens, or `tokenId` in
|
|
184
|
+
* particular (ignoring whether it is owned by `owner`).
|
|
185
|
+
*
|
|
186
|
+
* WARNING: This function assumes that `owner` is the actual owner of `tokenId` and does not verify this
|
|
187
|
+
* assumption.
|
|
188
|
+
*/
|
|
189
|
+
function _isAuthorized(address owner, address spender, uint256 tokenId) internal view virtual returns (bool) {
|
|
190
|
+
return spender != address(0)
|
|
191
|
+
&& (owner == spender || isApprovedForAll(owner, spender) || _getApproved(tokenId) == spender);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* @dev Checks if `spender` can operate on `tokenId`, assuming the provided `owner` is the actual owner.
|
|
196
|
+
* Reverts if `spender` does not have approval from the provided `owner` for the given token or for all its assets
|
|
197
|
+
* the `spender` for the specific `tokenId`.
|
|
198
|
+
*
|
|
199
|
+
* WARNING: This function assumes that `owner` is the actual owner of `tokenId` and does not verify this
|
|
200
|
+
* assumption.
|
|
201
|
+
*/
|
|
202
|
+
function _checkAuthorized(address owner, address spender, uint256 tokenId) internal view virtual {
|
|
203
|
+
if (!_isAuthorized(owner, spender, tokenId)) {
|
|
204
|
+
if (owner == address(0)) {
|
|
205
|
+
revert ERC721NonexistentToken(tokenId);
|
|
206
|
+
} else {
|
|
207
|
+
revert ERC721InsufficientApproval(spender, tokenId);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* @dev Unsafe write access to the balances, used by extensions that "mint" tokens using an {ownerOf} override.
|
|
214
|
+
*
|
|
215
|
+
* NOTE: the value is limited to type(uint128).max. This protect against _balance overflow. It is unrealistic that
|
|
216
|
+
* a uint256 would ever overflow from increments when these increments are bounded to uint128 values.
|
|
217
|
+
*
|
|
218
|
+
* WARNING: Increasing an account's balance using this function tends to be paired with an override of the
|
|
219
|
+
* {_ownerOf} function to resolve the ownership of the corresponding tokens so that balances and ownership
|
|
220
|
+
* remain consistent with one another.
|
|
221
|
+
*/
|
|
222
|
+
function _increaseBalance(address account, uint128 value) internal virtual {
|
|
223
|
+
unchecked {
|
|
224
|
+
_balances[account] += value;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* @dev Transfers `tokenId` from its current owner to `to`, or alternatively mints (or burns) if the current owner
|
|
230
|
+
* (or `to`) is the zero address. Returns the owner of the `tokenId` before the update.
|
|
231
|
+
*
|
|
232
|
+
* The `auth` argument is optional. If the value passed is non 0, then this function will check that
|
|
233
|
+
* `auth` is either the owner of the token, or approved to operate on the token (by the owner).
|
|
234
|
+
*
|
|
235
|
+
* Emits a {Transfer} event.
|
|
236
|
+
*
|
|
237
|
+
* NOTE: If overriding this function in a way that tracks balances, see also {_increaseBalance}.
|
|
238
|
+
*/
|
|
239
|
+
function _update(address to, uint256 tokenId, address auth) internal virtual returns (address) {
|
|
240
|
+
address from = _ownerOf(tokenId);
|
|
241
|
+
|
|
242
|
+
// Perform (optional) operator check
|
|
243
|
+
if (auth != address(0)) {
|
|
244
|
+
_checkAuthorized(from, auth, tokenId);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// Execute the update
|
|
248
|
+
if (from != address(0)) {
|
|
249
|
+
// Clear approval. No need to re-authorize or emit the Approval event
|
|
250
|
+
_approve(address(0), tokenId, address(0), false);
|
|
251
|
+
|
|
252
|
+
unchecked {
|
|
253
|
+
_balances[from] -= 1;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (to != address(0)) {
|
|
258
|
+
unchecked {
|
|
259
|
+
_balances[to] += 1;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
_owners[tokenId] = to;
|
|
264
|
+
|
|
265
|
+
emit Transfer(from, to, tokenId);
|
|
266
|
+
|
|
267
|
+
return from;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* @dev Mints `tokenId` and transfers it to `to`.
|
|
272
|
+
*
|
|
273
|
+
* WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
|
|
274
|
+
*
|
|
275
|
+
* Requirements:
|
|
276
|
+
*
|
|
277
|
+
* - `tokenId` must not exist.
|
|
278
|
+
* - `to` cannot be the zero address.
|
|
279
|
+
*
|
|
280
|
+
* Emits a {Transfer} event.
|
|
281
|
+
*/
|
|
282
|
+
function _mint(address to, uint256 tokenId) internal {
|
|
283
|
+
if (to == address(0)) {
|
|
284
|
+
revert ERC721InvalidReceiver(address(0));
|
|
285
|
+
}
|
|
286
|
+
address previousOwner = _update(to, tokenId, address(0));
|
|
287
|
+
if (previousOwner != address(0)) {
|
|
288
|
+
revert ERC721InvalidSender(address(0));
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* @dev Mints `tokenId`, transfers it to `to` and checks for `to` acceptance.
|
|
294
|
+
*
|
|
295
|
+
* Requirements:
|
|
296
|
+
*
|
|
297
|
+
* - `tokenId` must not exist.
|
|
298
|
+
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
|
|
299
|
+
* a safe transfer.
|
|
300
|
+
*
|
|
301
|
+
* Emits a {Transfer} event.
|
|
302
|
+
*/
|
|
303
|
+
function _safeMint(address to, uint256 tokenId) internal {
|
|
304
|
+
_safeMint(to, tokenId, "");
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
|
|
309
|
+
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
|
|
310
|
+
*/
|
|
311
|
+
function _safeMint(address to, uint256 tokenId, bytes memory data) internal virtual {
|
|
312
|
+
_mint(to, tokenId);
|
|
313
|
+
_checkOnERC721Received(address(0), to, tokenId, data);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* @dev Destroys `tokenId`.
|
|
318
|
+
* The approval is cleared when the token is burned.
|
|
319
|
+
* This is an internal function that does not check if the sender is authorized to operate on the token.
|
|
320
|
+
*
|
|
321
|
+
* Requirements:
|
|
322
|
+
*
|
|
323
|
+
* - `tokenId` must exist.
|
|
324
|
+
*
|
|
325
|
+
* Emits a {Transfer} event.
|
|
326
|
+
*/
|
|
327
|
+
function _burn(uint256 tokenId) internal {
|
|
328
|
+
address previousOwner = _update(address(0), tokenId, address(0));
|
|
329
|
+
if (previousOwner == address(0)) {
|
|
330
|
+
revert ERC721NonexistentToken(tokenId);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* @dev Transfers `tokenId` from `from` to `to`.
|
|
336
|
+
* As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
|
|
337
|
+
*
|
|
338
|
+
* Requirements:
|
|
339
|
+
*
|
|
340
|
+
* - `to` cannot be the zero address.
|
|
341
|
+
* - `tokenId` token must be owned by `from`.
|
|
342
|
+
*
|
|
343
|
+
* Emits a {Transfer} event.
|
|
344
|
+
*/
|
|
345
|
+
function _transfer(address from, address to, uint256 tokenId) internal {
|
|
346
|
+
if (to == address(0)) {
|
|
347
|
+
revert ERC721InvalidReceiver(address(0));
|
|
348
|
+
}
|
|
349
|
+
address previousOwner = _update(to, tokenId, address(0));
|
|
350
|
+
if (previousOwner == address(0)) {
|
|
351
|
+
revert ERC721NonexistentToken(tokenId);
|
|
352
|
+
} else if (previousOwner != from) {
|
|
353
|
+
revert ERC721IncorrectOwner(from, tokenId, previousOwner);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* @dev Safely transfers `tokenId` token from `from` to `to`, checking that contract recipients
|
|
359
|
+
* are aware of the ERC721 standard to prevent tokens from being forever locked.
|
|
360
|
+
*
|
|
361
|
+
* `data` is additional data, it has no specified format and it is sent in call to `to`.
|
|
362
|
+
*
|
|
363
|
+
* This internal function is like {safeTransferFrom} in the sense that it invokes
|
|
364
|
+
* {IERC721Receiver-onERC721Received} on the receiver, and can be used to e.g.
|
|
365
|
+
* implement alternative mechanisms to perform token transfer, such as signature-based.
|
|
366
|
+
*
|
|
367
|
+
* Requirements:
|
|
368
|
+
*
|
|
369
|
+
* - `tokenId` token must exist and be owned by `from`.
|
|
370
|
+
* - `to` cannot be the zero address.
|
|
371
|
+
* - `from` cannot be the zero address.
|
|
372
|
+
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
|
|
373
|
+
* a safe transfer.
|
|
374
|
+
*
|
|
375
|
+
* Emits a {Transfer} event.
|
|
376
|
+
*/
|
|
377
|
+
function _safeTransfer(address from, address to, uint256 tokenId) internal {
|
|
378
|
+
_safeTransfer(from, to, tokenId, "");
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* @dev Same as {xref-ERC721-_safeTransfer-address-address-uint256-}[`_safeTransfer`], with an additional `data`
|
|
383
|
+
* parameter which is
|
|
384
|
+
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
|
|
385
|
+
*/
|
|
386
|
+
function _safeTransfer(address from, address to, uint256 tokenId, bytes memory data) internal virtual {
|
|
387
|
+
_transfer(from, to, tokenId);
|
|
388
|
+
_checkOnERC721Received(from, to, tokenId, data);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* @dev Approve `to` to operate on `tokenId`
|
|
393
|
+
*
|
|
394
|
+
* The `auth` argument is optional. If the value passed is non 0, then this function will check that `auth` is
|
|
395
|
+
* either the owner of the token, or approved to operate on all tokens held by this owner.
|
|
396
|
+
*
|
|
397
|
+
* Emits an {Approval} event.
|
|
398
|
+
*
|
|
399
|
+
* Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
|
|
400
|
+
*/
|
|
401
|
+
function _approve(address to, uint256 tokenId, address auth) internal {
|
|
402
|
+
_approve(to, tokenId, auth, true);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* @dev Variant of `_approve` with an optional flag to enable or disable the {Approval} event. The event is not
|
|
407
|
+
* emitted in the context of transfers.
|
|
408
|
+
*/
|
|
409
|
+
function _approve(address to, uint256 tokenId, address auth, bool emitEvent) internal virtual {
|
|
410
|
+
// Avoid reading the owner unless necessary
|
|
411
|
+
if (emitEvent || auth != address(0)) {
|
|
412
|
+
address owner = _requireOwned(tokenId);
|
|
413
|
+
|
|
414
|
+
// We do not use _isAuthorized because single-token approvals should not be able to call approve
|
|
415
|
+
if (auth != address(0) && owner != auth && !isApprovedForAll(owner, auth)) {
|
|
416
|
+
revert ERC721InvalidApprover(auth);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
if (emitEvent) {
|
|
420
|
+
emit Approval(owner, to, tokenId);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
_tokenApprovals[tokenId] = to;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* @dev Approve `operator` to operate on all of `owner` tokens
|
|
429
|
+
*
|
|
430
|
+
* Requirements:
|
|
431
|
+
* - operator can't be the address zero.
|
|
432
|
+
*
|
|
433
|
+
* Emits an {ApprovalForAll} event.
|
|
434
|
+
*/
|
|
435
|
+
function _setApprovalForAll(address owner, address operator, bool approved) internal virtual {
|
|
436
|
+
if (operator == address(0)) {
|
|
437
|
+
revert ERC721InvalidOperator(operator);
|
|
438
|
+
}
|
|
439
|
+
_operatorApprovals[owner][operator] = approved;
|
|
440
|
+
emit ApprovalForAll(owner, operator, approved);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* @dev Reverts if the `tokenId` doesn't have a current owner (it hasn't been minted, or it has been burned).
|
|
445
|
+
* Returns the owner.
|
|
446
|
+
*
|
|
447
|
+
* Overrides to ownership logic should be done to {_ownerOf}.
|
|
448
|
+
*/
|
|
449
|
+
function _requireOwned(uint256 tokenId) internal view returns (address) {
|
|
450
|
+
address owner = _ownerOf(tokenId);
|
|
451
|
+
if (owner == address(0)) {
|
|
452
|
+
revert ERC721NonexistentToken(tokenId);
|
|
453
|
+
}
|
|
454
|
+
return owner;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* @dev Private function to invoke {IERC721Receiver-onERC721Received} on a target address. This will revert if the
|
|
459
|
+
* recipient doesn't accept the token transfer. The call is not executed if the target address is not a contract.
|
|
460
|
+
*
|
|
461
|
+
* @param from address representing the previous owner of the given token ID
|
|
462
|
+
* @param to target address that will receive the tokens
|
|
463
|
+
* @param tokenId uint256 ID of the token to be transferred
|
|
464
|
+
* @param data bytes optional data to send along with the call
|
|
465
|
+
*/
|
|
466
|
+
function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory data) private {
|
|
467
|
+
if (to.code.length > 0) {
|
|
468
|
+
try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, data) returns (bytes4 retval) {
|
|
469
|
+
if (retval != IERC721Receiver.onERC721Received.selector) {
|
|
470
|
+
revert ERC721InvalidReceiver(to);
|
|
471
|
+
}
|
|
472
|
+
} catch (bytes memory reason) {
|
|
473
|
+
if (reason.length == 0) {
|
|
474
|
+
revert ERC721InvalidReceiver(to);
|
|
475
|
+
} else {
|
|
476
|
+
/// @solidity memory-safe-assembly
|
|
477
|
+
assembly {
|
|
478
|
+
revert(add(32, reason), mload(reason))
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|