{ "language": "Solidity", "sources": { "contracts/LendingNFT.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.4;\n\nimport \"@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol\";\nimport \"@openzeppelin/contracts/token/ERC721/IERC721.sol\";\nimport \"@openzeppelin/contracts/security/ReentrancyGuard.sol\";\nimport \"@openzeppelin/contracts/security/Pausable.sol\";\nimport \"@openzeppelin/contracts/utils/Counters.sol\";\nimport \"@openzeppelin/contracts/utils/Address.sol\";\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"@openzeppelin/contracts/utils/cryptography/ECDSA.sol\";\nimport \"./interfaces/ILendingNFT.sol\";\nimport \"./interfaces/IERC4907.sol\";\nimport \"./common/TransferHelper.sol\";\nimport \"./LendingStorage.sol\";\n\ncontract LendingNFT is AccessControl, ILendingNFT, ReentrancyGuard, Pausable, ERC721Holder\n{\n using ECDSA for bytes32;\n using Address for address;\n\n bytes32 private constant OPERATOR = keccak256(\"OPERATOR\");\n\n uint32 public constant timeADay = 1 days;\n LendingStorage private _storageAddress;\n\n event ORDERCREATE(address lender, address borrower, uint8 status, uint256 orderId, uint8 nftType, uint256 nftId, uint64 rentalDuration, uint256 dailyRentalPrice, uint256 timeStamp);\n event ORDERCANCEL(address canceler, uint8 status, uint256 orderId, uint8 nftType, uint256 nftId, uint256 timeStamp);\n event LENDINGPAYMENT(address borrower, uint8 status, uint256 orderId, uint8 nftType, uint256 nftId, uint256 receivedPrice, uint256 commissionPrice, uint256 expiredTime, uint256 timeStamp);\n event CLAIMPRICE(address lender, uint8 status, uint256 orderId, uint8 nftType, uint256 nftId, uint256 receivedPrice, uint256 timeStamp);\n event CLAIMNFT(address lender, uint8 status, uint256 orderId, uint8 nftType, uint256 nftId, uint256 timeStamp);\n\n constructor(address _storage) {\n _storageAddress = LendingStorage(_storage);\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n }\n\n modifier onlyAdmin() {\n require(hasRole(DEFAULT_ADMIN_ROLE, msg.sender), \"Restricted to admin.\");\n _;\n }\n\n modifier onlyOperator() {\n require(hasRole(OPERATOR, msg.sender), \"Restricted to OPERATOR.\");\n _;\n }\n\n function setOperator(address _operator) external onlyAdmin {\n _setupRole(OPERATOR, _operator);\n }\n\n function setCommissionPercent(uint32 _value) external onlyAdmin {\n LendingStorage.StorageInfor memory info = _storageAddress.getInfor();\n require(_value > 0 && _value < info.percentDecimals, \"VALUE_INVALID\");\n _storageAddress.setCommissionVal(_value);\n }\n\n function getCommissionPercent() external view returns(uint32) {\n return _storageAddress.getCommistionVal();\n }\n\n function setPause(bool _isPause) external onlyOperator {\n require(paused() != _isPause, \"PAUSEABLE_IS_NOT_CHANGE\");\n if (_isPause) {\n _pause();\n } else {\n _unpause();\n }\n }\n\n function orderNFT(\n address _borrower,\n uint8 _nftType,\n uint256 _nftId,\n uint64 _rentalDuration,\n uint256 _dailyRentalPrice\n ) external override\n nonReentrant whenNotPaused {\n LendingStorage.StorageInfor memory info = _storageAddress.getInfor();\n require(_borrower != address(0), \"ADDRESS_INVALID\");\n require(_nftType >= 0 && _nftType < info.countNFTContract, \"NFT_TYPE_INVALID\");\n require(_rentalDuration > 0, \"RENTAL_DURATION_INVALID\");\n require(_dailyRentalPrice > 0, \"DAILY_RENTAL_PRICE_INVALID\");\n require(_nftId > 0, \"NFTID_INVALID\");\n IERC721 nft = IERC721(_storageAddress.getNFTContractAddress(_nftType));\n require(nft.ownerOf(_nftId) == msg.sender, \"YOU_MUST_OWNER_OF_TOKEN\");\n address lender = _msgSender();\n uint256 orderId = _storageAddress.createItemOrder(_nftId, _nftType, _dailyRentalPrice, _rentalDuration, lender, _borrower);\n nft.safeTransferFrom(lender, address(this), _nftId, \"\");\n emit ORDERCREATE(lender, _borrower, uint8(LendingStorage.OrderStatus.WaitPayment), orderId, _nftType, _nftId, _rentalDuration, _dailyRentalPrice, block.timestamp);\n }\n\n function cancelOrderItem(\n uint256 _nftId,\n uint8 _nftType\n ) external override\n nonReentrant whenNotPaused {\n LendingStorage.StorageInfor memory info = _storageAddress.getInfor();\n require(_nftId > 0, \"NFT_INVALID\");\n require(_nftType >= 0 && _nftType < info.countNFTContract, \"NFT_TYPE_INVALID\");\n LendingStorage.OrderERC4907 memory orderItem = _storageAddress.getOrder(_nftId, _nftType);\n require(msg.sender == orderItem.lender || msg.sender == orderItem.borrower , \"UNAUTHORIZED\");\n require(orderItem.status == uint8(LendingStorage.OrderStatus.WaitPayment), \"METHOD_NOT_ALLOWED\");\n _storageAddress.deleteSellOrder(_nftId, _nftType);\n IERC721 nft = IERC721(_storageAddress.getNFTContractAddress(_nftType));\n nft.safeTransferFrom(address(this), orderItem.lender, _nftId, \"\");\n emit ORDERCANCEL(msg.sender, uint8(LendingStorage.OrderStatus.Cancel), orderItem.id, _nftType, _nftId, block.timestamp);\n }\n\n function paymentOrder(\n uint256 _nftId,\n uint8 _nftType,\n uint256 _startTime,\n string memory _orderUUid,\n bytes memory _signature\n ) external override\n nonReentrant whenNotPaused {\n LendingStorage.StorageInfor memory info = _storageAddress.getInfor();\n require(_nftId > 0, \"NFT_INVALID\");\n require(_nftType >= 0 && _nftType < info.countNFTContract, \"NFT_TYPE_INVALID\");\n require(_startTime > 0 && _startTime < block.timestamp + info.maxWaitingTime, \"STARTTIME_ERROR\");\n address borrower = _msgSender();\n require(_storageAddress.isExecutedOrder(_orderUUid) == false, \"ORDER_IS_EXECUTED\");\n _storageAddress.setExecutedOrder(_orderUUid, true);\n LendingStorage.OrderERC4907 memory orderItem = _storageAddress.getOrder(_nftId, _nftType);\n require(verifySignature(_nftId, _nftType, _signature, _orderUUid, info.adminVerify, orderItem.lender, msg.sender), \"SIGNATURE_INVALID\");\n require(orderItem.borrower == borrower, \"UNAUTHORIZED\");\n require(orderItem.status == uint8(LendingStorage.OrderStatus.WaitPayment), \"ORDER_STATUS_NOT_ACTION\");\n uint8 nftType = _nftType;\n uint256 expiredTime = block.timestamp + orderItem.rentalDuration * timeADay;\n uint256 nftId = _nftId;\n IERC4907 nft = IERC4907(_storageAddress.getNFTContractAddress(nftType));\n nft.setUser(nftId, borrower, uint64(expiredTime));\n uint8 statusPaid = uint8(LendingStorage.OrderStatus.Paid);\n _storageAddress.updateOrderItem(nftId, nftType, statusPaid, expiredTime);\n uint256 rentalPrice = orderItem.dailyRentalPrice * orderItem.rentalDuration;\n uint256 commissionPrice = (rentalPrice * orderItem.commissionPercent) / orderItem.percentDecimals;\n uint256 receivedPrice = rentalPrice - commissionPrice;\n _payment(address(this), info.commissionWallet, info.currencyToken, borrower, receivedPrice, commissionPrice);\n emit LENDINGPAYMENT(borrower, statusPaid, orderItem.id, nftType, nftId, receivedPrice, commissionPrice, expiredTime, block.timestamp);\n }\n\n function lenderRewardClaim(\n uint256 _nftId,\n uint8 _nftType,\n string memory _orderUUid,\n bytes memory _signature\n ) external override\n nonReentrant whenNotPaused {\n LendingStorage.StorageInfor memory info = _storageAddress.getInfor();\n require(_nftId > 0, \"NFT_INVALID\");\n require(_nftType >= 0 && _nftType < info.countNFTContract, \"NFT_TYPE_INVALID\");\n require(_storageAddress.isExecutedOrder(_orderUUid) == false, \"ORDER_IS_EXECUTED\");\n _storageAddress.setExecutedOrder(_orderUUid, true);\n LendingStorage.OrderERC4907 memory orderItem = _storageAddress.getOrder(_nftId, _nftType);\n require(verifySignature(_nftId, _nftType, _signature, _orderUUid, info.adminVerify, msg.sender, orderItem.borrower), \"SIGNATURE_INVALID\");\n require(orderItem.lender == msg.sender, \"UNAUTHORIZED\");\n uint8 statusPaid = uint8(LendingStorage.OrderStatus.Paid);\n uint8 statusClaimPrice = uint8(LendingStorage.OrderStatus.IsClaimPrice);\n uint8 statusExpired = uint8(LendingStorage.OrderStatus.Expired);\n require(orderItem.status == statusPaid || orderItem.status == statusExpired, \"METHOD_NOT_ALLOWED\");\n _storageAddress.updateOrderItem(_nftId, _nftType, statusClaimPrice, 0);\n uint256 rentalPrice = orderItem.dailyRentalPrice * orderItem.rentalDuration;\n uint256 receivedPrice = (rentalPrice * (orderItem.percentDecimals - orderItem.commissionPercent)) / orderItem.percentDecimals;\n TransferHelper.contractTransfer(info.currencyToken, msg.sender, receivedPrice);\n emit CLAIMPRICE(msg.sender, statusClaimPrice, orderItem.id, _nftType, _nftId, receivedPrice, block.timestamp);\n }\n\n function lenderClaimNFT(\n uint256 _nftId,\n uint8 _nftType,\n string memory _orderUUid,\n bytes memory _signature\n ) external override\n nonReentrant whenNotPaused {\n LendingStorage.StorageInfor memory info = _storageAddress.getInfor();\n require(_nftId > 0, \"NFT_INVALID\");\n require(_nftType >= 0 && _nftType < info.countNFTContract, \"NFT_TYPE_INVALID\");\n require(_storageAddress.isExecutedOrder(_orderUUid) == false, \"ORDER_IS_EXECUTED\");\n _storageAddress.setExecutedOrder(_orderUUid, true);\n LendingStorage.OrderERC4907 memory orderItem = _storageAddress.getOrder(_nftId, _nftType);\n require(verifySignature(_nftId, _nftType, _signature, _orderUUid, info.adminVerify, msg.sender, orderItem.borrower), \"SIGNATURE_INVALID\");\n require(orderItem.lender == msg.sender, \"UNAUTHORIZED\");\n require(orderItem.status == uint8(LendingStorage.OrderStatus.IsClaimPrice) && orderItem.expiredTime < block.timestamp, \"METHOD_NOT_ALLOWED\");\n _storageAddress.deleteSellOrder(_nftId, _nftType);\n IERC721 nft = IERC721(_storageAddress.getNFTContractAddress(_nftType));\n nft.safeTransferFrom(address(this), msg.sender, _nftId, \"\");\n emit CLAIMNFT(msg.sender, uint8(LendingStorage.OrderStatus.IsClaimNFT), orderItem.id, _nftType, _nftId, block.timestamp);\n }\n\n function _payment(\n address transactionWallet,\n address commisionWallet,\n address currencyExchange,\n address sender,\n uint256 receivedPrice,\n uint256 commissionPrice\n ) private {\n TransferHelper.safeTransferFrom(currencyExchange, sender, transactionWallet, receivedPrice);\n TransferHelper.safeTransferFrom(currencyExchange, sender, commisionWallet, commissionPrice);\n }\n\n function verifySignature(\n uint256 nftId,\n uint256 nftType,\n bytes memory signature,\n string memory orderUUid,\n address verifier,\n address lender,\n address borrower\n ) private pure returns (bool) {\n bytes32 hashValue = keccak256(abi.encodePacked(nftId, nftType, orderUUid, lender, borrower));\n address recover = hashValue.toEthSignedMessageHash().recover(signature);\n return recover == verifier;\n }\n}" }, "contracts/LendingStorage.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.4;\n\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"@openzeppelin/contracts/utils/Address.sol\";\nimport \"@openzeppelin/contracts/utils/Counters.sol\";\nimport \"@openzeppelin/contracts/security/ReentrancyGuard.sol\";\nimport \"@openzeppelin/contracts/security/Pausable.sol\";\nimport \"@openzeppelin/contracts/utils/cryptography/ECDSA.sol\";\n\ncontract LendingStorage is AccessControl, ReentrancyGuard, Pausable {\n using ECDSA for bytes32;\n using Address for address;\n using Counters for Counters.Counter;\n\n enum OrderStatus {\n default_zero,\n WaitPayment,\n Paid,\n IsClaimPrice,\n Expired,\n Cancel,\n IsClaimNFT\n }\n\n struct OrderERC4907 {\n uint256 id;\n address lender;\n address borrower;\n uint8 status;\n uint64 rentalDuration;\n uint256 dailyRentalPrice;\n uint256 startTime;\n uint256 expiredTime;\n uint32 commissionPercent;\n uint32 percentDecimals;\n }\n\n struct StorageInfor {\n uint256 countNFTContract;\n uint32 maxWaitingTime;\n uint32 percentDecimals;\n address adminVerify;\n address commissionWallet;\n address currencyToken;\n }\n\n bytes32 private constant OPERATOR = keccak256(\"OPERATOR\");\n bytes32 private constant MARKET = keccak256(\"MARKET\");\n address private _transactionWallet;\n address private _commissionWallet;\n address private _verifier;\n address private _currencyToken;\n uint32 private _commissionPercent;\n\n mapping(uint256 => Counters.Counter) private _orderIds;\n mapping(uint256 => mapping(uint256 => OrderERC4907)) private orders;\n mapping(string => bool) private _orderUUids;\n address[] private _contractAddresses;\n uint32 private _percentDecimals;\n uint32 private _maxWaitingTime;\n\n constructor() {\n _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n }\n\n modifier onlyAdmin() {\n require(hasRole(DEFAULT_ADMIN_ROLE, msg.sender), \"Restricted to admin.\");\n _;\n }\n\n modifier onlyOperator() {\n require(hasRole(OPERATOR, msg.sender), \"Restricted to OPERATOR.\");\n _;\n }\n\n function setPause(bool _isPause) external onlyOperator {\n require(paused() != _isPause, \"PAUSEABLE_IS_NOT_CHANGE\");\n if (_isPause) {\n _pause();\n } else {\n _unpause();\n }\n }\n\n modifier onlyMarket() {\n require(hasRole(MARKET, msg.sender), \"Restricted to market.\");\n _;\n }\n\n function setOperator(address _operator) external onlyAdmin {\n _setupRole(OPERATOR, _operator);\n }\n\n function setMarket(address _market) external onlyOperator {\n _setupRole(MARKET, _market);\n }\n\n function setMaxWaitingTime(uint32 _minutes) external onlyOperator {\n require(_minutes > 0 && _minutes <= 60, \"VALUE_INVALID\");\n _maxWaitingTime = _minutes * 60;\n }\n\n function setPercentDecimals(uint32 _decimals) external onlyOperator {\n require(_decimals > 0 && _decimals <= 10000, \"VALUE_INVALID\");\n _percentDecimals = _decimals * 100; // decimal * 100%\n }\n\n function setCommissionWallet(address _address) external onlyOperator {\n require(_address != address(0), \"ADDRESS_CAN_NOT_IS_ZERO\");\n _commissionWallet = _address;\n }\n\n function setCurrencyToken(address _token) external onlyOperator {\n require(_token != address(0), \"ADDRESS_CAN_NOT_IS_ZERO\");\n _currencyToken = _token;\n }\n\n function setCommissionVal(uint32 _value) external onlyMarket {\n _commissionPercent = _value;\n }\n\n function getCommistionVal() external onlyMarket view returns(uint32) {\n return _commissionPercent;\n }\n\n function setAddressVerify(address _address) external onlyOperator {\n require(_address != address(0), \"ADDRESS_CAN_NOT_IS_ZERO\");\n _verifier = _address;\n }\n\n function addNFTContractAddress(address[] memory _nftContractAddresses) external onlyOperator {\n for(uint256 i = 0; i < _nftContractAddresses.length; i++) {\n _contractAddresses.push(_nftContractAddresses[i]);\n }\n }\n\n function reloadNFTContractAddress(address[] memory _nftContractAddresses) external onlyOperator {\n require(_nftContractAddresses.length > 0, \"INVALD_WALLET\");\n require(_contractAddresses.length >= _nftContractAddresses.length, \"INVALID_PARAMS\");\n for(uint256 i = 0; i < _nftContractAddresses.length; i++) {\n _contractAddresses[i] = _nftContractAddresses[i];\n }\n }\n\n function createItemOrder(\n uint256 _nftId,\n uint8 _nftType,\n uint256 _dailyRentalPrice,\n uint64 _rentalDuration,\n address _lender,\n address _borrower\n ) external onlyMarket nonReentrant whenNotPaused returns (uint256) {\n OrderERC4907 memory existedOrder = orders[_nftId][_nftType];\n require(existedOrder.id == 0, \"Sell order is already existed\");\n _orderIds[_nftType].increment();\n uint256 orderId = _orderIds[_nftType].current();\n orders[_nftId][_nftType] = OrderERC4907({\n id: orderId,\n lender: _lender,\n borrower: _borrower,\n status: uint8(OrderStatus.WaitPayment),\n rentalDuration: _rentalDuration,\n dailyRentalPrice: _dailyRentalPrice,\n startTime: 0,\n expiredTime: 0,\n commissionPercent: _commissionPercent,\n percentDecimals: _percentDecimals\n });\n return orderId;\n }\n\n function getOrder(uint256 _nftId, uint256 _nftType) external onlyMarket view returns (OrderERC4907 memory) {\n return orders[_nftId][_nftType];\n }\n\n function updateOrderItem(\n uint256 _nftId,\n uint8 _nftType,\n uint8 _newStatus,\n uint256 _expiredTime\n ) external onlyMarket {\n if (_newStatus != uint8(OrderStatus.default_zero)) {\n orders[_nftId][_nftType].status = _newStatus;\n }\n if (_expiredTime != 0) {\n orders[_nftId][_nftType].startTime = block.timestamp;\n orders[_nftId][_nftType].expiredTime = _expiredTime;\n }\n }\n\n function deleteSellOrder(\n uint256 _nftId,\n uint8 _nftType\n ) external onlyMarket {\n orders[_nftId][_nftType].id = 0;\n delete orders[_nftId][_nftType];\n }\n\n function getNFTContractAddress(uint256 _nftType) external onlyMarket view returns(address) {\n return _contractAddresses[_nftType];\n }\n\n function isExecutedOrder(string memory _orderUUid) external onlyMarket view returns(bool) {\n return _orderUUids[_orderUUid];\n }\n\n function setExecutedOrder(string memory _orderUUid, bool _status) external onlyMarket {\n _orderUUids[_orderUUid] = _status;\n }\n\n function getInfor() onlyMarket external view returns (StorageInfor memory) {\n StorageInfor memory info = StorageInfor({\n countNFTContract: _contractAddresses.length,\n maxWaitingTime: _maxWaitingTime,\n percentDecimals: _percentDecimals,\n adminVerify: _verifier,\n commissionWallet: _commissionWallet,\n currencyToken: _currencyToken\n });\n return info;\n }\n}" }, "contracts/interfaces/ILendingNFT.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.4;\n\ninterface ILendingNFT\n{\n function orderNFT(\n address _borrower,\n uint8 _nftType,\n uint256 _nftId,\n uint64 _rentalDuration,\n uint256 _dailyRentalPrice\n ) external;\n\n function cancelOrderItem(\n uint256 _nftId,\n uint8 _nftType\n ) external;\n\n function paymentOrder(\n uint256 _nftId,\n uint8 _nftType,\n uint256 _startTime,\n string memory _orderUUid,\n bytes memory _signature\n ) external;\n\n function lenderRewardClaim(\n uint256 _nftId,\n uint8 _nftType,\n string memory _orderUUid,\n bytes memory _signature\n ) external;\n\n function lenderClaimNFT(\n uint256 _nftId,\n uint8 _nftType,\n string memory _orderUUid,\n bytes memory _signature\n ) external;\n}" }, "contracts/interfaces/IERC4907.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.7;\n\ninterface IERC4907 {\n\n // Logged when the user of an NFT is changed or expires is changed\n /// @notice Emitted when the `user` of an NFT or the `expires` of the `user` is changed\n /// The zero address for user indicates that there is no user address\n event UpdateUser(uint256 indexed tokenId, address indexed user, uint64 expires);\n\n /// @notice set the user and expires of an NFT\n /// @dev The zero address indicates there is no user\n /// Throws if `tokenId` is not valid NFT\n /// @param user The new user of the NFT\n /// @param expires UNIX timestamp, The new user could use the NFT before expires\n function setUser(uint256 tokenId, address user, uint64 expires) external;\n\n /// @notice Get the user address of an NFT\n /// @dev The zero address indicates that there is no user or the user is expired\n /// @param tokenId The NFT to get the user address for\n /// @return The user address for this NFT\n function userOf(uint256 tokenId) external view returns(address);\n\n /// @notice Get the user expires of an NFT\n /// @dev The zero value indicates that there is no user\n /// @param tokenId The NFT to get the user expires for\n /// @return The user expires for this NFT\n function userExpires(uint256 tokenId) external view returns(uint256);\n}\n" }, "contracts/common/TransferHelper.sol": { "content": "//SPDX-License-Identifier: MIT\npragma solidity ^0.8.4;\n\nlibrary TransferHelper {\n function safeTransferFrom(\n address token,\n address from,\n address to,\n uint256 value\n ) internal {\n // bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));\n (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));\n require(\n success && (data.length == 0 || abi.decode(data, (bool))),\n 'TransferHelper::transferFrom: transferFrom failed'\n );\n }\n\n function contractTransfer(\n address token,\n address to,\n uint256 value\n ) internal {\n // bytes4(keccak256(bytes('transfer(address,uint256)')));\n (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));\n require(\n success && (data.length == 0 || abi.decode(data, (bool))),\n 'TransferHelper::transferFrom: transferFrom failed'\n );\n }\n}\n" }, "@openzeppelin/contracts/security/ReentrancyGuard.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (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 // On the first call to nonReentrant, _notEntered will be true\n require(_status != _ENTERED, \"ReentrancyGuard: reentrant call\");\n\n // Any calls to nonReentrant after this point will fail\n _status = _ENTERED;\n\n _;\n\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/security/Pausable.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which allows children to implement an emergency stop\n * mechanism that can be triggered by an authorized account.\n *\n * This module is used through inheritance. It will make available the\n * modifiers `whenNotPaused` and `whenPaused`, which can be applied to\n * the functions of your contract. Note that they will not be pausable by\n * simply including this module, only once the modifiers are put in place.\n */\nabstract contract Pausable is Context {\n /**\n * @dev Emitted when the pause is triggered by `account`.\n */\n event Paused(address account);\n\n /**\n * @dev Emitted when the pause is lifted by `account`.\n */\n event Unpaused(address account);\n\n bool private _paused;\n\n /**\n * @dev Initializes the contract in unpaused state.\n */\n constructor() {\n _paused = false;\n }\n\n /**\n * @dev Modifier to make a function callable only when the contract is not paused.\n *\n * Requirements:\n *\n * - The contract must not be paused.\n */\n modifier whenNotPaused() {\n _requireNotPaused();\n _;\n }\n\n /**\n * @dev Modifier to make a function callable only when the contract is paused.\n *\n * Requirements:\n *\n * - The contract must be paused.\n */\n modifier whenPaused() {\n _requirePaused();\n _;\n }\n\n /**\n * @dev Returns true if the contract is paused, and false otherwise.\n */\n function paused() public view virtual returns (bool) {\n return _paused;\n }\n\n /**\n * @dev Throws if the contract is paused.\n */\n function _requireNotPaused() internal view virtual {\n require(!paused(), \"Pausable: paused\");\n }\n\n /**\n * @dev Throws if the contract is not paused.\n */\n function _requirePaused() internal view virtual {\n require(paused(), \"Pausable: not paused\");\n }\n\n /**\n * @dev Triggers stopped state.\n *\n * Requirements:\n *\n * - The contract must not be paused.\n */\n function _pause() internal virtual whenNotPaused {\n _paused = true;\n emit Paused(_msgSender());\n }\n\n /**\n * @dev Returns to normal state.\n *\n * Requirements:\n *\n * - The contract must be paused.\n */\n function _unpause() internal virtual whenPaused {\n _paused = false;\n emit Unpaused(_msgSender());\n }\n}\n" }, "@openzeppelin/contracts/utils/Counters.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Counters.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @title Counters\n * @author Matt Condon (@shrugs)\n * @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number\n * of elements in a mapping, issuing ERC721 ids, or counting request ids.\n *\n * Include with `using Counters for Counters.Counter;`\n */\nlibrary Counters {\n struct Counter {\n // This variable should never be directly accessed by users of the library: interactions must be restricted to\n // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add\n // this feature: see https://github.com/ethereum/solidity/issues/4637\n uint256 _value; // default: 0\n }\n\n function current(Counter storage counter) internal view returns (uint256) {\n return counter._value;\n }\n\n function increment(Counter storage counter) internal {\n unchecked {\n counter._value += 1;\n }\n }\n\n function decrement(Counter storage counter) internal {\n uint256 value = counter._value;\n require(value > 0, \"Counter: decrement overflow\");\n unchecked {\n counter._value = value - 1;\n }\n }\n\n function reset(Counter storage counter) internal {\n counter._value = 0;\n }\n}\n" }, "@openzeppelin/contracts/utils/Address.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.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 functionCall(target, data, \"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 require(isContract(target), \"Address: call to non-contract\");\n\n (bool success, bytes memory returndata) = target.call{value: value}(data);\n return verifyCallResult(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 require(isContract(target), \"Address: static call to non-contract\");\n\n (bool success, bytes memory returndata) = target.staticcall(data);\n return verifyCallResult(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 require(isContract(target), \"Address: delegate call to non-contract\");\n\n (bool success, bytes memory returndata) = target.delegatecall(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the\n * revert reason 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 // 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}\n" }, "@openzeppelin/contracts/access/AccessControl.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.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(uint160(account), 20),\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" }, "@openzeppelin/contracts/token/ERC721/IERC721.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.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: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.\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" }, "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC721/utils/ERC721Holder.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC721Receiver.sol\";\n\n/**\n * @dev Implementation of the {IERC721Receiver} interface.\n *\n * Accepts all token transfers.\n * Make sure the contract is able to use its token with {IERC721-safeTransferFrom}, {IERC721-approve} or {IERC721-setApprovalForAll}.\n */\ncontract ERC721Holder is IERC721Receiver {\n /**\n * @dev See {IERC721Receiver-onERC721Received}.\n *\n * Always returns `IERC721Receiver.onERC721Received.selector`.\n */\n function onERC721Received(\n address,\n address,\n uint256,\n bytes memory\n ) public virtual override returns (bytes4) {\n return this.onERC721Received.selector;\n }\n}\n" }, "@openzeppelin/contracts/utils/cryptography/ECDSA.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.3) (utils/cryptography/ECDSA.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../Strings.sol\";\n\n/**\n * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.\n *\n * These functions can be used to verify that a message was signed by the holder\n * of the private keys of a given address.\n */\nlibrary ECDSA {\n enum RecoverError {\n NoError,\n InvalidSignature,\n InvalidSignatureLength,\n InvalidSignatureS,\n InvalidSignatureV\n }\n\n function _throwError(RecoverError error) private pure {\n if (error == RecoverError.NoError) {\n return; // no error: do nothing\n } else if (error == RecoverError.InvalidSignature) {\n revert(\"ECDSA: invalid signature\");\n } else if (error == RecoverError.InvalidSignatureLength) {\n revert(\"ECDSA: invalid signature length\");\n } else if (error == RecoverError.InvalidSignatureS) {\n revert(\"ECDSA: invalid signature 's' value\");\n } else if (error == RecoverError.InvalidSignatureV) {\n revert(\"ECDSA: invalid signature 'v' value\");\n }\n }\n\n /**\n * @dev Returns the address that signed a hashed message (`hash`) with\n * `signature` or error string. This address can then be used for verification purposes.\n *\n * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:\n * this function rejects them by requiring the `s` value to be in the lower\n * half order, and the `v` value to be either 27 or 28.\n *\n * IMPORTANT: `hash` _must_ be the result of a hash operation for the\n * verification to be secure: it is possible to craft signatures that\n * recover to arbitrary addresses for non-hashed data. A safe way to ensure\n * this is by receiving a hash of the original message (which may otherwise\n * be too long), and then calling {toEthSignedMessageHash} on it.\n *\n * Documentation for signature generation:\n * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]\n * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]\n *\n * _Available since v4.3._\n */\n function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {\n if (signature.length == 65) {\n bytes32 r;\n bytes32 s;\n uint8 v;\n // ecrecover takes the signature parameters, and the only way to get them\n // currently is to use assembly.\n /// @solidity memory-safe-assembly\n assembly {\n r := mload(add(signature, 0x20))\n s := mload(add(signature, 0x40))\n v := byte(0, mload(add(signature, 0x60)))\n }\n return tryRecover(hash, v, r, s);\n } else {\n return (address(0), RecoverError.InvalidSignatureLength);\n }\n }\n\n /**\n * @dev Returns the address that signed a hashed message (`hash`) with\n * `signature`. This address can then be used for verification purposes.\n *\n * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:\n * this function rejects them by requiring the `s` value to be in the lower\n * half order, and the `v` value to be either 27 or 28.\n *\n * IMPORTANT: `hash` _must_ be the result of a hash operation for the\n * verification to be secure: it is possible to craft signatures that\n * recover to arbitrary addresses for non-hashed data. A safe way to ensure\n * this is by receiving a hash of the original message (which may otherwise\n * be too long), and then calling {toEthSignedMessageHash} on it.\n */\n function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {\n (address recovered, RecoverError error) = tryRecover(hash, signature);\n _throwError(error);\n return recovered;\n }\n\n /**\n * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.\n *\n * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]\n *\n * _Available since v4.3._\n */\n function tryRecover(\n bytes32 hash,\n bytes32 r,\n bytes32 vs\n ) internal pure returns (address, RecoverError) {\n bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);\n uint8 v = uint8((uint256(vs) >> 255) + 27);\n return tryRecover(hash, v, r, s);\n }\n\n /**\n * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.\n *\n * _Available since v4.2._\n */\n function recover(\n bytes32 hash,\n bytes32 r,\n bytes32 vs\n ) internal pure returns (address) {\n (address recovered, RecoverError error) = tryRecover(hash, r, vs);\n _throwError(error);\n return recovered;\n }\n\n /**\n * @dev Overload of {ECDSA-tryRecover} that receives the `v`,\n * `r` and `s` signature fields separately.\n *\n * _Available since v4.3._\n */\n function tryRecover(\n bytes32 hash,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) internal pure returns (address, RecoverError) {\n // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature\n // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines\n // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most\n // signatures from current libraries generate a unique signature with an s-value in the lower half order.\n //\n // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value\n // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or\n // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept\n // these malleable signatures as well.\n if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {\n return (address(0), RecoverError.InvalidSignatureS);\n }\n if (v != 27 && v != 28) {\n return (address(0), RecoverError.InvalidSignatureV);\n }\n\n // If the signature is valid (and not malleable), return the signer address\n address signer = ecrecover(hash, v, r, s);\n if (signer == address(0)) {\n return (address(0), RecoverError.InvalidSignature);\n }\n\n return (signer, RecoverError.NoError);\n }\n\n /**\n * @dev Overload of {ECDSA-recover} that receives the `v`,\n * `r` and `s` signature fields separately.\n */\n function recover(\n bytes32 hash,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) internal pure returns (address) {\n (address recovered, RecoverError error) = tryRecover(hash, v, r, s);\n _throwError(error);\n return recovered;\n }\n\n /**\n * @dev Returns an Ethereum Signed Message, created from a `hash`. This\n * produces hash corresponding to the one signed with the\n * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]\n * JSON-RPC method as part of EIP-191.\n *\n * See {recover}.\n */\n function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {\n // 32 is the length in bytes of hash,\n // enforced by the type signature above\n return keccak256(abi.encodePacked(\"\\x19Ethereum Signed Message:\\n32\", hash));\n }\n\n /**\n * @dev Returns an Ethereum Signed Message, created from `s`. This\n * produces hash corresponding to the one signed with the\n * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]\n * JSON-RPC method as part of EIP-191.\n *\n * See {recover}.\n */\n function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(\"\\x19Ethereum Signed Message:\\n\", Strings.toString(s.length), s));\n }\n\n /**\n * @dev Returns an Ethereum Signed Typed Data, created from a\n * `domainSeparator` and a `structHash`. This produces hash corresponding\n * to the one signed with the\n * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]\n * JSON-RPC method as part of EIP-712.\n *\n * See {recover}.\n */\n function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(\"\\x19\\x01\", domainSeparator, structHash));\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" }, "@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.7.0) (utils/Strings.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev String operations.\n */\nlibrary Strings {\n bytes16 private constant _HEX_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 // Inspired by OraclizeAPI's implementation - MIT licence\n // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol\n\n if (value == 0) {\n return \"0\";\n }\n uint256 temp = value;\n uint256 digits;\n while (temp != 0) {\n digits++;\n temp /= 10;\n }\n bytes memory buffer = new bytes(digits);\n while (value != 0) {\n digits -= 1;\n buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));\n value /= 10;\n }\n return string(buffer);\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 if (value == 0) {\n return \"0x00\";\n }\n uint256 temp = value;\n uint256 length = 0;\n while (temp != 0) {\n length++;\n temp >>= 8;\n }\n return toHexString(value, length);\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] = _HEX_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/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/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/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" } }, "settings": { "optimizer": { "enabled": true, "runs": 1 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "libraries": {} } }