ETH Price: $2,429.22 (+0.38%)

Transaction Decoder

Block:
16235432 at Dec-21-2022 08:21:35 PM +UTC
Transaction Fee:
0.002028766985194808 ETH $4.93
Gas Used:
122,488 Gas / 16.562985641 Gwei

Emitted Events:

26 SuperRareBazaar.AuctionBid( _contractAddress=SuperRareV2, _bidder=[Sender] 0x533b9cdce87facf35c4066f48537660bf2bf16ad, _tokenId=41458, _currencyAddress=0x00000000...000000000, _amount=7326000000000000000, _startedAuction=False, _newAuctionLength=88356, _previousBidder=0x5eeef1ed716a26380860097332f7db08dc2292b5 )

Account State Difference:

  Address   Before After State Difference Code
0x533b9CDc...bf2bf16AD
10.203757376125423251 Eth
Nonce: 129
2.655948609140228443 Eth
Nonce: 130
7.547808766985194808
0x5eeEf1ED...8dc2292B5 4.132086656150523992 Eth10.991886656150523992 Eth6.8598
0x6D7c4477...68E9a7a42
(SuperRare: Bazaar)
513.27255295033107 Eth513.95853295033107 Eth0.68598
(Fee Recipient: 0xBA4...8C5)
179.310847266305901577 Eth179.311153486305901577 Eth0.00030622

Execution Trace

ETH 7.54578 SuperRareBazaar.bid( _originContract=0xb932a70A57673d89f4acfFBE830E8ed7f75Fb9e0, _tokenId=41458, _currencyAddress=0x0000000000000000000000000000000000000000, _amount=7326000000000000000 )
  • ETH 7.54578 SuperRareAuctionHouse.bid( _originContract=0xb932a70A57673d89f4acfFBE830E8ed7f75Fb9e0, _tokenId=41458, _currencyAddress=0x0000000000000000000000000000000000000000, _amount=7326000000000000000 )
    • MarketplaceSettingsV2.calculateMarketplaceFee( _amount=7326000000000000000 ) => ( 219780000000000000 )
    • MarketplaceSettingsV2.STATICCALL( )
    • SuperRareV2.ownerOf( tokenId=41458 ) => ( 0x6D7c44773C52D396F43c2D511B81aa168E9a7a42 )
    • ETH 6.8598 Payments.refund( _payee=0x5eeEf1ED716A26380860097332F7DB08dc2292B5, _amount=6859800000000000000 )
      • ETH 6.8598 0x5eeef1ed716a26380860097332f7db08dc2292b5.CALL( )
      • MarketplaceSettingsV2.STATICCALL( )
        File 1 of 5: SuperRareBazaar
        // SPDX-License-Identifier: MIT
        pragma solidity 0.7.3;
        import "@openzeppelin/contracts-upgradeable-0.7.2/access/OwnableUpgradeable.sol";
        import "@openzeppelin/contracts-upgradeable-0.7.2/utils/ReentrancyGuardUpgradeable.sol";
        import "@openzeppelin/contracts-0.7.2/token/ERC721/IERC721.sol";
        import "./storage/SuperRareBazaarStorage.sol";
        import "./ISuperRareBazaar.sol";
        /// @author koloz
        /// @title SuperRareBazaar
        /// @notice The unified contract for the bazaar logic (Marketplace and Auction House).
        /// @dev All storage is inherrited and append only (no modifications) to make upgrade compliant.
        contract SuperRareBazaar is
            ISuperRareBazaar,
            OwnableUpgradeable,
            ReentrancyGuardUpgradeable,
            SuperRareBazaarStorage
        {
            /////////////////////////////////////////////////////////////////////////
            // Initializer
            /////////////////////////////////////////////////////////////////////////
            function initialize(
                address _marketplaceSettings,
                address _royaltyRegistry,
                address _royaltyEngine,
                address _superRareMarketplace,
                address _superRareAuctionHouse,
                address _spaceOperatorRegistry,
                address _approvedTokenRegistry,
                address _payments,
                address _stakingRegistry,
                address _networkBeneficiary
            ) public initializer {
                require(_marketplaceSettings != address(0));
                require(_royaltyRegistry != address(0));
                require(_royaltyEngine != address(0));
                require(_superRareMarketplace != address(0));
                require(_superRareAuctionHouse != address(0));
                require(_spaceOperatorRegistry != address(0));
                require(_approvedTokenRegistry != address(0));
                require(_payments != address(0));
                require(_networkBeneficiary != address(0));
                marketplaceSettings = IMarketplaceSettings(_marketplaceSettings);
                royaltyRegistry = IERC721CreatorRoyalty(_royaltyRegistry);
                royaltyEngine = IRoyaltyEngineV1(_royaltyEngine);
                superRareMarketplace = _superRareMarketplace;
                superRareAuctionHouse = _superRareAuctionHouse;
                spaceOperatorRegistry = ISpaceOperatorRegistry(_spaceOperatorRegistry);
                approvedTokenRegistry = IApprovedTokenRegistry(_approvedTokenRegistry);
                payments = IPayments(_payments);
                stakingRegistry = _stakingRegistry;
                networkBeneficiary = _networkBeneficiary;
                minimumBidIncreasePercentage = 10;
                maxAuctionLength = 7 days;
                auctionLengthExtension = 15 minutes;
                offerCancelationDelay = 5 minutes;
                __Ownable_init();
                __ReentrancyGuard_init();
            }
            /////////////////////////////////////////////////////////////////////////
            // Admin Functions
            /////////////////////////////////////////////////////////////////////////
            function setMarketplaceSettings(address _marketplaceSettings)
                external
                onlyOwner
            {
                require(_marketplaceSettings != address(0));
                marketplaceSettings = IMarketplaceSettings(_marketplaceSettings);
            }
            function setRoyaltyRegistry(address _royaltyRegistry) external onlyOwner {
                require(_royaltyRegistry != address(0));
                royaltyRegistry = IERC721CreatorRoyalty(_royaltyRegistry);
            }
            function setRoyaltyEngine(address _royaltyEngine) external onlyOwner {
                require(_royaltyEngine != address(0));
                royaltyEngine = IRoyaltyEngineV1(_royaltyEngine);
            }
            function setSuperRareMarketplace(address _superRareMarketplace)
                external
                onlyOwner
            {
                require(_superRareMarketplace != address(0));
                superRareMarketplace = _superRareMarketplace;
            }
            function setSuperRareAuctionHouse(address _superRareAuctionHouse)
                external
                onlyOwner
            {
                require(_superRareAuctionHouse != address(0));
                superRareAuctionHouse = _superRareAuctionHouse;
            }
            function setSpaceOperatorRegistry(address _spaceOperatorRegistry)
                external
                onlyOwner
            {
                require(_spaceOperatorRegistry != address(0));
                spaceOperatorRegistry = ISpaceOperatorRegistry(_spaceOperatorRegistry);
            }
            function setApprovedTokenRegistry(address _approvedTokenRegistry)
                external
                onlyOwner
            {
                require(_approvedTokenRegistry != address(0));
                approvedTokenRegistry = IApprovedTokenRegistry(_approvedTokenRegistry);
            }
            function setPayments(address _payments) external onlyOwner {
                require(_payments != address(0));
                payments = IPayments(_payments);
            }
            function setStakingRegistry(address _stakingRegistry) external onlyOwner {
                require(_stakingRegistry != address(0));
                stakingRegistry = _stakingRegistry;
            }
            function setNetworkBeneficiary(address _networkBeneficiary)
                external
                onlyOwner
            {
                require(_networkBeneficiary != address(0));
                networkBeneficiary = _networkBeneficiary;
            }
            function setMinimumBidIncreasePercentage(
                uint8 _minimumBidIncreasePercentage
            ) external onlyOwner {
                minimumBidIncreasePercentage = _minimumBidIncreasePercentage;
            }
            function setMaxAuctionLength(uint8 _maxAuctionLength) external onlyOwner {
                maxAuctionLength = _maxAuctionLength;
            }
            function setAuctionLengthExtension(uint256 _auctionLengthExtension)
                external
                onlyOwner
            {
                auctionLengthExtension = _auctionLengthExtension;
            }
            function setOfferCancelationDelay(uint256 _offerCancelationDelay)
                external
                onlyOwner
            {
                offerCancelationDelay = _offerCancelationDelay;
            }
            /////////////////////////////////////////////////////////////////////////
            // Marketplace Functions
            /////////////////////////////////////////////////////////////////////////
            /// @notice Place an offer for a given asset
            /// @dev Notice we need to verify that the msg sender has approved us to move funds on their behalf.
            /// @dev Covers use of any currency (0 address is eth).
            /// @dev _amount is the amount of the offer excluding the marketplace fee.
            /// @dev There can be multiple offers of different currencies, but only 1 per currency.
            /// @param _originContract Contract address of the asset being listed.
            /// @param _tokenId Token Id of the asset.
            /// @param _currencyAddress Address of the token being offered.
            /// @param _amount Amount being offered.
            /// @param _convertible If the offer can be converted into an auction
            function offer(
                address _originContract,
                uint256 _tokenId,
                address _currencyAddress,
                uint256 _amount,
                bool _convertible
            ) external payable override {
                (bool success, bytes memory data) = superRareMarketplace.delegatecall(
                    abi.encodeWithSelector(
                        this.offer.selector,
                        _originContract,
                        _tokenId,
                        _currencyAddress,
                        _amount,
                        _convertible
                    )
                );
                require(success, string(data));
            }
            /// @notice Purchases the token for the current sale price.
            /// @dev Covers use of any currency (0 address is eth).
            /// @dev Need to verify that the buyer (if not using eth) has the marketplace approved for _currencyContract.
            /// @dev Need to verify that the seller has the marketplace approved for _originContract.
            /// @param _originContract Contract address for asset being bought.
            /// @param _tokenId TokenId of asset being bought.
            /// @param _currencyAddress Currency address of asset being used to buy.
            /// @param _amount Amount the piece if being bought for (including marketplace fee).
            function buy(
                address _originContract,
                uint256 _tokenId,
                address _currencyAddress,
                uint256 _amount
            ) external payable override {
                (bool success, bytes memory data) = superRareMarketplace.delegatecall(
                    abi.encodeWithSelector(
                        this.buy.selector,
                        _originContract,
                        _tokenId,
                        _currencyAddress,
                        _amount
                    )
                );
                require(success, string(data));
            }
            /// @notice Cancels an existing offer the sender has placed on a piece.
            /// @param _originContract Contract address of token.
            /// @param _tokenId TokenId that has an offer.
            /// @param _currencyAddress Currency address of the offer.
            function cancelOffer(
                address _originContract,
                uint256 _tokenId,
                address _currencyAddress
            ) external override {
                (bool success, bytes memory data) = superRareMarketplace.delegatecall(
                    abi.encodeWithSelector(
                        this.cancelOffer.selector,
                        _originContract,
                        _tokenId,
                        _currencyAddress
                    )
                );
                require(success, string(data));
            }
            /// @notice Sets a sale price for the given asset(s) directed at the _target address.
            /// @dev Covers use of any currency (0 address is eth).
            /// @dev Sale price for everyone is denoted as the 0 address.
            /// @dev Only 1 currency can be used for the sale price directed at a speicific target.
            /// @dev _listPrice of 0 signifies removing the list price for the provided currency.
            /// @dev This function can be used for counter offers as well.
            /// @param _originContract Contract address of the asset being listed.
            /// @param _tokenId Token Id of the asset.
            /// @param _currencyAddress Contract address of the currency asset is being listed for.
            /// @param _listPrice Amount of the currency the asset is being listed for (including all decimal points).
            /// @param _target Address of the person this sale price is target to.
            /// @param _splitAddresses Addresses to split the sellers commission with.
            /// @param _splitRatios The ratio for the split corresponding to each of the addresses being split with.
            function setSalePrice(
                address _originContract,
                uint256 _tokenId,
                address _currencyAddress,
                uint256 _listPrice,
                address _target,
                address payable[] calldata _splitAddresses,
                uint8[] calldata _splitRatios
            ) external override {
                (bool success, bytes memory data) = superRareMarketplace.delegatecall(
                    abi.encodeWithSelector(
                        this.setSalePrice.selector,
                        _originContract,
                        _tokenId,
                        _currencyAddress,
                        _listPrice,
                        _target,
                        _splitAddresses,
                        _splitRatios
                    )
                );
                require(success, string(data));
            }
            /// @notice Removes the current sale price of an asset for _target for the given currency.
            /// @dev Sale prices could still exist for different currencies.
            /// @dev Sale prices could still exist for different targets.
            /// @dev Zero address for _currency means that its listed in ether.
            /// @dev _target of zero address is the general sale price.
            /// @param _originContract The origin contract of the asset.
            /// @param _tokenId The tokenId of the asset within the _originContract.
            /// @param _target The address of the person
            function removeSalePrice(
                address _originContract,
                uint256 _tokenId,
                address _target
            ) external override {
                IERC721 erc721 = IERC721(_originContract);
                address tokenOwner = erc721.ownerOf(_tokenId);
                require(
                    msg.sender == tokenOwner,
                    "removeSalePrice::Must be tokenOwner."
                );
                delete tokenSalePrices[_originContract][_tokenId][_target];
                emit SetSalePrice(
                    _originContract,
                    address(0),
                    address(0),
                    0,
                    _tokenId,
                    new address payable[](0),
                    new uint8[](0)
                );
            }
            /// @notice Accept an offer placed on _originContract : _tokenId.
            /// @dev Zero address for _currency means that the offer being accepted is in ether.
            /// @param _originContract Contract of the asset the offer was made on.
            /// @param _tokenId TokenId of the asset.
            /// @param _currencyAddress Address of the currency used for the offer.
            /// @param _amount Amount the offer was for/and is being accepted.
            /// @param _splitAddresses Addresses to split the sellers commission with.
            /// @param _splitRatios The ratio for the split corresponding to each of the addresses being split with.
            function acceptOffer(
                address _originContract,
                uint256 _tokenId,
                address _currencyAddress,
                uint256 _amount,
                address payable[] calldata _splitAddresses,
                uint8[] calldata _splitRatios
            ) external override {
                (bool success, bytes memory data) = superRareMarketplace.delegatecall(
                    abi.encodeWithSelector(
                        this.acceptOffer.selector,
                        _originContract,
                        _tokenId,
                        _currencyAddress,
                        _amount,
                        _splitAddresses,
                        _splitRatios
                    )
                );
                require(success, string(data));
            }
            /////////////////////////////////////////////////////////////////////////
            // Auction House Functions
            /////////////////////////////////////////////////////////////////////////
            /// @notice Configures an Auction for a given asset.
            /// @dev If auction type is coldie (reserve) then _startingAmount cant be 0.
            /// @dev _currencyAddress equal to the zero address denotes eth.
            /// @dev All time related params are unix epoch timestamps.
            /// @param _auctionType The type of auction being configured.
            /// @param _originContract Contract address of the asset being put up for auction.
            /// @param _tokenId Token Id of the asset.
            /// @param _startingAmount The reserve price or min bid of an auction.
            /// @param _currencyAddress The currency the auction is being conducted in.
            /// @param _lengthOfAuction The amount of time in seconds that the auction is configured for.
            /// @param _splitAddresses Addresses to split the sellers commission with.
            /// @param _splitRatios The ratio for the split corresponding to each of the addresses being split with.
            function configureAuction(
                bytes32 _auctionType,
                address _originContract,
                uint256 _tokenId,
                uint256 _startingAmount,
                address _currencyAddress,
                uint256 _lengthOfAuction,
                uint256 _startTime,
                address payable[] calldata _splitAddresses,
                uint8[] calldata _splitRatios
            ) external override {
                (bool success, bytes memory data) = superRareAuctionHouse.delegatecall(
                    abi.encodeWithSelector(
                        this.configureAuction.selector,
                        _auctionType,
                        _originContract,
                        _tokenId,
                        _startingAmount,
                        _currencyAddress,
                        _lengthOfAuction,
                        _startTime,
                        _splitAddresses,
                        _splitRatios
                    )
                );
                require(success, string(data));
            }
            /// @notice Converts an offer into a coldie auction.
            /// @dev Covers use of any currency (0 address is eth).
            /// @dev Only covers converting an offer to a coldie auction.
            /// @dev Cant convert offer if an auction currently exists.
            /// @param _originContract Contract address of the asset.
            /// @param _tokenId Token Id of the asset.
            /// @param _currencyAddress Address of the currency being converted.
            /// @param _amount Amount being converted into an auction.
            /// @param _lengthOfAuction Number of seconds the auction will last.
            /// @param _splitAddresses Addresses that the sellers take in will be split amongst.
            /// @param _splitRatios Ratios that the take in will be split by.
            function convertOfferToAuction(
                address _originContract,
                uint256 _tokenId,
                address _currencyAddress,
                uint256 _amount,
                uint256 _lengthOfAuction,
                address payable[] calldata _splitAddresses,
                uint8[] calldata _splitRatios
            ) external override {
                (bool success, bytes memory data) = superRareAuctionHouse.delegatecall(
                    abi.encodeWithSelector(
                        this.convertOfferToAuction.selector,
                        _originContract,
                        _tokenId,
                        _currencyAddress,
                        _amount,
                        _lengthOfAuction,
                        _splitAddresses,
                        _splitRatios
                    )
                );
                require(success, string(data));
            }
            /// @notice Cancels a configured Auction that has not started.
            /// @dev Requires the person sending the message to be the auction creator or token owner.
            /// @param _originContract Contract address of the asset pending auction.
            /// @param _tokenId Token Id of the asset.
            function cancelAuction(address _originContract, uint256 _tokenId)
                external
                override
            {
                (bool success, bytes memory data) = superRareAuctionHouse.delegatecall(
                    abi.encodeWithSelector(
                        this.cancelAuction.selector,
                        _originContract,
                        _tokenId
                    )
                );
                require(success, string(data));
            }
            /// @notice Places a bid on a valid auction.
            /// @dev Only the configured currency can be used (Zero address for eth)
            /// @param _originContract Contract address of asset being bid on.
            /// @param _tokenId Token Id of the asset.
            /// @param _currencyAddress Address of currency being used to bid.
            /// @param _amount Amount of the currency being used for the bid.
            function bid(
                address _originContract,
                uint256 _tokenId,
                address _currencyAddress,
                uint256 _amount
            ) external payable override {
                (bool success, bytes memory data) = superRareAuctionHouse.delegatecall(
                    abi.encodeWithSelector(
                        this.bid.selector,
                        _originContract,
                        _tokenId,
                        _currencyAddress,
                        _amount
                    )
                );
                require(success, string(data));
            }
            /// @notice Settles an auction that has ended.
            /// @dev Anyone is able to settle an auction since non-input params are used.
            /// @param _originContract Contract address of asset.
            /// @param _tokenId Token Id of the asset.
            function settleAuction(address _originContract, uint256 _tokenId)
                external
                override
            {
                (bool success, bytes memory data) = superRareAuctionHouse.delegatecall(
                    abi.encodeWithSelector(
                        this.settleAuction.selector,
                        _originContract,
                        _tokenId
                    )
                );
                require(success, string(data));
            }
            /// @notice Grabs the current auction details for a token.
            /// @param _originContract Contract address of asset.
            /// @param _tokenId Token Id of the asset.
            /** @return Auction Struct: creatorAddress, creationTime, startingTime, lengthOfAuction,
                        currencyAddress, minimumBid, auctionType, splitRecipients array, and splitRatios array.
            */
            function getAuctionDetails(address _originContract, uint256 _tokenId)
                external
                view
                override
                returns (
                    address,
                    uint256,
                    uint256,
                    uint256,
                    address,
                    uint256,
                    bytes32,
                    address payable[] memory,
                    uint8[] memory
                )
            {
                Auction memory auction = tokenAuctions[_originContract][_tokenId];
                return (
                    auction.auctionCreator,
                    auction.creationBlock,
                    auction.startingTime,
                    auction.lengthOfAuction,
                    auction.currencyAddress,
                    auction.minimumBid,
                    auction.auctionType,
                    auction.splitRecipients,
                    auction.splitRatios
                );
            }
            function getSalePrice(
                address _originContract,
                uint256 _tokenId,
                address _target
            )
                external
                view
                override
                returns (
                    address,
                    address,
                    uint256,
                    address payable[] memory,
                    uint8[] memory
                )
            {
                SalePrice memory sp = tokenSalePrices[_originContract][_tokenId][
                    _target
                ];
                return (
                    sp.seller,
                    sp.currencyAddress,
                    sp.amount,
                    sp.splitRecipients,
                    sp.splitRatios
                );
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.7.0;
        import "../utils/ContextUpgradeable.sol";
        import "../proxy/Initializable.sol";
        /**
         * @dev Contract module which provides a basic access control mechanism, where
         * there is an account (an owner) that can be granted exclusive access to
         * specific functions.
         *
         * By default, the owner account will be the one that deploys the contract. This
         * can later be changed with {transferOwnership}.
         *
         * This module is used through inheritance. It will make available the modifier
         * `onlyOwner`, which can be applied to your functions to restrict their use to
         * the owner.
         */
        abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
            address private _owner;
            event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
            /**
             * @dev Initializes the contract setting the deployer as the initial owner.
             */
            function __Ownable_init() internal initializer {
                __Context_init_unchained();
                __Ownable_init_unchained();
            }
            function __Ownable_init_unchained() internal initializer {
                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;
            }
            uint256[49] private __gap;
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.7.0;
        import "../proxy/Initializable.sol";
        /**
         * @dev Contract module that helps prevent reentrant calls to a function.
         *
         * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
         * available, which can be applied to functions to make sure there are no nested
         * (reentrant) calls to them.
         *
         * Note that because there is a single `nonReentrant` guard, functions marked as
         * `nonReentrant` may not call one another. This can be worked around by making
         * those functions `private`, and then adding `external` `nonReentrant` entry
         * points to them.
         *
         * TIP: If you would like to learn more about reentrancy and alternative ways
         * to protect against it, check out our blog post
         * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
         */
        abstract contract ReentrancyGuardUpgradeable is Initializable {
            // Booleans are more expensive than uint256 or any type that takes up a full
            // word because each write operation emits an extra SLOAD to first read the
            // slot's contents, replace the bits taken up by the boolean, and then write
            // back. This is the compiler's defense against contract upgrades and
            // pointer aliasing, and it cannot be disabled.
            // The values being non-zero value makes deployment a bit more expensive,
            // but in exchange the refund on every call to nonReentrant will be lower in
            // amount. Since refunds are capped to a percentage of the total
            // transaction's gas, it is best to keep them low in cases like this one, to
            // increase the likelihood of the full refund coming into effect.
            uint256 private constant _NOT_ENTERED = 1;
            uint256 private constant _ENTERED = 2;
            uint256 private _status;
            function __ReentrancyGuard_init() internal initializer {
                __ReentrancyGuard_init_unchained();
            }
            function __ReentrancyGuard_init_unchained() internal initializer {
                _status = _NOT_ENTERED;
            }
            /**
             * @dev Prevents a contract from calling itself, directly or indirectly.
             * Calling a `nonReentrant` function from another `nonReentrant`
             * function is not supported. It is possible to prevent this from happening
             * by making the `nonReentrant` function external, and make it call a
             * `private` function that does the actual work.
             */
            modifier nonReentrant() {
                // On the first call to nonReentrant, _notEntered will be true
                require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
                // Any calls to nonReentrant after this point will fail
                _status = _ENTERED;
                _;
                // By storing the original value once again, a refund is triggered (see
                // https://eips.ethereum.org/EIPS/eip-2200)
                _status = _NOT_ENTERED;
            }
            uint256[49] private __gap;
        }
        // SPDX-License-Identifier: MIT
        pragma solidity >=0.6.2 <0.8.0;
        import "../../introspection/IERC165.sol";
        /**
         * @dev Required interface of an ERC721 compliant contract.
         */
        interface IERC721 is IERC165 {
            /**
             * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
             */
            event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
            /**
             * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
             */
            event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
            /**
             * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
             */
            event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
            /**
             * @dev Returns the number of tokens in ``owner``'s account.
             */
            function balanceOf(address owner) external view returns (uint256 balance);
            /**
             * @dev Returns the owner of the `tokenId` token.
             *
             * Requirements:
             *
             * - `tokenId` must exist.
             */
            function ownerOf(uint256 tokenId) external view returns (address owner);
            /**
             * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
             * are aware of the ERC721 protocol to prevent tokens from being forever locked.
             *
             * Requirements:
             *
             * - `from` cannot be the zero address.
             * - `to` cannot be the zero address.
             * - `tokenId` token must exist and be owned by `from`.
             * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
             * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
             *
             * Emits a {Transfer} event.
             */
            function safeTransferFrom(address from, address to, uint256 tokenId) external;
            /**
             * @dev Transfers `tokenId` token from `from` to `to`.
             *
             * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
             *
             * Requirements:
             *
             * - `from` cannot be the zero address.
             * - `to` cannot be the zero address.
             * - `tokenId` token must be owned by `from`.
             * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
             *
             * Emits a {Transfer} event.
             */
            function transferFrom(address from, address to, uint256 tokenId) external;
            /**
             * @dev Gives permission to `to` to transfer `tokenId` token to another account.
             * The approval is cleared when the token is transferred.
             *
             * Only a single account can be approved at a time, so approving the zero address clears previous approvals.
             *
             * Requirements:
             *
             * - The caller must own the token or be an approved operator.
             * - `tokenId` must exist.
             *
             * Emits an {Approval} event.
             */
            function approve(address to, uint256 tokenId) external;
            /**
             * @dev Returns the account approved for `tokenId` token.
             *
             * Requirements:
             *
             * - `tokenId` must exist.
             */
            function getApproved(uint256 tokenId) external view returns (address operator);
            /**
             * @dev Approve or remove `operator` as an operator for the caller.
             * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
             *
             * Requirements:
             *
             * - The `operator` cannot be the caller.
             *
             * Emits an {ApprovalForAll} event.
             */
            function setApprovalForAll(address operator, bool _approved) external;
            /**
             * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
             *
             * See {setApprovalForAll}
             */
            function isApprovedForAll(address owner, address operator) external view returns (bool);
            /**
              * @dev Safely transfers `tokenId` token from `from` to `to`.
              *
              * Requirements:
              *
              * - `from` cannot be the zero address.
              * - `to` cannot be the zero address.
              * - `tokenId` token must exist and be owned by `from`.
              * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
              * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
              *
              * Emits a {Transfer} event.
              */
            function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
        }
        // SPDX-License-Identifier: MIT
        pragma solidity 0.7.3;
        import "../../marketplace/IMarketplaceSettings.sol";
        import "../../royalty/creator/IERC721CreatorRoyalty.sol";
        import "../../payments/IPayments.sol";
        import "../../registry/spaces/ISpaceOperatorRegistry.sol";
        import "../../registry/token/IApprovedTokenRegistry.sol";
        import "../../royalty/creator/IRoyaltyEngine.sol";
        /// @author koloz
        /// @title SuperRareBazaar Storage Contract
        /// @dev STORAGE CAN ONLY BE APPENDED NOT INSERTED OR MODIFIED
        contract SuperRareBazaarStorage {
            /////////////////////////////////////////////////////////////////////////
            // Constants
            /////////////////////////////////////////////////////////////////////////
            // Auction Types
            bytes32 public constant COLDIE_AUCTION = "COLDIE_AUCTION";
            bytes32 public constant SCHEDULED_AUCTION = "SCHEDULED_AUCTION";
            bytes32 public constant NO_AUCTION = bytes32(0);
            /////////////////////////////////////////////////////////////////////////
            // Structs
            /////////////////////////////////////////////////////////////////////////
            // The Offer truct for a given token:
            // buyer - address of person making the offer
            // currencyAddress - address of the erc20 token used for an offer
            //                   or the zero address for eth
            // amount - offer in wei/full erc20 value
            // marketplaceFee - the amount that is taken by the network on offer acceptance.
            struct Offer {
                address payable buyer;
                uint256 amount;
                uint256 timestamp;
                uint8 marketplaceFee;
                bool convertible;
            }
            // The Sale Price struct for a given token:
            // seller - address of the person selling the token
            // currencyAddress - address of the erc20 token used for an offer
            //                   or the zero address for eth
            // amount - offer in wei/full erc20 value
            struct SalePrice {
                address payable seller;
                address currencyAddress;
                uint256 amount;
                address payable[] splitRecipients;
                uint8[] splitRatios;
            }
            // Structure of an Auction:
            // auctionCreator - creator of the auction
            // creationBlock - time that the auction was created/configured
            // startingBlock - time that the auction starts on
            // lengthOfAuction - how long the auction is
            // currencyAddress - address of the erc20 token used for an offer
            //                   or the zero address for eth
            // minimumBid - min amount a bidder can bid at the start of an auction.
            // auctionType - type of auction, represented as the formatted bytes 32 string
            struct Auction {
                address payable auctionCreator;
                uint256 creationBlock;
                uint256 startingTime;
                uint256 lengthOfAuction;
                address currencyAddress;
                uint256 minimumBid;
                bytes32 auctionType;
                address payable[] splitRecipients;
                uint8[] splitRatios;
            }
            struct Bid {
                address payable bidder;
                address currencyAddress;
                uint256 amount;
                uint8 marketplaceFee;
            }
            /////////////////////////////////////////////////////////////////////////
            // Events
            /////////////////////////////////////////////////////////////////////////
            event Sold(
                address indexed _originContract,
                address indexed _buyer,
                address indexed _seller,
                address _currencyAddress,
                uint256 _amount,
                uint256 _tokenId
            );
            event SetSalePrice(
                address indexed _originContract,
                address indexed _currencyAddress,
                address _target,
                uint256 _amount,
                uint256 _tokenId,
                address payable[] _splitRecipients,
                uint8[] _splitRatios
            );
            event OfferPlaced(
                address indexed _originContract,
                address indexed _bidder,
                address indexed _currencyAddress,
                uint256 _amount,
                uint256 _tokenId,
                bool _convertible
            );
            event AcceptOffer(
                address indexed _originContract,
                address indexed _bidder,
                address indexed _seller,
                address _currencyAddress,
                uint256 _amount,
                uint256 _tokenId,
                address payable[] _splitAddresses,
                uint8[] _splitRatios
            );
            event CancelOffer(
                address indexed _originContract,
                address indexed _bidder,
                address indexed _currencyAddress,
                uint256 _amount,
                uint256 _tokenId
            );
            event NewAuction(
                address indexed _contractAddress,
                uint256 indexed _tokenId,
                address indexed _auctionCreator,
                address _currencyAddress,
                uint256 _startingTime,
                uint256 _minimumBid,
                uint256 _lengthOfAuction
            );
            event CancelAuction(
                address indexed _contractAddress,
                uint256 indexed _tokenId,
                address indexed _auctionCreator
            );
            event AuctionBid(
                address indexed _contractAddress,
                address indexed _bidder,
                uint256 indexed _tokenId,
                address _currencyAddress,
                uint256 _amount,
                bool _startedAuction,
                uint256 _newAuctionLength,
                address _previousBidder
            );
            event AuctionSettled(
                address indexed _contractAddress,
                address indexed _bidder,
                address _seller,
                uint256 indexed _tokenId,
                address _currencyAddress,
                uint256 _amount
            );
            /////////////////////////////////////////////////////////////////////////
            // State Variables
            /////////////////////////////////////////////////////////////////////////
            // Current marketplace settings implementation to be used
            IMarketplaceSettings public marketplaceSettings;
            // Current creator royalty implementation to be used
            IERC721CreatorRoyalty public royaltyRegistry;
            // Address of the global royalty engine being used.
            IRoyaltyEngineV1 public royaltyEngine;
            // Current SuperRareMarketplace implementation to be used
            address public superRareMarketplace;
            // Current SuperRareAuctionHouse implementation to be used
            address public superRareAuctionHouse;
            // Current SpaceOperatorRegistry implementation to be used.
            ISpaceOperatorRegistry public spaceOperatorRegistry;
            // Current ApprovedTokenRegistry implementation being used for currencies.
            IApprovedTokenRegistry public approvedTokenRegistry;
            // Current payments contract to use
            IPayments public payments;
            // Address to be used for staking registry.
            address public stakingRegistry;
            // Address of the network beneficiary
            address public networkBeneficiary;
            // A minimum increase in bid amount when out bidding someone.
            uint8 public minimumBidIncreasePercentage; // 10 = 10%
            // Maximum length that an auction can be.
            uint256 public maxAuctionLength;
            // Extension length for an auction
            uint256 public auctionLengthExtension;
            // Offer cancellation delay
            uint256 public offerCancelationDelay;
            // Mapping from contract to mapping of tokenId to mapping of target to sale price.
            mapping(address => mapping(uint256 => mapping(address => SalePrice)))
                public tokenSalePrices;
            // Mapping from contract to mapping of tokenId to mapping of currency address to Current Offer.
            mapping(address => mapping(uint256 => mapping(address => Offer)))
                public tokenCurrentOffers;
            // Mapping from contract to mapping of tokenId to Auction.
            mapping(address => mapping(uint256 => Auction)) public tokenAuctions;
            // Mapping from contract to mapping of tokenId to Bid.
            mapping(address => mapping(uint256 => Bid)) public auctionBids;
            uint256[50] private __gap;
            /// ALL NEW STORAGE MUST COME AFTER THIS
        }
        // SPDX-License-Identifier: MIT
        pragma solidity 0.7.3;
        /// @author koloz
        /// @title ISuperRareBazaar
        /// @notice Interface for the SuperRareBazaar Contract
        interface ISuperRareBazaar {
            // Marketplace Functions
            // Buyer
            /// @notice Create an offer for a given asset
            /// @param _originContract Contract address of the asset being listed.
            /// @param _tokenId Token Id of the asset.
            /// @param _currencyAddress Address of the token being offered.
            /// @param _amount Amount being offered.
            /// @param _convertible If the offer can be converted into an auction
            function offer(
                address _originContract,
                uint256 _tokenId,
                address _currencyAddress,
                uint256 _amount,
                bool _convertible
            ) external payable;
            /// @notice Purchases the token for the current sale price.
            /// @param _originContract Contract address for asset being bought.
            /// @param _tokenId TokenId of asset being bought.
            /// @param _currencyAddress Currency address of asset being used to buy.
            /// @param _amount Amount the piece if being bought for.
            function buy(
                address _originContract,
                uint256 _tokenId,
                address _currencyAddress,
                uint256 _amount
            ) external payable;
            /// @notice Cancels an existing offer the sender has placed on a piece.
            /// @param _originContract Contract address of token.
            /// @param _tokenId TokenId that has an offer.
            /// @param _currencyAddress Currency address of the offer.
            function cancelOffer(
                address _originContract,
                uint256 _tokenId,
                address _currencyAddress
            ) external;
            // Seller
            /// @notice Sets a sale price for the given asset(s).
            /// @param _originContract Contract address of the asset being listed.
            /// @param _tokenId Token Id of the asset.
            /// @param _currencyAddress Contract address of the currency asset is being listed for.
            /// @param _listPrice Amount of the currency the asset is being listed for (including all decimal points).
            /// @param _target Address of the person this sale price is target to.
            /// @param _splitAddresses Addresses to split the sellers commission with.
            /// @param _splitRatios The ratio for the split corresponding to each of the addresses being split with.
            function setSalePrice(
                address _originContract,
                uint256 _tokenId,
                address _currencyAddress,
                uint256 _listPrice,
                address _target,
                address payable[] calldata _splitAddresses,
                uint8[] calldata _splitRatios
            ) external;
            /// @notice Removes the current sale price of an asset for the given currency.
            /// @param _originContract The origin contract of the asset.
            /// @param _tokenId The tokenId of the asset within the _originContract.
            /// @param _target The address of the person
            function removeSalePrice(
                address _originContract,
                uint256 _tokenId,
                address _target
            ) external;
            /// @notice Accept an offer placed on _originContract : _tokenId.
            /// @param _originContract Contract of the asset the offer was made on.
            /// @param _tokenId TokenId of the asset.
            /// @param _currencyAddress Address of the currency used for the offer.
            /// @param _amount Amount the offer was for/and is being accepted.
            /// @param _splitAddresses Addresses to split the sellers commission with.
            /// @param _splitRatios The ratio for the split corresponding to each of the addresses being split with.
            function acceptOffer(
                address _originContract,
                uint256 _tokenId,
                address _currencyAddress,
                uint256 _amount,
                address payable[] calldata _splitAddresses,
                uint8[] calldata _splitRatios
            ) external;
            // Auction House
            // Anyone
            /// @notice Settles an auction that has ended.
            /// @param _originContract Contract address of asset.
            /// @param _tokenId Token Id of the asset.
            function settleAuction(address _originContract, uint256 _tokenId) external;
            // Buyer
            /// @notice Places a bid on a valid auction.
            /// @param _originContract Contract address of asset being bid on.
            /// @param _tokenId Token Id of the asset.
            /// @param _currencyAddress Address of currency being used to bid.
            /// @param _amount Amount of the currency being used for the bid.
            function bid(
                address _originContract,
                uint256 _tokenId,
                address _currencyAddress,
                uint256 _amount
            ) external payable;
            // Seller
            /// @notice Configures an Auction for a given asset.
            /// @param _auctionType The type of auction being configured.
            /// @param _originContract Contract address of the asset being put up for auction.
            /// @param _tokenId Token Id of the asset.
            /// @param _startingAmount The reserve price or min bid of an auction.
            /// @param _currencyAddress The currency the auction is being conducted in.
            /// @param _lengthOfAuction The amount of time in seconds that the auction is configured for.
            /// @param _splitAddresses Addresses to split the sellers commission with.
            /// @param _splitRatios The ratio for the split corresponding to each of the addresses being split with.
            function configureAuction(
                bytes32 _auctionType,
                address _originContract,
                uint256 _tokenId,
                uint256 _startingAmount,
                address _currencyAddress,
                uint256 _lengthOfAuction,
                uint256 _startTime,
                address payable[] calldata _splitAddresses,
                uint8[] calldata _splitRatios
            ) external;
            /// @notice Cancels a configured Auction that has not started.
            /// @param _originContract Contract address of the asset pending auction.
            /// @param _tokenId Token Id of the asset.
            function cancelAuction(address _originContract, uint256 _tokenId) external;
            /// @notice Converts an offer into a coldie auction.
            /// @param _originContract Contract address of the asset.
            /// @param _tokenId Token Id of the asset.
            /// @param _currencyAddress Address of the currency being converted.
            /// @param _amount Amount being converted into an auction.
            /// @param _lengthOfAuction Number of seconds the auction will last.
            /// @param _splitAddresses Addresses that the sellers take in will be split amongst.
            /// @param _splitRatios Ratios that the take in will be split by.
            function convertOfferToAuction(
                address _originContract,
                uint256 _tokenId,
                address _currencyAddress,
                uint256 _amount,
                uint256 _lengthOfAuction,
                address payable[] calldata _splitAddresses,
                uint8[] calldata _splitRatios
            ) external;
            /// @notice Grabs the current auction details for a token.
            /// @param _originContract Contract address of asset.
            /// @param _tokenId Token Id of the asset.
            /** @return Auction Struct: creatorAddress, creationTime, startingTime, lengthOfAuction,
                        currencyAddress, minimumBid, auctionType, splitRecipients array, and splitRatios array.
            */
            function getAuctionDetails(address _originContract, uint256 _tokenId)
                external
                view
                returns (
                    address,
                    uint256,
                    uint256,
                    uint256,
                    address,
                    uint256,
                    bytes32,
                    address payable[] calldata,
                    uint8[] calldata
                );
            function getSalePrice(
                address _originContract,
                uint256 _tokenId,
                address _target
            )
                external
                view
                returns (
                    address,
                    address,
                    uint256,
                    address payable[] memory,
                    uint8[] memory
                );
        }
        // SPDX-License-Identifier: MIT
        pragma solidity >=0.6.0 <0.8.0;
        import "../proxy/Initializable.sol";
        /*
         * @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 GSN 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 ContextUpgradeable is Initializable {
            function __Context_init() internal initializer {
                __Context_init_unchained();
            }
            function __Context_init_unchained() internal initializer {
            }
            function _msgSender() internal view virtual returns (address payable) {
                return msg.sender;
            }
            function _msgData() internal view virtual returns (bytes memory) {
                this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
                return msg.data;
            }
            uint256[50] private __gap;
        }
        // SPDX-License-Identifier: MIT
        // solhint-disable-next-line compiler-version
        pragma solidity >=0.4.24 <0.8.0;
        import "../utils/AddressUpgradeable.sol";
        /**
         * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
         * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an
         * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
         * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
         *
         * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
         * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}.
         *
         * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
         * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
         */
        abstract contract Initializable {
            /**
             * @dev Indicates that the contract has been initialized.
             */
            bool private _initialized;
            /**
             * @dev Indicates that the contract is in the process of being initialized.
             */
            bool private _initializing;
            /**
             * @dev Modifier to protect an initializer function from being invoked twice.
             */
            modifier initializer() {
                require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized");
                bool isTopLevelCall = !_initializing;
                if (isTopLevelCall) {
                    _initializing = true;
                    _initialized = true;
                }
                _;
                if (isTopLevelCall) {
                    _initializing = false;
                }
            }
            /// @dev Returns true if and only if the function is running in the constructor
            function _isConstructor() private view returns (bool) {
                return !AddressUpgradeable.isContract(address(this));
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.7.0;
        /**
         * @dev Collection of functions related to the address type
         */
        library AddressUpgradeable {
            /**
             * @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);
            }
            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.6.0 <0.8.0;
        /**
         * @dev Interface of the ERC165 standard, as defined in the
         * https://eips.ethereum.org/EIPS/eip-165[EIP].
         *
         * 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
             * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
             * 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);
        }
        // SPDX-License-Identifier: MIT
        pragma solidity 0.7.3;
        /**
         * @title IMarketplaceSettings Settings governing a marketplace.
         */
        interface IMarketplaceSettings {
            /////////////////////////////////////////////////////////////////////////
            // Marketplace Min and Max Values
            /////////////////////////////////////////////////////////////////////////
            /**
             * @dev Get the max value to be used with the marketplace.
             * @return uint256 wei value.
             */
            function getMarketplaceMaxValue() external view returns (uint256);
            /**
             * @dev Get the max value to be used with the marketplace.
             * @return uint256 wei value.
             */
            function getMarketplaceMinValue() external view returns (uint256);
            /////////////////////////////////////////////////////////////////////////
            // Marketplace Fee
            /////////////////////////////////////////////////////////////////////////
            /**
             * @dev Get the marketplace fee percentage.
             * @return uint8 wei fee.
             */
            function getMarketplaceFeePercentage() external view returns (uint8);
            /**
             * @dev Utility function for calculating the marketplace fee for given amount of wei.
             * @param _amount uint256 wei amount.
             * @return uint256 wei fee.
             */
            function calculateMarketplaceFee(uint256 _amount)
                external
                view
                returns (uint256);
            /////////////////////////////////////////////////////////////////////////
            // Primary Sale Fee
            /////////////////////////////////////////////////////////////////////////
            /**
             * @dev Get the primary sale fee percentage for a specific ERC721 contract.
             * @param _contractAddress address ERC721Contract address.
             * @return uint8 wei primary sale fee.
             */
            function getERC721ContractPrimarySaleFeePercentage(address _contractAddress)
                external
                view
                returns (uint8);
            /**
             * @dev Utility function for calculating the primary sale fee for given amount of wei
             * @param _contractAddress address ERC721Contract address.
             * @param _amount uint256 wei amount.
             * @return uint256 wei fee.
             */
            function calculatePrimarySaleFee(address _contractAddress, uint256 _amount)
                external
                view
                returns (uint256);
            /**
             * @dev Check whether the ERC721 token has sold at least once.
             * @param _contractAddress address ERC721Contract address.
             * @param _tokenId uint256 token ID.
             * @return bool of whether the token has sold.
             */
            function hasERC721TokenSold(address _contractAddress, uint256 _tokenId)
                external
                view
                returns (bool);
            /**
             * @dev Mark a token as sold.
             * Requirements:
             *
             * - `_contractAddress` cannot be the zero address.
             * @param _contractAddress address ERC721Contract address.
             * @param _tokenId uint256 token ID.
             * @param _hasSold bool of whether the token should be marked sold or not.
             */
            function markERC721Token(
                address _contractAddress,
                uint256 _tokenId,
                bool _hasSold
            ) external;
            function setERC721ContractPrimarySaleFeePercentage(
                address _contractAddress,
                uint8 _percentage
            ) external;
        }
        // SPDX-License-Identifier: MIT
        pragma solidity 0.7.3;
        import "../../token/ERC721/IERC721TokenCreator.sol";
        /**
         * @title IERC721CreatorRoyalty Token level royalty interface.
         */
        interface IERC721CreatorRoyalty is IERC721TokenCreator {
            /**
             * @dev Get the royalty fee percentage for a specific ERC721 contract.
             * @param _contractAddress address ERC721Contract address.
             * @param _tokenId uint256 token ID.
             * @return uint8 wei royalty fee.
             */
            function getERC721TokenRoyaltyPercentage(
                address _contractAddress,
                uint256 _tokenId
            ) external view returns (uint8);
            /**
             * @dev Utililty function to calculate the royalty fee for a token.
             * @param _contractAddress address ERC721Contract address.
             * @param _tokenId uint256 token ID.
             * @param _amount uint256 wei amount.
             * @return uint256 wei fee.
             */
            function calculateRoyaltyFee(
                address _contractAddress,
                uint256 _tokenId,
                uint256 _amount
            ) external view returns (uint256);
            /**
             * @dev Utililty function to set the royalty percentage for a specific ERC721 contract.
             * @param _contractAddress address ERC721Contract address.
             * @param _percentage percentage for royalty
             */
            function setPercentageForSetERC721ContractRoyalty(
                address _contractAddress,
                uint8 _percentage
            ) external;
        }
        // SPDX-License-Identifier: MIT
        pragma solidity 0.7.3;
        /// @author koloz
        /// @title IPayments
        /// @notice Interface for the Payments contract used.
        interface IPayments {
            function refund(address _payee, uint256 _amount) external payable;
            function payout(address[] calldata _splits, uint256[] calldata _amounts)
                external
                payable;
        }
        // SPDX-License-Identifier: MIT
        pragma solidity 0.7.3;
        /// @author koloz
        /// @title ISpaceOperatorRegistry
        /// @notice The interface for the SpaceOperatorRegistry
        interface ISpaceOperatorRegistry {
            function getPlatformCommission(address _operator)
                external
                view
                returns (uint8);
            function setPlatformCommission(address _operator, uint8 _commission)
                external;
            function isApprovedSpaceOperator(address _operator)
                external
                view
                returns (bool);
            function setSpaceOperatorApproved(address _operator, bool _approved)
                external;
        }
        // SPDX-License-Identifier: MIT
        pragma solidity 0.7.3;
        interface IApprovedTokenRegistry {
            /// @notice Returns if a token has been approved or not.
            /// @param _tokenContract Contract of token being checked.
            /// @return True if the token is allowed, false otherwise.
            function isApprovedToken(address _tokenContract)
                external
                view
                returns (bool);
            /// @notice Adds a token to the list of approved tokens.
            /// @param _tokenContract Contract of token being approved.
            function addApprovedToken(address _tokenContract) external;
            /// @notice Removes a token from the approved tokens list.
            /// @param _tokenContract Contract of token being approved.
            function removeApprovedToken(address _tokenContract) external;
            /// @notice Sets whether all token contracts should be approved.
            /// @param _allTokensApproved Bool denoting if all tokens should be approved.
            function setAllTokensApproved(bool _allTokensApproved) external;
        }
        // SPDX-License-Identifier: MIT
        pragma solidity 0.7.3;
        /// @author: manifold.xyz
        /**
         * @dev Lookup engine interface
         */
        interface IRoyaltyEngineV1 {
            /**
             * Get the royalty for a given token (address, id) and value amount.  Does not cache the bps/amounts.  Caches the spec for a given token address
             *
             * @param tokenAddress - The address of the token
             * @param tokenId      - The id of the token
             * @param value        - The value you wish to get the royalty of
             *
             * returns Two arrays of equal length, royalty recipients and the corresponding amount each recipient should get
             */
            function getRoyalty(
                address tokenAddress,
                uint256 tokenId,
                uint256 value
            )
                external
                returns (address payable[] memory recipients, uint256[] memory amounts);
            /**
             * View only version of getRoyalty
             *
             * @param tokenAddress - The address of the token
             * @param tokenId      - The id of the token
             * @param value        - The value you wish to get the royalty of
             *
             * returns Two arrays of equal length, royalty recipients and the corresponding amount each recipient should get
             */
            function getRoyaltyView(
                address tokenAddress,
                uint256 tokenId,
                uint256 value
            )
                external
                view
                returns (address payable[] memory recipients, uint256[] memory amounts);
        }
        // SPDX-License-Identifier: MIT
        pragma solidity 0.7.3;
        interface IERC721TokenCreator {
            function tokenCreator(address _contractAddress, uint256 _tokenId)
                external
                view
                returns (address payable);
        }
        

        File 2 of 5: SuperRareAuctionHouse
        // SPDX-License-Identifier: MIT
        pragma solidity 0.7.3;
        import "@openzeppelin/contracts-upgradeable-0.7.2/access/OwnableUpgradeable.sol";
        import "@openzeppelin/contracts-upgradeable-0.7.2/utils/ReentrancyGuardUpgradeable.sol";
        import "./ISuperRareAuctionHouse.sol";
        import "../SuperRareBazaarBase.sol";
        /// @author koloz
        /// @title SuperRareAuctionHouse
        /// @notice The logic for all functions related to the SuperRareAuctionHouse.
        contract SuperRareAuctionHouse is
            ISuperRareAuctionHouse,
            OwnableUpgradeable,
            ReentrancyGuardUpgradeable,
            SuperRareBazaarBase
        {
            using SafeMath for uint256;
            using SafeERC20 for IERC20;
            /////////////////////////////////////////////////////////////////////////
            // Initializer
            /////////////////////////////////////////////////////////////////////////
            function initialize(
                address _marketplaceSettings,
                address _royaltyRegistry,
                address _royaltyEngine,
                address _spaceOperatorRegistry,
                address _approvedTokenRegistry,
                address _payments,
                address _stakingRegistry,
                address _networkBeneficiary
            ) public initializer {
                require(_marketplaceSettings != address(0));
                require(_royaltyRegistry != address(0));
                require(_royaltyEngine != address(0));
                require(_spaceOperatorRegistry != address(0));
                require(_approvedTokenRegistry != address(0));
                require(_payments != address(0));
                require(_networkBeneficiary != address(0));
                marketplaceSettings = IMarketplaceSettings(_marketplaceSettings);
                royaltyRegistry = IERC721CreatorRoyalty(_royaltyRegistry);
                royaltyEngine = IRoyaltyEngineV1(_royaltyEngine);
                spaceOperatorRegistry = ISpaceOperatorRegistry(_spaceOperatorRegistry);
                approvedTokenRegistry = IApprovedTokenRegistry(_approvedTokenRegistry);
                payments = IPayments(_payments);
                stakingRegistry = _stakingRegistry;
                networkBeneficiary = _networkBeneficiary;
                minimumBidIncreasePercentage = 10;
                maxAuctionLength = 7 days;
                auctionLengthExtension = 15 minutes;
                offerCancelationDelay = 5 minutes;
                __Ownable_init();
                __ReentrancyGuard_init();
            }
            /// @notice Configures an Auction for a given asset.
            /// @dev If auction type is coldie (reserve) then _startingAmount cant be 0.
            /// @dev _currencyAddress equal to the zero address denotes eth.
            /// @dev All time related params are unix epoch timestamps.
            /// @param _auctionType The type of auction being configured.
            /// @param _originContract Contract address of the asset being put up for auction.
            /// @param _tokenId Token Id of the asset.
            /// @param _startingAmount The reserve price or min bid of an auction.
            /// @param _currencyAddress The currency the auction is being conducted in.
            /// @param _lengthOfAuction The amount of time in seconds that the auction is configured for.
            /// @param _splitAddresses Addresses to split the sellers commission with.
            /// @param _splitRatios The ratio for the split corresponding to each of the addresses being split with.
            function configureAuction(
                bytes32 _auctionType,
                address _originContract,
                uint256 _tokenId,
                uint256 _startingAmount,
                address _currencyAddress,
                uint256 _lengthOfAuction,
                uint256 _startTime,
                address payable[] calldata _splitAddresses,
                uint8[] calldata _splitRatios
            ) external override {
                _checkIfCurrencyIsApproved(_currencyAddress);
                _senderMustBeTokenOwner(_originContract, _tokenId);
                _ownerMustHaveMarketplaceApprovedForNFT(_originContract, _tokenId);
                _checkSplits(_splitAddresses, _splitRatios);
                _checkValidAuctionType(_auctionType);
                require(
                    _lengthOfAuction <= maxAuctionLength,
                    "configureAuction::Auction too long."
                );
                Auction memory auction = tokenAuctions[_originContract][_tokenId];
                require(
                    auction.auctionType == NO_AUCTION ||
                        auction.auctionCreator != msg.sender,
                    "configureAuction::Cannot have a current auction."
                );
                require(_lengthOfAuction > 0, "configureAuction::Length must be > 0");
                if (_auctionType == COLDIE_AUCTION) {
                    require(
                        _startingAmount > 0,
                        "configureAuction::Coldie starting price must be > 0"
                    );
                } else if (_auctionType == SCHEDULED_AUCTION) {
                    require(
                        _startTime > block.timestamp,
                        "configureAuction::Scheduled auction cannot start in past."
                    );
                }
                require(
                    _startingAmount <= marketplaceSettings.getMarketplaceMaxValue(),
                    "configureAuction::Cannot set starting price higher than max value."
                );
                tokenAuctions[_originContract][_tokenId] = Auction(
                    msg.sender,
                    block.number,
                    _auctionType == COLDIE_AUCTION ? 0 : _startTime,
                    _lengthOfAuction,
                    _currencyAddress,
                    _startingAmount,
                    _auctionType,
                    _splitAddresses,
                    _splitRatios
                );
                if (_auctionType == SCHEDULED_AUCTION) {
                    IERC721 erc721 = IERC721(_originContract);
                    erc721.transferFrom(msg.sender, address(this), _tokenId);
                }
                emit NewAuction(
                    _originContract,
                    _tokenId,
                    msg.sender,
                    _currencyAddress,
                    _startTime,
                    _startingAmount,
                    _lengthOfAuction
                );
            }
            /// @notice Converts an offer into a coldie auction.
            /// @param _originContract Contract address of the asset.
            /// @dev Covers use of any currency (0 address is eth).
            /// @dev Only covers converting an offer to a coldie auction.
            /// @dev Cant convert offer if an auction currently exists.
            /// @param _tokenId Token Id of the asset.
            /// @param _currencyAddress Address of the currency being converted.
            /// @param _amount Amount being converted into an auction.
            /// @param _lengthOfAuction Number of seconds the auction will last.
            /// @param _splitAddresses Addresses that the sellers take in will be split amongst.
            /// @param _splitRatios Ratios that the take in will be split by.
            function convertOfferToAuction(
                address _originContract,
                uint256 _tokenId,
                address _currencyAddress,
                uint256 _amount,
                uint256 _lengthOfAuction,
                address payable[] calldata _splitAddresses,
                uint8[] calldata _splitRatios
            ) external override {
                _senderMustBeTokenOwner(_originContract, _tokenId);
                _ownerMustHaveMarketplaceApprovedForNFT(_originContract, _tokenId);
                _checkSplits(_splitAddresses, _splitRatios);
                Auction memory auction = tokenAuctions[_originContract][_tokenId];
                require(
                    auction.auctionType == NO_AUCTION ||
                        auction.auctionCreator != msg.sender,
                    "convertOfferToAuction::Cannot have a current auction."
                );
                require(
                    _lengthOfAuction <= maxAuctionLength,
                    "convertOfferToAuction::Auction too long."
                );
                Offer memory currOffer = tokenCurrentOffers[_originContract][_tokenId][
                    _currencyAddress
                ];
                require(currOffer.buyer != msg.sender, "convert::own offer");
                require(
                    currOffer.convertible,
                    "convertOfferToAuction::Offer is not convertible"
                );
                require(
                    currOffer.amount == _amount,
                    "convertOfferToAuction::Converting offer with different amount."
                );
                tokenAuctions[_originContract][_tokenId] = Auction(
                    msg.sender,
                    block.number,
                    block.timestamp,
                    _lengthOfAuction,
                    _currencyAddress,
                    currOffer.amount,
                    COLDIE_AUCTION,
                    _splitAddresses,
                    _splitRatios
                );
                delete tokenCurrentOffers[_originContract][_tokenId][_currencyAddress];
                auctionBids[_originContract][_tokenId] = Bid(
                    currOffer.buyer,
                    _currencyAddress,
                    _amount,
                    marketplaceSettings.getMarketplaceFeePercentage()
                );
                IERC721 erc721 = IERC721(_originContract);
                erc721.transferFrom(msg.sender, address(this), _tokenId);
                emit NewAuction(
                    _originContract,
                    _tokenId,
                    msg.sender,
                    _currencyAddress,
                    block.timestamp,
                    _amount,
                    _lengthOfAuction
                );
                emit AuctionBid(
                    _originContract,
                    currOffer.buyer,
                    _tokenId,
                    _currencyAddress,
                    _amount,
                    true,
                    0,
                    address(0)
                );
            }
            /// @notice Cancels a configured Auction that has not started.
            /// @dev Requires the person sending the message to be the auction creator or token owner.
            /// @param _originContract Contract address of the asset pending auction.
            /// @param _tokenId Token Id of the asset.
            function cancelAuction(address _originContract, uint256 _tokenId)
                external
                override
            {
                Auction memory auction = tokenAuctions[_originContract][_tokenId];
                IERC721 erc721 = IERC721(_originContract);
                require(
                    auction.auctionType != NO_AUCTION,
                    "cancelAuction::Must have an auction configured."
                );
                require(
                    auction.startingTime == 0 || block.timestamp < auction.startingTime,
                    "cancelAuction::Auction must not have started."
                );
                require(
                    auction.auctionCreator == msg.sender ||
                        erc721.ownerOf(_tokenId) == msg.sender,
                    "cancelAuction::Must be creator or owner."
                );
                delete tokenAuctions[_originContract][_tokenId];
                if (erc721.ownerOf(_tokenId) == address(this)) {
                    erc721.transferFrom(address(this), msg.sender, _tokenId);
                }
                emit CancelAuction(_originContract, _tokenId, auction.auctionCreator);
            }
            /// @notice Places a bid on a valid auction.
            /// @dev Only the configured currency can be used (Zero address for eth)
            /// @param _originContract Contract address of asset being bid on.
            /// @param _tokenId Token Id of the asset.
            /// @param _currencyAddress Address of currency being used to bid.
            /// @param _amount Amount of the currency being used for the bid.
            function bid(
                address _originContract,
                uint256 _tokenId,
                address _currencyAddress,
                uint256 _amount
            ) external payable override nonReentrant {
                uint256 requiredAmount = _amount.add(
                    marketplaceSettings.calculateMarketplaceFee(_amount)
                );
                _senderMustHaveMarketplaceApproved(_currencyAddress, requiredAmount);
                Auction memory auction = tokenAuctions[_originContract][_tokenId];
                require(
                    auction.auctionType != NO_AUCTION,
                    "bid::Must have a current auction."
                );
                require(
                    auction.auctionCreator != msg.sender,
                    "bid::Cannot bid on your own auction."
                );
                require(
                    block.timestamp >= auction.startingTime,
                    "bid::Auction not active."
                );
                require(
                    _currencyAddress == auction.currencyAddress,
                    "bid::Currency must be in configured denomination"
                );
                require(_amount > 0, "bid::Cannot be 0");
                require(
                    _amount <= marketplaceSettings.getMarketplaceMaxValue(),
                    "bid::Must be less than max value."
                );
                require(
                    _amount >= auction.minimumBid,
                    "bid::Cannot be lower than minimum bid."
                );
                require(
                    auction.startingTime == 0 ||
                        block.timestamp <
                        auction.startingTime.add(auction.lengthOfAuction),
                    "bid::Must be active."
                );
                Bid memory currBid = auctionBids[_originContract][_tokenId];
                require(
                    _amount >=
                        currBid.amount.add(
                            currBid.amount.mul(minimumBidIncreasePercentage).div(100)
                        ),
                    "bid::Must be higher than prev bid + min increase."
                );
                IERC721 erc721 = IERC721(_originContract);
                address tokenOwner = erc721.ownerOf(_tokenId);
                require(
                    auction.auctionCreator == tokenOwner || tokenOwner == address(this),
                    "bid::Auction creator must be owner."
                );
                if (auction.auctionCreator == tokenOwner) {
                    _ownerMustHaveMarketplaceApprovedForNFT(_originContract, _tokenId);
                }
                _checkAmountAndTransfer(_currencyAddress, requiredAmount);
                _refund(
                    _currencyAddress,
                    currBid.amount,
                    currBid.marketplaceFee,
                    currBid.bidder
                );
                auctionBids[_originContract][_tokenId] = Bid(
                    msg.sender,
                    _currencyAddress,
                    _amount,
                    marketplaceSettings.getMarketplaceFeePercentage()
                );
                bool startedAuction = false;
                uint256 newAuctionLength = 0;
                if (auction.startingTime == 0) {
                    tokenAuctions[_originContract][_tokenId].startingTime = block
                        .timestamp;
                    erc721.transferFrom(
                        auction.auctionCreator,
                        address(this),
                        _tokenId
                    );
                    startedAuction = true;
                } else if (
                    auction.startingTime.add(auction.lengthOfAuction).sub(
                        block.timestamp
                    ) < auctionLengthExtension
                ) {
                    newAuctionLength = block.timestamp.add(auctionLengthExtension).sub(
                        auction.startingTime
                    );
                    tokenAuctions[_originContract][_tokenId]
                        .lengthOfAuction = newAuctionLength;
                }
                emit AuctionBid(
                    _originContract,
                    msg.sender,
                    _tokenId,
                    _currencyAddress,
                    _amount,
                    startedAuction,
                    newAuctionLength,
                    currBid.bidder
                );
            }
            /// @notice Settles an auction that has ended.
            /// @dev Anyone is able to settle an auction since non-input params are used.
            /// @param _originContract Contract address of asset.
            /// @param _tokenId Token Id of the asset.
            function settleAuction(address _originContract, uint256 _tokenId)
                external
                override
            {
                Auction memory auction = tokenAuctions[_originContract][_tokenId];
                require(
                    auction.auctionType != NO_AUCTION && auction.startingTime != 0,
                    "settleAuction::Must have a current valid auction."
                );
                require(
                    block.timestamp >=
                        auction.startingTime.add(auction.lengthOfAuction),
                    "settleAuction::Can only settle ended auctions."
                );
                Bid memory currBid = auctionBids[_originContract][_tokenId];
                delete tokenAuctions[_originContract][_tokenId];
                delete auctionBids[_originContract][_tokenId];
                IERC721 erc721 = IERC721(_originContract);
                if (currBid.bidder == address(0)) {
                    erc721.transferFrom(
                        address(this),
                        auction.auctionCreator,
                        _tokenId
                    );
                } else {
                    erc721.transferFrom(address(this), currBid.bidder, _tokenId);
                    _payout(
                        _originContract,
                        _tokenId,
                        auction.currencyAddress,
                        currBid.amount,
                        auction.auctionCreator,
                        auction.splitRecipients,
                        auction.splitRatios
                    );
                    marketplaceSettings.markERC721Token(
                        _originContract,
                        _tokenId,
                        true
                    );
                }
                emit AuctionSettled(
                    _originContract,
                    currBid.bidder,
                    auction.auctionCreator,
                    _tokenId,
                    auction.currencyAddress,
                    currBid.amount
                );
            }
            /// @notice Grabs the current auction details for a token.
            /// @param _originContract Contract address of asset.
            /// @param _tokenId Token Id of the asset.
            /** @return Auction Struct: creatorAddress, creationTime, startingTime, lengthOfAuction,
                        currencyAddress, minimumBid, auctionType, splitRecipients array, and splitRatios array.
            */
            function getAuctionDetails(address _originContract, uint256 _tokenId)
                external
                view
                override
                returns (
                    address,
                    uint256,
                    uint256,
                    uint256,
                    address,
                    uint256,
                    bytes32,
                    address payable[] memory,
                    uint8[] memory
                )
            {
                Auction memory auction = tokenAuctions[_originContract][_tokenId];
                return (
                    auction.auctionCreator,
                    auction.creationBlock,
                    auction.startingTime,
                    auction.lengthOfAuction,
                    auction.currencyAddress,
                    auction.minimumBid,
                    auction.auctionType,
                    auction.splitRecipients,
                    auction.splitRatios
                );
            }
            function _checkValidAuctionType(bytes32 _auctionType) internal pure {
                if (
                    _auctionType != COLDIE_AUCTION && _auctionType != SCHEDULED_AUCTION
                ) {
                    revert("Invalid Auction Type");
                }
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.7.0;
        import "../utils/ContextUpgradeable.sol";
        import "../proxy/Initializable.sol";
        /**
         * @dev Contract module which provides a basic access control mechanism, where
         * there is an account (an owner) that can be granted exclusive access to
         * specific functions.
         *
         * By default, the owner account will be the one that deploys the contract. This
         * can later be changed with {transferOwnership}.
         *
         * This module is used through inheritance. It will make available the modifier
         * `onlyOwner`, which can be applied to your functions to restrict their use to
         * the owner.
         */
        abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
            address private _owner;
            event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
            /**
             * @dev Initializes the contract setting the deployer as the initial owner.
             */
            function __Ownable_init() internal initializer {
                __Context_init_unchained();
                __Ownable_init_unchained();
            }
            function __Ownable_init_unchained() internal initializer {
                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;
            }
            uint256[49] private __gap;
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.7.0;
        import "../proxy/Initializable.sol";
        /**
         * @dev Contract module that helps prevent reentrant calls to a function.
         *
         * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
         * available, which can be applied to functions to make sure there are no nested
         * (reentrant) calls to them.
         *
         * Note that because there is a single `nonReentrant` guard, functions marked as
         * `nonReentrant` may not call one another. This can be worked around by making
         * those functions `private`, and then adding `external` `nonReentrant` entry
         * points to them.
         *
         * TIP: If you would like to learn more about reentrancy and alternative ways
         * to protect against it, check out our blog post
         * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
         */
        abstract contract ReentrancyGuardUpgradeable is Initializable {
            // Booleans are more expensive than uint256 or any type that takes up a full
            // word because each write operation emits an extra SLOAD to first read the
            // slot's contents, replace the bits taken up by the boolean, and then write
            // back. This is the compiler's defense against contract upgrades and
            // pointer aliasing, and it cannot be disabled.
            // The values being non-zero value makes deployment a bit more expensive,
            // but in exchange the refund on every call to nonReentrant will be lower in
            // amount. Since refunds are capped to a percentage of the total
            // transaction's gas, it is best to keep them low in cases like this one, to
            // increase the likelihood of the full refund coming into effect.
            uint256 private constant _NOT_ENTERED = 1;
            uint256 private constant _ENTERED = 2;
            uint256 private _status;
            function __ReentrancyGuard_init() internal initializer {
                __ReentrancyGuard_init_unchained();
            }
            function __ReentrancyGuard_init_unchained() internal initializer {
                _status = _NOT_ENTERED;
            }
            /**
             * @dev Prevents a contract from calling itself, directly or indirectly.
             * Calling a `nonReentrant` function from another `nonReentrant`
             * function is not supported. It is possible to prevent this from happening
             * by making the `nonReentrant` function external, and make it call a
             * `private` function that does the actual work.
             */
            modifier nonReentrant() {
                // On the first call to nonReentrant, _notEntered will be true
                require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
                // Any calls to nonReentrant after this point will fail
                _status = _ENTERED;
                _;
                // By storing the original value once again, a refund is triggered (see
                // https://eips.ethereum.org/EIPS/eip-2200)
                _status = _NOT_ENTERED;
            }
            uint256[49] private __gap;
        }
        // SPDX-License-Identifier: MIT
        pragma solidity 0.7.3;
        /// @author koloz
        /// @title ISuperRareAuctionHouse
        /// @notice The interface for the SuperRareAuctionHouse Functions.
        interface ISuperRareAuctionHouse {
            /// @notice Configures an Auction for a given asset.
            /// @param _auctionType The type of auction being configured.
            /// @param _originContract Contract address of the asset being put up for auction.
            /// @param _tokenId Token Id of the asset.
            /// @param _startingAmount The reserve price or min bid of an auction.
            /// @param _currencyAddress The currency the auction is being conducted in.
            /// @param _lengthOfAuction The amount of time in seconds that the auction is configured for.
            /// @param _splitAddresses Addresses to split the sellers commission with.
            /// @param _splitRatios The ratio for the split corresponding to each of the addresses being split with.
            function configureAuction(
                bytes32 _auctionType,
                address _originContract,
                uint256 _tokenId,
                uint256 _startingAmount,
                address _currencyAddress,
                uint256 _lengthOfAuction,
                uint256 _startTime,
                address payable[] calldata _splitAddresses,
                uint8[] calldata _splitRatios
            ) external;
            /// @notice Converts an offer into a coldie auction.
            /// @param _originContract Contract address of the asset.
            /// @param _tokenId Token Id of the asset.
            /// @param _currencyAddress Address of the currency being converted.
            /// @param _amount Amount being converted into an auction.
            /// @param _lengthOfAuction Number of seconds the auction will last.
            /// @param _splitAddresses Addresses that the sellers take in will be split amongst.
            /// @param _splitRatios Ratios that the take in will be split by.
            function convertOfferToAuction(
                address _originContract,
                uint256 _tokenId,
                address _currencyAddress,
                uint256 _amount,
                uint256 _lengthOfAuction,
                address payable[] calldata _splitAddresses,
                uint8[] calldata _splitRatios
            ) external;
            /// @notice Cancels a configured Auction that has not started.
            /// @param _originContract Contract address of the asset pending auction.
            /// @param _tokenId Token Id of the asset.
            function cancelAuction(address _originContract, uint256 _tokenId) external;
            /// @notice Places a bid on a valid auction.
            /// @param _originContract Contract address of asset being bid on.
            /// @param _tokenId Token Id of the asset.
            /// @param _currencyAddress Address of currency being used to bid.
            /// @param _amount Amount of the currency being used for the bid.
            function bid(
                address _originContract,
                uint256 _tokenId,
                address _currencyAddress,
                uint256 _amount
            ) external payable;
            /// @notice Settles an auction that has ended.
            /// @param _originContract Contract address of asset.
            /// @param _tokenId Token Id of the asset.
            function settleAuction(address _originContract, uint256 _tokenId) external;
            /// @notice Grabs the current auction details for a token.
            /// @param _originContract Contract address of asset.
            /// @param _tokenId Token Id of the asset.
            /** @return Auction Struct: creatorAddress, creationTime, startingTime, lengthOfAuction,
                        currencyAddress, minimumBid, auctionType, splitRecipients array, and splitRatios array.
            */
            function getAuctionDetails(address _originContract, uint256 _tokenId)
                external
                view
                returns (
                    address,
                    uint256,
                    uint256,
                    uint256,
                    address,
                    uint256,
                    bytes32,
                    address payable[] memory,
                    uint8[] memory
                );
        }
        // SPDX-License-Identifier: MIT
        pragma solidity 0.7.3;
        import "@openzeppelin/contracts-0.7.2/token/ERC721/IERC721.sol";
        import "@openzeppelin/contracts-0.7.2/token/ERC20/IERC20.sol";
        import "@openzeppelin/contracts-0.7.2/token/ERC20/SafeERC20.sol";
        import "@openzeppelin/contracts-0.7.2/math/SafeMath.sol";
        import "./storage/SuperRareBazaarStorage.sol";
        /// @author koloz
        /// @title SuperRareBazaarBase
        /// @notice Base contract containing the internal functions for the SuperRareBazaar.
        abstract contract SuperRareBazaarBase is SuperRareBazaarStorage {
            using SafeMath for uint256;
            using SafeMath for uint8;
            using SafeERC20 for IERC20;
            /////////////////////////////////////////////////////////////////////////
            // Internal Functions
            /////////////////////////////////////////////////////////////////////////
            /// @notice Checks to see if the currenccy address is eth or an approved erc20 token.
            /// @param _currencyAddress Address of currency (Zero address if eth).
            function _checkIfCurrencyIsApproved(address _currencyAddress)
                internal
                view
            {
                require(
                    _currencyAddress == address(0) ||
                        approvedTokenRegistry.isApprovedToken(_currencyAddress),
                    "Not approved currency"
                );
            }
            /// @notice Checks to see if the owner of the token has the marketplace approved.
            /// @param _originContract Contract address of the token being checked.
            /// @param _tokenId Token Id of the asset.
            function _ownerMustHaveMarketplaceApprovedForNFT(
                address _originContract,
                uint256 _tokenId
            ) internal view {
                IERC721 erc721 = IERC721(_originContract);
                address owner = erc721.ownerOf(_tokenId);
                require(
                    erc721.isApprovedForAll(owner, address(this)),
                    "owner must have approved contract"
                );
            }
            /// @notice Checks to see if the msg sender owns the token.
            /// @param _originContract Contract address of the token being checked.
            /// @param _tokenId Token Id of the asset.
            function _senderMustBeTokenOwner(address _originContract, uint256 _tokenId)
                internal
                view
            {
                IERC721 erc721 = IERC721(_originContract);
                require(
                    erc721.ownerOf(_tokenId) == msg.sender,
                    "sender must be the token owner"
                );
            }
            /// @notice Verifies that the splits supplied are valid.
            /// @dev A valid split has the same number of splits and ratios.
            /// @dev There can only be a max of 5 parties split with.
            /// @dev Total of the ratios should be 100 which is relative.
            /// @param _splits The addresses the amount is being split with.
            /// @param _ratios The ratios each address in _splits is getting.
            function _checkSplits(
                address payable[] calldata _splits,
                uint8[] calldata _ratios
            ) internal pure {
                require(_splits.length > 0, "checkSplits::Must have at least 1 split");
                require(_splits.length <= 5, "checkSplits::Split exceeded max size");
                require(
                    _splits.length == _ratios.length,
                    "checkSplits::Splits and ratios must be equal"
                );
                uint256 totalRatio = 0;
                for (uint256 i = 0; i < _ratios.length; i++) {
                    totalRatio += _ratios[i];
                }
                require(totalRatio == 100, "checkSplits::Total must be equal to 100");
            }
            /// @notice Checks to see if the sender has approved the marketplace to move tokens.
            /// @dev This is for offers/buys/bids and the allowance of erc20 tokens.
            /// @dev Returns on zero address because no allowance is needed for eth.
            /// @param _contract The address of the currency being checked.
            /// @param _amount The total amount being checked.
            function _senderMustHaveMarketplaceApproved(
                address _contract,
                uint256 _amount
            ) internal view {
                if (_contract == address(0)) {
                    return;
                }
                IERC20 erc20 = IERC20(_contract);
                require(
                    erc20.allowance(msg.sender, address(this)) >= _amount,
                    "sender needs to approve marketplace for currency"
                );
            }
            /// @notice Checks the user has the correct amount and transfers to the marketplace.
            /// @dev If the currency used is eth (zero address) the msg value is checked.
            /// @dev If eth isnt used and eth is sent we revert the txn.
            /// @dev We need to check this contracts balance before and after the transfer to ensure no fee.
            /// @param _currencyAddress Currency address being checked and transfered.
            /// @param _amount Total amount of currency.
            function _checkAmountAndTransfer(address _currencyAddress, uint256 _amount)
                internal
            {
                if (_currencyAddress == address(0)) {
                    require(msg.value == _amount, "not enough eth sent");
                    return;
                }
                require(msg.value == 0, "msg.value should be 0 when not using eth");
                IERC20 erc20 = IERC20(_currencyAddress);
                uint256 balanceBefore = erc20.balanceOf(address(this));
                erc20.safeTransferFrom(msg.sender, address(this), _amount);
                uint256 balanceAfter = erc20.balanceOf(address(this));
                require(
                    balanceAfter.sub(balanceBefore) == _amount,
                    "not enough tokens transfered"
                );
            }
            /// @notice Refunds an address the designated amount.
            /// @dev Return if amount being refunded is zero.
            /// @dev Forwards to payment contract if eth is being refunded.
            /// @param _currencyAddress Address of currency being refunded.
            /// @param _amount Amount being refunded.
            /// @param _marketplaceFee Marketplace Fee (percentage) paid by _recipient.
            /// @param _recipient Address amount is being refunded to.
            function _refund(
                address _currencyAddress,
                uint256 _amount,
                uint256 _marketplaceFee,
                address _recipient
            ) internal {
                if (_amount == 0) {
                    return;
                }
                uint256 requiredAmount = _amount.add(
                    _amount.mul(_marketplaceFee).div(100)
                );
                if (_currencyAddress == address(0)) {
                    (bool success, bytes memory data) = address(payments).call{
                        value: requiredAmount
                    }(
                        abi.encodeWithSignature(
                            "refund(address,uint256)",
                            _recipient,
                            requiredAmount
                        )
                    );
                    require(success, string(data));
                    return;
                }
                IERC20 erc20 = IERC20(_currencyAddress);
                erc20.safeTransfer(_recipient, requiredAmount);
            }
            /// @notice Sends a payout to all the necessary parties.
            /// @dev Sends payments to the network, royalty if applicable, and splits for the rest.
            /// @dev Forwards payments to the payment contract if payout is happening in eth.
            /// @dev Total amount of ratios should be 100 and is relative to the total ratio left.
            /// @param _originContract Contract address of asset triggering a payout.
            /// @param _tokenId Token Id of the asset.
            /// @param _currencyAddress Address of currency being paid out.
            /// @param _amount Total amount to be paid out.
            /// @param _seller Address of the person selling the asset.
            /// @param _splitAddrs Addresses that funds need to be split against.
            /// @param _splitRatios Ratios for split pertaining to each address.
            function _payout(
                address _originContract,
                uint256 _tokenId,
                address _currencyAddress,
                uint256 _amount,
                address _seller,
                address payable[] memory _splitAddrs,
                uint8[] memory _splitRatios
            ) internal {
                require(
                    _splitAddrs.length == _splitRatios.length,
                    "Number of split addresses and ratios must be equal."
                );
                /*
                The overall flow for payouts is:
                    1. Payout marketplace fee
                    2. Primary/Secondary Payouts
                        a. Primary -> If space sale, query space operator registry for platform comission and payout
                                      Else query marketplace setting for primary sale comission and payout
                        b. Secondary -> Query global royalty registry for recipients and amounts and payout
                    3. Calculate the amount for each _splitAddr based on remaining amount and payout
                 */
                uint256 remainingAmount = _amount;
                // Marketplace fee
                uint256 marketplaceFee = marketplaceSettings.calculateMarketplaceFee(
                    _amount
                );
                address payable[] memory mktFeeRecip = new address payable[](1);
                mktFeeRecip[0] = payable(networkBeneficiary);
                uint256[] memory mktFee = new uint256[](1);
                mktFee[0] = marketplaceFee;
                _performPayouts(_currencyAddress, marketplaceFee, mktFeeRecip, mktFee);
                if (
                    !marketplaceSettings.hasERC721TokenSold(_originContract, _tokenId)
                ) {
                    uint256[] memory platformFee = new uint256[](1);
                    if (spaceOperatorRegistry.isApprovedSpaceOperator(_seller)) {
                        uint256 platformCommission = spaceOperatorRegistry
                            .getPlatformCommission(_seller);
                        remainingAmount = remainingAmount.sub(
                            _amount.mul(platformCommission).div(100)
                        );
                        platformFee[0] = _amount.mul(platformCommission).div(100);
                        _performPayouts(
                            _currencyAddress,
                            platformFee[0],
                            mktFeeRecip,
                            platformFee
                        );
                    } else {
                        uint256 platformCommission = marketplaceSettings
                            .getERC721ContractPrimarySaleFeePercentage(_originContract);
                        remainingAmount = remainingAmount.sub(
                            _amount.mul(platformCommission).div(100)
                        );
                        platformFee[0] = _amount.mul(platformCommission).div(100);
                        _performPayouts(
                            _currencyAddress,
                            platformFee[0],
                            mktFeeRecip,
                            platformFee
                        );
                    }
                } else {
                    (
                        address payable[] memory receivers,
                        uint256[] memory royalties
                    ) = royaltyEngine.getRoyalty(_originContract, _tokenId, _amount);
                    uint256 totalRoyalties = 0;
                    for (uint256 i = 0; i < royalties.length; i++) {
                        totalRoyalties = totalRoyalties.add(royalties[i]);
                    }
                    remainingAmount = remainingAmount.sub(totalRoyalties);
                    _performPayouts(
                        _currencyAddress,
                        totalRoyalties,
                        receivers,
                        royalties
                    );
                }
                uint256[] memory remainingAmts = new uint256[](_splitAddrs.length);
                uint256 totalSplit = 0;
                for (uint256 i = 0; i < _splitAddrs.length; i++) {
                    remainingAmts[i] = remainingAmount.mul(_splitRatios[i]).div(100);
                    totalSplit = totalSplit.add(
                        remainingAmount.mul(_splitRatios[i]).div(100)
                    );
                }
                _performPayouts(
                    _currencyAddress,
                    totalSplit,
                    _splitAddrs,
                    remainingAmts
                );
            }
            function _performPayouts(
                address _currencyAddress,
                uint256 _amount,
                address payable[] memory _recipients,
                uint256[] memory _amounts
            ) internal {
                if (_currencyAddress == address(0)) {
                    (bool success, bytes memory data) = address(payments).call{
                        value: _amount
                    }(
                        abi.encodeWithSelector(
                            IPayments.payout.selector,
                            _recipients,
                            _amounts
                        )
                    );
                    require(success, string(data));
                } else {
                    IERC20 erc20 = IERC20(_currencyAddress);
                    for (uint256 i = 0; i < _recipients.length; i++) {
                        erc20.safeTransfer(_recipients[i], _amounts[i]);
                    }
                }
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity >=0.6.0 <0.8.0;
        import "../proxy/Initializable.sol";
        /*
         * @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 GSN 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 ContextUpgradeable is Initializable {
            function __Context_init() internal initializer {
                __Context_init_unchained();
            }
            function __Context_init_unchained() internal initializer {
            }
            function _msgSender() internal view virtual returns (address payable) {
                return msg.sender;
            }
            function _msgData() internal view virtual returns (bytes memory) {
                this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
                return msg.data;
            }
            uint256[50] private __gap;
        }
        // SPDX-License-Identifier: MIT
        // solhint-disable-next-line compiler-version
        pragma solidity >=0.4.24 <0.8.0;
        import "../utils/AddressUpgradeable.sol";
        /**
         * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
         * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an
         * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
         * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
         *
         * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
         * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}.
         *
         * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
         * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
         */
        abstract contract Initializable {
            /**
             * @dev Indicates that the contract has been initialized.
             */
            bool private _initialized;
            /**
             * @dev Indicates that the contract is in the process of being initialized.
             */
            bool private _initializing;
            /**
             * @dev Modifier to protect an initializer function from being invoked twice.
             */
            modifier initializer() {
                require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized");
                bool isTopLevelCall = !_initializing;
                if (isTopLevelCall) {
                    _initializing = true;
                    _initialized = true;
                }
                _;
                if (isTopLevelCall) {
                    _initializing = false;
                }
            }
            /// @dev Returns true if and only if the function is running in the constructor
            function _isConstructor() private view returns (bool) {
                return !AddressUpgradeable.isContract(address(this));
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.7.0;
        /**
         * @dev Collection of functions related to the address type
         */
        library AddressUpgradeable {
            /**
             * @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);
            }
            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.6.2 <0.8.0;
        import "../../introspection/IERC165.sol";
        /**
         * @dev Required interface of an ERC721 compliant contract.
         */
        interface IERC721 is IERC165 {
            /**
             * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
             */
            event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
            /**
             * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
             */
            event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
            /**
             * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
             */
            event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
            /**
             * @dev Returns the number of tokens in ``owner``'s account.
             */
            function balanceOf(address owner) external view returns (uint256 balance);
            /**
             * @dev Returns the owner of the `tokenId` token.
             *
             * Requirements:
             *
             * - `tokenId` must exist.
             */
            function ownerOf(uint256 tokenId) external view returns (address owner);
            /**
             * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
             * are aware of the ERC721 protocol to prevent tokens from being forever locked.
             *
             * Requirements:
             *
             * - `from` cannot be the zero address.
             * - `to` cannot be the zero address.
             * - `tokenId` token must exist and be owned by `from`.
             * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
             * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
             *
             * Emits a {Transfer} event.
             */
            function safeTransferFrom(address from, address to, uint256 tokenId) external;
            /**
             * @dev Transfers `tokenId` token from `from` to `to`.
             *
             * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
             *
             * Requirements:
             *
             * - `from` cannot be the zero address.
             * - `to` cannot be the zero address.
             * - `tokenId` token must be owned by `from`.
             * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
             *
             * Emits a {Transfer} event.
             */
            function transferFrom(address from, address to, uint256 tokenId) external;
            /**
             * @dev Gives permission to `to` to transfer `tokenId` token to another account.
             * The approval is cleared when the token is transferred.
             *
             * Only a single account can be approved at a time, so approving the zero address clears previous approvals.
             *
             * Requirements:
             *
             * - The caller must own the token or be an approved operator.
             * - `tokenId` must exist.
             *
             * Emits an {Approval} event.
             */
            function approve(address to, uint256 tokenId) external;
            /**
             * @dev Returns the account approved for `tokenId` token.
             *
             * Requirements:
             *
             * - `tokenId` must exist.
             */
            function getApproved(uint256 tokenId) external view returns (address operator);
            /**
             * @dev Approve or remove `operator` as an operator for the caller.
             * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
             *
             * Requirements:
             *
             * - The `operator` cannot be the caller.
             *
             * Emits an {ApprovalForAll} event.
             */
            function setApprovalForAll(address operator, bool _approved) external;
            /**
             * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
             *
             * See {setApprovalForAll}
             */
            function isApprovedForAll(address owner, address operator) external view returns (bool);
            /**
              * @dev Safely transfers `tokenId` token from `from` to `to`.
              *
              * Requirements:
              *
              * - `from` cannot be the zero address.
              * - `to` cannot be the zero address.
              * - `tokenId` token must exist and be owned by `from`.
              * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
              * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
              *
              * Emits a {Transfer} event.
              */
            function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
        }
        // SPDX-License-Identifier: MIT
        pragma solidity >=0.6.0 <0.8.0;
        /**
         * @dev Interface of the ERC20 standard as defined in the EIP.
         */
        interface IERC20 {
            /**
             * @dev Returns the amount of tokens in existence.
             */
            function totalSupply() external view returns (uint256);
            /**
             * @dev Returns the amount of tokens owned by `account`.
             */
            function balanceOf(address account) external view returns (uint256);
            /**
             * @dev Moves `amount` tokens from the caller's account to `recipient`.
             *
             * Returns a boolean value indicating whether the operation succeeded.
             *
             * Emits a {Transfer} event.
             */
            function transfer(address recipient, uint256 amount) external returns (bool);
            /**
             * @dev Returns the remaining number of tokens that `spender` will be
             * allowed to spend on behalf of `owner` through {transferFrom}. This is
             * zero by default.
             *
             * This value changes when {approve} or {transferFrom} are called.
             */
            function allowance(address owner, address spender) external view returns (uint256);
            /**
             * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
             *
             * Returns a boolean value indicating whether the operation succeeded.
             *
             * IMPORTANT: Beware that changing an allowance with this method brings the risk
             * that someone may use both the old and the new allowance by unfortunate
             * transaction ordering. One possible solution to mitigate this race
             * condition is to first reduce the spender's allowance to 0 and set the
             * desired value afterwards:
             * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
             *
             * Emits an {Approval} event.
             */
            function approve(address spender, uint256 amount) external returns (bool);
            /**
             * @dev Moves `amount` tokens from `sender` to `recipient` using the
             * allowance mechanism. `amount` is then deducted from the caller's
             * allowance.
             *
             * Returns a boolean value indicating whether the operation succeeded.
             *
             * Emits a {Transfer} event.
             */
            function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
            /**
             * @dev Emitted when `value` tokens are moved from one account (`from`) to
             * another (`to`).
             *
             * Note that `value` may be zero.
             */
            event Transfer(address indexed from, address indexed to, uint256 value);
            /**
             * @dev Emitted when the allowance of a `spender` for an `owner` is set by
             * a call to {approve}. `value` is the new allowance.
             */
            event Approval(address indexed owner, address indexed spender, uint256 value);
        }
        // SPDX-License-Identifier: MIT
        pragma solidity >=0.6.0 <0.8.0;
        import "./IERC20.sol";
        import "../../math/SafeMath.sol";
        import "../../utils/Address.sol";
        /**
         * @title SafeERC20
         * @dev Wrappers around ERC20 operations that throw on failure (when the token
         * contract returns false). Tokens that return no value (and instead revert or
         * throw on failure) are also supported, non-reverting calls are assumed to be
         * successful.
         * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
         * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
         */
        library SafeERC20 {
            using SafeMath for uint256;
            using Address for address;
            function safeTransfer(IERC20 token, address to, uint256 value) internal {
                _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
            }
            function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
                _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
            }
            /**
             * @dev Deprecated. This function has issues similar to the ones found in
             * {IERC20-approve}, and its usage is discouraged.
             *
             * Whenever possible, use {safeIncreaseAllowance} and
             * {safeDecreaseAllowance} instead.
             */
            function safeApprove(IERC20 token, address spender, uint256 value) internal {
                // safeApprove should only be called when setting an initial allowance,
                // or when resetting it to zero. To increase and decrease it, use
                // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
                // solhint-disable-next-line max-line-length
                require((value == 0) || (token.allowance(address(this), spender) == 0),
                    "SafeERC20: approve from non-zero to non-zero allowance"
                );
                _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
            }
            function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
                uint256 newAllowance = token.allowance(address(this), spender).add(value);
                _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
            }
            function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
                uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero");
                _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
            }
            /**
             * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
             * on the return value: the return value is optional (but if data is returned, it must not be false).
             * @param token The token targeted by the call.
             * @param data The call data (encoded using abi.encode or one of its variants).
             */
            function _callOptionalReturn(IERC20 token, bytes memory data) private {
                // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
                // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
                // the target address contains contract code and also asserts for success in the low-level call.
                bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
                if (returndata.length > 0) { // Return data is optional
                    // solhint-disable-next-line max-line-length
                    require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
                }
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity >=0.6.0 <0.8.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, with an overflow flag.
             *
             * _Available since v3.4._
             */
            function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
                uint256 c = a + b;
                if (c < a) return (false, 0);
                return (true, c);
            }
            /**
             * @dev Returns the substraction of two unsigned integers, with an overflow flag.
             *
             * _Available since v3.4._
             */
            function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
                if (b > a) return (false, 0);
                return (true, a - b);
            }
            /**
             * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
             *
             * _Available since v3.4._
             */
            function tryMul(uint256 a, uint256 b) internal pure returns (bool, 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 (true, 0);
                uint256 c = a * b;
                if (c / a != b) return (false, 0);
                return (true, c);
            }
            /**
             * @dev Returns the division of two unsigned integers, with a division by zero flag.
             *
             * _Available since v3.4._
             */
            function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
                if (b == 0) return (false, 0);
                return (true, a / b);
            }
            /**
             * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
             *
             * _Available since v3.4._
             */
            function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
                if (b == 0) return (false, 0);
                return (true, a % b);
            }
            /**
             * @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");
                return a - b;
            }
            /**
             * @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) {
                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, reverting 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) {
                require(b > 0, "SafeMath: division by zero");
                return a / b;
            }
            /**
             * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
             * reverting 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;
            }
            /**
             * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
             * overflow (when the result is negative).
             *
             * CAUTION: This function is deprecated because it requires allocating memory for the error
             * message unnecessarily. For custom revert reasons use {trySub}.
             *
             * Counterpart to Solidity's `-` operator.
             *
             * Requirements:
             *
             * - Subtraction cannot overflow.
             */
            function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
                require(b <= a, errorMessage);
                return a - b;
            }
            /**
             * @dev Returns the integer division of two unsigned integers, reverting with custom message on
             * division by zero. The result is rounded towards zero.
             *
             * CAUTION: This function is deprecated because it requires allocating memory for the error
             * message unnecessarily. For custom revert reasons use {tryDiv}.
             *
             * 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, string memory errorMessage) internal pure returns (uint256) {
                require(b > 0, errorMessage);
                return a / b;
            }
            /**
             * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
             * reverting with custom message when dividing by zero.
             *
             * CAUTION: This function is deprecated because it requires allocating memory for the error
             * message unnecessarily. For custom revert reasons use {tryMod}.
             *
             * 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, string memory errorMessage) internal pure returns (uint256) {
                require(b > 0, errorMessage);
                return a % b;
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity 0.7.3;
        import "../../marketplace/IMarketplaceSettings.sol";
        import "../../royalty/creator/IERC721CreatorRoyalty.sol";
        import "../../payments/IPayments.sol";
        import "../../registry/spaces/ISpaceOperatorRegistry.sol";
        import "../../registry/token/IApprovedTokenRegistry.sol";
        import "../../royalty/creator/IRoyaltyEngine.sol";
        /// @author koloz
        /// @title SuperRareBazaar Storage Contract
        /// @dev STORAGE CAN ONLY BE APPENDED NOT INSERTED OR MODIFIED
        contract SuperRareBazaarStorage {
            /////////////////////////////////////////////////////////////////////////
            // Constants
            /////////////////////////////////////////////////////////////////////////
            // Auction Types
            bytes32 public constant COLDIE_AUCTION = "COLDIE_AUCTION";
            bytes32 public constant SCHEDULED_AUCTION = "SCHEDULED_AUCTION";
            bytes32 public constant NO_AUCTION = bytes32(0);
            /////////////////////////////////////////////////////////////////////////
            // Structs
            /////////////////////////////////////////////////////////////////////////
            // The Offer truct for a given token:
            // buyer - address of person making the offer
            // currencyAddress - address of the erc20 token used for an offer
            //                   or the zero address for eth
            // amount - offer in wei/full erc20 value
            // marketplaceFee - the amount that is taken by the network on offer acceptance.
            struct Offer {
                address payable buyer;
                uint256 amount;
                uint256 timestamp;
                uint8 marketplaceFee;
                bool convertible;
            }
            // The Sale Price struct for a given token:
            // seller - address of the person selling the token
            // currencyAddress - address of the erc20 token used for an offer
            //                   or the zero address for eth
            // amount - offer in wei/full erc20 value
            struct SalePrice {
                address payable seller;
                address currencyAddress;
                uint256 amount;
                address payable[] splitRecipients;
                uint8[] splitRatios;
            }
            // Structure of an Auction:
            // auctionCreator - creator of the auction
            // creationBlock - time that the auction was created/configured
            // startingBlock - time that the auction starts on
            // lengthOfAuction - how long the auction is
            // currencyAddress - address of the erc20 token used for an offer
            //                   or the zero address for eth
            // minimumBid - min amount a bidder can bid at the start of an auction.
            // auctionType - type of auction, represented as the formatted bytes 32 string
            struct Auction {
                address payable auctionCreator;
                uint256 creationBlock;
                uint256 startingTime;
                uint256 lengthOfAuction;
                address currencyAddress;
                uint256 minimumBid;
                bytes32 auctionType;
                address payable[] splitRecipients;
                uint8[] splitRatios;
            }
            struct Bid {
                address payable bidder;
                address currencyAddress;
                uint256 amount;
                uint8 marketplaceFee;
            }
            /////////////////////////////////////////////////////////////////////////
            // Events
            /////////////////////////////////////////////////////////////////////////
            event Sold(
                address indexed _originContract,
                address indexed _buyer,
                address indexed _seller,
                address _currencyAddress,
                uint256 _amount,
                uint256 _tokenId
            );
            event SetSalePrice(
                address indexed _originContract,
                address indexed _currencyAddress,
                address _target,
                uint256 _amount,
                uint256 _tokenId,
                address payable[] _splitRecipients,
                uint8[] _splitRatios
            );
            event OfferPlaced(
                address indexed _originContract,
                address indexed _bidder,
                address indexed _currencyAddress,
                uint256 _amount,
                uint256 _tokenId,
                bool _convertible
            );
            event AcceptOffer(
                address indexed _originContract,
                address indexed _bidder,
                address indexed _seller,
                address _currencyAddress,
                uint256 _amount,
                uint256 _tokenId,
                address payable[] _splitAddresses,
                uint8[] _splitRatios
            );
            event CancelOffer(
                address indexed _originContract,
                address indexed _bidder,
                address indexed _currencyAddress,
                uint256 _amount,
                uint256 _tokenId
            );
            event NewAuction(
                address indexed _contractAddress,
                uint256 indexed _tokenId,
                address indexed _auctionCreator,
                address _currencyAddress,
                uint256 _startingTime,
                uint256 _minimumBid,
                uint256 _lengthOfAuction
            );
            event CancelAuction(
                address indexed _contractAddress,
                uint256 indexed _tokenId,
                address indexed _auctionCreator
            );
            event AuctionBid(
                address indexed _contractAddress,
                address indexed _bidder,
                uint256 indexed _tokenId,
                address _currencyAddress,
                uint256 _amount,
                bool _startedAuction,
                uint256 _newAuctionLength,
                address _previousBidder
            );
            event AuctionSettled(
                address indexed _contractAddress,
                address indexed _bidder,
                address _seller,
                uint256 indexed _tokenId,
                address _currencyAddress,
                uint256 _amount
            );
            /////////////////////////////////////////////////////////////////////////
            // State Variables
            /////////////////////////////////////////////////////////////////////////
            // Current marketplace settings implementation to be used
            IMarketplaceSettings public marketplaceSettings;
            // Current creator royalty implementation to be used
            IERC721CreatorRoyalty public royaltyRegistry;
            // Address of the global royalty engine being used.
            IRoyaltyEngineV1 public royaltyEngine;
            // Current SuperRareMarketplace implementation to be used
            address public superRareMarketplace;
            // Current SuperRareAuctionHouse implementation to be used
            address public superRareAuctionHouse;
            // Current SpaceOperatorRegistry implementation to be used.
            ISpaceOperatorRegistry public spaceOperatorRegistry;
            // Current ApprovedTokenRegistry implementation being used for currencies.
            IApprovedTokenRegistry public approvedTokenRegistry;
            // Current payments contract to use
            IPayments public payments;
            // Address to be used for staking registry.
            address public stakingRegistry;
            // Address of the network beneficiary
            address public networkBeneficiary;
            // A minimum increase in bid amount when out bidding someone.
            uint8 public minimumBidIncreasePercentage; // 10 = 10%
            // Maximum length that an auction can be.
            uint256 public maxAuctionLength;
            // Extension length for an auction
            uint256 public auctionLengthExtension;
            // Offer cancellation delay
            uint256 public offerCancelationDelay;
            // Mapping from contract to mapping of tokenId to mapping of target to sale price.
            mapping(address => mapping(uint256 => mapping(address => SalePrice)))
                public tokenSalePrices;
            // Mapping from contract to mapping of tokenId to mapping of currency address to Current Offer.
            mapping(address => mapping(uint256 => mapping(address => Offer)))
                public tokenCurrentOffers;
            // Mapping from contract to mapping of tokenId to Auction.
            mapping(address => mapping(uint256 => Auction)) public tokenAuctions;
            // Mapping from contract to mapping of tokenId to Bid.
            mapping(address => mapping(uint256 => Bid)) public auctionBids;
            uint256[50] private __gap;
            /// ALL NEW STORAGE MUST COME AFTER THIS
        }
        // SPDX-License-Identifier: MIT
        pragma solidity >=0.6.0 <0.8.0;
        /**
         * @dev Interface of the ERC165 standard, as defined in the
         * https://eips.ethereum.org/EIPS/eip-165[EIP].
         *
         * 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
             * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
             * 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);
        }
        // SPDX-License-Identifier: MIT
        pragma solidity >=0.6.2 <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.7.3;
        /**
         * @title IMarketplaceSettings Settings governing a marketplace.
         */
        interface IMarketplaceSettings {
            /////////////////////////////////////////////////////////////////////////
            // Marketplace Min and Max Values
            /////////////////////////////////////////////////////////////////////////
            /**
             * @dev Get the max value to be used with the marketplace.
             * @return uint256 wei value.
             */
            function getMarketplaceMaxValue() external view returns (uint256);
            /**
             * @dev Get the max value to be used with the marketplace.
             * @return uint256 wei value.
             */
            function getMarketplaceMinValue() external view returns (uint256);
            /////////////////////////////////////////////////////////////////////////
            // Marketplace Fee
            /////////////////////////////////////////////////////////////////////////
            /**
             * @dev Get the marketplace fee percentage.
             * @return uint8 wei fee.
             */
            function getMarketplaceFeePercentage() external view returns (uint8);
            /**
             * @dev Utility function for calculating the marketplace fee for given amount of wei.
             * @param _amount uint256 wei amount.
             * @return uint256 wei fee.
             */
            function calculateMarketplaceFee(uint256 _amount)
                external
                view
                returns (uint256);
            /////////////////////////////////////////////////////////////////////////
            // Primary Sale Fee
            /////////////////////////////////////////////////////////////////////////
            /**
             * @dev Get the primary sale fee percentage for a specific ERC721 contract.
             * @param _contractAddress address ERC721Contract address.
             * @return uint8 wei primary sale fee.
             */
            function getERC721ContractPrimarySaleFeePercentage(address _contractAddress)
                external
                view
                returns (uint8);
            /**
             * @dev Utility function for calculating the primary sale fee for given amount of wei
             * @param _contractAddress address ERC721Contract address.
             * @param _amount uint256 wei amount.
             * @return uint256 wei fee.
             */
            function calculatePrimarySaleFee(address _contractAddress, uint256 _amount)
                external
                view
                returns (uint256);
            /**
             * @dev Check whether the ERC721 token has sold at least once.
             * @param _contractAddress address ERC721Contract address.
             * @param _tokenId uint256 token ID.
             * @return bool of whether the token has sold.
             */
            function hasERC721TokenSold(address _contractAddress, uint256 _tokenId)
                external
                view
                returns (bool);
            /**
             * @dev Mark a token as sold.
             * Requirements:
             *
             * - `_contractAddress` cannot be the zero address.
             * @param _contractAddress address ERC721Contract address.
             * @param _tokenId uint256 token ID.
             * @param _hasSold bool of whether the token should be marked sold or not.
             */
            function markERC721Token(
                address _contractAddress,
                uint256 _tokenId,
                bool _hasSold
            ) external;
            function setERC721ContractPrimarySaleFeePercentage(
                address _contractAddress,
                uint8 _percentage
            ) external;
        }
        // SPDX-License-Identifier: MIT
        pragma solidity 0.7.3;
        import "../../token/ERC721/IERC721TokenCreator.sol";
        /**
         * @title IERC721CreatorRoyalty Token level royalty interface.
         */
        interface IERC721CreatorRoyalty is IERC721TokenCreator {
            /**
             * @dev Get the royalty fee percentage for a specific ERC721 contract.
             * @param _contractAddress address ERC721Contract address.
             * @param _tokenId uint256 token ID.
             * @return uint8 wei royalty fee.
             */
            function getERC721TokenRoyaltyPercentage(
                address _contractAddress,
                uint256 _tokenId
            ) external view returns (uint8);
            /**
             * @dev Utililty function to calculate the royalty fee for a token.
             * @param _contractAddress address ERC721Contract address.
             * @param _tokenId uint256 token ID.
             * @param _amount uint256 wei amount.
             * @return uint256 wei fee.
             */
            function calculateRoyaltyFee(
                address _contractAddress,
                uint256 _tokenId,
                uint256 _amount
            ) external view returns (uint256);
            /**
             * @dev Utililty function to set the royalty percentage for a specific ERC721 contract.
             * @param _contractAddress address ERC721Contract address.
             * @param _percentage percentage for royalty
             */
            function setPercentageForSetERC721ContractRoyalty(
                address _contractAddress,
                uint8 _percentage
            ) external;
        }
        // SPDX-License-Identifier: MIT
        pragma solidity 0.7.3;
        /// @author koloz
        /// @title IPayments
        /// @notice Interface for the Payments contract used.
        interface IPayments {
            function refund(address _payee, uint256 _amount) external payable;
            function payout(address[] calldata _splits, uint256[] calldata _amounts)
                external
                payable;
        }
        // SPDX-License-Identifier: MIT
        pragma solidity 0.7.3;
        /// @author koloz
        /// @title ISpaceOperatorRegistry
        /// @notice The interface for the SpaceOperatorRegistry
        interface ISpaceOperatorRegistry {
            function getPlatformCommission(address _operator)
                external
                view
                returns (uint8);
            function setPlatformCommission(address _operator, uint8 _commission)
                external;
            function isApprovedSpaceOperator(address _operator)
                external
                view
                returns (bool);
            function setSpaceOperatorApproved(address _operator, bool _approved)
                external;
        }
        // SPDX-License-Identifier: MIT
        pragma solidity 0.7.3;
        interface IApprovedTokenRegistry {
            /// @notice Returns if a token has been approved or not.
            /// @param _tokenContract Contract of token being checked.
            /// @return True if the token is allowed, false otherwise.
            function isApprovedToken(address _tokenContract)
                external
                view
                returns (bool);
            /// @notice Adds a token to the list of approved tokens.
            /// @param _tokenContract Contract of token being approved.
            function addApprovedToken(address _tokenContract) external;
            /// @notice Removes a token from the approved tokens list.
            /// @param _tokenContract Contract of token being approved.
            function removeApprovedToken(address _tokenContract) external;
            /// @notice Sets whether all token contracts should be approved.
            /// @param _allTokensApproved Bool denoting if all tokens should be approved.
            function setAllTokensApproved(bool _allTokensApproved) external;
        }
        // SPDX-License-Identifier: MIT
        pragma solidity 0.7.3;
        /// @author: manifold.xyz
        /**
         * @dev Lookup engine interface
         */
        interface IRoyaltyEngineV1 {
            /**
             * Get the royalty for a given token (address, id) and value amount.  Does not cache the bps/amounts.  Caches the spec for a given token address
             *
             * @param tokenAddress - The address of the token
             * @param tokenId      - The id of the token
             * @param value        - The value you wish to get the royalty of
             *
             * returns Two arrays of equal length, royalty recipients and the corresponding amount each recipient should get
             */
            function getRoyalty(
                address tokenAddress,
                uint256 tokenId,
                uint256 value
            )
                external
                returns (address payable[] memory recipients, uint256[] memory amounts);
            /**
             * View only version of getRoyalty
             *
             * @param tokenAddress - The address of the token
             * @param tokenId      - The id of the token
             * @param value        - The value you wish to get the royalty of
             *
             * returns Two arrays of equal length, royalty recipients and the corresponding amount each recipient should get
             */
            function getRoyaltyView(
                address tokenAddress,
                uint256 tokenId,
                uint256 value
            )
                external
                view
                returns (address payable[] memory recipients, uint256[] memory amounts);
        }
        // SPDX-License-Identifier: MIT
        pragma solidity 0.7.3;
        interface IERC721TokenCreator {
            function tokenCreator(address _contractAddress, uint256 _tokenId)
                external
                view
                returns (address payable);
        }
        

        File 3 of 5: MarketplaceSettingsV2
        // SPDX-License-Identifier: MIT
        pragma solidity 0.8.10;
        import {IMarketplaceSettings} from "./IMarketplaceSettings.sol";
        import {Ownable} from "openzeppelin-contracts/access/Ownable.sol";
        import {AccessControl} from "openzeppelin-contracts/access/AccessControl.sol";
        import {ITokenCreator} from "../token/ITokenCreator.sol";
        import {IERC721} from "openzeppelin-contracts/token/ERC721/IERC721.sol";
        import {EnumerableSet} from "openzeppelin-contracts/utils/structs/EnumerableSet.sol";
        contract MarketplaceSettingsV2 is Ownable, AccessControl, IMarketplaceSettings {
            bytes32 public constant TOKEN_MARK_ROLE = keccak256("TOKEN_MARK_ROLE");
            // This is meant to be the MarketplaceSettings contract located in the V1 folder
            IMarketplaceSettings private oldMarketplaceSettings;
            // EnumerableSet library method
            using EnumerableSet for EnumerableSet.AddressSet;
            // EnumerableSet of contracts marked sold
            EnumerableSet.AddressSet private contractSold;
            uint256 private maxValue;
            uint256 private minValue;
            uint8 private marketplaceFeePercentage;
            uint8 private primarySaleFeePercentage;
            constructor(address newOwner, address oldSettings) {
                maxValue = 2**254;
                minValue = 1000;
                marketplaceFeePercentage = 3;
                primarySaleFeePercentage = 15;
                require(
                    newOwner != address(0),
                    "constructor::New owner address cannot be null"
                );
                require(
                    oldSettings != address(0),
                    "constructor::Old Marketplace Settings address cannot be null"
                );
                _setupRole(AccessControl.DEFAULT_ADMIN_ROLE, newOwner);
                _setupRole(TOKEN_MARK_ROLE, newOwner);
                transferOwnership(newOwner);
                oldMarketplaceSettings = IMarketplaceSettings(oldSettings);
            }
            function grantMarketplaceAccess(address _account) external {
                require(
                    hasRole(AccessControl.DEFAULT_ADMIN_ROLE, _msgSender()),
                    "grantMarketplaceAccess::Must be admin to call method"
                );
                grantRole(TOKEN_MARK_ROLE, _account);
            }
            function getMarketplaceMaxValue() external view override returns (uint256) {
                return maxValue;
            }
            function setPrimarySaleFeePercentage(uint8 _primarySaleFeePercentage)
                external
                onlyOwner
            {
                primarySaleFeePercentage = _primarySaleFeePercentage;
            }
            function setMarketplaceMaxValue(uint256 _maxValue) external onlyOwner {
                maxValue = _maxValue;
            }
            function getMarketplaceMinValue() external view override returns (uint256) {
                return minValue;
            }
            function setMarketplaceMinValue(uint256 _minValue) external onlyOwner {
                minValue = _minValue;
            }
            function getMarketplaceFeePercentage()
                external
                view
                override
                returns (uint8)
            {
                return marketplaceFeePercentage;
            }
            function setMarketplaceFeePercentage(uint8 _percentage) external onlyOwner {
                require(
                    _percentage <= 100,
                    "setMarketplaceFeePercentage::_percentage must be <= 100"
                );
                marketplaceFeePercentage = _percentage;
            }
            function calculateMarketplaceFee(uint256 _amount)
                external
                view
                override
                returns (uint256)
            {
                return (_amount * marketplaceFeePercentage) / 100;
            }
            function getERC721ContractPrimarySaleFeePercentage(address)
                external
                view
                override
                returns (uint8)
            {
                return primarySaleFeePercentage;
            }
            function setERC721ContractPrimarySaleFeePercentage(
                address _contractAddress,
                uint8 _percentage
            ) external override {}
            function calculatePrimarySaleFee(address, uint256 _amount)
                external
                view
                override
                returns (uint256)
            {
                return (_amount * primarySaleFeePercentage) / 100;
            }
            function hasERC721TokenSold(address _contractAddress, uint256 _tokenId)
                external
                view
                override
                returns (bool)
            {
                bool contractHasSold = contractSold.contains(_contractAddress);
                if (contractHasSold) return true;
                return
                    oldMarketplaceSettings.hasERC721TokenSold(
                        _contractAddress,
                        _tokenId
                    );
            }
            function markERC721Token(
                address _contractAddress,
                uint256 _tokenId,
                bool _hasSold
            ) public override {
                require(
                    hasRole(TOKEN_MARK_ROLE, msg.sender),
                    "markERC721Token::Must have TOKEN_MARK_ROLE role to call method"
                );
                oldMarketplaceSettings.markERC721Token(
                    _contractAddress,
                    _tokenId,
                    _hasSold
                );
            }
            function markTokensAsSold(
                address _originContract,
                uint256[] calldata _tokenIds
            ) external {
                require(
                    hasRole(TOKEN_MARK_ROLE, msg.sender),
                    "markERC721Token::Must have TOKEN_MARK_ROLE role to call method"
                );
                // limit to batches of 2000
                require(
                    _tokenIds.length <= 2000,
                    "markTokensAsSold::Attempted to mark more than 2000 tokens as sold"
                );
                // Mark provided tokens as sold.
                for (uint256 i = 0; i < _tokenIds.length; i++) {
                    markERC721Token(_originContract, _tokenIds[i], true);
                }
            }
            function markContractAsSold(address _contractAddress)
                external
                returns (bool)
            {
                require(
                    hasRole(TOKEN_MARK_ROLE, msg.sender),
                    "markContract::Must have TOKEN_MARK_ROLE role to call method"
                );
                // Prevents contract address from being marked multiple times
                require(
                    !contractSold.contains(_contractAddress),
                    "markContract::Contract already marked as sold"
                );
                // Adds contract address to set
                return contractSold.add(_contractAddress);
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity 0.8.10;
        /**
         * @title IMarketplaceSettings Settings governing a marketplace.
         */
        interface IMarketplaceSettings {
            /////////////////////////////////////////////////////////////////////////
            // Marketplace Min and Max Values
            /////////////////////////////////////////////////////////////////////////
            /**
             * @dev Get the max value to be used with the marketplace.
             * @return uint256 wei value.
             */
            function getMarketplaceMaxValue() external view returns (uint256);
            /**
             * @dev Get the max value to be used with the marketplace.
             * @return uint256 wei value.
             */
            function getMarketplaceMinValue() external view returns (uint256);
            /////////////////////////////////////////////////////////////////////////
            // Marketplace Fee
            /////////////////////////////////////////////////////////////////////////
            /**
             * @dev Get the marketplace fee percentage.
             * @return uint8 wei fee.
             */
            function getMarketplaceFeePercentage() external view returns (uint8);
            /**
             * @dev Utility function for calculating the marketplace fee for given amount of wei.
             * @param _amount uint256 wei amount.
             * @return uint256 wei fee.
             */
            function calculateMarketplaceFee(uint256 _amount)
                external
                view
                returns (uint256);
            /////////////////////////////////////////////////////////////////////////
            // Primary Sale Fee
            /////////////////////////////////////////////////////////////////////////
            /**
             * @dev Get the primary sale fee percentage for a specific ERC721 contract.
             * @param _contractAddress address ERC721Contract address.
             * @return uint8 wei primary sale fee.
             */
            function getERC721ContractPrimarySaleFeePercentage(address _contractAddress)
                external
                view
                returns (uint8);
            /**
             * @dev Utility function for calculating the primary sale fee for given amount of wei
             * @param _contractAddress address ERC721Contract address.
             * @param _amount uint256 wei amount.
             * @return uint256 wei fee.
             */
            function calculatePrimarySaleFee(address _contractAddress, uint256 _amount)
                external
                view
                returns (uint256);
            /**
             * @dev Check whether the ERC721 token has sold at least once.
             * @param _contractAddress address ERC721Contract address.
             * @param _tokenId uint256 token ID.
             * @return bool of whether the token has sold.
             */
            function hasERC721TokenSold(address _contractAddress, uint256 _tokenId)
                external
                view
                returns (bool);
            /**
             * @dev Mark a token as sold.
             * Requirements:
             *
             * - `_contractAddress` cannot be the zero address.
             * @param _contractAddress address ERC721Contract address.
             * @param _tokenId uint256 token ID.
             * @param _hasSold bool of whether the token should be marked sold or not.
             */
            function markERC721Token(
                address _contractAddress,
                uint256 _tokenId,
                bool _hasSold
            ) external;
            function setERC721ContractPrimarySaleFeePercentage(
                address _contractAddress,
                uint8 _percentage
            ) external;
        }
        // SPDX-License-Identifier: MIT
        // OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)
        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() {
                _transferOwnership(_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 {
                _transferOwnership(address(0));
            }
            /**
             * @dev Transfers ownership of the contract to a new account (`newOwner`).
             * Can only be called by the current owner.
             */
            function transferOwnership(address newOwner) public virtual onlyOwner {
                require(newOwner != address(0), "Ownable: new owner is the zero address");
                _transferOwnership(newOwner);
            }
            /**
             * @dev Transfers ownership of the contract to a new account (`newOwner`).
             * Internal function without access restriction.
             */
            function _transferOwnership(address newOwner) internal virtual {
                address oldOwner = _owner;
                _owner = newOwner;
                emit OwnershipTransferred(oldOwner, newOwner);
            }
        }
        // SPDX-License-Identifier: MIT
        // OpenZeppelin Contracts (last updated v4.6.0) (access/AccessControl.sol)
        pragma solidity ^0.8.0;
        import "./IAccessControl.sol";
        import "../utils/Context.sol";
        import "../utils/Strings.sol";
        import "../utils/introspection/ERC165.sol";
        /**
         * @dev Contract module that allows children to implement role-based access
         * control mechanisms. This is a lightweight version that doesn't allow enumerating role
         * members except through off-chain means by accessing the contract event logs. Some
         * applications may benefit from on-chain enumerability, for those cases see
         * {AccessControlEnumerable}.
         *
         * Roles are referred to by their `bytes32` identifier. These should be exposed
         * in the external API and be unique. The best way to achieve this is by
         * using `public constant` hash digests:
         *
         * ```
         * bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
         * ```
         *
         * Roles can be used to represent a set of permissions. To restrict access to a
         * function call, use {hasRole}:
         *
         * ```
         * function foo() public {
         *     require(hasRole(MY_ROLE, msg.sender));
         *     ...
         * }
         * ```
         *
         * Roles can be granted and revoked dynamically via the {grantRole} and
         * {revokeRole} functions. Each role has an associated admin role, and only
         * accounts that have a role's admin role can call {grantRole} and {revokeRole}.
         *
         * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
         * that only accounts with this role will be able to grant or revoke other
         * roles. More complex role relationships can be created by using
         * {_setRoleAdmin}.
         *
         * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
         * grant and revoke this role. Extra precautions should be taken to secure
         * accounts that have been granted it.
         */
        abstract contract AccessControl is Context, IAccessControl, ERC165 {
            struct RoleData {
                mapping(address => bool) members;
                bytes32 adminRole;
            }
            mapping(bytes32 => RoleData) private _roles;
            bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
            /**
             * @dev Modifier that checks that an account has a specific role. Reverts
             * with a standardized message including the required role.
             *
             * The format of the revert reason is given by the following regular expression:
             *
             *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
             *
             * _Available since v4.1._
             */
            modifier onlyRole(bytes32 role) {
                _checkRole(role);
                _;
            }
            /**
             * @dev See {IERC165-supportsInterface}.
             */
            function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
                return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
            }
            /**
             * @dev Returns `true` if `account` has been granted `role`.
             */
            function hasRole(bytes32 role, address account) public view virtual override returns (bool) {
                return _roles[role].members[account];
            }
            /**
             * @dev Revert with a standard message if `_msgSender()` is missing `role`.
             * Overriding this function changes the behavior of the {onlyRole} modifier.
             *
             * Format of the revert message is described in {_checkRole}.
             *
             * _Available since v4.6._
             */
            function _checkRole(bytes32 role) internal view virtual {
                _checkRole(role, _msgSender());
            }
            /**
             * @dev Revert with a standard message if `account` is missing `role`.
             *
             * The format of the revert reason is given by the following regular expression:
             *
             *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
             */
            function _checkRole(bytes32 role, address account) internal view virtual {
                if (!hasRole(role, account)) {
                    revert(
                        string(
                            abi.encodePacked(
                                "AccessControl: account ",
                                Strings.toHexString(uint160(account), 20),
                                " is missing role ",
                                Strings.toHexString(uint256(role), 32)
                            )
                        )
                    );
                }
            }
            /**
             * @dev Returns the admin role that controls `role`. See {grantRole} and
             * {revokeRole}.
             *
             * To change a role's admin, use {_setRoleAdmin}.
             */
            function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {
                return _roles[role].adminRole;
            }
            /**
             * @dev Grants `role` to `account`.
             *
             * If `account` had not been already granted `role`, emits a {RoleGranted}
             * event.
             *
             * Requirements:
             *
             * - the caller must have ``role``'s admin role.
             */
            function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
                _grantRole(role, account);
            }
            /**
             * @dev Revokes `role` from `account`.
             *
             * If `account` had been granted `role`, emits a {RoleRevoked} event.
             *
             * Requirements:
             *
             * - the caller must have ``role``'s admin role.
             */
            function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
                _revokeRole(role, account);
            }
            /**
             * @dev Revokes `role` from the calling account.
             *
             * Roles are often managed via {grantRole} and {revokeRole}: this function's
             * purpose is to provide a mechanism for accounts to lose their privileges
             * if they are compromised (such as when a trusted device is misplaced).
             *
             * If the calling account had been revoked `role`, emits a {RoleRevoked}
             * event.
             *
             * Requirements:
             *
             * - the caller must be `account`.
             */
            function renounceRole(bytes32 role, address account) public virtual override {
                require(account == _msgSender(), "AccessControl: can only renounce roles for self");
                _revokeRole(role, account);
            }
            /**
             * @dev Grants `role` to `account`.
             *
             * If `account` had not been already granted `role`, emits a {RoleGranted}
             * event. Note that unlike {grantRole}, this function doesn't perform any
             * checks on the calling account.
             *
             * [WARNING]
             * ====
             * This function should only be called from the constructor when setting
             * up the initial roles for the system.
             *
             * Using this function in any other way is effectively circumventing the admin
             * system imposed by {AccessControl}.
             * ====
             *
             * NOTE: This function is deprecated in favor of {_grantRole}.
             */
            function _setupRole(bytes32 role, address account) internal virtual {
                _grantRole(role, account);
            }
            /**
             * @dev Sets `adminRole` as ``role``'s admin role.
             *
             * Emits a {RoleAdminChanged} event.
             */
            function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
                bytes32 previousAdminRole = getRoleAdmin(role);
                _roles[role].adminRole = adminRole;
                emit RoleAdminChanged(role, previousAdminRole, adminRole);
            }
            /**
             * @dev Grants `role` to `account`.
             *
             * Internal function without access restriction.
             */
            function _grantRole(bytes32 role, address account) internal virtual {
                if (!hasRole(role, account)) {
                    _roles[role].members[account] = true;
                    emit RoleGranted(role, account, _msgSender());
                }
            }
            /**
             * @dev Revokes `role` from `account`.
             *
             * Internal function without access restriction.
             */
            function _revokeRole(bytes32 role, address account) internal virtual {
                if (hasRole(role, account)) {
                    _roles[role].members[account] = false;
                    emit RoleRevoked(role, account, _msgSender());
                }
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity 0.8.10;
        interface ITokenCreator {
            // bytes4(keccak256(tokenCreator(uint256))) == 0x40c1a064
            function tokenCreator(uint256 _tokenId)
                external
                view
                returns (address payable);
        }
        // SPDX-License-Identifier: MIT
        // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721.sol)
        pragma solidity ^0.8.0;
        import "../../utils/introspection/IERC165.sol";
        /**
         * @dev Required interface of an ERC721 compliant contract.
         */
        interface IERC721 is IERC165 {
            /**
             * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
             */
            event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
            /**
             * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
             */
            event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
            /**
             * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
             */
            event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
            /**
             * @dev Returns the number of tokens in ``owner``'s account.
             */
            function balanceOf(address owner) external view returns (uint256 balance);
            /**
             * @dev Returns the owner of the `tokenId` token.
             *
             * Requirements:
             *
             * - `tokenId` must exist.
             */
            function ownerOf(uint256 tokenId) external view returns (address owner);
            /**
             * @dev Safely transfers `tokenId` token from `from` to `to`.
             *
             * Requirements:
             *
             * - `from` cannot be the zero address.
             * - `to` cannot be the zero address.
             * - `tokenId` token must exist and be owned by `from`.
             * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
             * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
             *
             * Emits a {Transfer} event.
             */
            function safeTransferFrom(
                address from,
                address to,
                uint256 tokenId,
                bytes calldata data
            ) external;
            /**
             * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
             * are aware of the ERC721 protocol to prevent tokens from being forever locked.
             *
             * Requirements:
             *
             * - `from` cannot be the zero address.
             * - `to` cannot be the zero address.
             * - `tokenId` token must exist and be owned by `from`.
             * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
             * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
             *
             * Emits a {Transfer} event.
             */
            function safeTransferFrom(
                address from,
                address to,
                uint256 tokenId
            ) external;
            /**
             * @dev Transfers `tokenId` token from `from` to `to`.
             *
             * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
             *
             * Requirements:
             *
             * - `from` cannot be the zero address.
             * - `to` cannot be the zero address.
             * - `tokenId` token must be owned by `from`.
             * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
             *
             * Emits a {Transfer} event.
             */
            function transferFrom(
                address from,
                address to,
                uint256 tokenId
            ) external;
            /**
             * @dev Gives permission to `to` to transfer `tokenId` token to another account.
             * The approval is cleared when the token is transferred.
             *
             * Only a single account can be approved at a time, so approving the zero address clears previous approvals.
             *
             * Requirements:
             *
             * - The caller must own the token or be an approved operator.
             * - `tokenId` must exist.
             *
             * Emits an {Approval} event.
             */
            function approve(address to, uint256 tokenId) external;
            /**
             * @dev Approve or remove `operator` as an operator for the caller.
             * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
             *
             * Requirements:
             *
             * - The `operator` cannot be the caller.
             *
             * Emits an {ApprovalForAll} event.
             */
            function setApprovalForAll(address operator, bool _approved) external;
            /**
             * @dev Returns the account approved for `tokenId` token.
             *
             * Requirements:
             *
             * - `tokenId` must exist.
             */
            function getApproved(uint256 tokenId) external view returns (address operator);
            /**
             * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
             *
             * See {setApprovalForAll}
             */
            function isApprovedForAll(address owner, address operator) external view returns (bool);
        }
        // SPDX-License-Identifier: MIT
        // OpenZeppelin Contracts (last updated v4.6.0) (utils/structs/EnumerableSet.sol)
        pragma solidity ^0.8.0;
        /**
         * @dev Library for managing
         * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
         * types.
         *
         * Sets have the following properties:
         *
         * - Elements are added, removed, and checked for existence in constant time
         * (O(1)).
         * - Elements are enumerated in O(n). No guarantees are made on the ordering.
         *
         * ```
         * contract Example {
         *     // Add the library methods
         *     using EnumerableSet for EnumerableSet.AddressSet;
         *
         *     // Declare a set state variable
         *     EnumerableSet.AddressSet private mySet;
         * }
         * ```
         *
         * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
         * and `uint256` (`UintSet`) are supported.
         */
        library EnumerableSet {
            // To implement this library for multiple types with as little code
            // repetition as possible, we write it in terms of a generic Set type with
            // bytes32 values.
            // The Set implementation uses private functions, and user-facing
            // implementations (such as AddressSet) are just wrappers around the
            // underlying Set.
            // This means that we can only create new EnumerableSets for types that fit
            // in bytes32.
            struct Set {
                // Storage of set values
                bytes32[] _values;
                // Position of the value in the `values` array, plus 1 because index 0
                // means a value is not in the set.
                mapping(bytes32 => uint256) _indexes;
            }
            /**
             * @dev Add a value to a set. O(1).
             *
             * Returns true if the value was added to the set, that is if it was not
             * already present.
             */
            function _add(Set storage set, bytes32 value) private returns (bool) {
                if (!_contains(set, value)) {
                    set._values.push(value);
                    // The value is stored at length-1, but we add 1 to all indexes
                    // and use 0 as a sentinel value
                    set._indexes[value] = set._values.length;
                    return true;
                } else {
                    return false;
                }
            }
            /**
             * @dev Removes a value from a set. O(1).
             *
             * Returns true if the value was removed from the set, that is if it was
             * present.
             */
            function _remove(Set storage set, bytes32 value) private returns (bool) {
                // We read and store the value's index to prevent multiple reads from the same storage slot
                uint256 valueIndex = set._indexes[value];
                if (valueIndex != 0) {
                    // Equivalent to contains(set, value)
                    // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
                    // the array, and then remove the last element (sometimes called as 'swap and pop').
                    // This modifies the order of the array, as noted in {at}.
                    uint256 toDeleteIndex = valueIndex - 1;
                    uint256 lastIndex = set._values.length - 1;
                    if (lastIndex != toDeleteIndex) {
                        bytes32 lastValue = set._values[lastIndex];
                        // Move the last value to the index where the value to delete is
                        set._values[toDeleteIndex] = lastValue;
                        // Update the index for the moved value
                        set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
                    }
                    // Delete the slot where the moved value was stored
                    set._values.pop();
                    // Delete the index for the deleted slot
                    delete set._indexes[value];
                    return true;
                } else {
                    return false;
                }
            }
            /**
             * @dev Returns true if the value is in the set. O(1).
             */
            function _contains(Set storage set, bytes32 value) private view returns (bool) {
                return set._indexes[value] != 0;
            }
            /**
             * @dev Returns the number of values on the set. O(1).
             */
            function _length(Set storage set) private view returns (uint256) {
                return set._values.length;
            }
            /**
             * @dev Returns the value stored at position `index` in the set. O(1).
             *
             * Note that there are no guarantees on the ordering of values inside the
             * array, and it may change when more values are added or removed.
             *
             * Requirements:
             *
             * - `index` must be strictly less than {length}.
             */
            function _at(Set storage set, uint256 index) private view returns (bytes32) {
                return set._values[index];
            }
            /**
             * @dev Return the entire set in an array
             *
             * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
             * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
             * this function has an unbounded cost, and using it as part of a state-changing function may render the function
             * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
             */
            function _values(Set storage set) private view returns (bytes32[] memory) {
                return set._values;
            }
            // Bytes32Set
            struct Bytes32Set {
                Set _inner;
            }
            /**
             * @dev Add a value to a set. O(1).
             *
             * Returns true if the value was added to the set, that is if it was not
             * already present.
             */
            function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
                return _add(set._inner, value);
            }
            /**
             * @dev Removes a value from a set. O(1).
             *
             * Returns true if the value was removed from the set, that is if it was
             * present.
             */
            function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
                return _remove(set._inner, value);
            }
            /**
             * @dev Returns true if the value is in the set. O(1).
             */
            function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
                return _contains(set._inner, value);
            }
            /**
             * @dev Returns the number of values in the set. O(1).
             */
            function length(Bytes32Set storage set) internal view returns (uint256) {
                return _length(set._inner);
            }
            /**
             * @dev Returns the value stored at position `index` in the set. O(1).
             *
             * Note that there are no guarantees on the ordering of values inside the
             * array, and it may change when more values are added or removed.
             *
             * Requirements:
             *
             * - `index` must be strictly less than {length}.
             */
            function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
                return _at(set._inner, index);
            }
            /**
             * @dev Return the entire set in an array
             *
             * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
             * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
             * this function has an unbounded cost, and using it as part of a state-changing function may render the function
             * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
             */
            function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
                return _values(set._inner);
            }
            // AddressSet
            struct AddressSet {
                Set _inner;
            }
            /**
             * @dev Add a value to a set. O(1).
             *
             * Returns true if the value was added to the set, that is if it was not
             * already present.
             */
            function add(AddressSet storage set, address value) internal returns (bool) {
                return _add(set._inner, bytes32(uint256(uint160(value))));
            }
            /**
             * @dev Removes a value from a set. O(1).
             *
             * Returns true if the value was removed from the set, that is if it was
             * present.
             */
            function remove(AddressSet storage set, address value) internal returns (bool) {
                return _remove(set._inner, bytes32(uint256(uint160(value))));
            }
            /**
             * @dev Returns true if the value is in the set. O(1).
             */
            function contains(AddressSet storage set, address value) internal view returns (bool) {
                return _contains(set._inner, bytes32(uint256(uint160(value))));
            }
            /**
             * @dev Returns the number of values in the set. O(1).
             */
            function length(AddressSet storage set) internal view returns (uint256) {
                return _length(set._inner);
            }
            /**
             * @dev Returns the value stored at position `index` in the set. O(1).
             *
             * Note that there are no guarantees on the ordering of values inside the
             * array, and it may change when more values are added or removed.
             *
             * Requirements:
             *
             * - `index` must be strictly less than {length}.
             */
            function at(AddressSet storage set, uint256 index) internal view returns (address) {
                return address(uint160(uint256(_at(set._inner, index))));
            }
            /**
             * @dev Return the entire set in an array
             *
             * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
             * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
             * this function has an unbounded cost, and using it as part of a state-changing function may render the function
             * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
             */
            function values(AddressSet storage set) internal view returns (address[] memory) {
                bytes32[] memory store = _values(set._inner);
                address[] memory result;
                assembly {
                    result := store
                }
                return result;
            }
            // UintSet
            struct UintSet {
                Set _inner;
            }
            /**
             * @dev Add a value to a set. O(1).
             *
             * Returns true if the value was added to the set, that is if it was not
             * already present.
             */
            function add(UintSet storage set, uint256 value) internal returns (bool) {
                return _add(set._inner, bytes32(value));
            }
            /**
             * @dev Removes a value from a set. O(1).
             *
             * Returns true if the value was removed from the set, that is if it was
             * present.
             */
            function remove(UintSet storage set, uint256 value) internal returns (bool) {
                return _remove(set._inner, bytes32(value));
            }
            /**
             * @dev Returns true if the value is in the set. O(1).
             */
            function contains(UintSet storage set, uint256 value) internal view returns (bool) {
                return _contains(set._inner, bytes32(value));
            }
            /**
             * @dev Returns the number of values on the set. O(1).
             */
            function length(UintSet storage set) internal view returns (uint256) {
                return _length(set._inner);
            }
            /**
             * @dev Returns the value stored at position `index` in the set. O(1).
             *
             * Note that there are no guarantees on the ordering of values inside the
             * array, and it may change when more values are added or removed.
             *
             * Requirements:
             *
             * - `index` must be strictly less than {length}.
             */
            function at(UintSet storage set, uint256 index) internal view returns (uint256) {
                return uint256(_at(set._inner, index));
            }
            /**
             * @dev Return the entire set in an array
             *
             * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
             * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
             * this function has an unbounded cost, and using it as part of a state-changing function may render the function
             * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
             */
            function values(UintSet storage set) internal view returns (uint256[] memory) {
                bytes32[] memory store = _values(set._inner);
                uint256[] memory result;
                assembly {
                    result := store
                }
                return result;
            }
        }
        // SPDX-License-Identifier: MIT
        // OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
        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) {
                return msg.data;
            }
        }
        // SPDX-License-Identifier: MIT
        // OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)
        pragma solidity ^0.8.0;
        /**
         * @dev External interface of AccessControl declared to support ERC165 detection.
         */
        interface IAccessControl {
            /**
             * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
             *
             * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
             * {RoleAdminChanged} not being emitted signaling this.
             *
             * _Available since v3.1._
             */
            event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
            /**
             * @dev Emitted when `account` is granted `role`.
             *
             * `sender` is the account that originated the contract call, an admin role
             * bearer except when using {AccessControl-_setupRole}.
             */
            event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
            /**
             * @dev Emitted when `account` is revoked `role`.
             *
             * `sender` is the account that originated the contract call:
             *   - if using `revokeRole`, it is the admin role bearer
             *   - if using `renounceRole`, it is the role bearer (i.e. `account`)
             */
            event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
            /**
             * @dev Returns `true` if `account` has been granted `role`.
             */
            function hasRole(bytes32 role, address account) external view returns (bool);
            /**
             * @dev Returns the admin role that controls `role`. See {grantRole} and
             * {revokeRole}.
             *
             * To change a role's admin, use {AccessControl-_setRoleAdmin}.
             */
            function getRoleAdmin(bytes32 role) external view returns (bytes32);
            /**
             * @dev Grants `role` to `account`.
             *
             * If `account` had not been already granted `role`, emits a {RoleGranted}
             * event.
             *
             * Requirements:
             *
             * - the caller must have ``role``'s admin role.
             */
            function grantRole(bytes32 role, address account) external;
            /**
             * @dev Revokes `role` from `account`.
             *
             * If `account` had been granted `role`, emits a {RoleRevoked} event.
             *
             * Requirements:
             *
             * - the caller must have ``role``'s admin role.
             */
            function revokeRole(bytes32 role, address account) external;
            /**
             * @dev Revokes `role` from the calling account.
             *
             * Roles are often managed via {grantRole} and {revokeRole}: this function's
             * purpose is to provide a mechanism for accounts to lose their privileges
             * if they are compromised (such as when a trusted device is misplaced).
             *
             * If the calling account had been granted `role`, emits a {RoleRevoked}
             * event.
             *
             * Requirements:
             *
             * - the caller must be `account`.
             */
            function renounceRole(bytes32 role, address account) external;
        }
        // SPDX-License-Identifier: MIT
        // OpenZeppelin Contracts v4.4.1 (utils/Strings.sol)
        pragma solidity ^0.8.0;
        /**
         * @dev String operations.
         */
        library Strings {
            bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
            /**
             * @dev Converts a `uint256` to its ASCII `string` decimal representation.
             */
            function toString(uint256 value) internal pure returns (string memory) {
                // Inspired by OraclizeAPI's implementation - MIT licence
                // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
                if (value == 0) {
                    return "0";
                }
                uint256 temp = value;
                uint256 digits;
                while (temp != 0) {
                    digits++;
                    temp /= 10;
                }
                bytes memory buffer = new bytes(digits);
                while (value != 0) {
                    digits -= 1;
                    buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
                    value /= 10;
                }
                return string(buffer);
            }
            /**
             * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
             */
            function toHexString(uint256 value) internal pure returns (string memory) {
                if (value == 0) {
                    return "0x00";
                }
                uint256 temp = value;
                uint256 length = 0;
                while (temp != 0) {
                    length++;
                    temp >>= 8;
                }
                return toHexString(value, length);
            }
            /**
             * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
             */
            function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
                bytes memory buffer = new bytes(2 * length + 2);
                buffer[0] = "0";
                buffer[1] = "x";
                for (uint256 i = 2 * length + 1; i > 1; --i) {
                    buffer[i] = _HEX_SYMBOLS[value & 0xf];
                    value >>= 4;
                }
                require(value == 0, "Strings: hex length insufficient");
                return string(buffer);
            }
        }
        // SPDX-License-Identifier: MIT
        // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
        pragma solidity ^0.8.0;
        import "./IERC165.sol";
        /**
         * @dev Implementation of the {IERC165} interface.
         *
         * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
         * for the additional interface id that will be supported. For example:
         *
         * ```solidity
         * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
         *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
         * }
         * ```
         *
         * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
         */
        abstract contract ERC165 is IERC165 {
            /**
             * @dev See {IERC165-supportsInterface}.
             */
            function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
                return interfaceId == type(IERC165).interfaceId;
            }
        }
        // SPDX-License-Identifier: MIT
        // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
        pragma solidity ^0.8.0;
        /**
         * @dev Interface of the ERC165 standard, as defined in the
         * https://eips.ethereum.org/EIPS/eip-165[EIP].
         *
         * 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
             * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
             * 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 4 of 5: SuperRareV2
        pragma solidity ^0.4.24;
        
        /**
         * @title SafeMath
         * @dev Math operations with safety checks that revert on error
         */
        library SafeMath {
        
          /**
          * @dev Multiplies two numbers, reverts on 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-solidity/pull/522
            if (a == 0) {
              return 0;
            }
        
            uint256 c = a * b;
            require(c / a == b);
        
            return c;
          }
        
          /**
          * @dev Integer division of two numbers truncating the quotient, reverts on division by zero.
          */
          function div(uint256 a, uint256 b) internal pure returns (uint256) {
            require(b > 0); // Solidity only automatically asserts when dividing by 0
            uint256 c = a / b;
            // assert(a == b * c + a % b); // There is no case in which this doesn't hold
        
            return c;
          }
        
          /**
          * @dev Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend).
          */
          function sub(uint256 a, uint256 b) internal pure returns (uint256) {
            require(b <= a);
            uint256 c = a - b;
        
            return c;
          }
        
          /**
          * @dev Adds two numbers, reverts on overflow.
          */
          function add(uint256 a, uint256 b) internal pure returns (uint256) {
            uint256 c = a + b;
            require(c >= a);
        
            return c;
          }
        
          /**
          * @dev Divides two numbers and returns the remainder (unsigned integer modulo),
          * reverts when dividing by zero.
          */
          function mod(uint256 a, uint256 b) internal pure returns (uint256) {
            require(b != 0);
            return a % b;
          }
        }
        
        interface IERC165 {
        
          /**
           * @notice Query if a contract implements an interface
           * @param interfaceId The interface identifier, as specified in ERC-165
           * @dev Interface identification is specified in ERC-165. This function
           * uses less than 30,000 gas.
           */
          function supportsInterface(bytes4 interfaceId)
            external
            view
            returns (bool);
        }
        
        interface ISuperRare {
          /**
           * @notice A descriptive name for a collection of NFTs in this contract
           */
          function name() external pure returns (string _name);
        
          /**
           * @notice An abbreviated name for NFTs in this contract
           */
          function symbol() external pure returns (string _symbol);
        
          /** 
           * @dev Returns whether the creator is whitelisted
           * @param _creator address to check
           * @return bool 
           */
          function isWhitelisted(address _creator) external view returns (bool);
        
          /** 
           * @notice A distinct Uniform Resource Identifier (URI) for a given asset.
           * @dev Throws if `_tokenId` is not a valid NFT. URIs are defined in RFC
           * 3986. The URI may point to a JSON file that conforms to the "ERC721
           * Metadata JSON Schema".
           */
          function tokenURI(uint256 _tokenId) external view returns (string);
        
          /**
          * @dev Gets the creator of the token
          * @param _tokenId uint256 ID of the token
          * @return address of the creator
          */
          function creatorOfToken(uint256 _tokenId) public view returns (address);
        
          /**
          * @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);
        }
        
        /**
         * @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(keccak256("onERC721Received(address,address,uint256,bytes)"))`
           */
          function onERC721Received(
            address operator,
            address from,
            uint256 tokenId,
            bytes data
          )
            public
            returns(bytes4);
        }
        
        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
          );
        
          function balanceOf(address owner) public view returns (uint256 balance);
          function ownerOf(uint256 tokenId) public view returns (address owner);
        
          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 transferFrom(address from, address to, uint256 tokenId) public;
          function safeTransferFrom(address from, address to, uint256 tokenId)
            public;
        
          function safeTransferFrom(
            address from,
            address to,
            uint256 tokenId,
            bytes data
          )
            public;
        }
        
        contract IERC721Creator is IERC721 {
            /**
           * @dev Gets the creator of the token
           * @param _tokenId uint256 ID of the token
           * @return address of the creator
           */
            function tokenCreator(uint256 _tokenId) public view returns (address);
        }
        
        /**
         * @title ERC-721 Non-Fungible Token Standard, optional metadata extension
         * @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
         */
        contract IERC721Metadata is IERC721 {
          function name() external view returns (string);
          function symbol() external view returns (string);
          function tokenURI(uint256 tokenId) external view returns (string);
        }
        
        /**
         * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
         * @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
         */
        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);
        }
        
        /**
         * Utility library of inline functions on addresses
         */
        library Address {
        
          /**
           * Returns whether the target address is a contract
           * @dev This function will return false if invoked during the constructor of a contract,
           * as the code is not actually created until after the constructor finishes.
           * @param account address of the account to check
           * @return whether the target address is a contract
           */
          function isContract(address account) internal view returns (bool) {
            uint256 size;
            // XXX Currently there is no better way to check if there is a contract in an address
            // than to check the size of the code at that address.
            // See https://ethereum.stackexchange.com/a/14016/36603
            // for more details about how this works.
            // TODO Check this again before the Serenity release, because all addresses will be
            // contracts then.
            // solium-disable-next-line security/no-inline-assembly
            assembly { size := extcodesize(account) }
            return size > 0;
          }
        
        }
        
        /**
         * @title ERC165
         * @author Matt Condon (@shrugs)
         * @dev Implements ERC165 using a lookup table.
         */
        contract ERC165 is IERC165 {
        
          bytes4 private constant _InterfaceId_ERC165 = 0x01ffc9a7;
          /**
           * 0x01ffc9a7 ===
           *   bytes4(keccak256('supportsInterface(bytes4)'))
           */
        
          /**
           * @dev a mapping of interface id to whether or not it's supported
           */
          mapping(bytes4 => bool) private _supportedInterfaces;
        
          /**
           * @dev A contract implementing SupportsInterfaceWithLookup
           * implement ERC165 itself
           */
          constructor()
            internal
          {
            _registerInterface(_InterfaceId_ERC165);
          }
        
          /**
           * @dev implement supportsInterface(bytes4) using a lookup table
           */
          function supportsInterface(bytes4 interfaceId)
            external
            view
            returns (bool)
          {
            return _supportedInterfaces[interfaceId];
          }
        
          /**
           * @dev internal method for registering an interface
           */
          function _registerInterface(bytes4 interfaceId)
            internal
          {
            require(interfaceId != 0xffffffff);
            _supportedInterfaces[interfaceId] = true;
          }
        }
        
        /**
         * @title ERC721 Non-Fungible Token Standard basic implementation
         * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
         */
        contract ERC721 is ERC165, IERC721 {
        
          using SafeMath for uint256;
          using Address for address;
        
          // 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 => uint256) private _ownedTokensCount;
        
          // Mapping from owner to operator approvals
          mapping (address => mapping (address => bool)) private _operatorApprovals;
        
          bytes4 private constant _InterfaceId_ERC721 = 0x80ac58cd;
          /*
           * 0x80ac58cd ===
           *   bytes4(keccak256('balanceOf(address)')) ^
           *   bytes4(keccak256('ownerOf(uint256)')) ^
           *   bytes4(keccak256('approve(address,uint256)')) ^
           *   bytes4(keccak256('getApproved(uint256)')) ^
           *   bytes4(keccak256('setApprovalForAll(address,bool)')) ^
           *   bytes4(keccak256('isApprovedForAll(address,address)')) ^
           *   bytes4(keccak256('transferFrom(address,address,uint256)')) ^
           *   bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^
           *   bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)'))
           */
        
          constructor()
            public
          {
            // register the supported interfaces to conform to ERC721 via ERC165
            _registerInterface(_InterfaceId_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));
            return _ownedTokensCount[owner];
          }
        
          /**
           * @dev Gets the owner of the specified token ID
           * @param tokenId uint256 ID of the token to query the owner of
           * @return owner 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));
            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);
            require(msg.sender == owner || isApprovedForAll(owner, msg.sender));
        
            _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));
            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);
            _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
          {
            require(_isApprovedOrOwner(msg.sender, tokenId));
            require(to != address(0));
        
            _clearApproval(from, tokenId);
            _removeTokenFrom(from, tokenId);
            _addTokenTo(to, tokenId);
        
            emit Transfer(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
          {
            // solium-disable-next-line arg-overflow
            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 _data
          )
            public
          {
            transferFrom(from, to, tokenId);
            // solium-disable-next-line arg-overflow
            require(_checkOnERC721Received(from, to, tokenId, _data));
          }
        
          /**
           * @dev Returns whether the specified token exists
           * @param tokenId uint256 ID of the token to query the existence of
           * @return 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)
          {
            address owner = ownerOf(tokenId);
            // Disable solium check because of
            // https://github.com/duaraghav8/Solium/issues/175
            // solium-disable-next-line operator-whitespace
            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 by the msg.sender
           */
          function _mint(address to, uint256 tokenId) internal {
            require(to != address(0));
            _addTokenTo(to, tokenId);
            emit Transfer(address(0), to, 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 by the msg.sender
           */
          function _burn(address owner, uint256 tokenId) internal {
            _clearApproval(owner, tokenId);
            _removeTokenFrom(owner, tokenId);
            emit Transfer(owner, address(0), tokenId);
          }
        
          /**
           * @dev Internal function to add a token ID to the list of a given address
           * Note that this function is left internal to make ERC721Enumerable possible, but is not
           * intended to be called by custom derived contracts: in particular, it emits no Transfer event.
           * @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 _addTokenTo(address to, uint256 tokenId) internal {
            require(_tokenOwner[tokenId] == address(0));
            _tokenOwner[tokenId] = to;
            _ownedTokensCount[to] = _ownedTokensCount[to].add(1);
          }
        
          /**
           * @dev Internal function to remove a token ID from the list of a given address
           * Note that this function is left internal to make ERC721Enumerable possible, but is not
           * intended to be called by custom derived contracts: in particular, it emits no Transfer event,
           * and doesn't clear approvals.
           * @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 _removeTokenFrom(address from, uint256 tokenId) internal {
            require(ownerOf(tokenId) == from);
            _ownedTokensCount[from] = _ownedTokensCount[from].sub(1);
            _tokenOwner[tokenId] = address(0);
          }
        
          /**
           * @dev Internal function to invoke `onERC721Received` on a target address
           * The call is not executed if the target address is not a contract
           * @param from address representing the previous owner of the given token ID
           * @param to target address that will receive the tokens
           * @param tokenId uint256 ID of the token to be transferred
           * @param _data bytes optional data to send along with the call
           * @return whether the call correctly returned the expected magic value
           */
          function _checkOnERC721Received(
            address from,
            address to,
            uint256 tokenId,
            bytes _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
           * Reverts if the given address is not indeed the owner of the token
           * @param owner owner of the token
           * @param tokenId uint256 ID of the token to be transferred
           */
          function _clearApproval(address owner, uint256 tokenId) private {
            require(ownerOf(tokenId) == owner);
            if (_tokenApprovals[tokenId] != address(0)) {
              _tokenApprovals[tokenId] = address(0);
            }
          }
        }
        
        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 private constant _InterfaceId_ERC721Enumerable = 0x780e9d63;
          /**
           * 0x780e9d63 ===
           *   bytes4(keccak256('totalSupply()')) ^
           *   bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) ^
           *   bytes4(keccak256('tokenByIndex(uint256)'))
           */
        
          /**
           * @dev Constructor function
           */
          constructor() public {
            // register the supported interface to conform to ERC721 via ERC165
            _registerInterface(_InterfaceId_ERC721Enumerable);
          }
        
          /**
           * @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));
            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());
            return _allTokens[index];
          }
        
          /**
           * @dev Internal function to add a token ID to the list of a given address
           * This function is internal due to language limitations, see the note in ERC721.sol.
           * It is not intended to be called by custom derived contracts: in particular, it emits no Transfer event.
           * @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 _addTokenTo(address to, uint256 tokenId) internal {
            super._addTokenTo(to, tokenId);
            uint256 length = _ownedTokens[to].length;
            _ownedTokens[to].push(tokenId);
            _ownedTokensIndex[tokenId] = length;
          }
        
          /**
           * @dev Internal function to remove a token ID from the list of a given address
           * This function is internal due to language limitations, see the note in ERC721.sol.
           * It is not intended to be called by custom derived contracts: in particular, it emits no Transfer event,
           * and doesn't clear approvals.
           * @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 _removeTokenFrom(address from, uint256 tokenId) internal {
            super._removeTokenFrom(from, tokenId);
        
            // To prevent a gap in the array, we store the last token in the index of the token to delete, and
            // then delete the last slot.
            uint256 tokenIndex = _ownedTokensIndex[tokenId];
            uint256 lastTokenIndex = _ownedTokens[from].length.sub(1);
            uint256 lastToken = _ownedTokens[from][lastTokenIndex];
        
            _ownedTokens[from][tokenIndex] = lastToken;
            // This also deletes the contents at the last position of the array
            _ownedTokens[from].length--;
        
            // Note that this will handle single-element arrays. In that case, both tokenIndex and lastTokenIndex are going to
            // be zero. Then we can make sure that we will remove tokenId from the ownedTokens list since we are first swapping
            // the lastToken to the first position, and then dropping the element placed in the last position of the list
        
            _ownedTokensIndex[tokenId] = 0;
            _ownedTokensIndex[lastToken] = tokenIndex;
          }
        
          /**
           * @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 by the msg.sender
           */
          function _mint(address to, uint256 tokenId) internal {
            super._mint(to, tokenId);
        
            _allTokensIndex[tokenId] = _allTokens.length;
            _allTokens.push(tokenId);
          }
        
          /**
           * @dev Internal function to burn a specific token
           * Reverts if the token does not exist
           * @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);
        
            // Reorg all tokens array
            uint256 tokenIndex = _allTokensIndex[tokenId];
            uint256 lastTokenIndex = _allTokens.length.sub(1);
            uint256 lastToken = _allTokens[lastTokenIndex];
        
            _allTokens[tokenIndex] = lastToken;
            _allTokens[lastTokenIndex] = 0;
        
            _allTokens.length--;
            _allTokensIndex[tokenId] = 0;
            _allTokensIndex[lastToken] = tokenIndex;
          }
        }
        
        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 private constant InterfaceId_ERC721Metadata = 0x5b5e139f;
          /**
           * 0x5b5e139f ===
           *   bytes4(keccak256('name()')) ^
           *   bytes4(keccak256('symbol()')) ^
           *   bytes4(keccak256('tokenURI(uint256)'))
           */
        
          /**
           * @dev Constructor function
           */
          constructor(string name, string symbol) public {
            _name = name;
            _symbol = symbol;
        
            // register the supported interfaces to conform to ERC721 via ERC165
            _registerInterface(InterfaceId_ERC721Metadata);
          }
        
          /**
           * @dev Gets the token name
           * @return string representing the token name
           */
          function name() external view returns (string) {
            return _name;
          }
        
          /**
           * @dev Gets the token symbol
           * @return string representing the token symbol
           */
          function symbol() external view returns (string) {
            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) {
            require(_exists(tokenId));
            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 uri) internal {
            require(_exists(tokenId));
            _tokenURIs[tokenId] = uri;
          }
        
          /**
           * @dev Internal function to burn a specific token
           * Reverts if the token does not exist
           * @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];
            }
          }
        }
        
        /**
         * @title Ownable
         * @dev The Ownable contract has an owner address, and provides basic authorization control
         * functions, this simplifies the implementation of "user permissions".
         */
        contract Ownable {
          address private _owner;
        
          event OwnershipTransferred(
            address indexed previousOwner,
            address indexed newOwner
          );
        
          /**
           * @dev The Ownable constructor sets the original `owner` of the contract to the sender
           * account.
           */
          constructor() internal {
            _owner = msg.sender;
            emit OwnershipTransferred(address(0), _owner);
          }
        
          /**
           * @return the address of the owner.
           */
          function owner() public view returns(address) {
            return _owner;
          }
        
          /**
           * @dev Throws if called by any account other than the owner.
           */
          modifier onlyOwner() {
            require(isOwner());
            _;
          }
        
          /**
           * @return true if `msg.sender` is the owner of the contract.
           */
          function isOwner() public view returns(bool) {
            return msg.sender == _owner;
          }
        
          /**
           * @dev Allows the current owner to relinquish control of the contract.
           * @notice Renouncing to ownership will leave the contract without an owner.
           * It will not be possible to call the functions with the `onlyOwner`
           * modifier anymore.
           */
          function renounceOwnership() public onlyOwner {
            emit OwnershipTransferred(_owner, address(0));
            _owner = address(0);
          }
        
          /**
           * @dev Allows the current owner to transfer control of the contract to a newOwner.
           * @param newOwner The address to transfer ownership to.
           */
          function transferOwnership(address newOwner) public onlyOwner {
            _transferOwnership(newOwner);
          }
        
          /**
           * @dev Transfers control of the contract to a newOwner.
           * @param newOwner The address to transfer ownership to.
           */
          function _transferOwnership(address newOwner) internal {
            require(newOwner != address(0));
            emit OwnershipTransferred(_owner, newOwner);
            _owner = newOwner;
          }
        }
        
        contract Whitelist is Ownable {
            // Mapping of address to boolean indicating whether the address is whitelisted
            mapping(address => bool) private whitelistMap;
        
            // flag controlling whether whitelist is enabled.
            bool private whitelistEnabled = true;
        
            event AddToWhitelist(address indexed _newAddress);
            event RemoveFromWhitelist(address indexed _removedAddress);
        
            /**
           * @dev Enable or disable the whitelist
           * @param _enabled bool of whether to enable the whitelist.
           */
            function enableWhitelist(bool _enabled) public onlyOwner {
                whitelistEnabled = _enabled;
            }
        
            /**
           * @dev Adds the provided address to the whitelist
           * @param _newAddress address to be added to the whitelist
           */
            function addToWhitelist(address _newAddress) public onlyOwner {
                _whitelist(_newAddress);
                emit AddToWhitelist(_newAddress);
            }
        
            /**
           * @dev Removes the provided address to the whitelist
           * @param _removedAddress address to be removed from the whitelist
           */
            function removeFromWhitelist(address _removedAddress) public onlyOwner {
                _unWhitelist(_removedAddress);
                emit RemoveFromWhitelist(_removedAddress);
            }
        
            /**
           * @dev Returns whether the address is whitelisted
           * @param _address address to check
           * @return bool
           */
            function isWhitelisted(address _address) public view returns (bool) {
                if (whitelistEnabled) {
                    return whitelistMap[_address];
                } else {
                    return true;
                }
            }
        
            /**
           * @dev Internal function for removing an address from the whitelist
           * @param _removedAddress address to unwhitelisted
           */
            function _unWhitelist(address _removedAddress) internal {
                whitelistMap[_removedAddress] = false;
            }
        
            /**
           * @dev Internal function for adding the provided address to the whitelist
           * @param _newAddress address to be added to the whitelist
           */
            function _whitelist(address _newAddress) internal {
                whitelistMap[_newAddress] = true;
            }
        }
        
        /**
         * @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://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
         */
        contract ERC721Full is ERC721, ERC721Enumerable, ERC721Metadata {
          constructor(string name, string symbol) ERC721Metadata(name, symbol)
            public
          {
          }
        }
        
        
        contract SuperRareV2 is ERC721Full, IERC721Creator, Ownable, Whitelist {
            using SafeMath for uint256;
        
            // Mapping from token ID to the creator's address.
            mapping(uint256 => address) private tokenCreators;
        
            // Counter for creating token IDs
            uint256 private idCounter;
        
            // Old SuperRare contract to look up token details.
            ISuperRare private oldSuperRare;
        
            // Event indicating metadata was updated.
            event TokenURIUpdated(uint256 indexed _tokenId, string  _uri);
        
            constructor(
              string _name,
              string _symbol,
              address _oldSuperRare
            )
            ERC721Full(_name, _symbol)
            {
              // Get reference to old SR contract.
              oldSuperRare = ISuperRare(_oldSuperRare);
        
              uint256 oldSupply = oldSuperRare.totalSupply();
              // Set id counter to be continuous with SuperRare.
              idCounter = oldSupply + 1;
            }
        
            /**
             * @dev Whitelists a bunch of addresses.
             * @param _whitelistees address[] of addresses to whitelist.
             */
            function initWhitelist(address[] _whitelistees) public onlyOwner {
              // Add all whitelistees.
              for (uint256 i = 0; i < _whitelistees.length; i++) {
                address creator = _whitelistees[i];
                if (!isWhitelisted(creator)) {
                  _whitelist(creator);
                }
              }
            }
        
            /**
             * @dev Checks that the token is owned by the sender.
             * @param _tokenId uint256 ID of the token.
             */
            modifier onlyTokenOwner(uint256 _tokenId) {
              address owner = ownerOf(_tokenId);
              require(owner == msg.sender, "must be the owner of the token");
              _;
            }
        
            /**
             * @dev Checks that the token was created by the sender.
             * @param _tokenId uint256 ID of the token.
             */
            modifier onlyTokenCreator(uint256 _tokenId) {
              address creator = tokenCreator(_tokenId);
              require(creator == msg.sender, "must be the creator of the token");
              _;
            }
        
            /**
             * @dev Adds a new unique token to the supply.
             * @param _uri string metadata uri associated with the token.
             */
            function addNewToken(string _uri) public {
              require(isWhitelisted(msg.sender), "must be whitelisted to create tokens");
              _createToken(_uri, msg.sender);
            }
        
            /**
             * @dev Deletes the token with the provided ID.
             * @param _tokenId uint256 ID of the token.
             */
            function deleteToken(uint256 _tokenId) public onlyTokenOwner(_tokenId) {
              _burn(msg.sender, _tokenId);
            }
        
            /**
             * @dev Updates the token metadata if the owner is also the
             *      creator.
             * @param _tokenId uint256 ID of the token.
             * @param _uri string metadata URI.
             */
            function updateTokenMetadata(uint256 _tokenId, string _uri)
              public
              onlyTokenOwner(_tokenId)
              onlyTokenCreator(_tokenId)
            {
              _setTokenURI(_tokenId, _uri);
              emit TokenURIUpdated(_tokenId, _uri);
            }
        
            /**
            * @dev Gets the creator of the token.
            * @param _tokenId uint256 ID of the token.
            * @return address of the creator.
            */
            function tokenCreator(uint256 _tokenId) public view returns (address) {
                return tokenCreators[_tokenId];
            }
        
            /**
             * @dev Internal function for setting the token's creator.
             * @param _tokenId uint256 id of the token.
             * @param _creator address of the creator of the token.
             */
            function _setTokenCreator(uint256 _tokenId, address _creator) internal {
              tokenCreators[_tokenId] = _creator;
            }
        
            /**
             * @dev Internal function creating a new token.
             * @param _uri string metadata uri associated with the token
             * @param _creator address of the creator of the token.
             */
            function _createToken(string _uri, address _creator) internal returns (uint256) {
              uint256 newId = idCounter;
              idCounter++;
              _mint(_creator, newId);
              _setTokenURI(newId, _uri);
              _setTokenCreator(newId, _creator);
              return newId;
            }
        }

        File 5 of 5: Payments
        // SPDX-License-Identifier: MIT
        pragma solidity 0.7.3;
        import "@openzeppelin/contracts-0.7.2/payment/PullPayment.sol";
        import "@openzeppelin/contracts-0.7.2/math/SafeMath.sol";
        import "./IPayments.sol";
        /**
         * @title Payments contract for SuperRare Marketplaces.
         */
        contract Payments is IPayments, PullPayment {
            using SafeMath for uint256;
            /////////////////////////////////////////////////////////////////////////
            // refund
            /////////////////////////////////////////////////////////////////////////
            /**
             * @dev Internal function to refund an address. Typically for canceled bids or offers.
             * Requirements:
             *
             *  - _payee cannot be the zero address
             *
             * @param _amount uint256 value to be split.
             * @param _payee address seller of the token.
             */
            function refund(address _payee, uint256 _amount) external payable override {
                require(
                    _payee != address(0),
                    "refund::no payees can be the zero address"
                );
                require(msg.value == _amount);
                if (_amount > 0) {
                    (bool success, ) = address(_payee).call{value: _amount}("");
                    if (!success) {
                        _asyncTransfer(_payee, _amount);
                    }
                }
            }
            /////////////////////////////////////////////////////////////////////////
            // payout
            /////////////////////////////////////////////////////////////////////////
            function payout(address[] calldata _splits, uint256[] calldata _amounts)
                external
                payable
                override
            {
                uint256 totalAmount = 0;
                for (uint256 i = 0; i < _splits.length; i++) {
                    totalAmount = totalAmount.add(_amounts[i]);
                    if (_splits[i] != address(0)) {
                        (bool success, ) = address(_splits[i]).call{value: _amounts[i]}(
                            ""
                        );
                        if (!success) {
                            _asyncTransfer(_splits[i], _amounts[i]);
                        }
                    }
                }
                require(msg.value == totalAmount, "payout::not enough sent");
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity >=0.6.2 <0.8.0;
        import "./escrow/Escrow.sol";
        /**
         * @dev Simple implementation of a
         * https://consensys.github.io/smart-contract-best-practices/recommendations/#favor-pull-over-push-for-external-calls[pull-payment]
         * strategy, where the paying contract doesn't interact directly with the
         * receiver account, which must withdraw its payments itself.
         *
         * Pull-payments are often considered the best practice when it comes to sending
         * Ether, security-wise. It prevents recipients from blocking execution, and
         * eliminates reentrancy concerns.
         *
         * TIP: If you would like to learn more about reentrancy and alternative ways
         * to protect against it, check out our blog post
         * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
         *
         * To use, derive from the `PullPayment` contract, and use {_asyncTransfer}
         * instead of Solidity's `transfer` function. Payees can query their due
         * payments with {payments}, and retrieve them with {withdrawPayments}.
         */
        abstract contract PullPayment {
            Escrow private _escrow;
            constructor () internal {
                _escrow = new Escrow();
            }
            /**
             * @dev Withdraw accumulated payments, forwarding all gas to the recipient.
             *
             * Note that _any_ account can call this function, not just the `payee`.
             * This means that contracts unaware of the `PullPayment` protocol can still
             * receive funds this way, by having a separate account call
             * {withdrawPayments}.
             *
             * WARNING: Forwarding all gas opens the door to reentrancy vulnerabilities.
             * Make sure you trust the recipient, or are either following the
             * checks-effects-interactions pattern or using {ReentrancyGuard}.
             *
             * @param payee Whose payments will be withdrawn.
             */
            function withdrawPayments(address payable payee) public virtual {
                _escrow.withdraw(payee);
            }
            /**
             * @dev Returns the payments owed to an address.
             * @param dest The creditor's address.
             */
            function payments(address dest) public view returns (uint256) {
                return _escrow.depositsOf(dest);
            }
            /**
             * @dev Called by the payer to store the sent amount as credit to be pulled.
             * Funds sent in this way are stored in an intermediate {Escrow} contract, so
             * there is no danger of them being spent before withdrawal.
             *
             * @param dest The destination address of the funds.
             * @param amount The amount to transfer.
             */
            function _asyncTransfer(address dest, uint256 amount) internal virtual {
                _escrow.deposit{ value: amount }(dest);
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity >=0.6.0 <0.8.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, with an overflow flag.
             *
             * _Available since v3.4._
             */
            function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
                uint256 c = a + b;
                if (c < a) return (false, 0);
                return (true, c);
            }
            /**
             * @dev Returns the substraction of two unsigned integers, with an overflow flag.
             *
             * _Available since v3.4._
             */
            function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
                if (b > a) return (false, 0);
                return (true, a - b);
            }
            /**
             * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
             *
             * _Available since v3.4._
             */
            function tryMul(uint256 a, uint256 b) internal pure returns (bool, 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 (true, 0);
                uint256 c = a * b;
                if (c / a != b) return (false, 0);
                return (true, c);
            }
            /**
             * @dev Returns the division of two unsigned integers, with a division by zero flag.
             *
             * _Available since v3.4._
             */
            function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
                if (b == 0) return (false, 0);
                return (true, a / b);
            }
            /**
             * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
             *
             * _Available since v3.4._
             */
            function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
                if (b == 0) return (false, 0);
                return (true, a % b);
            }
            /**
             * @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");
                return a - b;
            }
            /**
             * @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) {
                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, reverting 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) {
                require(b > 0, "SafeMath: division by zero");
                return a / b;
            }
            /**
             * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
             * reverting 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;
            }
            /**
             * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
             * overflow (when the result is negative).
             *
             * CAUTION: This function is deprecated because it requires allocating memory for the error
             * message unnecessarily. For custom revert reasons use {trySub}.
             *
             * Counterpart to Solidity's `-` operator.
             *
             * Requirements:
             *
             * - Subtraction cannot overflow.
             */
            function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
                require(b <= a, errorMessage);
                return a - b;
            }
            /**
             * @dev Returns the integer division of two unsigned integers, reverting with custom message on
             * division by zero. The result is rounded towards zero.
             *
             * CAUTION: This function is deprecated because it requires allocating memory for the error
             * message unnecessarily. For custom revert reasons use {tryDiv}.
             *
             * 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, string memory errorMessage) internal pure returns (uint256) {
                require(b > 0, errorMessage);
                return a / b;
            }
            /**
             * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
             * reverting with custom message when dividing by zero.
             *
             * CAUTION: This function is deprecated because it requires allocating memory for the error
             * message unnecessarily. For custom revert reasons use {tryMod}.
             *
             * 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, string memory errorMessage) internal pure returns (uint256) {
                require(b > 0, errorMessage);
                return a % b;
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity 0.7.3;
        /// @author koloz
        /// @title IPayments
        /// @notice Interface for the Payments contract used.
        interface IPayments {
            function refund(address _payee, uint256 _amount) external payable;
            function payout(address[] calldata _splits, uint256[] calldata _amounts)
                external
                payable;
        }
        // SPDX-License-Identifier: MIT
        pragma solidity >=0.6.0 <0.8.0;
        import "../../math/SafeMath.sol";
        import "../../access/Ownable.sol";
        import "../../utils/Address.sol";
         /**
          * @title Escrow
          * @dev Base escrow contract, holds funds designated for a payee until they
          * withdraw them.
          *
          * Intended usage: This contract (and derived escrow contracts) should be a
          * standalone contract, that only interacts with the contract that instantiated
          * it. That way, it is guaranteed that all Ether will be handled according to
          * the `Escrow` rules, and there is no need to check for payable functions or
          * transfers in the inheritance tree. The contract that uses the escrow as its
          * payment method should be its owner, and provide public methods redirecting
          * to the escrow's deposit and withdraw.
          */
        contract Escrow is Ownable {
            using SafeMath for uint256;
            using Address for address payable;
            event Deposited(address indexed payee, uint256 weiAmount);
            event Withdrawn(address indexed payee, uint256 weiAmount);
            mapping(address => uint256) private _deposits;
            function depositsOf(address payee) public view returns (uint256) {
                return _deposits[payee];
            }
            /**
             * @dev Stores the sent amount as credit to be withdrawn.
             * @param payee The destination address of the funds.
             */
            function deposit(address payee) public payable virtual onlyOwner {
                uint256 amount = msg.value;
                _deposits[payee] = _deposits[payee].add(amount);
                emit Deposited(payee, amount);
            }
            /**
             * @dev Withdraw accumulated balance for a payee, forwarding all gas to the
             * recipient.
             *
             * WARNING: Forwarding all gas opens the door to reentrancy vulnerabilities.
             * Make sure you trust the recipient, or are either following the
             * checks-effects-interactions pattern or using {ReentrancyGuard}.
             *
             * @param payee The address whose funds will be withdrawn and transferred to.
             */
            function withdraw(address payable payee) public virtual onlyOwner {
                uint256 payment = _deposits[payee];
                _deposits[payee] = 0;
                payee.sendValue(payment);
                emit Withdrawn(payee, payment);
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity >=0.6.0 <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 () internal {
                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.6.2 <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.6.0 <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 GSN 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 payable) {
                return msg.sender;
            }
            function _msgData() internal view virtual returns (bytes memory) {
                this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
                return msg.data;
            }
        }