UNPKG

@openzeppelin/upgrades

Version:

JavaScript library for the OpenZeppelin smart contract platform

320 lines (319 loc) 1.09 MB
{ "fileName": "MockStandaloneERC721.sol", "contractName": "Address", "source": "pragma solidity ^0.5.0;\n\nimport \"../Initializable.sol\";\n\n// File: contracts/introspection/IERC165.sol\n\n/**\n * @title IERC165\n * @dev https://github.com/ethereum/EIPs/blob/master/EIPS/eip-165.md\n */\ninterface IERC165 {\n /**\n * @notice Query if a contract implements an interface\n * @param interfaceId The interface identifier, as specified in ERC-165\n * @dev Interface identification is specified in ERC-165. This function\n * uses less than 30,000 gas.\n */\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n\n// File: contracts/token/MockERC721/IMockERC721.sol\n\n\n\n/**\n * @title MockERC721 Non-Fungible Token Standard basic interface\n * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md\n */\ncontract IMockERC721 is Initializable, IERC165 {\n event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);\n event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);\n event ApprovalForAll(address indexed owner, address indexed operator, bool approved);\n\n function balanceOf(address owner) public view returns (uint256 balance);\n function ownerOf(uint256 tokenId) public view returns (address owner);\n\n function approve(address to, uint256 tokenId) public;\n function getApproved(uint256 tokenId) public view returns (address operator);\n\n function setApprovalForAll(address operator, bool _approved) public;\n function isApprovedForAll(address owner, address operator) public view returns (bool);\n\n function transferFrom(address from, address to, uint256 tokenId) public;\n function safeTransferFrom(address from, address to, uint256 tokenId) public;\n\n function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public;\n}\n\n// File: contracts/token/MockERC721/IMockERC721Receiver.sol\n\n/**\n * @title MockERC721 token receiver interface\n * @dev Interface for any contract that wants to support safeTransfers\n * from MockERC721 asset contracts.\n */\ncontract IMockERC721Receiver {\n /**\n * @notice Handle the receipt of an NFT\n * @dev The MockERC721 smart contract calls this function on the recipient\n * after a `safeTransfer`. This function MUST return the function selector,\n * otherwise the caller will revert the transaction. The selector to be\n * returned can be obtained as `this.onMockERC721Received.selector`. This\n * function MAY throw to revert and reject the transfer.\n * Note: the MockERC721 contract address is always the message sender.\n * @param operator The address which called `safeTransferFrom` function\n * @param from The address which previously owned the token\n * @param tokenId The NFT identifier which is being transferred\n * @param data Additional data with no specified format\n * @return `bytes4(keccak256(\"onMockERC721Received(address,address,uint256,bytes)\"))`\n */\n function onMockERC721Received(address operator, address from, uint256 tokenId, bytes memory data)\n public returns (bytes4);\n}\n\n// File: contracts/math/SafeMath.sol\n\n/**\n * @title SafeMath\n * @dev Unsigned math operations with safety checks that revert on error\n */\nlibrary SafeMath {\n /**\n * @dev Multiplies two unsigned integers, reverts on overflow.\n */\n function mul(uint256 a, uint256 b) internal pure returns (uint256) {\n // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\n // benefit is lost if 'b' is also tested.\n // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522\n if (a == 0) {\n return 0;\n }\n\n uint256 c = a * b;\n require(c / a == b);\n\n return c;\n }\n\n /**\n * @dev Integer division of two unsigned integers truncating the quotient, reverts on division by zero.\n */\n function div(uint256 a, uint256 b) internal pure returns (uint256) {\n // Solidity only automatically asserts when dividing by 0\n require(b > 0);\n uint256 c = a / b;\n // assert(a == b * c + a % b); // There is no case in which this doesn't hold\n\n return c;\n }\n\n /**\n * @dev Subtracts two unsigned integers, reverts on overflow (i.e. if subtrahend is greater than minuend).\n */\n function sub(uint256 a, uint256 b) internal pure returns (uint256) {\n require(b <= a);\n uint256 c = a - b;\n\n return c;\n }\n\n /**\n * @dev Adds two unsigned integers, reverts on overflow.\n */\n function add(uint256 a, uint256 b) internal pure returns (uint256) {\n uint256 c = a + b;\n require(c >= a);\n\n return c;\n }\n\n /**\n * @dev Divides two unsigned integers and returns the remainder (unsigned integer modulo),\n * reverts when dividing by zero.\n */\n function mod(uint256 a, uint256 b) internal pure returns (uint256) {\n require(b != 0);\n return a % b;\n }\n}\n\n// File: contracts/utils/Address.sol\n\n/**\n * Utility library of inline functions on addresses\n */\nlibrary Address {\n /**\n * Returns whether the target address is a contract\n * @dev This function will return false if invoked during the constructor of a contract,\n * as the code is not actually created until after the constructor finishes.\n * @param account address of the account to check\n * @return whether the target address is a contract\n */\n function isContract(address account) internal view returns (bool) {\n uint256 size;\n // XXX Currently there is no better way to check if there is a contract in an address\n // than to check the size of the code at that address.\n // See https://ethereum.stackexchange.com/a/14016/36603\n // for more details about how this works.\n // TODO Check this again before the Serenity release, because all addresses will be\n // contracts then.\n // solhint-disable-next-line no-inline-assembly\n assembly { size := extcodesize(account) }\n return size > 0;\n }\n}\n\n// File: contracts/introspection/ERC165.sol\n\n\n\n/**\n * @title ERC165\n * @author Matt Condon (@shrugs)\n * @dev Implements ERC165 using a lookup table.\n */\ncontract ERC165 is Initializable, IERC165 {\n bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7;\n /**\n * 0x01ffc9a7 ===\n * bytes4(keccak256('supportsInterface(bytes4)'))\n */\n\n /**\n * @dev a mapping of interface id to whether or not it's supported\n */\n mapping(bytes4 => bool) private _supportedInterfaces;\n\n /**\n * @dev A contract implementing SupportsInterfaceWithLookup\n * implement ERC165 itself\n */\n function initialize() public initializer {\n _registerInterface(_INTERFACE_ID_ERC165);\n }\n\n /**\n * @dev implement supportsInterface(bytes4) using a lookup table\n */\n function supportsInterface(bytes4 interfaceId) public view returns (bool) {\n return _supportedInterfaces[interfaceId];\n }\n\n /**\n * @dev internal method for registering an interface\n */\n function _registerInterface(bytes4 interfaceId) internal {\n require(interfaceId != 0xffffffff);\n _supportedInterfaces[interfaceId] = true;\n }\n\n uint256[50] private ______gap;\n}\n\n// File: contracts/token/MockERC721/MockERC721.sol\n\n/**\n * @title MockERC721 Non-Fungible Token Standard basic implementation\n * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md\n */\ncontract MockERC721 is Initializable, ERC165, IMockERC721 {\n using SafeMath for uint256;\n using Address for address;\n\n // Equals to `bytes4(keccak256(\"onMockERC721Received(address,address,uint256,bytes)\"))`\n // which can be also obtained as `IMockERC721Receiver(0).onMockERC721Received.selector`\n bytes4 private constant _MockERC721_RECEIVED = 0x150b7a02;\n\n // Mapping from token ID to owner\n mapping (uint256 => address) private _tokenOwner;\n\n // Mapping from token ID to approved address\n mapping (uint256 => address) private _tokenApprovals;\n\n // Mapping from owner to number of owned token\n mapping (address => uint256) private _ownedTokensCount;\n\n // Mapping from owner to operator approvals\n mapping (address => mapping (address => bool)) private _operatorApprovals;\n\n bytes4 private constant _INTERFACE_ID_MockERC721 = 0x80ac58cd;\n /*\n * 0x80ac58cd ===\n * bytes4(keccak256('balanceOf(address)')) ^\n * bytes4(keccak256('ownerOf(uint256)')) ^\n * bytes4(keccak256('approve(address,uint256)')) ^\n * bytes4(keccak256('getApproved(uint256)')) ^\n * bytes4(keccak256('setApprovalForAll(address,bool)')) ^\n * bytes4(keccak256('isApprovedForAll(address,address)')) ^\n * bytes4(keccak256('transferFrom(address,address,uint256)')) ^\n * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^\n * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)'))\n */\n\n function initialize() public initializer {\n ERC165.initialize();\n\n // register the supported interfaces to conform to MockERC721 via ERC165\n _registerInterface(_INTERFACE_ID_MockERC721);\n }\n\n function _hasBeenInitialized() internal view returns (bool) {\n return supportsInterface(_INTERFACE_ID_MockERC721);\n }\n\n /**\n * @dev Gets the balance of the specified address\n * @param owner address to query the balance of\n * @return uint256 representing the amount owned by the passed address\n */\n function balanceOf(address owner) public view returns (uint256) {\n require(owner != address(0));\n return _ownedTokensCount[owner];\n }\n\n /**\n * @dev Gets the owner of the specified token ID\n * @param tokenId uint256 ID of the token to query the owner of\n * @return owner address currently marked as the owner of the given token ID\n */\n function ownerOf(uint256 tokenId) public view returns (address) {\n address owner = _tokenOwner[tokenId];\n require(owner != address(0));\n return owner;\n }\n\n /**\n * @dev Approves another address to transfer the given token ID\n * The zero address indicates there is no approved address.\n * There can only be one approved address per token at a given time.\n * Can only be called by the token owner or an approved operator.\n * @param to address to be approved for the given token ID\n * @param tokenId uint256 ID of the token to be approved\n */\n function approve(address to, uint256 tokenId) public {\n address owner = ownerOf(tokenId);\n require(to != owner);\n require(msg.sender == owner || isApprovedForAll(owner, msg.sender));\n\n _tokenApprovals[tokenId] = to;\n emit Approval(owner, to, tokenId);\n }\n\n /**\n * @dev Gets the approved address for a token ID, or zero if no address set\n * Reverts if the token ID does not exist.\n * @param tokenId uint256 ID of the token to query the approval of\n * @return address currently approved for the given token ID\n */\n function getApproved(uint256 tokenId) public view returns (address) {\n require(_exists(tokenId));\n return _tokenApprovals[tokenId];\n }\n\n /**\n * @dev Sets or unsets the approval of a given operator\n * An operator is allowed to transfer all tokens of the sender on their behalf\n * @param to operator address to set the approval\n * @param approved representing the status of the approval to be set\n */\n function setApprovalForAll(address to, bool approved) public {\n require(to != msg.sender);\n _operatorApprovals[msg.sender][to] = approved;\n emit ApprovalForAll(msg.sender, to, approved);\n }\n\n /**\n * @dev Tells whether an operator is approved by a given owner\n * @param owner owner address which you want to query the approval of\n * @param operator operator address which you want to query the approval of\n * @return bool whether the given operator is approved by the given owner\n */\n function isApprovedForAll(address owner, address operator) public view returns (bool) {\n return _operatorApprovals[owner][operator];\n }\n\n /**\n * @dev Transfers the ownership of a given token ID to another address\n * Usage of this method is discouraged, use `safeTransferFrom` whenever possible\n * Requires the msg sender to be the owner, approved, or operator\n * @param from current owner of the token\n * @param to address to receive the ownership of the given token ID\n * @param tokenId uint256 ID of the token to be transferred\n */\n function transferFrom(address from, address to, uint256 tokenId) public {\n require(_isApprovedOrOwner(msg.sender, tokenId));\n\n _transferFrom(from, to, tokenId);\n }\n\n /**\n * @dev Safely transfers the ownership of a given token ID to another address\n * If the target address is a contract, it must implement `onMockERC721Received`,\n * which is called upon a safe transfer, and return the magic value\n * `bytes4(keccak256(\"onMockERC721Received(address,address,uint256,bytes)\"))`; otherwise,\n * the transfer is reverted.\n *\n * Requires the msg sender to be the owner, approved, or operator\n * @param from current owner of the token\n * @param to address to receive the ownership of the given token ID\n * @param tokenId uint256 ID of the token to be transferred\n */\n function safeTransferFrom(address from, address to, uint256 tokenId) public {\n safeTransferFrom(from, to, tokenId, \"\");\n }\n\n /**\n * @dev Safely transfers the ownership of a given token ID to another address\n * If the target address is a contract, it must implement `onMockERC721Received`,\n * which is called upon a safe transfer, and return the magic value\n * `bytes4(keccak256(\"onMockERC721Received(address,address,uint256,bytes)\"))`; otherwise,\n * the transfer is reverted.\n * Requires the msg sender to be the owner, approved, or operator\n * @param from current owner of the token\n * @param to address to receive the ownership of the given token ID\n * @param tokenId uint256 ID of the token to be transferred\n * @param _data bytes data to send along with a safe transfer check\n */\n function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) public {\n transferFrom(from, to, tokenId);\n require(_checkOnMockERC721Received(from, to, tokenId, _data));\n }\n\n /**\n * @dev Returns whether the specified token exists\n * @param tokenId uint256 ID of the token to query the existence of\n * @return whether the token exists\n */\n function _exists(uint256 tokenId) internal view returns (bool) {\n address owner = _tokenOwner[tokenId];\n return owner != address(0);\n }\n\n /**\n * @dev Returns whether the given spender can transfer a given token ID\n * @param spender address of the spender to query\n * @param tokenId uint256 ID of the token to be transferred\n * @return bool whether the msg.sender is approved for the given token ID,\n * is an operator of the owner, or is the owner of the token\n */\n function _isApprovedOrOwner(address spender, uint256 tokenId) internal view returns (bool) {\n address owner = ownerOf(tokenId);\n return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender));\n }\n\n /**\n * @dev Internal function to mint a new token\n * Reverts if the given token ID already exists\n * @param to The address that will own the minted token\n * @param tokenId uint256 ID of the token to be minted\n */\n function _mint(address to, uint256 tokenId) internal {\n require(to != address(0));\n require(!_exists(tokenId));\n\n _tokenOwner[tokenId] = to;\n _ownedTokensCount[to] = _ownedTokensCount[to].add(1);\n\n emit Transfer(address(0), to, tokenId);\n }\n\n /**\n * @dev Internal function to burn a specific token\n * Reverts if the token does not exist\n * Deprecated, use _burn(uint256) instead.\n * @param owner owner of the token to burn\n * @param tokenId uint256 ID of the token being burned\n */\n function _burn(address owner, uint256 tokenId) internal {\n require(ownerOf(tokenId) == owner);\n\n _clearApproval(tokenId);\n\n _ownedTokensCount[owner] = _ownedTokensCount[owner].sub(1);\n _tokenOwner[tokenId] = address(0);\n\n emit Transfer(owner, address(0), tokenId);\n }\n\n /**\n * @dev Internal function to burn a specific token\n * Reverts if the token does not exist\n * @param tokenId uint256 ID of the token being burned\n */\n function _burn(uint256 tokenId) internal {\n _burn(ownerOf(tokenId), tokenId);\n }\n\n /**\n * @dev Internal function to transfer ownership of a given token ID to another address.\n * As opposed to transferFrom, this imposes no restrictions on msg.sender.\n * @param from current owner of the token\n * @param to address to receive the ownership of the given token ID\n * @param tokenId uint256 ID of the token to be transferred\n */\n function _transferFrom(address from, address to, uint256 tokenId) internal {\n require(ownerOf(tokenId) == from);\n require(to != address(0));\n\n _clearApproval(tokenId);\n\n _ownedTokensCount[from] = _ownedTokensCount[from].sub(1);\n _ownedTokensCount[to] = _ownedTokensCount[to].add(1);\n\n _tokenOwner[tokenId] = to;\n\n emit Transfer(from, to, tokenId);\n }\n\n /**\n * @dev Internal function to invoke `onMockERC721Received` on a target address\n * The call is not executed if the target address is not a contract\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 tokenId uint256 ID of the token to be transferred\n * @param _data bytes optional data to send along with the call\n * @return whether the call correctly returned the expected magic value\n */\n function _checkOnMockERC721Received(address from, address to, uint256 tokenId, bytes memory _data)\n internal returns (bool)\n {\n if (!to.isContract()) {\n return true;\n }\n\n bytes4 retval = IMockERC721Receiver(to).onMockERC721Received(msg.sender, from, tokenId, _data);\n return (retval == _MockERC721_RECEIVED);\n }\n\n /**\n * @dev Private function to clear current approval of a given token ID\n * @param tokenId uint256 ID of the token to be transferred\n */\n function _clearApproval(uint256 tokenId) private {\n if (_tokenApprovals[tokenId] != address(0)) {\n _tokenApprovals[tokenId] = address(0);\n }\n }\n\n uint256[50] private ______gap;\n}\n\n// File: contracts/token/MockERC721/IMockERC721Enumerable.sol\n\n\n\n/**\n * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension\n * @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md\n */\ncontract IMockERC721Enumerable is Initializable, IMockERC721 {\n function totalSupply() public view returns (uint256);\n function tokenOfOwnerByIndex(address owner, uint256 index) public view returns (uint256 tokenId);\n\n function tokenByIndex(uint256 index) public view returns (uint256);\n}\n\n// File: contracts/token/MockERC721/MockERC721Enumerable.sol\n\n\n\n\n\n/**\n * @title ERC-721 Non-Fungible Token with optional enumeration extension logic\n * @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md\n */\ncontract MockERC721Enumerable is Initializable, ERC165, MockERC721, IMockERC721Enumerable {\n // Mapping from owner to list of owned token IDs\n mapping(address => uint256[]) private _ownedTokens;\n\n // Mapping from token ID to index of the owner tokens list\n mapping(uint256 => uint256) private _ownedTokensIndex;\n\n // Array with all token ids, used for enumeration\n uint256[] private _allTokens;\n\n // Mapping from token id to position in the allTokens array\n mapping(uint256 => uint256) private _allTokensIndex;\n\n bytes4 private constant _INTERFACE_ID_MockERC721_ENUMERABLE = 0x780e9d63;\n /**\n * 0x780e9d63 ===\n * bytes4(keccak256('totalSupply()')) ^\n * bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) ^\n * bytes4(keccak256('tokenByIndex(uint256)'))\n */\n\n /**\n * @dev Constructor function\n */\n function initialize() public initializer {\n require(MockERC721._hasBeenInitialized());\n\n // register the supported interface to conform to MockERC721 via ERC165\n _registerInterface(_INTERFACE_ID_MockERC721_ENUMERABLE);\n }\n\n function _hasBeenInitialized() internal view returns (bool) {\n return supportsInterface(_INTERFACE_ID_MockERC721_ENUMERABLE);\n }\n\n /**\n * @dev Gets the token ID at a given index of the tokens list of the requested owner\n * @param owner address owning the tokens list to be accessed\n * @param index uint256 representing the index to be accessed of the requested tokens list\n * @return uint256 token ID at the given index of the tokens list owned by the requested address\n */\n function tokenOfOwnerByIndex(address owner, uint256 index) public view returns (uint256) {\n require(index < balanceOf(owner));\n return _ownedTokens[owner][index];\n }\n\n /**\n * @dev Gets the total amount of tokens stored by the contract\n * @return uint256 representing the total amount of tokens\n */\n function totalSupply() public view returns (uint256) {\n return _allTokens.length;\n }\n\n /**\n * @dev Gets the token ID at a given index of all the tokens in this contract\n * Reverts if the index is greater or equal to the total number of tokens\n * @param index uint256 representing the index to be accessed of the tokens list\n * @return uint256 token ID at the given index of the tokens list\n */\n function tokenByIndex(uint256 index) public view returns (uint256) {\n require(index < totalSupply());\n return _allTokens[index];\n }\n\n /**\n * @dev Internal function to transfer ownership of a given token ID to another address.\n * As opposed to transferFrom, this imposes no restrictions on msg.sender.\n * @param from current owner of the token\n * @param to address to receive the ownership of the given token ID\n * @param tokenId uint256 ID of the token to be transferred\n */\n function _transferFrom(address from, address to, uint256 tokenId) internal {\n super._transferFrom(from, to, tokenId);\n\n _removeTokenFromOwnerEnumeration(from, tokenId);\n\n _addTokenToOwnerEnumeration(to, tokenId);\n }\n\n /**\n * @dev Internal function to mint a new token\n * Reverts if the given token ID already exists\n * @param to address the beneficiary that will own the minted token\n * @param tokenId uint256 ID of the token to be minted\n */\n function _mint(address to, uint256 tokenId) internal {\n super._mint(to, tokenId);\n\n _addTokenToOwnerEnumeration(to, tokenId);\n\n _addTokenToAllTokensEnumeration(tokenId);\n }\n\n /**\n * @dev Internal function to burn a specific token\n * Reverts if the token does not exist\n * Deprecated, use _burn(uint256) instead\n * @param owner owner of the token to burn\n * @param tokenId uint256 ID of the token being burned\n */\n function _burn(address owner, uint256 tokenId) internal {\n super._burn(owner, tokenId);\n\n _removeTokenFromOwnerEnumeration(owner, tokenId);\n // Since tokenId will be deleted, we can clear its slot in _ownedTokensIndex to trigger a gas refund\n _ownedTokensIndex[tokenId] = 0;\n\n _removeTokenFromAllTokensEnumeration(tokenId);\n }\n\n /**\n * @dev Gets the list of token IDs of the requested owner\n * @param owner address owning the tokens\n * @return uint256[] List of token IDs owned by the requested address\n */\n function _tokensOfOwner(address owner) internal view returns (uint256[] storage) {\n return _ownedTokens[owner];\n }\n\n /**\n * @dev Private function to add a token to this extension's ownership-tracking data structures.\n * @param to address representing the new owner of the given token ID\n * @param tokenId uint256 ID of the token to be added to the tokens list of the given address\n */\n function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {\n _ownedTokensIndex[tokenId] = _ownedTokens[to].length;\n _ownedTokens[to].push(tokenId);\n }\n\n /**\n * @dev Private function to add a token to this extension's token tracking data structures.\n * @param tokenId uint256 ID of the token to be added to the tokens list\n */\n function _addTokenToAllTokensEnumeration(uint256 tokenId) private {\n _allTokensIndex[tokenId] = _allTokens.length;\n _allTokens.push(tokenId);\n }\n\n /**\n * @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that\n * while the token is not assigned a new owner, the _ownedTokensIndex mapping is _not_ updated: this allows for\n * gas optimizations e.g. when performing a transfer operation (avoiding double writes).\n * This has O(1) time complexity, but alters the order of the _ownedTokens array.\n * @param from address representing the previous owner of the given token ID\n * @param tokenId uint256 ID of the token to be removed from the tokens list of the given address\n */\n function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private {\n // To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and\n // then delete the last slot (swap and pop).\n\n uint256 lastTokenIndex = _ownedTokens[from].length.sub(1);\n uint256 tokenIndex = _ownedTokensIndex[tokenId];\n\n // When the token to delete is the last token, the swap operation is unnecessary\n if (tokenIndex != lastTokenIndex) {\n uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];\n\n _ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token\n _ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index\n }\n\n // This also deletes the contents at the last position of the array\n _ownedTokens[from].length--;\n\n // Note that _ownedTokensIndex[tokenId] hasn't been cleared: it still points to the old slot (now occcupied by\n // lasTokenId, or just over the end of the array if the token was the last one).\n }\n\n /**\n * @dev Private function to remove a token from this extension's token tracking data structures.\n * This has O(1) time complexity, but alters the order of the _allTokens array.\n * @param tokenId uint256 ID of the token to be removed from the tokens list\n */\n function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {\n // To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and\n // then delete the last slot (swap and pop).\n\n uint256 lastTokenIndex = _allTokens.length.sub(1);\n uint256 tokenIndex = _allTokensIndex[tokenId];\n\n // When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so\n // rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding\n // an 'if' statement (like in _removeTokenFromOwnerEnumeration)\n uint256 lastTokenId = _allTokens[lastTokenIndex];\n\n _allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token\n _allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index\n\n // This also deletes the contents at the last position of the array\n _allTokens.length--;\n _allTokensIndex[tokenId] = 0;\n }\n\n uint256[50] private ______gap;\n}\n\n// File: contracts/token/MockERC721/IMockERC721Metadata.sol\n\n\n\n/**\n * @title ERC-721 Non-Fungible Token Standard, optional metadata extension\n * @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md\n */\ncontract IMockERC721Metadata is Initializable, IMockERC721 {\n function name() external view returns (string memory);\n function symbol() external view returns (string memory);\n function tokenURI(uint256 tokenId) external view returns (string memory);\n}\n\n// File: contracts/token/MockERC721/MockERC721Metadata.sol\n\n\n\n\n\ncontract MockERC721Metadata is Initializable, ERC165, MockERC721, IMockERC721Metadata {\n // Token name\n string private _name;\n\n // Token symbol\n string private _symbol;\n\n // Optional mapping for token URIs\n mapping(uint256 => string) private _tokenURIs;\n\n bytes4 private constant _INTERFACE_ID_MockERC721_METADATA = 0x5b5e139f;\n /**\n * 0x5b5e139f ===\n * bytes4(keccak256('name()')) ^\n * bytes4(keccak256('symbol()')) ^\n * bytes4(keccak256('tokenURI(uint256)'))\n */\n\n /**\n * @dev Constructor function\n */\n function initialize(string memory name, string memory symbol) public initializer {\n require(MockERC721._hasBeenInitialized());\n\n _name = name;\n _symbol = symbol;\n\n // register the supported interfaces to conform to MockERC721 via ERC165\n _registerInterface(_INTERFACE_ID_MockERC721_METADATA);\n }\n\n function _hasBeenInitialized() internal view returns (bool) {\n return supportsInterface(_INTERFACE_ID_MockERC721_METADATA);\n }\n\n /**\n * @dev Gets the token name\n * @return string representing the token name\n */\n function name() external view returns (string memory) {\n return _name;\n }\n\n /**\n * @dev Gets the token symbol\n * @return string representing the token symbol\n */\n function symbol() external view returns (string memory) {\n return _symbol;\n }\n\n /**\n * @dev Returns an URI for a given token ID\n * Throws if the token ID does not exist. May return an empty string.\n * @param tokenId uint256 ID of the token to query\n */\n function tokenURI(uint256 tokenId) external view returns (string memory) {\n require(_exists(tokenId));\n return _tokenURIs[tokenId];\n }\n\n /**\n * @dev Internal function to set the token URI for a given token\n * Reverts if the token ID does not exist\n * @param tokenId uint256 ID of the token to set its URI\n * @param uri string URI to assign\n */\n function _setTokenURI(uint256 tokenId, string memory uri) internal {\n require(_exists(tokenId));\n _tokenURIs[tokenId] = uri;\n }\n\n /**\n * @dev Internal function to burn a specific token\n * Reverts if the token does not exist\n * Deprecated, use _burn(uint256) instead\n * @param owner owner of the token to burn\n * @param tokenId uint256 ID of the token being burned by the msg.sender\n */\n function _burn(address owner, uint256 tokenId) internal {\n super._burn(owner, tokenId);\n\n // Clear metadata (if any)\n if (bytes(_tokenURIs[tokenId]).length != 0) {\n delete _tokenURIs[tokenId];\n }\n }\n\n uint256[50] private ______gap;\n}\n\n// File: contracts/access/Roles.sol\n\n/**\n * @title Roles\n * @dev Library for managing addresses assigned to a Role.\n */\nlibrary Roles {\n struct Role {\n mapping (address => bool) bearer;\n }\n\n /**\n * @dev give an account access to this role\n */\n function add(Role storage role, address account) internal {\n require(account != address(0));\n require(!has(role, account));\n\n role.bearer[account] = true;\n }\n\n /**\n * @dev remove an account's access to this role\n */\n function remove(Role storage role, address account) internal {\n require(account != address(0));\n require(has(role, account));\n\n role.bearer[account] = false;\n }\n\n /**\n * @dev check if an account has this role\n * @return bool\n */\n function has(Role storage role, address account) internal view returns (bool) {\n require(account != address(0));\n return role.bearer[account];\n }\n}\n\n// File: contracts/access/roles/MinterRole.sol\n\n\n\n\ncontract MinterRole is Initializable {\n using Roles for Roles.Role;\n\n event MinterAdded(address indexed account);\n event MinterRemoved(address indexed account);\n\n Roles.Role private _minters;\n\n function initialize(address sender) public initializer {\n if (!isMinter(sender)) {\n _addMinter(sender);\n }\n }\n\n modifier onlyMinter() {\n require(isMinter(msg.sender));\n _;\n }\n\n function isMinter(address account) public view returns (bool) {\n return _minters.has(account);\n }\n\n function addMinter(address account) public onlyMinter {\n _addMinter(account);\n }\n\n function renounceMinter() public {\n _removeMinter(msg.sender);\n }\n\n function _addMinter(address account) internal {\n _minters.add(account);\n emit MinterAdded(account);\n }\n\n function _removeMinter(address account) internal {\n _minters.remove(account);\n emit MinterRemoved(account);\n }\n\n uint256[50] private ______gap;\n}\n\n// File: contracts/token/MockERC721/MockERC721MetadataMintable.sol\n\n\n\n\n\n/**\n * @title MockERC721MetadataMintable\n * @dev MockERC721 minting logic with metadata\n */\ncontract MockERC721MetadataMintable is Initializable, MockERC721, MockERC721Metadata, MinterRole {\n function initialize(address sender) public initializer {\n require(MockERC721._hasBeenInitialized());\n require(MockERC721Metadata._hasBeenInitialized());\n MinterRole.initialize(sender);\n }\n\n /**\n * @dev Function to mint tokens\n * @param to The address that will receive the minted tokens.\n * @param tokenId The token id to mint.\n * @param tokenURI The token URI of the minted token.\n * @return A boolean that indicates if the operation was successful.\n */\n function mintWithTokenURI(address to, uint256 tokenId, string memory tokenURI) public onlyMinter returns (bool) {\n _mint(to, tokenId);\n _setTokenURI(tokenId, tokenURI);\n return true;\n }\n\n uint256[50] private ______gap;\n}\n\n// File: contracts/access/roles/PauserRole.sol\n\n\n\n\ncontract PauserRole is Initializable {\n using Roles for Roles.Role;\n\n event PauserAdded(address indexed account);\n event PauserRemoved(address indexed account);\n\n Roles.Role private _pausers;\n\n function initialize(address sender) public initializer {\n if (!isPauser(sender)) {\n _addPauser(sender);\n }\n }\n\n modifier onlyPauser() {\n require(isPauser(msg.sender));\n _;\n }\n\n function isPauser(address account) public view returns (bool) {\n return _pausers.has(account);\n }\n\n function addPauser(address account) public onlyPauser {\n _addPauser(account);\n }\n\n function renouncePauser() public {\n _removePauser(msg.sender);\n }\n\n function _addPauser(address account) internal {\n _pausers.add(account);\n emit PauserAdded(account);\n }\n\n function _removePauser(address account) internal {\n _pausers.remove(account);\n emit PauserRemoved(account);\n }\n\n uint256[50] private ______gap;\n}\n\n// File: contracts/lifecycle/Pausable.sol\n\n\n\n/**\n * @title Pausable\n * @dev Base contract which allows children to implement an emergency stop mechanism.\n */\ncontract Pausable is Initializable, PauserRole {\n event Paused(address account);\n event Unpaused(address account);\n\n bool private _paused;\n\n function initialize(address sender) public initializer {\n PauserRole.initialize(sender);\n\n _paused = false;\n }\n\n /**\n * @return true if the contract is paused, false otherwise.\n */\n function paused() public view returns (bool) {\n return _paused;\n }\n\n /**\n * @dev Modifier to make a function callable only when the contract is not paused.\n */\n modifier whenNotPaused() {\n require(!_paused);\n _;\n }\n\n /**\n * @dev Modifier to make a function callable only when the contract is paused.\n */\n modifier whenPaused() {\n require(_paused);\n _;\n }\n\n /**\n * @dev called by the owner to pause, triggers stopped state\n */\n function pause() public onlyPauser whenNotPaused {\n _paused = true;\n emit Paused(msg.sender);\n }\n\n /**\n * @dev called by the owner to unpause, returns to normal state\n */\n function unpause() public onlyPauser whenPaused {\n _paused = false;\n emit Unpaused(msg.sender);\n }\n\n uint256[50] private ______gap;\n}\n\n// File: contracts/token/MockERC721/MockERC721Pausable.sol\n\n\n\n\n/**\n * @title MockERC721 Non-Fungible Pausable token\n * @dev MockERC721 modified with pausable transfers.\n **/\ncontract MockERC721Pausable is Initializable, MockERC721, Pausable {\n function initialize(address sender) public initializer {\n require(MockERC721._hasBeenInitialized());\n Pausable.initialize(sender);\n }\n\n function approve(address to, uint256 tokenId) public whenNotPaused {\n super.approve(to, tokenId);\n }\n\n function setApprovalForAll(address to, bool approved) public whenNotPaused {\n super.setApprovalForAll(to, approved);\n }\n\n function transferFrom(address from, address to, uint256 tokenId) public whenNotPaused {\n super.transferFrom(from, to, tokenId);\n }\n\n uint256[50] private ______gap;\n}\n\n// File: contracts/token/MockERC721/StandaloneMockERC721.sol\n\n\n\n\n\n\n\n\n/**\n * @title Standard MockERC721 token, with minting and pause functionality.\n *\n */\ncontract MockStandaloneERC721\n is Initializable, MockERC721, MockERC721Enumerable, MockERC721Metadata, MockERC721MetadataMintable, MockERC721Pausable\n{\n function initialize(string memory name, string memory symbol, address[] memory minters, address[] memory pausers) public initializer {\n MockERC721.initialize();\n MockERC721Enumerable.initialize();\n MockERC721Metadata.initialize(name, symbol);\n\n // Initialize the minter and pauser roles, and renounce them\n MockERC721MetadataMintable.initialize(address(this));\n _removeMinter(address(this));\n\n MockERC721Pausable.initialize(address(this));\n _removePauser(address(this));\n\n // Add the requested minters and pausers (this can be done after renouncing since\n // these are the internal calls)\n for (uint256 i = 0; i < minters.length; ++i) {\n _addMinter(minters[i]);\n }\n\n for (uint256 i = 0; i < pausers.length; ++i) {\n _addPauser(pausers[i]);\n }\n }\n}\n", "sourcePath": "contracts/mocks/MockStandaloneERC721.sol", "sourceMap": "5024:996:13:-;;132:2:-1;166:7;155:9;146:7;137:37;252:7;246:14;243:1;238:23;232:4;229:33;270:1;265:20;;;;222:63;;265:20;274:9;222:63;;298:9;295:1;288:20;328:4;319:7;311:22;352:7;343;336:24", "deployedSourceMap": "5024:996:13:-;;;;;;;;", "abi": [], "ast": { "absolutePath": "contracts/mocks/MockStandaloneERC721.sol", "exportedSymbols": { "Address": [ 2120 ], "ERC165": [ 2176 ], "IERC165": [ 1861 ], "IMockERC721": [ 1963 ], "IMockERC721Enumerable": [ 2777 ], "IMockERC721Metadata": [ 3153 ], "IMockERC721Receiver": [ 1977 ], "MinterRole": [ 3506 ], "MockERC721": [ 2751 ], "MockERC721Enumerable": [ 3131 ], "MockERC721Metadata": [ 3299 ], "MockERC721MetadataMintable": [ 3571 ], "MockERC721Pausable": [ 3867 ], "MockStandaloneERC721": [ 3979 ], "Pausable": [ 3782 ], "PauserRole": [ 3686 ], "Roles": [ 3391 ], "SafeMath": [ 2103 ] }, "id": 3980, "nodeType": "SourceUnit", "nodes": [ { "id": 1852, "literals": [ "solidity", "^", "0.5", ".0" ], "nodeType": "PragmaDirective", "src": "0:23:13" }, { "absolutePath": "contracts/Initializable.sol", "file": "../Initializable.sol", "id": 1853, "nodeType": "ImportDirective", "scope": 3980, "sourceUnit": 69, "src": "25:30:13", "symbolAliases": [], "unitAlias": "" }, { "baseContracts": [], "contractDependencies": [], "contractKind": "interface", "documentation": "@title IERC165\n@dev https://github.com/ethereum/EIPs/blob/master/EIPS/eip-165.md", "fullyImplemented": false, "id": 1861, "linearizedBaseContracts": [ 1861 ], "name": "IERC165", "nodeType": "ContractDefinition", "nodes": [ { "body": null, "documentation": "@notice Query if a contract implements an interface\n@param interfaceId The interface identifier, as specified in ERC-165\n@dev Interface identification is specified in ERC-165. This function\nuses less than 30,000 gas.", "id": 1860, "implemented": false, "kind": "function", "modifiers": [], "name": "supportsInterface", "nodeType": "FunctionDefinition", "parameters": { "id": 1856, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 1855, "name": "interfaceId", "nodeType": "VariableDeclaration", "scope": 1860, "src": "510:18:13", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_bytes4", "typeString": "bytes4" }, "typeName": { "id": 1854, "name": "bytes4", "nodeType": "ElementaryTypeName", "src": "510:6:13", "typeDescriptions": { "typeIdentifier": "t_bytes4", "typeString": "bytes4" } }, "value": null, "visibility": "internal" } ], "src": "509:20:13" }, "returnParameters": { "id": 1859, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 1858, "name": "", "nodeType": "VariableDeclaration", "scope": 1860, "src": "553:4:13", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" }, "typeName": { "id": 1857, "name": "bool", "nodeType": "ElementaryTypeName", "src": "553:4:13", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "value": null, "visibility": "internal" } ], "src": "552:6:13" }, "scope": 1861, "src": "483:76:13", "stateMutability": "view", "superFunction": null, "visibility": "external" } ], "scope": 3980, "src": "198:363:13" }, { "baseContracts": [ { "arguments": null, "baseName": { "contractScope": null, "id": 1862, "name": "Initializable", "nodeType": "UserDefinedTypeName", "referencedDeclaration": 68, "src": "788:13:13", "typeDescriptions": { "typeIdentifier": "t_contract$_Initializable_$68", "typeString": "contract Initializable" } }, "id": 1863, "nodeType": "InheritanceSpecifier", "src": "788:13:13" }, { "arguments": null, "baseName": { "contractScope": null, "id": 1864, "name": "IERC165", "nodeType": "UserDefinedTypeName", "referencedDeclaration": 1861, "src": "803:7:13", "typeDescriptions": { "typeIdentifier": "t_contract$_IERC165_$1861", "typeString": "contract IERC165" } }, "id": 1865, "nodeType": "InheritanceSpecifier", "src": "803:7:13" } ], "contractDependencies": [ 68, 1861 ], "contractKind": "contract", "documentation": "@title MockERC721 Non-Fungible Token Standard basic interface\n@dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md", "fullyImplemented": false, "id": 1963, "linearizedBaseContracts": [ 1963, 1861, 68 ], "name": "IMockERC721", "nodeType": "ContractDefinition", "nodes": [ { "anonymous": false, "documentation": null, "id": 1873, "name": "Transfer", "nodeType": "EventDefinition", "parameters": { "id": 1872, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 1867, "indexed": true, "name": "from", "nodeType": "VariableDeclaration", "scope": 1873, "src": "832:20:13", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" }, "typeName": { "id": 1866, "name": "address", "nodeType": "ElementaryTypeName", "src": "832:7:13", "stateMutability": "nonpayable", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "value": null, "visibility": "internal" }, { "constant": false, "id": 1869, "indexed": true, "name": "to", "nodeType": "VariableDeclaration", "scope": 1873, "src": "854:18:13", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" }, "typeName": { "id": 1868, "name": "address", "nodeType": "ElementaryTypeName", "src": "854:7:13", "stateMutability": "nonpayable", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "value": null, "visibility": "internal" }, { "constant": false, "id": 1871, "indexed": true, "name": "tokenId", "nodeType": "VariableDeclaration", "scope": 1873, "src": "874:23:13", "stateVariable": false,