ETH Price: $2,515.95 (-0.37%)

Transaction Decoder

Block:
20346915 at Jul-20-2024 09:42:23 AM +UTC
Transaction Fee:
0.0006828661200556 ETH $1.72
Gas Used:
196,820 Gas / 3.46949558 Gwei

Emitted Events:

146 ERC721DeterministicCollection.Transfer( from=[Sender] 0xd518542ec76a24f886538831757b199c07cfcf7f, to=0x9a72C1E2...690BEd42B, tokenId=77720471251395203783063504430548779051344580405605244105681501423293 )
147 ERC721DeterministicCollection.Transfer( from=[Sender] 0xd518542ec76a24f886538831757b199c07cfcf7f, to=0x9a72C1E2...690BEd42B, tokenId=77720471251395203783063504430548779051344580405605244105681501425884 )
148 ERC721DeterministicCollection.Transfer( from=[Sender] 0xd518542ec76a24f886538831757b199c07cfcf7f, to=0x9a72C1E2...690BEd42B, tokenId=77720471251395203783063504430548779051344580405605244105681501422913 )
149 ERC1967Proxy.0xe84937306948525e68609d1c69a800e44f01d5a3b0597a6383fcdef31b1937dd( 0xe84937306948525e68609d1c69a800e44f01d5a3b0597a6383fcdef31b1937dd, 0000000000000000000000000000000000000000000000000000000000000040, 00000000000000000000000000000000000000000000000000000000000001e0, 0000000000000000000000000000000000000000000000000000000000000003, 0000000000000000000000000000000000000000000000000000000000000000, 000000000000000000000000d5b0f341cb6db2a8022e1e1c13dc4404870a510c, 00000002e20000000000000000000000000000000000000000000000000006bd, 0000000000000000000000000000000000000000000000000000000000000001, 0000000000000000000000000000000000000000000000000000000000000000, 000000000000000000000000d5b0f341cb6db2a8022e1e1c13dc4404870a510c, 00000002e20000000000000000000000000000000000000000000000000010dc, 0000000000000000000000000000000000000000000000000000000000000001, 0000000000000000000000000000000000000000000000000000000000000000, 000000000000000000000000d5b0f341cb6db2a8022e1e1c13dc4404870a510c, 00000002e2000000000000000000000000000000000000000000000000000541, 0000000000000000000000000000000000000000000000000000000000000001, 0000000000000000000000000000000000000000000000000000000000000003, 0000000000000000000000000000000000000000000000000000000000000001, 0000000000000000000000000000000000000000000000000000000000000001, 0000000000000000000000000000000000000000000000000000000000000001 )

Account State Difference:

  Address   Before After State Difference Code
(beaverbuild)
6.830163208757589918 Eth6.830298461493389918 Eth0.0001352527358
0xd518542E...C07cFcf7f
0.140891961668287082 Eth
Nonce: 352
0.140209095548231482 Eth
Nonce: 353
0.0006828661200556
0xD5b0F341...4870a510c

Execution Trace

ERC1967Proxy.30d475ba( )
  • 0x70377582891baa34f3ce6cdd0486d3b41df7cb63.30d475ba( )
    • ERC721DeterministicCollection.transferFrom( from=0xd518542Ec76a24f886538831757B199C07cFcf7f, to=0x9a72C1E2636D38C15583D3C44d9a162690BEd42B, tokenId=77720471251395203783063504430548779051344580405605244105681501423293 )
    • ERC721DeterministicCollection.transferFrom( from=0xd518542Ec76a24f886538831757B199C07cFcf7f, to=0x9a72C1E2636D38C15583D3C44d9a162690BEd42B, tokenId=77720471251395203783063504430548779051344580405605244105681501425884 )
    • ERC721DeterministicCollection.transferFrom( from=0xd518542Ec76a24f886538831757B199C07cFcf7f, to=0x9a72C1E2636D38C15583D3C44d9a162690BEd42B, tokenId=77720471251395203783063504430548779051344580405605244105681501422913 )
      File 1 of 2: ERC1967Proxy
      // SPDX-License-Identifier: MIT
      pragma solidity ^0.8.0;
      import "@openzeppelin/contracts/proxy/beacon/BeaconProxy.sol";
      import "@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol";
      import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
      import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
      import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
      // Kept for backwards compatibility with older versions of Hardhat and Truffle plugins.
      contract AdminUpgradeabilityProxy is TransparentUpgradeableProxy {
          constructor(address logic, address admin, bytes memory data) payable TransparentUpgradeableProxy(logic, admin, data) {}
      }
      // SPDX-License-Identifier: MIT
      pragma solidity ^0.8.0;
      import "./IBeacon.sol";
      import "../Proxy.sol";
      import "../ERC1967/ERC1967Upgrade.sol";
      /**
       * @dev This contract implements a proxy that gets the implementation address for each call from a {UpgradeableBeacon}.
       *
       * The beacon address is stored in storage slot `uint256(keccak256('eip1967.proxy.beacon')) - 1`, so that it doesn't
       * conflict with the storage layout of the implementation behind the proxy.
       *
       * _Available since v3.4._
       */
      contract BeaconProxy is Proxy, ERC1967Upgrade {
          /**
           * @dev Initializes the proxy with `beacon`.
           *
           * If `data` is nonempty, it's used as data in a delegate call to the implementation returned by the beacon. This
           * will typically be an encoded function call, and allows initializating the storage of the proxy like a Solidity
           * constructor.
           *
           * Requirements:
           *
           * - `beacon` must be a contract with the interface {IBeacon}.
           */
          constructor(address beacon, bytes memory data) payable {
              assert(_BEACON_SLOT == bytes32(uint256(keccak256("eip1967.proxy.beacon")) - 1));
              _upgradeBeaconToAndCall(beacon, data, false);
          }
          /**
           * @dev Returns the current beacon address.
           */
          function _beacon() internal view virtual returns (address) {
              return _getBeacon();
          }
          /**
           * @dev Returns the current implementation address of the associated beacon.
           */
          function _implementation() internal view virtual override returns (address) {
              return IBeacon(_getBeacon()).implementation();
          }
          /**
           * @dev Changes the proxy to use a new beacon. Deprecated: see {_upgradeBeaconToAndCall}.
           *
           * If `data` is nonempty, it's used as data in a delegate call to the implementation returned by the beacon.
           *
           * Requirements:
           *
           * - `beacon` must be a contract.
           * - The implementation returned by `beacon` must be a contract.
           */
          function _setBeacon(address beacon, bytes memory data) internal virtual {
              _upgradeBeaconToAndCall(beacon, data, false);
          }
      }
      // SPDX-License-Identifier: MIT
      pragma solidity ^0.8.0;
      import "./IBeacon.sol";
      import "../../access/Ownable.sol";
      import "../../utils/Address.sol";
      /**
       * @dev This contract is used in conjunction with one or more instances of {BeaconProxy} to determine their
       * implementation contract, which is where they will delegate all function calls.
       *
       * An owner is able to change the implementation the beacon points to, thus upgrading the proxies that use this beacon.
       */
      contract UpgradeableBeacon is IBeacon, Ownable {
          address private _implementation;
          /**
           * @dev Emitted when the implementation returned by the beacon is changed.
           */
          event Upgraded(address indexed implementation);
          /**
           * @dev Sets the address of the initial implementation, and the deployer account as the owner who can upgrade the
           * beacon.
           */
          constructor(address implementation_) {
              _setImplementation(implementation_);
          }
          /**
           * @dev Returns the current implementation address.
           */
          function implementation() public view virtual override returns (address) {
              return _implementation;
          }
          /**
           * @dev Upgrades the beacon to a new implementation.
           *
           * Emits an {Upgraded} event.
           *
           * Requirements:
           *
           * - msg.sender must be the owner of the contract.
           * - `newImplementation` must be a contract.
           */
          function upgradeTo(address newImplementation) public virtual onlyOwner {
              _setImplementation(newImplementation);
              emit Upgraded(newImplementation);
          }
          /**
           * @dev Sets the implementation contract address for this beacon
           *
           * Requirements:
           *
           * - `newImplementation` must be a contract.
           */
          function _setImplementation(address newImplementation) private {
              require(Address.isContract(newImplementation), "UpgradeableBeacon: implementation is not a contract");
              _implementation = newImplementation;
          }
      }
      // SPDX-License-Identifier: MIT
      pragma solidity ^0.8.0;
      import "../Proxy.sol";
      import "./ERC1967Upgrade.sol";
      /**
       * @dev This contract implements an upgradeable proxy. It is upgradeable because calls are delegated to an
       * implementation address that can be changed. This address is stored in storage in the location specified by
       * https://eips.ethereum.org/EIPS/eip-1967[EIP1967], so that it doesn't conflict with the storage layout of the
       * implementation behind the proxy.
       */
      contract ERC1967Proxy is Proxy, ERC1967Upgrade {
          /**
           * @dev Initializes the upgradeable proxy with an initial implementation specified by `_logic`.
           *
           * If `_data` is nonempty, it's used as data in a delegate call to `_logic`. This will typically be an encoded
           * function call, and allows initializating the storage of the proxy like a Solidity constructor.
           */
          constructor(address _logic, bytes memory _data) payable {
              assert(_IMPLEMENTATION_SLOT == bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1));
              _upgradeToAndCall(_logic, _data, false);
          }
          /**
           * @dev Returns the current implementation address.
           */
          function _implementation() internal view virtual override returns (address impl) {
              return ERC1967Upgrade._getImplementation();
          }
      }
      // SPDX-License-Identifier: MIT
      pragma solidity ^0.8.0;
      import "../ERC1967/ERC1967Proxy.sol";
      /**
       * @dev This contract implements a proxy that is upgradeable by an admin.
       *
       * To avoid https://medium.com/nomic-labs-blog/malicious-backdoors-in-ethereum-proxies-62629adf3357[proxy selector
       * clashing], which can potentially be used in an attack, this contract uses the
       * https://blog.openzeppelin.com/the-transparent-proxy-pattern/[transparent proxy pattern]. This pattern implies two
       * things that go hand in hand:
       *
       * 1. If any account other than the admin calls the proxy, the call will be forwarded to the implementation, even if
       * that call matches one of the admin functions exposed by the proxy itself.
       * 2. If the admin calls the proxy, it can access the admin functions, but its calls will never be forwarded to the
       * implementation. If the admin tries to call a function on the implementation it will fail with an error that says
       * "admin cannot fallback to proxy target".
       *
       * These properties mean that the admin account can only be used for admin actions like upgrading the proxy or changing
       * the admin, so it's best if it's a dedicated account that is not used for anything else. This will avoid headaches due
       * to sudden errors when trying to call a function from the proxy implementation.
       *
       * Our recommendation is for the dedicated account to be an instance of the {ProxyAdmin} contract. If set up this way,
       * you should think of the `ProxyAdmin` instance as the real administrative interface of your proxy.
       */
      contract TransparentUpgradeableProxy is ERC1967Proxy {
          /**
           * @dev Initializes an upgradeable proxy managed by `_admin`, backed by the implementation at `_logic`, and
           * optionally initialized with `_data` as explained in {ERC1967Proxy-constructor}.
           */
          constructor(address _logic, address admin_, bytes memory _data) payable ERC1967Proxy(_logic, _data) {
              assert(_ADMIN_SLOT == bytes32(uint256(keccak256("eip1967.proxy.admin")) - 1));
              _changeAdmin(admin_);
          }
          /**
           * @dev Modifier used internally that will delegate the call to the implementation unless the sender is the admin.
           */
          modifier ifAdmin() {
              if (msg.sender == _getAdmin()) {
                  _;
              } else {
                  _fallback();
              }
          }
          /**
           * @dev Returns the current admin.
           *
           * NOTE: Only the admin can call this function. See {ProxyAdmin-getProxyAdmin}.
           *
           * TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using the
           * https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
           * `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103`
           */
          function admin() external ifAdmin returns (address admin_) {
              admin_ = _getAdmin();
          }
          /**
           * @dev Returns the current implementation.
           *
           * NOTE: Only the admin can call this function. See {ProxyAdmin-getProxyImplementation}.
           *
           * TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using the
           * https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
           * `0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc`
           */
          function implementation() external ifAdmin returns (address implementation_) {
              implementation_ = _implementation();
          }
          /**
           * @dev Changes the admin of the proxy.
           *
           * Emits an {AdminChanged} event.
           *
           * NOTE: Only the admin can call this function. See {ProxyAdmin-changeProxyAdmin}.
           */
          function changeAdmin(address newAdmin) external virtual ifAdmin {
              _changeAdmin(newAdmin);
          }
          /**
           * @dev Upgrade the implementation of the proxy.
           *
           * NOTE: Only the admin can call this function. See {ProxyAdmin-upgrade}.
           */
          function upgradeTo(address newImplementation) external ifAdmin {
              _upgradeToAndCall(newImplementation, bytes(""), false);
          }
          /**
           * @dev Upgrade the implementation of the proxy, and then call a function from the new implementation as specified
           * by `data`, which should be an encoded function call. This is useful to initialize new storage variables in the
           * proxied contract.
           *
           * NOTE: Only the admin can call this function. See {ProxyAdmin-upgradeAndCall}.
           */
          function upgradeToAndCall(address newImplementation, bytes calldata data) external payable ifAdmin {
              _upgradeToAndCall(newImplementation, data, true);
          }
          /**
           * @dev Returns the current admin.
           */
          function _admin() internal view virtual returns (address) {
              return _getAdmin();
          }
          /**
           * @dev Makes sure the admin cannot access the fallback function. See {Proxy-_beforeFallback}.
           */
          function _beforeFallback() internal virtual override {
              require(msg.sender != _getAdmin(), "TransparentUpgradeableProxy: admin cannot fallback to proxy target");
              super._beforeFallback();
          }
      }
      // SPDX-License-Identifier: MIT
      pragma solidity ^0.8.0;
      import "./TransparentUpgradeableProxy.sol";
      import "../../access/Ownable.sol";
      /**
       * @dev This is an auxiliary contract meant to be assigned as the admin of a {TransparentUpgradeableProxy}. For an
       * explanation of why you would want to use this see the documentation for {TransparentUpgradeableProxy}.
       */
      contract ProxyAdmin is Ownable {
          /**
           * @dev Returns the current implementation of `proxy`.
           *
           * Requirements:
           *
           * - This contract must be the admin of `proxy`.
           */
          function getProxyImplementation(TransparentUpgradeableProxy proxy) public view virtual returns (address) {
              // We need to manually run the static call since the getter cannot be flagged as view
              // bytes4(keccak256("implementation()")) == 0x5c60da1b
              (bool success, bytes memory returndata) = address(proxy).staticcall(hex"5c60da1b");
              require(success);
              return abi.decode(returndata, (address));
          }
          /**
           * @dev Returns the current admin of `proxy`.
           *
           * Requirements:
           *
           * - This contract must be the admin of `proxy`.
           */
          function getProxyAdmin(TransparentUpgradeableProxy proxy) public view virtual returns (address) {
              // We need to manually run the static call since the getter cannot be flagged as view
              // bytes4(keccak256("admin()")) == 0xf851a440
              (bool success, bytes memory returndata) = address(proxy).staticcall(hex"f851a440");
              require(success);
              return abi.decode(returndata, (address));
          }
          /**
           * @dev Changes the admin of `proxy` to `newAdmin`.
           *
           * Requirements:
           *
           * - This contract must be the current admin of `proxy`.
           */
          function changeProxyAdmin(TransparentUpgradeableProxy proxy, address newAdmin) public virtual onlyOwner {
              proxy.changeAdmin(newAdmin);
          }
          /**
           * @dev Upgrades `proxy` to `implementation`. See {TransparentUpgradeableProxy-upgradeTo}.
           *
           * Requirements:
           *
           * - This contract must be the admin of `proxy`.
           */
          function upgrade(TransparentUpgradeableProxy proxy, address implementation) public virtual onlyOwner {
              proxy.upgradeTo(implementation);
          }
          /**
           * @dev Upgrades `proxy` to `implementation` and calls a function on the new implementation. See
           * {TransparentUpgradeableProxy-upgradeToAndCall}.
           *
           * Requirements:
           *
           * - This contract must be the admin of `proxy`.
           */
          function upgradeAndCall(TransparentUpgradeableProxy proxy, address implementation, bytes memory data) public payable virtual onlyOwner {
              proxy.upgradeToAndCall{value: msg.value}(implementation, data);
          }
      }
      // SPDX-License-Identifier: MIT
      pragma solidity ^0.8.0;
      /**
       * @dev This is the interface that {BeaconProxy} expects of its beacon.
       */
      interface IBeacon {
          /**
           * @dev Must return an address that can be used as a delegate call target.
           *
           * {BeaconProxy} will check that this address is a contract.
           */
          function implementation() external view returns (address);
      }
      // SPDX-License-Identifier: MIT
      pragma solidity ^0.8.0;
      /**
       * @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM
       * instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to
       * be specified by overriding the virtual {_implementation} function.
       *
       * Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a
       * different contract through the {_delegate} function.
       *
       * The success and return data of the delegated call will be returned back to the caller of the proxy.
       */
      abstract contract Proxy {
          /**
           * @dev Delegates the current call to `implementation`.
           *
           * This function does not return to its internall call site, it will return directly to the external caller.
           */
          function _delegate(address implementation) internal virtual {
              // solhint-disable-next-line no-inline-assembly
              assembly {
                  // Copy msg.data. We take full control of memory in this inline assembly
                  // block because it will not return to Solidity code. We overwrite the
                  // Solidity scratch pad at memory position 0.
                  calldatacopy(0, 0, calldatasize())
                  // Call the implementation.
                  // out and outsize are 0 because we don't know the size yet.
                  let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)
                  // Copy the returned data.
                  returndatacopy(0, 0, returndatasize())
                  switch result
                  // delegatecall returns 0 on error.
                  case 0 { revert(0, returndatasize()) }
                  default { return(0, returndatasize()) }
              }
          }
          /**
           * @dev This is a virtual function that should be overriden so it returns the address to which the fallback function
           * and {_fallback} should delegate.
           */
          function _implementation() internal view virtual returns (address);
          /**
           * @dev Delegates the current call to the address returned by `_implementation()`.
           *
           * This function does not return to its internall call site, it will return directly to the external caller.
           */
          function _fallback() internal virtual {
              _beforeFallback();
              _delegate(_implementation());
          }
          /**
           * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other
           * function in the contract matches the call data.
           */
          fallback () external payable virtual {
              _fallback();
          }
          /**
           * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data
           * is empty.
           */
          receive () external payable virtual {
              _fallback();
          }
          /**
           * @dev Hook that is called before falling back to the implementation. Can happen as part of a manual `_fallback`
           * call, or as part of the Solidity `fallback` or `receive` functions.
           *
           * If overriden should call `super._beforeFallback()`.
           */
          function _beforeFallback() internal virtual {
          }
      }
      // SPDX-License-Identifier: MIT
      pragma solidity ^0.8.2;
      import "../beacon/IBeacon.sol";
      import "../../utils/Address.sol";
      import "../../utils/StorageSlot.sol";
      /**
       * @dev This abstract contract provides getters and event emitting update functions for
       * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.
       *
       * _Available since v4.1._
       *
       * @custom:oz-upgrades-unsafe-allow delegatecall
       */
      abstract contract ERC1967Upgrade {
          // This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1
          bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143;
          /**
           * @dev Storage slot with the address of the current implementation.
           * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is
           * validated in the constructor.
           */
          bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
          /**
           * @dev Emitted when the implementation is upgraded.
           */
          event Upgraded(address indexed implementation);
          /**
           * @dev Returns the current implementation address.
           */
          function _getImplementation() internal view returns (address) {
              return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
          }
          /**
           * @dev Stores a new address in the EIP1967 implementation slot.
           */
          function _setImplementation(address newImplementation) private {
              require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
              StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
          }
          /**
           * @dev Perform implementation upgrade
           *
           * Emits an {Upgraded} event.
           */
          function _upgradeTo(address newImplementation) internal {
              _setImplementation(newImplementation);
              emit Upgraded(newImplementation);
          }
          /**
           * @dev Perform implementation upgrade with additional setup call.
           *
           * Emits an {Upgraded} event.
           */
          function _upgradeToAndCall(address newImplementation, bytes memory data, bool forceCall) internal {
              _setImplementation(newImplementation);
              emit Upgraded(newImplementation);
              if (data.length > 0 || forceCall) {
                  Address.functionDelegateCall(newImplementation, data);
              }
          }
          /**
           * @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call.
           *
           * Emits an {Upgraded} event.
           */
          function _upgradeToAndCallSecure(address newImplementation, bytes memory data, bool forceCall) internal {
              address oldImplementation = _getImplementation();
              // Initial upgrade and setup call
              _setImplementation(newImplementation);
              if (data.length > 0 || forceCall) {
                  Address.functionDelegateCall(newImplementation, data);
              }
              // Perform rollback test if not already in progress
              StorageSlot.BooleanSlot storage rollbackTesting = StorageSlot.getBooleanSlot(_ROLLBACK_SLOT);
              if (!rollbackTesting.value) {
                  // Trigger rollback using upgradeTo from the new implementation
                  rollbackTesting.value = true;
                  Address.functionDelegateCall(
                      newImplementation,
                      abi.encodeWithSignature(
                          "upgradeTo(address)",
                          oldImplementation
                      )
                  );
                  rollbackTesting.value = false;
                  // Check rollback was effective
                  require(oldImplementation == _getImplementation(), "ERC1967Upgrade: upgrade breaks further upgrades");
                  // Finally reset to the new implementation and log the upgrade
                  _setImplementation(newImplementation);
                  emit Upgraded(newImplementation);
              }
          }
          /**
           * @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does
           * not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that).
           *
           * Emits a {BeaconUpgraded} event.
           */
          function _upgradeBeaconToAndCall(address newBeacon, bytes memory data, bool forceCall) internal {
              _setBeacon(newBeacon);
              emit BeaconUpgraded(newBeacon);
              if (data.length > 0 || forceCall) {
                  Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);
              }
          }
          /**
           * @dev Storage slot with the admin of the contract.
           * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is
           * validated in the constructor.
           */
          bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
          /**
           * @dev Emitted when the admin account has changed.
           */
          event AdminChanged(address previousAdmin, address newAdmin);
          /**
           * @dev Returns the current admin.
           */
          function _getAdmin() internal view returns (address) {
              return StorageSlot.getAddressSlot(_ADMIN_SLOT).value;
          }
          /**
           * @dev Stores a new address in the EIP1967 admin slot.
           */
          function _setAdmin(address newAdmin) private {
              require(newAdmin != address(0), "ERC1967: new admin is the zero address");
              StorageSlot.getAddressSlot(_ADMIN_SLOT).value = newAdmin;
          }
          /**
           * @dev Changes the admin of the proxy.
           *
           * Emits an {AdminChanged} event.
           */
          function _changeAdmin(address newAdmin) internal {
              emit AdminChanged(_getAdmin(), newAdmin);
              _setAdmin(newAdmin);
          }
          /**
           * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
           * This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor.
           */
          bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;
          /**
           * @dev Emitted when the beacon is upgraded.
           */
          event BeaconUpgraded(address indexed beacon);
          /**
           * @dev Returns the current beacon.
           */
          function _getBeacon() internal view returns (address) {
              return StorageSlot.getAddressSlot(_BEACON_SLOT).value;
          }
          /**
           * @dev Stores a new beacon in the EIP1967 beacon slot.
           */
          function _setBeacon(address newBeacon) private {
              require(
                  Address.isContract(newBeacon),
                  "ERC1967: new beacon is not a contract"
              );
              require(
                  Address.isContract(IBeacon(newBeacon).implementation()),
                  "ERC1967: beacon implementation is not a contract"
              );
              StorageSlot.getAddressSlot(_BEACON_SLOT).value = newBeacon;
          }
      }
      // SPDX-License-Identifier: MIT
      pragma solidity ^0.8.0;
      /**
       * @dev Collection of functions related to the address type
       */
      library Address {
          /**
           * @dev Returns true if `account` is a contract.
           *
           * [IMPORTANT]
           * ====
           * It is unsafe to assume that an address for which this function returns
           * false is an externally-owned account (EOA) and not a contract.
           *
           * Among others, `isContract` will return false for the following
           * types of addresses:
           *
           *  - an externally-owned account
           *  - a contract in construction
           *  - an address where a contract will be created
           *  - an address where a contract lived, but was destroyed
           * ====
           */
          function isContract(address account) internal view returns (bool) {
              // This method relies on extcodesize, which returns 0 for contracts in
              // construction, since the code is only stored at the end of the
              // constructor execution.
              uint256 size;
              // solhint-disable-next-line no-inline-assembly
              assembly { size := extcodesize(account) }
              return size > 0;
          }
          /**
           * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
           * `recipient`, forwarding all available gas and reverting on errors.
           *
           * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
           * of certain opcodes, possibly making contracts go over the 2300 gas limit
           * imposed by `transfer`, making them unable to receive funds via
           * `transfer`. {sendValue} removes this limitation.
           *
           * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
           *
           * IMPORTANT: because control is transferred to `recipient`, care must be
           * taken to not create reentrancy vulnerabilities. Consider using
           * {ReentrancyGuard} or the
           * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
           */
          function sendValue(address payable recipient, uint256 amount) internal {
              require(address(this).balance >= amount, "Address: insufficient balance");
              // solhint-disable-next-line avoid-low-level-calls, avoid-call-value
              (bool success, ) = recipient.call{ value: amount }("");
              require(success, "Address: unable to send value, recipient may have reverted");
          }
          /**
           * @dev Performs a Solidity function call using a low level `call`. A
           * plain`call` is an unsafe replacement for a function call: use this
           * function instead.
           *
           * If `target` reverts with a revert reason, it is bubbled up by this
           * function (like regular Solidity function calls).
           *
           * Returns the raw returned data. To convert to the expected return value,
           * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
           *
           * Requirements:
           *
           * - `target` must be a contract.
           * - calling `target` with `data` must not revert.
           *
           * _Available since v3.1._
           */
          function functionCall(address target, bytes memory data) internal returns (bytes memory) {
            return functionCall(target, data, "Address: low-level call failed");
          }
          /**
           * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
           * `errorMessage` as a fallback revert reason when `target` reverts.
           *
           * _Available since v3.1._
           */
          function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
              return functionCallWithValue(target, data, 0, errorMessage);
          }
          /**
           * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
           * but also transferring `value` wei to `target`.
           *
           * Requirements:
           *
           * - the calling contract must have an ETH balance of at least `value`.
           * - the called Solidity function must be `payable`.
           *
           * _Available since v3.1._
           */
          function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
              return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
          }
          /**
           * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
           * with `errorMessage` as a fallback revert reason when `target` reverts.
           *
           * _Available since v3.1._
           */
          function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
              require(address(this).balance >= value, "Address: insufficient balance for call");
              require(isContract(target), "Address: call to non-contract");
              // solhint-disable-next-line avoid-low-level-calls
              (bool success, bytes memory returndata) = target.call{ value: value }(data);
              return _verifyCallResult(success, returndata, errorMessage);
          }
          /**
           * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
           * but performing a static call.
           *
           * _Available since v3.3._
           */
          function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
              return functionStaticCall(target, data, "Address: low-level static call failed");
          }
          /**
           * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
           * but performing a static call.
           *
           * _Available since v3.3._
           */
          function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
              require(isContract(target), "Address: static call to non-contract");
              // solhint-disable-next-line avoid-low-level-calls
              (bool success, bytes memory returndata) = target.staticcall(data);
              return _verifyCallResult(success, returndata, errorMessage);
          }
          /**
           * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
           * but performing a delegate call.
           *
           * _Available since v3.4._
           */
          function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
              return functionDelegateCall(target, data, "Address: low-level delegate call failed");
          }
          /**
           * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
           * but performing a delegate call.
           *
           * _Available since v3.4._
           */
          function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
              require(isContract(target), "Address: delegate call to non-contract");
              // solhint-disable-next-line avoid-low-level-calls
              (bool success, bytes memory returndata) = target.delegatecall(data);
              return _verifyCallResult(success, returndata, errorMessage);
          }
          function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
              if (success) {
                  return returndata;
              } else {
                  // Look for revert reason and bubble it up if present
                  if (returndata.length > 0) {
                      // The easiest way to bubble the revert reason is using memory via assembly
                      // solhint-disable-next-line no-inline-assembly
                      assembly {
                          let returndata_size := mload(returndata)
                          revert(add(32, returndata), returndata_size)
                      }
                  } else {
                      revert(errorMessage);
                  }
              }
          }
      }
      // SPDX-License-Identifier: MIT
      pragma solidity ^0.8.0;
      /**
       * @dev Library for reading and writing primitive types to specific storage slots.
       *
       * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
       * This library helps with reading and writing to such slots without the need for inline assembly.
       *
       * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
       *
       * Example usage to set ERC1967 implementation slot:
       * ```
       * contract ERC1967 {
       *     bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
       *
       *     function _getImplementation() internal view returns (address) {
       *         return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
       *     }
       *
       *     function _setImplementation(address newImplementation) internal {
       *         require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
       *         StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
       *     }
       * }
       * ```
       *
       * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._
       */
      library StorageSlot {
          struct AddressSlot {
              address value;
          }
          struct BooleanSlot {
              bool value;
          }
          struct Bytes32Slot {
              bytes32 value;
          }
          struct Uint256Slot {
              uint256 value;
          }
          /**
           * @dev Returns an `AddressSlot` with member `value` located at `slot`.
           */
          function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
              assembly {
                  r.slot := slot
              }
          }
          /**
           * @dev Returns an `BooleanSlot` with member `value` located at `slot`.
           */
          function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
              assembly {
                  r.slot := slot
              }
          }
          /**
           * @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
           */
          function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
              assembly {
                  r.slot := slot
              }
          }
          /**
           * @dev Returns an `Uint256Slot` with member `value` located at `slot`.
           */
          function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
              assembly {
                  r.slot := slot
              }
          }
      }
      // SPDX-License-Identifier: MIT
      pragma solidity ^0.8.0;
      import "../utils/Context.sol";
      /**
       * @dev Contract module which provides a basic access control mechanism, where
       * there is an account (an owner) that can be granted exclusive access to
       * specific functions.
       *
       * By default, the owner account will be the one that deploys the contract. This
       * can later be changed with {transferOwnership}.
       *
       * This module is used through inheritance. It will make available the modifier
       * `onlyOwner`, which can be applied to your functions to restrict their use to
       * the owner.
       */
      abstract contract Ownable is Context {
          address private _owner;
          event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
          /**
           * @dev Initializes the contract setting the deployer as the initial owner.
           */
          constructor () {
              address msgSender = _msgSender();
              _owner = msgSender;
              emit OwnershipTransferred(address(0), msgSender);
          }
          /**
           * @dev Returns the address of the current owner.
           */
          function owner() public view virtual returns (address) {
              return _owner;
          }
          /**
           * @dev Throws if called by any account other than the owner.
           */
          modifier onlyOwner() {
              require(owner() == _msgSender(), "Ownable: caller is not the owner");
              _;
          }
          /**
           * @dev Leaves the contract without owner. It will not be possible to call
           * `onlyOwner` functions anymore. Can only be called by the current owner.
           *
           * NOTE: Renouncing ownership will leave the contract without an owner,
           * thereby removing any functionality that is only available to the owner.
           */
          function renounceOwnership() public virtual onlyOwner {
              emit OwnershipTransferred(_owner, address(0));
              _owner = address(0);
          }
          /**
           * @dev Transfers ownership of the contract to a new account (`newOwner`).
           * Can only be called by the current owner.
           */
          function transferOwnership(address newOwner) public virtual onlyOwner {
              require(newOwner != address(0), "Ownable: new owner is the zero address");
              emit OwnershipTransferred(_owner, newOwner);
              _owner = newOwner;
          }
      }
      // SPDX-License-Identifier: MIT
      pragma solidity ^0.8.0;
      /*
       * @dev Provides information about the current execution context, including the
       * sender of the transaction and its data. While these are generally available
       * via msg.sender and msg.data, they should not be accessed in such a direct
       * manner, since when dealing with meta-transactions the account sending and
       * paying for execution may not be the actual sender (as far as an application
       * is concerned).
       *
       * This contract is only required for intermediate, library-like contracts.
       */
      abstract contract Context {
          function _msgSender() internal view virtual returns (address) {
              return msg.sender;
          }
          function _msgData() internal view virtual returns (bytes calldata) {
              this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
              return msg.data;
          }
      }
      

      File 2 of 2: ERC721DeterministicCollection
      // File: @openzeppelin/contracts/ownership/Ownable.sol
      
      pragma solidity ^0.5.0;
      
      /**
       * @dev Contract module which provides a basic access control mechanism, where
       * there is an account (an owner) that can be granted exclusive access to
       * specific functions.
       *
       * This module is used through inheritance. It will make available the modifier
       * `onlyOwner`, which can be aplied to your functions to restrict their use to
       * the owner.
       */
      contract Ownable {
          address private _owner;
      
          event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
      
          /**
           * @dev Initializes the contract setting the deployer as the initial owner.
           */
          constructor () internal {
              _owner = msg.sender;
              emit OwnershipTransferred(address(0), _owner);
          }
      
          /**
           * @dev Returns the address of the current owner.
           */
          function owner() public view returns (address) {
              return _owner;
          }
      
          /**
           * @dev Throws if called by any account other than the owner.
           */
          modifier onlyOwner() {
              require(isOwner(), "Ownable: caller is not the owner");
              _;
          }
      
          /**
           * @dev Returns true if the caller is the current owner.
           */
          function isOwner() public view returns (bool) {
              return msg.sender == _owner;
          }
      
          /**
           * @dev Leaves the contract without owner. It will not be possible to call
           * `onlyOwner` functions anymore. Can only be called by the current owner.
           *
           * > Note: Renouncing ownership will leave the contract without an owner,
           * thereby removing any functionality that is only available to the owner.
           */
          function renounceOwnership() public onlyOwner {
              emit OwnershipTransferred(_owner, address(0));
              _owner = address(0);
          }
      
          /**
           * @dev Transfers ownership of the contract to a new account (`newOwner`).
           * Can only be called by the current owner.
           */
          function transferOwnership(address newOwner) public onlyOwner {
              _transferOwnership(newOwner);
          }
      
          /**
           * @dev Transfers ownership of the contract to a new account (`newOwner`).
           */
          function _transferOwnership(address newOwner) internal {
              require(newOwner != address(0), "Ownable: new owner is the zero address");
              emit OwnershipTransferred(_owner, newOwner);
              _owner = newOwner;
          }
      }
      
      // File: @openzeppelin/contracts/introspection/IERC165.sol
      
      pragma solidity ^0.5.0;
      
      /**
       * @dev Interface of the ERC165 standard, as defined in the
       * [EIP](https://eips.ethereum.org/EIPS/eip-165).
       *
       * Implementers can declare support of contract interfaces, which can then be
       * queried by others (`ERC165Checker`).
       *
       * For an implementation, see `ERC165`.
       */
      interface IERC165 {
          /**
           * @dev Returns true if this contract implements the interface defined by
           * `interfaceId`. See the corresponding
           * [EIP section](https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified)
           * to learn more about how these ids are created.
           *
           * This function call must use less than 30 000 gas.
           */
          function supportsInterface(bytes4 interfaceId) external view returns (bool);
      }
      
      // File: @openzeppelin/contracts/token/ERC721/IERC721.sol
      
      pragma solidity ^0.5.0;
      
      
      /**
       * @dev Required interface of an ERC721 compliant contract.
       */
      contract IERC721 is IERC165 {
          event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
          event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
          event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
      
          /**
           * @dev Returns the number of NFTs in `owner`'s account.
           */
          function balanceOf(address owner) public view returns (uint256 balance);
      
          /**
           * @dev Returns the owner of the NFT specified by `tokenId`.
           */
          function ownerOf(uint256 tokenId) public view returns (address owner);
      
          /**
           * @dev Transfers a specific NFT (`tokenId`) from one account (`from`) to
           * another (`to`).
           *
           * 
           *
           * Requirements:
           * - `from`, `to` cannot be zero.
           * - `tokenId` must be owned by `from`.
           * - If the caller is not `from`, it must be have been allowed to move this
           * NFT by either `approve` or `setApproveForAll`.
           */
          function safeTransferFrom(address from, address to, uint256 tokenId) public;
          /**
           * @dev Transfers a specific NFT (`tokenId`) from one account (`from`) to
           * another (`to`).
           *
           * Requirements:
           * - If the caller is not `from`, it must be approved to move this NFT by
           * either `approve` or `setApproveForAll`.
           */
          function transferFrom(address from, address to, uint256 tokenId) public;
          function approve(address to, uint256 tokenId) public;
          function getApproved(uint256 tokenId) public view returns (address operator);
      
          function setApprovalForAll(address operator, bool _approved) public;
          function isApprovedForAll(address owner, address operator) public view returns (bool);
      
      
          function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public;
      }
      
      // File: @openzeppelin/contracts/token/ERC721/IERC721Receiver.sol
      
      pragma solidity ^0.5.0;
      
      /**
       * @title ERC721 token receiver interface
       * @dev Interface for any contract that wants to support safeTransfers
       * from ERC721 asset contracts.
       */
      contract IERC721Receiver {
          /**
           * @notice Handle the receipt of an NFT
           * @dev The ERC721 smart contract calls this function on the recipient
           * after a `safeTransfer`. This function MUST return the function selector,
           * otherwise the caller will revert the transaction. The selector to be
           * returned can be obtained as `this.onERC721Received.selector`. This
           * function MAY throw to revert and reject the transfer.
           * Note: the ERC721 contract address is always the message sender.
           * @param operator The address which called `safeTransferFrom` function
           * @param from The address which previously owned the token
           * @param tokenId The NFT identifier which is being transferred
           * @param data Additional data with no specified format
           * @return bytes4 `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`
           */
          function onERC721Received(address operator, address from, uint256 tokenId, bytes memory data)
          public returns (bytes4);
      }
      
      // File: @openzeppelin/contracts/math/SafeMath.sol
      
      pragma solidity ^0.5.0;
      
      /**
       * @dev Wrappers over Solidity's arithmetic operations with added overflow
       * checks.
       *
       * Arithmetic operations in Solidity wrap on overflow. This can easily result
       * in bugs, because programmers usually assume that an overflow raises an
       * error, which is the standard behavior in high level programming languages.
       * `SafeMath` restores this intuition by reverting the transaction when an
       * operation overflows.
       *
       * Using this library instead of the unchecked operations eliminates an entire
       * class of bugs, so it's recommended to use it always.
       */
      library SafeMath {
          /**
           * @dev Returns the addition of two unsigned integers, reverting on
           * overflow.
           *
           * Counterpart to Solidity's `+` operator.
           *
           * Requirements:
           * - Addition cannot overflow.
           */
          function add(uint256 a, uint256 b) internal pure returns (uint256) {
              uint256 c = a + b;
              require(c >= a, "SafeMath: addition overflow");
      
              return c;
          }
      
          /**
           * @dev Returns the subtraction of two unsigned integers, reverting on
           * overflow (when the result is negative).
           *
           * Counterpart to Solidity's `-` operator.
           *
           * Requirements:
           * - Subtraction cannot overflow.
           */
          function sub(uint256 a, uint256 b) internal pure returns (uint256) {
              require(b <= a, "SafeMath: subtraction overflow");
              uint256 c = a - b;
      
              return c;
          }
      
          /**
           * @dev Returns the multiplication of two unsigned integers, reverting on
           * overflow.
           *
           * Counterpart to Solidity's `*` operator.
           *
           * Requirements:
           * - Multiplication cannot overflow.
           */
          function mul(uint256 a, uint256 b) internal pure returns (uint256) {
              // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
              // benefit is lost if 'b' is also tested.
              // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
              if (a == 0) {
                  return 0;
              }
      
              uint256 c = a * b;
              require(c / a == b, "SafeMath: multiplication overflow");
      
              return c;
          }
      
          /**
           * @dev Returns the integer division of two unsigned integers. Reverts on
           * division by zero. The result is rounded towards zero.
           *
           * Counterpart to Solidity's `/` operator. Note: this function uses a
           * `revert` opcode (which leaves remaining gas untouched) while Solidity
           * uses an invalid opcode to revert (consuming all remaining gas).
           *
           * Requirements:
           * - The divisor cannot be zero.
           */
          function div(uint256 a, uint256 b) internal pure returns (uint256) {
              // Solidity only automatically asserts when dividing by 0
              require(b > 0, "SafeMath: division by zero");
              uint256 c = a / b;
              // assert(a == b * c + a % b); // There is no case in which this doesn't hold
      
              return c;
          }
      
          /**
           * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
           * Reverts when dividing by zero.
           *
           * Counterpart to Solidity's `%` operator. This function uses a `revert`
           * opcode (which leaves remaining gas untouched) while Solidity uses an
           * invalid opcode to revert (consuming all remaining gas).
           *
           * Requirements:
           * - The divisor cannot be zero.
           */
          function mod(uint256 a, uint256 b) internal pure returns (uint256) {
              require(b != 0, "SafeMath: modulo by zero");
              return a % b;
          }
      }
      
      // File: @openzeppelin/contracts/utils/Address.sol
      
      pragma solidity ^0.5.0;
      
      /**
       * @dev Collection of functions related to the address type,
       */
      library Address {
          /**
           * @dev Returns true if `account` is a contract.
           *
           * This test is non-exhaustive, and there may be false-negatives: during the
           * execution of a contract's constructor, its address will be reported as
           * not containing a contract.
           *
           * > It is unsafe to assume that an address for which this function returns
           * false is an externally-owned account (EOA) and not a contract.
           */
          function isContract(address account) internal view returns (bool) {
              // This method relies in extcodesize, which returns 0 for contracts in
              // construction, since the code is only stored at the end of the
              // constructor execution.
      
              uint256 size;
              // solhint-disable-next-line no-inline-assembly
              assembly { size := extcodesize(account) }
              return size > 0;
          }
      }
      
      // File: @openzeppelin/contracts/drafts/Counters.sol
      
      pragma solidity ^0.5.0;
      
      
      /**
       * @title Counters
       * @author Matt Condon (@shrugs)
       * @dev Provides counters that can only be incremented or decremented by one. This can be used e.g. to track the number
       * of elements in a mapping, issuing ERC721 ids, or counting request ids.
       *
       * Include with `using Counters for Counters.Counter;`
       * Since it is not possible to overflow a 256 bit integer with increments of one, `increment` can skip the SafeMath
       * overflow check, thereby saving gas. This does assume however correct usage, in that the underlying `_value` is never
       * directly accessed.
       */
      library Counters {
          using SafeMath for uint256;
      
          struct Counter {
              // This variable should never be directly accessed by users of the library: interactions must be restricted to
              // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add
              // this feature: see https://github.com/ethereum/solidity/issues/4637
              uint256 _value; // default: 0
          }
      
          function current(Counter storage counter) internal view returns (uint256) {
              return counter._value;
          }
      
          function increment(Counter storage counter) internal {
              counter._value += 1;
          }
      
          function decrement(Counter storage counter) internal {
              counter._value = counter._value.sub(1);
          }
      }
      
      // File: @openzeppelin/contracts/introspection/ERC165.sol
      
      pragma solidity ^0.5.0;
      
      
      /**
       * @dev Implementation of the `IERC165` interface.
       *
       * Contracts may inherit from this and call `_registerInterface` to declare
       * their support of an interface.
       */
      contract ERC165 is IERC165 {
          /*
           * bytes4(keccak256('supportsInterface(bytes4)')) == 0x01ffc9a7
           */
          bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7;
      
          /**
           * @dev Mapping of interface ids to whether or not it's supported.
           */
          mapping(bytes4 => bool) private _supportedInterfaces;
      
          constructor () internal {
              // Derived contracts need only register support for their own interfaces,
              // we register support for ERC165 itself here
              _registerInterface(_INTERFACE_ID_ERC165);
          }
      
          /**
           * @dev See `IERC165.supportsInterface`.
           *
           * Time complexity O(1), guaranteed to always use less than 30 000 gas.
           */
          function supportsInterface(bytes4 interfaceId) external view returns (bool) {
              return _supportedInterfaces[interfaceId];
          }
      
          /**
           * @dev Registers the contract as an implementer of the interface defined by
           * `interfaceId`. Support of the actual ERC165 interface is automatic and
           * registering its interface id is not required.
           *
           * See `IERC165.supportsInterface`.
           *
           * Requirements:
           *
           * - `interfaceId` cannot be the ERC165 invalid interface (`0xffffffff`).
           */
          function _registerInterface(bytes4 interfaceId) internal {
              require(interfaceId != 0xffffffff, "ERC165: invalid interface id");
              _supportedInterfaces[interfaceId] = true;
          }
      }
      
      // File: @openzeppelin/contracts/token/ERC721/ERC721.sol
      
      pragma solidity ^0.5.0;
      
      
      
      
      
      
      
      /**
       * @title ERC721 Non-Fungible Token Standard basic implementation
       * @dev see https://eips.ethereum.org/EIPS/eip-721
       */
      contract ERC721 is ERC165, IERC721 {
          using SafeMath for uint256;
          using Address for address;
          using Counters for Counters.Counter;
      
          // Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`
          // which can be also obtained as `IERC721Receiver(0).onERC721Received.selector`
          bytes4 private constant _ERC721_RECEIVED = 0x150b7a02;
      
          // Mapping from token ID to owner
          mapping (uint256 => address) private _tokenOwner;
      
          // Mapping from token ID to approved address
          mapping (uint256 => address) private _tokenApprovals;
      
          // Mapping from owner to number of owned token
          mapping (address => Counters.Counter) private _ownedTokensCount;
      
          // Mapping from owner to operator approvals
          mapping (address => mapping (address => bool)) private _operatorApprovals;
      
          /*
           *     bytes4(keccak256('balanceOf(address)')) == 0x70a08231
           *     bytes4(keccak256('ownerOf(uint256)')) == 0x6352211e
           *     bytes4(keccak256('approve(address,uint256)')) == 0x095ea7b3
           *     bytes4(keccak256('getApproved(uint256)')) == 0x081812fc
           *     bytes4(keccak256('setApprovalForAll(address,bool)')) == 0xa22cb465
           *     bytes4(keccak256('isApprovedForAll(address,address)')) == 0xe985e9c
           *     bytes4(keccak256('transferFrom(address,address,uint256)')) == 0x23b872dd
           *     bytes4(keccak256('safeTransferFrom(address,address,uint256)')) == 0x42842e0e
           *     bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) == 0xb88d4fde
           *
           *     => 0x70a08231 ^ 0x6352211e ^ 0x095ea7b3 ^ 0x081812fc ^
           *        0xa22cb465 ^ 0xe985e9c ^ 0x23b872dd ^ 0x42842e0e ^ 0xb88d4fde == 0x80ac58cd
           */
          bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd;
      
          constructor () public {
              // register the supported interfaces to conform to ERC721 via ERC165
              _registerInterface(_INTERFACE_ID_ERC721);
          }
      
          /**
           * @dev Gets the balance of the specified address.
           * @param owner address to query the balance of
           * @return uint256 representing the amount owned by the passed address
           */
          function balanceOf(address owner) public view returns (uint256) {
              require(owner != address(0), "ERC721: balance query for the zero address");
      
              return _ownedTokensCount[owner].current();
          }
      
          /**
           * @dev Gets the owner of the specified token ID.
           * @param tokenId uint256 ID of the token to query the owner of
           * @return address currently marked as the owner of the given token ID
           */
          function ownerOf(uint256 tokenId) public view returns (address) {
              address owner = _tokenOwner[tokenId];
              require(owner != address(0), "ERC721: owner query for nonexistent token");
      
              return owner;
          }
      
          /**
           * @dev Approves another address to transfer the given token ID
           * The zero address indicates there is no approved address.
           * There can only be one approved address per token at a given time.
           * Can only be called by the token owner or an approved operator.
           * @param to address to be approved for the given token ID
           * @param tokenId uint256 ID of the token to be approved
           */
          function approve(address to, uint256 tokenId) public {
              address owner = ownerOf(tokenId);
              require(to != owner, "ERC721: approval to current owner");
      
              require(msg.sender == owner || isApprovedForAll(owner, msg.sender),
                  "ERC721: approve caller is not owner nor approved for all"
              );
      
              _tokenApprovals[tokenId] = to;
              emit Approval(owner, to, tokenId);
          }
      
          /**
           * @dev Gets the approved address for a token ID, or zero if no address set
           * Reverts if the token ID does not exist.
           * @param tokenId uint256 ID of the token to query the approval of
           * @return address currently approved for the given token ID
           */
          function getApproved(uint256 tokenId) public view returns (address) {
              require(_exists(tokenId), "ERC721: approved query for nonexistent token");
      
              return _tokenApprovals[tokenId];
          }
      
          /**
           * @dev Sets or unsets the approval of a given operator
           * An operator is allowed to transfer all tokens of the sender on their behalf.
           * @param to operator address to set the approval
           * @param approved representing the status of the approval to be set
           */
          function setApprovalForAll(address to, bool approved) public {
              require(to != msg.sender, "ERC721: approve to caller");
      
              _operatorApprovals[msg.sender][to] = approved;
              emit ApprovalForAll(msg.sender, to, approved);
          }
      
          /**
           * @dev Tells whether an operator is approved by a given owner.
           * @param owner owner address which you want to query the approval of
           * @param operator operator address which you want to query the approval of
           * @return bool whether the given operator is approved by the given owner
           */
          function isApprovedForAll(address owner, address operator) public view returns (bool) {
              return _operatorApprovals[owner][operator];
          }
      
          /**
           * @dev Transfers the ownership of a given token ID to another address.
           * Usage of this method is discouraged, use `safeTransferFrom` whenever possible.
           * Requires the msg.sender to be the owner, approved, or operator.
           * @param from current owner of the token
           * @param to address to receive the ownership of the given token ID
           * @param tokenId uint256 ID of the token to be transferred
           */
          function transferFrom(address from, address to, uint256 tokenId) public {
              //solhint-disable-next-line max-line-length
              require(_isApprovedOrOwner(msg.sender, tokenId), "ERC721: transfer caller is not owner nor approved");
      
              _transferFrom(from, to, tokenId);
          }
      
          /**
           * @dev Safely transfers the ownership of a given token ID to another address
           * If the target address is a contract, it must implement `onERC721Received`,
           * which is called upon a safe transfer, and return the magic value
           * `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`; otherwise,
           * the transfer is reverted.
           * Requires the msg.sender to be the owner, approved, or operator
           * @param from current owner of the token
           * @param to address to receive the ownership of the given token ID
           * @param tokenId uint256 ID of the token to be transferred
           */
          function safeTransferFrom(address from, address to, uint256 tokenId) public {
              safeTransferFrom(from, to, tokenId, "");
          }
      
          /**
           * @dev Safely transfers the ownership of a given token ID to another address
           * If the target address is a contract, it must implement `onERC721Received`,
           * which is called upon a safe transfer, and return the magic value
           * `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`; otherwise,
           * the transfer is reverted.
           * Requires the msg.sender to be the owner, approved, or operator
           * @param from current owner of the token
           * @param to address to receive the ownership of the given token ID
           * @param tokenId uint256 ID of the token to be transferred
           * @param _data bytes data to send along with a safe transfer check
           */
          function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) public {
              transferFrom(from, to, tokenId);
              require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
          }
      
          /**
           * @dev Returns whether the specified token exists.
           * @param tokenId uint256 ID of the token to query the existence of
           * @return bool whether the token exists
           */
          function _exists(uint256 tokenId) internal view returns (bool) {
              address owner = _tokenOwner[tokenId];
              return owner != address(0);
          }
      
          /**
           * @dev Returns whether the given spender can transfer a given token ID.
           * @param spender address of the spender to query
           * @param tokenId uint256 ID of the token to be transferred
           * @return bool whether the msg.sender is approved for the given token ID,
           * is an operator of the owner, or is the owner of the token
           */
          function _isApprovedOrOwner(address spender, uint256 tokenId) internal view returns (bool) {
              require(_exists(tokenId), "ERC721: operator query for nonexistent token");
              address owner = ownerOf(tokenId);
              return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender));
          }
      
          /**
           * @dev Internal function to mint a new token.
           * Reverts if the given token ID already exists.
           * @param to The address that will own the minted token
           * @param tokenId uint256 ID of the token to be minted
           */
          function _mint(address to, uint256 tokenId) internal {
              require(to != address(0), "ERC721: mint to the zero address");
              require(!_exists(tokenId), "ERC721: token already minted");
      
              _tokenOwner[tokenId] = to;
              _ownedTokensCount[to].increment();
      
              emit Transfer(address(0), to, tokenId);
          }
      
          /**
           * @dev Internal function to burn a specific token.
           * Reverts if the token does not exist.
           * Deprecated, use _burn(uint256) instead.
           * @param owner owner of the token to burn
           * @param tokenId uint256 ID of the token being burned
           */
          function _burn(address owner, uint256 tokenId) internal {
              require(ownerOf(tokenId) == owner, "ERC721: burn of token that is not own");
      
              _clearApproval(tokenId);
      
              _ownedTokensCount[owner].decrement();
              _tokenOwner[tokenId] = address(0);
      
              emit Transfer(owner, address(0), tokenId);
          }
      
          /**
           * @dev Internal function to burn a specific token.
           * Reverts if the token does not exist.
           * @param tokenId uint256 ID of the token being burned
           */
          function _burn(uint256 tokenId) internal {
              _burn(ownerOf(tokenId), tokenId);
          }
      
          /**
           * @dev Internal function to transfer ownership of a given token ID to another address.
           * As opposed to transferFrom, this imposes no restrictions on msg.sender.
           * @param from current owner of the token
           * @param to address to receive the ownership of the given token ID
           * @param tokenId uint256 ID of the token to be transferred
           */
          function _transferFrom(address from, address to, uint256 tokenId) internal {
              require(ownerOf(tokenId) == from, "ERC721: transfer of token that is not own");
              require(to != address(0), "ERC721: transfer to the zero address");
      
              _clearApproval(tokenId);
      
              _ownedTokensCount[from].decrement();
              _ownedTokensCount[to].increment();
      
              _tokenOwner[tokenId] = to;
      
              emit Transfer(from, to, tokenId);
          }
      
          /**
           * @dev Internal function to invoke `onERC721Received` on a target address.
           * The call is not executed if the target address is not a contract.
           *
           * This function is deprecated.
           * @param from address representing the previous owner of the given token ID
           * @param to target address that will receive the tokens
           * @param tokenId uint256 ID of the token to be transferred
           * @param _data bytes optional data to send along with the call
           * @return bool whether the call correctly returned the expected magic value
           */
          function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory _data)
              internal returns (bool)
          {
              if (!to.isContract()) {
                  return true;
              }
      
              bytes4 retval = IERC721Receiver(to).onERC721Received(msg.sender, from, tokenId, _data);
              return (retval == _ERC721_RECEIVED);
          }
      
          /**
           * @dev Private function to clear current approval of a given token ID.
           * @param tokenId uint256 ID of the token to be transferred
           */
          function _clearApproval(uint256 tokenId) private {
              if (_tokenApprovals[tokenId] != address(0)) {
                  _tokenApprovals[tokenId] = address(0);
              }
          }
      }
      
      // File: @openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol
      
      pragma solidity ^0.5.0;
      
      
      /**
       * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
       * @dev See https://eips.ethereum.org/EIPS/eip-721
       */
      contract IERC721Enumerable is IERC721 {
          function totalSupply() public view returns (uint256);
          function tokenOfOwnerByIndex(address owner, uint256 index) public view returns (uint256 tokenId);
      
          function tokenByIndex(uint256 index) public view returns (uint256);
      }
      
      // File: @openzeppelin/contracts/token/ERC721/ERC721Enumerable.sol
      
      pragma solidity ^0.5.0;
      
      
      
      
      /**
       * @title ERC-721 Non-Fungible Token with optional enumeration extension logic
       * @dev See https://eips.ethereum.org/EIPS/eip-721
       */
      contract ERC721Enumerable is ERC165, ERC721, IERC721Enumerable {
          // Mapping from owner to list of owned token IDs
          mapping(address => uint256[]) private _ownedTokens;
      
          // Mapping from token ID to index of the owner tokens list
          mapping(uint256 => uint256) private _ownedTokensIndex;
      
          // Array with all token ids, used for enumeration
          uint256[] private _allTokens;
      
          // Mapping from token id to position in the allTokens array
          mapping(uint256 => uint256) private _allTokensIndex;
      
          /*
           *     bytes4(keccak256('totalSupply()')) == 0x18160ddd
           *     bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) == 0x2f745c59
           *     bytes4(keccak256('tokenByIndex(uint256)')) == 0x4f6ccce7
           *
           *     => 0x18160ddd ^ 0x2f745c59 ^ 0x4f6ccce7 == 0x780e9d63
           */
          bytes4 private constant _INTERFACE_ID_ERC721_ENUMERABLE = 0x780e9d63;
      
          /**
           * @dev Constructor function.
           */
          constructor () public {
              // register the supported interface to conform to ERC721Enumerable via ERC165
              _registerInterface(_INTERFACE_ID_ERC721_ENUMERABLE);
          }
      
          /**
           * @dev Gets the token ID at a given index of the tokens list of the requested owner.
           * @param owner address owning the tokens list to be accessed
           * @param index uint256 representing the index to be accessed of the requested tokens list
           * @return uint256 token ID at the given index of the tokens list owned by the requested address
           */
          function tokenOfOwnerByIndex(address owner, uint256 index) public view returns (uint256) {
              require(index < balanceOf(owner), "ERC721Enumerable: owner index out of bounds");
              return _ownedTokens[owner][index];
          }
      
          /**
           * @dev Gets the total amount of tokens stored by the contract.
           * @return uint256 representing the total amount of tokens
           */
          function totalSupply() public view returns (uint256) {
              return _allTokens.length;
          }
      
          /**
           * @dev Gets the token ID at a given index of all the tokens in this contract
           * Reverts if the index is greater or equal to the total number of tokens.
           * @param index uint256 representing the index to be accessed of the tokens list
           * @return uint256 token ID at the given index of the tokens list
           */
          function tokenByIndex(uint256 index) public view returns (uint256) {
              require(index < totalSupply(), "ERC721Enumerable: global index out of bounds");
              return _allTokens[index];
          }
      
          /**
           * @dev Internal function to transfer ownership of a given token ID to another address.
           * As opposed to transferFrom, this imposes no restrictions on msg.sender.
           * @param from current owner of the token
           * @param to address to receive the ownership of the given token ID
           * @param tokenId uint256 ID of the token to be transferred
           */
          function _transferFrom(address from, address to, uint256 tokenId) internal {
              super._transferFrom(from, to, tokenId);
      
              _removeTokenFromOwnerEnumeration(from, tokenId);
      
              _addTokenToOwnerEnumeration(to, tokenId);
          }
      
          /**
           * @dev Internal function to mint a new token.
           * Reverts if the given token ID already exists.
           * @param to address the beneficiary that will own the minted token
           * @param tokenId uint256 ID of the token to be minted
           */
          function _mint(address to, uint256 tokenId) internal {
              super._mint(to, tokenId);
      
              _addTokenToOwnerEnumeration(to, tokenId);
      
              _addTokenToAllTokensEnumeration(tokenId);
          }
      
          /**
           * @dev Internal function to burn a specific token.
           * Reverts if the token does not exist.
           * Deprecated, use _burn(uint256) instead.
           * @param owner owner of the token to burn
           * @param tokenId uint256 ID of the token being burned
           */
          function _burn(address owner, uint256 tokenId) internal {
              super._burn(owner, tokenId);
      
              _removeTokenFromOwnerEnumeration(owner, tokenId);
              // Since tokenId will be deleted, we can clear its slot in _ownedTokensIndex to trigger a gas refund
              _ownedTokensIndex[tokenId] = 0;
      
              _removeTokenFromAllTokensEnumeration(tokenId);
          }
      
          /**
           * @dev Gets the list of token IDs of the requested owner.
           * @param owner address owning the tokens
           * @return uint256[] List of token IDs owned by the requested address
           */
          function _tokensOfOwner(address owner) internal view returns (uint256[] storage) {
              return _ownedTokens[owner];
          }
      
          /**
           * @dev Private function to add a token to this extension's ownership-tracking data structures.
           * @param to address representing the new owner of the given token ID
           * @param tokenId uint256 ID of the token to be added to the tokens list of the given address
           */
          function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
              _ownedTokensIndex[tokenId] = _ownedTokens[to].length;
              _ownedTokens[to].push(tokenId);
          }
      
          /**
           * @dev Private function to add a token to this extension's token tracking data structures.
           * @param tokenId uint256 ID of the token to be added to the tokens list
           */
          function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
              _allTokensIndex[tokenId] = _allTokens.length;
              _allTokens.push(tokenId);
          }
      
          /**
           * @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that
           * while the token is not assigned a new owner, the _ownedTokensIndex mapping is _not_ updated: this allows for
           * gas optimizations e.g. when performing a transfer operation (avoiding double writes).
           * This has O(1) time complexity, but alters the order of the _ownedTokens array.
           * @param from address representing the previous owner of the given token ID
           * @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
           */
          function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private {
              // To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
              // then delete the last slot (swap and pop).
      
              uint256 lastTokenIndex = _ownedTokens[from].length.sub(1);
              uint256 tokenIndex = _ownedTokensIndex[tokenId];
      
              // When the token to delete is the last token, the swap operation is unnecessary
              if (tokenIndex != lastTokenIndex) {
                  uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];
      
                  _ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
                  _ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
              }
      
              // This also deletes the contents at the last position of the array
              _ownedTokens[from].length--;
      
              // Note that _ownedTokensIndex[tokenId] hasn't been cleared: it still points to the old slot (now occupied by
              // lastTokenId, or just over the end of the array if the token was the last one).
          }
      
          /**
           * @dev Private function to remove a token from this extension's token tracking data structures.
           * This has O(1) time complexity, but alters the order of the _allTokens array.
           * @param tokenId uint256 ID of the token to be removed from the tokens list
           */
          function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
              // To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and
              // then delete the last slot (swap and pop).
      
              uint256 lastTokenIndex = _allTokens.length.sub(1);
              uint256 tokenIndex = _allTokensIndex[tokenId];
      
              // When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so
              // rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding
              // an 'if' statement (like in _removeTokenFromOwnerEnumeration)
              uint256 lastTokenId = _allTokens[lastTokenIndex];
      
              _allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
              _allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
      
              // This also deletes the contents at the last position of the array
              _allTokens.length--;
              _allTokensIndex[tokenId] = 0;
          }
      }
      
      // File: @openzeppelin/contracts/token/ERC721/IERC721Metadata.sol
      
      pragma solidity ^0.5.0;
      
      
      /**
       * @title ERC-721 Non-Fungible Token Standard, optional metadata extension
       * @dev See https://eips.ethereum.org/EIPS/eip-721
       */
      contract IERC721Metadata is IERC721 {
          function name() external view returns (string memory);
          function symbol() external view returns (string memory);
          function tokenURI(uint256 tokenId) external view returns (string memory);
      }
      
      // File: @openzeppelin/contracts/token/ERC721/ERC721Metadata.sol
      
      pragma solidity ^0.5.0;
      
      
      
      
      contract ERC721Metadata is ERC165, ERC721, IERC721Metadata {
          // Token name
          string private _name;
      
          // Token symbol
          string private _symbol;
      
          // Optional mapping for token URIs
          mapping(uint256 => string) private _tokenURIs;
      
          /*
           *     bytes4(keccak256('name()')) == 0x06fdde03
           *     bytes4(keccak256('symbol()')) == 0x95d89b41
           *     bytes4(keccak256('tokenURI(uint256)')) == 0xc87b56dd
           *
           *     => 0x06fdde03 ^ 0x95d89b41 ^ 0xc87b56dd == 0x5b5e139f
           */
          bytes4 private constant _INTERFACE_ID_ERC721_METADATA = 0x5b5e139f;
      
          /**
           * @dev Constructor function
           */
          constructor (string memory name, string memory symbol) public {
              _name = name;
              _symbol = symbol;
      
              // register the supported interfaces to conform to ERC721 via ERC165
              _registerInterface(_INTERFACE_ID_ERC721_METADATA);
          }
      
          /**
           * @dev Gets the token name.
           * @return string representing the token name
           */
          function name() external view returns (string memory) {
              return _name;
          }
      
          /**
           * @dev Gets the token symbol.
           * @return string representing the token symbol
           */
          function symbol() external view returns (string memory) {
              return _symbol;
          }
      
          /**
           * @dev Returns an URI for a given token ID.
           * Throws if the token ID does not exist. May return an empty string.
           * @param tokenId uint256 ID of the token to query
           */
          function tokenURI(uint256 tokenId) external view returns (string memory) {
              require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
              return _tokenURIs[tokenId];
          }
      
          /**
           * @dev Internal function to set the token URI for a given token.
           * Reverts if the token ID does not exist.
           * @param tokenId uint256 ID of the token to set its URI
           * @param uri string URI to assign
           */
          function _setTokenURI(uint256 tokenId, string memory uri) internal {
              require(_exists(tokenId), "ERC721Metadata: URI set of nonexistent token");
              _tokenURIs[tokenId] = uri;
          }
      
          /**
           * @dev Internal function to burn a specific token.
           * Reverts if the token does not exist.
           * Deprecated, use _burn(uint256) instead.
           * @param owner owner of the token to burn
           * @param tokenId uint256 ID of the token being burned by the msg.sender
           */
          function _burn(address owner, uint256 tokenId) internal {
              super._burn(owner, tokenId);
      
              // Clear metadata (if any)
              if (bytes(_tokenURIs[tokenId]).length != 0) {
                  delete _tokenURIs[tokenId];
              }
          }
      }
      
      // File: @openzeppelin/contracts/token/ERC721/ERC721Full.sol
      
      pragma solidity ^0.5.0;
      
      
      
      
      /**
       * @title Full ERC721 Token
       * This implementation includes all the required and some optional functionality of the ERC721 standard
       * Moreover, it includes approve all functionality using operator terminology
       * @dev see https://eips.ethereum.org/EIPS/eip-721
       */
      contract ERC721Full is ERC721, ERC721Enumerable, ERC721Metadata {
          constructor (string memory name, string memory symbol) public ERC721Metadata(name, symbol) {
              // solhint-disable-previous-line no-empty-blocks
          }
      }
      
      // File: contracts/libs/String.sol
      
      pragma solidity ^0.5.11;
      
      library String {
      
          /**
           * @dev Convert bytes32 to string.
           * @param _x - to be converted to string.
           * @return string
           */
          function bytes32ToString(bytes32 _x) internal pure returns (string memory) {
              bytes memory bytesString = new bytes(32);
              uint charCount = 0;
              for (uint j = 0; j < 32; j++) {
                  byte char = byte(bytes32(uint(_x) * 2 ** (8 * j)));
                  if (char != 0) {
                      bytesString[charCount] = char;
                      charCount++;
                  }
              }
              bytes memory bytesStringTrimmed = new bytes(charCount);
              for (uint j = 0; j < charCount; j++) {
                  bytesStringTrimmed[j] = bytesString[j];
              }
              return string(bytesStringTrimmed);
          }
      
          /**
           * @dev Convert uint to string.
           * @param _i - uint256 to be converted to string.
           * @return uint in string
           */
          function uintToString(uint _i) internal pure returns (string memory _uintAsString) {
              uint i = _i;
      
              if (i == 0) {
                  return "0";
              }
              uint j = i;
              uint len;
              while (j != 0) {
                  len++;
                  j /= 10;
              }
              bytes memory bstr = new bytes(len);
              uint k = len - 1;
              while (i != 0) {
                  bstr[k--] = byte(uint8(48 + i % 10));
                  i /= 10;
              }
              return string(bstr);
          }
      }
      
      // File: contracts/ERC721BaseCollection.sol
      
      pragma solidity ^0.5.11;
      
      
      
      
      contract ERC721BaseCollection is Ownable, ERC721Full {
          using String for bytes32;
          using String for uint256;
      
          mapping(bytes32 => uint256) public maxIssuance;
          mapping(bytes32 => uint) public issued;
          mapping(uint256 => string) internal _tokenPaths;
          mapping(address => bool) public allowed;
      
          string[] public wearables;
      
          string public baseURI;
          bool public isComplete;
      
          event BaseURI(string _oldBaseURI, string _newBaseURI);
          event Allowed(address indexed _operator, bool _allowed);
          event AddWearable(bytes32 indexed _wearableIdKey, string _wearableId, uint256 _maxIssuance);
          event Issue(address indexed _beneficiary, uint256 indexed _tokenId, bytes32 indexed _wearableIdKey, string _wearableId, uint256 _issuedId);
          event Complete();
      
      
          /**
           * @dev Create the contract.
           * @param _name - name of the contract
           * @param _symbol - symbol of the contract
           * @param _operator - Address allowed to mint tokens
           * @param _baseURI - base URI for token URIs
           */
          constructor(string memory _name, string memory _symbol, address _operator, string memory _baseURI) public ERC721Full(_name, _symbol) {
              setAllowed(_operator, true);
              setBaseURI(_baseURI);
          }
      
          modifier onlyAllowed() {
              require(allowed[msg.sender], "Only an `allowed` address can issue tokens");
              _;
          }
      
      
          /**
           * @dev Set Base URI.
           * @param _baseURI - base URI for token URIs
           */
          function setBaseURI(string memory _baseURI) public onlyOwner {
              emit BaseURI(baseURI, _baseURI);
              baseURI = _baseURI;
          }
      
          /**
           * @dev Set allowed account to issue tokens.
           * @param _operator - Address allowed to issue tokens
           * @param _allowed - Whether is allowed or not
           */
          function setAllowed(address _operator, bool _allowed) public onlyOwner {
              require(_operator != address(0), "Invalid address");
              require(allowed[_operator] != _allowed, "You should set a different value");
      
              allowed[_operator] = _allowed;
              emit Allowed(_operator, _allowed);
          }
      
      
          /**
           * @dev Returns an URI for a given token ID.
           * Throws if the token ID does not exist. May return an empty string.
           * @param _tokenId - uint256 ID of the token queried
           * @return token URI
           */
          function tokenURI(uint256 _tokenId) external view returns (string memory) {
              require(_exists(_tokenId), "ERC721Metadata: received a URI query for a nonexistent token");
              return string(abi.encodePacked(baseURI, _tokenPaths[_tokenId]));
          }
      
      
          /**
           * @dev Transfers the ownership of given tokens ID to another address.
           * Usage of this method is discouraged, use {safeBatchTransferFrom} whenever possible.
           * Requires the msg.sender to be the owner, approved, or operator.
           * @param _from current owner of the token
           * @param _to address to receive the ownership of the given token ID
           * @param _tokenIds uint256 ID of the token to be transferred
           */
          function batchTransferFrom(address _from, address _to, uint256[] calldata _tokenIds) external {
              for (uint256 i = 0; i < _tokenIds.length; i++) {
                  transferFrom(_from, _to, _tokenIds[i]);
              }
          }
      
          /**
           * @dev Returns the wearables length.
           * @return wearable length
           */
          function wearablesCount() external view returns (uint256) {
              return wearables.length;
          }
      
          /**
           * @dev Complete the collection.
           * @notice that it will only prevent for adding more wearables.
           * The issuance is still allowed.
           */
          function completeCollection() external onlyOwner {
              require(!isComplete, "The collection is already completed");
              isComplete = true;
              emit Complete();
          }
      
           /**
           * @dev Add a new wearable to the collection.
           * @notice that this method should only allow wearableIds less than or equal to 32 bytes
           * @param _wearableIds - wearable ids
           * @param _maxIssuances - total supply for the wearables
           */
          function addWearables(bytes32[] calldata _wearableIds, uint256[] calldata _maxIssuances) external onlyOwner {
              require(_wearableIds.length == _maxIssuances.length, "Parameters should have the same length");
      
              for (uint256 i = 0; i < _wearableIds.length; i++) {
                  addWearable(_wearableIds[i].bytes32ToString(), _maxIssuances[i]);
              }
          }
      
          /**
           * @dev Add a new wearable to the collection.
           * @notice that this method allows wearableIds of any size. It should be used
           * if a wearableId is greater than 32 bytes
           * @param _wearableId - wearable id
           * @param _maxIssuance - total supply for the wearable
           */
          function addWearable(string memory _wearableId, uint256 _maxIssuance) public onlyOwner {
              require(!isComplete, "The collection is complete");
              bytes32 key = getWearableKey(_wearableId);
      
              require(maxIssuance[key] == 0, "Can not modify an existing wearable");
              require(_maxIssuance > 0, "Max issuance should be greater than 0");
      
              maxIssuance[key] = _maxIssuance;
              wearables.push(_wearableId);
      
              emit AddWearable(key, _wearableId, _maxIssuance);
          }
      
          /**
           * @dev Safely transfers the ownership of given token IDs to another address
           * If the target address is a contract, it must implement {IERC721Receiver-onERC721Received},
           * which is called upon a safe transfer, and return the magic value
           * `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`; otherwise,
           * the transfer is reverted.
           * Requires the msg.sender to be the owner, approved, or operator
           * @param _from - current owner of the token
           * @param _to - address to receive the ownership of the given token ID
           * @param _tokenIds - uint256 IDs of the tokens to be transferred
           */
          function safeBatchTransferFrom(address _from, address _to, uint256[] memory _tokenIds) public {
              safeBatchTransferFrom(_from, _to, _tokenIds, "");
          }
      
          /**
           * @dev Safely transfers the ownership of given token IDs to another address
           * If the target address is a contract, it must implement {IERC721Receiver-onERC721Received},
           * which is called upon a safe transfer, and return the magic value
           * `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`; otherwise,
           * the transfer is reverted.
           * Requires the msg.sender to be the owner, approved, or operator
           * @param _from - current owner of the token
           * @param _to - address to receive the ownership of the given token ID
           * @param _tokenIds - uint256 ID of the tokens to be transferred
           * @param _data bytes data to send along with a safe transfer check
           */
          function safeBatchTransferFrom(address _from, address _to, uint256[] memory _tokenIds, bytes memory _data) public {
              for (uint256 i = 0; i < _tokenIds.length; i++) {
                  safeTransferFrom(_from, _to, _tokenIds[i], _data);
              }
          }
      
          /**
           * @dev Get keccak256 of a wearableId.
           * @param _wearableId - token wearable
           * @return bytes32 keccak256 of the wearableId
           */
          function getWearableKey(string memory _wearableId) public pure returns (bytes32) {
              return keccak256(abi.encodePacked(_wearableId));
          }
      
          /**
           * @dev Mint a new NFT of the specified kind.
           * @notice that will throw if kind has reached its maximum or is invalid
           * @param _beneficiary - owner of the token
           * @param _tokenId - token
           * @param _wearableIdKey - wearable key
           * @param _wearableId - token wearable
           * @param _issuedId - issued id
           */
          function _mint(
              address _beneficiary,
              uint256 _tokenId,
              bytes32 _wearableIdKey,
              string memory _wearableId,
              uint256 _issuedId
          ) internal {
              // Check issuance
              require(
                  _issuedId > 0 && _issuedId <= maxIssuance[_wearableIdKey],
                  "Invalid issued id"
              );
              require(issued[_wearableIdKey] < maxIssuance[_wearableIdKey], "Option exhausted");
      
              // Mint erc721 token
              super._mint(_beneficiary, _tokenId);
      
              // Increase issuance
              issued[_wearableIdKey] = issued[_wearableIdKey] + 1;
      
              // Log
              emit Issue(_beneficiary, _tokenId, _wearableIdKey, _wearableId, _issuedId);
          }
      }
      
      // File: contracts/ERC721DeterministicCollection.sol
      
      pragma solidity ^0.5.11;
      
      
      
      
      
      contract ERC721DeterministicCollection is Ownable, ERC721Full, ERC721BaseCollection {
          uint8 constant public OPTIONS_BITS = 40;
          uint8 constant public ISSUANCE_BITS = 216;
      
          uint40 constant public MAX_OPTIONS = uint40(-1);
          uint216 constant public MAX_ISSUANCE = uint216(-1);
      
          /**
           * @dev Create the contract.
           * @param _name - name of the contract
           * @param _symbol - symbol of the contract
           * @param _operator - Address allowed to mint tokens
           * @param _baseURI - base URI for token URIs
           */
          constructor(
              string memory _name,
              string memory _symbol,
              address _operator,
              string memory _baseURI
          ) public ERC721BaseCollection(_name, _symbol, _operator, _baseURI) {}
      
           /**
           * @dev Add a new wearable to the collection.
           * @notice that this method allows wearableIds of any size. It should be used
           * if a wearableId is greater than 32 bytes
           * @param _wearableId - wearable id
           * @param _maxIssuance - total supply for the wearable
           */
          function addWearable(string memory _wearableId, uint256 _maxIssuance) public onlyOwner {
              require(wearables.length < MAX_OPTIONS, "Wearables options have reached MAX_OPTIONS");
              require(_maxIssuance <= MAX_ISSUANCE, "Max issuance should be lower or equal than MAX_ISSUANCE");
      
              super.addWearable(_wearableId, _maxIssuance);
          }
      
           /**
           * @dev Returns an URI for a given token ID.
           * Throws if the token ID does not exist. May return an empty string.
           * @param _tokenId - uint256 ID of the token queried
           * @return token URI
           */
          function tokenURI(uint256 _tokenId) external view returns (string memory) {
              require(_exists(_tokenId), "ERC721Metadata: received a URI query for a nonexistent token");
      
              (uint256 optionId, uint256 issuedId) = _decodeTokenId(_tokenId);
      
              return string(abi.encodePacked(baseURI, wearables[optionId], "/", issuedId.uintToString()));
          }
      
          /**
           * @dev Issue a new NFT of the specified kind.
           * @notice that will throw if kind has reached its maximum or is invalid
           * @param _beneficiary - owner of the token
           * @param _optionId - option id
           * @param _issuedId - issued id
           */
          function issueToken(address _beneficiary,  uint256 _optionId, uint256 _issuedId) external onlyAllowed {
              _issueToken(_beneficiary, _optionId, _issuedId);
          }
      
          /**
           * @dev Issue NFTs.
           * @notice that will throw if kind has reached its maximum or is invalid
           * @param _beneficiaries - owner of the tokens
           * @param _optionIds - option ids
           * @param _issuedIds - issued ids
           */
          function issueTokens(address[] calldata _beneficiaries, uint256[] calldata _optionIds, uint256[] calldata _issuedIds) external onlyAllowed {
              require(_beneficiaries.length == _optionIds.length, "Parameters should have the same length");
              require(_optionIds.length == _issuedIds.length, "Parameters should have the same length");
      
              for (uint256 i = 0; i < _optionIds.length; i++) {
                  _issueToken(_beneficiaries[i],_optionIds[i], _issuedIds[i]);
              }
          }
      
          /**
           * @dev Issue a new NFT of the specified kind.
           * @notice that will throw if kind has reached its maximum or is invalid
           * @param _beneficiary - owner of the token
           * @param _optionId - option id
           * @param _issuedId - issued id
           */
          function _issueToken(address _beneficiary, uint256 _optionId, uint256 _issuedId) internal {
              // Check option id
              require(_optionId < wearables.length, "Invalid option id");
      
              // Get werable
              string memory wearableId = wearables[_optionId];
      
              // Get wearable key
              bytes32 key = getWearableKey(wearableId);
      
              // Encode token id
              uint tokenId = _encodeTokenId(_optionId, _issuedId);
      
              // Mint token
              _mint(_beneficiary, tokenId, key, wearableId, _issuedId);
          }
      
           /**
           * @dev Encode token id
           * @notice optionId (`optionBits` bits) + issuedId (`issuedIdBits` bits)
           * @param _optionId - option id
           * @param _issuedId - issued id
           * @return uint256 of the encoded id
           */
          function _encodeTokenId(uint256 _optionId, uint256 _issuedId) internal pure returns (uint256 id) {
              require(_optionId <= MAX_OPTIONS, "The option id should be lower or equal than the MAX_OPTIONS");
              require(_issuedId <= MAX_ISSUANCE, "The issuance id should be lower or equal than the MAX_ISSUANCE");
      
              // solium-disable-next-line security/no-inline-assembly
              assembly {
                  id := or(shl(ISSUANCE_BITS, _optionId), _issuedId)
              }
          }
      
          /**
           * @dev Decode token id
           * @notice optionId (`optionBits` bits) + issuedId (`issuedIdBits` bits)
           * @param _id - token id
           * @return uint256 of the option id
           * @return uint256 of the issued id
           */
          function _decodeTokenId(uint256 _id) internal pure returns (uint256 optionId, uint256 issuedId) {
              uint256 mask = MAX_ISSUANCE;
              // solium-disable-next-line security/no-inline-assembly
              assembly {
                  optionId := shr(ISSUANCE_BITS, _id)
                  issuedId := and(mask, _id)
              }
          }
      }