Description:
Multi-signature wallet contract requiring multiple confirmations for transaction execution.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
{{
"language": "Solidity",
"sources": {
"src/QuirkiesImplementationV7.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
// developed by @hexzerodev
import {ERC721CUpgradeable} from "./ERC721C/upgradeable/ERC721CUpgradeable.sol";
import {
IStrictAuthorizedTransferSecurityRegistry,
TransferSecurityLevels
} from "./IStrictAuthorizedTransferSecurityRegistry.sol";
import {OwnableUpgradeable} from "openzeppelin-upgradeable/access/OwnableUpgradeable.sol";
import {ERC2981Upgradeable} from "openzeppelin-upgradeable/token/common/ERC2981Upgradeable.sol";
import {Strings} from "openzeppelin/utils/Strings.sol";
library QuirkiesV1Storage {
struct Layout {
address quirkiesV1Address;
bool claimOpen;
string baseURI;
mapping(uint256 => bool) stakedMap_deprecated;
mapping(address => bool) stakingContractsMap;
mapping(uint256 => address) stakedMap;
string stakedBaseURI;
bool hasSetupV5Validator;
uint256 operatorWhitelistID;
}
bytes32 internal constant STORAGE_SLOT = keccak256("QuirkiesImplV1.storage");
function layout() internal pure returns (Layout storage l) {
bytes32 slot = STORAGE_SLOT;
assembly {
l.slot := slot
}
}
}
contract QuirkiesImplementationV7 is OwnableUpgradeable, ERC721CUpgradeable, ERC2981Upgradeable {
using Strings for uint256;
/* -------------------------------------------------------------------------- */
/* errors */
/* -------------------------------------------------------------------------- */
error ErrStaked();
error ErrUnauthorizedStaker();
error ErrNotStaked();
error ErrNotOwner();
error ErrAlreadySetupValidator();
/* -------------------------------------------------------------------------- */
/* constants */
/* -------------------------------------------------------------------------- */
address constant VALIDATOR_ADDRESS = 0xA000027A9B2802E1ddf7000061001e5c005A0000;
/* -------------------------------------------------------------------------- */
/* constructor */
/* -------------------------------------------------------------------------- */
function initialize(address quirkiesV1Address_, string memory baseURI_, address teamWallet_) public initializer {
__ERC721_init("Quirkies", "QRKS");
__Ownable_init();
__ERC2981_init();
// initial states
QuirkiesV1Storage.layout().quirkiesV1Address = quirkiesV1Address_;
QuirkiesV1Storage.layout().baseURI = baseURI_;
// erc2981 royalty - 7%
_setDefaultRoyalty(teamWallet_, 700);
}
function setupV5Validator() external onlyOwner {
// check
if (QuirkiesV1Storage.layout().hasSetupV5Validator) {
revert ErrAlreadySetupValidator();
}
// update state
QuirkiesV1Storage.layout().hasSetupV5Validator = true;
// setup validator
IStrictAuthorizedTransferSecurityRegistry v = IStrictAuthorizedTransferSecurityRegistry(VALIDATOR_ADDRESS);
uint256 _operatorWhitelistID = v.createList("QRKS");
QuirkiesV1Storage.layout().operatorWhitelistID = _operatorWhitelistID;
v.addAccountToWhitelist(uint120(_operatorWhitelistID), 0x9A1D00bEd7CD04BCDA516d721A596eb22Aac6834); //
v.addAccountToWhitelist(uint120(_operatorWhitelistID), 0x9A1D001670C8b17F8B7900E8d7a41e785B3F0515);
//
v.addAccountToWhitelist(uint120(_operatorWhitelistID), 0x1E0049783F008A0085193E00003D00cd54003c71);
//
// setToCustomValidatorAndSecurityPolicy
setTransferValidator(address(v));
v.setTransferSecurityLevelOfCollection(address(this), TransferSecurityLevels.Three);
v.applyListToCollection(address(this), uint120(_operatorWhitelistID));
}
/* -------------------------------------------------------------------------- */
/* owners */
/* -------------------------------------------------------------------------- */
function setBaseURI(string memory baseURI_) public onlyOwner {
QuirkiesV1Storage.layout().baseURI = baseURI_;
}
function setStakedBaseURI(string memory stakedBaseURI_) public onlyOwner {
QuirkiesV1Storage.layout().stakedBaseURI = stakedBaseURI_;
}
function setStakingContract(address stakingContract_, bool isStakingContract_) public onlyOwner {
QuirkiesV1Storage.layout().stakingContractsMap[stakingContract_] = isStakingContract_;
}
/**
* @dev Sets the default recommended creator royalty according to ERC2981
* @param receiver The address for royalties to be sent to
* @param feeNumerator Royalty in basis point (e.g. 1 == 0.01%, 500 == 5%)
*/
function setDefaultRoyalty(address receiver, uint96 feeNumerator) public onlyOwner {
_setDefaultRoyalty(receiver, feeNumerator);
}
function addToWhitelist(address[] memory addrs_) external onlyOwner {
IStrictAuthorizedTransferSecurityRegistry v = IStrictAuthorizedTransferSecurityRegistry(VALIDATOR_ADDRESS);
v.addAccountsToWhitelist(uint120(QuirkiesV1Storage.layout().operatorWhitelistID), addrs_);
}
function removeFromWhitelist(address[] memory addrs_) external onlyOwner {
IStrictAuthorizedTransferSecurityRegistry v = IStrictAuthorizedTransferSecurityRegistry(VALIDATOR_ADDRESS);
v.removeAccountsFromWhitelist(uint120(QuirkiesV1Storage.layout().operatorWhitelistID), addrs_);
}
function addAccountToAuthorizers(address account_) external onlyOwner {
IStrictAuthorizedTransferSecurityRegistry v = IStrictAuthorizedTransferSecurityRegistry(VALIDATOR_ADDRESS);
uint256 id = QuirkiesV1Storage.layout().operatorWhitelistID;
v.addAccountToAuthorizers(uint120(id), account_);
}
function addAccountsToAuthorizers(address[] memory accounts_) external onlyOwner {
IStrictAuthorizedTransferSecurityRegistry v = IStrictAuthorizedTransferSecurityRegistry(VALIDATOR_ADDRESS);
uint256 id = QuirkiesV1Storage.layout().operatorWhitelistID;
v.addAccountsToAuthorizers(uint120(id), accounts_);
}
function removeAccountFromAuthorizers(address account_) external onlyOwner {
IStrictAuthorizedTransferSecurityRegistry v = IStrictAuthorizedTransferSecurityRegistry(VALIDATOR_ADDRESS);
uint256 id = QuirkiesV1Storage.layout().operatorWhitelistID;
v.removeAccountFromAuthorizers(uint120(id), account_);
}
function removeAccountsFromAuthorizers(address[] memory accounts_) external onlyOwner {
IStrictAuthorizedTransferSecurityRegistry v = IStrictAuthorizedTransferSecurityRegistry(VALIDATOR_ADDRESS);
uint256 id = QuirkiesV1Storage.layout().operatorWhitelistID;
v.removeAccountsFromAuthorizers(uint120(id), accounts_);
}
/* -------------------------------------------------------------------------- */
/* views */
/* -------------------------------------------------------------------------- */
function baseURI() external view returns (string memory) {
return QuirkiesV1Storage.layout().baseURI;
}
function stakedBaseURI() external view returns (string memory) {
return QuirkiesV1Storage.layout().stakedBaseURI;
}
function isStaked(uint256 tokenID_) external view returns (bool) {
return QuirkiesV1Storage.layout().stakedMap[tokenID_] != address(0);
}
function isStakingContract(address address_) external view returns (bool) {
return QuirkiesV1Storage.layout().stakingContractsMap[address_];
}
function totalSupply() external pure returns (uint256) {
return 5000;
}
function operatorWhitelistID() external view returns (uint256) {
return QuirkiesV1Storage.layout().operatorWhitelistID;
}
/* -------------------------------------------------------------------------- */
/* staking */
/* -------------------------------------------------------------------------- */
function setStaked(uint256 tokenID_, bool staked_) external {
// check is authorized
if (!QuirkiesV1Storage.layout().stakingContractsMap[msg.sender]) {
revert ErrUnauthorizedStaker();
}
// stake
if (staked_) {
// check not staked
if (QuirkiesV1Storage.layout().stakedMap[tokenID_] != address(0)) {
revert ErrStaked();
}
QuirkiesV1Storage.layout().stakedMap[tokenID_] = msg.sender;
}
// unstake
else {
// check staked
if (QuirkiesV1Storage.layout().stakedMap[tokenID_] != msg.sender) {
revert ErrNotStaked();
}
delete QuirkiesV1Storage.layout().stakedMap[tokenID_];
}
}
/* -------------------------------------------------------------------------- */
/* erc721 */
/* -------------------------------------------------------------------------- */
function _beforeTokenTransfer(address from, address to, uint256 firstTokenId, uint256 batchSize)
internal
virtual
override
{
super._beforeTokenTransfer(from, to, firstTokenId, batchSize);
if (QuirkiesV1Storage.layout().stakedMap[firstTokenId] != address(0)) {
revert ErrStaked();
}
}
function _baseURI() internal view virtual override returns (string memory) {
return QuirkiesV1Storage.layout().baseURI;
}
function tokenURI(uint256 tokenId) public view override returns (string memory) {
_requireMinted(tokenId);
bool __isStaked = QuirkiesV1Storage.layout().stakedMap[tokenId] != address(0);
string memory baseURI = __isStaked ? QuirkiesV1Storage.layout().stakedBaseURI : _baseURI();
return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
}
function approve(address to, uint256 tokenId) public virtual override {
// Check if 'to' is whitelisted
IStrictAuthorizedTransferSecurityRegistry v = IStrictAuthorizedTransferSecurityRegistry(VALIDATOR_ADDRESS);
uint256 id = QuirkiesV1Storage.layout().operatorWhitelistID;
if (!v.isAccountWhitelisted(uint120(id), to)) revert("Operator not whitelisted");
super.approve(to, tokenId);
}
function setApprovalForAll(address operator, bool approved) public virtual override {
// Only check when granting approval, not revoking
if (approved) {
IStrictAuthorizedTransferSecurityRegistry v = IStrictAuthorizedTransferSecurityRegistry(VALIDATOR_ADDRESS);
uint256 id = QuirkiesV1Storage.layout().operatorWhitelistID;
if (!v.isAccountWhitelisted(uint120(id), operator)) revert("Operator not whitelisted");
}
super.setApprovalForAll(operator, approved);
}
/* -------------------------------------------------------------------------- */
/* erc165 overrides */
/* -------------------------------------------------------------------------- */
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(ERC721CUpgradeable, ERC2981Upgradeable)
returns (bool)
{
return ERC721CUpgradeable.supportsInterface(interfaceId) || ERC2981Upgradeable.supportsInterface(interfaceId);
}
/* -------------------------------------------------------------------------- */
/* creatorTokenBase overrides */
/* -------------------------------------------------------------------------- */
// creatorTokenBase overrides
function _requireCallerIsContractOwner() internal view override {
if (msg.sender != owner()) {
revert ErrNotOwner();
}
}
}
"
},
"src/ERC721C/upgradeable/ERC721CUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import {
CreatorTokenBaseUpgradeable,
ICreatorToken,
TransferSecurityLevels,
ICreatorTokenTransferValidator
} from "./CreatorTokenBaseUpgradeable.sol";
import {ERC721Upgradeable} from "openzeppelin-upgradeable/token/ERC721/ERC721Upgradeable.sol";
/**
* @title ERC721CInitializable
* @author Limit Break, Inc.
* @notice Initializable implementation of ERC721C to allow for EIP-1167 proxy clones.
*/
abstract contract ERC721CUpgradeable is ERC721Upgradeable, CreatorTokenBaseUpgradeable {
function __ERC721C_init(string memory name_, string memory symbol_) internal onlyInitializing {
__ERC721_init(name_, symbol_);
}
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(ICreatorToken).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @notice Returns the function selector for the transfer validator's validation function to be called
* @notice for transaction simulation.
*/
function getTransferValidationFunction() external pure returns (bytes4 functionSignature, bool isViewFunction) {
functionSignature = bytes4(keccak256("validateTransfer(address,address,address,uint256)"));
isViewFunction = true;
}
/// @dev Ties the open-zeppelin _beforeTokenTransfer hook to more granular transfer validation logic
function _beforeTokenTransfer(address from, address to, uint256 firstTokenId, uint256 batchSize)
internal
virtual
override
{
for (uint256 i = 0; i < batchSize;) {
_validateBeforeTransfer(from, to, firstTokenId + i);
unchecked {
++i;
}
}
}
/// @dev Ties the open-zeppelin _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;
}
}
}
}
"
},
"src/IStrictAuthorizedTransferSecurityRegistry.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
enum ListTypes {
AuthorizerList,
OperatorList,
OperatorRequiringAuthorizationList
}
enum TransferSecurityLevels {
Recommended,
One,
Two,
Three,
Four,
Five,
Six,
Seven,
Eight
}
/// @title IStrictAuthorizedTransferSecurityRegistry
/// @dev Interface for the Authorized Transfer Security Registry, a simplified version of the Transfer
/// Security Registry that only supports authorizers and whitelisted operators, and assumes a
/// security level of OperatorWhitelistEnableOTC + authorizers for all collections that use it.
/// Note that a number of view functions on collections that add this validator will not work.
interface IStrictAuthorizedTransferSecurityRegistry {
event CreatedList(uint256 indexed id, string name);
event AppliedListToCollection(address indexed collection, uint120 indexed id);
event ReassignedListOwnership(uint256 indexed id, address indexed newOwner);
event AddedAccountToList(ListTypes indexed kind, uint256 indexed id, address indexed account);
event RemovedAccountFromList(ListTypes indexed kind, uint256 indexed id, address indexed account);
event SetTransferSecurityLevel(address collection, TransferSecurityLevels level);
error StrictAuthorizedTransferSecurityRegistry__ListDoesNotExist();
error StrictAuthorizedTransferSecurityRegistry__CallerDoesNotOwnList();
error StrictAuthorizedTransferSecurityRegistry__ArrayLengthCannotBeZero();
error StrictAuthorizedTransferSecurityRegistry__CallerMustHaveElevatedPermissionsForSpecifiedNFT();
error StrictAuthorizedTransferSecurityRegistry__ListOwnershipCannotBeTransferredToZeroAddress();
error StrictAuthorizedTransferSecurityRegistry__ZeroAddressNotAllowed();
error StrictAuthorizedTransferSecurityRegistry__UnauthorizedTransfer();
error StrictAuthorizedTransferSecurityRegistry__CallerIsNotValidAuthorizer();
error StrictAuthorizedTransferSecurityRegistry__UnsupportedSecurityLevel();
error StrictAuthorizedTransferSecurityRegistry__UnsupportedSecurityLevelDetail();
error StrictAuthorizedTransferSecurityRegistry__CallerMustBeWhitelistedOperator();
error StrictAuthorizedTransferSecurityRegistry__ReceiverMustNotHaveDeployedCode();
error StrictAuthorizedTransferSecurityRegistry__ReceiverProofOfEOASignatureUnverified();
/// Manage lists of authorizers & operators that can be applied to collections
function createList(string calldata name) external returns (uint120);
function createListCopy(string calldata name, uint120 sourceListId) external returns (uint120);
function reassignOwnershipOfList(uint120 id, address newOwner) external;
function renounceOwnershipOfList(uint120 id) external;
function applyListToCollection(address collection, uint120 id) external;
function listOwners(uint120 id) external view returns (address);
/// Manage and query for authorizers on lists
function addAccountToAuthorizers(uint120 id, address account) external;
function addAccountsToAuthorizers(uint120 id, address[] calldata accounts) external;
function addAuthorizers(uint120 id, address[] calldata accounts) external;
function removeAccountFromAuthorizers(uint120 id, address account) external;
function removeAccountsFromAuthorizers(uint120 id, address[] calldata accounts) external;
function getAuthorizerAccounts(uint120 id) external view returns (address[] memory);
function isAccountAuthorizer(uint120 id, address account) external view returns (bool);
function getAuthorizerAccountsByCollection(address collection) external view returns (address[] memory);
function isAccountAuthorizerOfCollection(address collection, address account) external view returns (bool);
/// Manage and query for operators on lists
function addAccountToWhitelist(uint120 id, address account) external;
function addAccountsToWhitelist(uint120 id, address[] calldata accounts) external;
function addOperators(uint120 id, address[] calldata accounts) external;
function removeAccountFromWhitelist(uint120 id, address account) external;
function removeAccountsFromWhitelist(uint120 id, address[] calldata accounts) external;
function getWhitelistedAccounts(uint120 id) external view returns (address[] memory);
function isAccountWhitelisted(uint120 id, address account) external view returns (bool);
function getWhitelistedAccountsByCollection(address collection) external view returns (address[] memory);
function isAccountWhitelistedByCollection(address collection, address account) external view returns (bool);
/// Manage and query for blacklists on lists
function addAccountToBlacklist(uint120 id, address account) external;
function addAccountsToBlacklist(uint120 id, address[] calldata accounts) external;
function removeAccountFromBlacklist(uint120 id, address account) external;
function removeAccountsFromBlacklist(uint120 id, address[] calldata accounts) external;
function getBlacklistedAccounts(uint120 id) external view returns (address[] memory);
function isAccountBlacklisted(uint120 id, address account) external view returns (bool);
function getBlacklistedAccountsByCollection(address collection) external view returns (address[] memory);
function isAccountBlacklistedByCollection(address collection, address account) external view returns (bool);
function setTransferSecurityLevelOfCollection(
address collection,
uint8 level,
bool enableAuthorizationMode,
bool authorizersCanSetWildcardOperators,
bool enableAccountFreezingMode
) external;
function setTransferSecurityLevelOfCollection(address collection, TransferSecurityLevels level) external;
function isVerifiedEOA(address account) external view returns (bool);
/// Ensure that a specific operator has been authorized to transfer tokens
function validateTransfer(address caller, address from, address to) external view;
/// Ensure that a transfer has been authorized for a specific tokenId
function validateTransfer(address caller, address from, address to, uint256 tokenId) external view;
/// Ensure that a transfer has been authorized for a specific amount of a specific tokenId, and
/// reduce the transferable amount remaining
function validateTransfer(address caller, address from, address to, uint256 tokenId, uint256 amount) external;
/// Legacy alias for validateTransfer (address caller, address from, address to)
function applyCollectionTransferPolicy(address caller, address from, address to) external view;
/// Temporarily assign a specific allowed operator for a given collection
function beforeAuthorizedTransfer(address operator, address token) external;
/// Clear assignment of a specific allowed operator for a given collection
function afterAuthorizedTransfer(address token) external;
/// Temporarily allow a specific tokenId from a given collection to be transferred
function beforeAuthorizedTransfer(address token, uint256 tokenId) external;
/// Clear assignment of an specific tokenId's transfer allowance
function afterAuthorizedTransfer(address token, uint256 tokenId) external;
/// Temporarily allow a specific amount of a specific tokenId from a given collection to be transferred
function beforeAuthorizedTransferWithAmount(address token, uint256 tokenId, uint256 amount) external;
/// Clear assignment of a tokenId's transfer allowance for a specific amount
function afterAuthorizedTransferWithAmount(address token, uint256 tokenId) external;
}
"
},
"lib/openzeppelin-contracts-upgradeable/contracts/access/OwnableUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
function __Ownable_init() internal onlyInitializing {
__Ownable_init_unchained();
}
function __Ownable_init_unchained() internal onlyInitializing {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}
"
},
"lib/openzeppelin-contracts-upgradeable/contracts/token/common/ERC2981Upgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/common/ERC2981.sol)
pragma solidity ^0.8.0;
import "../../interfaces/IERC2981Upgradeable.sol";
import "../../utils/introspection/ERC165Upgradeable.sol";
import "../../proxy/utils/Initializable.sol";
/**
* @dev Implementation of the NFT Royalty Standard, a standardized way to retrieve royalty payment information.
*
* Royalty information can be specified globally for all token ids via {_setDefaultRoyalty}, and/or individually for
* specific token ids via {_setTokenRoyalty}. The latter takes precedence over the first.
*
* Royalty is specified as a fraction of sale price. {_feeDenominator} is overridable but defaults to 10000, meaning the
* fee is specified in basis points by default.
*
* IMPORTANT: ERC-2981 only specifies a way to signal royalty information and does not enforce its payment. See
* https://eips.ethereum.org/EIPS/eip-2981#optional-royalty-payments[Rationale] in the EIP. Marketplaces are expected to
* voluntarily pay royalties together with sales, but note that this standard is not yet widely supported.
*
* _Available since v4.5._
*/
abstract contract ERC2981Upgradeable is Initializable, IERC2981Upgradeable, ERC165Upgradeable {
function __ERC2981_init() internal onlyInitializing {
}
function __ERC2981_init_unchained() internal onlyInitializing {
}
struct RoyaltyInfo {
address receiver;
uint96 royaltyFraction;
}
RoyaltyInfo private _defaultRoyaltyInfo;
mapping(uint256 => RoyaltyInfo) private _tokenRoyaltyInfo;
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165Upgradeable, ERC165Upgradeable) returns (bool) {
return interfaceId == type(IERC2981Upgradeable).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @inheritdoc IERC2981Upgradeable
*/
function royaltyInfo(uint256 _tokenId, uint256 _salePrice) public view virtual override returns (address, uint256) {
RoyaltyInfo memory royalty = _tokenRoyaltyInfo[_tokenId];
if (royalty.receiver == address(0)) {
royalty = _defaultRoyaltyInfo;
}
uint256 royaltyAmount = (_salePrice * royalty.royaltyFraction) / _feeDenominator();
return (royalty.receiver, royaltyAmount);
}
/**
* @dev The denominator with which to interpret the fee set in {_setTokenRoyalty} and {_setDefaultRoyalty} as a
* fraction of the sale price. Defaults to 10000 so fees are expressed in basis points, but may be customized by an
* override.
*/
function _feeDenominator() internal pure virtual returns (uint96) {
return 10000;
}
/**
* @dev Sets the royalty information that all ids in this contract will default to.
*
* Requirements:
*
* - `receiver` cannot be the zero address.
* - `feeNumerator` cannot be greater than the fee denominator.
*/
function _setDefaultRoyalty(address receiver, uint96 feeNumerator) internal virtual {
require(feeNumerator <= _feeDenominator(), "ERC2981: royalty fee will exceed salePrice");
require(receiver != address(0), "ERC2981: invalid receiver");
_defaultRoyaltyInfo = RoyaltyInfo(receiver, feeNumerator);
}
/**
* @dev Removes default royalty information.
*/
function _deleteDefaultRoyalty() internal virtual {
delete _defaultRoyaltyInfo;
}
/**
* @dev Sets the royalty information for a specific token id, overriding the global default.
*
* Requirements:
*
* - `receiver` cannot be the zero address.
* - `feeNumerator` cannot be greater than the fee denominator.
*/
function _setTokenRoyalty(
uint256 tokenId,
address receiver,
uint96 feeNumerator
) internal virtual {
require(feeNumerator <= _feeDenominator(), "ERC2981: royalty fee will exceed salePrice");
require(receiver != address(0), "ERC2981: Invalid parameters");
_tokenRoyaltyInfo[tokenId] = RoyaltyInfo(receiver, feeNumerator);
}
/**
* @dev Resets royalty information for the token id back to the global default.
*/
function _resetTokenRoyalty(uint256 tokenId) internal virtual {
delete _tokenRoyaltyInfo[tokenId];
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[48] private __gap;
}
"
},
"lib/openzeppelin-contracts/contracts/utils/Strings.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)
pragma solidity ^0.8.0;
import "./math/Math.sol";
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
}
"
},
"src/ERC721C/upgradeable/CreatorTokenBaseUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "../OwnablePermissions.sol";
import "../interfaces/ICreatorToken.sol";
import "../interfaces/ICreatorTokenTransferValidator.sol";
import "../TransferValidation.sol";
import {IERC165} from "openzeppelin/interfaces/IERC165.sol";
library CreatorTokenBaseStorage {
struct Layout {
ICreatorTokenTransferValidator transferValidator;
}
bytes32 internal constant STORAGE_SLOT = keccak256("CreatorTokenBase.storage");
function layout() internal pure returns (Layout storage l) {
bytes32 slot = STORAGE_SLOT;
assembly {
l.slot := slot
}
}
}
/**
* @title CreatorTokenBase
* @author Limit Break, Inc.
* @notice CreatorTokenBase is an abstract contract that provides basic functionality for managing token
* transfer policies through an implementation of ICreatorTokenTransferValidator. This contract is intended to be used
* as a base for creator-specific token contracts, enabling customizable transfer restrictions and security policies.
*
* <h4>Features:</h4>
* <ul>Ownable: This contract can have an owner who can set and update the transfer validator.</ul>
* <ul>TransferValidation: Implements the basic token transfer validation interface.</ul>
* <ul>ICreatorToken: Implements the interface for creator tokens, providing view functions for token security policies.</ul>
*
* <h4>Benefits:</h4>
* <ul>Provides a flexible and modular way to implement custom token transfer restrictions and security policies.</ul>
* <ul>Allows creators to enforce policies such as whitelisted operators and permitted contract receivers.</ul>
* <ul>Can be easily integrated into other token contracts as a base contract.</ul>
*
* <h4>Intended Usage:</h4>
* <ul>Use as a base contract for creator token implementations that require advanced transfer restrictions and
* security policies.</ul>
* <ul>Set and update the ICreatorTokenTransferValidator implementation contract to enforce desired policies for the
* creator token.</ul>
*/
abstract contract CreatorTokenBaseUpgradeable is OwnablePermissions, TransferValidation, ICreatorToken {
error CreatorTokenBase__InvalidTransferValidatorContract();
error CreatorTokenBase__SetTransferValidatorFirst();
address public constant DEFAULT_TRANSFER_VALIDATOR = address(0x0000721C310194CcfC01E523fc93C9cCcFa2A0Ac);
TransferSecurityLevels public constant DEFAULT_TRANSFER_SECURITY_LEVEL = TransferSecurityLevels.One;
uint120 public constant DEFAULT_OPERATOR_WHITELIST_ID = uint120(1);
/**
* @notice Allows the contract owner to set the transfer validator to the official validator contract
* and set the security policy to the recommended default settings.
* @dev May be overridden to change the default behavior of an individual collection.
*/
function setToDefaultSecurityPolicy() public virtual {
_requireCallerIsContractOwner();
setTransferValidator(DEFAULT_TRANSFER_VALIDATOR);
ICreatorTokenTransferValidator(DEFAULT_TRANSFER_VALIDATOR).setTransferSecurityLevelOfCollection(
address(this), DEFAULT_TRANSFER_SECURITY_LEVEL
);
ICreatorTokenTransferValidator(DEFAULT_TRANSFER_VALIDATOR).setOperatorWhitelistOfCollection(
address(this), DEFAULT_OPERATOR_WHITELIST_ID
);
}
/**
* @notice Allows the contract owner to set the transfer validator to a custom validator contract
* and set the security policy to their own custom settings.
*/
function setToCustomValidatorAndSecurityPolicy(
address validator,
TransferSecurityLevels level,
uint120 operatorWhitelistId,
uint120 permittedContractReceiversAllowlistId
) public {
_requireCallerIsContractOwner();
setTransferValidator(validator);
ICreatorTokenTransferValidator(validator).setTransferSecurityLevelOfCollection(address(this), level);
ICreatorTokenTransferValidator(validator).setOperatorWhitelistOfCollection(address(this), operatorWhitelistId);
ICreatorTokenTransferValidator(validator).setPermittedContractReceiverAllowlistOfCollection(
address(this), permittedContractReceiversAllowlistId
);
}
/**
* @notice Allows the contract owner to set the security policy to their own custom settings.
* @dev Reverts if the transfer validator has not been set.
*/
function setToCustomSecurityPolicy(
TransferSecurityLevels level,
uint120 operatorWhitelistId,
uint120 permittedContractReceiversAllowlistId
) public {
_requireCallerIsContractOwner();
ICreatorTokenTransferValidator validator = ICreatorTokenTransferValidator(getTransferValidator());
if (address(validator) == address(0)) {
revert CreatorTokenBase__SetTransferValidatorFirst();
}
validator.setTransferSecurityLevelOfCollection(address(this), level);
validator.setOperatorWhitelistOfCollection(address(this), operatorWhitelistId);
validator.setPermittedContractReceiverAllowlistOfCollection(
address(this), permittedContractReceiversAllowlistId
);
}
/**
* @notice Sets the transfer validator for the token contract.
*
* @dev Throws when provided validator contract is not the zero address and doesn't support
* the ICreatorTokenTransferValidator interface.
* @dev Throws when the caller is not the contract owner.
*
* @dev <h4>Postconditions:</h4>
* 1. The transferValidator address is updated.
* 2. The `TransferValidatorUpdated` event is emitted.
*
* @param transferValidator_ The address of the transfer validator contract.
*/
function setTransferValidator(address transferValidator_) public {
_requireCallerIsContractOwner();
bool isValidTransferValidator = false;
if (transferValidator_.code.length > 0) {
try IERC165(transferValidator_).supportsInterface(type(ICreatorTokenTransferValidator).interfaceId)
returns (bool supportsInterface) {
isValidTransferValidator = supportsInterface;
} catch {}
}
if (transferValidator_ != address(0) && !isValidTransferValidator) {
revert CreatorTokenBase__InvalidTransferValidatorContract();
}
emit TransferValidatorUpdated(address(CreatorTokenBaseStorage.layout().transferValidator), transferValidator_);
CreatorTokenBaseStorage.layout().transferValidator = ICreatorTokenTransferValidator(transferValidator_);
}
/**
* @notice Returns the transfer validator contract address for this token contract.
*/
function getTransferValidator() public view override returns (address) {
return address(CreatorTokenBaseStorage.layout().transferValidator);
}
/**
* @notice Returns the security policy for this token contract, which includes:
* Transfer security level, operator whitelist id, permitted contract receiver allowlist id.
*/
function getSecurityPolicy() public view override returns (CollectionSecurityPolicy memory) {
if (address(CreatorTokenBaseStorage.layout().transferValidator) != address(0)) {
return CreatorTokenBaseStorage.layout().transferValidator.getCollectionSecurityPolicy(address(this));
}
return CollectionSecurityPolicy({
transferSecurityLevel: TransferSecurityLevels.Zero,
operatorWhitelistId: 0,
permittedContractReceiversId: 0
});
}
/**
* @notice Returns the list of all whitelisted operators for this token contract.
* @dev This can be an expensive call and should only be used in view-only functions.
*/
function getWhitelistedOperators() public view override returns (address[] memory) {
if (address(CreatorTokenBaseStorage.layout().transferValidator) != address(0)) {
return CreatorTokenBaseStorage.layout().transferValidator.getWhitelistedOperators(
CreatorTokenBaseStorage.layout().transferValidator.getCollectionSecurityPolicy(address(this))
.operatorWhitelistId
);
}
return new address[](0);
}
/**
* @notice Returns the list of permitted contract receivers for this token contract.
* @dev This can be an expensive call and should only be used in view-only functions.
*/
function getPermittedContractReceivers() public view override returns (address[] memory) {
if (address(CreatorTokenBaseStorage.layout().transferValidator) != address(0)) {
return CreatorTokenBaseStorage.layout().transferValidator.getPermittedContractReceivers(
CreatorTokenBaseStorage.layout().transferValidator.getCollectionSecurityPolicy(address(this))
.permittedContractReceiversId
);
}
return new address[](0);
}
/**
* @notice Checks if an operator is whitelisted for this token contract.
* @param operator The address of the operator to check.
*/
function isOperatorWhitelisted(address operator) public view override returns (bool) {
if (address(CreatorTokenBaseStorage.layout().transferValidator) != address(0)) {
return CreatorTokenBaseStorage.layout().transferValidator.isOperatorWhitelisted(
CreatorTokenBaseStorage.layout().transferValidator.getCollectionSecurityPolicy(address(this))
.operatorWhitelistId,
operator
);
}
return false;
}
/**
* @notice Checks if a contract receiver is permitted for this token contract.
* @param receiver The address of the receiver to check.
*/
function isContractReceiverPermitted(address receiver) public view override returns (bool) {
if (address(CreatorTokenBaseStorage.layout().transferValidator) != address(0)) {
return CreatorTokenBaseStorage.layout().transferValidator.isContractReceiverPermitted(
CreatorTokenBaseStorage.layout().transferValidator.getCollectionSecurityPolicy(address(this))
.permittedContractReceiversId,
receiver
);
}
return false;
}
/**
* @notice Determines if a transfer is allowed based on the token contract's security policy. Use this function
* to simulate whether or not a transfer made by the specified `caller` from the `from` address to the `to`
* address would be allowed by this token's security policy.
*
* @notice This function only checks the security policy restrictions and does not check whether token ownership
* or approvals are in place.
*
* @param caller The address of the simulated caller.
* @param from The address of the sender.
* @param to The address of the receiver.
* @return True if the transfer is allowed, false otherwise.
*/
function isTransferAllowed(address caller, address from, address to) public view override returns (bool) {
if (address(CreatorTokenBaseStorage.layout().transferValidator) != address(0)) {
try CreatorTokenBaseStorage.layout().transferValidator.applyCollectionTransferPolicy(caller, from, to) {
return true;
} catch {
return false;
}
}
return true;
}
/**
* @dev Pre-validates a token transfer, reverting if the transfer is not allowed by this token's security policy.
* Inheriting contracts are responsible for overriding the _beforeTokenTransfer function, or its equivalent
* and calling _validateBeforeTransfer so that checks can be properly applied during token transfers.
*
* @dev Throws when the transfer doesn't comply with the collection's transfer policy, if the transferValidator is
* set to a non-zero address.
*
* @param caller The address of the caller.
* @param from The address of the sender.
* @param to The address of the receiver.
*/
function _preValidateTransfer(address caller, address from, address to, uint256, /*tokenId*/ uint256 /*value*/ )
internal
virtual
override
{
if (address(CreatorTokenBaseStorage.layout().transferValidator) != address(0)) {
CreatorTokenBaseStorage.layout().transferValidator.applyCollectionTransferPolicy(caller, from, to);
}
}
}
"
},
"lib/openzeppelin-contracts-upgradeable/contracts/token/ERC721/ERC721Upgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.2) (token/ERC721/ERC721.sol)
pragma solidity ^0.8.0;
import "./IERC721Upgradeable.sol";
import "./IERC721ReceiverUpgradeable.sol";
import "./extensions/IERC721MetadataUpgradeable.sol";
import "../../utils/AddressUpgradeable.sol";
import "../../utils/ContextUpgradeable.sol";
import "../../utils/StringsUpgradeable.sol";
import "../../utils/introspection/ERC165Upgradeable.sol";
import "../../proxy/utils/Initializable.sol";
/**
* @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
* the Metadata extension, but not including the Enumerable extension, which is available separately as
* {ERC721Enumerable}.
*/
contract ERC721Upgradeable is Initializable, ContextUpgradeable, ERC165Upgradeable, IERC721Upgradeable, IERC721MetadataUpgradeable {
using AddressUpgradeable for address;
using StringsUpgradeable for uint256;
// Token name
string private _name;
// Token symbol
string private _symbol;
// Mapping from token ID to owner address
mapping(uint256 => address) private _owners;
// Mapping owner address to token count
mapping(address => uint256) private _balances;
// Mapping from token ID to approved address
mapping(uint256 => address) private _tokenApprovals;
// Mapping from owner to operator approvals
mapping(address => mapping(address => bool)) private _operatorApprovals;
/**
* @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
*/
function __ERC721_init(string memory name_, string memory symbol_) internal onlyInitializing {
__ERC721_init_unchained(name_, symbol_);
}
function __ERC721_init_unchained(string memory name_, string memory symbol_) internal onlyInitializing {
_name = name_;
_symbol = symbol_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165Upgradeable, IERC165Upgradeable) returns (bool) {
return
interfaceId == type(IERC721Upgradeable).interfaceId ||
interfaceId == type(IERC721MetadataUpgradeable).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721-balanceOf}.
*/
function balanceOf(address owner) public view virtual override returns (uint256) {
require(owner != address(0), "ERC721: address zero is not a valid owner");
return _balances[owner];
}
/**
* @dev See {IERC721-ownerOf}.
*/
function ownerOf(uint256 tokenId) public view virtual override returns (address) {
address owner = _ownerOf(tokenId);
require(owner != address(0), "ERC721: invalid token ID");
return owner;
}
/**
* @dev See {IERC721Metadata-name}.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev See {IERC721Metadata-symbol}.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
_requireMinted(tokenId);
string memory baseURI = _baseURI();
return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
}
/**
* @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
* token will be the concatenation of the `baseURI` and the `tokenId`. Empty
* by default, can be overridden in child contracts.
*/
function _baseURI() internal view virtual returns (string memory) {
return "";
}
/**
* @dev See {IERC721-approve}.
*/
function approve(address to, uint256 tokenId) public virtual override {
address owner = ERC721Upgradeable.ownerOf(tokenId);
require(to != owner, "ERC721: approval to current owner");
require(
_msgSender() == owner || isApprovedForAll(owner, _msgSender()),
"ERC721: approve caller is not token owner or approved for all"
);
_approve(to, tokenId);
}
/**
* @dev See {IERC721-getApproved}.
*/
function getApproved(uint256 tokenId) public view virtual override returns (address) {
_requireMinted(tokenId);
return _tokenApprovals[tokenId];
}
/**
* @dev See {IERC721-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual override {
_setApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC721-isApprovedForAll}.
*/
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
return _operatorApprovals[owner][operator];
}
/**
* @dev See {IERC721-transferFrom}.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
//solhint-disable-next-line max-line-length
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: caller is not token owner or approved");
_transfer(from, to, tokenId);
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes memory data
) public virtual override {
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: caller is not token owner or approved");
_safeTransfer(from, to, tokenId, data);
}
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* `data` is additional data, it has no specified format and it is sent in call to `to`.
*
* This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
* implement alternative mechanisms to perform token transfer, such as signature-based.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeTransfer(
address from,
address to,
uint256 tokenId,
bytes memory data
) internal virtual {
_transfer(from, to, tokenId);
require(_checkOnERC721Received(from, to, tokenId, data), "ERC721: transfer to non ERC721Receiver implementer");
}
/**
* @dev Returns the owner of the `tokenId`. Does NOT revert if token doesn't exist
*/
function _ownerOf(uint256 tokenId) internal view virtual returns (address) {
return _owners[tokenId];
}
/**
* @dev Returns whether `tokenId` exists.
*
* Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
*
* Tokens start existing when they are minted (`_mint`),
* and stop existing when they are burned (`_burn`).
*/
function _exists(uint256 tokenId) internal view virtual returns (bool) {
return _ownerOf(tokenId) != address(0);
}
/**
* @dev Returns whether `spender` is allowed to manage `tokenId`.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
address owner = ERC721Upgradeable.ownerOf(tokenId);
return (spender == owner || isApprovedForAll(owner, spender) || getApproved(tokenId) == spender);
}
/**
* @dev Safely mints `tokenId` and transfers it to `to`.
*
* Requirements:
*
* - `tokenId` must not exist.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeMint(address to, uint256 tokenId) internal virtual {
_safeMint(to, tokenId, "");
}
/**
* @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
function _safeMint(
address to,
uint256 tokenId,
bytes memory data
) internal virtual {
_mint(to, tokenId);
require(
_checkOnERC721Received(address(0), to, tokenId, data),
"ERC721: transfer to non ERC721Receiver implementer"
);
}
/**
* @dev Mints `tokenId` and transfers it to `to`.
*
* WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
*
* Requirements:
*
* - `tokenId` must not exist.
* - `to` cannot be the zero address.
*
* Emits a {Transfer} event.
*/
function _mint(address to, uint256 tokenId) internal virtual {
require(to != address(0), "ERC721: mint to the zero address");
require(!_exists(tokenId), "ERC721: token already minted");
_beforeTokenTransfer(address(0), to, tokenId, 1);
// Check that tokenId was not minted by `_beforeTokenTransfer` hook
require(!_exists(tokenId), "ERC721: token already minted");
unchecked {
// Will not overflow unless all 2**256 token ids are minted to the same owner.
// Given that tokens are minted one by one, it is impossible in practice that
// this ever happens. Might change if we allow batch minting.
// The ERC fails to describe this case.
_balances[to] += 1;
}
_owners[tokenId] = to;
emit Transfer(address(0), to, tokenId);
_afterTokenTransfer(address(0), to, tokenId, 1);
}
/**
* @dev Destroys `tokenId`.
* The approval is cleared when the token is burned.
* This is an internal function that does not check if the sender is authorized to operate on the token.
*
* Requirements:
*
* - `tokenId` must exist.
*
* Emits a {Transfer} event.
*/
function _burn(uint256 tokenId) internal virtual {
address owner = ERC721Upgradeable.ownerOf(tokenId);
_beforeTokenTransfer(owner, address(0), tokenId, 1);
// Update ownership in case tokenId was transferred by `_beforeTokenTransfer` hook
owner = ERC721Upgradeable.ownerOf(tokenId);
// Clear approvals
delete _tokenApprovals[tokenId];
unchecked {
// Cannot overflow, as that would require more tokens to be burned/transferred
// out than the owner initially received through minting and transferring in.
_balances[owner] -= 1;
}
delete _owners[tokenId];
emit Transfer(owner, address(0), tokenId);
_afterTokenTransfer(owner, address(0), tokenId, 1);
}
/**
* @dev Transfers `tokenId` from `from` to `to`.
* As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
*
* Emits a {Transfer} event.
*/
function _transfer(
address from,
address to,
uint256 tokenId
) internal virtual {
require(ERC721Upgradeable.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner");
require(to != address(0), "ERC721: transfer to the zero address");
_beforeTokenTransfer(from, to, tokenId, 1);
// Check that tokenId was not transferred by `_beforeTokenTransfer` hook
require(ERC721Upgradeable.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner");
// Clear approvals from the previous owner
delete _tokenApprovals[tokenId];
unchecked {
// `_balances[from]` cannot overflow for the same reason as described in `_burn`:
// `from`'s balance is the number of token held, which is at least one before the current
// transfer.
// `_balances[to]` could overflow in the conditions described in `_mint`. That would require
// all 2**256 token ids to be minted, which in practice is impossible.
_balances[from] -= 1;
_balances[to] += 1;
}
_owners[tokenId] = to;
emit Transfer(from, to, tokenId);
_afterTokenTransfer(from, to, tokenId, 1);
}
/**
* @dev Approve `to` to operate on `tokenId`
*
* Emits an {Approval} event.
*/
function _approve(address to, uint256 tokenId) internal virtual {
_tokenApprovals[tokenId] = to;
emit Approval(ERC721Upgradeable.ownerOf(tokenId), to, tokenId);
}
/**
* @dev Approve `operator` to operate on all of `owner` tokens
*
* Emits an {ApprovalForAll} event.
*/
function _setApprovalForAll(
address owner,
address operator,
bool approved
) internal virtual {
require(owner != operator, "ERC721: approve to caller");
_operatorApprovals[owner][operator] = approved;
emit ApprovalForAll(owner, operator, approved);
}
/**
* @dev Reverts if the `tokenId` has not been minted yet.
*/
function _requireMinted(uint256 tokenId) internal view virtual {
require(_exists(tokenId), "ERC721: invalid token ID");
}
/**
* @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
* The call is not executed if the target address is not a contract.
*
* @param from address representing the previous owner of the given token ID
* @param to target address that will receive the tokens
* @param tokenId uint256 ID of the token to be transferred
* @param data bytes optional data to send along with the call
* @return bool whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(
address from,
address to,
uint256 tokenId,
bytes memory data
) private returns (bool) {
if (to.isContract()) {
try IERC721ReceiverUpgradeable(to).onERC721Received(_msgSender(), from, tokenId, data) returns (bytes4 retval) {
return retval == IERC721ReceiverUpgradeable.onERC721Received.selector;
} catch (bytes memory reason) {
if (reason.length == 0) {
revert("ERC721: transfer to non ERC721Receiver implementer");
} else {
/// @solidity memory-safe-assembly
assembly {
revert(add(32, reason), mload(reason))
}
}
}
} else {
return true;
}
}
/**
* @dev Hook that is called before any token transfer. This includes minting and burning. If {ERC721Consecutive} is
* used, the hook may be called as part of a consecutive (batch) mint, as indicated by `batchSize` greater than 1.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s tokens will be transferred to `to`.
* - When `from` is zero, the tokens will be minted for `to`.
* - When `to` is zero, ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
* - `batchSize` is non-zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 firstTokenId,
uint256 batchSize
) internal virtual {}
/**
* @dev Hook that is called after any token transfer. This includes minting and burning. If {ERC721Consecutive} is
* used, the hook may be called as part of a consecutive (batch) mint, as indicated by `batchSize` greater than 1.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s tokens were transferred to `to`.
* - When `from` is zero, the tokens were minted for `to`.
* - When `to` is zero, ``from``'s tokens were burned.
* - `from` and `to` are never both zero.
* - `batchSize` is non-zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(
address from,
address to,
uint256 firstTokenId,
uint256 batchSize
) internal virtual {}
/**
* @dev Unsafe write access to the balances, used by extensions that "mint" tokens using an {ownerOf} override.
*
* WARNING: Anyone calling this MUST ensure that the balances remain consistent with the ownership. The invariant
* being that for any address `a` the value returned by `balanceOf(a)` must be equal to the number of tokens such
* that `ownerOf(tokenId)` is `a`.
*/
// solhint-disable-next-line func-name-mixedcase
function __unsafe_increaseBalance(address account, uint256 amount) internal {
_balances[account] += amount;
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* v
Submitted on: 2025-10-14 09:17:00
Comments
Log in to comment.
No comments yet.