{ "language": "Solidity", "sources": { "contracts/goosea.sol": { "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.8.17;\n\nimport { Base64 } from 'base64-sol/base64.sol';\nimport \"contract-allow-list/contracts/ERC721AntiScam/restrictApprove/ERC721RestrictApprove.sol\";\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"@openzeppelin/contracts/utils/cryptography/MerkleProof.sol\";\nimport \"@openzeppelin/contracts/token/common/ERC2981.sol\";\nimport \"@openzeppelin/contracts/security/ReentrancyGuard.sol\";\nimport {UpdatableOperatorFilterer} from \"operator-filter-registry/src/UpdatableOperatorFilterer.sol\";\nimport {RevokableDefaultOperatorFilterer} from \"operator-filter-registry/src/RevokableDefaultOperatorFilterer.sol\";\n\n\n\n//tokenURI interface\ninterface iTokenURI {\n function tokenURI(uint256 _tokenId) external view returns (string memory);\n}\n\n//SBT interface\ninterface iSbtCollection {\n function externalMint(address _address , uint256 _amount ) external payable;\n function balanceOf(address _owner) external view returns (uint);\n}\n\n\ncontract GooSeaContract is RevokableDefaultOperatorFilterer, ERC2981 ,Ownable, ERC721RestrictApprove ,AccessControl,ReentrancyGuard {\n\n constructor(\n ) ERC721Psi(\"Goosea\", \"GSA\") {\n \n //Role initialization\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n grantRole(MINTER_ROLE , msg.sender);\n grantRole(AIRDROP_ROLE , msg.sender);\n grantRole(ADMIN , msg.sender);\n\n\n setUseSingleMetadata(true);\n setMetadataTitle(\"GooSea\");\n setMetadataDescription(\"GooSea\");\n setMetadataAttributes(\"GooSea\");\n setImageURI(\"https://data.itsuzai.xyz/goosea/image/1.gif\");\n\n //CAL initialization\n setCALLevel(1);\n\n _setCAL(0xdbaa28cBe70aF04EbFB166b1A3E8F8034e5B9FC7);//Ethereum mainnet proxy\n //_setCAL(0xb506d7BbE23576b8AAf22477cd9A7FDF08002211);//Goerli testnet proxy\n\n _addLocalContractAllowList(0x1E0049783F008A0085193E00003D00cd54003c71);//OpenSea\n _addLocalContractAllowList(0x4feE7B061C97C9c496b01DbcE9CDb10c02f0a0Be);//Rarible\n //_addLocalContractAllowList(0xf42aa99F011A1fA7CDA90E5E98b277E306BcA83e);//looksrare\n //_addLocalContractAllowList(0xF849de01B080aDC3A814FaBE1E2087475cF2E354);//x2y2\n //_addLocalContractAllowList(0xb16c1342E617A5B6E4b631EB114483FDB289c0A4);//sudoswap\n //_addLocalContractAllowList(0x00000000000111AbE46ff893f3B2fdF1F759a8A8);//blur\n\n //initial mint\n _safeMint(msg.sender, 1);\n _burn(0);\n\n _safeMint(0x0a1A1569d5D1E69D2DF790f9De59891fe6B59dD9, 1);\n _safeMint(0x018988E3A863205dE9F227F1cA7A38221ea5CE2D, 1);\n _safeMint(0x832d725E181A32bc569551460f5bb3B619ef1B9b, 1);\n _safeMint(0x1D028D6fFEFbc9ec660aA30385733415F20f78fd, 1);\n _safeMint(0xeb03AAeC3754c1C1953ad52B42Cd234bE78F03D0, 1);\n _safeMint(0xdEcf4B112d4120B6998e5020a6B4819E490F7db6, 1);\n _safeMint(0x9643CaB1125C63CC0B9B06183FAF49ab891b26bD, 49);\n\n //Royalty\n setDefaultRoyalty(0x02F8E85E7A5b1EF6B2FDf82d75ACf26fC6CC4717 , 1000);\n setWithdrawAddress(0x9643CaB1125C63CC0B9B06183FAF49ab891b26bD);\n }\n\n //\n //withdraw section\n //\n\n address public withdrawAddress = 0xdEcf4B112d4120B6998e5020a6B4819E490F7db6;\n\n function setWithdrawAddress(address _withdrawAddress) public onlyOwner {\n withdrawAddress = _withdrawAddress;\n }\n\n function withdraw() public payable onlyOwner {\n (bool os, ) = payable(withdrawAddress).call{value: address(this).balance}('');\n require(os);\n }\n\n //\n //mint section\n //\n\n uint256 public cost = 50000000000000000;\n uint256 public maxSupply = 555;\n uint256 public maxMintAmountPerTransaction = 5;\n uint256 public publicSaleMaxMintAmountPerAddress = 5;\n bool public paused = true;\n\n bool public onlyAllowlisted = true;\n bool public mintCount = true;\n bool public burnAndMintMode = false;\n\n //0 : Merkle Tree\n //1 : Mapping\n uint256 public allowlistType = 0;\n bytes32 public merkleRoot;\n uint256 public saleId = 0;\n mapping(uint256 => mapping(address => uint256)) public userMintedAmount;\n mapping(uint256 => mapping(address => uint256)) public allowlistUserAmount;\n\n bool public mintWithSBT = false;\n iSbtCollection public sbtCollection;\n\n\n modifier callerIsUser() {\n require(tx.origin == msg.sender, \"The caller is another contract.\");\n _;\n }\n \n //mint with merkle tree\n function mint(uint256 _mintAmount , uint256 _maxMintAmount , bytes32[] calldata _merkleProof , uint256 _burnId ) public payable callerIsUser{\n require(!paused, \"the contract is paused\");\n require(0 < _mintAmount, \"need to mint at least 1 NFT\");\n require(_mintAmount <= maxMintAmountPerTransaction, \"max mint amount per session exceeded\");\n require( (_nextTokenId() -1) + _mintAmount <= maxSupply , \"max NFT limit exceeded\");\n require(cost * _mintAmount <= msg.value, \"insufficient funds\");\n\n uint256 maxMintAmountPerAddress;\n if(onlyAllowlisted == true) {\n if(allowlistType == 0){\n //Merkle tree\n bytes32 leaf = keccak256( abi.encodePacked(msg.sender, _maxMintAmount) );\n require(MerkleProof.verify(_merkleProof, merkleRoot, leaf), \"user is not allowlisted\");\n maxMintAmountPerAddress = _maxMintAmount;\n }else if(allowlistType == 1){\n //Mapping\n require( allowlistUserAmount[saleId][msg.sender] != 0 , \"user is not allowlisted\");\n maxMintAmountPerAddress = allowlistUserAmount[saleId][msg.sender];\n }\n }else{\n maxMintAmountPerAddress = publicSaleMaxMintAmountPerAddress;\n }\n\n if(mintCount == true){\n require(_mintAmount <= maxMintAmountPerAddress - userMintedAmount[saleId][msg.sender] , \"max NFT per address exceeded\");\n userMintedAmount[saleId][msg.sender] += _mintAmount;\n }\n\n if(burnAndMintMode == true ){\n require(_mintAmount == 1, \"The number of mints is over.\");\n require(msg.sender == ownerOf(_burnId) , \"Owner is different\");\n _burn(_burnId);\n }\n\n if( mintWithSBT == true ){\n if( sbtCollection.balanceOf(msg.sender) == 0 ){\n sbtCollection.externalMint(msg.sender,1);\n }\n }\n\n _safeMint(msg.sender, _mintAmount);\n }\n\n bytes32 public constant AIRDROP_ROLE = keccak256(\"AIRDROP_ROLE\");\n function airdropMint(address[] calldata _airdropAddresses , uint256[] memory _UserMintAmount) public {\n require(hasRole(AIRDROP_ROLE, msg.sender), \"Caller is not a air dropper\");\n require(_airdropAddresses.length == _UserMintAmount.length , \"Array lengths are different\");\n uint256 _mintAmount = 0;\n for (uint256 i = 0; i < _UserMintAmount.length; i++) {\n _mintAmount += _UserMintAmount[i];\n }\n require(0 < _mintAmount , \"need to mint at least 1 NFT\");\n require( (_nextTokenId() -1) + _mintAmount <= maxSupply , \"max NFT limit exceeded\"); \n for (uint256 i = 0; i < _UserMintAmount.length; i++) {\n _safeMint(_airdropAddresses[i], _UserMintAmount[i] );\n }\n }\n\n function currentTokenId() public view returns(uint256){\n return _nextTokenId() -1;\n }\n\n function setMintWithSBT(bool _mintWithSBT) public onlyRole(ADMIN) {\n mintWithSBT = _mintWithSBT;\n }\n\n function setSbtCollection(address _address) public onlyRole(ADMIN) {\n sbtCollection = iSbtCollection(_address);\n }\n\n function setBurnAndMintMode(bool _burnAndMintMode) public onlyRole(ADMIN) {\n burnAndMintMode = _burnAndMintMode;\n }\n\n function setMerkleRoot(bytes32 _merkleRoot) public onlyRole(ADMIN) {\n merkleRoot = _merkleRoot;\n }\n\n function setPause(bool _state) public onlyRole(ADMIN) {\n paused = _state;\n }\n\n function setAllowListType(uint256 _type)public onlyRole(ADMIN){\n require( _type == 0 || _type == 1 , \"Allow list type error\");\n allowlistType = _type;\n }\n\n function setAllowlistMapping(uint256 _saleId , address[] memory addresses, uint256[] memory saleSupplies) public onlyRole(ADMIN) {\n require(addresses.length == saleSupplies.length);\n for (uint256 i = 0; i < addresses.length; i++) {\n allowlistUserAmount[_saleId][addresses[i]] = saleSupplies[i];\n }\n }\n\n function getAllowlistUserAmount(address _address ) public view returns(uint256){\n return allowlistUserAmount[saleId][_address];\n }\n\n function getUserMintedAmountBySaleId(uint256 _saleId , address _address ) public view returns(uint256){\n return userMintedAmount[_saleId][_address];\n }\n\n function getUserMintedAmount(address _address ) public view returns(uint256){\n return userMintedAmount[saleId][_address];\n }\n\n function setSaleId(uint256 _saleId) public onlyRole(ADMIN) {\n saleId = _saleId;\n }\n\n function setMaxSupply(uint256 _maxSupply) public onlyRole(ADMIN) {\n maxSupply = _maxSupply;\n }\n\n function setPublicSaleMaxMintAmountPerAddress(uint256 _publicSaleMaxMintAmountPerAddress) public onlyRole(ADMIN) {\n publicSaleMaxMintAmountPerAddress = _publicSaleMaxMintAmountPerAddress;\n }\n\n function setCost(uint256 _newCost) public onlyRole(ADMIN) {\n cost = _newCost;\n }\n\n function setOnlyAllowlisted(bool _state) public onlyRole(ADMIN) {\n onlyAllowlisted = _state;\n }\n\n function setMaxMintAmountPerTransaction(uint256 _maxMintAmountPerTransaction) public onlyRole(ADMIN) {\n maxMintAmountPerTransaction = _maxMintAmountPerTransaction;\n }\n \n function setMintCount(bool _state) public onlyRole(ADMIN) {\n mintCount = _state;\n }\n \n\n\n //\n //URI section\n //\n\n string public baseURI;\n string public baseExtension = \".json\";\n\n function _baseURI() internal view virtual override returns (string memory) {\n return baseURI; \n }\n\n function setBaseURI(string memory _newBaseURI) public onlyRole(ADMIN) {\n baseURI = _newBaseURI;\n }\n\n function setBaseExtension(string memory _newBaseExtension) public onlyRole(ADMIN) {\n baseExtension = _newBaseExtension;\n }\n\n\n\n //\n //interface metadata\n //\n\n iTokenURI public interfaceOfTokenURI;\n bool public useInterfaceMetadata = false;\n\n function setInterfaceOfTokenURI(address _address) public onlyRole(ADMIN) {\n interfaceOfTokenURI = iTokenURI(_address);\n }\n\n function setUseInterfaceMetadata(bool _useInterfaceMetadata) public onlyRole(ADMIN) {\n useInterfaceMetadata = _useInterfaceMetadata;\n }\n\n\n\n //\n //single metadata\n //\n\n bool public useSingleMetadata = false;\n string public imageURI;\n string public metadataTitle;\n string public metadataDescription;\n string public metadataAttributes;\n bool public useAnimationUrl = false;\n string public animationURI;\n\n //single image metadata\n function setUseSingleMetadata(bool _useSingleMetadata) public onlyRole(ADMIN) {\n useSingleMetadata = _useSingleMetadata;\n }\n function setMetadataTitle(string memory _metadataTitle) public onlyRole(ADMIN) {\n metadataTitle = _metadataTitle;\n }\n function setMetadataDescription(string memory _metadataDescription) public onlyRole(ADMIN) {\n metadataDescription = _metadataDescription;\n }\n function setMetadataAttributes(string memory _metadataAttributes) public onlyRole(ADMIN) {\n metadataAttributes = _metadataAttributes;\n }\n function setImageURI(string memory _ImageURI) public onlyRole(ADMIN) {\n imageURI = _ImageURI;\n }\n function setUseAnimationUrl(bool _useAnimationUrl) public onlyRole(ADMIN) {\n useAnimationUrl = _useAnimationUrl;\n }\n function setAnimationURI(string memory _animationURI) public onlyRole(ADMIN) {\n animationURI = _animationURI;\n }\n\n\n\n //\n //token URI\n //\n\n function tokenURI(uint256 tokenId) public view override returns (string memory) {\n if (useInterfaceMetadata == true) {\n return interfaceOfTokenURI.tokenURI(tokenId);\n }\n if(useSingleMetadata == true){\n return string( abi.encodePacked( 'data:application/json;base64,' , Base64.encode(\n abi.encodePacked(\n '{',\n '\"name\":\"' , metadataTitle ,'\",' ,\n '\"description\":\"' , metadataDescription , '\",' ,\n '\"image\": \"' , imageURI , '\",' ,\n useAnimationUrl==true ? string(abi.encodePacked('\"animation_url\": \"' , animationURI , '\",')) :\"\" ,\n '\"attributes\":[{\"trait_type\":\"type\",\"value\":\"' , metadataAttributes , '\"}]',\n '}'\n )\n ) ) );\n }\n return string(abi.encodePacked(ERC721Psi.tokenURI(tokenId), baseExtension));\n }\n\n\n\n\n //\n //burnin' section\n //\n\n bytes32 public constant MINTER_ROLE = keccak256(\"MINTER_ROLE\");\n bytes32 public constant BURNER_ROLE = keccak256(\"BURNER_ROLE\");\n\n function externalMint(address _address , uint256 _amount ) external payable {\n require(hasRole(MINTER_ROLE, msg.sender), \"Caller is not a minter\");\n require( (_nextTokenId() -1) + _amount <= maxSupply , \"max NFT limit exceeded\");\n _safeMint( _address, _amount );\n }\n\n function externalBurn(uint256[] memory _burnTokenIds) external nonReentrant{\n require(hasRole(BURNER_ROLE, msg.sender), \"Caller is not a burner\");\n for (uint256 i = 0; i < _burnTokenIds.length; i++) {\n uint256 tokenId = _burnTokenIds[i];\n require(tx.origin == ownerOf(tokenId) , \"Owner is different\");\n _burn(tokenId);\n } \n }\n\n\n\n //\n //sbt and opensea filter section\n //\n\n bool public isSBT = false;\n\n function setIsSBT(bool _state) public onlyRole(ADMIN) {\n isSBT = _state;\n }\n\n function _beforeTokenTransfers( address from, address to, uint256 startTokenId, uint256 quantity) internal virtual override{\n require( isSBT == false || from == address(0) || to == address(0)|| to == address(0x000000000000000000000000000000000000dEaD), \"transfer is prohibited\");\n super._beforeTokenTransfers(from, to, startTokenId, quantity);\n }\n\n function setApprovalForAll(address operator, bool approved) public virtual override onlyAllowedOperatorApproval(operator){\n require( isSBT == false || approved == false , \"setApprovalForAll is prohibited\");\n super.setApprovalForAll(operator, approved);\n }\n\n function approve(address operator, uint256 tokenId) public virtual override onlyAllowedOperatorApproval(operator){\n require( isSBT == false , \"approve is prohibited\");\n super.approve(operator, tokenId);\n }\n\n function transferFrom(address from, address to, uint256 tokenId) public override onlyAllowedOperator(from) {\n super.transferFrom(from, to, tokenId);\n }\n\n function safeTransferFrom(address from, address to, uint256 tokenId) public override onlyAllowedOperator(from) {\n super.safeTransferFrom(from, to, tokenId);\n }\n\n function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public override onlyAllowedOperator(from) {\n super.safeTransferFrom(from, to, tokenId, data);\n }\n\n function owner() public view virtual override (Ownable, UpdatableOperatorFilterer) returns (address) {\n return Ownable.owner();\n }\n\n\n\n\n //\n //ERC721PsiAddressData section\n //\n\n // Mapping owner address to address data\n mapping(address => AddressData) _addressData;\n\n // Compiler will pack this into a single 256bit word.\n struct AddressData {\n // Realistically, 2**64-1 is more than enough.\n uint64 balance;\n // Keeps track of mint count with minimal overhead for tokenomics.\n uint64 numberMinted;\n // Keeps track of burn count with minimal overhead for tokenomics.\n uint64 numberBurned;\n // For miscellaneous variable(s) pertaining to the address\n // (e.g. number of whitelist mint slots used).\n // If there are multiple variables, please pack them into a uint64.\n uint64 aux;\n }\n\n\n /**\n * @dev See {IERC721-balanceOf}.\n */\n function balanceOf(address _owner) \n public \n view \n virtual \n override \n returns (uint) \n {\n require(_owner != address(0), \"ERC721Psi: balance query for the zero address\");\n return uint256(_addressData[_owner].balance); \n }\n\n /**\n * @dev Hook that is called after a set of serially-ordered token ids have been transferred. This includes\n * minting.\n *\n * startTokenId - the first token id to be transferred\n * quantity - the amount to be transferred\n *\n * Calling conditions:\n *\n * - when `from` and `to` are both non-zero.\n * - `from` and `to` are never both zero.\n */\n function _afterTokenTransfers(\n address from,\n address to,\n uint256 startTokenId,\n uint256 quantity\n ) internal override virtual {\n require(quantity < 2 ** 64);\n uint64 _quantity = uint64(quantity);\n\n if(from != address(0)){\n _addressData[from].balance -= _quantity;\n } else {\n // Mint\n _addressData[to].numberMinted += _quantity;\n }\n\n if(to != address(0)){\n _addressData[to].balance += _quantity;\n } else {\n // Burn\n _addressData[from].numberBurned += _quantity;\n }\n super._afterTokenTransfers(from, to, startTokenId, quantity);\n }\n\n\n\n\n //\n //ERC721AntiScam section\n //\n\n bytes32 public constant ADMIN = keccak256(\"ADMIN\");\n\n function setEnebleRestrict(bool _enableRestrict )public onlyRole(ADMIN){\n enableRestrict = _enableRestrict;\n }\n\n /*///////////////////////////////////////////////////////////////\n OVERRIDES ERC721RestrictApprove\n //////////////////////////////////////////////////////////////*/\n function addLocalContractAllowList(address transferer)\n external\n override\n onlyRole(ADMIN)\n {\n _addLocalContractAllowList(transferer);\n }\n\n function removeLocalContractAllowList(address transferer)\n external\n override\n onlyRole(ADMIN)\n {\n _removeLocalContractAllowList(transferer);\n }\n\n function getLocalContractAllowList()\n external\n override\n view\n returns(address[] memory)\n {\n return _getLocalContractAllowList();\n }\n\n function setCALLevel(uint256 level) public override onlyRole(ADMIN) {\n CALLevel = level;\n }\n\n function setCAL(address calAddress) external override onlyRole(ADMIN) {\n _setCAL(calAddress);\n }\n\n\n\n\n //\n //setDefaultRoyalty\n //\n function setDefaultRoyalty(address _receiver, uint96 _feeNumerator) public onlyOwner{\n _setDefaultRoyalty(_receiver, _feeNumerator);\n }\n\n\n\n /*///////////////////////////////////////////////////////////////\n OVERRIDES ERC721RestrictApprove\n //////////////////////////////////////////////////////////////*/\n function supportsInterface(bytes4 interfaceId)\n public\n view\n override(ERC2981,ERC721RestrictApprove, AccessControl)\n returns (bool)\n {\n return\n ERC2981.supportsInterface(interfaceId) ||\n AccessControl.supportsInterface(interfaceId) ||\n ERC721RestrictApprove.supportsInterface(interfaceId);\n }\n\n\n \n\n}" }, "operator-filter-registry/src/RevokableDefaultOperatorFilterer.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.13;\n\nimport {RevokableOperatorFilterer} from \"./RevokableOperatorFilterer.sol\";\n\n/**\n * @title RevokableDefaultOperatorFilterer\n * @notice Inherits from RevokableOperatorFilterer and automatically subscribes to the default OpenSea subscription.\n * Note that OpenSea will disable creator fee enforcement if filtered operators begin fulfilling orders\n * on-chain, eg, if the registry is revoked or bypassed.\n */\nabstract contract RevokableDefaultOperatorFilterer is RevokableOperatorFilterer {\n address constant DEFAULT_SUBSCRIPTION = address(0x3cc6CddA760b79bAfa08dF41ECFA224f810dCeB6);\n\n constructor() RevokableOperatorFilterer(0x000000000000AAeB6D7670E522A718067333cd4E, DEFAULT_SUBSCRIPTION, true) {}\n}\n" }, "operator-filter-registry/src/UpdatableOperatorFilterer.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.13;\n\nimport {IOperatorFilterRegistry} from \"./IOperatorFilterRegistry.sol\";\n\n/**\n * @title UpdatableOperatorFilterer\n * @notice Abstract contract whose constructor automatically registers and optionally subscribes to or copies another\n * registrant's entries in the OperatorFilterRegistry. This contract allows the Owner to update the\n * OperatorFilterRegistry address via updateOperatorFilterRegistryAddress, including to the zero address,\n * which will bypass registry checks.\n * Note that OpenSea will still disable creator fee enforcement if filtered operators begin fulfilling orders\n * on-chain, eg, if the registry is revoked or bypassed.\n * @dev This smart contract is meant to be inherited by token contracts so they can use the following:\n * - `onlyAllowedOperator` modifier for `transferFrom` and `safeTransferFrom` methods.\n * - `onlyAllowedOperatorApproval` modifier for `approve` and `setApprovalForAll` methods.\n */\nabstract contract UpdatableOperatorFilterer {\n error OperatorNotAllowed(address operator);\n error OnlyOwner();\n\n IOperatorFilterRegistry public operatorFilterRegistry;\n\n constructor(address _registry, address subscriptionOrRegistrantToCopy, bool subscribe) {\n IOperatorFilterRegistry registry = IOperatorFilterRegistry(_registry);\n operatorFilterRegistry = registry;\n // If an inheriting token contract is deployed to a network without the registry deployed, the modifier\n // will not revert, but the contract will need to be registered with the registry once it is deployed in\n // order for the modifier to filter addresses.\n if (address(registry).code.length > 0) {\n if (subscribe) {\n registry.registerAndSubscribe(address(this), subscriptionOrRegistrantToCopy);\n } else {\n if (subscriptionOrRegistrantToCopy != address(0)) {\n registry.registerAndCopyEntries(address(this), subscriptionOrRegistrantToCopy);\n } else {\n registry.register(address(this));\n }\n }\n }\n }\n\n modifier onlyAllowedOperator(address from) virtual {\n // Allow spending tokens from addresses with balance\n // Note that this still allows listings and marketplaces with escrow to transfer tokens if transferred\n // from an EOA.\n if (from != msg.sender) {\n _checkFilterOperator(msg.sender);\n }\n _;\n }\n\n modifier onlyAllowedOperatorApproval(address operator) virtual {\n _checkFilterOperator(operator);\n _;\n }\n\n /**\n * @notice Update the address that the contract will make OperatorFilter checks against. When set to the zero\n * address, checks will be bypassed. OnlyOwner.\n */\n function updateOperatorFilterRegistryAddress(address newRegistry) public virtual {\n if (msg.sender != owner()) {\n revert OnlyOwner();\n }\n operatorFilterRegistry = IOperatorFilterRegistry(newRegistry);\n }\n\n /**\n * @dev assume the contract has an owner, but leave specific Ownable implementation up to inheriting contract\n */\n function owner() public view virtual returns (address);\n\n function _checkFilterOperator(address operator) internal view virtual {\n IOperatorFilterRegistry registry = operatorFilterRegistry;\n // Check registry code length to facilitate testing in environments without a deployed registry.\n if (address(registry) != address(0) && address(registry).code.length > 0) {\n if (!registry.isOperatorAllowed(address(this), operator)) {\n revert OperatorNotAllowed(operator);\n }\n }\n }\n}\n" }, "@openzeppelin/contracts/security/ReentrancyGuard.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (security/ReentrancyGuard.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Contract module that helps prevent reentrant calls to a function.\n *\n * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\n * available, which can be applied to functions to make sure there are no nested\n * (reentrant) calls to them.\n *\n * Note that because there is a single `nonReentrant` guard, functions marked as\n * `nonReentrant` may not call one another. This can be worked around by making\n * those functions `private`, and then adding `external` `nonReentrant` entry\n * points to them.\n *\n * TIP: If you would like to learn more about reentrancy and alternative ways\n * to protect against it, check out our blog post\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\n */\nabstract contract ReentrancyGuard {\n // Booleans are more expensive than uint256 or any type that takes up a full\n // word because each write operation emits an extra SLOAD to first read the\n // slot's contents, replace the bits taken up by the boolean, and then write\n // back. This is the compiler's defense against contract upgrades and\n // pointer aliasing, and it cannot be disabled.\n\n // The values being non-zero value makes deployment a bit more expensive,\n // but in exchange the refund on every call to nonReentrant will be lower in\n // amount. Since refunds are capped to a percentage of the total\n // transaction's gas, it is best to keep them low in cases like this one, to\n // increase the likelihood of the full refund coming into effect.\n uint256 private constant _NOT_ENTERED = 1;\n uint256 private constant _ENTERED = 2;\n\n uint256 private _status;\n\n constructor() {\n _status = _NOT_ENTERED;\n }\n\n /**\n * @dev Prevents a contract from calling itself, directly or indirectly.\n * Calling a `nonReentrant` function from another `nonReentrant`\n * function is not supported. It is possible to prevent this from happening\n * by making the `nonReentrant` function external, and making it call a\n * `private` function that does the actual work.\n */\n modifier nonReentrant() {\n _nonReentrantBefore();\n _;\n _nonReentrantAfter();\n }\n\n function _nonReentrantBefore() private {\n // On the first call to nonReentrant, _status will be _NOT_ENTERED\n require(_status != _ENTERED, \"ReentrancyGuard: reentrant call\");\n\n // Any calls to nonReentrant after this point will fail\n _status = _ENTERED;\n }\n\n function _nonReentrantAfter() private {\n // By storing the original value once again, a refund is triggered (see\n // https://eips.ethereum.org/EIPS/eip-2200)\n _status = _NOT_ENTERED;\n }\n}\n" }, "@openzeppelin/contracts/token/common/ERC2981.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (token/common/ERC2981.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../../interfaces/IERC2981.sol\";\nimport \"../../utils/introspection/ERC165.sol\";\n\n/**\n * @dev Implementation of the NFT Royalty Standard, a standardized way to retrieve royalty payment information.\n *\n * Royalty information can be specified globally for all token ids via {_setDefaultRoyalty}, and/or individually for\n * specific token ids via {_setTokenRoyalty}. The latter takes precedence over the first.\n *\n * Royalty is specified as a fraction of sale price. {_feeDenominator} is overridable but defaults to 10000, meaning the\n * fee is specified in basis points by default.\n *\n * IMPORTANT: ERC-2981 only specifies a way to signal royalty information and does not enforce its payment. See\n * https://eips.ethereum.org/EIPS/eip-2981#optional-royalty-payments[Rationale] in the EIP. Marketplaces are expected to\n * voluntarily pay royalties together with sales, but note that this standard is not yet widely supported.\n *\n * _Available since v4.5._\n */\nabstract contract ERC2981 is IERC2981, ERC165 {\n struct RoyaltyInfo {\n address receiver;\n uint96 royaltyFraction;\n }\n\n RoyaltyInfo private _defaultRoyaltyInfo;\n mapping(uint256 => RoyaltyInfo) private _tokenRoyaltyInfo;\n\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC165) returns (bool) {\n return interfaceId == type(IERC2981).interfaceId || super.supportsInterface(interfaceId);\n }\n\n /**\n * @inheritdoc IERC2981\n */\n function royaltyInfo(uint256 _tokenId, uint256 _salePrice) public view virtual override returns (address, uint256) {\n RoyaltyInfo memory royalty = _tokenRoyaltyInfo[_tokenId];\n\n if (royalty.receiver == address(0)) {\n royalty = _defaultRoyaltyInfo;\n }\n\n uint256 royaltyAmount = (_salePrice * royalty.royaltyFraction) / _feeDenominator();\n\n return (royalty.receiver, royaltyAmount);\n }\n\n /**\n * @dev The denominator with which to interpret the fee set in {_setTokenRoyalty} and {_setDefaultRoyalty} as a\n * fraction of the sale price. Defaults to 10000 so fees are expressed in basis points, but may be customized by an\n * override.\n */\n function _feeDenominator() internal pure virtual returns (uint96) {\n return 10000;\n }\n\n /**\n * @dev Sets the royalty information that all ids in this contract will default to.\n *\n * Requirements:\n *\n * - `receiver` cannot be the zero address.\n * - `feeNumerator` cannot be greater than the fee denominator.\n */\n function _setDefaultRoyalty(address receiver, uint96 feeNumerator) internal virtual {\n require(feeNumerator <= _feeDenominator(), \"ERC2981: royalty fee will exceed salePrice\");\n require(receiver != address(0), \"ERC2981: invalid receiver\");\n\n _defaultRoyaltyInfo = RoyaltyInfo(receiver, feeNumerator);\n }\n\n /**\n * @dev Removes default royalty information.\n */\n function _deleteDefaultRoyalty() internal virtual {\n delete _defaultRoyaltyInfo;\n }\n\n /**\n * @dev Sets the royalty information for a specific token id, overriding the global default.\n *\n * Requirements:\n *\n * - `receiver` cannot be the zero address.\n * - `feeNumerator` cannot be greater than the fee denominator.\n */\n function _setTokenRoyalty(\n uint256 tokenId,\n address receiver,\n uint96 feeNumerator\n ) internal virtual {\n require(feeNumerator <= _feeDenominator(), \"ERC2981: royalty fee will exceed salePrice\");\n require(receiver != address(0), \"ERC2981: Invalid parameters\");\n\n _tokenRoyaltyInfo[tokenId] = RoyaltyInfo(receiver, feeNumerator);\n }\n\n /**\n * @dev Resets royalty information for the token id back to the global default.\n */\n function _resetTokenRoyalty(uint256 tokenId) internal virtual {\n delete _tokenRoyaltyInfo[tokenId];\n }\n}\n" }, "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/cryptography/MerkleProof.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev These functions deal with verification of Merkle Tree proofs.\n *\n * The tree and the proofs can be generated using our\n * https://github.com/OpenZeppelin/merkle-tree[JavaScript library].\n * You will find a quickstart guide in the readme.\n *\n * WARNING: You should avoid using leaf values that are 64 bytes long prior to\n * hashing, or use a hash function other than keccak256 for hashing leaves.\n * This is because the concatenation of a sorted pair of internal nodes in\n * the merkle tree could be reinterpreted as a leaf value.\n * OpenZeppelin's JavaScript library generates merkle trees that are safe\n * against this attack out of the box.\n */\nlibrary MerkleProof {\n /**\n * @dev Returns true if a `leaf` can be proved to be a part of a Merkle tree\n * defined by `root`. For this, a `proof` must be provided, containing\n * sibling hashes on the branch from the leaf to the root of the tree. Each\n * pair of leaves and each pair of pre-images are assumed to be sorted.\n */\n function verify(\n bytes32[] memory proof,\n bytes32 root,\n bytes32 leaf\n ) internal pure returns (bool) {\n return processProof(proof, leaf) == root;\n }\n\n /**\n * @dev Calldata version of {verify}\n *\n * _Available since v4.7._\n */\n function verifyCalldata(\n bytes32[] calldata proof,\n bytes32 root,\n bytes32 leaf\n ) internal pure returns (bool) {\n return processProofCalldata(proof, leaf) == root;\n }\n\n /**\n * @dev Returns the rebuilt hash obtained by traversing a Merkle tree up\n * from `leaf` using `proof`. A `proof` is valid if and only if the rebuilt\n * hash matches the root of the tree. When processing the proof, the pairs\n * of leafs & pre-images are assumed to be sorted.\n *\n * _Available since v4.4._\n */\n function processProof(bytes32[] memory proof, bytes32 leaf) internal pure returns (bytes32) {\n bytes32 computedHash = leaf;\n for (uint256 i = 0; i < proof.length; i++) {\n computedHash = _hashPair(computedHash, proof[i]);\n }\n return computedHash;\n }\n\n /**\n * @dev Calldata version of {processProof}\n *\n * _Available since v4.7._\n */\n function processProofCalldata(bytes32[] calldata proof, bytes32 leaf) internal pure returns (bytes32) {\n bytes32 computedHash = leaf;\n for (uint256 i = 0; i < proof.length; i++) {\n computedHash = _hashPair(computedHash, proof[i]);\n }\n return computedHash;\n }\n\n /**\n * @dev Returns true if the `leaves` can be simultaneously proven to be a part of a merkle tree defined by\n * `root`, according to `proof` and `proofFlags` as described in {processMultiProof}.\n *\n * CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details.\n *\n * _Available since v4.7._\n */\n function multiProofVerify(\n bytes32[] memory proof,\n bool[] memory proofFlags,\n bytes32 root,\n bytes32[] memory leaves\n ) internal pure returns (bool) {\n return processMultiProof(proof, proofFlags, leaves) == root;\n }\n\n /**\n * @dev Calldata version of {multiProofVerify}\n *\n * CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details.\n *\n * _Available since v4.7._\n */\n function multiProofVerifyCalldata(\n bytes32[] calldata proof,\n bool[] calldata proofFlags,\n bytes32 root,\n bytes32[] memory leaves\n ) internal pure returns (bool) {\n return processMultiProofCalldata(proof, proofFlags, leaves) == root;\n }\n\n /**\n * @dev Returns the root of a tree reconstructed from `leaves` and sibling nodes in `proof`. The reconstruction\n * proceeds by incrementally reconstructing all inner nodes by combining a leaf/inner node with either another\n * leaf/inner node or a proof sibling node, depending on whether each `proofFlags` item is true or false\n * respectively.\n *\n * CAUTION: Not all merkle trees admit multiproofs. To use multiproofs, it is sufficient to ensure that: 1) the tree\n * is complete (but not necessarily perfect), 2) the leaves to be proven are in the opposite order they are in the\n * tree (i.e., as seen from right to left starting at the deepest layer and continuing at the next layer).\n *\n * _Available since v4.7._\n */\n function processMultiProof(\n bytes32[] memory proof,\n bool[] memory proofFlags,\n bytes32[] memory leaves\n ) internal pure returns (bytes32 merkleRoot) {\n // This function rebuild the root hash by traversing the tree up from the leaves. The root is rebuilt by\n // consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the\n // `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of\n // the merkle tree.\n uint256 leavesLen = leaves.length;\n uint256 totalHashes = proofFlags.length;\n\n // Check proof validity.\n require(leavesLen + proof.length - 1 == totalHashes, \"MerkleProof: invalid multiproof\");\n\n // The xxxPos values are \"pointers\" to the next value to consume in each array. All accesses are done using\n // `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's \"pop\".\n bytes32[] memory hashes = new bytes32[](totalHashes);\n uint256 leafPos = 0;\n uint256 hashPos = 0;\n uint256 proofPos = 0;\n // At each step, we compute the next hash using two values:\n // - a value from the \"main queue\". If not all leaves have been consumed, we get the next leaf, otherwise we\n // get the next hash.\n // - depending on the flag, either another value for the \"main queue\" (merging branches) or an element from the\n // `proof` array.\n for (uint256 i = 0; i < totalHashes; i++) {\n bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];\n bytes32 b = proofFlags[i] ? leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++] : proof[proofPos++];\n hashes[i] = _hashPair(a, b);\n }\n\n if (totalHashes > 0) {\n return hashes[totalHashes - 1];\n } else if (leavesLen > 0) {\n return leaves[0];\n } else {\n return proof[0];\n }\n }\n\n /**\n * @dev Calldata version of {processMultiProof}.\n *\n * CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details.\n *\n * _Available since v4.7._\n */\n function processMultiProofCalldata(\n bytes32[] calldata proof,\n bool[] calldata proofFlags,\n bytes32[] memory leaves\n ) internal pure returns (bytes32 merkleRoot) {\n // This function rebuild the root hash by traversing the tree up from the leaves. The root is rebuilt by\n // consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the\n // `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of\n // the merkle tree.\n uint256 leavesLen = leaves.length;\n uint256 totalHashes = proofFlags.length;\n\n // Check proof validity.\n require(leavesLen + proof.length - 1 == totalHashes, \"MerkleProof: invalid multiproof\");\n\n // The xxxPos values are \"pointers\" to the next value to consume in each array. All accesses are done using\n // `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's \"pop\".\n bytes32[] memory hashes = new bytes32[](totalHashes);\n uint256 leafPos = 0;\n uint256 hashPos = 0;\n uint256 proofPos = 0;\n // At each step, we compute the next hash using two values:\n // - a value from the \"main queue\". If not all leaves have been consumed, we get the next leaf, otherwise we\n // get the next hash.\n // - depending on the flag, either another value for the \"main queue\" (merging branches) or an element from the\n // `proof` array.\n for (uint256 i = 0; i < totalHashes; i++) {\n bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];\n bytes32 b = proofFlags[i] ? leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++] : proof[proofPos++];\n hashes[i] = _hashPair(a, b);\n }\n\n if (totalHashes > 0) {\n return hashes[totalHashes - 1];\n } else if (leavesLen > 0) {\n return leaves[0];\n } else {\n return proof[0];\n }\n }\n\n function _hashPair(bytes32 a, bytes32 b) private pure returns (bytes32) {\n return a < b ? _efficientHash(a, b) : _efficientHash(b, a);\n }\n\n function _efficientHash(bytes32 a, bytes32 b) private pure returns (bytes32 value) {\n /// @solidity memory-safe-assembly\n assembly {\n mstore(0x00, a)\n mstore(0x20, b)\n value := keccak256(0x00, 0x40)\n }\n }\n}\n" }, "@openzeppelin/contracts/access/Ownable.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n address private _owner;\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the deployer as the initial owner.\n */\n constructor() {\n _transferOwnership(_msgSender());\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n _checkOwner();\n _;\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function owner() public view virtual returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if the sender is not the owner.\n */\n function _checkOwner() internal view virtual {\n require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions anymore. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby removing any functionality that is only available to the owner.\n */\n function renounceOwnership() public virtual onlyOwner {\n _transferOwnership(address(0));\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public virtual onlyOwner {\n require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n _transferOwnership(newOwner);\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Internal function without access restriction.\n */\n function _transferOwnership(address newOwner) internal virtual {\n address oldOwner = _owner;\n _owner = newOwner;\n emit OwnershipTransferred(oldOwner, newOwner);\n }\n}\n" }, "@openzeppelin/contracts/access/AccessControl.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (access/AccessControl.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IAccessControl.sol\";\nimport \"../utils/Context.sol\";\nimport \"../utils/Strings.sol\";\nimport \"../utils/introspection/ERC165.sol\";\n\n/**\n * @dev Contract module that allows children to implement role-based access\n * control mechanisms. This is a lightweight version that doesn't allow enumerating role\n * members except through off-chain means by accessing the contract event logs. Some\n * applications may benefit from on-chain enumerability, for those cases see\n * {AccessControlEnumerable}.\n *\n * Roles are referred to by their `bytes32` identifier. These should be exposed\n * in the external API and be unique. The best way to achieve this is by\n * using `public constant` hash digests:\n *\n * ```\n * bytes32 public constant MY_ROLE = keccak256(\"MY_ROLE\");\n * ```\n *\n * Roles can be used to represent a set of permissions. To restrict access to a\n * function call, use {hasRole}:\n *\n * ```\n * function foo() public {\n * require(hasRole(MY_ROLE, msg.sender));\n * ...\n * }\n * ```\n *\n * Roles can be granted and revoked dynamically via the {grantRole} and\n * {revokeRole} functions. Each role has an associated admin role, and only\n * accounts that have a role's admin role can call {grantRole} and {revokeRole}.\n *\n * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means\n * that only accounts with this role will be able to grant or revoke other\n * roles. More complex role relationships can be created by using\n * {_setRoleAdmin}.\n *\n * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to\n * grant and revoke this role. Extra precautions should be taken to secure\n * accounts that have been granted it.\n */\nabstract contract AccessControl is Context, IAccessControl, ERC165 {\n struct RoleData {\n mapping(address => bool) members;\n bytes32 adminRole;\n }\n\n mapping(bytes32 => RoleData) private _roles;\n\n bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;\n\n /**\n * @dev Modifier that checks that an account has a specific role. Reverts\n * with a standardized message including the required role.\n *\n * The format of the revert reason is given by the following regular expression:\n *\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\n *\n * _Available since v4.1._\n */\n modifier onlyRole(bytes32 role) {\n _checkRole(role);\n _;\n }\n\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);\n }\n\n /**\n * @dev Returns `true` if `account` has been granted `role`.\n */\n function hasRole(bytes32 role, address account) public view virtual override returns (bool) {\n return _roles[role].members[account];\n }\n\n /**\n * @dev Revert with a standard message if `_msgSender()` is missing `role`.\n * Overriding this function changes the behavior of the {onlyRole} modifier.\n *\n * Format of the revert message is described in {_checkRole}.\n *\n * _Available since v4.6._\n */\n function _checkRole(bytes32 role) internal view virtual {\n _checkRole(role, _msgSender());\n }\n\n /**\n * @dev Revert with a standard message if `account` is missing `role`.\n *\n * The format of the revert reason is given by the following regular expression:\n *\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\n */\n function _checkRole(bytes32 role, address account) internal view virtual {\n if (!hasRole(role, account)) {\n revert(\n string(\n abi.encodePacked(\n \"AccessControl: account \",\n Strings.toHexString(account),\n \" is missing role \",\n Strings.toHexString(uint256(role), 32)\n )\n )\n );\n }\n }\n\n /**\n * @dev Returns the admin role that controls `role`. See {grantRole} and\n * {revokeRole}.\n *\n * To change a role's admin, use {_setRoleAdmin}.\n */\n function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {\n return _roles[role].adminRole;\n }\n\n /**\n * @dev Grants `role` to `account`.\n *\n * If `account` had not been already granted `role`, emits a {RoleGranted}\n * event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n *\n * May emit a {RoleGranted} event.\n */\n function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\n _grantRole(role, account);\n }\n\n /**\n * @dev Revokes `role` from `account`.\n *\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n *\n * May emit a {RoleRevoked} event.\n */\n function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\n _revokeRole(role, account);\n }\n\n /**\n * @dev Revokes `role` from the calling account.\n *\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\n * purpose is to provide a mechanism for accounts to lose their privileges\n * if they are compromised (such as when a trusted device is misplaced).\n *\n * If the calling account had been revoked `role`, emits a {RoleRevoked}\n * event.\n *\n * Requirements:\n *\n * - the caller must be `account`.\n *\n * May emit a {RoleRevoked} event.\n */\n function renounceRole(bytes32 role, address account) public virtual override {\n require(account == _msgSender(), \"AccessControl: can only renounce roles for self\");\n\n _revokeRole(role, account);\n }\n\n /**\n * @dev Grants `role` to `account`.\n *\n * If `account` had not been already granted `role`, emits a {RoleGranted}\n * event. Note that unlike {grantRole}, this function doesn't perform any\n * checks on the calling account.\n *\n * May emit a {RoleGranted} event.\n *\n * [WARNING]\n * ====\n * This function should only be called from the constructor when setting\n * up the initial roles for the system.\n *\n * Using this function in any other way is effectively circumventing the admin\n * system imposed by {AccessControl}.\n * ====\n *\n * NOTE: This function is deprecated in favor of {_grantRole}.\n */\n function _setupRole(bytes32 role, address account) internal virtual {\n _grantRole(role, account);\n }\n\n /**\n * @dev Sets `adminRole` as ``role``'s admin role.\n *\n * Emits a {RoleAdminChanged} event.\n */\n function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {\n bytes32 previousAdminRole = getRoleAdmin(role);\n _roles[role].adminRole = adminRole;\n emit RoleAdminChanged(role, previousAdminRole, adminRole);\n }\n\n /**\n * @dev Grants `role` to `account`.\n *\n * Internal function without access restriction.\n *\n * May emit a {RoleGranted} event.\n */\n function _grantRole(bytes32 role, address account) internal virtual {\n if (!hasRole(role, account)) {\n _roles[role].members[account] = true;\n emit RoleGranted(role, account, _msgSender());\n }\n }\n\n /**\n * @dev Revokes `role` from `account`.\n *\n * Internal function without access restriction.\n *\n * May emit a {RoleRevoked} event.\n */\n function _revokeRole(bytes32 role, address account) internal virtual {\n if (hasRole(role, account)) {\n _roles[role].members[account] = false;\n emit RoleRevoked(role, account, _msgSender());\n }\n }\n}\n" }, "contract-allow-list/contracts/ERC721AntiScam/restrictApprove/ERC721RestrictApprove.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.0;\n\nimport \"erc721psi/contracts/extension/ERC721PsiBurnable.sol\";\nimport \"./IERC721RestrictApprove.sol\";\nimport \"@openzeppelin/contracts/utils/structs/EnumerableSet.sol\";\nimport \"../../proxy/interface/IContractAllowListProxy.sol\";\n\n/// @title AntiScam機能付きERC721A\n/// @dev Readmeを見てください。\n\nabstract contract ERC721RestrictApprove is ERC721PsiBurnable, IERC721RestrictApprove {\n using EnumerableSet for EnumerableSet.AddressSet;\n\n IContractAllowListProxy public CAL;\n EnumerableSet.AddressSet localAllowedAddresses;\n\n modifier onlyHolder(uint256 tokenId) {\n require(\n msg.sender == ownerOf(tokenId),\n \"RestrictApprove: operation is only holder.\"\n );\n _;\n }\n\n /*//////////////////////////////////////////////////////////////\n 変数\n //////////////////////////////////////////////////////////////*/\n bool public enableRestrict = true;\n\n // token lock\n mapping(uint256 => uint256) public tokenCALLevel;\n\n // wallet lock\n mapping(address => uint256) public walletCALLevel;\n\n // contract lock\n uint256 public CALLevel = 1;\n\n /*///////////////////////////////////////////////////////////////\n Approve抑制機能ロジック\n //////////////////////////////////////////////////////////////*/\n function _addLocalContractAllowList(address transferer)\n internal\n virtual\n {\n localAllowedAddresses.add(transferer);\n emit LocalCalAdded(msg.sender, transferer);\n }\n\n function _removeLocalContractAllowList(address transferer)\n internal\n virtual\n {\n localAllowedAddresses.remove(transferer);\n emit LocalCalRemoved(msg.sender, transferer);\n }\n\n function _getLocalContractAllowList()\n internal\n virtual\n view\n returns(address[] memory)\n {\n return localAllowedAddresses.values();\n }\n\n function _isLocalAllowed(address transferer)\n internal\n view\n virtual\n returns (bool)\n {\n return localAllowedAddresses.contains(transferer);\n }\n\n function _isAllowed(address transferer)\n internal\n view\n virtual\n returns (bool)\n {\n return _isAllowed(msg.sender, transferer);\n }\n\n function _isAllowed(uint256 tokenId, address transferer)\n internal\n view\n virtual\n returns (bool)\n {\n uint256 level = _getCALLevel(msg.sender, tokenId);\n return _isAllowed(transferer, level);\n }\n\n function _isAllowed(address holder, address transferer)\n internal\n view\n virtual\n returns (bool)\n {\n uint256 level = _getCALLevel(holder);\n return _isAllowed(transferer, level);\n }\n\n function _isAllowed(address transferer, uint256 level)\n internal\n view\n virtual\n returns (bool)\n {\n if (!enableRestrict) {\n return true;\n }\n\n return _isLocalAllowed(transferer) || CAL.isAllowed(transferer, level);\n }\n\n function _getCALLevel(address holder, uint256 tokenId)\n internal\n view\n virtual\n returns (uint256)\n {\n if (tokenCALLevel[tokenId] > 0) {\n return tokenCALLevel[tokenId];\n }\n\n return _getCALLevel(holder);\n }\n\n function _getCALLevel(address holder)\n internal\n view\n virtual\n returns (uint256)\n {\n if (walletCALLevel[holder] > 0) {\n return walletCALLevel[holder];\n }\n\n return CALLevel;\n }\n\n function _setCAL(address _cal) internal virtual {\n CAL = IContractAllowListProxy(_cal);\n }\n\n function _deleteTokenCALLevel(uint256 tokenId) internal virtual {\n delete tokenCALLevel[tokenId];\n }\n\n function setTokenCALLevel(uint256 tokenId, uint256 level)\n external\n virtual\n onlyHolder(tokenId)\n {\n tokenCALLevel[tokenId] = level;\n }\n\n function setWalletCALLevel(uint256 level)\n external\n virtual\n {\n walletCALLevel[msg.sender] = level;\n }\n\n /*///////////////////////////////////////////////////////////////\n OVERRIDES\n //////////////////////////////////////////////////////////////*/\n\n function isApprovedForAll(address owner, address operator)\n public\n view\n virtual\n override\n returns (bool)\n {\n if (_isAllowed(owner, operator) == false) {\n return false;\n }\n return super.isApprovedForAll(owner, operator);\n }\n\n function setApprovalForAll(address operator, bool approved)\n public\n virtual\n override\n {\n require(\n _isAllowed(operator) || approved == false,\n \"RestrictApprove: Can not approve locked token\"\n );\n super.setApprovalForAll(operator, approved);\n }\n\n function _beforeApprove(address to, uint256 tokenId)\n internal\n virtual\n {\n if (to != address(0)) {\n require(_isAllowed(tokenId, to), \"RestrictApprove: The contract is not allowed.\");\n }\n }\n\n function approve(address to, uint256 tokenId)\n public\n virtual\n override\n {\n _beforeApprove(to, tokenId);\n super.approve(to, tokenId);\n }\n\n function _afterTokenTransfers(\n address from,\n address, /*to*/\n uint256 startTokenId,\n uint256 /*quantity*/\n ) internal virtual override {\n // 転送やバーンにおいては、常にstartTokenIdは TokenIDそのものとなります。\n if (from != address(0)) {\n // CALレベルをデフォルトに戻す。\n _deleteTokenCALLevel(startTokenId);\n }\n }\n\n function supportsInterface(bytes4 interfaceId)\n public\n view\n virtual\n override\n returns (bool)\n {\n return\n interfaceId == type(IERC721RestrictApprove).interfaceId ||\n super.supportsInterface(interfaceId);\n }\n}\n" }, "base64-sol/base64.sol": { "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0;\n\n/// @title Base64\n/// @author Brecht Devos - \n/// @notice Provides functions for encoding/decoding base64\nlibrary Base64 {\n string internal constant TABLE_ENCODE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';\n bytes internal constant TABLE_DECODE = hex\"0000000000000000000000000000000000000000000000000000000000000000\"\n hex\"00000000000000000000003e0000003f3435363738393a3b3c3d000000000000\"\n hex\"00000102030405060708090a0b0c0d0e0f101112131415161718190000000000\"\n hex\"001a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132330000000000\";\n\n function encode(bytes memory data) internal pure returns (string memory) {\n if (data.length == 0) return '';\n\n // load the table into memory\n string memory table = TABLE_ENCODE;\n\n // multiply by 4/3 rounded up\n uint256 encodedLen = 4 * ((data.length + 2) / 3);\n\n // add some extra buffer at the end required for the writing\n string memory result = new string(encodedLen + 32);\n\n assembly {\n // set the actual output length\n mstore(result, encodedLen)\n\n // prepare the lookup table\n let tablePtr := add(table, 1)\n\n // input ptr\n let dataPtr := data\n let endPtr := add(dataPtr, mload(data))\n\n // result ptr, jump over length\n let resultPtr := add(result, 32)\n\n // run over the input, 3 bytes at a time\n for {} lt(dataPtr, endPtr) {}\n {\n // read 3 bytes\n dataPtr := add(dataPtr, 3)\n let input := mload(dataPtr)\n\n // write 4 characters\n mstore8(resultPtr, mload(add(tablePtr, and(shr(18, input), 0x3F))))\n resultPtr := add(resultPtr, 1)\n mstore8(resultPtr, mload(add(tablePtr, and(shr(12, input), 0x3F))))\n resultPtr := add(resultPtr, 1)\n mstore8(resultPtr, mload(add(tablePtr, and(shr( 6, input), 0x3F))))\n resultPtr := add(resultPtr, 1)\n mstore8(resultPtr, mload(add(tablePtr, and( input, 0x3F))))\n resultPtr := add(resultPtr, 1)\n }\n\n // padding with '='\n switch mod(mload(data), 3)\n case 1 { mstore(sub(resultPtr, 2), shl(240, 0x3d3d)) }\n case 2 { mstore(sub(resultPtr, 1), shl(248, 0x3d)) }\n }\n\n return result;\n }\n\n function decode(string memory _data) internal pure returns (bytes memory) {\n bytes memory data = bytes(_data);\n\n if (data.length == 0) return new bytes(0);\n require(data.length % 4 == 0, \"invalid base64 decoder input\");\n\n // load the table into memory\n bytes memory table = TABLE_DECODE;\n\n // every 4 characters represent 3 bytes\n uint256 decodedLen = (data.length / 4) * 3;\n\n // add some extra buffer at the end required for the writing\n bytes memory result = new bytes(decodedLen + 32);\n\n assembly {\n // padding with '='\n let lastBytes := mload(add(data, mload(data)))\n if eq(and(lastBytes, 0xFF), 0x3d) {\n decodedLen := sub(decodedLen, 1)\n if eq(and(lastBytes, 0xFFFF), 0x3d3d) {\n decodedLen := sub(decodedLen, 1)\n }\n }\n\n // set the actual output length\n mstore(result, decodedLen)\n\n // prepare the lookup table\n let tablePtr := add(table, 1)\n\n // input ptr\n let dataPtr := data\n let endPtr := add(dataPtr, mload(data))\n\n // result ptr, jump over length\n let resultPtr := add(result, 32)\n\n // run over the input, 4 characters at a time\n for {} lt(dataPtr, endPtr) {}\n {\n // read 4 characters\n dataPtr := add(dataPtr, 4)\n let input := mload(dataPtr)\n\n // write 3 bytes\n let output := add(\n add(\n shl(18, and(mload(add(tablePtr, and(shr(24, input), 0xFF))), 0xFF)),\n shl(12, and(mload(add(tablePtr, and(shr(16, input), 0xFF))), 0xFF))),\n add(\n shl( 6, and(mload(add(tablePtr, and(shr( 8, input), 0xFF))), 0xFF)),\n and(mload(add(tablePtr, and( input , 0xFF))), 0xFF)\n )\n )\n mstore(resultPtr, shl(232, output))\n resultPtr := add(resultPtr, 3)\n }\n }\n\n return result;\n }\n}\n" }, "operator-filter-registry/src/IOperatorFilterRegistry.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.13;\n\ninterface IOperatorFilterRegistry {\n function isOperatorAllowed(address registrant, address operator) external view returns (bool);\n function register(address registrant) external;\n function registerAndSubscribe(address registrant, address subscription) external;\n function registerAndCopyEntries(address registrant, address registrantToCopy) external;\n function unregister(address addr) external;\n function updateOperator(address registrant, address operator, bool filtered) external;\n function updateOperators(address registrant, address[] calldata operators, bool filtered) external;\n function updateCodeHash(address registrant, bytes32 codehash, bool filtered) external;\n function updateCodeHashes(address registrant, bytes32[] calldata codeHashes, bool filtered) external;\n function subscribe(address registrant, address registrantToSubscribe) external;\n function unsubscribe(address registrant, bool copyExistingEntries) external;\n function subscriptionOf(address addr) external returns (address registrant);\n function subscribers(address registrant) external returns (address[] memory);\n function subscriberAt(address registrant, uint256 index) external returns (address);\n function copyEntriesOf(address registrant, address registrantToCopy) external;\n function isOperatorFiltered(address registrant, address operator) external returns (bool);\n function isCodeHashOfFiltered(address registrant, address operatorWithCode) external returns (bool);\n function isCodeHashFiltered(address registrant, bytes32 codeHash) external returns (bool);\n function filteredOperators(address addr) external returns (address[] memory);\n function filteredCodeHashes(address addr) external returns (bytes32[] memory);\n function filteredOperatorAt(address registrant, uint256 index) external returns (address);\n function filteredCodeHashAt(address registrant, uint256 index) external returns (bytes32);\n function isRegistered(address addr) external returns (bool);\n function codeHashOf(address addr) external returns (bytes32);\n}\n" }, "operator-filter-registry/src/RevokableOperatorFilterer.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.13;\n\nimport {UpdatableOperatorFilterer} from \"./UpdatableOperatorFilterer.sol\";\nimport {IOperatorFilterRegistry} from \"./IOperatorFilterRegistry.sol\";\n\n/**\n * @title RevokableOperatorFilterer\n * @notice This contract is meant to allow contracts to permanently skip OperatorFilterRegistry checks if desired. The\n * Registry itself has an \"unregister\" function, but if the contract is ownable, the owner can re-register at\n * any point. As implemented, this abstract contract allows the contract owner to permanently skip the\n * OperatorFilterRegistry checks by calling revokeOperatorFilterRegistry. Once done, the registry\n * address cannot be further updated.\n * Note that OpenSea will still disable creator fee enforcement if filtered operators begin fulfilling orders\n * on-chain, eg, if the registry is revoked or bypassed.\n */\nabstract contract RevokableOperatorFilterer is UpdatableOperatorFilterer {\n error RegistryHasBeenRevoked();\n error InitialRegistryAddressCannotBeZeroAddress();\n\n bool public isOperatorFilterRegistryRevoked;\n\n constructor(address _registry, address subscriptionOrRegistrantToCopy, bool subscribe)\n UpdatableOperatorFilterer(_registry, subscriptionOrRegistrantToCopy, subscribe)\n {\n // don't allow creating a contract with a permanently revoked registry\n if (_registry == address(0)) {\n revert InitialRegistryAddressCannotBeZeroAddress();\n }\n }\n\n function _checkFilterOperator(address operator) internal view virtual override {\n if (address(operatorFilterRegistry) != address(0)) {\n super._checkFilterOperator(operator);\n }\n }\n\n /**\n * @notice Update the address that the contract will make OperatorFilter checks against. When set to the zero\n * address, checks will be permanently bypassed, and the address cannot be updated again. OnlyOwner.\n */\n function updateOperatorFilterRegistryAddress(address newRegistry) public override {\n if (msg.sender != owner()) {\n revert OnlyOwner();\n }\n // if registry has been revoked, do not allow further updates\n if (isOperatorFilterRegistryRevoked) {\n revert RegistryHasBeenRevoked();\n }\n\n operatorFilterRegistry = IOperatorFilterRegistry(newRegistry);\n }\n\n /**\n * @notice Revoke the OperatorFilterRegistry address, permanently bypassing checks. OnlyOwner.\n */\n function revokeOperatorFilterRegistry() public {\n if (msg.sender != owner()) {\n revert OnlyOwner();\n }\n // if registry has been revoked, do not allow further updates\n if (isOperatorFilterRegistryRevoked) {\n revert RegistryHasBeenRevoked();\n }\n\n // set to zero address to bypass checks\n operatorFilterRegistry = IOperatorFilterRegistry(address(0));\n isOperatorFilterRegistryRevoked = true;\n }\n}\n" }, "contract-allow-list/contracts/proxy/interface/IContractAllowListProxy.sol": { "content": "// SPDX-License-Identifier: MIT\r\npragma solidity >=0.7.0 <0.9.0;\r\n\r\ninterface IContractAllowListProxy {\r\n function isAllowed(address _transferer, uint256 _level)\r\n external\r\n view\r\n returns (bool);\r\n}\r\n" }, "@openzeppelin/contracts/utils/structs/EnumerableSet.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/structs/EnumerableSet.sol)\n// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Library for managing\n * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive\n * types.\n *\n * Sets have the following properties:\n *\n * - Elements are added, removed, and checked for existence in constant time\n * (O(1)).\n * - Elements are enumerated in O(n). No guarantees are made on the ordering.\n *\n * ```\n * contract Example {\n * // Add the library methods\n * using EnumerableSet for EnumerableSet.AddressSet;\n *\n * // Declare a set state variable\n * EnumerableSet.AddressSet private mySet;\n * }\n * ```\n *\n * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)\n * and `uint256` (`UintSet`) are supported.\n *\n * [WARNING]\n * ====\n * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure\n * unusable.\n * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.\n *\n * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an\n * array of EnumerableSet.\n * ====\n */\nlibrary EnumerableSet {\n // To implement this library for multiple types with as little code\n // repetition as possible, we write it in terms of a generic Set type with\n // bytes32 values.\n // The Set implementation uses private functions, and user-facing\n // implementations (such as AddressSet) are just wrappers around the\n // underlying Set.\n // This means that we can only create new EnumerableSets for types that fit\n // in bytes32.\n\n struct Set {\n // Storage of set values\n bytes32[] _values;\n // Position of the value in the `values` array, plus 1 because index 0\n // means a value is not in the set.\n mapping(bytes32 => uint256) _indexes;\n }\n\n /**\n * @dev Add a value to a set. O(1).\n *\n * Returns true if the value was added to the set, that is if it was not\n * already present.\n */\n function _add(Set storage set, bytes32 value) private returns (bool) {\n if (!_contains(set, value)) {\n set._values.push(value);\n // The value is stored at length-1, but we add 1 to all indexes\n // and use 0 as a sentinel value\n set._indexes[value] = set._values.length;\n return true;\n } else {\n return false;\n }\n }\n\n /**\n * @dev Removes a value from a set. O(1).\n *\n * Returns true if the value was removed from the set, that is if it was\n * present.\n */\n function _remove(Set storage set, bytes32 value) private returns (bool) {\n // We read and store the value's index to prevent multiple reads from the same storage slot\n uint256 valueIndex = set._indexes[value];\n\n if (valueIndex != 0) {\n // Equivalent to contains(set, value)\n // To delete an element from the _values array in O(1), we swap the element to delete with the last one in\n // the array, and then remove the last element (sometimes called as 'swap and pop').\n // This modifies the order of the array, as noted in {at}.\n\n uint256 toDeleteIndex = valueIndex - 1;\n uint256 lastIndex = set._values.length - 1;\n\n if (lastIndex != toDeleteIndex) {\n bytes32 lastValue = set._values[lastIndex];\n\n // Move the last value to the index where the value to delete is\n set._values[toDeleteIndex] = lastValue;\n // Update the index for the moved value\n set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex\n }\n\n // Delete the slot where the moved value was stored\n set._values.pop();\n\n // Delete the index for the deleted slot\n delete set._indexes[value];\n\n return true;\n } else {\n return false;\n }\n }\n\n /**\n * @dev Returns true if the value is in the set. O(1).\n */\n function _contains(Set storage set, bytes32 value) private view returns (bool) {\n return set._indexes[value] != 0;\n }\n\n /**\n * @dev Returns the number of values on the set. O(1).\n */\n function _length(Set storage set) private view returns (uint256) {\n return set._values.length;\n }\n\n /**\n * @dev Returns the value stored at position `index` in the set. O(1).\n *\n * Note that there are no guarantees on the ordering of values inside the\n * array, and it may change when more values are added or removed.\n *\n * Requirements:\n *\n * - `index` must be strictly less than {length}.\n */\n function _at(Set storage set, uint256 index) private view returns (bytes32) {\n return set._values[index];\n }\n\n /**\n * @dev Return the entire set in an array\n *\n * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n */\n function _values(Set storage set) private view returns (bytes32[] memory) {\n return set._values;\n }\n\n // Bytes32Set\n\n struct Bytes32Set {\n Set _inner;\n }\n\n /**\n * @dev Add a value to a set. O(1).\n *\n * Returns true if the value was added to the set, that is if it was not\n * already present.\n */\n function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {\n return _add(set._inner, value);\n }\n\n /**\n * @dev Removes a value from a set. O(1).\n *\n * Returns true if the value was removed from the set, that is if it was\n * present.\n */\n function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {\n return _remove(set._inner, value);\n }\n\n /**\n * @dev Returns true if the value is in the set. O(1).\n */\n function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {\n return _contains(set._inner, value);\n }\n\n /**\n * @dev Returns the number of values in the set. O(1).\n */\n function length(Bytes32Set storage set) internal view returns (uint256) {\n return _length(set._inner);\n }\n\n /**\n * @dev Returns the value stored at position `index` in the set. O(1).\n *\n * Note that there are no guarantees on the ordering of values inside the\n * array, and it may change when more values are added or removed.\n *\n * Requirements:\n *\n * - `index` must be strictly less than {length}.\n */\n function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {\n return _at(set._inner, index);\n }\n\n /**\n * @dev Return the entire set in an array\n *\n * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n */\n function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {\n bytes32[] memory store = _values(set._inner);\n bytes32[] memory result;\n\n /// @solidity memory-safe-assembly\n assembly {\n result := store\n }\n\n return result;\n }\n\n // AddressSet\n\n struct AddressSet {\n Set _inner;\n }\n\n /**\n * @dev Add a value to a set. O(1).\n *\n * Returns true if the value was added to the set, that is if it was not\n * already present.\n */\n function add(AddressSet storage set, address value) internal returns (bool) {\n return _add(set._inner, bytes32(uint256(uint160(value))));\n }\n\n /**\n * @dev Removes a value from a set. O(1).\n *\n * Returns true if the value was removed from the set, that is if it was\n * present.\n */\n function remove(AddressSet storage set, address value) internal returns (bool) {\n return _remove(set._inner, bytes32(uint256(uint160(value))));\n }\n\n /**\n * @dev Returns true if the value is in the set. O(1).\n */\n function contains(AddressSet storage set, address value) internal view returns (bool) {\n return _contains(set._inner, bytes32(uint256(uint160(value))));\n }\n\n /**\n * @dev Returns the number of values in the set. O(1).\n */\n function length(AddressSet storage set) internal view returns (uint256) {\n return _length(set._inner);\n }\n\n /**\n * @dev Returns the value stored at position `index` in the set. O(1).\n *\n * Note that there are no guarantees on the ordering of values inside the\n * array, and it may change when more values are added or removed.\n *\n * Requirements:\n *\n * - `index` must be strictly less than {length}.\n */\n function at(AddressSet storage set, uint256 index) internal view returns (address) {\n return address(uint160(uint256(_at(set._inner, index))));\n }\n\n /**\n * @dev Return the entire set in an array\n *\n * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n */\n function values(AddressSet storage set) internal view returns (address[] memory) {\n bytes32[] memory store = _values(set._inner);\n address[] memory result;\n\n /// @solidity memory-safe-assembly\n assembly {\n result := store\n }\n\n return result;\n }\n\n // UintSet\n\n struct UintSet {\n Set _inner;\n }\n\n /**\n * @dev Add a value to a set. O(1).\n *\n * Returns true if the value was added to the set, that is if it was not\n * already present.\n */\n function add(UintSet storage set, uint256 value) internal returns (bool) {\n return _add(set._inner, bytes32(value));\n }\n\n /**\n * @dev Removes a value from a set. O(1).\n *\n * Returns true if the value was removed from the set, that is if it was\n * present.\n */\n function remove(UintSet storage set, uint256 value) internal returns (bool) {\n return _remove(set._inner, bytes32(value));\n }\n\n /**\n * @dev Returns true if the value is in the set. O(1).\n */\n function contains(UintSet storage set, uint256 value) internal view returns (bool) {\n return _contains(set._inner, bytes32(value));\n }\n\n /**\n * @dev Returns the number of values in the set. O(1).\n */\n function length(UintSet storage set) internal view returns (uint256) {\n return _length(set._inner);\n }\n\n /**\n * @dev Returns the value stored at position `index` in the set. O(1).\n *\n * Note that there are no guarantees on the ordering of values inside the\n * array, and it may change when more values are added or removed.\n *\n * Requirements:\n *\n * - `index` must be strictly less than {length}.\n */\n function at(UintSet storage set, uint256 index) internal view returns (uint256) {\n return uint256(_at(set._inner, index));\n }\n\n /**\n * @dev Return the entire set in an array\n *\n * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n */\n function values(UintSet storage set) internal view returns (uint256[] memory) {\n bytes32[] memory store = _values(set._inner);\n uint256[] memory result;\n\n /// @solidity memory-safe-assembly\n assembly {\n result := store\n }\n\n return result;\n }\n}\n" }, "contract-allow-list/contracts/ERC721AntiScam/restrictApprove/IERC721RestrictApprove.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.0;\n\n/// @title IERC721RestrictApprove\n/// @dev Approve抑制機能付きコントラクトのインターフェース\n/// @author Lavulite\n\ninterface IERC721RestrictApprove {\n /**\n * @dev CALレベルが変更された場合のイベント\n */\n event CalLevelChanged(address indexed operator, uint256 indexed level);\n \n /**\n * @dev LocalContractAllowListnに追加された場合のイベント\n */\n event LocalCalAdded(address indexed operator, address indexed transferer);\n\n /**\n * @dev LocalContractAllowListnに削除された場合のイベント\n */\n event LocalCalRemoved(address indexed operator, address indexed transferer);\n\n /**\n * @dev CALを利用する場合のCALのレベルを設定する。レベルが高いほど、許可されるコントラクトの範囲が狭い。\n */\n function setCALLevel(uint256 level) external;\n\n /**\n * @dev CALのアドレスをセットする。\n */\n function setCAL(address calAddress) external;\n\n /**\n * @dev CALのリストに無い独自の許可アドレスを追加する場合、こちらにアドレスを記載する。\n */\n function addLocalContractAllowList(address transferer) external;\n\n /**\n * @dev CALのリストにある独自の許可アドレスを削除する場合、こちらにアドレスを記載する。\n */\n function removeLocalContractAllowList(address transferer) external;\n\n /**\n * @dev CALのリストにある独自の許可アドレスの一覧を取得する。\n */\n function getLocalContractAllowList() external view returns(address[] memory);\n\n}\n" }, "erc721psi/contracts/extension/ERC721PsiBurnable.sol": { "content": "// SPDX-License-Identifier: MIT\n/**\n ______ _____ _____ ______ ___ __ _ _ _ \n | ____| __ \\ / ____|____ |__ \\/_ | || || |\n | |__ | |__) | | / / ) || | \\| |/ |\n | __| | _ /| | / / / / | |\\_ _/ \n | |____| | \\ \\| |____ / / / /_ | | | | \n |______|_| \\_\\\\_____|/_/ |____||_| |_| \n \n \n */\npragma solidity ^0.8.0;\n\nimport \"solidity-bits/contracts/BitMaps.sol\";\nimport \"../ERC721Psi.sol\";\n\n\nabstract contract ERC721PsiBurnable is ERC721Psi {\n using BitMaps for BitMaps.BitMap;\n BitMaps.BitMap private _burnedToken;\n\n /**\n * @dev Destroys `tokenId`.\n * The approval is cleared when the token is burned.\n *\n * Requirements:\n *\n * - `tokenId` must exist.\n *\n * Emits a {Transfer} event.\n */\n function _burn(uint256 tokenId) internal virtual {\n address from = ownerOf(tokenId);\n _beforeTokenTransfers(from, address(0), tokenId, 1);\n _burnedToken.set(tokenId);\n \n emit Transfer(from, address(0), tokenId);\n\n _afterTokenTransfers(from, address(0), tokenId, 1);\n }\n\n /**\n * @dev Returns whether `tokenId` exists.\n *\n * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.\n *\n * Tokens start existing when they are minted (`_mint`),\n * and stop existing when they are burned (`_burn`).\n */\n function _exists(uint256 tokenId) internal view override virtual returns (bool){\n if(_burnedToken.get(tokenId)) {\n return false;\n } \n return super._exists(tokenId);\n }\n\n /**\n * @dev See {IERC721Enumerable-totalSupply}.\n */\n function totalSupply() public view virtual override returns (uint256) {\n return _totalMinted() - _burned();\n }\n\n /**\n * @dev Returns number of token burned.\n */\n function _burned() internal view returns (uint256 burned){\n uint256 startBucket = _startTokenId() >> 8;\n uint256 lastBucket = (_nextTokenId() >> 8) + 1;\n\n for(uint256 i=startBucket; i < lastBucket; i++) {\n uint256 bucket = _burnedToken.getBucket(i);\n burned += _popcount(bucket);\n }\n }\n\n /**\n * @dev Returns number of set bits.\n */\n function _popcount(uint256 x) private pure returns (uint256 count) {\n unchecked{\n for (count=0; x!=0; count++)\n x &= x - 1;\n }\n }\n}" }, "@openzeppelin/contracts/utils/introspection/ERC165.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC165.sol\";\n\n/**\n * @dev Implementation of the {IERC165} interface.\n *\n * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check\n * for the additional interface id that will be supported. For example:\n *\n * ```solidity\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\n * }\n * ```\n *\n * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.\n */\nabstract contract ERC165 is IERC165 {\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n return interfaceId == type(IERC165).interfaceId;\n }\n}\n" }, "@openzeppelin/contracts/interfaces/IERC2981.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (interfaces/IERC2981.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/introspection/IERC165.sol\";\n\n/**\n * @dev Interface for the NFT Royalty Standard.\n *\n * A standardized way to retrieve royalty payment information for non-fungible tokens (NFTs) to enable universal\n * support for royalty payments across all NFT marketplaces and ecosystem participants.\n *\n * _Available since v4.5._\n */\ninterface IERC2981 is IERC165 {\n /**\n * @dev Returns how much royalty is owed and to whom, based on a sale price that may be denominated in any unit of\n * exchange. The royalty amount is denominated and should be paid in that same unit of exchange.\n */\n function royaltyInfo(uint256 tokenId, uint256 salePrice)\n external\n view\n returns (address receiver, uint256 royaltyAmount);\n}\n" }, "@openzeppelin/contracts/utils/Context.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n}\n" }, "@openzeppelin/contracts/utils/Strings.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./math/Math.sol\";\n\n/**\n * @dev String operations.\n */\nlibrary Strings {\n bytes16 private constant _SYMBOLS = \"0123456789abcdef\";\n uint8 private constant _ADDRESS_LENGTH = 20;\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` decimal representation.\n */\n function toString(uint256 value) internal pure returns (string memory) {\n unchecked {\n uint256 length = Math.log10(value) + 1;\n string memory buffer = new string(length);\n uint256 ptr;\n /// @solidity memory-safe-assembly\n assembly {\n ptr := add(buffer, add(32, length))\n }\n while (true) {\n ptr--;\n /// @solidity memory-safe-assembly\n assembly {\n mstore8(ptr, byte(mod(value, 10), _SYMBOLS))\n }\n value /= 10;\n if (value == 0) break;\n }\n return buffer;\n }\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\n */\n function toHexString(uint256 value) internal pure returns (string memory) {\n unchecked {\n return toHexString(value, Math.log256(value) + 1);\n }\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\n */\n function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\n bytes memory buffer = new bytes(2 * length + 2);\n buffer[0] = \"0\";\n buffer[1] = \"x\";\n for (uint256 i = 2 * length + 1; i > 1; --i) {\n buffer[i] = _SYMBOLS[value & 0xf];\n value >>= 4;\n }\n require(value == 0, \"Strings: hex length insufficient\");\n return string(buffer);\n }\n\n /**\n * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.\n */\n function toHexString(address addr) internal pure returns (string memory) {\n return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);\n }\n}\n" }, "@openzeppelin/contracts/access/IAccessControl.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev External interface of AccessControl declared to support ERC165 detection.\n */\ninterface IAccessControl {\n /**\n * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`\n *\n * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite\n * {RoleAdminChanged} not being emitted signaling this.\n *\n * _Available since v3.1._\n */\n event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);\n\n /**\n * @dev Emitted when `account` is granted `role`.\n *\n * `sender` is the account that originated the contract call, an admin role\n * bearer except when using {AccessControl-_setupRole}.\n */\n event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);\n\n /**\n * @dev Emitted when `account` is revoked `role`.\n *\n * `sender` is the account that originated the contract call:\n * - if using `revokeRole`, it is the admin role bearer\n * - if using `renounceRole`, it is the role bearer (i.e. `account`)\n */\n event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);\n\n /**\n * @dev Returns `true` if `account` has been granted `role`.\n */\n function hasRole(bytes32 role, address account) external view returns (bool);\n\n /**\n * @dev Returns the admin role that controls `role`. See {grantRole} and\n * {revokeRole}.\n *\n * To change a role's admin, use {AccessControl-_setRoleAdmin}.\n */\n function getRoleAdmin(bytes32 role) external view returns (bytes32);\n\n /**\n * @dev Grants `role` to `account`.\n *\n * If `account` had not been already granted `role`, emits a {RoleGranted}\n * event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n */\n function grantRole(bytes32 role, address account) external;\n\n /**\n * @dev Revokes `role` from `account`.\n *\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n */\n function revokeRole(bytes32 role, address account) external;\n\n /**\n * @dev Revokes `role` from the calling account.\n *\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\n * purpose is to provide a mechanism for accounts to lose their privileges\n * if they are compromised (such as when a trusted device is misplaced).\n *\n * If the calling account had been granted `role`, emits a {RoleRevoked}\n * event.\n *\n * Requirements:\n *\n * - the caller must be `account`.\n */\n function renounceRole(bytes32 role, address account) external;\n}\n" }, "erc721psi/contracts/ERC721Psi.sol": { "content": "// SPDX-License-Identifier: MIT\n/**\n ______ _____ _____ ______ ___ __ _ _ _ \n | ____| __ \\ / ____|____ |__ \\/_ | || || |\n | |__ | |__) | | / / ) || | \\| |/ |\n | __| | _ /| | / / / / | |\\_ _/ \n | |____| | \\ \\| |____ / / / /_ | | | | \n |______|_| \\_\\\\_____|/_/ |____||_| |_| \n\n - github: https://github.com/estarriolvetch/ERC721Psi\n - npm: https://www.npmjs.com/package/erc721psi\n \n */\n\npragma solidity ^0.8.0;\n\nimport \"@openzeppelin/contracts/token/ERC721/IERC721.sol\";\nimport \"@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol\";\nimport \"@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol\";\nimport \"@openzeppelin/contracts/utils/Context.sol\";\nimport \"@openzeppelin/contracts/utils/Strings.sol\";\nimport \"@openzeppelin/contracts/utils/introspection/ERC165.sol\";\nimport \"@openzeppelin/contracts/utils/Address.sol\";\nimport \"@openzeppelin/contracts/utils/StorageSlot.sol\";\nimport \"solidity-bits/contracts/BitMaps.sol\";\n\n\ncontract ERC721Psi is Context, ERC165, IERC721, IERC721Metadata {\n using Address for address;\n using Strings for uint256;\n using BitMaps for BitMaps.BitMap;\n\n BitMaps.BitMap private _batchHead;\n\n string private _name;\n string private _symbol;\n\n // Mapping from token ID to owner address\n mapping(uint256 => address) internal _owners;\n uint256 private _currentIndex;\n\n mapping(uint256 => address) private _tokenApprovals;\n mapping(address => mapping(address => bool)) private _operatorApprovals;\n\n /**\n * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.\n */\n constructor(string memory name_, string memory symbol_) {\n _name = name_;\n _symbol = symbol_;\n _currentIndex = _startTokenId();\n }\n\n /**\n * @dev Returns the starting token ID.\n * To change the starting token ID, please override this function.\n */\n function _startTokenId() internal pure returns (uint256) {\n // It will become modifiable in the future versions\n return 0;\n }\n\n /**\n * @dev Returns the next token ID to be minted.\n */\n function _nextTokenId() internal view virtual returns (uint256) {\n return _currentIndex;\n }\n\n /**\n * @dev Returns the total amount of tokens minted in the contract.\n */\n function _totalMinted() internal view virtual returns (uint256) {\n return _currentIndex - _startTokenId();\n }\n\n\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId)\n public\n view\n virtual\n override(ERC165, IERC165)\n returns (bool)\n {\n return\n interfaceId == type(IERC721).interfaceId ||\n interfaceId == type(IERC721Metadata).interfaceId ||\n super.supportsInterface(interfaceId);\n }\n\n /**\n * @dev See {IERC721-balanceOf}.\n */\n function balanceOf(address owner) \n public \n view \n virtual \n override \n returns (uint) \n {\n require(owner != address(0), \"ERC721Psi: balance query for the zero address\");\n\n uint count;\n for( uint i = _startTokenId(); i < _nextTokenId(); ++i ){\n if(_exists(i)){\n if( owner == ownerOf(i)){\n ++count;\n }\n }\n }\n return count;\n }\n\n /**\n * @dev See {IERC721-ownerOf}.\n */\n function ownerOf(uint256 tokenId)\n public\n view\n virtual\n override\n returns (address)\n {\n (address owner, ) = _ownerAndBatchHeadOf(tokenId);\n return owner;\n }\n\n function _ownerAndBatchHeadOf(uint256 tokenId) internal view returns (address owner, uint256 tokenIdBatchHead){\n require(_exists(tokenId), \"ERC721Psi: owner query for nonexistent token\");\n tokenIdBatchHead = _getBatchHead(tokenId);\n owner = _owners[tokenIdBatchHead];\n }\n\n /**\n * @dev See {IERC721Metadata-name}.\n */\n function name() public view virtual override returns (string memory) {\n return _name;\n }\n\n /**\n * @dev See {IERC721Metadata-symbol}.\n */\n function symbol() public view virtual override returns (string memory) {\n return _symbol;\n }\n\n /**\n * @dev See {IERC721Metadata-tokenURI}.\n */\n function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {\n require(_exists(tokenId), \"ERC721Psi: URI query for nonexistent token\");\n\n string memory baseURI = _baseURI();\n return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : \"\";\n }\n\n /**\n * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each\n * token will be the concatenation of the `baseURI` and the `tokenId`. Empty\n * by default, can be overriden in child contracts.\n */\n function _baseURI() internal view virtual returns (string memory) {\n return \"\";\n }\n\n\n /**\n * @dev See {IERC721-approve}.\n */\n function approve(address to, uint256 tokenId) public virtual override {\n address owner = ownerOf(tokenId);\n require(to != owner, \"ERC721Psi: approval to current owner\");\n\n require(\n _msgSender() == owner || isApprovedForAll(owner, _msgSender()),\n \"ERC721Psi: approve caller is not owner nor approved for all\"\n );\n\n _approve(to, tokenId);\n }\n\n /**\n * @dev See {IERC721-getApproved}.\n */\n function getApproved(uint256 tokenId)\n public\n view\n virtual\n override\n returns (address)\n {\n require(\n _exists(tokenId),\n \"ERC721Psi: approved query for nonexistent token\"\n );\n\n return _tokenApprovals[tokenId];\n }\n\n /**\n * @dev See {IERC721-setApprovalForAll}.\n */\n function setApprovalForAll(address operator, bool approved)\n public\n virtual\n override\n {\n require(operator != _msgSender(), \"ERC721Psi: approve to caller\");\n\n _operatorApprovals[_msgSender()][operator] = approved;\n emit ApprovalForAll(_msgSender(), operator, approved);\n }\n\n /**\n * @dev See {IERC721-isApprovedForAll}.\n */\n function isApprovedForAll(address owner, address operator)\n public\n view\n virtual\n override\n returns (bool)\n {\n return _operatorApprovals[owner][operator];\n }\n\n /**\n * @dev See {IERC721-transferFrom}.\n */\n function transferFrom(\n address from,\n address to,\n uint256 tokenId\n ) public virtual override {\n //solhint-disable-next-line max-line-length\n require(\n _isApprovedOrOwner(_msgSender(), tokenId),\n \"ERC721Psi: transfer caller is not owner nor approved\"\n );\n\n _transfer(from, to, tokenId);\n }\n\n /**\n * @dev See {IERC721-safeTransferFrom}.\n */\n function safeTransferFrom(\n address from,\n address to,\n uint256 tokenId\n ) public virtual override {\n safeTransferFrom(from, to, tokenId, \"\");\n }\n\n /**\n * @dev See {IERC721-safeTransferFrom}.\n */\n function safeTransferFrom(\n address from,\n address to,\n uint256 tokenId,\n bytes memory _data\n ) public virtual override {\n require(\n _isApprovedOrOwner(_msgSender(), tokenId),\n \"ERC721Psi: transfer caller is not owner nor approved\"\n );\n _safeTransfer(from, to, tokenId, _data);\n }\n\n /**\n * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients\n * are aware of the ERC721 protocol to prevent tokens from being forever locked.\n *\n * `_data` is additional data, it has no specified format and it is sent in call to `to`.\n *\n * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.\n * implement alternative mechanisms to perform token transfer, such as signature-based.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `tokenId` token must exist and be owned by `from`.\n * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\n *\n * Emits a {Transfer} event.\n */\n function _safeTransfer(\n address from,\n address to,\n uint256 tokenId,\n bytes memory _data\n ) internal virtual {\n _transfer(from, to, tokenId);\n require(\n _checkOnERC721Received(from, to, tokenId, 1,_data),\n \"ERC721Psi: transfer to non ERC721Receiver implementer\"\n );\n }\n\n /**\n * @dev Returns whether `tokenId` exists.\n *\n * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.\n *\n * Tokens start existing when they are minted (`_mint`).\n */\n function _exists(uint256 tokenId) internal view virtual returns (bool) {\n return tokenId < _nextTokenId() && _startTokenId() <= tokenId;\n }\n\n /**\n * @dev Returns whether `spender` is allowed to manage `tokenId`.\n *\n * Requirements:\n *\n * - `tokenId` must exist.\n */\n function _isApprovedOrOwner(address spender, uint256 tokenId)\n internal\n view\n virtual\n returns (bool)\n {\n require(\n _exists(tokenId),\n \"ERC721Psi: operator query for nonexistent token\"\n );\n address owner = ownerOf(tokenId);\n return (spender == owner ||\n getApproved(tokenId) == spender ||\n isApprovedForAll(owner, spender));\n }\n\n /**\n * @dev Safely mints `quantity` tokens and transfers them to `to`.\n *\n * Requirements:\n *\n * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called for each safe transfer.\n * - `quantity` must be greater than 0.\n *\n * Emits a {Transfer} event.\n */\n function _safeMint(address to, uint256 quantity) internal virtual {\n _safeMint(to, quantity, \"\");\n }\n\n \n function _safeMint(\n address to,\n uint256 quantity,\n bytes memory _data\n ) internal virtual {\n uint256 nextTokenId = _nextTokenId();\n _mint(to, quantity);\n require(\n _checkOnERC721Received(address(0), to, nextTokenId, quantity, _data),\n \"ERC721Psi: transfer to non ERC721Receiver implementer\"\n );\n }\n\n\n function _mint(\n address to,\n uint256 quantity\n ) internal virtual {\n uint256 nextTokenId = _nextTokenId();\n \n require(quantity > 0, \"ERC721Psi: quantity must be greater 0\");\n require(to != address(0), \"ERC721Psi: mint to the zero address\");\n \n _beforeTokenTransfers(address(0), to, nextTokenId, quantity);\n _currentIndex += quantity;\n _owners[nextTokenId] = to;\n _batchHead.set(nextTokenId);\n _afterTokenTransfers(address(0), to, nextTokenId, quantity);\n \n // Emit events\n for(uint256 tokenId=nextTokenId; tokenId < nextTokenId + quantity; tokenId++){\n emit Transfer(address(0), to, tokenId);\n } \n }\n\n\n /**\n * @dev Transfers `tokenId` from `from` to `to`.\n * As opposed to {transferFrom}, this imposes no restrictions on msg.sender.\n *\n * Requirements:\n *\n * - `to` cannot be the zero address.\n * - `tokenId` token must be owned by `from`.\n *\n * Emits a {Transfer} event.\n */\n function _transfer(\n address from,\n address to,\n uint256 tokenId\n ) internal virtual {\n (address owner, uint256 tokenIdBatchHead) = _ownerAndBatchHeadOf(tokenId);\n\n require(\n owner == from,\n \"ERC721Psi: transfer of token that is not own\"\n );\n require(to != address(0), \"ERC721Psi: transfer to the zero address\");\n\n _beforeTokenTransfers(from, to, tokenId, 1);\n\n // Clear approvals from the previous owner\n _approve(address(0), tokenId); \n\n uint256 subsequentTokenId = tokenId + 1;\n\n if(!_batchHead.get(subsequentTokenId) && \n subsequentTokenId < _nextTokenId()\n ) {\n _owners[subsequentTokenId] = from;\n _batchHead.set(subsequentTokenId);\n }\n\n _owners[tokenId] = to;\n if(tokenId != tokenIdBatchHead) {\n _batchHead.set(tokenId);\n }\n\n emit Transfer(from, to, tokenId);\n\n _afterTokenTransfers(from, to, tokenId, 1);\n }\n\n /**\n * @dev Approve `to` to operate on `tokenId`\n *\n * Emits a {Approval} event.\n */\n function _approve(address to, uint256 tokenId) internal virtual {\n _tokenApprovals[tokenId] = to;\n emit Approval(ownerOf(tokenId), to, tokenId);\n }\n\n /**\n * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.\n * The call is not executed if the target address is not a contract.\n *\n * @param from address representing the previous owner of the given token ID\n * @param to target address that will receive the tokens\n * @param startTokenId uint256 the first ID of the tokens to be transferred\n * @param quantity uint256 amount of the tokens to be transfered.\n * @param _data bytes optional data to send along with the call\n * @return r bool whether the call correctly returned the expected magic value\n */\n function _checkOnERC721Received(\n address from,\n address to,\n uint256 startTokenId,\n uint256 quantity,\n bytes memory _data\n ) private returns (bool r) {\n if (to.isContract()) {\n r = true;\n for(uint256 tokenId = startTokenId; tokenId < startTokenId + quantity; tokenId++){\n try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) {\n r = r && retval == IERC721Receiver.onERC721Received.selector;\n } catch (bytes memory reason) {\n if (reason.length == 0) {\n revert(\"ERC721Psi: transfer to non ERC721Receiver implementer\");\n } else {\n assembly {\n revert(add(32, reason), mload(reason))\n }\n }\n }\n }\n return r;\n } else {\n return true;\n }\n }\n\n function _getBatchHead(uint256 tokenId) internal view returns (uint256 tokenIdBatchHead) {\n tokenIdBatchHead = _batchHead.scanForward(tokenId); \n }\n\n\n function totalSupply() public virtual view returns (uint256) {\n return _totalMinted();\n }\n\n /**\n * @dev Returns an array of token IDs owned by `owner`.\n *\n * This function scans the ownership mapping and is O(`totalSupply`) in complexity.\n * It is meant to be called off-chain.\n *\n * This function is compatiable with ERC721AQueryable.\n */\n function tokensOfOwner(address owner) external view virtual returns (uint256[] memory) {\n unchecked {\n uint256 tokenIdsIdx;\n uint256 tokenIdsLength = balanceOf(owner);\n uint256[] memory tokenIds = new uint256[](tokenIdsLength);\n for (uint256 i = _startTokenId(); tokenIdsIdx != tokenIdsLength; ++i) {\n if (_exists(i)) {\n if (ownerOf(i) == owner) {\n tokenIds[tokenIdsIdx++] = i;\n }\n }\n }\n return tokenIds; \n }\n }\n\n /**\n * @dev Hook that is called before a set of serially-ordered token ids are about to be transferred. This includes minting.\n *\n * startTokenId - the first token id to be transferred\n * quantity - the amount to be transferred\n *\n * Calling conditions:\n *\n * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be\n * transferred to `to`.\n * - When `from` is zero, `tokenId` will be minted for `to`.\n */\n function _beforeTokenTransfers(\n address from,\n address to,\n uint256 startTokenId,\n uint256 quantity\n ) internal virtual {}\n\n /**\n * @dev Hook that is called after a set of serially-ordered token ids have been transferred. This includes\n * minting.\n *\n * startTokenId - the first token id to be transferred\n * quantity - the amount to be transferred\n *\n * Calling conditions:\n *\n * - when `from` and `to` are both non-zero.\n * - `from` and `to` are never both zero.\n */\n function _afterTokenTransfers(\n address from,\n address to,\n uint256 startTokenId,\n uint256 quantity\n ) internal virtual {}\n}" }, "solidity-bits/contracts/BitMaps.sol": { "content": "// SPDX-License-Identifier: MIT\n/**\n _____ ___ ___ __ ____ _ __ \n / ___/____ / (_)___/ (_) /___ __ / __ )(_) /______\n \\__ \\/ __ \\/ / / __ / / __/ / / / / __ / / __/ ___/\n ___/ / /_/ / / / /_/ / / /_/ /_/ / / /_/ / / /_(__ ) \n/____/\\____/_/_/\\__,_/_/\\__/\\__, / /_____/_/\\__/____/ \n /____/ \n\n- npm: https://www.npmjs.com/package/solidity-bits\n- github: https://github.com/estarriolvetch/solidity-bits\n\n */\npragma solidity ^0.8.0;\n\nimport \"./BitScan.sol\";\n\n/**\n * @dev This Library is a modified version of Openzeppelin's BitMaps library.\n * Functions of finding the index of the closest set bit from a given index are added.\n * The indexing of each bucket is modifed to count from the MSB to the LSB instead of from the LSB to the MSB.\n * The modification of indexing makes finding the closest previous set bit more efficient in gas usage.\n*/\n\n/**\n * @dev Library for managing uint256 to bool mapping in a compact and efficient way, providing the keys are sequential.\n * Largelly inspired by Uniswap's https://github.com/Uniswap/merkle-distributor/blob/master/contracts/MerkleDistributor.sol[merkle-distributor].\n */\n\nlibrary BitMaps {\n using BitScan for uint256;\n uint256 private constant MASK_INDEX_ZERO = (1 << 255);\n uint256 private constant MASK_FULL = type(uint256).max;\n\n struct BitMap {\n mapping(uint256 => uint256) _data;\n }\n\n /**\n * @dev Returns whether the bit at `index` is set.\n */\n function get(BitMap storage bitmap, uint256 index) internal view returns (bool) {\n uint256 bucket = index >> 8;\n uint256 mask = MASK_INDEX_ZERO >> (index & 0xff);\n return bitmap._data[bucket] & mask != 0;\n }\n\n /**\n * @dev Sets the bit at `index` to the boolean `value`.\n */\n function setTo(\n BitMap storage bitmap,\n uint256 index,\n bool value\n ) internal {\n if (value) {\n set(bitmap, index);\n } else {\n unset(bitmap, index);\n }\n }\n\n /**\n * @dev Sets the bit at `index`.\n */\n function set(BitMap storage bitmap, uint256 index) internal {\n uint256 bucket = index >> 8;\n uint256 mask = MASK_INDEX_ZERO >> (index & 0xff);\n bitmap._data[bucket] |= mask;\n }\n\n /**\n * @dev Unsets the bit at `index`.\n */\n function unset(BitMap storage bitmap, uint256 index) internal {\n uint256 bucket = index >> 8;\n uint256 mask = MASK_INDEX_ZERO >> (index & 0xff);\n bitmap._data[bucket] &= ~mask;\n }\n\n\n /**\n * @dev Consecutively sets `amount` of bits starting from the bit at `startIndex`.\n */ \n function setBatch(BitMap storage bitmap, uint256 startIndex, uint256 amount) internal {\n uint256 bucket = startIndex >> 8;\n\n uint256 bucketStartIndex = (startIndex & 0xff);\n\n unchecked {\n if(bucketStartIndex + amount < 256) {\n bitmap._data[bucket] |= MASK_FULL << (256 - amount) >> bucketStartIndex;\n } else {\n bitmap._data[bucket] |= MASK_FULL >> bucketStartIndex;\n amount -= (256 - bucketStartIndex);\n bucket++;\n\n while(amount > 256) {\n bitmap._data[bucket] = MASK_FULL;\n amount -= 256;\n bucket++;\n }\n\n bitmap._data[bucket] |= MASK_FULL << (256 - amount);\n }\n }\n }\n\n\n /**\n * @dev Consecutively unsets `amount` of bits starting from the bit at `startIndex`.\n */ \n function unsetBatch(BitMap storage bitmap, uint256 startIndex, uint256 amount) internal {\n uint256 bucket = startIndex >> 8;\n\n uint256 bucketStartIndex = (startIndex & 0xff);\n\n unchecked {\n if(bucketStartIndex + amount < 256) {\n bitmap._data[bucket] &= ~(MASK_FULL << (256 - amount) >> bucketStartIndex);\n } else {\n bitmap._data[bucket] &= ~(MASK_FULL >> bucketStartIndex);\n amount -= (256 - bucketStartIndex);\n bucket++;\n\n while(amount > 256) {\n bitmap._data[bucket] = 0;\n amount -= 256;\n bucket++;\n }\n\n bitmap._data[bucket] &= ~(MASK_FULL << (256 - amount));\n }\n }\n }\n\n\n /**\n * @dev Find the closest index of the set bit before `index`.\n */\n function scanForward(BitMap storage bitmap, uint256 index) internal view returns (uint256 setBitIndex) {\n uint256 bucket = index >> 8;\n\n // index within the bucket\n uint256 bucketIndex = (index & 0xff);\n\n // load a bitboard from the bitmap.\n uint256 bb = bitmap._data[bucket];\n\n // offset the bitboard to scan from `bucketIndex`.\n bb = bb >> (0xff ^ bucketIndex); // bb >> (255 - bucketIndex)\n \n if(bb > 0) {\n unchecked {\n setBitIndex = (bucket << 8) | (bucketIndex - bb.bitScanForward256()); \n }\n } else {\n while(true) {\n require(bucket > 0, \"BitMaps: The set bit before the index doesn't exist.\");\n unchecked {\n bucket--;\n }\n // No offset. Always scan from the least significiant bit now.\n bb = bitmap._data[bucket];\n \n if(bb > 0) {\n unchecked {\n setBitIndex = (bucket << 8) | (255 - bb.bitScanForward256());\n break;\n }\n } \n }\n }\n }\n\n function getBucket(BitMap storage bitmap, uint256 bucket) internal view returns (uint256) {\n return bitmap._data[bucket];\n }\n}\n" }, "@openzeppelin/contracts/utils/introspection/IERC165.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\n *\n * Implementers can declare support of contract interfaces, which can then be\n * queried by others ({ERC165Checker}).\n *\n * For an implementation, see {ERC165}.\n */\ninterface IERC165 {\n /**\n * @dev Returns true if this contract implements the interface defined by\n * `interfaceId`. See the corresponding\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\n * to learn more about how these ids are created.\n *\n * This function call must use less than 30 000 gas.\n */\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n" }, "@openzeppelin/contracts/utils/math/Math.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Standard math utilities missing in the Solidity language.\n */\nlibrary Math {\n enum Rounding {\n Down, // Toward negative infinity\n Up, // Toward infinity\n Zero // Toward zero\n }\n\n /**\n * @dev Returns the largest of two numbers.\n */\n function max(uint256 a, uint256 b) internal pure returns (uint256) {\n return a > b ? a : b;\n }\n\n /**\n * @dev Returns the smallest of two numbers.\n */\n function min(uint256 a, uint256 b) internal pure returns (uint256) {\n return a < b ? a : b;\n }\n\n /**\n * @dev Returns the average of two numbers. The result is rounded towards\n * zero.\n */\n function average(uint256 a, uint256 b) internal pure returns (uint256) {\n // (a + b) / 2 can overflow.\n return (a & b) + (a ^ b) / 2;\n }\n\n /**\n * @dev Returns the ceiling of the division of two numbers.\n *\n * This differs from standard division with `/` in that it rounds up instead\n * of rounding down.\n */\n function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\n // (a + b - 1) / b can overflow on addition, so we distribute.\n return a == 0 ? 0 : (a - 1) / b + 1;\n }\n\n /**\n * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0\n * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)\n * with further edits by Uniswap Labs also under MIT license.\n */\n function mulDiv(\n uint256 x,\n uint256 y,\n uint256 denominator\n ) internal pure returns (uint256 result) {\n unchecked {\n // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use\n // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256\n // variables such that product = prod1 * 2^256 + prod0.\n uint256 prod0; // Least significant 256 bits of the product\n uint256 prod1; // Most significant 256 bits of the product\n assembly {\n let mm := mulmod(x, y, not(0))\n prod0 := mul(x, y)\n prod1 := sub(sub(mm, prod0), lt(mm, prod0))\n }\n\n // Handle non-overflow cases, 256 by 256 division.\n if (prod1 == 0) {\n return prod0 / denominator;\n }\n\n // Make sure the result is less than 2^256. Also prevents denominator == 0.\n require(denominator > prod1);\n\n ///////////////////////////////////////////////\n // 512 by 256 division.\n ///////////////////////////////////////////////\n\n // Make division exact by subtracting the remainder from [prod1 prod0].\n uint256 remainder;\n assembly {\n // Compute remainder using mulmod.\n remainder := mulmod(x, y, denominator)\n\n // Subtract 256 bit number from 512 bit number.\n prod1 := sub(prod1, gt(remainder, prod0))\n prod0 := sub(prod0, remainder)\n }\n\n // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.\n // See https://cs.stackexchange.com/q/138556/92363.\n\n // Does not overflow because the denominator cannot be zero at this stage in the function.\n uint256 twos = denominator & (~denominator + 1);\n assembly {\n // Divide denominator by twos.\n denominator := div(denominator, twos)\n\n // Divide [prod1 prod0] by twos.\n prod0 := div(prod0, twos)\n\n // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.\n twos := add(div(sub(0, twos), twos), 1)\n }\n\n // Shift in bits from prod1 into prod0.\n prod0 |= prod1 * twos;\n\n // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such\n // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for\n // four bits. That is, denominator * inv = 1 mod 2^4.\n uint256 inverse = (3 * denominator) ^ 2;\n\n // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works\n // in modular arithmetic, doubling the correct bits in each step.\n inverse *= 2 - denominator * inverse; // inverse mod 2^8\n inverse *= 2 - denominator * inverse; // inverse mod 2^16\n inverse *= 2 - denominator * inverse; // inverse mod 2^32\n inverse *= 2 - denominator * inverse; // inverse mod 2^64\n inverse *= 2 - denominator * inverse; // inverse mod 2^128\n inverse *= 2 - denominator * inverse; // inverse mod 2^256\n\n // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.\n // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is\n // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1\n // is no longer required.\n result = prod0 * inverse;\n return result;\n }\n }\n\n /**\n * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.\n */\n function mulDiv(\n uint256 x,\n uint256 y,\n uint256 denominator,\n Rounding rounding\n ) internal pure returns (uint256) {\n uint256 result = mulDiv(x, y, denominator);\n if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {\n result += 1;\n }\n return result;\n }\n\n /**\n * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.\n *\n * Inspired by Henry S. Warren, Jr.'s \"Hacker's Delight\" (Chapter 11).\n */\n function sqrt(uint256 a) internal pure returns (uint256) {\n if (a == 0) {\n return 0;\n }\n\n // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.\n //\n // We know that the \"msb\" (most significant bit) of our target number `a` is a power of 2 such that we have\n // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.\n //\n // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`\n // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`\n // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`\n //\n // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.\n uint256 result = 1 << (log2(a) >> 1);\n\n // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,\n // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at\n // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision\n // into the expected uint128 result.\n unchecked {\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n return min(result, a / result);\n }\n }\n\n /**\n * @notice Calculates sqrt(a), following the selected rounding direction.\n */\n function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = sqrt(a);\n return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);\n }\n }\n\n /**\n * @dev Return the log in base 2, rounded down, of a positive value.\n * Returns 0 if given 0.\n */\n function log2(uint256 value) internal pure returns (uint256) {\n uint256 result = 0;\n unchecked {\n if (value >> 128 > 0) {\n value >>= 128;\n result += 128;\n }\n if (value >> 64 > 0) {\n value >>= 64;\n result += 64;\n }\n if (value >> 32 > 0) {\n value >>= 32;\n result += 32;\n }\n if (value >> 16 > 0) {\n value >>= 16;\n result += 16;\n }\n if (value >> 8 > 0) {\n value >>= 8;\n result += 8;\n }\n if (value >> 4 > 0) {\n value >>= 4;\n result += 4;\n }\n if (value >> 2 > 0) {\n value >>= 2;\n result += 2;\n }\n if (value >> 1 > 0) {\n result += 1;\n }\n }\n return result;\n }\n\n /**\n * @dev Return the log in base 2, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log2(value);\n return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);\n }\n }\n\n /**\n * @dev Return the log in base 10, rounded down, of a positive value.\n * Returns 0 if given 0.\n */\n function log10(uint256 value) internal pure returns (uint256) {\n uint256 result = 0;\n unchecked {\n if (value >= 10**64) {\n value /= 10**64;\n result += 64;\n }\n if (value >= 10**32) {\n value /= 10**32;\n result += 32;\n }\n if (value >= 10**16) {\n value /= 10**16;\n result += 16;\n }\n if (value >= 10**8) {\n value /= 10**8;\n result += 8;\n }\n if (value >= 10**4) {\n value /= 10**4;\n result += 4;\n }\n if (value >= 10**2) {\n value /= 10**2;\n result += 2;\n }\n if (value >= 10**1) {\n result += 1;\n }\n }\n return result;\n }\n\n /**\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log10(value);\n return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);\n }\n }\n\n /**\n * @dev Return the log in base 256, rounded down, of a positive value.\n * Returns 0 if given 0.\n *\n * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.\n */\n function log256(uint256 value) internal pure returns (uint256) {\n uint256 result = 0;\n unchecked {\n if (value >> 128 > 0) {\n value >>= 128;\n result += 16;\n }\n if (value >> 64 > 0) {\n value >>= 64;\n result += 8;\n }\n if (value >> 32 > 0) {\n value >>= 32;\n result += 4;\n }\n if (value >> 16 > 0) {\n value >>= 16;\n result += 2;\n }\n if (value >> 8 > 0) {\n result += 1;\n }\n }\n return result;\n }\n\n /**\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log256(value);\n return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);\n }\n }\n}\n" }, "solidity-bits/contracts/BitScan.sol": { "content": "// SPDX-License-Identifier: MIT\n/**\n _____ ___ ___ __ ____ _ __ \n / ___/____ / (_)___/ (_) /___ __ / __ )(_) /______\n \\__ \\/ __ \\/ / / __ / / __/ / / / / __ / / __/ ___/\n ___/ / /_/ / / / /_/ / / /_/ /_/ / / /_/ / / /_(__ ) \n/____/\\____/_/_/\\__,_/_/\\__/\\__, / /_____/_/\\__/____/ \n /____/ \n\n- npm: https://www.npmjs.com/package/solidity-bits\n- github: https://github.com/estarriolvetch/solidity-bits\n\n */\n\npragma solidity ^0.8.0;\n\n\nlibrary BitScan {\n uint256 constant private DEBRUIJN_256 = 0x818283848586878898a8b8c8d8e8f929395969799a9b9d9e9faaeb6bedeeff;\n bytes constant private LOOKUP_TABLE_256 = hex\"0001020903110a19042112290b311a3905412245134d2a550c5d32651b6d3a7506264262237d468514804e8d2b95569d0d495ea533a966b11c886eb93bc176c9071727374353637324837e9b47af86c7155181ad4fd18ed32c9096db57d59ee30e2e4a6a5f92a6be3498aae067ddb2eb1d5989b56fd7baf33ca0c2ee77e5caf7ff0810182028303840444c545c646c7425617c847f8c949c48a4a8b087b8c0c816365272829aaec650acd0d28fdad4e22d6991bd97dfdcea58b4d6f29fede4f6fe0f1f2f3f4b5b6b607b8b93a3a7b7bf357199c5abcfd9e168bcdee9b3f1ecf5fd1e3e5a7a8aa2b670c4ced8bbe8f0f4fc3d79a1c3cde7effb78cce6facbf9f8\";\n\n /**\n @dev Isolate the least significant set bit.\n */ \n function isolateLS1B256(uint256 bb) pure internal returns (uint256) {\n require(bb > 0);\n unchecked {\n return bb & (0 - bb);\n }\n } \n\n /**\n @dev Isolate the most significant set bit.\n */ \n function isolateMS1B256(uint256 bb) pure internal returns (uint256) {\n require(bb > 0);\n unchecked {\n bb |= bb >> 128;\n bb |= bb >> 64;\n bb |= bb >> 32;\n bb |= bb >> 16;\n bb |= bb >> 8;\n bb |= bb >> 4;\n bb |= bb >> 2;\n bb |= bb >> 1;\n \n return (bb >> 1) + 1;\n }\n } \n\n /**\n @dev Find the index of the lest significant set bit. (trailing zero count)\n */ \n function bitScanForward256(uint256 bb) pure internal returns (uint8) {\n unchecked {\n return uint8(LOOKUP_TABLE_256[(isolateLS1B256(bb) * DEBRUIJN_256) >> 248]);\n } \n }\n\n /**\n @dev Find the index of the most significant set bit.\n */ \n function bitScanReverse256(uint256 bb) pure internal returns (uint8) {\n unchecked {\n return 255 - uint8(LOOKUP_TABLE_256[((isolateMS1B256(bb) * DEBRUIJN_256) >> 248)]);\n } \n }\n\n function log2(uint256 bb) pure internal returns (uint8) {\n unchecked {\n return uint8(LOOKUP_TABLE_256[(isolateMS1B256(bb) * DEBRUIJN_256) >> 248]);\n } \n }\n}\n" }, "@openzeppelin/contracts/utils/StorageSlot.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (utils/StorageSlot.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Library for reading and writing primitive types to specific storage slots.\n *\n * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.\n * This library helps with reading and writing to such slots without the need for inline assembly.\n *\n * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.\n *\n * Example usage to set ERC1967 implementation slot:\n * ```\n * contract ERC1967 {\n * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;\n *\n * function _getImplementation() internal view returns (address) {\n * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;\n * }\n *\n * function _setImplementation(address newImplementation) internal {\n * require(Address.isContract(newImplementation), \"ERC1967: new implementation is not a contract\");\n * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;\n * }\n * }\n * ```\n *\n * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._\n */\nlibrary StorageSlot {\n struct AddressSlot {\n address value;\n }\n\n struct BooleanSlot {\n bool value;\n }\n\n struct Bytes32Slot {\n bytes32 value;\n }\n\n struct Uint256Slot {\n uint256 value;\n }\n\n /**\n * @dev Returns an `AddressSlot` with member `value` located at `slot`.\n */\n function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {\n /// @solidity memory-safe-assembly\n assembly {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `BooleanSlot` with member `value` located at `slot`.\n */\n function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {\n /// @solidity memory-safe-assembly\n assembly {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `Bytes32Slot` with member `value` located at `slot`.\n */\n function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {\n /// @solidity memory-safe-assembly\n assembly {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `Uint256Slot` with member `value` located at `slot`.\n */\n function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {\n /// @solidity memory-safe-assembly\n assembly {\n r.slot := slot\n }\n }\n}\n" }, "@openzeppelin/contracts/utils/Address.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)\n\npragma solidity ^0.8.1;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n /**\n * @dev Returns true if `account` is a contract.\n *\n * [IMPORTANT]\n * ====\n * It is unsafe to assume that an address for which this function returns\n * false is an externally-owned account (EOA) and not a contract.\n *\n * Among others, `isContract` will return false for the following\n * types of addresses:\n *\n * - an externally-owned account\n * - a contract in construction\n * - an address where a contract will be created\n * - an address where a contract lived, but was destroyed\n * ====\n *\n * [IMPORTANT]\n * ====\n * You shouldn't rely on `isContract` to protect against flash loan attacks!\n *\n * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n * constructor.\n * ====\n */\n function isContract(address account) internal view returns (bool) {\n // This method relies on extcodesize/address.code.length, which returns 0\n // for contracts in construction, since the code is only stored at the end\n // of the constructor execution.\n\n return account.code.length > 0;\n }\n\n /**\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n * `recipient`, forwarding all available gas and reverting on errors.\n *\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\n * imposed by `transfer`, making them unable to receive funds via\n * `transfer`. {sendValue} removes this limitation.\n *\n * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n *\n * IMPORTANT: because control is transferred to `recipient`, care must be\n * taken to not create reentrancy vulnerabilities. Consider using\n * {ReentrancyGuard} or the\n * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n (bool success, ) = recipient.call{value: amount}(\"\");\n require(success, \"Address: unable to send value, recipient may have reverted\");\n }\n\n /**\n * @dev Performs a Solidity function call using a low level `call`. A\n * plain `call` is an unsafe replacement for a function call: use this\n * function instead.\n *\n * If `target` reverts with a revert reason, it is bubbled up by this\n * function (like regular Solidity function calls).\n *\n * Returns the raw returned data. To convert to the expected return value,\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *\n * Requirements:\n *\n * - `target` must be a contract.\n * - calling `target` with `data` must not revert.\n *\n * _Available since v3.1._\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n * `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but also transferring `value` wei to `target`.\n *\n * Requirements:\n *\n * - the calling contract must have an ETH balance of at least `value`.\n * - the called Solidity function must be `payable`.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n * with `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(address(this).balance >= value, \"Address: insufficient balance for call\");\n (bool success, bytes memory returndata) = target.call{value: value}(data);\n return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n return functionStaticCall(target, data, \"Address: low-level static call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal view returns (bytes memory) {\n (bool success, bytes memory returndata) = target.staticcall(data);\n return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n (bool success, bytes memory returndata) = target.delegatecall(data);\n return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n }\n\n /**\n * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n *\n * _Available since v4.8._\n */\n function verifyCallResultFromTarget(\n address target,\n bool success,\n bytes memory returndata,\n string memory errorMessage\n ) internal view returns (bytes memory) {\n if (success) {\n if (returndata.length == 0) {\n // only check isContract if the call was successful and the return data is empty\n // otherwise we already know that it was a contract\n require(isContract(target), \"Address: call to non-contract\");\n }\n return returndata;\n } else {\n _revert(returndata, errorMessage);\n }\n }\n\n /**\n * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n * revert reason or using the provided one.\n *\n * _Available since v4.3._\n */\n function verifyCallResult(\n bool success,\n bytes memory returndata,\n string memory errorMessage\n ) internal pure returns (bytes memory) {\n if (success) {\n return returndata;\n } else {\n _revert(returndata, errorMessage);\n }\n }\n\n function _revert(bytes memory returndata, string memory errorMessage) private pure {\n // Look for revert reason and bubble it up if present\n if (returndata.length > 0) {\n // The easiest way to bubble the revert reason is using memory via assembly\n /// @solidity memory-safe-assembly\n assembly {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert(errorMessage);\n }\n }\n}\n" }, "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC721.sol\";\n\n/**\n * @title ERC-721 Non-Fungible Token Standard, optional metadata extension\n * @dev See https://eips.ethereum.org/EIPS/eip-721\n */\ninterface IERC721Metadata is IERC721 {\n /**\n * @dev Returns the token collection name.\n */\n function name() external view returns (string memory);\n\n /**\n * @dev Returns the token collection symbol.\n */\n function symbol() external view returns (string memory);\n\n /**\n * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.\n */\n function tokenURI(uint256 tokenId) external view returns (string memory);\n}\n" }, "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @title ERC721 token receiver interface\n * @dev Interface for any contract that wants to support safeTransfers\n * from ERC721 asset contracts.\n */\ninterface IERC721Receiver {\n /**\n * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}\n * by `operator` from `from`, this function is called.\n *\n * It must return its Solidity selector to confirm the token transfer.\n * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.\n *\n * The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.\n */\n function onERC721Received(\n address operator,\n address from,\n uint256 tokenId,\n bytes calldata data\n ) external returns (bytes4);\n}\n" }, "@openzeppelin/contracts/token/ERC721/IERC721.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC721/IERC721.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../../utils/introspection/IERC165.sol\";\n\n/**\n * @dev Required interface of an ERC721 compliant contract.\n */\ninterface IERC721 is IERC165 {\n /**\n * @dev Emitted when `tokenId` token is transferred from `from` to `to`.\n */\n event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);\n\n /**\n * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.\n */\n event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);\n\n /**\n * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.\n */\n event ApprovalForAll(address indexed owner, address indexed operator, bool approved);\n\n /**\n * @dev Returns the number of tokens in ``owner``'s account.\n */\n function balanceOf(address owner) external view returns (uint256 balance);\n\n /**\n * @dev Returns the owner of the `tokenId` token.\n *\n * Requirements:\n *\n * - `tokenId` must exist.\n */\n function ownerOf(uint256 tokenId) external view returns (address owner);\n\n /**\n * @dev Safely transfers `tokenId` token from `from` to `to`.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `tokenId` token must exist and be owned by `from`.\n * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.\n * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\n *\n * Emits a {Transfer} event.\n */\n function safeTransferFrom(\n address from,\n address to,\n uint256 tokenId,\n bytes calldata data\n ) external;\n\n /**\n * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients\n * are aware of the ERC721 protocol to prevent tokens from being forever locked.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `tokenId` token must exist and be owned by `from`.\n * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}.\n * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\n *\n * Emits a {Transfer} event.\n */\n function safeTransferFrom(\n address from,\n address to,\n uint256 tokenId\n ) external;\n\n /**\n * @dev Transfers `tokenId` token from `from` to `to`.\n *\n * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721\n * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must\n * understand this adds an external call which potentially creates a reentrancy vulnerability.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `tokenId` token must be owned by `from`.\n * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(\n address from,\n address to,\n uint256 tokenId\n ) external;\n\n /**\n * @dev Gives permission to `to` to transfer `tokenId` token to another account.\n * The approval is cleared when the token is transferred.\n *\n * Only a single account can be approved at a time, so approving the zero address clears previous approvals.\n *\n * Requirements:\n *\n * - The caller must own the token or be an approved operator.\n * - `tokenId` must exist.\n *\n * Emits an {Approval} event.\n */\n function approve(address to, uint256 tokenId) external;\n\n /**\n * @dev Approve or remove `operator` as an operator for the caller.\n * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.\n *\n * Requirements:\n *\n * - The `operator` cannot be the caller.\n *\n * Emits an {ApprovalForAll} event.\n */\n function setApprovalForAll(address operator, bool _approved) external;\n\n /**\n * @dev Returns the account approved for `tokenId` token.\n *\n * Requirements:\n *\n * - `tokenId` must exist.\n */\n function getApproved(uint256 tokenId) external view returns (address operator);\n\n /**\n * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.\n *\n * See {setApprovalForAll}\n */\n function isApprovedForAll(address owner, address operator) external view returns (bool);\n}\n" } }, "settings": { "optimizer": { "enabled": true, "runs": 200 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } } } }