ETH Price: $3,341.03 (-1.08%)

Token

Neil Barrett Collection by MODA (NEIL_BARRETT_MODA)
 

Overview

Max Total Supply

30 NEIL_BARRETT_MODA

Holders

18

Market

Volume (24H)

N/A

Min Price (24H)

N/A

Max Price (24H)

N/A
Balance
7 NEIL_BARRETT_MODA
0xbaf8300d95c2f09477132c4767e0d59fd64e4b38
Loading...
Loading
Loading...
Loading
Loading...
Loading

Click here to update the token information / general information
# Exchange Pair Price  24H Volume % Volume

Contract Source Code Verified (Exact Match)

Contract Name:
WhiteListedTokenERC721V3

Compiler Version
v0.6.12+commit.27d51765

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 104 : WhiteListedTokenERC721V3.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/cryptography/ECDSA.sol";
import "../ERC721BaseV3.sol";
/**
 * @title RefinableERC721TokenWhiteListed
 * @dev only minters can mint token.

 */
contract WhiteListedTokenERC721V3 is ERC721BaseV3 {
    using ECDSA for bytes32;

    address payable public defaultRoyaltyReceiver = address(0);
    uint256 public defaultRoyaltyReceiverBps = 0;

    /**
     * @dev Constructor Function
     * @param _name name of the token ex: Rarible
     * @param _symbol symbol of the token ex: RARI
     * @param _root address of admin account
     * @param _signer address of signer account
     * @param _contractURI URI of contract ex: https://api-mainnet.rarible.com/contractMetadata/{address}
     * @param _baseURI ex: https://ipfs.daonomic.com
    */
    constructor(
        string memory _name,
        string memory _symbol,
        address _root,
        address _signer,
        string memory _contractURI,
        string memory _baseURI
    ) public ERC721BaseV3(_name, _symbol, _contractURI, _baseURI) {
        addAdmin(_root);
        addSigner(_signer);
    }

    function mint(
        uint256 _tokenId,
        bytes memory _signature,
        RoyaltyLibrary.RoyaltyShareDetails[] memory _royaltyShares,
        string memory _uri,
        uint256 _royaltyBps,
        RoyaltyLibrary.Strategy _royaltyStrategy,
        RoyaltyLibrary.RoyaltyShareDetails[] memory _primaryRoyaltyShares
    ) public onlyMinter {
        require(
            isSigner(
                keccak256(abi.encodePacked(address(this), _tokenId, msg.sender)).toEthSignedMessageHash().recover(_signature)
            ),
            "invalid signer"
        );

        RoyaltyLibrary.RoyaltyShareDetails[] memory defaultPrimaryRoyaltyShares = new RoyaltyLibrary.RoyaltyShareDetails[](1);
        if (defaultRoyaltyReceiver != address(0) && defaultRoyaltyReceiverBps != 0)
            defaultPrimaryRoyaltyShares[0] = RoyaltyLibrary.RoyaltyShareDetails({
            recipient : defaultRoyaltyReceiver,
            value : defaultRoyaltyReceiverBps
            });
        _mint(msg.sender, _tokenId, _royaltyShares, _uri, _royaltyBps, RoyaltyLibrary.Strategy.PRIMARY_SALE_STRATEGY, defaultPrimaryRoyaltyShares);
    }

    function mintSimilarBatch(
        uint256[] memory _tokenIds,
        bytes[] memory _signatures,
        RoyaltyLibrary.RoyaltyShareDetails[] memory _royaltyShares,
        string[] memory _uris,
        uint256 _royaltyBps,
        RoyaltyLibrary.Strategy _royaltyStrategy,
        RoyaltyLibrary.RoyaltyShareDetails[] memory _primaryRoyaltyShares
    ) public onlyMinter {

        require(_tokenIds.length < 101, "You can only batch mint 100 tokens");

        for(uint i = 0; i < _tokenIds.length; i++) {
            mint(_tokenIds[i], _signatures[i], _royaltyShares, _uris[i], _royaltyBps, _royaltyStrategy, _primaryRoyaltyShares);
        }
    }

    function setDefaultRoyaltyReceiver(address payable _receiver) public onlyAdmin {
        defaultRoyaltyReceiver = _receiver;
    }

    function setDefaultRoyaltyReceiverBps(uint256 _bps) public onlyAdmin {
        require(_bps <= 10 ** 4, "ERC721: Fee bps should not exceed 10000");
        defaultRoyaltyReceiverBps = _bps;
    }
}

File 2 of 104 : ERC1155Airdrop.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
import "@openzeppelin/contracts/GSN/Context.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";

/**
 * @notice Airdrop contract for Refinable NFT Marketplace
 */
contract ERC1155Airdrop is Context, ReentrancyGuard {

    /// @notice ERC1155 NFT
    IERC1155 public token;
    IERC1155 public tokenV2;

    event AirdropContractDeployed();
    event AirdropFinished(
        uint256 tokenId,
        address[] recipients
    );

    /**
     * @dev Constructor Function
    */
    constructor(
        IERC1155 _token,
        IERC1155 _tokenV2
    ) public {
        require(address(_token) != address(0), "Invalid NFT");
        require(address(_tokenV2) != address(0), "Invalid NFT");

        token = _token;
        tokenV2 = _tokenV2;

        emit AirdropContractDeployed();
    }

    /**
     * @dev Owner of token can airdrop tokens to recipients
     * @param _tokenId id of the token
     * @param _recipients addresses of recipients
     */
    function airdrop(IERC1155 _token, uint256 _tokenId, address[] memory _recipients) external nonReentrant {
        require(
            _token == token || _token == tokenV2,
            "ERC1155Airdrop: Token is not allowed"
        );
        require(
            _token.balanceOf(_msgSender(), _tokenId) >= _recipients.length,
            "ERC1155Airdrop: Caller does not have amount of tokens"
        );
        require(
            _token.isApprovedForAll(_msgSender(), address(this)),
            "ERC1155Airdrop: Owner has not approved"
        );

        for (uint256 i = 0; i < _recipients.length; i++) {
            _token.safeTransferFrom(_msgSender(), _recipients[i], _tokenId, 1, "");
        }

        emit AirdropFinished(_tokenId, _recipients);
    }
}

File 3 of 104 : IERC1155.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.2 <0.8.0;

import "../../introspection/IERC165.sol";

/**
 * @dev Required interface of an ERC1155 compliant contract, as defined in the
 * https://eips.ethereum.org/EIPS/eip-1155[EIP].
 *
 * _Available since v3.1._
 */
interface IERC1155 is IERC165 {
    /**
     * @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`.
     */
    event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);

    /**
     * @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all
     * transfers.
     */
    event TransferBatch(address indexed operator, address indexed from, address indexed to, uint256[] ids, uint256[] values);

    /**
     * @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to
     * `approved`.
     */
    event ApprovalForAll(address indexed account, address indexed operator, bool approved);

    /**
     * @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.
     *
     * If an {URI} event was emitted for `id`, the standard
     * https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value
     * returned by {IERC1155MetadataURI-uri}.
     */
    event URI(string value, uint256 indexed id);

    /**
     * @dev Returns the amount of tokens of token type `id` owned by `account`.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function balanceOf(address account, uint256 id) external view returns (uint256);

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.
     *
     * Requirements:
     *
     * - `accounts` and `ids` must have the same length.
     */
    function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids) external view returns (uint256[] memory);

    /**
     * @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,
     *
     * Emits an {ApprovalForAll} event.
     *
     * Requirements:
     *
     * - `operator` cannot be the caller.
     */
    function setApprovalForAll(address operator, bool approved) external;

    /**
     * @dev Returns true if `operator` is approved to transfer ``account``'s tokens.
     *
     * See {setApprovalForAll}.
     */
    function isApprovedForAll(address account, address operator) external view returns (bool);

    /**
     * @dev Transfers `amount` tokens of token type `id` from `from` to `to`.
     *
     * Emits a {TransferSingle} event.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - If the caller is not `from`, it must be have been approved to spend ``from``'s tokens via {setApprovalForAll}.
     * - `from` must have a balance of tokens of type `id` of at least `amount`.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
     * acceptance magic value.
     */
    function safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes calldata data) external;

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
     *
     * Emits a {TransferBatch} event.
     *
     * Requirements:
     *
     * - `ids` and `amounts` must have the same length.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
     * acceptance magic value.
     */
    function safeBatchTransferFrom(address from, address to, uint256[] calldata ids, uint256[] calldata amounts, bytes calldata data) external;
}

File 4 of 104 : Context.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../utils/Context.sol";

File 5 of 104 : ReentrancyGuard.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/**
 * @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 ReentrancyGuard {
    // 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;

    constructor () internal {
        _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;
    }
}

File 6 of 104 : IERC165.sol
// 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);
}

File 7 of 104 : Context.sol
// 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;
    }
}

File 8 of 104 : ERC721Sale.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/cryptography/ECDSA.sol";

import "../proxy/TransferProxy.sol";
import "../proxy/ServiceFeeProxy.sol";
import "./ERC721SaleNonceHolder.sol";
import "../tokens/v1/HasSecondarySaleFees.sol";
import "../tokens/HasSecondarySale.sol";
import "../tge/interfaces/IBEP20.sol";
import "../managers/TradeTokenManager.sol";
import "../managers/NftTokenManager.sol";
import "../libs/RoyaltyLibrary.sol";
import "../service_fee/RoyaltiesStrategy.sol";
import "./VipPrivatePublicSaleInfo.sol";

contract ERC721Sale is ReentrancyGuard, RoyaltiesStrategy, VipPrivatePublicSaleInfo {
    using ECDSA for bytes32;
    using RoyaltyLibrary for RoyaltyLibrary.Strategy;

    event CloseOrder(
        address indexed token,
        uint256 indexed tokenId,
        address owner,
        uint256 nonce
    );
    event Buy(
        address indexed token,
        uint256 indexed tokenId,
        address owner,
        address payToken,
        uint256 price,
        address buyer
    );

    bytes constant EMPTY = "";
    bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd;
    bytes4 private constant _INTERFACE_ID_HAS_SECONDARY_SALE = 0x5595380a;
    bytes4 private constant _INTERFACE_ID_FEES = 0xb7799584;
    bytes4 private constant _INTERFACE_ID_ROYALTY = 0x7b296bd9;
    bytes4 private constant _INTERFACE_ID_ROYALTY_V2 = 0x9e4a83d4;

    address public transferProxy;
    address public serviceFeeProxy;
    address public nonceHolder;
    address public tradeTokenManager;

    constructor(
        address _transferProxy,
        address _nonceHolder,
        address _serviceFeeProxy,
        address _tradeTokenManager
    ) public {
        transferProxy = _transferProxy;
        nonceHolder = _nonceHolder;
        serviceFeeProxy = _serviceFeeProxy;
        tradeTokenManager = _tradeTokenManager;
    }

    function buy(
        address _token,
        address _royaltyToken,
        uint256 _tokenId,
        address _payToken,
        address payable _owner,
        bytes memory _signature
    ) public payable nonReentrant {
        
        bytes32 saleId = getID(_owner, _token, _tokenId);

        // clean up saleInfo
        if(!whitelistNeeded(saleId) && saleInfo[saleId].vipSaleDate >= 0) {
            delete saleInfo[saleId];
        }

        require(
            IERC721(_token).supportsInterface(_INTERFACE_ID_ERC721),
            "ERC721Sale: Invalid NFT"
        );

        if (_royaltyToken != address(0)) {
            require(
                IERC721(_royaltyToken).supportsInterface(_INTERFACE_ID_ROYALTY_V2),
                "ERC721Sale: Invalid royalty contract"
            );
            require(
                IRoyalty(_royaltyToken).getTokenContract() == _token,
                "ERC721Sale: Royalty Token address does not match buy token"
            );
        }

        require(whitelisted(saleId, msg.sender), "You should be whitelisted and sale should have started");

        require(
            IERC721(_token).ownerOf(_tokenId) == _owner,
            "ERC721Sale: Seller is not the owner of the token"
        );

        uint256 receiveAmount;
        if (_payToken == address(0)) {
            receiveAmount = msg.value;
        } else {
            require(TradeTokenManager(tradeTokenManager).supportToken(_payToken) == true, "ERC721Sale: Pay Token is not allowed");
            receiveAmount = IBEP20(_payToken).allowance(_msgSender(), address(this));
        }

        uint256 price = receiveAmount.mul(10 ** 4).div(ServiceFeeProxy(serviceFeeProxy).getBuyServiceFeeBps(_msgSender()).add(10000));

        uint256 nonce = verifySignature(
            _token,
            _tokenId,
            _payToken,
            _owner,
            price,
            _signature
        );
        verifyOpenAndModifyState(_token, _tokenId, _owner, nonce);
        if (_royaltyToken != address(0)) {
            _distributeProfit(_royaltyToken, _tokenId, _payToken, _owner, price, receiveAmount);
        } else {
            _distributeProfit(_token, _tokenId, _payToken, _owner, price, receiveAmount);
        }

        TransferProxy(transferProxy).erc721safeTransferFrom(_token, _owner, _msgSender(), _tokenId);

        emit Buy(_token, _tokenId, _owner, _payToken, price, _msgSender());
    }

    function _distributeProfit(
        address _token,
        uint256 _tokenId,
        address _payToken,
        address payable _owner,
        uint256 _totalPrice,
        uint256 _receiveAmount
    ) internal {
        bool supportSecondarySale = IERC165(_token).supportsInterface(_INTERFACE_ID_HAS_SECONDARY_SALE);
        address payable serviceFeeRecipient = ServiceFeeProxy(serviceFeeProxy).getServiceFeeRecipient();
        uint256 sellerServiceFee;
        uint256 sellerReceiveAmount;
        uint256 royalties;
        if (supportSecondarySale) {
            bool isSecondarySale = HasSecondarySale(_token).checkSecondarySale(_tokenId);
            uint256 sellerServiceFeeBps = ServiceFeeProxy(serviceFeeProxy).getSellServiceFeeBps(_owner, isSecondarySale);
            sellerServiceFee = _totalPrice.mul(sellerServiceFeeBps).div(10 ** 4);
            sellerReceiveAmount = _totalPrice.sub(sellerServiceFee);
            /*
               * The sellerReceiveAmount is on sale price minus seller service fee minus buyer service fee
               * This make sures we have enough balance even the royalties is 100%
            */
            if (
                IERC165(_token).supportsInterface(_INTERFACE_ID_FEES)
                || IERC165(_token).supportsInterface(_INTERFACE_ID_ROYALTY)
                || IERC165(_token).supportsInterface(_INTERFACE_ID_ROYALTY_V2)
            )
                royalties = _payOutRoyaltiesByStrategy(_token, _tokenId, _payToken, _msgSender(), sellerReceiveAmount, isSecondarySale);
            sellerReceiveAmount = sellerReceiveAmount.sub(royalties);
            HasSecondarySale(_token).setSecondarySale(_tokenId);
        } else {
            // default to second sale if it's random 721 token
            uint256 sellerServiceFeeBps = ServiceFeeProxy(serviceFeeProxy).getSellServiceFeeBps(_owner, true);
            sellerServiceFee = _totalPrice.mul(sellerServiceFeeBps).div(10 ** 4);
            sellerReceiveAmount = _totalPrice.sub(sellerServiceFee);
        }
        if (_payToken == address(0)) {
            _owner.transfer(sellerReceiveAmount);
            serviceFeeRecipient.transfer(sellerServiceFee.add(_receiveAmount.sub(_totalPrice)));
        } else {
            IBEP20(_payToken).transferFrom(_msgSender(), _owner, sellerReceiveAmount);
            IBEP20(_payToken).transferFrom(_msgSender(), serviceFeeRecipient, sellerServiceFee.add(_receiveAmount.sub(_totalPrice)));
        }
    }

    function cancel(address token, uint256 tokenId) public {
        uint256 nonce = ERC721SaleNonceHolder(nonceHolder).getNonce(token, tokenId, _msgSender());
        ERC721SaleNonceHolder(nonceHolder).setNonce(token, tokenId, _msgSender(), nonce.add(1));

        emit CloseOrder(token, tokenId, _msgSender(), nonce.add(1));
    }

    function verifySignature(
        address _token,
        uint256 _tokenId,
        address _payToken,
        address payable _owner,
        uint256 _price,
        bytes memory _signature
    ) internal view returns (uint256 nonce) {
        nonce = ERC721SaleNonceHolder(nonceHolder).getNonce(_token, _tokenId, _owner);
        address owner;
        if (_payToken == address(0)) {
            owner = keccak256(abi.encodePacked(_token, _tokenId, _price, nonce)).toEthSignedMessageHash().recover(_signature);
        } else {
            owner = keccak256(abi.encodePacked(_token, _tokenId, _payToken, _price, nonce)).toEthSignedMessageHash().recover(_signature);
        }
        require(
            owner == _owner,
            "ERC721Sale: Incorrect signature"
        );
    }

    function verifyOpenAndModifyState(
        address _token,
        uint256 _tokenId,
        address _owner,
        uint256 _nonce
    ) internal {
        ERC721SaleNonceHolder(nonceHolder).setNonce(_token, _tokenId, _owner, _nonce.add(1));
        emit CloseOrder(_token, _tokenId, _owner, _nonce.add(1));
    }
}

File 9 of 104 : SafeMath.sol
// 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;
    }
}

File 10 of 104 : IERC721.sol
// 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;
}

File 11 of 104 : ECDSA.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/**
 * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
 *
 * These functions can be used to verify that a message was signed by the holder
 * of the private keys of a given address.
 */
library ECDSA {
    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature`. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {toEthSignedMessageHash} on it.
     */
    function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
        // Check the signature length
        if (signature.length != 65) {
            revert("ECDSA: invalid signature length");
        }

        // Divide the signature in r, s and v variables
        bytes32 r;
        bytes32 s;
        uint8 v;

        // ecrecover takes the signature parameters, and the only way to get them
        // currently is to use assembly.
        // solhint-disable-next-line no-inline-assembly
        assembly {
            r := mload(add(signature, 0x20))
            s := mload(add(signature, 0x40))
            v := byte(0, mload(add(signature, 0x60)))
        }

        return recover(hash, v, r, s);
    }

    /**
     * @dev Overload of {ECDSA-recover-bytes32-bytes-} that receives the `v`,
     * `r` and `s` signature fields separately.
     */
    function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
        // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
        // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
        // the valid range for s in (281): 0 < s < secp256k1n ÷ 2 + 1, and for v in (282): v ∈ {27, 28}. Most
        // signatures from current libraries generate a unique signature with an s-value in the lower half order.
        //
        // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
        // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
        // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
        // these malleable signatures as well.
        require(uint256(s) <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0, "ECDSA: invalid signature 's' value");
        require(v == 27 || v == 28, "ECDSA: invalid signature 'v' value");

        // If the signature is valid (and not malleable), return the signer address
        address signer = ecrecover(hash, v, r, s);
        require(signer != address(0), "ECDSA: invalid signature");

        return signer;
    }

    /**
     * @dev Returns an Ethereum Signed Message, created from a `hash`. This
     * replicates the behavior of the
     * https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign[`eth_sign`]
     * JSON-RPC method.
     *
     * See {recover}.
     */
    function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
        // 32 is the length in bytes of hash,
        // enforced by the type signature above
        return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
    }
}

File 12 of 104 : TransferProxy.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;

import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";

import "../roles/OperatorRole.sol";

contract TransferProxy is OperatorRole {
    function erc721safeTransferFrom(
        address token,
        address from,
        address to,
        uint256 tokenId
    ) external onlyOperator {
        IERC721(token).safeTransferFrom(from, to, tokenId);
    }

    function erc1155safeTransferFrom(
        address token,
        address _from,
        address _to,
        uint256 _id,
        uint256 _value,
        bytes calldata _data
    ) external onlyOperator {
        IERC1155(token).safeTransferFrom(_from, _to, _id, _value, _data);
    }
}

File 13 of 104 : ServiceFeeProxy.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;

import "../interfaces/IServiceFee.sol";
import "../roles/AdminRole.sol";

/**
 * @notice Service Fee Proxy to communicate service fee contract
 */
contract ServiceFeeProxy is AdminRole {
    /// @notice service fee contract
    IServiceFee public serviceFeeContract;

    event ServiceFeeContractUpdated(address serviceFeeContract);

    /**
     * @notice Lets admin set the service fee contract
     * @param _serviceFeeContract address of serviceFeeContract
     */
    function setServiceFeeContract(address _serviceFeeContract) onlyAdmin external {
        require(
            _serviceFeeContract != address(0),
            "ServiceFeeProxy.setServiceFeeContract: Zero address"
        );
        serviceFeeContract = IServiceFee(_serviceFeeContract);
        emit ServiceFeeContractUpdated(_serviceFeeContract);
    }

    /**
     * @notice Fetch sell service fee bps from service fee contract
     * @param _seller address of seller
     */
    function getSellServiceFeeBps(address _seller, bool isSecondarySale) external view returns (uint256) {
        require(
            _seller != address(0),
            "ServiceFeeProxy.getSellServiceFeeBps: Zero address"
        );
        return serviceFeeContract.getSellServiceFeeBps(_seller, isSecondarySale);
    }

    /**
     * @notice Fetch buy service fee bps from service fee contract
     * @param _buyer address of seller
     */
    function getBuyServiceFeeBps(address _buyer) external view returns (uint256) {
        require(
            _buyer != address(0),
            "ServiceFeeProxy.getBuyServiceFeeBps: Zero address"
        );
        return serviceFeeContract.getBuyServiceFeeBps(_buyer);
    }

    /**
     * @notice Get service fee recipient address
     */
    function getServiceFeeRecipient() external view returns (address payable) {
        return serviceFeeContract.getServiceFeeRecipient();
    }

    /**
     * @notice Set service fee recipient address
     * @param _serviceFeeRecipient address of recipient
     */
    function setServiceFeeRecipient(address payable _serviceFeeRecipient) external onlyAdmin {
        require(
            _serviceFeeRecipient != address(0),
            "ServiceFeeProxy.setServiceFeeRecipient: Zero address"
        );

        serviceFeeContract.setServiceFeeRecipient(_serviceFeeRecipient);
    }
}

File 14 of 104 : ERC721SaleNonceHolder.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;

import "../roles/OperatorRole.sol";

contract ERC721SaleNonceHolder is OperatorRole {
    // keccak256(token, owner, tokenId) => nonce
    mapping(bytes32 => uint256) public nonces;

    // keccak256(token, owner, tokenId, nonce) => completed amount
    mapping(bytes32 => uint256) public completed;

    function getNonce(
        address token,
        uint256 tokenId,
        address owner
    ) public view returns (uint256) {
        return nonces[getNonceKey(token, tokenId, owner)];
    }

    function setNonce(
        address token,
        uint256 tokenId,
        address owner,
        uint256 nonce
    ) public onlyOperator {
        nonces[getNonceKey(token, tokenId, owner)] = nonce;
    }

    function getNonceKey(
        address token,
        uint256 tokenId,
        address owner
    ) public pure returns (bytes32) {
        return keccak256(abi.encodePacked(token, tokenId, owner));
    }

    function getCompleted(
        address token,
        uint256 tokenId,
        address owner,
        uint256 nonce
    ) public view returns (uint256) {
        return completed[getCompletedKey(token, tokenId, owner, nonce)];
    }

    function setCompleted(
        address token,
        uint256 tokenId,
        address owner,
        uint256 nonce,
        uint256 _completed
    ) public onlyOperator {
        completed[getCompletedKey(token, tokenId, owner, nonce)] = _completed;
    }

    function getCompletedKey(
        address token,
        uint256 tokenId,
        address owner,
        uint256 nonce
    ) public pure returns (bytes32) {
        return keccak256(abi.encodePacked(token, tokenId, owner, nonce));
    }
}

File 15 of 104 : HasSecondarySaleFees.sol
pragma solidity ^0.6.12;
// SPDX-License-Identifier: UNLICENSED

import "@openzeppelin/contracts/introspection/ERC165.sol";

abstract contract HasSecondarySaleFees is ERC165 {

    event SecondarySaleFees(uint256 tokenId, address[] recipients, uint[] bps);

    /*
     * bytes4(keccak256('getFeeBps(uint256)')) == 0x0ebd4c7f
     * bytes4(keccak256('getFeeRecipients(uint256)')) == 0xb9c4d9fb
     *
     * => 0x0ebd4c7f ^ 0xb9c4d9fb == 0xb7799584
     */
    bytes4 private constant _INTERFACE_ID_FEES = 0xb7799584;

    constructor() public {
        _registerInterface(_INTERFACE_ID_FEES);
    }

    function getFeeRecipients(uint256 id) public virtual view returns (address payable[] memory);
    function getFeeBps(uint256 id) public virtual view returns (uint[] memory);
}

File 16 of 104 : HasSecondarySale.sol
pragma solidity ^0.6.12;
// SPDX-License-Identifier: UNLICENSED

import "@openzeppelin/contracts/introspection/ERC165.sol";
import "../interfaces/IHasSecondarySale.sol";

abstract contract HasSecondarySale is ERC165, IHasSecondarySale {

    // From IHasSecondarySale
    bytes4 private constant _INTERFACE_ID_HAS_SECONDARY_SALE = 0x5595380a;

    constructor() public {
        _registerInterface(_INTERFACE_ID_HAS_SECONDARY_SALE);
    }
}

File 17 of 104 : IBEP20.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.6.12;

interface IBEP20 {
  /**
   * @dev Returns the amount of tokens in existence.
   */
  function totalSupply() external view returns (uint256);

  /**
   * @dev Returns the token decimals.
   */
  function decimals() external view returns (uint8);

  /**
   * @dev Returns the token symbol.
   */
  function symbol() external view returns (string memory);

  /**
   * @dev Returns the token name.
   */
  function name() external view returns (string memory);

  /**
   * @dev Returns the bep token owner.
   */
  function getOwner() external view returns (address);

  /**
   * @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);
}

File 18 of 104 : TradeTokenManager.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;

import "../interfaces/ITokenManager.sol";
import "../roles/AdminRole.sol";
import "../tge/interfaces/IBEP20.sol";

contract TradeTokenManager is ITokenManager, AdminRole {

    struct TradeToken {
        string symbol;
        bool created;
        bool active;
    }

    /// @notice ERC20 Token address -> active boolean
    mapping(address => TradeToken) public tokens;

    modifier exist(address _token) {
        require(tokens[_token].created != false, "TradeTokenManager: Token is not added");
        _;
    }

    function addToken(address _erc20Token,string calldata _symbol, bool _active) onlyAdmin external {
        require(_erc20Token != address(0), "TradeTokenManager: Cannot be zero address");
        require(tokens[_erc20Token].created == false, "TradeTokenManager: Token already exist");
        require(IBEP20(_erc20Token).totalSupply() != 0, "TradeTokenManager: Token is not ERC20 standard");
        tokens[_erc20Token] = TradeToken({
            symbol: _symbol,
            created: true,
            active: _active
        });
    }

    function setToken(address _erc20Token, bool _active) onlyAdmin exist(_erc20Token) external override {
        tokens[_erc20Token].active = _active;
    }

    function removeToken(address _erc20Token) onlyAdmin exist(_erc20Token) external override {
        delete tokens[_erc20Token];
    }

    function supportToken(address _erc20Token) exist(_erc20Token) external view override returns (bool) {
        return tokens[_erc20Token].active;
    }
}

File 19 of 104 : NftTokenManager.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;

import "../roles/AdminRole.sol";
import "../interfaces/ITokenManager.sol";
import "../interfaces/IRoyalty.sol";
import "../libs/NftTokenLibrary.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";

contract NftTokenManager is ITokenManager, AdminRole {
    struct NftToken {
        string name;
        bool created;
        bool active;
        NftTokenLibrary.TokenType tokenType;
    }

    /// @notice ERC1155 or ERC721 Token address -> active boolean
    mapping(address => NftToken) public tokens;

    bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd;
    bytes4 private constant _INTERFACE_ID_ERC1155 = 0xd9b67a26;

    modifier exist(address _token) {
        require(tokens[_token].created != false, "NftTokenManager: Token is not added");
        _;
    }
    // TODO: Add Token By Batch
    function addToken(address _token, string calldata _name, bool _active, NftTokenLibrary.TokenType _tokenType) onlyAdmin external {
        require(_token != address(0), "NftTokenManager: Cannot be zero address");
        require(tokens[_token].created == false, "NftTokenManager: Token already exist");
        // TODO: Add Royalty type and link royalty to erc token
        if (_tokenType != NftTokenLibrary.TokenType.REFINABLE_ROYALTY_ERC721_CONTRACT && _tokenType != NftTokenLibrary.TokenType.REFINABLE_ROYALTY_ERC1155_CONTRACT) {
            require(
                IERC721(_token).supportsInterface(_INTERFACE_ID_ERC721) || IERC1155(_token).supportsInterface(_INTERFACE_ID_ERC1155),
                "NftTokenManager: Token is not ERC1155 or ERC721 standard"
            );
        } else {
            require(
                IERC165(_token).supportsInterface(type(IRoyalty).interfaceId),
                "NftTokenManager: Token is not IRoyalty standard"
            );
        }
        tokens[_token] = NftToken({
        name : _name,
        created : true,
        active : _active,
        tokenType : _tokenType
        });
    }

    function setToken(address _token, bool _active) onlyAdmin exist(_token) external override {
        tokens[_token].active = _active;
    }

    function removeToken(address _token) onlyAdmin exist(_token) external override {
        delete tokens[_token];
    }

    function supportToken(address _token) exist(_token) external view override returns (bool) {
        return tokens[_token].active;
    }

    function getTokenType(address _token) exist(_token) external view returns (NftTokenLibrary.TokenType) {
        return tokens[_token].tokenType;
    }
}

File 20 of 104 : RoyaltyLibrary.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;

library RoyaltyLibrary {
    enum Strategy {
        ROYALTY_STRATEGY, // get royalty from the sales price (default)
        PROFIT_DISTRIBUTION_STRATEGY, // profit sharing from a fixed royalties of the sales price
        PRIMARY_SALE_STRATEGY // 1 party get royalty from primary sale, secondary sale will follow ROYALTY_STRATEGY
    }

    struct RoyaltyInfo {
        uint256 value; //bps
        Strategy strategy;
    }

    struct RoyaltyShareDetails {
        address payable recipient;
        uint256 value; // bps
    }
}

File 21 of 104 : RoyaltiesStrategy.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;

import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/GSN/Context.sol";
import "@openzeppelin/contracts/introspection/IERC165.sol";

import "../libs/RoyaltyLibrary.sol";
import "../tokens/v2/ERC721BaseV2.sol";
import "../tge/interfaces/IBEP20.sol";
import "../tokens/Royalty.sol";
import "../tokens/v1/HasSecondarySaleFees.sol";
import "../interfaces/IPrimaryRoyalty.sol";

abstract contract RoyaltiesStrategy is Context {
    using SafeMath for uint256;
    using RoyaltyLibrary for RoyaltyLibrary.RoyaltyShareDetails;
    using RoyaltyLibrary for RoyaltyLibrary.RoyaltyInfo;

    bytes4 private constant _INTERFACE_ID_ROYALTY = 0x7b296bd9;
    bytes4 private constant _INTERFACE_ID_ROYALTY_V2 = 0x9e4a83d4;

    function _payOutRoyaltiesByStrategy(
        address _token,
        uint256 _tokenId,
        address _payToken,
        address _payer,
        uint256 _actualPrice, // the total paid price - seller service fee - buyer service fee
        bool _isSecondarySale
    ) internal returns (uint256){
        /*
           * The _totalPrice is on sale price minus seller service fee minus buyer service fee
           * This make sures we have enough balance even the royalties is 100%
        */
        uint256 royalties;
        if (
            IERC165(_token).supportsInterface(_INTERFACE_ID_ROYALTY)
            || IERC165(_token).supportsInterface(_INTERFACE_ID_ROYALTY_V2)
        ) {
            royalties = _payOutRoyalties(_token, _tokenId, _payToken, _payer, _actualPrice, _isSecondarySale);
        } else {
            // support the old contract with no strategy
            address payable[] memory recipients = HasSecondarySaleFees(_token).getFeeRecipients(_tokenId);
            uint256[] memory royaltyShares = HasSecondarySaleFees(_token).getFeeBps(_tokenId);
            require(royaltyShares.length == recipients.length, "RoyaltyStrategy: Royalty share array length not match recipients array length");
            uint256 sumRoyaltyShareBps;
            for (uint256 i = 0; i < royaltyShares.length; i++) {
                sumRoyaltyShareBps = sumRoyaltyShareBps.add(royaltyShares[i]);
            }
            require(
                sumRoyaltyShareBps <= 10 ** 4,
                "RoyaltyStrategy: Total Royalty Shares bps should not exceed 10000"
            );
            for (uint256 i = 0; i < royaltyShares.length; i++) {
                uint256 recipientRoyalty = _actualPrice.mul(royaltyShares[i]).div(10 ** 4);
                _transferToken(_payToken, _payer, recipients[i], recipientRoyalty);
                royalties = royalties.add(recipientRoyalty);
            }
        }
        return royalties;
    }

    function _payOutRoyalties(address _token, uint256 _tokenId, address _payToken, address _payer, uint256 _payPrice, bool _isSecondarySale) internal returns (uint256) {
        uint256 royalties;
        RoyaltyLibrary.RoyaltyInfo memory royalty = Royalty(_token).getRoyalty(_tokenId);
        RoyaltyLibrary.RoyaltyShareDetails[] memory royaltyShares;
        if (royalty.strategy == RoyaltyLibrary.Strategy.PRIMARY_SALE_STRATEGY && _isSecondarySale == false) {
            if (IERC165(_token).supportsInterface(type(IPrimaryRoyalty).interfaceId)) {
                royaltyShares = IPrimaryRoyalty(_token).getPrimaryRoyaltyShares(_tokenId);
            } else {
                royaltyShares = Royalty(_token).getRoyaltyShares(_tokenId);
            }
        } else {
            royaltyShares = Royalty(_token).getRoyaltyShares(_tokenId);
        }
        _checkRoyaltiesBps(royalty, royaltyShares);
        for (uint256 i = 0; i < royaltyShares.length; i++) {
            uint256 recipientRoyalty;
            if (royalty.strategy == RoyaltyLibrary.Strategy.PROFIT_DISTRIBUTION_STRATEGY && _isSecondarySale) {
                recipientRoyalty = _payPrice.mul(royalty.value).mul(royaltyShares[i].value).div(10 ** 8);
            } else {
                recipientRoyalty = _payPrice.mul(royaltyShares[i].value).div(10 ** 4);
            }
            _transferToken(_payToken, _payer, royaltyShares[i].recipient, recipientRoyalty);
            royalties = royalties.add(recipientRoyalty);
        }
        return royalties;
    }

    function _checkRoyaltiesBps(RoyaltyLibrary.RoyaltyInfo memory _royalty, RoyaltyLibrary.RoyaltyShareDetails[] memory _royaltyShares) internal pure {
        require(
            _royalty.value <= 10 ** 4,
            "RoyaltyStrategy: Royalty bps should be less than 10000"
        );
        uint256 sumRoyaltyShareBps;
        for (uint256 i = 0; i < _royaltyShares.length; i++) {
            sumRoyaltyShareBps = sumRoyaltyShareBps.add(_royaltyShares[i].value);
        }
        if (_royalty.strategy == RoyaltyLibrary.Strategy.PROFIT_DISTRIBUTION_STRATEGY) {
            require(
                sumRoyaltyShareBps == 10 ** 4,
                "RoyaltyStrategy: Total Royalty Shares bps should be 10000"
            );
        } else {
            require(
                sumRoyaltyShareBps <= 10 ** 4,
                "RoyaltyStrategy: Total Royalty Shares bps should not exceed 10000"
            );
        }
    }

    function _transferToken(address _payToken, address _payer, address payable _recipient, uint256 _amount) internal {
        if (_payToken == address(0)) {
            _recipient.transfer(_amount);
        } else {
            if (_payer == address(this)) {
                IBEP20(_payToken).transfer(_recipient, _amount);
            } else {
                IBEP20(_payToken).transferFrom(_payer, _recipient, _amount);
            }
        }
    }
}

File 22 of 104 : VipPrivatePublicSaleInfo.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {ERC165Checker} from "@openzeppelin/contracts/introspection/ERC165Checker.sol";
import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/utils/Strings.sol";

abstract contract VipPrivatePublicSaleInfo is Ownable {

    using ERC165Checker for address;

    enum WhitelistType{ VIP, PRIVATE }

    struct SaleInfo {
        uint256 vipSaleDate;
        mapping(address => bool) vipWhitelist;
        uint256 privateSaleDate;
        mapping(address => bool) privateWhitelist;
        uint256 publicSaleDate;
        address creator;
    }

    /// @dev address -> token id -> sale info
    mapping(bytes32 => SaleInfo) public saleInfo;

    event Whitelisted(WhitelistType whitelistType, address indexed account, bool isWhitelisted);

    modifier onlyCreator(bytes32 _saleId) {
        require(saleInfo[_saleId].creator == msg.sender, "Whitelist: Not Sale creator");
        _;
    }

    function setSaleInfo(        
        address _token,
        uint256 _tokenId,
        uint256 _vipSaleDate,
        uint256 _privateSaleDate,
        uint256 _publicSaleDate
    ) external {

        if(_token.supportsInterface(type(IERC1155).interfaceId)) {
            require(
                IERC1155(_token).balanceOf(msg.sender, _tokenId) > 0,
                "ERC1155Sale: Caller doesn't have any tokens"
            );
        } else if(_token.supportsInterface(type(IERC721).interfaceId)) {
            require(
                IERC721(_token).ownerOf(_tokenId) == msg.sender,
                "ERC721Sale: Caller doesn't this tokenId"
            );
        } else {
            require(false, "not ERC1155 or ERC721 token");
        }

        bytes32 saleId = getID(msg.sender, _token, _tokenId);

        saleInfo[saleId] = SaleInfo({
            vipSaleDate: _vipSaleDate,
            privateSaleDate: _privateSaleDate,
            publicSaleDate: _publicSaleDate,
            creator: msg.sender
        });
    }

    function batchSetSaleInfo(
        address[] memory _tokens,
        uint256[] memory _tokenIds,
        uint256 _vipSaleDate,
        uint256 _privateSaleDate,
        uint256 _publicSaleDate
    ) external {         

        require(_tokens.length == _tokenIds.length, "tokens and token ids length doesnt match");

        for(uint i = 0; i < _tokenIds.length; i++) {

            if(_tokens[i].supportsInterface(type(IERC1155).interfaceId)) {
                require(
                    IERC1155(_tokens[i]).balanceOf(msg.sender, _tokenIds[i]) > 0,
                    "ERC1155Sale: Caller doesn't have any tokens"
                );
            } else if(_tokens[i].supportsInterface(type(IERC721).interfaceId)) {
                require(
                    IERC721(_tokens[i]).ownerOf(_tokenIds[i]) == msg.sender,
                    "ERC721Sale: Caller doesn't this tokenId"
                );
            } else {
                require(false, "not ERC1155 or ERC721 token");
            }


            bytes32 saleId = getID(msg.sender, _tokens[i], _tokenIds[i]);
            saleInfo[saleId] = SaleInfo({
                vipSaleDate: _vipSaleDate,
                privateSaleDate: _privateSaleDate,
                publicSaleDate: _publicSaleDate,
                creator: msg.sender
            });
        }
    }

    function whitelisted(bytes32 saleId, address _address)
    public
    view
    returns (bool)
    {

        // if it doesn't exist, we just allow sale to go through
        if(saleInfo[saleId].creator == address(0)) {
            return true;
        }

        // should be whitelisted if we're in the VIP sale
        if(
            saleInfo[saleId].vipSaleDate <= _getNow() &&
            saleInfo[saleId].privateSaleDate > _getNow() 
        ) {
            return saleInfo[saleId].vipWhitelist[_address];
        }
        

        // should be whitelisted if we're in the Private sale
        if(
            saleInfo[saleId].privateSaleDate <= _getNow() && 
            saleInfo[saleId].publicSaleDate > _getNow() 
        ) {
            return 
                saleInfo[saleId].vipWhitelist[_address] || 
                saleInfo[saleId].privateWhitelist[_address];
        }

        return false;
    }

    function whitelistNeeded(bytes32 saleId)
    public
    view
    returns (bool)
    {
        // whitelist has passed when now is > vip and private sale date
        if(
            saleInfo[saleId].vipSaleDate < _getNow() &&
            saleInfo[saleId].privateSaleDate < _getNow() &&
            saleInfo[saleId].publicSaleDate < _getNow()

        ) {
            return false;
        }


        return true;
    }

    function toggleAddressByBatch(bytes32[] memory _saleIds, WhitelistType[][] memory _whitelistTypes, address[][][] memory _addresses, bool enable)
    public
    {
        // for many sale ids
        for(uint i = 0; i < _saleIds.length; i++) {       

            require(saleInfo[_saleIds[i]].creator == msg.sender, "Whitelist: Not Sale creator");

            // 1 sale can have many whitelist types
            for (uint256 j = 0; j < _whitelistTypes[i].length; j++) {

                // 1 whitelist type can have many addresses
                for(uint k = 0; k < _addresses[i][j].length; k++) {
                    if(_whitelistTypes[i][j] == WhitelistType.VIP) {
                        require(saleInfo[_saleIds[i]].vipWhitelist[_addresses[i][j][k]] == !enable);
                        saleInfo[_saleIds[i]].vipWhitelist[_addresses[i][j][k]] = enable;
                        emit Whitelisted(WhitelistType.VIP, _addresses[i][j][k], enable);
                    }
                    if(_whitelistTypes[i][j] == WhitelistType.PRIVATE) {
                        require(saleInfo[_saleIds[i]].privateWhitelist[_addresses[i][j][k]] == !enable);
                        saleInfo[_saleIds[i]].privateWhitelist[_addresses[i][j][k]] = enable;
                        emit Whitelisted(WhitelistType.PRIVATE, _addresses[i][j][k], enable);
                    }
                }
            }
        }
    }

    function _getNow() internal virtual view returns (uint256) {
        return block.timestamp;
    }

    /*
     * @notice Get Sale info with owner address and token id
     * @param _owner address of token Owner
     * @param _tokenId Id of token
     */
    function getSaleInfo(
        address _owner,
        address _token,
        uint256 _tokenId
    ) public view returns (bytes32 saleId, uint256 vipSaleDate, uint256 privateSaleDate, uint256 publicSaleDate, address creator) {

        bytes32 _saleId = getID(_owner, _token, _tokenId);

        require(saleInfo[_saleId].vipSaleDate >= 0, "VipPrivatePublicSale: Sale has no dates set");

        return (_saleId, saleInfo[_saleId].vipSaleDate, saleInfo[_saleId].privateSaleDate, saleInfo[_saleId].publicSaleDate, saleInfo[_saleId].creator);
    }



    
    function getID(address _owner, address _token, uint256 _tokenId) public pure returns (bytes32) {
        return sha256(abi.encodePacked(_owner, ":", _token, ":",Strings.toString(_tokenId)));
    }

    function getIDBatch(address[] memory _owners, address[] memory _tokens, uint256[] memory _tokenIds) public pure returns (bytes32[] memory) {
        
        require(_tokenIds.length <= 100, "You are requesting too many ids, max 100");
        require(_tokenIds.length == _owners.length, "tokenIds length != owners length");
        require(_tokenIds.length == _tokens.length, "tokenIds length != tokens length");
        
        bytes32[] memory ids = new bytes32[](_tokenIds.length);
        
        for(uint i = 0; i < _tokenIds.length; i++) {
            ids[i] = getID(_owners[i], _tokens[i], _tokenIds[i]);
        }

        return ids;
    }
}

File 23 of 104 : OperatorRole.sol
pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;
// SPDX-License-Identifier: UNLICENSED

import "@openzeppelin/contracts/access/AccessControl.sol";

contract OperatorRole is AccessControl {
    
    bytes32 public constant OPERATOR_ROLE = keccak256("OPERATOR_ROLE");

    modifier onlyAdmin() {
        require(isAdmin(_msgSender()), "Ownable: caller is not the admin");
        _;
    }

    modifier onlyOperator() {
        require(isOperator(_msgSender()), "Ownable: caller is not the operator");
        _;
    }

    constructor() public {
        _setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
    }

    function addOperator(address _account) public onlyAdmin {
        _setupRole(OPERATOR_ROLE , _account);
    }

    function removeOperator(address _account) public onlyAdmin {
        revokeRole(OPERATOR_ROLE , _account);
    }

    function isAdmin(address _account) internal virtual view returns(bool) {
        return hasRole(DEFAULT_ADMIN_ROLE , _account);
    }

    function isOperator(address _account) internal virtual view returns(bool) {
        return hasRole(OPERATOR_ROLE , _account);
    }
}

File 24 of 104 : AccessControl.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../utils/EnumerableSet.sol";
import "../utils/Address.sol";
import "../utils/Context.sol";

/**
 * @dev Contract module that allows children to implement role-based access
 * control mechanisms.
 *
 * 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 {
    using EnumerableSet for EnumerableSet.AddressSet;
    using Address for address;

    struct RoleData {
        EnumerableSet.AddressSet members;
        bytes32 adminRole;
    }

    mapping (bytes32 => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

    /**
     * @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 {_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) public view returns (bool) {
        return _roles[role].members.contains(account);
    }

    /**
     * @dev Returns the number of accounts that have `role`. Can be used
     * together with {getRoleMember} to enumerate all bearers of a role.
     */
    function getRoleMemberCount(bytes32 role) public view returns (uint256) {
        return _roles[role].members.length();
    }

    /**
     * @dev Returns one of the accounts that have `role`. `index` must be a
     * value between 0 and {getRoleMemberCount}, non-inclusive.
     *
     * Role bearers are not sorted in any particular way, and their ordering may
     * change at any point.
     *
     * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
     * you perform all queries on the same block. See the following
     * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
     * for more information.
     */
    function getRoleMember(bytes32 role, uint256 index) public view returns (address) {
        return _roles[role].members.at(index);
    }

    /**
     * @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 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 {
        require(hasRole(_roles[role].adminRole, _msgSender()), "AccessControl: sender must be an admin to grant");

        _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 {
        require(hasRole(_roles[role].adminRole, _msgSender()), "AccessControl: sender must be an admin to revoke");

        _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 granted `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `account`.
     */
    function renounceRole(bytes32 role, address account) public virtual {
        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}.
     * ====
     */
    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 {
        emit RoleAdminChanged(role, _roles[role].adminRole, adminRole);
        _roles[role].adminRole = adminRole;
    }

    function _grantRole(bytes32 role, address account) private {
        if (_roles[role].members.add(account)) {
            emit RoleGranted(role, account, _msgSender());
        }
    }

    function _revokeRole(bytes32 role, address account) private {
        if (_roles[role].members.remove(account)) {
            emit RoleRevoked(role, account, _msgSender());
        }
    }
}

File 25 of 104 : EnumerableSet.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <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;

            // When the value to delete is the last one, the swap operation is unnecessary. However, since this occurs
            // so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement.

            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] = toDeleteIndex + 1; // All indexes are 1-based

            // 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) {
        require(set._values.length > index, "EnumerableSet: index out of bounds");
        return set._values[index];
    }

    // 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);
    }

    // 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))));
    }


    // 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));
    }
}

File 26 of 104 : Address.sol
// 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);
            }
        }
    }
}

File 27 of 104 : IServiceFee.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

/**
 * @notice Service Fee interface for Refinable NFT Marketplace
 */
interface IServiceFee {

    /**
     * @notice Lets admin set the refinable token contract
     * @param _refinableTokenContract address of refinable token contract
     */
    function setRefinableTokenContract(address _refinableTokenContract) external;

    /**
     * @notice Admin can add proxy address
     * @param _proxyAddr address of proxy
     */
    function addProxy(address _proxyAddr) external;

    /**
     * @notice Admin can remove proxy address
     * @param _proxyAddr address of proxy
     */
    function removeProxy(address _proxyAddr) external;

    /**
     * @notice Calculate the seller service fee in according to the business logic and returns it
     * @param _seller address of seller
     * @param _isPrimarySale sale is primary or secondary
     */
    function getSellServiceFeeBps(address _seller, bool _isPrimarySale) external view returns (uint256);

    /**
     * @notice Calculate the buyer service fee in according to the business logic and returns it
     * @param _buyer address of buyer
     */
    function getBuyServiceFeeBps(address _buyer) external view returns (uint256);

    /**
     * @notice Get service fee recipient address
     */
    function getServiceFeeRecipient() external view returns (address payable);

    /**
     * @notice Set service fee recipient address
     * @param _serviceFeeRecipient address of recipient
     */
    function setServiceFeeRecipient(address payable _serviceFeeRecipient) external;
}

File 28 of 104 : AdminRole.sol
pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;
// SPDX-License-Identifier: UNLICENSED

import "@openzeppelin/contracts/access/AccessControl.sol";

contract AdminRole is AccessControl {

    modifier onlyAdmin() {
        require(isAdmin(_msgSender()), "Ownable: caller is not the admin");
        _;
    }

    constructor() public {
        _setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
    }

    function isAdmin(address _account) internal virtual view returns(bool) {
        return hasRole(DEFAULT_ADMIN_ROLE , _account);
    }
}

File 29 of 104 : ERC165.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "./IERC165.sol";

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts may inherit from this and call {_registerInterface} to declare
 * their support of an interface.
 */
abstract contract ERC165 is IERC165 {
    /*
     * bytes4(keccak256('supportsInterface(bytes4)')) == 0x01ffc9a7
     */
    bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7;

    /**
     * @dev Mapping of interface ids to whether or not it's supported.
     */
    mapping(bytes4 => bool) private _supportedInterfaces;

    constructor () internal {
        // Derived contracts need only register support for their own interfaces,
        // we register support for ERC165 itself here
        _registerInterface(_INTERFACE_ID_ERC165);
    }

    /**
     * @dev See {IERC165-supportsInterface}.
     *
     * Time complexity O(1), guaranteed to always use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return _supportedInterfaces[interfaceId];
    }

    /**
     * @dev Registers the contract as an implementer of the interface defined by
     * `interfaceId`. Support of the actual ERC165 interface is automatic and
     * registering its interface id is not required.
     *
     * See {IERC165-supportsInterface}.
     *
     * Requirements:
     *
     * - `interfaceId` cannot be the ERC165 invalid interface (`0xffffffff`).
     */
    function _registerInterface(bytes4 interfaceId) internal virtual {
        require(interfaceId != 0xffffffff, "ERC165: invalid interface id");
        _supportedInterfaces[interfaceId] = true;
    }
}

File 30 of 104 : IHasSecondarySale.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;

interface IHasSecondarySale {

    /*
     * bytes4(keccak256('checkSecondarySale(uint256)')) == 0x0e883747
     * bytes4(keccak256('setSecondarySale(uint256)')) == 0x5b1d0f4d
     *
     * => 0x0e883747 ^ 0x5b1d0f4d == 0x5595380a
     */
//    bytes4 private constant _INTERFACE_ID_HAS_SECONDARY_SALE = 0x5595380a;
//
//    constructor() public {
//        _registerInterface(_INTERFACE_ID_HAS_SECONDARY_SALE);
//    }

    function checkSecondarySale(uint256 tokenId) external view returns (bool);
    function setSecondarySale(uint256 tokenId) external;
}

File 31 of 104 : ITokenManager.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;

interface ITokenManager {
    function setToken(address _token, bool _active) external;

    function removeToken(address _token) external;

    function supportToken(address _token) external view returns (bool);
}

File 32 of 104 : IRoyalty.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "../libs/RoyaltyLibrary.sol";

interface IRoyalty {
    using RoyaltyLibrary for RoyaltyLibrary.Strategy;
    using RoyaltyLibrary for RoyaltyLibrary.RoyaltyInfo;
    using RoyaltyLibrary for RoyaltyLibrary.RoyaltyShareDetails;

    /*
     * bytes4(keccak256('getRoyalty(uint256)')) == 0x1af9cf49
     * bytes4(keccak256('getRoyaltyShares(uint256)')) == 0xac04f243
     * bytes4(keccak256('getTokenContract()') == 0x28b7bede
     *
     * => 0x1af9cf49 ^ 0xac04f243 ^ 0x28b7bede  == 0x9e4a83d4
     */

    //    bytes4 private constant _INTERFACE_ID_ROYALTY = 0x9e4a83d4;
    //
    //    constructor() public {
    //        _registerInterface(_INTERFACE_ID_ROYALTY);
    //    }

    function getRoyalty(uint256 _tokenId) external view returns (RoyaltyLibrary.RoyaltyInfo memory);

    function getRoyaltyShares(uint256 _tokenId) external view returns (RoyaltyLibrary.RoyaltyShareDetails[] memory);

    function getTokenContract() external view returns (address);
}

File 33 of 104 : NftTokenLibrary.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;

library NftTokenLibrary {
    // DO NOT change the ordering
    enum TokenType {
        ERC721_CONTRACT, // 0
        ERC1155_CONTRACT, // 1
        REFINABLE_ERC721_CONTRACT, // 2
        REFINABLE_ERC1155_CONTRACT, // 3
        REFINABLE_ERC721_V2_CONTRACT, // 4
        REFINABLE_ERC1155_V2_CONTRACT, // 5
        REFINABLE_WHITELISTED_ERC721_CONTRACT, // 6
        REFINABLE_WHITELISTED_ERC1155_CONTRACT, // 7
        REFINABLE_WHITELISTED_ERC721_V2_CONTRACT, // 8
        REFINABLE_WHITELISTED_ERC1155_V2_CONTRACT, // 9
        REFINABLE_WHITELISTED_ERC721_V3_CONTRACT, // 10
        REFINABLE_WHITELISTED_ERC1155_V3_CONTRACT, // 11
        REFINABLE_ROYALTY_ERC721_CONTRACT, // 12
        REFINABLE_ROYALTY_ERC1155_CONTRACT // 13
    }
}

File 34 of 104 : ERC721BaseV2.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/token/ERC721/ERC721Burnable.sol";
import "../HasContractURI.sol";
import "../HasSecondarySale.sol";
import "../../roles/MinterRole.sol";
import "../../libs/RoyaltyLibrary.sol";
import "../Royalty.sol";

/**
 * @title Full ERC721 Token with support for baseURI
 * This implementation includes all the required and some optional functionality of the ERC721 standard
 * Moreover, it includes approve all functionality using operator terminology
 * @dev see https://eips.ethereum.org/EIPS/eip-721
 */
abstract contract ERC721BaseV2 is
HasSecondarySale,
HasContractURI,
ERC721Burnable,
MinterRole,
Royalty
{
    /// @dev sale is primary or secondary
    mapping(uint256 => bool) public isSecondarySale;

    /*
     * bytes4(keccak256('MINT_WITH_ADDRESS')) == 0xe37243f2
     */
    bytes4 private constant _INTERFACE_ID_MINT_WITH_ADDRESS = 0xe37243f2;


    /**
     * @dev Constructor function
     */
    constructor(
        string memory _name,
        string memory _symbol,
        string memory contractURI,
        string memory _baseURI
    ) public HasContractURI(contractURI) ERC721(_name, _symbol) {
        // register the supported interfaces to conform to ERC721 via ERC165
        _registerInterface(_INTERFACE_ID_MINT_WITH_ADDRESS);
        _setBaseURI(_baseURI);
    }

    function checkSecondarySale(uint256 _tokenId) public view override returns (bool) {
        return isSecondarySale[_tokenId];
    }

    function setSecondarySale(uint256 _tokenId) public override {
        isSecondarySale[_tokenId] = true;
    }

    function _mint(
        address _to,
        uint256 _tokenId,
        RoyaltyLibrary.RoyaltyShareDetails[] memory _royaltyShares,
        string memory _uri,
        uint256 _royaltyBps,
        RoyaltyLibrary.Strategy _royaltyStrategy
    ) internal {
        require(_exists(_tokenId) == false, "ERC721: Token is already minted");
        require(bytes(_uri).length > 0, "ERC721: Uri should be set");

        _mint(_to, _tokenId);
        _setTokenURI(_tokenId, _uri);
        uint256 sumRoyaltyShareBps;
        for (uint256 i = 0; i < _royaltyShares.length; i++) {
            sumRoyaltyShareBps = sumRoyaltyShareBps.add(_royaltyShares[i].value);
        }

        if(_royaltyStrategy == RoyaltyLibrary.Strategy.ROYALTY_STRATEGY) {
            require(
                sumRoyaltyShareBps <= 10**4,
                "ERC721: Total fee bps should not exceed 10000"
            );
            _setRoyalty(_tokenId, sumRoyaltyShareBps, RoyaltyLibrary.Strategy.ROYALTY_STRATEGY);
        } else if (_royaltyStrategy == RoyaltyLibrary.Strategy.PROFIT_DISTRIBUTION_STRATEGY) {
            require(
                sumRoyaltyShareBps == 10**4,
                "ERC721: Total fee bps should be 10000"
            );
            _setRoyalty(_tokenId, _royaltyBps,  RoyaltyLibrary.Strategy.PROFIT_DISTRIBUTION_STRATEGY);
        }else{
            revert("ERC721: Royalty option does not exist");
        }
        _addRoyaltyShares(_tokenId, _royaltyShares);
    }

    function setBaseURI(string memory _baseURI) public onlyAdmin {
        _setBaseURI(_baseURI);
    }

    function setContractURI(string memory _contractURI) public onlyAdmin {
        _setContractURI(_contractURI);
    }
}

File 35 of 104 : Royalty.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/GSN/Context.sol";
import "@openzeppelin/contracts/introspection/ERC165.sol";
import "../libs/RoyaltyLibrary.sol";
import "../interfaces/IRoyalty.sol";
import "../interfaces/IPrimaryRoyalty.sol";
import "../interfaces/ICreator.sol";

abstract contract Royalty is Context, ERC165, IRoyalty, IPrimaryRoyalty, ICreator {
    event SetRoyaltyShares (
        uint256 indexed tokenId,
        address[] recipients,
        uint[] bp
    );

    event SetRoyalty (
        address owner,
        uint256 indexed tokenId,
        uint256 value,
        RoyaltyLibrary.Strategy strategy
    );

    event SetPrimaryRoyaltyShares (
        uint256 indexed tokenId,
        address[] recipients,
        uint[] bp
    );

    // tokenId => royalty
    mapping(uint256 => RoyaltyLibrary.RoyaltyInfo) public royalty;

    // tokenId => royaltyShares
    mapping(uint256 => RoyaltyLibrary.RoyaltyShareDetails[]) public royaltyShares;

    // tokenId => creator address
    mapping(uint256 => address) creators;

    // tokenId => primary royalty
    mapping(uint256 => RoyaltyLibrary.RoyaltyShareDetails[]) primaryRoyaltyShares;

    // Max count of royalty shares
    uint256 maxRoyaltyShareCount = 100;

    /*
     * bytes4(keccak256('getRoyalty(uint256 _tokenId)')) == 0x71f1e123
     * bytes4(keccak256('getRoyaltyShares(uint256 _tokenId)')) == 0x8e9727ba
     * bytes4(keccak256('_setRoyalty(uint256 _tokenId, uint256 _bps, RoyaltyLibrary.Strategy _strategy')) == 0x8bb6c361
     * bytes4(keccak256('_addRoyaltyShares(uint256 _tokenId, RoyaltyLibrary.RoyaltyShareDetails[] memory _royaltyShares)')) == 0xa0034d9f
     * bytes4(keccak256('royalty()')) == 0x29ee566c
     * bytes4(keccak256('royaltyShares()')) == 0x861475d2
     *
     * => 0x71f1e123 ^ 0x8e9727ba ^ 0x8bb6c361 ^ 0xa0034d9f ^ 0x29ee566c ^ 0x861475d2 == 0x7b296bd9
     */

    // IMPORTANT: This is version 1 of the royalty. Please do not delete for record.
    bytes4 private constant _INTERFACE_ID_ROYALTY = 0x7b296bd9;

    // From IRoyalty
    bytes4 private constant _INTERFACE_ID_ROYALTY_V2 = 0x9e4a83d4;

    constructor() public {
        _registerInterface(_INTERFACE_ID_ROYALTY_V2);
        _registerInterface(type(IPrimaryRoyalty).interfaceId);
        _registerInterface(type(ICreator).interfaceId);
    }

    function getTokenContract() public view override returns (address) {
        return address(this);
    }

    function getRoyalty(uint256 _tokenId) public view override returns (RoyaltyLibrary.RoyaltyInfo memory) {
        return royalty[_tokenId];
    }

    function getRoyaltyShares(uint256 _tokenId) public view override returns (RoyaltyLibrary.RoyaltyShareDetails[] memory) {
        return royaltyShares[_tokenId];
    }

    function getPrimaryRoyaltyShares(uint256 _tokenId) external view override returns (RoyaltyLibrary.RoyaltyShareDetails[] memory) {
        return primaryRoyaltyShares[_tokenId];
    }

    function getCreator(uint256 _tokenId) external view override returns (address) {
        return creators[_tokenId];
    }

    function _setRoyalty(uint256 _tokenId, uint256 _bps, RoyaltyLibrary.Strategy _strategy) internal {
        require(
            _bps <= 10 ** 4,
            "Royalty: Total royalty bps should not exceed 10000"
        );
        royalty[_tokenId] = RoyaltyLibrary.RoyaltyInfo({
        value : _bps,
        strategy : _strategy
        });
        emit SetRoyalty(_msgSender(), _tokenId, _bps, _strategy);
    }

    function _addRoyaltyShares(uint256 _tokenId, RoyaltyLibrary.RoyaltyShareDetails[] memory _royaltyShares) internal {
        require(
            _royaltyShares.length <= maxRoyaltyShareCount,
            "Royalty: Amount of royalty recipients can't exceed 100"
        );

        address[] memory recipients = new address[](_royaltyShares.length);
        uint[] memory bps = new uint[](_royaltyShares.length);
        for (uint i = 0; i < _royaltyShares.length; i++) {
            require(_royaltyShares[i].recipient != address(0x0), "Royalty: Royalty share recipient should be present");
            require(_royaltyShares[i].value != 0, "Royalty: Royalty share bps value should be positive");
            royaltyShares[_tokenId].push(_royaltyShares[i]);
            recipients[i] = _royaltyShares[i].recipient;
            bps[i] = _royaltyShares[i].value;
        }
        if (_royaltyShares.length > 0) {
            emit SetRoyaltyShares(_tokenId, recipients, bps);
        }
    }

    function _addPrimaryRoyaltyShares(uint256 _tokenId, RoyaltyLibrary.RoyaltyShareDetails[] memory _royaltyShares) internal {
        require(
            _royaltyShares.length <= maxRoyaltyShareCount,
            "Royalty: Amount of royalty recipients can't exceed 100"
        );

        address[] memory recipients = new address[](_royaltyShares.length);
        uint[] memory bps = new uint[](_royaltyShares.length);
        // Pushing the royalty shares into the mapping
        for (uint i = 0; i < _royaltyShares.length; i++) {
            require(_royaltyShares[i].recipient != address(0x0), "Royalty: Primary royalty share recipient should be present");
            require(_royaltyShares[i].value != 0, "Royalty: Primary royalty share bps value should be positive");
            primaryRoyaltyShares[_tokenId].push(_royaltyShares[i]);
            recipients[i] = _royaltyShares[i].recipient;
            bps[i] = _royaltyShares[i].value;
        }
        if (_royaltyShares.length > 0) {
            emit SetPrimaryRoyaltyShares(_tokenId, recipients, bps);
        }
    }
}

File 36 of 104 : IPrimaryRoyalty.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "../libs/RoyaltyLibrary.sol";

interface IPrimaryRoyalty {

    /*
     * bytes4(keccak256('getPrimaryRoyaltyShares(uint256)')) == 0x20b029a5
     */

    //    bytes4 private constant _INTERFACE_ID_PRIMARY_ROYALTY = 0x20b029a5;
    //
    //    constructor() public {
    //        _registerInterface(_INTERFACE_ID_PRIMARY_ROYALTY);
    //    }

    function getPrimaryRoyaltyShares(uint256 _tokenId) external view returns (RoyaltyLibrary.RoyaltyShareDetails[] memory);
}

File 37 of 104 : ERC721Burnable.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../../utils/Context.sol";
import "./ERC721.sol";

/**
 * @title ERC721 Burnable Token
 * @dev ERC721 Token that can be irreversibly burned (destroyed).
 */
abstract contract ERC721Burnable is Context, ERC721 {
    /**
     * @dev Burns `tokenId`. See {ERC721-_burn}.
     *
     * Requirements:
     *
     * - The caller must own `tokenId` or be an approved operator.
     */
    function burn(uint256 tokenId) public virtual {
        //solhint-disable-next-line max-line-length
        require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721Burnable: caller is not owner nor approved");
        _burn(tokenId);
    }
}

File 38 of 104 : HasContractURI.sol
pragma solidity ^0.6.12;
// SPDX-License-Identifier: UNLICENSED

import "@openzeppelin/contracts/introspection/ERC165.sol";

contract HasContractURI is ERC165 {

    string public contractURI;

    /*
     * bytes4(keccak256('contractURI()')) == 0xe8a3d485
     */
    bytes4 private constant _INTERFACE_ID_CONTRACT_URI = 0xe8a3d485;

    constructor(string memory _contractURI) public {
        contractURI = _contractURI;
        _registerInterface(_INTERFACE_ID_CONTRACT_URI);
    }

    /**
     * @dev Internal function to set the contract URI
     * @param _contractURI string URI prefix to assign
     */
    function _setContractURI(string memory _contractURI) internal {
        contractURI = _contractURI;
    }
}

File 39 of 104 : MinterRole.sol
pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;
// SPDX-License-Identifier: UNLICENSED

import "@openzeppelin/contracts/access/AccessControl.sol";

contract MinterRole is AccessControl {
    
    bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
    bytes32 public constant SIGNER_ROLE = keccak256("SIGNER_ROLE");

    modifier onlyAdmin() {
        require(isAdmin(_msgSender()), "Ownable: caller is not the admin");
        _;
    }

    modifier onlySigner() {
        require(isSigner(_msgSender()), "Ownable: caller is not the signer");
        _;
    }

    modifier onlyMinter() {
        require(isMinter(_msgSender()), "Ownable: caller is not the minter");
        _;
    }

    constructor() public {
        _setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
    }

    function addSigner(address _account) public onlyAdmin {
        grantRole(SIGNER_ROLE, _account);
    }

    function removeSigner(address _account) public onlyAdmin {
        revokeRole(SIGNER_ROLE, _account);
    }

    function addMinterBatch(address[] memory _accounts) public onlyAdmin {
        for(uint256 i = 0; i< _accounts.length; i++) {
            _setupRole(MINTER_ROLE, _accounts[i]);
        }
    }

    function addMinter(address _account) public onlyAdmin {
        _setupRole(MINTER_ROLE, _account);
    }

    function removeMinter(address _account) public onlyAdmin {
        revokeRole(MINTER_ROLE, _account);
    }

    function addAdmin(address _account) public onlyAdmin {
        _setupRole(DEFAULT_ADMIN_ROLE , _account);
    }

    function removeAdmin(address _account) public onlyAdmin {
        revokeRole(DEFAULT_ADMIN_ROLE , _account);
    }

    function isSigner(address _account) internal virtual view returns(bool) {
        return hasRole(SIGNER_ROLE, _account);
    }

    function isMinter(address _account) internal virtual view returns(bool) {
        return hasRole(MINTER_ROLE, _account);
    }

    function isAdmin(address _account) internal virtual view returns(bool) {
        return hasRole(DEFAULT_ADMIN_ROLE , _account);
    }
}

File 40 of 104 : ERC721.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../../utils/Context.sol";
import "./IERC721.sol";
import "./IERC721Metadata.sol";
import "./IERC721Enumerable.sol";
import "./IERC721Receiver.sol";
import "../../introspection/ERC165.sol";
import "../../math/SafeMath.sol";
import "../../utils/Address.sol";
import "../../utils/EnumerableSet.sol";
import "../../utils/EnumerableMap.sol";
import "../../utils/Strings.sol";

/**
 * @title ERC721 Non-Fungible Token Standard basic implementation
 * @dev see https://eips.ethereum.org/EIPS/eip-721
 */
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Enumerable {
    using SafeMath for uint256;
    using Address for address;
    using EnumerableSet for EnumerableSet.UintSet;
    using EnumerableMap for EnumerableMap.UintToAddressMap;
    using Strings for uint256;

    // 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 holder address to their (enumerable) set of owned tokens
    mapping (address => EnumerableSet.UintSet) private _holderTokens;

    // Enumerable mapping from token ids to their owners
    EnumerableMap.UintToAddressMap private _tokenOwners;

    // Mapping from token ID to approved address
    mapping (uint256 => address) private _tokenApprovals;

    // Mapping from owner to operator approvals
    mapping (address => mapping (address => bool)) private _operatorApprovals;

    // Token name
    string private _name;

    // Token symbol
    string private _symbol;

    // Optional mapping for token URIs
    mapping (uint256 => string) private _tokenURIs;

    // Base URI
    string private _baseURI;

    /*
     *     bytes4(keccak256('balanceOf(address)')) == 0x70a08231
     *     bytes4(keccak256('ownerOf(uint256)')) == 0x6352211e
     *     bytes4(keccak256('approve(address,uint256)')) == 0x095ea7b3
     *     bytes4(keccak256('getApproved(uint256)')) == 0x081812fc
     *     bytes4(keccak256('setApprovalForAll(address,bool)')) == 0xa22cb465
     *     bytes4(keccak256('isApprovedForAll(address,address)')) == 0xe985e9c5
     *     bytes4(keccak256('transferFrom(address,address,uint256)')) == 0x23b872dd
     *     bytes4(keccak256('safeTransferFrom(address,address,uint256)')) == 0x42842e0e
     *     bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) == 0xb88d4fde
     *
     *     => 0x70a08231 ^ 0x6352211e ^ 0x095ea7b3 ^ 0x081812fc ^
     *        0xa22cb465 ^ 0xe985e9c5 ^ 0x23b872dd ^ 0x42842e0e ^ 0xb88d4fde == 0x80ac58cd
     */
    bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd;

    /*
     *     bytes4(keccak256('name()')) == 0x06fdde03
     *     bytes4(keccak256('symbol()')) == 0x95d89b41
     *     bytes4(keccak256('tokenURI(uint256)')) == 0xc87b56dd
     *
     *     => 0x06fdde03 ^ 0x95d89b41 ^ 0xc87b56dd == 0x5b5e139f
     */
    bytes4 private constant _INTERFACE_ID_ERC721_METADATA = 0x5b5e139f;

    /*
     *     bytes4(keccak256('totalSupply()')) == 0x18160ddd
     *     bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) == 0x2f745c59
     *     bytes4(keccak256('tokenByIndex(uint256)')) == 0x4f6ccce7
     *
     *     => 0x18160ddd ^ 0x2f745c59 ^ 0x4f6ccce7 == 0x780e9d63
     */
    bytes4 private constant _INTERFACE_ID_ERC721_ENUMERABLE = 0x780e9d63;

    /**
     * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
     */
    constructor (string memory name_, string memory symbol_) public {
        _name = name_;
        _symbol = symbol_;

        // register the supported interfaces to conform to ERC721 via ERC165
        _registerInterface(_INTERFACE_ID_ERC721);
        _registerInterface(_INTERFACE_ID_ERC721_METADATA);
        _registerInterface(_INTERFACE_ID_ERC721_ENUMERABLE);
    }

    /**
     * @dev See {IERC721-balanceOf}.
     */
    function balanceOf(address owner) public view virtual override returns (uint256) {
        require(owner != address(0), "ERC721: balance query for the zero address");
        return _holderTokens[owner].length();
    }

    /**
     * @dev See {IERC721-ownerOf}.
     */
    function ownerOf(uint256 tokenId) public view virtual override returns (address) {
        return _tokenOwners.get(tokenId, "ERC721: owner query for nonexistent token");
    }

    /**
     * @dev See {IERC721Metadata-name}.
     */
    function name() public view virtual override returns (string memory) {
        return _name;
    }

    /**
     * @dev See {IERC721Metadata-symbol}.
     */
    function symbol() public view virtual override returns (string memory) {
        return _symbol;
    }

    /**
     * @dev See {IERC721Metadata-tokenURI}.
     */
    function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
        require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");

        string memory _tokenURI = _tokenURIs[tokenId];
        string memory base = baseURI();

        // If there is no base URI, return the token URI.
        if (bytes(base).length == 0) {
            return _tokenURI;
        }
        // If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked).
        if (bytes(_tokenURI).length > 0) {
            return string(abi.encodePacked(base, _tokenURI));
        }
        // If there is a baseURI but no tokenURI, concatenate the tokenID to the baseURI.
        return string(abi.encodePacked(base, tokenId.toString()));
    }

    /**
    * @dev Returns the base URI set via {_setBaseURI}. This will be
    * automatically added as a prefix in {tokenURI} to each token's URI, or
    * to the token ID if no specific URI is set for that token ID.
    */
    function baseURI() public view virtual returns (string memory) {
        return _baseURI;
    }

    /**
     * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
     */
    function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) {
        return _holderTokens[owner].at(index);
    }

    /**
     * @dev See {IERC721Enumerable-totalSupply}.
     */
    function totalSupply() public view virtual override returns (uint256) {
        // _tokenOwners are indexed by tokenIds, so .length() returns the number of tokenIds
        return _tokenOwners.length();
    }

    /**
     * @dev See {IERC721Enumerable-tokenByIndex}.
     */
    function tokenByIndex(uint256 index) public view virtual override returns (uint256) {
        (uint256 tokenId, ) = _tokenOwners.at(index);
        return tokenId;
    }

    /**
     * @dev See {IERC721-approve}.
     */
    function approve(address to, uint256 tokenId) public virtual override {
        address owner = ERC721.ownerOf(tokenId);
        require(to != owner, "ERC721: approval to current owner");

        require(_msgSender() == owner || ERC721.isApprovedForAll(owner, _msgSender()),
            "ERC721: approve caller is not owner nor approved for all"
        );

        _approve(to, tokenId);
    }

    /**
     * @dev See {IERC721-getApproved}.
     */
    function getApproved(uint256 tokenId) public view virtual override returns (address) {
        require(_exists(tokenId), "ERC721: approved query for nonexistent token");

        return _tokenApprovals[tokenId];
    }

    /**
     * @dev See {IERC721-setApprovalForAll}.
     */
    function setApprovalForAll(address operator, bool approved) public virtual override {
        require(operator != _msgSender(), "ERC721: approve to caller");

        _operatorApprovals[_msgSender()][operator] = approved;
        emit ApprovalForAll(_msgSender(), operator, approved);
    }

    /**
     * @dev See {IERC721-isApprovedForAll}.
     */
    function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
        return _operatorApprovals[owner][operator];
    }

    /**
     * @dev See {IERC721-transferFrom}.
     */
    function transferFrom(address from, address to, uint256 tokenId) public virtual override {
        //solhint-disable-next-line max-line-length
        require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");

        _transfer(from, to, tokenId);
    }

    /**
     * @dev See {IERC721-safeTransferFrom}.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override {
        safeTransferFrom(from, to, tokenId, "");
    }

    /**
     * @dev See {IERC721-safeTransferFrom}.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) public virtual override {
        require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
        _safeTransfer(from, to, tokenId, _data);
    }

    /**
     * @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.
     *
     * `_data` is additional data, it has no specified format and it is sent in call to `to`.
     *
     * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
     * implement alternative mechanisms to perform token transfer, such as signature-based.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function _safeTransfer(address from, address to, uint256 tokenId, bytes memory _data) internal virtual {
        _transfer(from, to, tokenId);
        require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
    }

    /**
     * @dev Returns whether `tokenId` exists.
     *
     * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
     *
     * Tokens start existing when they are minted (`_mint`),
     * and stop existing when they are burned (`_burn`).
     */
    function _exists(uint256 tokenId) internal view virtual returns (bool) {
        return _tokenOwners.contains(tokenId);
    }

    /**
     * @dev Returns whether `spender` is allowed to manage `tokenId`.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
        require(_exists(tokenId), "ERC721: operator query for nonexistent token");
        address owner = ERC721.ownerOf(tokenId);
        return (spender == owner || getApproved(tokenId) == spender || ERC721.isApprovedForAll(owner, spender));
    }

    /**
     * @dev Safely mints `tokenId` and transfers it to `to`.
     *
     * Requirements:
     d*
     * - `tokenId` must not exist.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function _safeMint(address to, uint256 tokenId) internal virtual {
        _safeMint(to, tokenId, "");
    }

    /**
     * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
     * forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
     */
    function _safeMint(address to, uint256 tokenId, bytes memory _data) internal virtual {
        _mint(to, tokenId);
        require(_checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
    }

    /**
     * @dev Mints `tokenId` and transfers it to `to`.
     *
     * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
     *
     * Requirements:
     *
     * - `tokenId` must not exist.
     * - `to` cannot be the zero address.
     *
     * Emits a {Transfer} event.
     */
    function _mint(address to, uint256 tokenId) internal virtual {
        require(to != address(0), "ERC721: mint to the zero address");
        require(!_exists(tokenId), "ERC721: token already minted");

        _beforeTokenTransfer(address(0), to, tokenId);

        _holderTokens[to].add(tokenId);

        _tokenOwners.set(tokenId, to);

        emit Transfer(address(0), to, tokenId);
    }

    /**
     * @dev Destroys `tokenId`.
     * The approval is cleared when the token is burned.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     *
     * Emits a {Transfer} event.
     */
    function _burn(uint256 tokenId) internal virtual {
        address owner = ERC721.ownerOf(tokenId); // internal owner

        _beforeTokenTransfer(owner, address(0), tokenId);

        // Clear approvals
        _approve(address(0), tokenId);

        // Clear metadata (if any)
        if (bytes(_tokenURIs[tokenId]).length != 0) {
            delete _tokenURIs[tokenId];
        }

        _holderTokens[owner].remove(tokenId);

        _tokenOwners.remove(tokenId);

        emit Transfer(owner, address(0), tokenId);
    }

    /**
     * @dev Transfers `tokenId` from `from` to `to`.
     *  As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     *
     * Emits a {Transfer} event.
     */
    function _transfer(address from, address to, uint256 tokenId) internal virtual {
        require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own"); // internal owner
        require(to != address(0), "ERC721: transfer to the zero address");

        _beforeTokenTransfer(from, to, tokenId);

        // Clear approvals from the previous owner
        _approve(address(0), tokenId);

        _holderTokens[from].remove(tokenId);
        _holderTokens[to].add(tokenId);

        _tokenOwners.set(tokenId, to);

        emit Transfer(from, to, tokenId);
    }

    /**
     * @dev Sets `_tokenURI` as the tokenURI of `tokenId`.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual {
        require(_exists(tokenId), "ERC721Metadata: URI set of nonexistent token");
        _tokenURIs[tokenId] = _tokenURI;
    }

    /**
     * @dev Internal function to set the base URI for all token IDs. It is
     * automatically added as a prefix to the value returned in {tokenURI},
     * or to the token ID if {tokenURI} is empty.
     */
    function _setBaseURI(string memory baseURI_) internal virtual {
        _baseURI = baseURI_;
    }

    /**
     * @dev Internal function to invoke {IERC721Receiver-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 bool whether the call correctly returned the expected magic value
     */
    function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory _data)
        private returns (bool)
    {
        if (!to.isContract()) {
            return true;
        }
        bytes memory returndata = to.functionCall(abi.encodeWithSelector(
            IERC721Receiver(to).onERC721Received.selector,
            _msgSender(),
            from,
            tokenId,
            _data
        ), "ERC721: transfer to non ERC721Receiver implementer");
        bytes4 retval = abi.decode(returndata, (bytes4));
        return (retval == _ERC721_RECEIVED);
    }

    /**
     * @dev Approve `to` to operate on `tokenId`
     *
     * Emits an {Approval} event.
     */
    function _approve(address to, uint256 tokenId) internal virtual {
        _tokenApprovals[tokenId] = to;
        emit Approval(ERC721.ownerOf(tokenId), to, tokenId); // internal owner
    }

    /**
     * @dev Hook that is called before any token transfer. This includes minting
     * and burning.
     *
     * Calling conditions:
     *
     * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
     * transferred to `to`.
     * - When `from` is zero, `tokenId` will be minted for `to`.
     * - When `to` is zero, ``from``'s `tokenId` will be burned.
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual { }
}

File 41 of 104 : IERC721Metadata.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.2 <0.8.0;

import "./IERC721.sol";

/**
 * @title ERC-721 Non-Fungible Token Standard, optional metadata extension
 * @dev See https://eips.ethereum.org/EIPS/eip-721
 */
interface IERC721Metadata is IERC721 {

    /**
     * @dev Returns the token collection name.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the token collection symbol.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
     */
    function tokenURI(uint256 tokenId) external view returns (string memory);
}

File 42 of 104 : IERC721Enumerable.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.2 <0.8.0;

import "./IERC721.sol";

/**
 * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
 * @dev See https://eips.ethereum.org/EIPS/eip-721
 */
interface IERC721Enumerable is IERC721 {

    /**
     * @dev Returns the total amount of tokens stored by the contract.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns a token ID owned by `owner` at a given `index` of its token list.
     * Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
     */
    function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId);

    /**
     * @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
     * Use along with {totalSupply} to enumerate all tokens.
     */
    function tokenByIndex(uint256 index) external view returns (uint256);
}

File 43 of 104 : IERC721Receiver.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/**
 * @title ERC721 token receiver interface
 * @dev Interface for any contract that wants to support safeTransfers
 * from ERC721 asset contracts.
 */
interface IERC721Receiver {
    /**
     * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
     * by `operator` from `from`, this function is called.
     *
     * It must return its Solidity selector to confirm the token transfer.
     * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
     *
     * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.
     */
    function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) external returns (bytes4);
}

File 44 of 104 : EnumerableMap.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/**
 * @dev Library for managing an enumerable variant of Solidity's
 * https://solidity.readthedocs.io/en/latest/types.html#mapping-types[`mapping`]
 * type.
 *
 * Maps have the following properties:
 *
 * - Entries are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Entries are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```
 * contract Example {
 *     // Add the library methods
 *     using EnumerableMap for EnumerableMap.UintToAddressMap;
 *
 *     // Declare a set state variable
 *     EnumerableMap.UintToAddressMap private myMap;
 * }
 * ```
 *
 * As of v3.0.0, only maps of type `uint256 -> address` (`UintToAddressMap`) are
 * supported.
 */
library EnumerableMap {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Map type with
    // bytes32 keys and values.
    // The Map implementation uses private functions, and user-facing
    // implementations (such as Uint256ToAddressMap) are just wrappers around
    // the underlying Map.
    // This means that we can only create new EnumerableMaps for types that fit
    // in bytes32.

    struct MapEntry {
        bytes32 _key;
        bytes32 _value;
    }

    struct Map {
        // Storage of map keys and values
        MapEntry[] _entries;

        // Position of the entry defined by a key in the `entries` array, plus 1
        // because index 0 means a key is not in the map.
        mapping (bytes32 => uint256) _indexes;
    }

    /**
     * @dev Adds a key-value pair to a map, or updates the value for an existing
     * key. O(1).
     *
     * Returns true if the key was added to the map, that is if it was not
     * already present.
     */
    function _set(Map storage map, bytes32 key, bytes32 value) private returns (bool) {
        // We read and store the key's index to prevent multiple reads from the same storage slot
        uint256 keyIndex = map._indexes[key];

        if (keyIndex == 0) { // Equivalent to !contains(map, key)
            map._entries.push(MapEntry({ _key: key, _value: value }));
            // The entry is stored at length-1, but we add 1 to all indexes
            // and use 0 as a sentinel value
            map._indexes[key] = map._entries.length;
            return true;
        } else {
            map._entries[keyIndex - 1]._value = value;
            return false;
        }
    }

    /**
     * @dev Removes a key-value pair from a map. O(1).
     *
     * Returns true if the key was removed from the map, that is if it was present.
     */
    function _remove(Map storage map, bytes32 key) private returns (bool) {
        // We read and store the key's index to prevent multiple reads from the same storage slot
        uint256 keyIndex = map._indexes[key];

        if (keyIndex != 0) { // Equivalent to contains(map, key)
            // To delete a key-value pair from the _entries array in O(1), we swap the entry to delete with the last one
            // in the array, and then remove the last entry (sometimes called as 'swap and pop').
            // This modifies the order of the array, as noted in {at}.

            uint256 toDeleteIndex = keyIndex - 1;
            uint256 lastIndex = map._entries.length - 1;

            // When the entry to delete is the last one, the swap operation is unnecessary. However, since this occurs
            // so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement.

            MapEntry storage lastEntry = map._entries[lastIndex];

            // Move the last entry to the index where the entry to delete is
            map._entries[toDeleteIndex] = lastEntry;
            // Update the index for the moved entry
            map._indexes[lastEntry._key] = toDeleteIndex + 1; // All indexes are 1-based

            // Delete the slot where the moved entry was stored
            map._entries.pop();

            // Delete the index for the deleted slot
            delete map._indexes[key];

            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Returns true if the key is in the map. O(1).
     */
    function _contains(Map storage map, bytes32 key) private view returns (bool) {
        return map._indexes[key] != 0;
    }

    /**
     * @dev Returns the number of key-value pairs in the map. O(1).
     */
    function _length(Map storage map) private view returns (uint256) {
        return map._entries.length;
    }

   /**
    * @dev Returns the key-value pair stored at position `index` in the map. O(1).
    *
    * Note that there are no guarantees on the ordering of entries inside the
    * array, and it may change when more entries are added or removed.
    *
    * Requirements:
    *
    * - `index` must be strictly less than {length}.
    */
    function _at(Map storage map, uint256 index) private view returns (bytes32, bytes32) {
        require(map._entries.length > index, "EnumerableMap: index out of bounds");

        MapEntry storage entry = map._entries[index];
        return (entry._key, entry._value);
    }

    /**
     * @dev Tries to returns the value associated with `key`.  O(1).
     * Does not revert if `key` is not in the map.
     */
    function _tryGet(Map storage map, bytes32 key) private view returns (bool, bytes32) {
        uint256 keyIndex = map._indexes[key];
        if (keyIndex == 0) return (false, 0); // Equivalent to contains(map, key)
        return (true, map._entries[keyIndex - 1]._value); // All indexes are 1-based
    }

    /**
     * @dev Returns the value associated with `key`.  O(1).
     *
     * Requirements:
     *
     * - `key` must be in the map.
     */
    function _get(Map storage map, bytes32 key) private view returns (bytes32) {
        uint256 keyIndex = map._indexes[key];
        require(keyIndex != 0, "EnumerableMap: nonexistent key"); // Equivalent to contains(map, key)
        return map._entries[keyIndex - 1]._value; // All indexes are 1-based
    }

    /**
     * @dev Same as {_get}, with a custom error message when `key` is not in the map.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {_tryGet}.
     */
    function _get(Map storage map, bytes32 key, string memory errorMessage) private view returns (bytes32) {
        uint256 keyIndex = map._indexes[key];
        require(keyIndex != 0, errorMessage); // Equivalent to contains(map, key)
        return map._entries[keyIndex - 1]._value; // All indexes are 1-based
    }

    // UintToAddressMap

    struct UintToAddressMap {
        Map _inner;
    }

    /**
     * @dev Adds a key-value pair to a map, or updates the value for an existing
     * key. O(1).
     *
     * Returns true if the key was added to the map, that is if it was not
     * already present.
     */
    function set(UintToAddressMap storage map, uint256 key, address value) internal returns (bool) {
        return _set(map._inner, bytes32(key), bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the key was removed from the map, that is if it was present.
     */
    function remove(UintToAddressMap storage map, uint256 key) internal returns (bool) {
        return _remove(map._inner, bytes32(key));
    }

    /**
     * @dev Returns true if the key is in the map. O(1).
     */
    function contains(UintToAddressMap storage map, uint256 key) internal view returns (bool) {
        return _contains(map._inner, bytes32(key));
    }

    /**
     * @dev Returns the number of elements in the map. O(1).
     */
    function length(UintToAddressMap storage map) internal view returns (uint256) {
        return _length(map._inner);
    }

   /**
    * @dev Returns the element 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(UintToAddressMap storage map, uint256 index) internal view returns (uint256, address) {
        (bytes32 key, bytes32 value) = _at(map._inner, index);
        return (uint256(key), address(uint160(uint256(value))));
    }

    /**
     * @dev Tries to returns the value associated with `key`.  O(1).
     * Does not revert if `key` is not in the map.
     *
     * _Available since v3.4._
     */
    function tryGet(UintToAddressMap storage map, uint256 key) internal view returns (bool, address) {
        (bool success, bytes32 value) = _tryGet(map._inner, bytes32(key));
        return (success, address(uint160(uint256(value))));
    }

    /**
     * @dev Returns the value associated with `key`.  O(1).
     *
     * Requirements:
     *
     * - `key` must be in the map.
     */
    function get(UintToAddressMap storage map, uint256 key) internal view returns (address) {
        return address(uint160(uint256(_get(map._inner, bytes32(key)))));
    }

    /**
     * @dev Same as {get}, with a custom error message when `key` is not in the map.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryGet}.
     */
    function get(UintToAddressMap storage map, uint256 key, string memory errorMessage) internal view returns (address) {
        return address(uint160(uint256(_get(map._inner, bytes32(key), errorMessage))));
    }
}

File 45 of 104 : Strings.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/**
 * @dev String operations.
 */
library Strings {
    /**
     * @dev Converts a `uint256` to its ASCII `string` 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);
        uint256 index = digits - 1;
        temp = value;
        while (temp != 0) {
            buffer[index--] = bytes1(uint8(48 + temp % 10));
            temp /= 10;
        }
        return string(buffer);
    }
}

File 46 of 104 : ICreator.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;

interface ICreator {
    /*
     * bytes4(keccak256('getCreator(uint256)')) == 0xd48e638a
     */

    //    bytes4 private constant _INTERFACE_ID_CREATOR = 0xd48e638a;
    //
    //    constructor() public {
    //        _registerInterface(_INTERFACE_ID_CREATOR);
    //    }

    function getCreator(uint256 _tokenId) external view returns (address);
}

File 47 of 104 : Ownable.sol
// 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;
    }
}

File 48 of 104 : ERC165Checker.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.2 <0.8.0;

/**
 * @dev Library used to query support of an interface declared via {IERC165}.
 *
 * Note that these functions return the actual result of the query: they do not
 * `revert` if an interface is not supported. It is up to the caller to decide
 * what to do in these cases.
 */
library ERC165Checker {
    // As per the EIP-165 spec, no interface should ever match 0xffffffff
    bytes4 private constant _INTERFACE_ID_INVALID = 0xffffffff;

    /*
     * bytes4(keccak256('supportsInterface(bytes4)')) == 0x01ffc9a7
     */
    bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7;

    /**
     * @dev Returns true if `account` supports the {IERC165} interface,
     */
    function supportsERC165(address account) internal view returns (bool) {
        // Any contract that implements ERC165 must explicitly indicate support of
        // InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid
        return _supportsERC165Interface(account, _INTERFACE_ID_ERC165) &&
            !_supportsERC165Interface(account, _INTERFACE_ID_INVALID);
    }

    /**
     * @dev Returns true if `account` supports the interface defined by
     * `interfaceId`. Support for {IERC165} itself is queried automatically.
     *
     * See {IERC165-supportsInterface}.
     */
    function supportsInterface(address account, bytes4 interfaceId) internal view returns (bool) {
        // query support of both ERC165 as per the spec and support of _interfaceId
        return supportsERC165(account) &&
            _supportsERC165Interface(account, interfaceId);
    }

    /**
     * @dev Returns a boolean array where each value corresponds to the
     * interfaces passed in and whether they're supported or not. This allows
     * you to batch check interfaces for a contract where your expectation
     * is that some interfaces may not be supported.
     *
     * See {IERC165-supportsInterface}.
     *
     * _Available since v3.4._
     */
    function getSupportedInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool[] memory) {
        // an array of booleans corresponding to interfaceIds and whether they're supported or not
        bool[] memory interfaceIdsSupported = new bool[](interfaceIds.length);

        // query support of ERC165 itself
        if (supportsERC165(account)) {
            // query support of each interface in interfaceIds
            for (uint256 i = 0; i < interfaceIds.length; i++) {
                interfaceIdsSupported[i] = _supportsERC165Interface(account, interfaceIds[i]);
            }
        }

        return interfaceIdsSupported;
    }

    /**
     * @dev Returns true if `account` supports all the interfaces defined in
     * `interfaceIds`. Support for {IERC165} itself is queried automatically.
     *
     * Batch-querying can lead to gas savings by skipping repeated checks for
     * {IERC165} support.
     *
     * See {IERC165-supportsInterface}.
     */
    function supportsAllInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool) {
        // query support of ERC165 itself
        if (!supportsERC165(account)) {
            return false;
        }

        // query support of each interface in _interfaceIds
        for (uint256 i = 0; i < interfaceIds.length; i++) {
            if (!_supportsERC165Interface(account, interfaceIds[i])) {
                return false;
            }
        }

        // all interfaces supported
        return true;
    }

    /**
     * @notice Query if a contract implements an interface, does not check ERC165 support
     * @param account The address of the contract to query for support of an interface
     * @param interfaceId The interface identifier, as specified in ERC-165
     * @return true if the contract at account indicates support of the interface with
     * identifier interfaceId, false otherwise
     * @dev Assumes that account contains a contract that supports ERC165, otherwise
     * the behavior of this method is undefined. This precondition can be checked
     * with {supportsERC165}.
     * Interface identification is specified in ERC-165.
     */
    function _supportsERC165Interface(address account, bytes4 interfaceId) private view returns (bool) {
        // success determines whether the staticcall succeeded and result determines
        // whether the contract at account indicates support of _interfaceId
        (bool success, bool result) = _callERC165SupportsInterface(account, interfaceId);

        return (success && result);
    }

    /**
     * @notice Calls the function with selector 0x01ffc9a7 (ERC165) and suppresses throw
     * @param account The address of the contract to query for support of an interface
     * @param interfaceId The interface identifier, as specified in ERC-165
     * @return success true if the STATICCALL succeeded, false otherwise
     * @return result true if the STATICCALL succeeded and the contract at account
     * indicates support of the interface with identifier interfaceId, false otherwise
     */
    function _callERC165SupportsInterface(address account, bytes4 interfaceId)
        private
        view
        returns (bool, bool)
    {
        bytes memory encodedParams = abi.encodeWithSelector(_INTERFACE_ID_ERC165, interfaceId);
        (bool success, bytes memory result) = account.staticcall{ gas: 30000 }(encodedParams);
        if (result.length < 32) return (false, false);
        return (success, abi.decode(result, (bool)));
    }
}

File 49 of 104 : ERC721Base.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;

import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";

import "../HasContractURI.sol";
import "./HasSecondarySaleFees.sol";
import "../HasSecondarySale.sol";

/**
 * @title Full ERC721 Token with support for baseURI
 * This implementation includes all the required and some optional functionality of the ERC721 standard
 * Moreover, it includes approve all functionality using operator terminology
 * @dev see https://eips.ethereum.org/EIPS/eip-721
 */
abstract contract ERC721Base is
    HasSecondarySaleFees,
    HasSecondarySale,
    ERC721,
    HasContractURI
{
    // Token name
    // Now in openzeppelin ERC721
    // string public override name;

    // Token symbol
    // Now in openzeppelin ERC721
    // string public override symbol;

    using SafeMath for uint256;

    struct Fee {
        address payable recipient;
        uint256 value;
    }

    // id => fees
    mapping(uint256 => Fee[]) public fees;

    /// @dev sale is primary or secondary
    mapping(uint256 => bool) public isSecondarySale;

    // Max count of fees
    uint256 maxFeesCount = 100;

    /*
     *     bytes4(keccak256('name()')) == 0x06fdde03
     *     bytes4(keccak256('symbol()')) == 0x95d89b41
     *     bytes4(keccak256('tokenURI(uint256)')) == 0xc87b56dd
     *
     *     => 0x06fdde03 ^ 0x95d89b41 ^ 0xc87b56dd == 0x5b5e139f
     */
    bytes4 private constant _INTERFACE_ID_ERC721_METADATA = 0x5b5e139f;

    /**
     * @dev Constructor function
     */
    constructor(
        string memory _name,
        string memory _symbol,
        string memory contractURI,
        string memory _baseURI
    ) public HasContractURI(contractURI) ERC721(_name, _symbol) {
        // register the supported interfaces to conform to ERC721 via ERC165
        _registerInterface(_INTERFACE_ID_ERC721_METADATA);
        _setBaseURI(_baseURI);
    }

    function getFeeRecipients(uint256 id)
        public
        view
        override
        returns (address payable[] memory)
    {
        Fee[] memory _fees = fees[id];
        address payable[] memory result = new address payable[](_fees.length);
        for (uint256 i = 0; i < _fees.length; i++) {
            result[i] = _fees[i].recipient;
        }
        return result;
    }

    function getFeeBps(uint256 id) public view override returns (uint256[] memory) {
        Fee[] memory _fees = fees[id];
        uint256[] memory result = new uint256[](_fees.length);
        for (uint256 i = 0; i < _fees.length; i++) {
            result[i] = _fees[i].value;
        }
        return result;
    }

    function checkSecondarySale(uint256 id) public view override returns(bool) {
        return isSecondarySale[id];
    }

    function setSecondarySale(uint256 id) public override {
        isSecondarySale[id] = true;
    }

    function _mint(
        address to,
        uint256 tokenId,
        Fee[] memory _fees
    ) internal {
        require(
            _fees.length <= maxFeesCount,
            "Amount of fee recipients can't exceed 100"
        );

        uint256 sumFeeBps = 0;
        for (uint256 i = 0; i < _fees.length; i++) {
            sumFeeBps = sumFeeBps.add(_fees[i].value);
        }

        require(
            sumFeeBps <= 10000,
            "Total fee bps should not exceed 10000"
        );

        _mint(to, tokenId);
        address[] memory recipients = new address[](_fees.length);
        uint256[] memory bps = new uint256[](_fees.length);
        for (uint256 i = 0; i < _fees.length; i++) {
            require(
                _fees[i].recipient != address(0x0),
                "Recipient should be present"
            );
            require(_fees[i].value != 0, "Fee value should be positive");
            fees[tokenId].push(_fees[i]);
            recipients[i] = _fees[i].recipient;
            bps[i] = _fees[i].value;
        }
        if (_fees.length > 0) {
            emit SecondarySaleFees(tokenId, recipients, bps);
        }
    }
}

File 50 of 104 : RefinableERC721WhiteListedToken.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/token/ERC721/IERC721Metadata.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721Burnable.sol";
import "@openzeppelin/contracts/cryptography/ECDSA.sol";
import "./ERC721Base.sol";
import "../../roles/MinterRole.sol";
import "../../libs/Ownable.sol";
/**
 * @title RefinableERC721TokenWhiteListed
 * @dev only minters can mint token.
 */
contract RefinableERC721WhiteListedToken is
IERC721,
IERC721Metadata,
ERC721Burnable,
ERC721Base,
MinterRole,
Ownable
{
    using ECDSA for bytes32;

    /**
     * @dev Constructor Function
     * @param _name name of the token ex: Rarible
     * @param _symbol symbol of the token ex: RARI
     * @param _root address of admin account
     * @param _signer address of signer account
     * @param _contractURI URI of contract ex: https://api-mainnet.rarible.com/contractMetadata/{address}
     * @param _baseURI ex: https://ipfs.daonomic.com
    */
    constructor(
        string memory _name,
        string memory _symbol,
        address _root,
        address _signer,
        string memory _contractURI,
        string memory _baseURI
    ) public ERC721Base(_name, _symbol, _contractURI, _baseURI) {
        addAdmin(_root);
        addSigner(_signer);
        _registerInterface(bytes4(keccak256("MINT_WITH_ADDRESS")));
    }

    function mint(
        uint256 _tokenId,
        bytes memory _signature,
        Fee[] memory _fees,
        string memory _tokenURI
    ) public onlyMinter {
        require(
            isSigner(
                keccak256(abi.encodePacked(address(this), _tokenId, msg.sender)).toEthSignedMessageHash().recover(_signature)
            ),
            "invalid signer"
        );
        _mint(msg.sender, _tokenId, _fees);
        _setTokenURI(_tokenId, _tokenURI);
    }

    function setBaseURI(string memory _baseURI) public onlyOwner {
        _setBaseURI(_baseURI);
    }

    function setContractURI(string memory _contractURI) public onlyOwner {
        _setContractURI(_contractURI);
    }
}

File 51 of 104 : Ownable.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.12;

abstract contract Ownable {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() public {
        _owner = msg.sender;
        emit OwnershipTransferred(address(0), msg.sender);
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        require(_owner == msg.sender, "Ownable: caller is not the owner");
        _;
    }
}

File 52 of 104 : RefinableERC721Token.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/token/ERC721/IERC721Metadata.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721Burnable.sol";
import "@openzeppelin/contracts/cryptography/ECDSA.sol";
import "./ERC721Base.sol";
import "../../roles/SignerRole.sol";
import "../../libs/Ownable.sol";

/**
 * @title RefinableERC721Token
 * @dev anyone can mint token.
 */
contract RefinableERC721Token is
    IERC721,
    IERC721Metadata,
    ERC721Burnable,
    ERC721Base,
    SignerRole,
    Ownable
{
    using ECDSA for bytes32;

    /**
     * @dev Constructor Function
     * @param _name name of the token ex: Rarible
     * @param _symbol symbol of the token ex: RARI
     * @param _root address of admin account
     * @param _signer address of signer account
     * @param _contractURI URI of contract ex: https://api-mainnet.rarible.com/contractMetadata/{address}
     * @param _baseURI ex: https://ipfs.daonomic.com
    */
    constructor(
        string memory _name,
        string memory _symbol,
        address _root,
        address _signer,
        string memory _contractURI,
        string memory _baseURI
    ) public ERC721Base(_name, _symbol, _contractURI, _baseURI) {
        addAdmin(_root);
        addSigner(_signer);
        _registerInterface(bytes4(keccak256("MINT_WITH_ADDRESS")));
    }

    function mint(
        uint256 _tokenId,
        bytes memory _signature,
        Fee[] memory _fees,
        string memory _tokenURI
    ) public {
        require(
            isSigner(
                keccak256(abi.encodePacked(address(this), _tokenId, msg.sender)).toEthSignedMessageHash().recover(_signature)
            ),
            "invalid signer"
        );
        _mint(msg.sender, _tokenId, _fees);
        _setTokenURI(_tokenId, _tokenURI);
    }

    function setBaseURI(string memory _baseURI) public onlyOwner {
        _setBaseURI(_baseURI);
    }

    function setContractURI(string memory _contractURI) public onlyOwner {
        _setContractURI(_contractURI);
    }
}

File 53 of 104 : SignerRole.sol
pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;
// SPDX-License-Identifier: UNLICENSED

import "@openzeppelin/contracts/access/AccessControl.sol";

contract SignerRole is AccessControl {
    
    bytes32 public constant SIGNER_ROLE = keccak256("SIGNER_ROLE");

    modifier onlyAdmin() {
        require(isAdmin(_msgSender()), "Ownable: caller is not the admin");
        _;
    }

    modifier onlySigner() {
        require(isSigner(_msgSender()), "Ownable: caller is not the signer");
        _;
    }

    constructor() public {
        _setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
    }

    function addAdmin(address _accont) internal onlyAdmin {
        grantRole(DEFAULT_ADMIN_ROLE , _accont);
    }

    function removeAdmin(address _accont) internal onlyAdmin {
        revokeRole(DEFAULT_ADMIN_ROLE , _accont);
    }

    function addSigner(address _account) public onlyAdmin {
        grantRole(SIGNER_ROLE, _account);
    }

    function removeSigner(address _account) public onlyAdmin {
        revokeRole(SIGNER_ROLE, _account);
    }

    function isSigner(address _account) public virtual view returns(bool) {
        return hasRole(SIGNER_ROLE, _account);
    }

    function isAdmin(address _account) internal virtual view returns(bool) {
        return hasRole(DEFAULT_ADMIN_ROLE , _account);
    }
}

File 54 of 104 : RefinableERC1155Token.sol
pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;
// SPDX-License-Identifier: UNLICENSED

import "@openzeppelin/contracts/cryptography/ECDSA.sol";
import "./ERC1155Base.sol";
import "../../roles/SignerRole.sol";

contract RefinableERC1155Token is ERC1155Base, SignerRole {
    
    using ECDSA for bytes32;

    string public name;
    string public symbol;

    /**
     * @dev Constructor Function
     * @param _name name of the token ex: Rarible
     * @param _symbol symbol of the token ex: RARI
     * @param _signer address of signer account
     * @param _contractURI URI of contract ex: https://api-mainnet.rarible.com/contractMetadata/{address}
     * @param _tokenURIPrefix token URI Prefix
     * @param _uri ex: https://ipfs.daonomic.com
    */
    constructor(string memory _name, string memory _symbol, address _signer, string memory _contractURI, string memory _tokenURIPrefix, string memory _uri) ERC1155Base(_contractURI, _tokenURIPrefix, _uri) public {
        name = _name;
        symbol = _symbol;

        addAdmin(_msgSender());
        addSigner(_msgSender());
        addSigner(_signer);
        _registerInterface(bytes4(keccak256('MINT_WITH_ADDRESS')));
    }

    function mint(uint256 _tokenId, bytes memory _signature, Fee[] memory _fees, uint256 _supply, string memory _uri) public {
        require(
            isSigner(
                keccak256(abi.encodePacked(address(this), _tokenId, _msgSender()))
                    .toEthSignedMessageHash()
                    .recover(_signature)
            )
            ,"invalid signature"
        );
        _mint(_tokenId, _fees, _supply, _uri);
    }
}

File 55 of 104 : ERC1155Base.sol
pragma solidity ^0.6.12;
// SPDX-License-Identifier: UNLICENSED

import "./HasSecondarySaleFees.sol";
import "./ERC1155Metadata_URI.sol";
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "../../libs/Ownable.sol";
import "../HasContractURI.sol";

abstract contract ERC1155Base is HasSecondarySaleFees, Ownable, ERC1155Metadata_URI, HasContractURI, ERC1155 {

    struct Fee {
        address payable recipient;
        uint256 value;
    }

    // id => creator
    mapping (uint256 => address) public creators;
    // id => fees
    mapping (uint256 => Fee[]) public fees;

    // Max count of fees
    uint256 maxFeesCount = 100;

    constructor(string memory contractURI, string memory tokenURIPrefix, string memory uri) HasContractURI(contractURI) ERC1155Metadata_URI(tokenURIPrefix) ERC1155(uri) public {

    }

    function getFeeRecipients(uint256 id) public override view returns (address payable[] memory) {
        Fee[] memory _fees = fees[id];
        address payable[] memory result = new address payable[](_fees.length);
        for (uint i = 0; i < _fees.length; i++) {
            result[i] = _fees[i].recipient;
        }
        return result;
    }

    function getFeeBps(uint256 id) public override view returns (uint[] memory) {
        Fee[] memory _fees = fees[id];
        uint[] memory result = new uint[](_fees.length);
        for (uint i = 0; i < _fees.length; i++) {
            result[i] = _fees[i].value;
        }
        return result;
    }

    // Creates a new token type and assings _initialSupply to minter
    function _mint(uint256 _id, Fee[] memory _fees, uint256 _supply, string memory _uri) internal {
        require(
            _fees.length <= maxFeesCount,
            "Amount of fee recipients can't exceed 100"
        );

        uint256 sumFeeBps = 0;
        for (uint256 i = 0; i < _fees.length; i++) {
            sumFeeBps = sumFeeBps.add(_fees[i].value);
        }

        require(
            sumFeeBps <= 10000,
            "Total fee bps should not exceed 10000"
        );

        require(creators[_id] == address(0x0), "Token is already minted");
        require(_supply != 0, "Supply should be positive");
        require(bytes(_uri).length > 0, "uri should be set");

        creators[_id] = msg.sender;
        address[] memory recipients = new address[](_fees.length);
        uint[] memory bps = new uint[](_fees.length);
        for (uint i = 0; i < _fees.length; i++) {
            require(_fees[i].recipient != address(0x0), "Recipient should be present");
            require(_fees[i].value != 0, "Fee value should be positive");
            fees[_id].push(_fees[i]);
            recipients[i] = _fees[i].recipient;
            bps[i] = _fees[i].value;
        }
        if (_fees.length > 0) {
            emit SecondarySaleFees(_id, recipients, bps);
        }
        _mint(msg.sender, _id, _supply, "");
        //balanceOf(msg.sender, _id) = _supply;
        _setTokenURI(_id, _uri);

        // Transfer event with mint semantic
        emit TransferSingle(msg.sender, address(0x0), msg.sender, _id, _supply);
        emit URI(_uri, _id);
    }

    function burn(address _owner, uint256 _id, uint256 _value) external {

        require(_owner == msg.sender || isApprovedForAll(_owner, msg.sender) == true, "Need operator approval for 3rd party burns.");

        _burn(_owner, _id, _value);
        // SafeMath will throw with insuficient funds _owner
        // or if _id is not valid (balance will be 0)
        // balanceOf(_owner, _id) = balanceOf( _owner, _id).sub(_value);

        // MUST emit event
        // emit TransferSingle(msg.sender, _owner, address(0x0), _id, _value);
    }

    /**
     * @dev Internal function to set the token URI for a given token.
     * Reverts if the token ID does not exist.
     * @param tokenId uint256 ID of the token to set its URI
     * @param uri string URI to assign
     */
    function _setTokenURI(uint256 tokenId, string memory uri) override virtual internal {
        require(creators[tokenId] != address(0x0), "_setTokenURI: Token should exist");
        super._setTokenURI(tokenId, uri);
    }

    function setTokenURIPrefix(string memory tokenURIPrefix) public onlyOwner {
        _setTokenURIPrefix(tokenURIPrefix);
    }

    function setContractURI(string memory contractURI) public onlyOwner {
        _setContractURI(contractURI);
    }

    function uri(uint256 _id) override(ERC1155Metadata_URI, ERC1155) external view returns (string memory) {
        return _tokenURI(_id);
    }
}

File 56 of 104 : ERC1155Metadata_URI.sol
pragma solidity ^0.6.12;
// SPDX-License-Identifier: UNLICENSED

import "../HasContractURI.sol";
import "@openzeppelin/contracts/token/ERC1155/IERC1155MetadataURI.sol";
import "../HasTokenURI.sol";

/**
    Note: The ERC-165 identifier for this interface is 0x0e89341c.
*/
abstract contract ERC1155Metadata_URI is IERC1155MetadataURI, HasTokenURI {

    constructor(string memory _tokenURIPrefix) HasTokenURI(_tokenURIPrefix) public {

    }

    function uri(uint256 _id) override virtual external view returns (string memory) {
        return _tokenURI(_id);
    }
}

File 57 of 104 : ERC1155.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "./IERC1155.sol";
import "./IERC1155MetadataURI.sol";
import "./IERC1155Receiver.sol";
import "../../utils/Context.sol";
import "../../introspection/ERC165.sol";
import "../../math/SafeMath.sol";
import "../../utils/Address.sol";

/**
 *
 * @dev Implementation of the basic standard multi-token.
 * See https://eips.ethereum.org/EIPS/eip-1155
 * Originally based on code by Enjin: https://github.com/enjin/erc-1155
 *
 * _Available since v3.1._
 */
contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
    using SafeMath for uint256;
    using Address for address;

    // Mapping from token ID to account balances
    mapping (uint256 => mapping(address => uint256)) private _balances;

    // Mapping from account to operator approvals
    mapping (address => mapping(address => bool)) private _operatorApprovals;

    // Used as the URI for all token types by relying on ID substitution, e.g. https://token-cdn-domain/{id}.json
    string private _uri;

    /*
     *     bytes4(keccak256('balanceOf(address,uint256)')) == 0x00fdd58e
     *     bytes4(keccak256('balanceOfBatch(address[],uint256[])')) == 0x4e1273f4
     *     bytes4(keccak256('setApprovalForAll(address,bool)')) == 0xa22cb465
     *     bytes4(keccak256('isApprovedForAll(address,address)')) == 0xe985e9c5
     *     bytes4(keccak256('safeTransferFrom(address,address,uint256,uint256,bytes)')) == 0xf242432a
     *     bytes4(keccak256('safeBatchTransferFrom(address,address,uint256[],uint256[],bytes)')) == 0x2eb2c2d6
     *
     *     => 0x00fdd58e ^ 0x4e1273f4 ^ 0xa22cb465 ^
     *        0xe985e9c5 ^ 0xf242432a ^ 0x2eb2c2d6 == 0xd9b67a26
     */
    bytes4 private constant _INTERFACE_ID_ERC1155 = 0xd9b67a26;

    /*
     *     bytes4(keccak256('uri(uint256)')) == 0x0e89341c
     */
    bytes4 private constant _INTERFACE_ID_ERC1155_METADATA_URI = 0x0e89341c;

    /**
     * @dev See {_setURI}.
     */
    constructor (string memory uri_) public {
        _setURI(uri_);

        // register the supported interfaces to conform to ERC1155 via ERC165
        _registerInterface(_INTERFACE_ID_ERC1155);

        // register the supported interfaces to conform to ERC1155MetadataURI via ERC165
        _registerInterface(_INTERFACE_ID_ERC1155_METADATA_URI);
    }

    /**
     * @dev See {IERC1155MetadataURI-uri}.
     *
     * This implementation returns the same URI for *all* token types. It relies
     * on the token type ID substitution mechanism
     * https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP].
     *
     * Clients calling this function must replace the `\{id\}` substring with the
     * actual token type ID.
     */
    function uri(uint256) external view virtual override returns (string memory) {
        return _uri;
    }

    /**
     * @dev See {IERC1155-balanceOf}.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function balanceOf(address account, uint256 id) public view virtual override returns (uint256) {
        require(account != address(0), "ERC1155: balance query for the zero address");
        return _balances[id][account];
    }

    /**
     * @dev See {IERC1155-balanceOfBatch}.
     *
     * Requirements:
     *
     * - `accounts` and `ids` must have the same length.
     */
    function balanceOfBatch(
        address[] memory accounts,
        uint256[] memory ids
    )
        public
        view
        virtual
        override
        returns (uint256[] memory)
    {
        require(accounts.length == ids.length, "ERC1155: accounts and ids length mismatch");

        uint256[] memory batchBalances = new uint256[](accounts.length);

        for (uint256 i = 0; i < accounts.length; ++i) {
            batchBalances[i] = balanceOf(accounts[i], ids[i]);
        }

        return batchBalances;
    }

    /**
     * @dev See {IERC1155-setApprovalForAll}.
     */
    function setApprovalForAll(address operator, bool approved) public virtual override {
        require(_msgSender() != operator, "ERC1155: setting approval status for self");

        _operatorApprovals[_msgSender()][operator] = approved;
        emit ApprovalForAll(_msgSender(), operator, approved);
    }

    /**
     * @dev See {IERC1155-isApprovedForAll}.
     */
    function isApprovedForAll(address account, address operator) public view virtual override returns (bool) {
        return _operatorApprovals[account][operator];
    }

    /**
     * @dev See {IERC1155-safeTransferFrom}.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 id,
        uint256 amount,
        bytes memory data
    )
        public
        virtual
        override
    {
        require(to != address(0), "ERC1155: transfer to the zero address");
        require(
            from == _msgSender() || isApprovedForAll(from, _msgSender()),
            "ERC1155: caller is not owner nor approved"
        );

        address operator = _msgSender();

        _beforeTokenTransfer(operator, from, to, _asSingletonArray(id), _asSingletonArray(amount), data);

        _balances[id][from] = _balances[id][from].sub(amount, "ERC1155: insufficient balance for transfer");
        _balances[id][to] = _balances[id][to].add(amount);

        emit TransferSingle(operator, from, to, id, amount);

        _doSafeTransferAcceptanceCheck(operator, from, to, id, amount, data);
    }

    /**
     * @dev See {IERC1155-safeBatchTransferFrom}.
     */
    function safeBatchTransferFrom(
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    )
        public
        virtual
        override
    {
        require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
        require(to != address(0), "ERC1155: transfer to the zero address");
        require(
            from == _msgSender() || isApprovedForAll(from, _msgSender()),
            "ERC1155: transfer caller is not owner nor approved"
        );

        address operator = _msgSender();

        _beforeTokenTransfer(operator, from, to, ids, amounts, data);

        for (uint256 i = 0; i < ids.length; ++i) {
            uint256 id = ids[i];
            uint256 amount = amounts[i];

            _balances[id][from] = _balances[id][from].sub(
                amount,
                "ERC1155: insufficient balance for transfer"
            );
            _balances[id][to] = _balances[id][to].add(amount);
        }

        emit TransferBatch(operator, from, to, ids, amounts);

        _doSafeBatchTransferAcceptanceCheck(operator, from, to, ids, amounts, data);
    }

    /**
     * @dev Sets a new URI for all token types, by relying on the token type ID
     * substitution mechanism
     * https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP].
     *
     * By this mechanism, any occurrence of the `\{id\}` substring in either the
     * URI or any of the amounts in the JSON file at said URI will be replaced by
     * clients with the token type ID.
     *
     * For example, the `https://token-cdn-domain/\{id\}.json` URI would be
     * interpreted by clients as
     * `https://token-cdn-domain/000000000000000000000000000000000000000000000000000000000004cce0.json`
     * for token type ID 0x4cce0.
     *
     * See {uri}.
     *
     * Because these URIs cannot be meaningfully represented by the {URI} event,
     * this function emits no events.
     */
    function _setURI(string memory newuri) internal virtual {
        _uri = newuri;
    }

    /**
     * @dev Creates `amount` tokens of token type `id`, and assigns them to `account`.
     *
     * Emits a {TransferSingle} event.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - If `account` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
     * acceptance magic value.
     */
    function _mint(address account, uint256 id, uint256 amount, bytes memory data) internal virtual {
        require(account != address(0), "ERC1155: mint to the zero address");

        address operator = _msgSender();

        _beforeTokenTransfer(operator, address(0), account, _asSingletonArray(id), _asSingletonArray(amount), data);

        _balances[id][account] = _balances[id][account].add(amount);
        emit TransferSingle(operator, address(0), account, id, amount);

        _doSafeTransferAcceptanceCheck(operator, address(0), account, id, amount, data);
    }

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_mint}.
     *
     * Requirements:
     *
     * - `ids` and `amounts` must have the same length.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
     * acceptance magic value.
     */
    function _mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data) internal virtual {
        require(to != address(0), "ERC1155: mint to the zero address");
        require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");

        address operator = _msgSender();

        _beforeTokenTransfer(operator, address(0), to, ids, amounts, data);

        for (uint i = 0; i < ids.length; i++) {
            _balances[ids[i]][to] = amounts[i].add(_balances[ids[i]][to]);
        }

        emit TransferBatch(operator, address(0), to, ids, amounts);

        _doSafeBatchTransferAcceptanceCheck(operator, address(0), to, ids, amounts, data);
    }

    /**
     * @dev Destroys `amount` tokens of token type `id` from `account`
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - `account` must have at least `amount` tokens of token type `id`.
     */
    function _burn(address account, uint256 id, uint256 amount) internal virtual {
        require(account != address(0), "ERC1155: burn from the zero address");

        address operator = _msgSender();

        _beforeTokenTransfer(operator, account, address(0), _asSingletonArray(id), _asSingletonArray(amount), "");

        _balances[id][account] = _balances[id][account].sub(
            amount,
            "ERC1155: burn amount exceeds balance"
        );

        emit TransferSingle(operator, account, address(0), id, amount);
    }

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_burn}.
     *
     * Requirements:
     *
     * - `ids` and `amounts` must have the same length.
     */
    function _burnBatch(address account, uint256[] memory ids, uint256[] memory amounts) internal virtual {
        require(account != address(0), "ERC1155: burn from the zero address");
        require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");

        address operator = _msgSender();

        _beforeTokenTransfer(operator, account, address(0), ids, amounts, "");

        for (uint i = 0; i < ids.length; i++) {
            _balances[ids[i]][account] = _balances[ids[i]][account].sub(
                amounts[i],
                "ERC1155: burn amount exceeds balance"
            );
        }

        emit TransferBatch(operator, account, address(0), ids, amounts);
    }

    /**
     * @dev Hook that is called before any token transfer. This includes minting
     * and burning, as well as batched variants.
     *
     * The same hook is called on both single and batched variants. For single
     * transfers, the length of the `id` and `amount` arrays will be 1.
     *
     * Calling conditions (for each `id` and `amount` pair):
     *
     * - When `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * of token type `id` will be  transferred to `to`.
     * - When `from` is zero, `amount` tokens of token type `id` will be minted
     * for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens of token type `id`
     * will be burned.
     * - `from` and `to` are never both zero.
     * - `ids` and `amounts` have the same, non-zero length.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(
        address operator,
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    )
        internal
        virtual
    { }

    function _doSafeTransferAcceptanceCheck(
        address operator,
        address from,
        address to,
        uint256 id,
        uint256 amount,
        bytes memory data
    )
        private
    {
        if (to.isContract()) {
            try IERC1155Receiver(to).onERC1155Received(operator, from, id, amount, data) returns (bytes4 response) {
                if (response != IERC1155Receiver(to).onERC1155Received.selector) {
                    revert("ERC1155: ERC1155Receiver rejected tokens");
                }
            } catch Error(string memory reason) {
                revert(reason);
            } catch {
                revert("ERC1155: transfer to non ERC1155Receiver implementer");
            }
        }
    }

    function _doSafeBatchTransferAcceptanceCheck(
        address operator,
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    )
        private
    {
        if (to.isContract()) {
            try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, amounts, data) returns (bytes4 response) {
                if (response != IERC1155Receiver(to).onERC1155BatchReceived.selector) {
                    revert("ERC1155: ERC1155Receiver rejected tokens");
                }
            } catch Error(string memory reason) {
                revert(reason);
            } catch {
                revert("ERC1155: transfer to non ERC1155Receiver implementer");
            }
        }
    }

    function _asSingletonArray(uint256 element) private pure returns (uint256[] memory) {
        uint256[] memory array = new uint256[](1);
        array[0] = element;

        return array;
    }
}

File 58 of 104 : IERC1155MetadataURI.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.2 <0.8.0;

import "./IERC1155.sol";

/**
 * @dev Interface of the optional ERC1155MetadataExtension interface, as defined
 * in the https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[EIP].
 *
 * _Available since v3.1._
 */
interface IERC1155MetadataURI is IERC1155 {
    /**
     * @dev Returns the URI for token type `id`.
     *
     * If the `\{id\}` substring is present in the URI, it must be replaced by
     * clients with the actual token type ID.
     */
    function uri(uint256 id) external view returns (string memory);
}

File 59 of 104 : HasTokenURI.sol
pragma solidity ^0.6.12;
// SPDX-License-Identifier: UNLICENSED

import "../libs/StringLibrary.sol";

contract HasTokenURI {
    using StringLibrary for string;

    //Token URI prefix
    string public tokenURIPrefix;

    // Optional mapping for token URIs
    mapping(uint256 => string) private _tokenURIs;

    constructor(string memory _tokenURIPrefix) public {
        tokenURIPrefix = _tokenURIPrefix;
    }

    /**
     * @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) internal view returns (string memory) {
        return tokenURIPrefix.append(_tokenURIs[tokenId]);
    }

    /**
     * @dev Internal function to set the token URI for a given token.
     * Reverts if the token ID does not exist.
     * @param tokenId uint256 ID of the token to set its URI
     * @param uri string URI to assign
     */
    function _setTokenURI(uint256 tokenId, string memory uri) virtual internal {
        _tokenURIs[tokenId] = uri;
    }

    /**
     * @dev Internal function to set the token URI prefix.
     * @param _tokenURIPrefix string URI prefix to assign
     */
    function _setTokenURIPrefix(string memory _tokenURIPrefix) internal {
        tokenURIPrefix = _tokenURIPrefix;
    }

    function _clearTokenURI(uint256 tokenId) internal {
        if (bytes(_tokenURIs[tokenId]).length != 0) {
            delete _tokenURIs[tokenId];
        }
    }
}

File 60 of 104 : StringLibrary.sol
pragma solidity ^0.6.12;
// SPDX-License-Identifier: UNLICENSED

import "./UintLibrary.sol";

library StringLibrary {
    using UintLibrary for uint256;

    function append(string memory _a, string memory _b) internal pure returns (string memory) {
        bytes memory _ba = bytes(_a);
        bytes memory _bb = bytes(_b);
        bytes memory bab = new bytes(_ba.length + _bb.length);
        uint k = 0;
        for (uint i = 0; i < _ba.length; i++) bab[k++] = _ba[i];
        for (uint i = 0; i < _bb.length; i++) bab[k++] = _bb[i];
        return string(bab);
    }

    function append(string memory _a, string memory _b, string memory _c) internal pure returns (string memory) {
        bytes memory _ba = bytes(_a);
        bytes memory _bb = bytes(_b);
        bytes memory _bc = bytes(_c);
        bytes memory bbb = new bytes(_ba.length + _bb.length + _bc.length);
        uint k = 0;
        for (uint i = 0; i < _ba.length; i++) bbb[k++] = _ba[i];
        for (uint i = 0; i < _bb.length; i++) bbb[k++] = _bb[i];
        for (uint i = 0; i < _bc.length; i++) bbb[k++] = _bc[i];
        return string(bbb);
    }

    function recover(string memory message, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
        bytes memory msgBytes = bytes(message);
        bytes memory fullMessage = concat(
            bytes("\x19Ethereum Signed Message:\n"),
            bytes(msgBytes.length.toString()),
            msgBytes,
            new bytes(0), new bytes(0), new bytes(0), new bytes(0)
        );
        return ecrecover(keccak256(fullMessage), v, r, s);
    }

    function concat(bytes memory _ba, bytes memory _bb, bytes memory _bc, bytes memory _bd, bytes memory _be, bytes memory _bf, bytes memory _bg) internal pure returns (bytes memory) {
        bytes memory resultBytes = new bytes(_ba.length + _bb.length + _bc.length + _bd.length + _be.length + _bf.length + _bg.length);
        uint k = 0;
        for (uint i = 0; i < _ba.length; i++) resultBytes[k++] = _ba[i];
        for (uint i = 0; i < _bb.length; i++) resultBytes[k++] = _bb[i];
        for (uint i = 0; i < _bc.length; i++) resultBytes[k++] = _bc[i];
        for (uint i = 0; i < _bd.length; i++) resultBytes[k++] = _bd[i];
        for (uint i = 0; i < _be.length; i++) resultBytes[k++] = _be[i];
        for (uint i = 0; i < _bf.length; i++) resultBytes[k++] = _bf[i];
        for (uint i = 0; i < _bg.length; i++) resultBytes[k++] = _bg[i];
        return resultBytes;
    }
}

File 61 of 104 : UintLibrary.sol
pragma solidity ^0.6.12;
// SPDX-License-Identifier: UNLICENSED

library UintLibrary {
    function toString(uint256 _i) internal pure returns (string memory) {
        if (_i == 0) {
            return "0";
        }
        uint j = _i;
        uint len;
        while (j != 0) {
            len++;
            j /= 10;
        }
        bytes memory bstr = new bytes(len);
        uint k = len - 1;
        while (_i != 0) {
            bstr[k--] = byte(uint8(48 + _i % 10));
            _i /= 10;
        }
        return string(bstr);
    }
}

File 62 of 104 : IERC1155Receiver.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../../introspection/IERC165.sol";

/**
 * _Available since v3.1._
 */
interface IERC1155Receiver is IERC165 {

    /**
        @dev Handles the receipt of a single ERC1155 token type. This function is
        called at the end of a `safeTransferFrom` after the balance has been updated.
        To accept the transfer, this must return
        `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
        (i.e. 0xf23a6e61, or its own function selector).
        @param operator The address which initiated the transfer (i.e. msg.sender)
        @param from The address which previously owned the token
        @param id The ID of the token being transferred
        @param value The amount of tokens being transferred
        @param data Additional data with no specified format
        @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
    */
    function onERC1155Received(
        address operator,
        address from,
        uint256 id,
        uint256 value,
        bytes calldata data
    )
        external
        returns(bytes4);

    /**
        @dev Handles the receipt of a multiple ERC1155 token types. This function
        is called at the end of a `safeBatchTransferFrom` after the balances have
        been updated. To accept the transfer(s), this must return
        `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
        (i.e. 0xbc197c81, or its own function selector).
        @param operator The address which initiated the batch transfer (i.e. msg.sender)
        @param from The address which previously owned the token
        @param ids An array containing ids of each token being transferred (order and length must match values array)
        @param values An array containing amounts of each token being transferred (order and length must match ids array)
        @param data Additional data with no specified format
        @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
    */
    function onERC1155BatchReceived(
        address operator,
        address from,
        uint256[] calldata ids,
        uint256[] calldata values,
        bytes calldata data
    )
        external
        returns(bytes4);
}

File 63 of 104 : RefinableERC1155WhiteListedToken.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/cryptography/ECDSA.sol";
import "./ERC1155Base.sol";
import "../../roles/MinterRole.sol";

contract RefinableERC1155WhiteListedToken is ERC1155Base, MinterRole {

    using ECDSA for bytes32;

    string public name;
    string public symbol;

    /**
     * @dev Constructor Function
     * @param _name name of the token ex: Rarible
     * @param _symbol symbol of the token ex: RARI
     * @param _signer address of signer account
     * @param _contractURI URI of contract ex: https://api-mainnet.rarible.com/contractMetadata/{address}
     * @param _tokenURIPrefix token URI Prefix
     * @param _uri ex: https://ipfs.daonomic.com
    */
    constructor(string memory _name, string memory _symbol, address _signer, string memory _contractURI, string memory _tokenURIPrefix, string memory _uri) ERC1155Base(_contractURI, _tokenURIPrefix, _uri) public {
        name = _name;
        symbol = _symbol;

        addSigner(_msgSender());
        addSigner(_signer);
        _registerInterface(bytes4(keccak256('MINT_WITH_ADDRESS')));
    }

    function mint(uint256 _tokenId, bytes memory _signature, Fee[] memory _fees, uint256 _supply, string memory _uri) public onlyMinter {
        require(
            hasRole(SIGNER_ROLE,
            keccak256(abi.encodePacked(address(this), _tokenId, _msgSender()))
            .toEthSignedMessageHash()
            .recover(_signature)
            )
        ,"invalid signature"
        );
        _mint(_tokenId, _fees, _supply, _uri);
    }
}

File 64 of 104 : ERC721BaseV3.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/token/ERC721/ERC721Burnable.sol";
import "../HasContractURI.sol";
import "../HasSecondarySale.sol";
import "../../roles/MinterRole.sol";
import "../../libs/RoyaltyLibrary.sol";
import "../Royalty.sol";

/**
 * @title Full ERC721 Token with support for baseURI
 * This implementation includes all the required and some optional functionality of the ERC721 standard
 * Moreover, it includes approve all functionality using operator terminology
 * @dev see https://eips.ethereum.org/EIPS/eip-721
 */
abstract contract ERC721BaseV3 is
HasSecondarySale,
HasContractURI,
ERC721Burnable,
MinterRole,
Royalty
{
    /// @dev sale is primary or secondary
    mapping(uint256 => bool) public isSecondarySale;

    /*
     * bytes4(keccak256('MINT_WITH_ADDRESS')) == 0xe37243f2
     */
    bytes4 private constant _INTERFACE_ID_MINT_WITH_ADDRESS = 0xe37243f2;


    /**
     * @dev Constructor function
     */
    constructor(
        string memory _name,
        string memory _symbol,
        string memory contractURI,
        string memory _baseURI
    ) public HasContractURI(contractURI) ERC721(_name, _symbol) {
        // register the supported interfaces to conform to ERC721 via ERC165
        _registerInterface(_INTERFACE_ID_MINT_WITH_ADDRESS);
        _setBaseURI(_baseURI);
    }

    function checkSecondarySale(uint256 _tokenId) public view override returns (bool) {
        return isSecondarySale[_tokenId];
    }

    function setSecondarySale(uint256 _tokenId) public override {
        isSecondarySale[_tokenId] = true;
    }

    function _mint(
        address _to,
        uint256 _tokenId,
        RoyaltyLibrary.RoyaltyShareDetails[] memory _royaltyShares,
        string memory _uri,
        uint256 _royaltyBps,
        RoyaltyLibrary.Strategy _royaltyStrategy,
        RoyaltyLibrary.RoyaltyShareDetails[] memory _primaryRoyaltyShares
    ) internal {
        require(_exists(_tokenId) == false, "ERC721: Token is already minted");
        require(bytes(_uri).length > 0, "ERC721: Uri should be set");

        _mint(_to, _tokenId);
        _setTokenURI(_tokenId, _uri);
        creators[_tokenId] = _to;
        uint256 sumRoyaltyShareBps;
        for (uint256 i = 0; i < _royaltyShares.length; i++) {
            sumRoyaltyShareBps = sumRoyaltyShareBps.add(_royaltyShares[i].value);
        }

        if (_royaltyStrategy == RoyaltyLibrary.Strategy.ROYALTY_STRATEGY) {
            require(
                sumRoyaltyShareBps <= 10 ** 4,
                "ERC721: Total fee bps should not exceed 10000"
            );
            _setRoyalty(_tokenId, sumRoyaltyShareBps, RoyaltyLibrary.Strategy.ROYALTY_STRATEGY);
        } else if (_royaltyStrategy == RoyaltyLibrary.Strategy.PROFIT_DISTRIBUTION_STRATEGY) {
            require(
                sumRoyaltyShareBps == 10 ** 4,
                "ERC721: Total fee bps should be 10000"
            );
            _setRoyalty(_tokenId, _royaltyBps, RoyaltyLibrary.Strategy.PROFIT_DISTRIBUTION_STRATEGY);
        } else if (_royaltyStrategy == RoyaltyLibrary.Strategy.PRIMARY_SALE_STRATEGY) {
            uint256 sumPrimaryRoyaltyShareBps;
            for (uint256 i = 0; i < _primaryRoyaltyShares.length; i++) {
                sumPrimaryRoyaltyShareBps = sumPrimaryRoyaltyShareBps + _primaryRoyaltyShares[i].value;
            }
            require(
                sumRoyaltyShareBps <= 10 ** 4,
                "Royalty: Total royalty share bps should not exceed 10000"
            );
            require(
                sumPrimaryRoyaltyShareBps <= 10 ** 4,
                "Royalty: Total primary royalty share bps should not exceed 10000"
            );
            _setRoyalty(_tokenId, sumRoyaltyShareBps, RoyaltyLibrary.Strategy.PRIMARY_SALE_STRATEGY);
            _addPrimaryRoyaltyShares(_tokenId, _primaryRoyaltyShares);
        } else {
            revert("ERC721: Royalty option does not exist");
        }
        _addRoyaltyShares(_tokenId, _royaltyShares);
    }

    function setBaseURI(string memory _baseURI) public onlyAdmin {
        _setBaseURI(_baseURI);
    }

    function setContractURI(string memory _contractURI) public onlyAdmin {
        _setContractURI(_contractURI);
    }
}

File 65 of 104 : WhiteListedTokenERC1155V3.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/cryptography/ECDSA.sol";
import "../ERC1155BaseV3.sol";
import "../../../libs/RoyaltyLibrary.sol";

contract WhiteListedTokenERC1155V3 is ERC1155BaseV3 {
    using ECDSA for bytes32;

    address payable public defaultRoyaltyReceiver = address(0);
    uint256 public defaultRoyaltyReceiverBps = 0;

    /**
     * @dev Constructor Function
     * @param _name name of the token ex: Rarible
     * @param _symbol symbol of the token ex: RARI
     * @param _signer address of signer account
     * @param _contractURI URI of contract ex: https://api-mainnet.rarible.com/contractMetadata/{address}
     * @param _tokenURIPrefix token URI Prefix
     * @param _uri ex: https://ipfs.daonomic.com
    */
    constructor(
        string memory _name,
        string memory _symbol,
        address _root,
        address _signer,
        string memory _contractURI,
        string memory _tokenURIPrefix,
        string memory _uri
    ) ERC1155BaseV3(_name, _symbol, _contractURI, _tokenURIPrefix, _uri) public {
        addAdmin(_root);
        addSigner(_signer);
    }

    //add the default royalties if the contract has set
    function mint(
        uint256 _tokenId,
        bytes memory _signature,
        RoyaltyLibrary.RoyaltyShareDetails[] memory _royaltyShares,
        uint256 _supply,
        string memory _uri,
        uint256 _royaltyBps,
        RoyaltyLibrary.Strategy _royaltyStrategy,
        RoyaltyLibrary.RoyaltyShareDetails[] memory _primaryRoyaltyShares
    ) public onlyMinter {
        require(
            hasRole(SIGNER_ROLE,
            keccak256(abi.encodePacked(address(this), _tokenId, _msgSender()))
            .toEthSignedMessageHash()
            .recover(_signature)
            )
        , "invalid signature"
        );

        RoyaltyLibrary.RoyaltyShareDetails[] memory defaultPrimaryRoyaltyShares = new RoyaltyLibrary.RoyaltyShareDetails[](1);
        if (defaultRoyaltyReceiver != address(0) && defaultRoyaltyReceiverBps != 0)
            defaultPrimaryRoyaltyShares[0] = RoyaltyLibrary.RoyaltyShareDetails({
            recipient : defaultRoyaltyReceiver,
            value : defaultRoyaltyReceiverBps
            });

        _mint(_tokenId, _royaltyShares, _supply, _uri, _royaltyBps, RoyaltyLibrary.Strategy.PRIMARY_SALE_STRATEGY, defaultPrimaryRoyaltyShares);
    }

    function setDefaultRoyaltyReceiver(address payable _receiver) public onlyAdmin {
        defaultRoyaltyReceiver = _receiver;
    }

    function setDefaultRoyaltyReceiverBps(uint256 _bps) public onlyAdmin {
        require(_bps <= 10 ** 4, "ERC1155: Fee bps should not exceed 10000");
        defaultRoyaltyReceiverBps = _bps;
    }
}

File 66 of 104 : ERC1155BaseV3.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "../HasContractURI.sol";
import "../HasTokenURI.sol";
import "./ERC1155Supply.sol";
import "../../roles/MinterRole.sol";
import "../../libs/RoyaltyLibrary.sol";
import "../Royalty.sol";
import "../../interfaces/ICreator.sol";
import "../../interfaces/IPrimaryRoyalty.sol";

abstract contract ERC1155BaseV3 is
HasTokenURI,
HasContractURI,
ERC1155Supply,
MinterRole,
Royalty
{
    string public name;
    string public symbol;

    /*
     * bytes4(keccak256('MINT_WITH_ADDRESS')) == 0xe37243f2
     */
    bytes4 private constant _INTERFACE_ID_MINT_WITH_ADDRESS = 0xe37243f2;

    constructor(
        string memory _name,
        string memory _symbol,
        string memory _contractURI,
        string memory _tokenURIPrefix,
        string memory _uri
    ) HasContractURI(_contractURI) HasTokenURI(_tokenURIPrefix) ERC1155(_uri) public {
        name = _name;
        symbol = _symbol;
        _registerInterface(_INTERFACE_ID_MINT_WITH_ADDRESS);
    }

    // Creates a new token type and assings _initialSupply to minter
    function _mint(
        uint256 _tokenId,
        RoyaltyLibrary.RoyaltyShareDetails[] memory _royaltyShares,
        uint256 _supply,
        string memory _uri,
        uint256 _royaltyBps,
        RoyaltyLibrary.Strategy _royaltyStrategy,
        RoyaltyLibrary.RoyaltyShareDetails[] memory _primaryRoyaltyShares
    ) internal {
        require(exists(_tokenId) == false, "ERC1155: Token is already minted");
        require(_supply != 0, "ERC1155: Supply should be positive");
        require(bytes(_uri).length > 0, "ERC1155: Uri should be set");

        _mint(_msgSender(), _tokenId, _supply, "");
        _setTokenURI(_tokenId, _uri);
        creators[_tokenId] = _msgSender();
        uint256 sumRoyaltyShareBps;
        for (uint256 i = 0; i < _royaltyShares.length; i++) {
            sumRoyaltyShareBps = sumRoyaltyShareBps.add(_royaltyShares[i].value);
        }

        if (_royaltyStrategy == RoyaltyLibrary.Strategy.ROYALTY_STRATEGY) {
            require(
                sumRoyaltyShareBps <= 10 ** 4,
                "ERC1155: Total fee bps should not exceed 10000"
            );
            _setRoyalty(_tokenId, sumRoyaltyShareBps, RoyaltyLibrary.Strategy.ROYALTY_STRATEGY);
        } else if (_royaltyStrategy == RoyaltyLibrary.Strategy.PROFIT_DISTRIBUTION_STRATEGY) {
            require(
                sumRoyaltyShareBps == 10 ** 4,
                "ERC1155: Total fee bps should be 10000"
            );
            _setRoyalty(_tokenId, _royaltyBps, RoyaltyLibrary.Strategy.PROFIT_DISTRIBUTION_STRATEGY);
        } else if (_royaltyStrategy == RoyaltyLibrary.Strategy.PRIMARY_SALE_STRATEGY) {
            uint256 sumPrimaryRoyaltyShareBps;
            for (uint256 i = 0; i < _primaryRoyaltyShares.length; i++) {
                sumPrimaryRoyaltyShareBps = sumPrimaryRoyaltyShareBps + _primaryRoyaltyShares[i].value;
            }
            require(
                sumRoyaltyShareBps <= 10 ** 4,
                "Royalty: Total royalty share bps should not exceed 10000"
            );
            require(
                sumPrimaryRoyaltyShareBps <= 10 ** 4,
                "Royalty: Total primary royalty share bps should not exceed 10000"
            );
            _setRoyalty(_tokenId, sumRoyaltyShareBps, RoyaltyLibrary.Strategy.PRIMARY_SALE_STRATEGY);
            _addPrimaryRoyaltyShares(_tokenId, _primaryRoyaltyShares);
        } else {
            revert("ERC1155: Royalty option does not exist");
        }

        _addRoyaltyShares(_tokenId, _royaltyShares);

        // Transfer event with mint semantic
        emit URI(_uri, _tokenId);
    }


    function burn(address _owner, uint256 _tokenId, uint256 _value) external {
        _burn(_owner, _tokenId, _value);
    }

    /**
     * @dev Internal function to set the token URI for a given token.
     * Reverts if the token ID does not exist.
     * @param _tokenId uint256 ID of the token to set its URI
     * @param _uri string URI to assign
     */
    function _setTokenURI(uint256 _tokenId, string memory _uri) override virtual internal {
        require(exists(_tokenId), "ERC1155: Token should exist");
        super._setTokenURI(_tokenId, _uri);
    }

    function setTokenURIPrefix(string memory _tokenURIPrefix) public onlyAdmin {
        _setTokenURIPrefix(_tokenURIPrefix);
    }

    function setContractURI(string memory _contractURI) public onlyAdmin {
        _setContractURI(_contractURI);
    }

    function uri(uint256 _tokenId) override external view returns (string memory) {
        return _tokenURI(_tokenId);
    }
}

File 67 of 104 : ERC1155Supply.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.12;

import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";

/**
 * @dev Extension of ERC1155 that adds tracking of total supply per id.
 *
 * Useful for scenarios where Fungible and Non-fungible tokens have to be
 * clearly identified. Note: While a totalSupply of 1 might mean the
 * corresponding is an NFT, there is no guarantees that no other token with the
 * same id are not going to be minted.
 */
abstract contract ERC1155Supply is ERC1155 {
    mapping(uint256 => uint256) private _totalSupply;

    /**
     * @dev Total amount of tokens in with a given id.
     */
    function totalSupply(uint256 id) public view virtual returns (uint256) {
        return _totalSupply[id];
    }

    /**
     * @dev Indicates weither any token exist with a given id, or not.
     */
    function exists(uint256 id) public view virtual returns (bool) {
        return ERC1155Supply.totalSupply(id) > 0;
    }

    /**
     * @dev See {ERC1155-_mint}.
     */
    function _mint(
        address account,
        uint256 id,
        uint256 amount,
        bytes memory data
    ) internal virtual override {
        super._mint(account, id, amount, data);
        _totalSupply[id] += amount;
    }

    /**
     * @dev See {ERC1155-_mintBatch}.
     */
    function _mintBatch(
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) internal virtual override {
        super._mintBatch(to, ids, amounts, data);
        for (uint256 i = 0; i < ids.length; ++i) {
            _totalSupply[ids[i]] += amounts[i];
        }
    }

    /**
     * @dev See {ERC1155-_burn}.
     */
    function _burn(
        address account,
        uint256 id,
        uint256 amount
    ) internal virtual override {
        require(
            account == _msgSender() || isApprovedForAll(account, _msgSender()),
            "ERC1155Supply: caller is not owner nor approved"
        );
        super._burn(account, id, amount);
        _totalSupply[id] -= amount;
    }

    /**
     * @dev See {ERC1155-_burnBatch}.
     */
    function _burnBatch(
        address account,
        uint256[] memory ids,
        uint256[] memory amounts
    ) internal virtual override {
        require(
            account == _msgSender() || isApprovedForAll(account, _msgSender()),
            "ERC1155Supply: caller is not owner nor approved"
        );
        super._burnBatch(account, ids, amounts);
        for (uint256 i = 0; i < ids.length; ++i) {
            _totalSupply[ids[i]] -= amounts[i];
        }
    }
}

File 68 of 104 : IMXHKERC1155WhiteListedTokenV3.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/cryptography/ECDSA.sol";
import "../ERC1155BaseV3.sol";
import "../../../libs/RoyaltyLibrary.sol";

contract IMXHKERC1155WhiteListedTokenV3 is ERC1155BaseV3 {
    using ECDSA for bytes32;

    address payable public defaultRoyaltyReceiver = address(0);
    uint256 public defaultRoyaltyReceiverBps = 0;

    /**
     * @dev Constructor Function
     * @param _name name of the token ex: Rarible
     * @param _symbol symbol of the token ex: RARI
     * @param _signer address of signer account
     * @param _contractURI URI of contract ex: https://api-mainnet.rarible.com/contractMetadata/{address}
     * @param _tokenURIPrefix token URI Prefix
     * @param _uri ex: https://ipfs.daonomic.com
    */
    constructor(
        string memory _name,
        string memory _symbol,
        address _root,
        address _signer,
        string memory _contractURI,
        string memory _tokenURIPrefix,
        string memory _uri
    ) ERC1155BaseV3(_name, _symbol, _contractURI, _tokenURIPrefix, _uri) public {
        addAdmin(_root);
        addSigner(_signer);
    }

    //add the default royalties if the contract has set
    function mint(
        uint256 _tokenId,
        bytes memory _signature,
        RoyaltyLibrary.RoyaltyShareDetails[] memory _royaltyShares,
        uint256 _supply,
        string memory _uri,
        uint256 _royaltyBps,
        RoyaltyLibrary.Strategy _royaltyStrategy,
        RoyaltyLibrary.RoyaltyShareDetails[] memory _primaryRoyaltyShares
    ) public onlyMinter {
        require(
            hasRole(SIGNER_ROLE,
            keccak256(abi.encodePacked(address(this), _tokenId, _msgSender()))
            .toEthSignedMessageHash()
            .recover(_signature)
            )
        , "invalid signature"
        );

        RoyaltyLibrary.RoyaltyShareDetails[] memory defaultPrimaryRoyaltyShares = new RoyaltyLibrary.RoyaltyShareDetails[](1);
        if (defaultRoyaltyReceiver != address(0) && defaultRoyaltyReceiverBps != 0)
            defaultPrimaryRoyaltyShares[0] = RoyaltyLibrary.RoyaltyShareDetails({
            recipient : defaultRoyaltyReceiver,
            value : defaultRoyaltyReceiverBps
            });

        _mint(_tokenId, _royaltyShares, _supply, _uri, _royaltyBps, RoyaltyLibrary.Strategy.PRIMARY_SALE_STRATEGY, defaultPrimaryRoyaltyShares);
    }

    function setDefaultRoyaltyReceiver(address payable _receiver) public onlyAdmin {
        defaultRoyaltyReceiver = _receiver;
    }

    function setDefaultRoyaltyReceiverBps(uint256 _bps) public onlyAdmin {
        require(_bps <= 10 ** 4, "ERC1155: Fee bps should not exceed 10000");
        defaultRoyaltyReceiverBps = _bps;
    }
}

File 69 of 104 : RefinableERC1155WhiteListedTokenV3.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/cryptography/ECDSA.sol";
import "../ERC1155BaseV3.sol";

contract RefinableERC1155WhiteListedTokenV3 is ERC1155BaseV3 {
    using ECDSA for bytes32;

    address payable public defaultRoyaltyReceiver = address(0);
    uint256 public defaultRoyaltyReceiverBps = 0;

    /**
     * @dev Constructor Function
     * @param _name name of the token ex: Rarible
     * @param _symbol symbol of the token ex: RARI
     * @param _signer address of signer account
     * @param _contractURI URI of contract ex: https://api-mainnet.rarible.com/contractMetadata/{address}
     * @param _tokenURIPrefix token URI Prefix
     * @param _uri ex: https://ipfs.daonomic.com
    */
    constructor(
        string memory _name,
        string memory _symbol,
        address _root,
        address _signer,
        string memory _contractURI,
        string memory _tokenURIPrefix,
        string memory _uri
    ) ERC1155BaseV3(_name, _symbol, _contractURI, _tokenURIPrefix, _uri) public {
        addAdmin(_root);
        addSigner(_signer);
    }

    function mint(
        uint256 _tokenId,
        bytes memory _signature,
        RoyaltyLibrary.RoyaltyShareDetails[] memory _royaltyShares,
        uint256 _supply,
        string memory _uri,
        uint256 _royaltyBps,
        RoyaltyLibrary.Strategy _royaltyStrategy,
        RoyaltyLibrary.RoyaltyShareDetails[] memory _primaryRoyaltyShares
    ) public onlyMinter {
        require(
            hasRole(SIGNER_ROLE,
            keccak256(abi.encodePacked(address(this), _tokenId, _msgSender()))
            .toEthSignedMessageHash()
            .recover(_signature)
            )
        , "invalid signature"
        );

        RoyaltyLibrary.RoyaltyShareDetails[] memory customPrimaryRoyaltyShares = new RoyaltyLibrary.RoyaltyShareDetails[](1);
        if (defaultRoyaltyReceiver != address(0) && defaultRoyaltyReceiverBps != 0) {
            customPrimaryRoyaltyShares[0] = RoyaltyLibrary.RoyaltyShareDetails({
            recipient : defaultRoyaltyReceiver,
            value : defaultRoyaltyReceiverBps
            });
        } else {
            customPrimaryRoyaltyShares = _primaryRoyaltyShares;
        } 

        _mint(_tokenId, _royaltyShares, _supply, _uri, _royaltyBps, _royaltyStrategy, customPrimaryRoyaltyShares);
    }

    function setDefaultRoyaltyReceiver(address payable _receiver) public onlyAdmin {
        defaultRoyaltyReceiver = _receiver;
    }

    function setDefaultRoyaltyReceiverBps(uint256 _bps) public onlyAdmin {
        require(_bps <= 10 ** 4, "ERC1155: Fee bps should not exceed 10000");
        defaultRoyaltyReceiverBps = _bps;
    }
}

File 70 of 104 : DAFERC1155WhiteListedTokenV3.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/cryptography/ECDSA.sol";
import "../ERC1155BaseV3.sol";
import "../../../libs/RoyaltyLibrary.sol";

contract DAFERC1155WhiteListedTokenV3 is ERC1155BaseV3 {
    using ECDSA for bytes32;

    address payable public defaultRoyaltyReceiver = address(0);
    uint256 public defaultRoyaltyReceiverBps = 0;

    /**
     * @dev Constructor Function
     * @param _name name of the token ex: Rarible
     * @param _symbol symbol of the token ex: RARI
     * @param _signer address of signer account
     * @param _contractURI URI of contract ex: https://api-mainnet.rarible.com/contractMetadata/{address}
     * @param _tokenURIPrefix token URI Prefix
     * @param _uri ex: https://ipfs.daonomic.com
    */
    constructor(
        string memory _name,
        string memory _symbol,
        address _root,
        address _signer,
        string memory _contractURI,
        string memory _tokenURIPrefix,
        string memory _uri
    ) ERC1155BaseV3(_name, _symbol, _contractURI, _tokenURIPrefix, _uri) public {
        addAdmin(_root);
        addSigner(_signer);
    }

    //add the default royalties if the contract has set
    function mint(
        uint256 _tokenId,
        bytes memory _signature,
        RoyaltyLibrary.RoyaltyShareDetails[] memory _royaltyShares,
        uint256 _supply,
        string memory _uri,
        uint256 _royaltyBps,
        RoyaltyLibrary.Strategy _royaltyStrategy,
        RoyaltyLibrary.RoyaltyShareDetails[] memory _primaryRoyaltyShares
    ) public onlyMinter {
        require(
            hasRole(SIGNER_ROLE,
            keccak256(abi.encodePacked(address(this), _tokenId, _msgSender()))
            .toEthSignedMessageHash()
            .recover(_signature)
            )
        , "invalid signature"
        );

        RoyaltyLibrary.RoyaltyShareDetails[] memory defaultPrimaryRoyaltyShares = new RoyaltyLibrary.RoyaltyShareDetails[](1);
        if (defaultRoyaltyReceiver != address(0) && defaultRoyaltyReceiverBps != 0)
            defaultPrimaryRoyaltyShares[0] = RoyaltyLibrary.RoyaltyShareDetails({
            recipient : defaultRoyaltyReceiver,
            value : defaultRoyaltyReceiverBps
            });

        _mint(_tokenId, _royaltyShares, _supply, _uri, _royaltyBps, RoyaltyLibrary.Strategy.PRIMARY_SALE_STRATEGY, defaultPrimaryRoyaltyShares);
    }

    function setDefaultRoyaltyReceiver(address payable _receiver) public onlyAdmin {
        defaultRoyaltyReceiver = _receiver;
    }

    function setDefaultRoyaltyReceiverBps(uint256 _bps) public onlyAdmin {
        require(_bps <= 10 ** 4, "ERC1155: Fee bps should not exceed 10000");
        defaultRoyaltyReceiverBps = _bps;
    }
}

File 71 of 104 : CoralERC1155WhiteListedTokenV3.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/cryptography/ECDSA.sol";
import "../ERC1155BaseV3.sol";
import "../../../libs/RoyaltyLibrary.sol";

contract CoralERC1155WhiteListedTokenV3 is ERC1155BaseV3 {
    using ECDSA for bytes32;

    RoyaltyLibrary.RoyaltyShareDetails[] public defaultPrimaryRoyaltyReceivers;

    /**
     * @dev Constructor Function
     * @param _name name of the token ex: Rarible
     * @param _symbol symbol of the token ex: RARI
     * @param _signer address of signer account
     * @param _contractURI URI of contract ex: https://api-mainnet.rarible.com/contractMetadata/{address}
     * @param _tokenURIPrefix token URI Prefix
     * @param _uri ex: https://ipfs.daonomic.com
    */
    constructor(
        string memory _name,
        string memory _symbol,
        address _root,
        address _signer,
        string memory _contractURI,
        string memory _tokenURIPrefix,
        string memory _uri
    ) ERC1155BaseV3(_name, _symbol, _contractURI, _tokenURIPrefix, _uri) public {
        addAdmin(_root);
        addSigner(_signer);
    }

    //add the default royalties if the contract has set
    function mint(
        uint256 _tokenId,
        bytes memory _signature,
        RoyaltyLibrary.RoyaltyShareDetails[] memory _royaltyShares,
        uint256 _supply,
        string memory _uri,
        uint256 _royaltyBps,
        RoyaltyLibrary.Strategy _royaltyStrategy,
        RoyaltyLibrary.RoyaltyShareDetails[] memory _primaryRoyaltyShares
    ) public onlyMinter {
        require(
            hasRole(SIGNER_ROLE,
            keccak256(abi.encodePacked(address(this), _tokenId, _msgSender()))
            .toEthSignedMessageHash()
            .recover(_signature)
            )
        , "invalid signature"
        );

        _mint(_tokenId, _royaltyShares, _supply, _uri, _royaltyBps, RoyaltyLibrary.Strategy.PRIMARY_SALE_STRATEGY, defaultPrimaryRoyaltyReceivers);
    }

    function setPrimaryDefaultRoyaltyReceivers(RoyaltyLibrary.RoyaltyShareDetails[] memory _receivers) public onlyAdmin {
        delete defaultPrimaryRoyaltyReceivers;
        for (uint256 i = 0; i < _receivers.length; i++) {
            defaultPrimaryRoyaltyReceivers.push(_receivers[i]);
        }
    }
}

File 72 of 104 : RoyaltyERC721Mock.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/GSN/Context.sol";
import "@openzeppelin/contracts/introspection/ERC165.sol";
import "../../interfaces/IRoyalty.sol";
import "../../interfaces/IHasSecondarySale.sol";
import "../../libs/RoyaltyLibrary.sol";
import "./RanERC721Mock.sol";
import "../../interfaces/ICreator.sol";
import "../../interfaces/IPrimaryRoyalty.sol";


contract RoyaltyERC721Mock is Context, IRoyalty, IHasSecondarySale, ERC165, ICreator, IPrimaryRoyalty {
    event SetRoyaltyShares (
        uint256 indexed tokenId,
        address[] recipients,
        uint[] bp
    );

    event SetRoyalty (
        address owner,
        uint256 indexed tokenId,
        uint256 value,
        RoyaltyLibrary.Strategy strategy
    );

    event SetPrimaryRoyaltyShares (
        uint256 indexed tokenId,
        address[] recipients,
        uint[] bp
    );

    // tokenId => royalty
    mapping(uint256 => RoyaltyLibrary.RoyaltyInfo) royalty;

    // tokenId => royaltyShares
    mapping(uint256 => RoyaltyLibrary.RoyaltyShareDetails[]) royaltyShares;

    // tokenId => bool: true is first sale, false is secondary sale
    mapping(uint256 => bool) isSecondarySale;

    // ERC721/1155 Address
    address tokenContract;

    // Max count of royalty shares
    uint256 maxRoyaltyShareCount;

    // tokenId => creator address
    mapping(uint256 => address) creators;

    // tokenId => primary royalty
    mapping(uint256 => RoyaltyLibrary.RoyaltyShareDetails[]) primaryRoyaltyShares;

    constructor (address _tokenContract, uint256 _maxRoyaltyShareCount) public {
        tokenContract = _tokenContract;
        maxRoyaltyShareCount = _maxRoyaltyShareCount;

        _registerInterface(type(IRoyalty).interfaceId);
        _registerInterface(type(IHasSecondarySale).interfaceId);
        _registerInterface(type(IPrimaryRoyalty).interfaceId);
        _registerInterface(type(ICreator).interfaceId);
    }

    function getTokenContract() external view override returns (address) {
        return tokenContract;
    }

    //    // Optional
    //    function setTokenContract(address token);

    function getRoyalty(uint256 _tokenId) external view override returns (RoyaltyLibrary.RoyaltyInfo memory) {
        return royalty[_tokenId];
    }

    function getRoyaltyShares(uint256 _tokenId) external view override returns (RoyaltyLibrary.RoyaltyShareDetails[] memory) {
        return royaltyShares[_tokenId];
    }

    function checkSecondarySale(uint256 _tokenId) public view override returns (bool) {
        return isSecondarySale[_tokenId];
    }

    function setSecondarySale(uint256 _tokenId) public override {
        isSecondarySale[_tokenId] = true;
    }

    function getPrimaryRoyaltyShares(uint256 _tokenId) external view override returns (RoyaltyLibrary.RoyaltyShareDetails[] memory) {
        return primaryRoyaltyShares[_tokenId];
    }

    function getCreator(uint256 _tokenId) external view override returns (address) {
        return creators[_tokenId];
    }

    function mint(
        uint256 _tokenId,
        bytes memory _signature,
        string memory _uri,
        RoyaltyLibrary.RoyaltyShareDetails[] memory _royaltyShares,
        uint256 _royaltyBps,
        RoyaltyLibrary.Strategy _royaltyStrategy,
        RoyaltyLibrary.RoyaltyShareDetails[] memory _primaryRoyaltyShares
    ) public {
        RanERC721Mock(tokenContract).mint(_msgSender(), _tokenId);
        _addRoyalties(_tokenId, _royaltyShares, _royaltyBps, _royaltyStrategy, _primaryRoyaltyShares);
        creators[_tokenId] = _msgSender();
    }

    // Optional to make it public or not
    function _addRoyalties(
        uint256 _tokenId,
        RoyaltyLibrary.RoyaltyShareDetails[] memory _royaltyShares,
        uint256 _royaltyBps,
        RoyaltyLibrary.Strategy _royaltyStrategy,
        RoyaltyLibrary.RoyaltyShareDetails[] memory _primaryRoyaltyShares
    ) internal {
        uint256 sumRoyaltyShareBps;
        for (uint256 i = 0; i < _royaltyShares.length; i++) {
            sumRoyaltyShareBps = sumRoyaltyShareBps + _royaltyShares[i].value;
        }

        if (_royaltyStrategy == RoyaltyLibrary.Strategy.ROYALTY_STRATEGY) {
            require(
                sumRoyaltyShareBps <= 10 ** 4,
                "Royalty: Total royalty share bps should not exceed 10000"
            );
            _setRoyalty(_tokenId, sumRoyaltyShareBps, RoyaltyLibrary.Strategy.ROYALTY_STRATEGY);
        } else if (_royaltyStrategy == RoyaltyLibrary.Strategy.PROFIT_DISTRIBUTION_STRATEGY) {
            require(
                sumRoyaltyShareBps == 10 ** 4,
                "Royalty: Total royalty share bps should be 10000"
            );
            _setRoyalty(_tokenId, _royaltyBps, RoyaltyLibrary.Strategy.PROFIT_DISTRIBUTION_STRATEGY);
        } else if (_royaltyStrategy == RoyaltyLibrary.Strategy.PRIMARY_SALE_STRATEGY) {
            uint256 sumPrimaryRoyaltyShareBps;
            for (uint256 i = 0; i < _primaryRoyaltyShares.length; i++) {
                sumPrimaryRoyaltyShareBps = sumPrimaryRoyaltyShareBps + _primaryRoyaltyShares[i].value;
            }
            require(
                sumRoyaltyShareBps <= 10 ** 4,
                "Royalty: Total royalty share bps should not exceed 10000"
            );
            require(
                sumPrimaryRoyaltyShareBps <= 10 ** 4,
                "Royalty: Total primary royalty share bps should not exceed 10000"
            );
            _setRoyalty(_tokenId, sumRoyaltyShareBps, RoyaltyLibrary.Strategy.PRIMARY_SALE_STRATEGY);
            _addPrimaryRoyaltyShares(_tokenId, _primaryRoyaltyShares);
        } else {
            revert("Royalty: Royalty option does not exist");
        }

        _addRoyaltyShares(_tokenId, _royaltyShares);
    }

    function _setRoyalty(uint256 _tokenId, uint256 _bps, RoyaltyLibrary.Strategy _strategy) internal {
        require(
            _bps <= 10 ** 4,
            "Royalty: Total royalty bps should not exceed 10000"
        );
        royalty[_tokenId] = RoyaltyLibrary.RoyaltyInfo({
        value : _bps,
        strategy : _strategy
        });
        emit SetRoyalty(_msgSender(), _tokenId, _bps, _strategy);
    }

    function _addRoyaltyShares(uint256 _tokenId, RoyaltyLibrary.RoyaltyShareDetails[] memory _royaltyShares) internal {
        require(
            _royaltyShares.length <= maxRoyaltyShareCount,
            "Royalty: Amount of royalty recipients can't exceed 100"
        );

        address[] memory recipients = new address[](_royaltyShares.length);
        uint[] memory bps = new uint[](_royaltyShares.length);
        // Pushing the royalty shares into the mapping
        for (uint i = 0; i < _royaltyShares.length; i++) {
            require(_royaltyShares[i].recipient != address(0x0), "Royalty: Royalty share recipient should be present");
            require(_royaltyShares[i].value != 0, "Royalty: Royalty share bps value should be positive");
            royaltyShares[_tokenId].push(_royaltyShares[i]);
            recipients[i] = _royaltyShares[i].recipient;
            bps[i] = _royaltyShares[i].value;
        }
        if (_royaltyShares.length > 0) {
            emit SetRoyaltyShares(_tokenId, recipients, bps);
        }
    }

    function _addPrimaryRoyaltyShares(uint256 _tokenId, RoyaltyLibrary.RoyaltyShareDetails[] memory _royaltyShares) internal {
        require(
            _royaltyShares.length <= maxRoyaltyShareCount,
            "Royalty: Amount of royalty recipients can't exceed 100"
        );

        address[] memory recipients = new address[](_royaltyShares.length);
        uint[] memory bps = new uint[](_royaltyShares.length);
        // Pushing the royalty shares into the mapping
        for (uint i = 0; i < _royaltyShares.length; i++) {
            require(_royaltyShares[i].recipient != address(0x0), "Royalty: Primary royalty share recipient should be present");
            require(_royaltyShares[i].value != 0, "Royalty: Primary royalty share bps value should be positive");
            primaryRoyaltyShares[_tokenId].push(_royaltyShares[i]);
            recipients[i] = _royaltyShares[i].recipient;
            bps[i] = _royaltyShares[i].value;
        }
        if (_royaltyShares.length > 0) {
            emit SetPrimaryRoyaltyShares(_tokenId, recipients, bps);
        }
    }
}

File 73 of 104 : RanERC721Mock.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

contract RanERC721Mock is ERC721 {
    constructor (string memory name, string memory symbol) ERC721 (name, symbol) public {}

    function mint(address to, uint256 tokenId) public {
        _mint(to, tokenId);
    }
}

File 74 of 104 : RoyaltyERC1155Mock.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/GSN/Context.sol";
import "@openzeppelin/contracts/introspection/ERC165.sol";
import "../../interfaces/IRoyalty.sol";
import "../../libs/RoyaltyLibrary.sol";
import "./RanERC1155Mock.sol";
import "../../interfaces/ICreator.sol";
import "../../interfaces/IPrimaryRoyalty.sol";


contract RoyaltyERC1155Mock is Context, IRoyalty, ERC165, ICreator, IPrimaryRoyalty {
    event SetRoyaltyShares (
        uint256 indexed tokenId,
        address[] recipients,
        uint[] bp
    );

    event SetRoyalty (
        address owner,
        uint256 indexed tokenId,
        uint256 value,
        RoyaltyLibrary.Strategy strategy
    );

    event SetPrimaryRoyaltyShares (
        uint256 indexed tokenId,
        address[] recipients,
        uint[] bp
    );

    // tokenId => royalty
    mapping(uint256 => RoyaltyLibrary.RoyaltyInfo) royalty;

    // tokenId => royaltyShares
    mapping(uint256 => RoyaltyLibrary.RoyaltyShareDetails[]) royaltyShares;

    // tokenId => bool: true is first sale, false is secondary sale
    mapping(uint256 => bool) isSecondarySale;

    // ERC721/1155 Address
    address tokenContract;

    // Max count of royalty shares
    uint256 maxRoyaltyShareCount;

    // tokenId => creator address
    mapping(uint256 => address) creators;

    // tokenId => primary royalty
    mapping(uint256 => RoyaltyLibrary.RoyaltyShareDetails[]) primaryRoyaltyShares;

    constructor (address _tokenContract, uint256 _maxRoyaltyShareCount) public {
        tokenContract = _tokenContract;
        maxRoyaltyShareCount = _maxRoyaltyShareCount;

        _registerInterface(type(IRoyalty).interfaceId);
        _registerInterface(type(IPrimaryRoyalty).interfaceId);
        _registerInterface(type(ICreator).interfaceId);
    }

    function getTokenContract() external view override returns (address) {
        return tokenContract;
    }

    //    // Optional
    //    function setTokenContract(address token);

    function getRoyalty(uint256 _tokenId) external view override returns (RoyaltyLibrary.RoyaltyInfo memory) {
        return royalty[_tokenId];
    }

    function getRoyaltyShares(uint256 _tokenId) external view override returns (RoyaltyLibrary.RoyaltyShareDetails[] memory) {
        return royaltyShares[_tokenId];
    }

    function getPrimaryRoyaltyShares(uint256 _tokenId) external view override returns (RoyaltyLibrary.RoyaltyShareDetails[] memory) {
        return primaryRoyaltyShares[_tokenId];
    }

    function getCreator(uint256 _tokenId) external view override returns (address) {
        return creators[_tokenId];
    }

    function mint(
        uint256 _tokenId,
        bytes memory _signature,
        uint256 _supply,
        string memory _uri,
        RoyaltyLibrary.RoyaltyShareDetails[] memory _royaltyShares,
        uint256 _royaltyBps,
        RoyaltyLibrary.Strategy _royaltyStrategy,
        RoyaltyLibrary.RoyaltyShareDetails[] memory _primaryRoyaltyShares
    ) public {
        RanERC1155Mock(tokenContract).mint(_msgSender(), _tokenId, _supply);
        _addRoyalties(_tokenId, _royaltyShares, _royaltyBps, _royaltyStrategy, _primaryRoyaltyShares);
        creators[_tokenId] = _msgSender();
    }

    // Optional to make it public or not
    function _addRoyalties(
        uint256 _tokenId,
        RoyaltyLibrary.RoyaltyShareDetails[] memory _royaltyShares,
        uint256 _royaltyBps,
        RoyaltyLibrary.Strategy _royaltyStrategy,
        RoyaltyLibrary.RoyaltyShareDetails[] memory _primaryRoyaltyShares
    ) internal {
        uint256 sumRoyaltyShareBps;
        for (uint256 i = 0; i < _royaltyShares.length; i++) {
            sumRoyaltyShareBps = sumRoyaltyShareBps + _royaltyShares[i].value;
        }

        if (_royaltyStrategy == RoyaltyLibrary.Strategy.ROYALTY_STRATEGY) {
            require(
                sumRoyaltyShareBps <= 10 ** 4,
                "Royalty: Total royalty share bps should not exceed 10000"
            );
            _setRoyalty(_tokenId, sumRoyaltyShareBps, RoyaltyLibrary.Strategy.ROYALTY_STRATEGY);
        } else if (_royaltyStrategy == RoyaltyLibrary.Strategy.PROFIT_DISTRIBUTION_STRATEGY) {
            require(
                sumRoyaltyShareBps == 10 ** 4,
                "Royalty: Total royalty share bps should be 10000"
            );
            _setRoyalty(_tokenId, _royaltyBps, RoyaltyLibrary.Strategy.PROFIT_DISTRIBUTION_STRATEGY);
        } else if (_royaltyStrategy == RoyaltyLibrary.Strategy.PRIMARY_SALE_STRATEGY) {
            uint256 sumPrimaryRoyaltyShareBps;
            for (uint256 i = 0; i < _primaryRoyaltyShares.length; i++) {
                sumPrimaryRoyaltyShareBps = sumPrimaryRoyaltyShareBps + _primaryRoyaltyShares[i].value;
            }
            require(
                sumRoyaltyShareBps <= 10 ** 4,
                "Royalty: Total royalty share bps should not exceed 10000"
            );
            require(
                sumPrimaryRoyaltyShareBps <= 10 ** 4,
                "Royalty: Total primary royalty share bps should not exceed 10000"
            );
            _setRoyalty(_tokenId, sumRoyaltyShareBps, RoyaltyLibrary.Strategy.PRIMARY_SALE_STRATEGY);
            _addPrimaryRoyaltyShares(_tokenId, _primaryRoyaltyShares);
        } else {
            revert("Royalty: Royalty option does not exist");
        }

        _addRoyaltyShares(_tokenId, _royaltyShares);
    }

    function _setRoyalty(uint256 _tokenId, uint256 _bps, RoyaltyLibrary.Strategy _strategy) internal {
        require(
            _bps <= 10 ** 4,
            "Royalty: Total royalty bps should not exceed 10000"
        );
        royalty[_tokenId] = RoyaltyLibrary.RoyaltyInfo({
        value : _bps,
        strategy : _strategy
        });
        emit SetRoyalty(_msgSender(), _tokenId, _bps, _strategy);
    }

    function _addRoyaltyShares(uint256 _tokenId, RoyaltyLibrary.RoyaltyShareDetails[] memory _royaltyShares) internal {
        require(
            _royaltyShares.length <= maxRoyaltyShareCount,
            "Royalty: Amount of royalty recipients can't exceed 100"
        );

        address[] memory recipients = new address[](_royaltyShares.length);
        uint[] memory bps = new uint[](_royaltyShares.length);
        // Pushing the royalty shares into the mapping
        for (uint i = 0; i < _royaltyShares.length; i++) {
            require(_royaltyShares[i].recipient != address(0x0), "Royalty: Royalty share recipient should be present");
            require(_royaltyShares[i].value != 0, "Royalty: Royalty share bps value should be positive");
            royaltyShares[_tokenId].push(_royaltyShares[i]);
            recipients[i] = _royaltyShares[i].recipient;
            bps[i] = _royaltyShares[i].value;
        }
        if (_royaltyShares.length > 0) {
            emit SetRoyaltyShares(_tokenId, recipients, bps);
        }
    }

    function _addPrimaryRoyaltyShares(uint256 _tokenId, RoyaltyLibrary.RoyaltyShareDetails[] memory _royaltyShares) internal {
        require(
            _royaltyShares.length <= maxRoyaltyShareCount,
            "Royalty: Amount of royalty recipients can't exceed 100"
        );

        address[] memory recipients = new address[](_royaltyShares.length);
        uint[] memory bps = new uint[](_royaltyShares.length);
        // Pushing the royalty shares into the mapping
        for (uint i = 0; i < _royaltyShares.length; i++) {
            require(_royaltyShares[i].recipient != address(0x0), "Royalty: Primary royalty share recipient should be present");
            require(_royaltyShares[i].value != 0, "Royalty: Primary royalty share bps value should be positive");
            primaryRoyaltyShares[_tokenId].push(_royaltyShares[i]);
            recipients[i] = _royaltyShares[i].recipient;
            bps[i] = _royaltyShares[i].value;
        }
        if (_royaltyShares.length > 0) {
            emit SetPrimaryRoyaltyShares(_tokenId, recipients, bps);
        }
    }
}

File 75 of 104 : RanERC1155Mock.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;

import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";

contract RanERC1155Mock is ERC1155 {
    constructor (string memory uri) ERC1155 (uri) public {}

    function mint(address account, uint256 id, uint256 amount) public {
        _mint(account, id, amount, '');
    }
}

File 76 of 104 : ERC1155Supply.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.12;

import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";

/**
 * @dev Extension of ERC1155 that adds tracking of total supply per id.
 *
 * Useful for scenarios where Fungible and Non-fungible tokens have to be
 * clearly identified. Note: While a totalSupply of 1 might mean the
 * corresponding is an NFT, there is no guarantees that no other token with the
 * same id are not going to be minted.
 */
abstract contract ERC1155Supply is ERC1155 {
    mapping(uint256 => uint256) private _totalSupply;

    /**
     * @dev Total amount of tokens in with a given id.
     */
    function totalSupply(uint256 id) public view virtual returns (uint256) {
        return _totalSupply[id];
    }

    /**
     * @dev Indicates weither any token exist with a given id, or not.
     */
    function exists(uint256 id) public view virtual returns (bool) {
        return ERC1155Supply.totalSupply(id) > 0;
    }

    /**
     * @dev See {ERC1155-_mint}.
     */
    function _mint(
        address account,
        uint256 id,
        uint256 amount,
        bytes memory data
    ) internal virtual override {
        super._mint(account, id, amount, data);
        _totalSupply[id] += amount;
    }

    /**
     * @dev See {ERC1155-_mintBatch}.
     */
    function _mintBatch(
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) internal virtual override {
        super._mintBatch(to, ids, amounts, data);
        for (uint256 i = 0; i < ids.length; ++i) {
            _totalSupply[ids[i]] += amounts[i];
        }
    }

    /**
     * @dev See {ERC1155-_burn}.
     */
    function _burn(
        address account,
        uint256 id,
        uint256 amount
    ) internal virtual override {
        require(
            account == _msgSender() || isApprovedForAll(account, _msgSender()),
            "ERC1155Supply: caller is not owner nor approved"
        );
        super._burn(account, id, amount);
        _totalSupply[id] -= amount;
    }

    /**
     * @dev See {ERC1155-_burnBatch}.
     */
    function _burnBatch(
        address account,
        uint256[] memory ids,
        uint256[] memory amounts
    ) internal virtual override {
        require(
            account == _msgSender() || isApprovedForAll(account, _msgSender()),
            "ERC1155Supply: caller is not owner nor approved"
        );
        super._burnBatch(account, ids, amounts);
        for (uint256 i = 0; i < ids.length; ++i) {
            _totalSupply[ids[i]] -= amounts[i];
        }
    }
}

File 77 of 104 : ERC1155BaseV2.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "../HasContractURI.sol";
import "../HasTokenURI.sol";
import "./ERC1155Supply.sol";
import "../../roles/MinterRole.sol";
import "../../libs/RoyaltyLibrary.sol";
import "../Royalty.sol";

abstract contract ERC1155BaseV2 is
HasTokenURI,
HasContractURI,
ERC1155Supply,
MinterRole,
Royalty
{
    string public name;
    string public symbol;

    /*
     * bytes4(keccak256('MINT_WITH_ADDRESS')) == 0xe37243f2
     */
    bytes4 private constant _INTERFACE_ID_MINT_WITH_ADDRESS = 0xe37243f2;

    constructor(
        string memory _name,
        string memory _symbol,
        string memory _contractURI,
        string memory _tokenURIPrefix,
        string memory _uri
    ) HasContractURI(_contractURI) HasTokenURI(_tokenURIPrefix) ERC1155(_uri) public {
        name = _name;
        symbol = _symbol;
        _registerInterface(_INTERFACE_ID_MINT_WITH_ADDRESS);
    }

    // Creates a new token type and assings _initialSupply to minter
    function _mint(
        uint256 _tokenId,
        RoyaltyLibrary.RoyaltyShareDetails[] memory _royaltyShares,
        uint256 _supply,
        string memory _uri,
        uint256 _royaltyBps,
        RoyaltyLibrary.Strategy _royaltyStrategy
    ) internal {
        require(exists(_tokenId) == false, "ERC1155: Token is already minted");
        require(_supply != 0, "ERC1155: Supply should be positive");
        require(bytes(_uri).length > 0, "ERC1155: Uri should be set");

        _mint(msg.sender, _tokenId, _supply, "");
        _setTokenURI(_tokenId, _uri);
        uint256 sumRoyaltyShareBps;
        for (uint256 i = 0; i < _royaltyShares.length; i++) {
            sumRoyaltyShareBps = sumRoyaltyShareBps.add(_royaltyShares[i].value);
        }

        if(_royaltyStrategy == RoyaltyLibrary.Strategy.ROYALTY_STRATEGY) {
            require(
                sumRoyaltyShareBps <= 10**4,
                "ERC1155: Total fee bps should not exceed 10000"
            );
            _setRoyalty(_tokenId, sumRoyaltyShareBps, RoyaltyLibrary.Strategy.ROYALTY_STRATEGY);
        } else if (_royaltyStrategy == RoyaltyLibrary.Strategy.PROFIT_DISTRIBUTION_STRATEGY) {
            require(
                sumRoyaltyShareBps == 10**4,
                "ERC1155: Total fee bps should be 10000"
            );
            _setRoyalty(_tokenId, _royaltyBps,  RoyaltyLibrary.Strategy.PROFIT_DISTRIBUTION_STRATEGY);
        }else{
            revert("ERC1155: Royalty option does not exist");
        }

        _addRoyaltyShares(_tokenId, _royaltyShares);

        // Transfer event with mint semantic
        emit URI(_uri, _tokenId);
    }

    function burn(address _owner, uint256 _tokenId, uint256 _value) external {
        _burn(_owner, _tokenId, _value);
    }

    /**
     * @dev Internal function to set the token URI for a given token.
     * Reverts if the token ID does not exist.
     * @param _tokenId uint256 ID of the token to set its URI
     * @param _uri string URI to assign
     */
    function _setTokenURI(uint256 _tokenId, string memory _uri) override virtual internal {
        require(exists(_tokenId), "ERC1155: Token should exist");
        super._setTokenURI(_tokenId, _uri);
    }

    function setTokenURIPrefix(string memory _tokenURIPrefix) public onlyAdmin {
        _setTokenURIPrefix(_tokenURIPrefix);
    }

    function setContractURI(string memory _contractURI) public onlyAdmin {
        _setContractURI(_contractURI);
    }

    function uri(uint256 _tokenId) override external view returns (string memory) {
        return _tokenURI(_tokenId);
    }
}

File 78 of 104 : RefinableERC1155WhiteListedTokenV2.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/cryptography/ECDSA.sol";
import "./ERC1155BaseV2.sol";

contract RefinableERC1155WhiteListedTokenV2 is ERC1155BaseV2 {

    using ECDSA for bytes32;

    address payable public defaultRoyaltyReceiver = address(0);
    uint256 public defaultRoyaltyReceiverBps = 0;

    /**
     * @dev Constructor Function
     * @param _name name of the token ex: Rarible
     * @param _symbol symbol of the token ex: RARI
     * @param _signer address of signer account
     * @param _contractURI URI of contract ex: https://api-mainnet.rarible.com/contractMetadata/{address}
     * @param _tokenURIPrefix token URI Prefix
     * @param _uri ex: https://ipfs.daonomic.com
    */
    constructor(
        string memory _name,
        string memory _symbol,
        address _root,
        address _signer,
        string memory _contractURI,
        string memory _tokenURIPrefix,
        string memory _uri
    ) ERC1155BaseV2(_name, _symbol, _contractURI, _tokenURIPrefix, _uri) public {
        addAdmin(_root);
        addSigner(_signer);
    }

    //add the default royalties if the contract has set
    function mint(
        uint256 _tokenId,
        bytes memory _signature,
        RoyaltyLibrary.RoyaltyShareDetails[] memory _royaltyShares,
        uint256 _supply,
        string memory _uri,
        uint256 _royaltyBps,
        RoyaltyLibrary.Strategy _royaltyStrategy
    ) public onlyMinter {
        require(
            hasRole(SIGNER_ROLE,
            keccak256(abi.encodePacked(address(this), _tokenId, _msgSender()))
            .toEthSignedMessageHash()
            .recover(_signature)
            )
        , "invalid signature"
        );
        RoyaltyLibrary.RoyaltyShareDetails[] memory newRoyaltyShares;
        if (defaultRoyaltyReceiver != address(0) && defaultRoyaltyReceiverBps != 0) {
            newRoyaltyShares = new RoyaltyLibrary.RoyaltyShareDetails[](_royaltyShares.length + 1);
            for (uint256 i = 0; i < _royaltyShares.length; i++) {
                newRoyaltyShares[i] = _royaltyShares[i];
            }
            newRoyaltyShares[_royaltyShares.length] = RoyaltyLibrary.RoyaltyShareDetails({
            recipient : defaultRoyaltyReceiver,
            value : defaultRoyaltyReceiverBps
            });
        } else {
            newRoyaltyShares = _royaltyShares;
        }

        _mint(_tokenId, newRoyaltyShares, _supply, _uri, _royaltyBps, _royaltyStrategy);
    }

    function setDefaultRoyaltyReceiver(address payable _receiver) public onlyAdmin {
        defaultRoyaltyReceiver = _receiver;
    }

    function setDefaultRoyaltyReceiverBps(uint256 _bps) public onlyAdmin {
        require(_bps <= 10**4, "ERC721: Fee bps should not exceed 10000");
        defaultRoyaltyReceiverBps = _bps;
    }
}

File 79 of 104 : RefinableERC1155TokenV2.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/cryptography/ECDSA.sol";
import "./ERC1155BaseV2.sol";

contract RefinableERC1155TokenV2 is ERC1155BaseV2 {
    using ECDSA for bytes32;

    /**
     * @dev Constructor Function
     * @param _name name of the token ex: Rarible
     * @param _symbol symbol of the token ex: RARI
     * @param _signer address of signer account
     * @param _contractURI URI of contract ex: https://api-mainnet.rarible.com/contractMetadata/{address}
     * @param _tokenURIPrefix token URI Prefix
     * @param _uri ex: https://ipfs.daonomic.com
    */
    constructor(
        string memory _name,
        string memory _symbol,
        address _root,
        address _signer,
        string memory _contractURI,
        string memory _tokenURIPrefix,
        string memory _uri
    ) ERC1155BaseV2(_name, _symbol, _contractURI, _tokenURIPrefix, _uri) public {
        addAdmin(_root);
        addSigner(_signer);
    }

    function mint(
        uint256 _tokenId,
        bytes memory _signature,
        RoyaltyLibrary.RoyaltyShareDetails[] memory _royaltyShares,
        uint256 _supply,
        string memory _uri,
        uint256 _royaltyBps,
        RoyaltyLibrary.Strategy _royaltyStrategy
    ) public {
        require(
            isSigner(
                keccak256(abi.encodePacked(address(this), _tokenId, _msgSender()))
                .toEthSignedMessageHash()
                .recover(_signature)
            )
        , "invalid signature"
        );
        _mint(_tokenId, _royaltyShares, _supply, _uri, _royaltyBps, _royaltyStrategy);
    }
}

File 80 of 104 : ERC1155Sale.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";

import "./ERC1155SaleNonceHolder.sol";
import "../tokens/v1/HasSecondarySaleFees.sol";
import "../proxy/TransferProxy.sol";
import "../proxy/ServiceFeeProxy.sol";
import "../tge/interfaces/IBEP20.sol";
import "../managers/TradeTokenManager.sol";
import "../managers/NftTokenManager.sol";
import "../libs/RoyaltyLibrary.sol";
import "../service_fee/RoyaltiesStrategy.sol";
import "../interfaces/ICreator.sol";

import "./VipPrivatePublicSaleInfo.sol";

contract ERC1155Sale is ReentrancyGuard, RoyaltiesStrategy, VipPrivatePublicSaleInfo {
  using ECDSA for bytes32;
    using RoyaltyLibrary for RoyaltyLibrary.Strategy;

    event CloseOrder(
        address indexed token,
        uint256 indexed tokenId,
        address owner,
        uint256 nonce
    );
    event Buy(
        address indexed token,
        uint256 indexed tokenId,
        address owner,
        address payToken,
        uint256 price,
        address buyer,
        uint256 value
    );    

    bytes constant EMPTY = "";
    bytes4 private constant _INTERFACE_ID_ERC1155 = 0xd9b67a26;
    bytes4 private constant _INTERFACE_ID_FEES = 0xb7799584;
    bytes4 private constant _INTERFACE_ID_ROYALTY = 0x7b296bd9;
    bytes4 private constant _INTERFACE_ID_ROYALTY_V2 = 0x9e4a83d4;

    address public transferProxy;
    address public serviceFeeProxy;
    address public nonceHolder;
    address public tradeTokenManager;

    constructor(
        address _transferProxy,
        address _nonceHolder,
        address _serviceFeeProxy,
        address _tradeTokenManager
    ) public {
        transferProxy = _transferProxy;
        nonceHolder = _nonceHolder;
        serviceFeeProxy = _serviceFeeProxy;
        tradeTokenManager = _tradeTokenManager;
    }

    function buy(
        address _token,
        address _royaltyToken,
        uint256 _tokenId,
        address _payToken,
        address payable _owner,
        uint256 _selling,
        uint256 _buying,
        bytes memory _signature
    ) public payable nonReentrant {

        bytes32 saleId = getID(_owner, _token, _tokenId);

        // clean up saleInfo
        if(!whitelistNeeded(saleId) && saleInfo[saleId].vipSaleDate >= 0) {
            delete saleInfo[saleId];
        }

        require(
            IERC1155(_token).supportsInterface(_INTERFACE_ID_ERC1155),
            "ERC1155Sale: Invalid NFT"
        );

        if (_royaltyToken != address(0)) {
            require(
                IERC1155(_royaltyToken).supportsInterface(_INTERFACE_ID_ROYALTY_V2),
                "ERC1155Sale: Invalid royalty contract"
            );
            require(
                IRoyalty(_royaltyToken).getTokenContract() == _token,
                "ERC1155Sale: Royalty Token address does not match buy token"
            );
        }

        require(whitelisted(saleId, msg.sender), "You should be whitelisted and sale should have started");

        require(
            IERC1155(_token).balanceOf(_owner, _tokenId) >= _buying,
            "ERC1155Sale: Owner doesn't enough tokens"
        );

        uint256 receiveAmount;
        if (_payToken == address(0)) {
            receiveAmount = msg.value;
        } else {
            require(TradeTokenManager(tradeTokenManager).supportToken(_payToken) == true, "ERC721Sale: Pay Token is not allowed");
            receiveAmount = IBEP20(_payToken).allowance(msg.sender, address(this));
        }

        uint256 price = receiveAmount.mul(10 ** 4).div(ServiceFeeProxy(serviceFeeProxy).getBuyServiceFeeBps(msg.sender).add(10 ** 4)).div(_buying);

        uint256 nonce = verifySignature(
            _token,
            _tokenId,
            _payToken,
            _owner,
            _selling,
            price,
            _signature
        );
        verifyOpenAndModifyState(
            _token,
            _tokenId,
            _owner,
            nonce,
            _selling,
            _buying
        );

        TransferProxy(transferProxy).erc1155safeTransferFrom(
            _token,
            _owner,
            msg.sender,
            _tokenId,
            _buying,
            EMPTY
        );

        if (_royaltyToken != address(0)) {
            _distributeProfit(_royaltyToken, _tokenId, _payToken, _owner, price.mul(_buying), receiveAmount);
        } else {
            _distributeProfit(_token, _tokenId, _payToken, _owner, price.mul(_buying), receiveAmount);
        }
        emit Buy(_token, _tokenId, _owner, _payToken, price, msg.sender, _buying);
    }

    function _distributeProfit(
        address _token,
        uint256 _tokenId,
        address _payToken,
        address payable _owner,
        uint256 _totalPrice,
        uint256 _receiveAmount
    ) internal {
        bool isSecondarySale = _checkSecondarySale(_token, _tokenId, _owner);
        uint256 sellerServiceFeeBps = ServiceFeeProxy(serviceFeeProxy).getSellServiceFeeBps(_owner, isSecondarySale);
        address payable serviceFeeRecipient = ServiceFeeProxy(serviceFeeProxy).getServiceFeeRecipient();
        uint256 sellerServiceFee = _totalPrice.mul(sellerServiceFeeBps).div(10 ** 4);
        /*
           * The sellerReceiveAmount is on sale price minus seller service fee minus buyer service fee
           * This make sures we have enough balance even the royalties is 100%
        */
        uint256 sellerReceiveAmount = _totalPrice.sub(sellerServiceFee);
        uint256 royalties;
        if (
            IERC165(_token).supportsInterface(_INTERFACE_ID_FEES)
            || IERC165(_token).supportsInterface(_INTERFACE_ID_ROYALTY)
            || IERC165(_token).supportsInterface(_INTERFACE_ID_ROYALTY_V2)
        )
            royalties = _payOutRoyaltiesByStrategy(_token, _tokenId, _payToken, _msgSender(), sellerReceiveAmount, isSecondarySale);

        sellerReceiveAmount = sellerReceiveAmount.sub(royalties);
        if (_payToken == address(0)) {
            _owner.transfer(sellerReceiveAmount);
            serviceFeeRecipient.transfer(sellerServiceFee.add(_receiveAmount.sub(_totalPrice)));
        } else {
            IBEP20(_payToken).transferFrom(_msgSender(), _owner, sellerReceiveAmount);
            IBEP20(_payToken).transferFrom(_msgSender(), serviceFeeRecipient, sellerServiceFee.add(_receiveAmount.sub(_totalPrice)));
        }
    }

    function _checkSecondarySale(address _token, uint256 _tokenId, address _seller) internal returns (bool){
        if (IERC165(_token).supportsInterface(type(ICreator).interfaceId)) {
            address creator = ICreator(_token).getCreator(_tokenId);
            return (creator != _seller);
        } else {
            return true;
        }
    }

    function cancel(address token, uint256 tokenId) public {
        uint256 nonce = ERC1155SaleNonceHolder(nonceHolder).getNonce(token, tokenId, msg.sender);
        ERC1155SaleNonceHolder(nonceHolder).setNonce(token, tokenId, msg.sender, nonce.add(1));

        emit CloseOrder(token, tokenId, msg.sender, nonce.add(1));
    }

    function verifySignature(
        address _token,
        uint256 _tokenId,
        address _payToken,
        address payable _owner,
        uint256 _selling,
        uint256 _price,
        bytes memory _signature
    ) internal view returns (uint256 nonce) {
        nonce = ERC1155SaleNonceHolder(nonceHolder).getNonce(_token, _tokenId, _owner);
        address owner;

        if (_payToken == address(0)) {
            owner = keccak256(abi.encodePacked(_token, _tokenId, _price, _selling, nonce))
            .toEthSignedMessageHash()
            .recover(_signature);
        } else {
            owner = keccak256(abi.encodePacked(_token, _tokenId, _payToken, _price, _selling, nonce))
            .toEthSignedMessageHash()
            .recover(_signature);
        }

        require(
            owner == _owner,
            "ERC1155Sale: Incorrect signature"
        );
    }

    function verifyOpenAndModifyState(
        address _token,
        uint256 _tokenId,
        address payable _owner,
        uint256 _nonce,
        uint256 _selling,
        uint256 _buying
    ) internal {
        uint256 comp = ERC1155SaleNonceHolder(nonceHolder)
        .getCompleted(_token, _tokenId, _owner, _nonce)
        .add(_buying);
        require(comp <= _selling);
        ERC1155SaleNonceHolder(nonceHolder).setCompleted(_token, _tokenId, _owner, _nonce, comp);

        if (comp == _selling) {
            ERC1155SaleNonceHolder(nonceHolder).setNonce(_token, _tokenId, _owner, _nonce.add(1));
            emit CloseOrder(_token, _tokenId, _owner, _nonce.add(1));
        }
    }
}

File 81 of 104 : ERC1155SaleNonceHolder.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;

import "../roles/OperatorRole.sol";

contract ERC1155SaleNonceHolder is OperatorRole {
    // keccak256(token, owner, tokenId) => nonce
    mapping(bytes32 => uint256) public nonces;

    // keccak256(token, owner, tokenId, nonce) => completed amount
    mapping(bytes32 => uint256) public completed;

    function getNonce(
        address token,
        uint256 tokenId,
        address owner
    ) public view returns (uint256) {
        return nonces[getNonceKey(token, tokenId, owner)];
    }

    function setNonce(
        address token,
        uint256 tokenId,
        address owner,
        uint256 nonce
    ) public onlyOperator {
        nonces[getNonceKey(token, tokenId, owner)] = nonce;
    }

    function getNonceKey(
        address token,
        uint256 tokenId,
        address owner
    ) public pure returns (bytes32) {
        return keccak256(abi.encodePacked(token, tokenId, owner));
    }

    function getCompleted(
        address token,
        uint256 tokenId,
        address owner,
        uint256 nonce
    ) public view returns (uint256) {
        return completed[getCompletedKey(token, tokenId, owner, nonce)];
    }

    function setCompleted(
        address token,
        uint256 tokenId,
        address owner,
        uint256 nonce,
        uint256 _completed
    ) public onlyOperator {
        completed[getCompletedKey(token, tokenId, owner, nonce)] = _completed;
    }

    function getCompletedKey(
        address token,
        uint256 tokenId,
        address owner,
        uint256 nonce
    ) public pure returns (bytes32) {
        return keccak256(abi.encodePacked(token, tokenId, owner, nonce));
    }
}

File 82 of 104 : ERC721Auction.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/GSN/Context.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "../tge/interfaces/IBEP20.sol";
import "../tokens/HasSecondarySale.sol";
import "../proxy/ServiceFeeProxy.sol";
import "../roles/AdminRole.sol";
import "../libs/BidLibrary.sol";
import "../managers/TradeTokenManager.sol";
import "../managers/NftTokenManager.sol";
import "../service_fee/RoyaltiesStrategy.sol";

/**
 * @notice Primary sale auction contract for Refinable NFTs
 */
contract ERC721Auction is Context, ReentrancyGuard, AdminRole, RoyaltiesStrategy {
    using SafeMath for uint256;
    using Address for address payable;
    using BidLibrary for BidLibrary.Bid[];

    /// @notice Event emitted only on construction. To be used by indexers
    event AuctionContractDeployed();

    event PauseToggled(bool isPaused);

    event Destroy();

    event AuctionCreated(bytes32 auctionId, address token, uint256 indexed tokenId, address payToken);

    event AuctionCreateTimeLimitUpdated(uint256 auctionCreateTimeLimit);

    event AuctionStartTimeUpdated(bytes32 auctionId, address token, uint256 indexed tokenId, uint256 startTime);

    event AuctionEndTimeUpdated(bytes32 auctionId, address token, uint256 indexed tokenId, uint256 endTime);

    event MinBidIncrementBpsUpdated(uint256 minBidIncrementBps);

    event MaxBidStackCountUpdated(uint256 maxBidStackCount);

    event BidWithdrawalLockTimeUpdated(uint256 bidWithdrawalLockTime);

    event BidPlaced(
        bytes32 auctionId,
        address token,
        uint256 indexed tokenId,
        address payToken,
        address indexed bidder,
        uint256 bidAmount,
        uint256 actualBidAmount
    );

    event BidWithdrawn(
        bytes32 auctionId,
        address token,
        uint256 indexed tokenId,
        address payToken,
        address indexed bidder,
        uint256 bidAmount
    );

    event BidRefunded(
        address indexed bidder,
        uint256 bidAmount,
        address payToken
    );

    event AuctionResulted(
        bytes32 auctionId,
        address token,
        uint256 indexed tokenId,
        address payToken,
        address indexed winner,
        uint256 winningBidAmount
    );

    event AuctionCancelled(bytes32 auctionId, address token, uint256 indexed tokenId);

    /// @notice Parameters of an auction
    struct Auction {
        address token;
        address royaltyToken;
        uint256 tokenId;
        address owner;
        address payToken;
        uint256 startPrice;
        uint256 startTime;
        uint256 endTime;
        bool created;
    }

    address public serviceFeeProxy;

    address public tradeTokenManager;

    /// @notice ERC721 Auction ID -> Auction Parameters
    mapping(bytes32 => Auction) public auctions;

    /// @notice ERC721 Auction ID -> Bid Parameters
    mapping(bytes32 => BidLibrary.Bid[]) public bids;

    /// @notice globally and across all auctions, the amount by which a bid has to increase
    uint256 public minBidIncrementBps = 250;

    //@notice global auction create time limit
    uint256 public auctionCreateTimeLimit = 30 days;

    /// @notice global bid withdrawal lock time
    uint256 public bidWithdrawalLockTime = 3 days;

    /// @notice global limit time betwen bid time and auction end time
    uint256 public bidLimitBeforeEndTime = 5 minutes;

    /// @notice max bidders stack count
    uint256 public maxBidStackCount = 1;

    /// @notice for switching off auction creations, bids and withdrawals
    bool public isPaused;

    bytes4 private constant _INTERFACE_ID_HAS_SECONDARY_SALE = 0x5595380a;
    bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd;
    bytes4 private constant _INTERFACE_ID_FEES = 0xb7799584;
    bytes4 private constant _INTERFACE_ID_ROYALTY = 0x7b296bd9;
    bytes4 private constant _INTERFACE_ID_ROYALTY_V2 = 0x9e4a83d4;

    modifier whenNotPaused() {
        require(!isPaused, "Auction: Function is currently paused");
        _;
    }

    modifier onlyCreatedAuction(bytes32 _auctionId) {
        require(
            auctions[_auctionId].created == true,
            "Auction: Auction does not exist"
        );
        _;
    }

    /**
     * @notice Auction Constructor
    * @param _serviceFeeProxy service fee proxy
     */
    constructor(
        address _serviceFeeProxy,
        address _tradeTokenManager
    ) public {
        serviceFeeProxy = _serviceFeeProxy;
        tradeTokenManager = _tradeTokenManager;
        _setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
        emit AuctionContractDeployed();
    }

    /**
     * @notice Creates a new auction for a given token
     * @dev Only the owner of a token can create an auction and must have approved the contract
     * @dev End time for the auction must be in the future.
     * @param _token Token Address that follows ERC721 standard
     * @param _tokenId Token ID of the token being auctioned
     * @param _startPrice Starting bid price of the token being auctioned
     * @param _startTimestamp Unix epoch in seconds for the auction start time
     * @param _endTimestamp Unix epoch in seconds for the auction end time.
     */
    function createAuction(
        address _token,
        address _royaltyToken,
        uint256 _tokenId,
        address _payToken,
        uint256 _startPrice,
        uint256 _startTimestamp,
        uint256 _endTimestamp
    ) external whenNotPaused {
        require(
            _startTimestamp <= _getNow().add(auctionCreateTimeLimit),
            "Auction: Exceed auction start time limit"
        );
        require(
            IERC721(_token).supportsInterface(_INTERFACE_ID_ERC721),
            "Auction: Invalid NFT"
        );

        if (_royaltyToken != address(0)) {
            require(
                IERC721(_royaltyToken).supportsInterface(_INTERFACE_ID_ROYALTY_V2),
                "Auction: Invalid royalty contract"
            );
            require(
                IRoyalty(_royaltyToken).getTokenContract() == _token,
                "Auction: Royalty Token address does not match buy token"
            );
        }

        // Check owner of the token is the creator and approved
        require(
            IERC721(_token).ownerOf(_tokenId) == msg.sender,
            "Auction: Caller is not the owner"
        );
        require(
            IERC721(_token).isApprovedForAll(msg.sender, address(this)),
            "Auction: Owner has not approved"
        );

        if (_payToken != address(0)) {
            require(
                TradeTokenManager(tradeTokenManager).supportToken(_payToken) == true,
                "Auction: Pay Token is not allowed"
            );
        }

        bytes32 auctionId = getAuctionId(_token, _tokenId, msg.sender);

        // Check the auction already created, can only list 1 token at a time
        require(
            auctions[auctionId].created == false,
            "Auction: Auction has been already created"
        );
        // Check end time not before start time and that end is in the future
        require(
            _endTimestamp > _startTimestamp && _endTimestamp > _getNow(),
            "Auction: Auction time is incorrect"
        );

        // Setup the auction
        auctions[auctionId] = Auction({
        token : _token,
        royaltyToken : _royaltyToken,
        tokenId : _tokenId,
        owner : msg.sender,
        payToken : _payToken,
        startPrice : _startPrice,
        startTime : _startTimestamp,
        endTime : _endTimestamp,
        created : true
        });

        emit AuctionCreated(auctionId, _token, _tokenId, _payToken);
    }

    /**
     * @notice Places a new bid, out bidding the existing bidder if found and criteria is reached
     * @dev Only callable when the auction is open
     * @dev Bids from smart contracts are prohibited to prevent griefing with always reverting receiver
     * @param _auctionId Auction ID the id can be obtained from the getAuctionId function
     */
    function placeBid(bytes32 _auctionId)
    external
    payable
    nonReentrant
    whenNotPaused
    onlyCreatedAuction(_auctionId)
    {
        require(
            msg.sender.isContract() == false,
            "Auction: No contracts permitted"
        );

        // Ensure auction is in flight
        require(
            _getNow() >= auctions[_auctionId].startTime && _getNow() <= auctions[_auctionId].endTime,
            "Auction: Bidding outside of the auction window"
        );

        uint256 bidAmount;

        if (auctions[_auctionId].payToken == address(0)) {
            bidAmount = msg.value;
        } else {
            bidAmount = IBEP20(auctions[_auctionId].payToken).allowance(msg.sender, address(this));
            require(
                IBEP20(auctions[_auctionId].payToken).transferFrom(msg.sender, address(this), bidAmount) == true,
                "Auction: Token transfer failed"
            );
        }

        // Ensure bid adheres to outbid increment and threshold
        uint256 actualBidAmount = bidAmount.mul(10 ** 4).div(ServiceFeeProxy(serviceFeeProxy).getBuyServiceFeeBps(msg.sender).add(10 ** 4));
        uint256 minBidRequired;
        BidLibrary.Bid[] storage bidList = bids[_auctionId];

        if (bidList.length != 0) {
            minBidRequired =
            bidList[bidList.length - 1].actualBidAmount.mul(minBidIncrementBps.add(10 ** 4)).div(10 ** 4);
        } else {
            minBidRequired = auctions[_auctionId].startPrice;
        }

        require(
            actualBidAmount >= minBidRequired,
            "Auction: Failed to outbid min price"
        );

        // assign top bidder and bid time
        BidLibrary.Bid memory newHighestBid = BidLibrary.Bid({
        bidder : _msgSender(),
        bidAmount : bidAmount,
        actualBidAmount : actualBidAmount,
        bidTime : _getNow()
        });

        bidList.push(newHighestBid);

        //Refund old bid if bidlist overflows thans max bid stack count
        if (bidList.length > maxBidStackCount) {
            BidLibrary.Bid memory oldBid = bidList[0];
            if (oldBid.bidder != address(0)) {
                _refundBid(oldBid.bidder, oldBid.bidAmount, auctions[_auctionId].payToken);
            }

            bidList.removeByIndex(0);
        }

        //Increase auction end time if bid time is more than 5 mins before end time
        if (auctions[_auctionId].endTime <= newHighestBid.bidTime.add(bidLimitBeforeEndTime)) {
            _updateAuctionEndTime(_auctionId, auctions[_auctionId].endTime.add(bidLimitBeforeEndTime));
        }

        emit BidPlaced(
            _auctionId,
            auctions[_auctionId].token,
            auctions[_auctionId].tokenId,
            auctions[_auctionId].payToken,
            _msgSender(),
            bidAmount,
            actualBidAmount
        );
    }

    /**
     * @notice Given a sender who is in the bid list of auction, allows them to withdraw their bid
     * @dev Only callable by the existing top bidder
     * @param _auctionId Auction ID the id can be obtained from the getAuctionId function
     */
    function withdrawBid(bytes32 _auctionId)
    external
    nonReentrant
    whenNotPaused
    onlyCreatedAuction(_auctionId)
    {
        BidLibrary.Bid[] storage bidList = bids[_auctionId];
        require(bidList.length > 0, "Auction: There is no bid");

        uint256 withdrawIndex = bidList.length;
        for (uint256 i = 0; i < bidList.length; i++) {
            if (bidList[i].bidder == _msgSender()) {
                withdrawIndex = i;
            }
        }

        require(withdrawIndex != bidList.length, "Auction: Caller is not bidder");

        BidLibrary.Bid storage withdrawableBid = bidList[withdrawIndex];

        // Check withdrawal after delay time
        require(
            _getNow() >= auctions[_auctionId].endTime.add(bidWithdrawalLockTime),
            "Auction: Cannot withdraw until auction ends"
        );

        if (withdrawableBid.bidder != address(0)) {
            _refundBid(withdrawableBid.bidder, withdrawableBid.bidAmount, auctions[_auctionId].payToken);
        }

        bidList.removeByIndex(withdrawIndex);

        emit BidWithdrawn(
            _auctionId,
            auctions[_auctionId].token,
            auctions[_auctionId].tokenId,
            auctions[_auctionId].payToken,
            _msgSender(),
            withdrawableBid.bidAmount
        );
    }

    /**
     * @notice Results a finished auction
     * @dev Only admin or smart contract
     * @dev Auction can only be resulted if there has been a bidder and reserve met.
     * @dev If there have been no bids, the auction needs to be cancelled instead using `cancelAuction()`
     * @param _auctionId Auction ID the id can be obtained from the getAuctionId function
     */
    function endAuction(bytes32 _auctionId)
    external
    nonReentrant
    onlyCreatedAuction(_auctionId)
    {
        Auction memory auction = auctions[_auctionId];

        require(
            isAdmin(msg.sender) || (auction.owner == msg.sender),
            "Auction: Only admin or auction owner can result the auction"
        );

        // Check the auction has ended
        require(
            _getNow() > auction.endTime,
            "Auction: Auction has not ended"
        );

        // Ensure this contract is approved to move the token
        require(
            IERC721(auction.token).isApprovedForAll(auction.owner, address(this)),
            "Auction: Auction not approved"
        );

        // Get info on who the highest bidder is
        BidLibrary.Bid[] storage bidList = bids[_auctionId];

        require(bidList.length > 0, "Auction: There is no bid");

        BidLibrary.Bid memory highestBid = bidList[bidList.length - 1];

        bool isSecondarySale;
        if (IERC165(auction.token).supportsInterface(_INTERFACE_ID_HAS_SECONDARY_SALE)) {
            isSecondarySale = HasSecondarySale(auction.token).checkSecondarySale(auction.tokenId);
        } else if (auction.royaltyToken != address(0) && IERC165(auction.royaltyToken).supportsInterface(_INTERFACE_ID_ROYALTY_V2)) {
            isSecondarySale = HasSecondarySale(auction.royaltyToken).checkSecondarySale(auction.tokenId);
        }
        // Work out platform fee from above reserve amount
        uint256 totalServiceFee = highestBid.bidAmount.sub(highestBid.actualBidAmount).add(
            highestBid.actualBidAmount.mul(
                ServiceFeeProxy(serviceFeeProxy).getSellServiceFeeBps(auction.owner, isSecondarySale)
            ).div(10 ** 4)
        );

        // Send platform fee
        address payable serviceFeeRecipient = ServiceFeeProxy(serviceFeeProxy).getServiceFeeRecipient();
        bool platformTransferSuccess;
        bool ownerTransferSuccess;
        uint256 royalties;
        if (
            IERC165(auction.token).supportsInterface(_INTERFACE_ID_FEES)
            || IERC165(auction.token).supportsInterface(_INTERFACE_ID_ROYALTY)
            || IERC165(auction.token).supportsInterface(_INTERFACE_ID_ROYALTY_V2)
        ) {
            royalties = _payOutRoyaltiesByStrategy(
                auction.token,
                auction.tokenId,
                auction.payToken,
                address(this),
                highestBid.bidAmount.sub(totalServiceFee),
                isSecondarySale
            );
        } else if (auction.royaltyToken != address(0) && IERC165(auction.royaltyToken).supportsInterface(_INTERFACE_ID_ROYALTY_V2)) {
            require(
                IRoyalty(auction.royaltyToken).getTokenContract() == auction.token,
                "Auction: Royalty Token address does not match buy token"
            );
            royalties = _payOutRoyaltiesByStrategy(
                auction.royaltyToken,
                auction.tokenId,
                auction.payToken,
                address(this),
                highestBid.bidAmount.sub(totalServiceFee),
                isSecondarySale
            );
        }
        uint256 remain = highestBid.bidAmount.sub(totalServiceFee).sub(royalties);
        if (auction.payToken == address(0)) {
            (platformTransferSuccess,) =
            serviceFeeRecipient.call{value : totalServiceFee}("");
            // Send remaining to designer
            if (remain > 0) {
                (ownerTransferSuccess,) =
                auction.owner.call{
                value : remain
                }("");
            }
        } else {
            platformTransferSuccess = IBEP20(auction.payToken).transfer(serviceFeeRecipient, totalServiceFee);
            if (remain > 0) {
                ownerTransferSuccess = IBEP20(auction.payToken).transfer(auction.owner, remain);
            }
        }

        require(
            platformTransferSuccess,
            "Auction: Failed to send fee"
        );
        if (remain > 0) {
            require(
                ownerTransferSuccess,
                "Auction: Failed to send winning bid"
            );
        }
        // Transfer the token to the winner
        IERC721(auction.token).safeTransferFrom(auction.owner, highestBid.bidder, auction.tokenId);

        if (IERC165(auction.token).supportsInterface(_INTERFACE_ID_HAS_SECONDARY_SALE))
            HasSecondarySale(auction.token).setSecondarySale(auction.tokenId);

        if (auction.royaltyToken != address(0) && IERC165(auction.royaltyToken).supportsInterface(_INTERFACE_ID_HAS_SECONDARY_SALE))
            HasSecondarySale(auction.royaltyToken).setSecondarySale(auction.tokenId);

        // Refund bid amount to bidders who isn't the top unfortunately
        for (uint256 i = 0; i < bidList.length - 1; i++) {
            _refundBid(bidList[i].bidder, bidList[i].bidAmount, auction.payToken);
        }

        // Clean up the highest bid
        delete bids[_auctionId];
        delete auctions[_auctionId];

        emit AuctionResulted(
            _auctionId,
            auction.token,
            auction.tokenId,
            auction.payToken,
            highestBid.bidder,
            highestBid.bidAmount
        );
    }

    /**
     * @notice Cancels and inflight and un-resulted auctions, returning the funds to bidders if found
     * @dev Only admin
     * @param _auctionId Auction ID the id can be obtained from the getAuctionId function
     */
    function cancelAuction(bytes32 _auctionId)
    external
    nonReentrant
    onlyCreatedAuction(_auctionId)
    {
        Auction memory auction = auctions[_auctionId];

        require(
            isAdmin(msg.sender) || (auction.owner == msg.sender),
            "Auction: Only admin or auction owner can result the auction"
        );

        // refund bid amount to existing bidders
        BidLibrary.Bid[] storage bidList = bids[_auctionId];

        if (bidList.length > 0) {
            for (uint256 i = 0; i < bidList.length; i++) {
                _refundBid(bidList[i].bidder, bidList[i].bidAmount, auction.payToken);
            }
        }

        // Remove auction and bids
        delete bids[_auctionId];
        delete auctions[_auctionId];

        emit AuctionCancelled(_auctionId, auction.token, auction.tokenId);
    }

    /**
     * @notice Update the auction create time limit by which how far ahead can auctions be created
     * @dev Only admin
     * @param _auctionCreateTimeLimit New auction create time limit
     */
    function updateAuctionCreateTimeLimit(uint256 _auctionCreateTimeLimit)
    external
    onlyAdmin
    {
        auctionCreateTimeLimit = _auctionCreateTimeLimit;
        emit AuctionCreateTimeLimitUpdated(_auctionCreateTimeLimit);
    }

    /**
     * @notice Update the amount by which bids have to increase, across all auctions
     * @dev Only admin
     * @param _minBidIncrementBps New bid step in WEI
     */
    function updateMinBidIncrementBps(uint256 _minBidIncrementBps)
    external
    onlyAdmin
    {
        minBidIncrementBps = _minBidIncrementBps;
        emit MinBidIncrementBpsUpdated(_minBidIncrementBps);
    }

    /**
     * @notice Update the global max bid stack count
     * @dev Only admin
     * @param _maxBidStackCount max bid stack count
     */
    function updateMaxBidStackCount(uint256 _maxBidStackCount)
    external
    onlyAdmin
    {
        maxBidStackCount = _maxBidStackCount;
        emit MaxBidStackCountUpdated(_maxBidStackCount);
    }

    /**
     * @notice Update the global bid withdrawal lockout time
     * @dev Only admin
     * @param _bidWithdrawalLockTime New bid withdrawal lock time
     */
    function updateBidWithdrawalLockTime(uint256 _bidWithdrawalLockTime)
    external
    onlyAdmin
    {
        bidWithdrawalLockTime = _bidWithdrawalLockTime;
        emit BidWithdrawalLockTimeUpdated(_bidWithdrawalLockTime);
    }

    /**
     * @notice Update the current start time for an auction
     * @dev Only admin
     * @dev Auction must exist
     * @param _auctionId Auction ID the id can be obtained from the getAuctionId function
     * @param _startTime New start time (unix epoch in seconds)
     */
    function updateAuctionStartTime(bytes32 _auctionId, uint256 _startTime)
    external
    onlyAdmin
    onlyCreatedAuction(_auctionId)
    {
        auctions[_auctionId].startTime = _startTime;
        emit AuctionStartTimeUpdated(_auctionId, auctions[_auctionId].token, auctions[_auctionId].tokenId, _startTime);
    }

    /**
     * @notice Update the current end time for an auction
     * @dev Only admin
     * @dev Auction must exist
     * @param _auctionId Auction ID the id can be obtained from the getAuctionId function
     * @param _endTimestamp New end time (unix epoch in seconds)
     */
    function updateAuctionEndTime(bytes32 _auctionId, uint256 _endTimestamp)
    external
    onlyAdmin
    onlyCreatedAuction(_auctionId)
    {
        require(
            auctions[_auctionId].startTime < _endTimestamp && _endTimestamp > _getNow(),
            "Auction: Auction time is incorrect"
        );

        _updateAuctionEndTime(_auctionId, _endTimestamp);
    }

    /**
     * @notice Method for getting all info about the auction
     * @param _auctionId Auction ID the id can be obtained from the getAuctionId function
     */
    function getAuction(bytes32 _auctionId)
    external
    view
    returns (Auction memory)
    {
        return auctions[_auctionId];
    }

    /**
     * @notice Method for getting all info about the bids
     * @param _auctionId Auction ID the id can be obtained from the getAuctionId function
     */
    function getBidList(bytes32 _auctionId) public view returns (BidLibrary.Bid[] memory) {
        return bids[_auctionId];
    }

    /**
     * @notice Method for getting auction id to query the auctions mapping
     * @param _token Token Address that follows ERC1155 standard
     * @param _tokenId Token ID of the token being auctioned
     * @param _owner Owner address of the token Id
    */
    function getAuctionId(address _token, uint256 _tokenId, address _owner) public pure returns (bytes32) {
        return sha256(abi.encodePacked(_token, _tokenId, _owner));
    }

    /**
     * @notice Method for the block timestamp
    */
    function _getNow() internal view virtual returns (uint256) {
        return block.timestamp;
    }

    /**
     * @notice Used for sending back escrowed funds from a previous bid
     * @param _bidder Address of the last highest bidder
     * @param _bidAmount Ether amount in WEI that the bidder sent when placing their bid
     */
    function _refundBid(address payable _bidder, uint256 _bidAmount, address _payToken) private {
        // refund previous best (if bid exists)
        bool successRefund;
        if (_payToken == address(0)) {
            (successRefund,) = _bidder.call{value : _bidAmount}("");
        } else {
            successRefund = IBEP20(_payToken).transfer(_bidder, _bidAmount);
        }
        require(
            successRefund,
            "Auction: Failed to refund"
        );
        emit BidRefunded(_bidder, _bidAmount, _payToken);
    }

    /**
     * @notice Private method used for update auction end time
     * @param _auctionId Auction ID the id can be obtained from the getAuctionId function
     * @param _endTimestamp timestamp of end time
     */
    function _updateAuctionEndTime(bytes32 _auctionId, uint256 _endTimestamp) private {
        auctions[_auctionId].endTime = _endTimestamp;
        emit AuctionEndTimeUpdated(_auctionId, auctions[_auctionId].token, auctions[_auctionId].tokenId, _endTimestamp);
    }

    /**
     * @notice Toggling the pause of the contract
     * @dev Only admin
    */
    function toggleIsPaused() external onlyAdmin {
        isPaused = !isPaused;
        emit PauseToggled(isPaused);
    }

    /**
     * @notice Destroy the smart contract
     * @dev Only admin
     */
    function destroy() external onlyAdmin {
        address payable serviceFeeRecipient = ServiceFeeProxy(serviceFeeProxy).getServiceFeeRecipient();
        selfdestruct(serviceFeeRecipient);
        emit Destroy();
    }
}

File 83 of 104 : BidLibrary.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "../tge/interfaces/IBEP20.sol";

library BidLibrary {
    /// @notice Information about the sender that placed a bid on an auction
    struct Bid {
        address payable bidder;
        uint256 bidAmount;
        uint256 actualBidAmount;
        uint256 bidTime;
    }

    function removeByIndex(Bid[] storage _list, uint256 _index) internal {
        for (uint256 i = _index; i < _list.length - 1; i++) {
            _list[i] = _list[i + 1];
        }
        _list.pop();
    }
}

File 84 of 104 : ERC721AuctionMock.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "../ERC721Auction.sol";
import "../../managers/TradeTokenManager.sol";

/**
 * @notice Mock Contract of ERC721Auction
 */
contract ERC721AuctionMock is ERC721Auction {
    uint256 public fakeBlockTimeStamp = 100;

    /**
     * @notice Auction Constructor
     * @param _serviceFeeProxy service fee proxy
     */
    constructor(
        address _serviceFeeProxy,
        address _tradeTokenManager
    ) ERC721Auction(_serviceFeeProxy, _tradeTokenManager)
    public {}

    function setBlockTimeStamp(uint256 _now) external {
        fakeBlockTimeStamp = _now;
    }

    function _getNow() internal override view returns (uint256) {
        return fakeBlockTimeStamp;
    }
}

File 85 of 104 : RefinableToken.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.6.12;

import './interfaces/IBEP20.sol';
import './libs/SafeMath.sol';
import './libs/Context.sol';
import './libs/Ownable.sol';

contract RefinableToken is Context, IBEP20, Ownable {
  using SafeMath for uint256;

  mapping(address => uint256) private _balances;

  mapping(address => mapping(address => uint256)) private _allowances;

  uint256 private _totalSupply;
  uint8 public _decimals;
  string public _symbol;
  string public _name;

  constructor() public {
    _name = 'Refinable Token';
    _symbol = 'FINE';
    _decimals = 18;
    _totalSupply = 5 * 10**8 * 10**18; // 500m
    _balances[msg.sender] = _totalSupply;

    emit Transfer(address(0), msg.sender, _totalSupply);
  }

  /**
   * @dev Returns the bep token owner.
   */
  function getOwner() external view virtual override returns (address) {
    return owner();
  }

  /**
   * @dev Returns the token decimals.
   */
  function decimals() external view virtual override returns (uint8) {
    return _decimals;
  }

  /**
   * @dev Returns the token symbol.
   */
  function symbol() external view virtual override returns (string memory) {
    return _symbol;
  }

  /**
   * @dev Returns the token name.
   */
  function name() external view virtual override returns (string memory) {
    return _name;
  }

  /**
   * @dev See {BEP20-totalSupply}.
   */
  function totalSupply() external view virtual override returns (uint256) {
    return _totalSupply;
  }

  /**
   * @dev See {BEP20-balanceOf}.
   */
  function balanceOf(address account)
    external
    view
    virtual
    override
    returns (uint256)
  {
    return _balances[account];
  }

  /**
   * @dev See {BEP20-transfer}.
   *
   * Requirements:
   *
   * - `recipient` cannot be the zero address.
   * - the caller must have a balance of at least `amount`.
   */
  function transfer(address recipient, uint256 amount)
    external
    override
    returns (bool)
  {
    _transfer(_msgSender(), recipient, amount);
    return true;
  }

  /**
   * @dev See {BEP20-allowance}.
   */
  function allowance(address owner, address spender)
    external
    view
    override
    returns (uint256)
  {
    return _allowances[owner][spender];
  }

  /**
   * @dev See {BEP20-approve}.
   *
   * Requirements:
   *
   * - `spender` cannot be the zero address.
   */
  function approve(address spender, uint256 amount)
    external
    override
    returns (bool)
  {
    _approve(_msgSender(), spender, amount);
    return true;
  }

  /**
   * @dev See {BEP20-transferFrom}.
   *
   * Emits an {Approval} event indicating the updated allowance. This is not
   * required by the EIP. See the note at the beginning of {BEP20};
   *
   * Requirements:
   * - `sender` and `recipient` cannot be the zero address.
   * - `sender` must have a balance of at least `amount`.
   * - the caller must have allowance for `sender`'s tokens of at least
   * `amount`.
   */
  function transferFrom(
    address sender,
    address recipient,
    uint256 amount
  ) external override returns (bool) {
    _transfer(sender, recipient, amount);
    _approve(
      sender,
      _msgSender(),
      _allowances[sender][_msgSender()].sub(
        amount,
        'BEP20: transfer amount exceeds allowance'
      )
    );
    return true;
  }

  /**
   * @dev Atomically increases the allowance granted to `spender` by the caller.
   *
   * This is an alternative to {approve} that can be used as a mitigation for
   * problems described in {BEP20-approve}.
   *
   * Emits an {Approval} event indicating the updated allowance.
   *
   * Requirements:
   *
   * - `spender` cannot be the zero address.
   */
  function increaseAllowance(address spender, uint256 addedValue)
    public
    returns (bool)
  {
    _approve(
      _msgSender(),
      spender,
      _allowances[_msgSender()][spender].add(addedValue)
    );
    return true;
  }

  /**
   * @dev Atomically decreases the allowance granted to `spender` by the caller.
   *
   * This is an alternative to {approve} that can be used as a mitigation for
   * problems described in {BEP20-approve}.
   *
   * Emits an {Approval} event indicating the updated allowance.
   *
   * Requirements:
   *
   * - `spender` cannot be the zero address.
   * - `spender` must have allowance for the caller of at least
   * `subtractedValue`.
   */
  function decreaseAllowance(address spender, uint256 subtractedValue)
    public
    returns (bool)
  {
    _approve(
      _msgSender(),
      spender,
      _allowances[_msgSender()][spender].sub(
        subtractedValue,
        'BEP20: decreased allowance below zero'
      )
    );
    return true;
  }

  /**
   * @dev Destroys `amount` tokens from the caller.
   *
   * See {BEP20-_burn}.
   */
  function burn(uint256 amount) public virtual {
    _burn(_msgSender(), amount);
  }

  /**
   * @dev Destroys `amount` tokens from `account`, deducting from the caller's
   * allowance.
   *
   * See {BEP20-_burn} and {BEP20-allowance}.
   *
   * Requirements:
   *
   * - the caller must have allowance for ``accounts``'s tokens of at least
   * `amount`.
   */
  function burnFrom(address account, uint256 amount) public virtual {
    uint256 decreasedAllowance =
      _allowances[account][_msgSender()].sub(
        amount,
        'BEP20: burn amount exceeds allowance'
      );

    _approve(account, _msgSender(), decreasedAllowance);
    _burn(account, amount);
  }

  /**
   * @dev Moves tokens `amount` from `sender` to `recipient`.
   *
   * This is internal function is equivalent to {transfer}, and can be used to
   * e.g. implement automatic token fees, slashing mechanisms, etc.
   *
   * Emits a {Transfer} event.
   *
   * Requirements:
   *
   * - `sender` cannot be the zero address.
   * - `recipient` cannot be the zero address.
   * - `sender` must have a balance of at least `amount`.
   */
  function _transfer(
    address sender,
    address recipient,
    uint256 amount
  ) internal {
    require(sender != address(0), 'BEP20: transfer from the zero address');
    require(recipient != address(0), 'BEP20: transfer to the zero address');

    _balances[sender] = _balances[sender].sub(
      amount,
      'BEP20: transfer amount exceeds balance'
    );
    _balances[recipient] = _balances[recipient].add(amount);
    emit Transfer(sender, recipient, amount);
  }

  /**
   * @dev Destroys `amount` tokens from `account`, reducing the
   * total supply.
   *
   * Emits a {Transfer} event with `to` set to the zero address.
   *
   * Requirements
   *
   * - `account` cannot be the zero address.
   * - `account` must have at least `amount` tokens.
   */
  function _burn(address account, uint256 amount) internal {
    require(account != address(0), 'BEP20: burn from the zero address');

    _balances[account] = _balances[account].sub(
      amount,
      'BEP20: burn amount exceeds balance'
    );
    _totalSupply = _totalSupply.sub(amount);
    emit Transfer(account, address(0), amount);
  }

  /**
   * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
   *
   * This is internal function is equivalent to `approve`, and can be used to
   * e.g. set automatic allowances for certain subsystems, etc.
   *
   * Emits an {Approval} event.
   *
   * Requirements:
   *
   * - `owner` cannot be the zero address.
   * - `spender` cannot be the zero address.
   */
  function _approve(
    address owner,
    address spender,
    uint256 amount
  ) internal {
    require(owner != address(0), 'BEP20: approve from the zero address');
    require(spender != address(0), 'BEP20: approve to the zero address');

    _allowances[owner][spender] = amount;
    emit Approval(owner, spender, amount);
  }
}

File 86 of 104 : SafeMath.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.6.12;

/**
 * @dev Wrappers over Solidity's arithmetic operations with added overflow
 * checks.
 *
 * Arithmetic operations in Solidity wrap on overflow. This can easily result
 * in bugs, because programmers usually assume that an overflow raises an
 * error, which is the standard behavior in high level programming languages.
 * `SafeMath` restores this intuition by reverting the transaction when an
 * operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 */
library SafeMath {
  /**
   * @dev Returns the addition of two unsigned integers, reverting on
   * overflow.
   *
   * Counterpart to Solidity's `+` operator.
   *
   * Requirements:
   * - Addition cannot overflow.
   */
  function add(uint256 a, uint256 b) internal pure returns (uint256) {
    uint256 c = a + b;
    require(c >= a, 'SafeMath: addition overflow');

    return c;
  }

  /**
   * @dev Returns the subtraction of two unsigned integers, reverting on
   * overflow (when the result is negative).
   *
   * Counterpart to Solidity's `-` operator.
   *
   * Requirements:
   * - Subtraction cannot overflow.
   */
  function sub(uint256 a, uint256 b) internal pure returns (uint256) {
    return sub(a, b, 'SafeMath: subtraction overflow');
  }

  /**
   * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
   * overflow (when the result is negative).
   *
   * 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);
    uint256 c = a - b;

    return c;
  }

  /**
   * @dev Returns the multiplication of two unsigned integers, reverting on
   * overflow.
   *
   * Counterpart to Solidity's `*` operator.
   *
   * Requirements:
   * - Multiplication cannot overflow.
   */
  function mul(uint256 a, uint256 b) internal pure returns (uint256) {
    // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
    // benefit is lost if 'b' is also tested.
    // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
    if (a == 0) {
      return 0;
    }

    uint256 c = a * b;
    require(c / a == b, 'SafeMath: multiplication overflow');

    return c;
  }

  /**
   * @dev Returns the integer division of two unsigned integers. Reverts on
   * division by zero. The result is rounded towards zero.
   *
   * Counterpart to Solidity's `/` operator. Note: this function uses a
   * `revert` opcode (which leaves remaining gas untouched) while Solidity
   * uses an invalid opcode to revert (consuming all remaining gas).
   *
   * Requirements:
   * - The divisor cannot be zero.
   */
  function div(uint256 a, uint256 b) internal pure returns (uint256) {
    return div(a, b, 'SafeMath: division by zero');
  }

  /**
   * @dev Returns the integer division of two unsigned integers. Reverts with custom message 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,
    string memory errorMessage
  ) internal pure returns (uint256) {
    // Solidity only automatically asserts when dividing by 0
    require(b > 0, errorMessage);
    uint256 c = a / b;
    // assert(a == b * c + a % b); // There is no case in which this doesn't hold

    return c;
  }

  /**
   * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
   * Reverts when dividing by zero.
   *
   * Counterpart to Solidity's `%` operator. This function uses a `revert`
   * opcode (which leaves remaining gas untouched) while Solidity uses an
   * invalid opcode to revert (consuming all remaining gas).
   *
   * Requirements:
   * - The divisor cannot be zero.
   */
  function mod(uint256 a, uint256 b) internal pure returns (uint256) {
    return mod(a, b, 'SafeMath: modulo by zero');
  }

  /**
   * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
   * Reverts with custom message 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,
    string memory errorMessage
  ) internal pure returns (uint256) {
    require(b != 0, errorMessage);
    return a % b;
  }
}

File 87 of 104 : Context.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.6.12;

/*
 * @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) {
    return msg.sender;
  }

  function _msgData() internal view virtual returns (bytes calldata) {
    this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
    return msg.data;
  }
}

File 88 of 104 : Ownable.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.6.12;

import './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() public {
    address msgSender = _msgSender();
    _owner = msgSender;
    emit OwnershipTransferred(address(0), msgSender);
  }

  /**
   * @dev Returns the address of the current owner.
   */
  function owner() public view returns (address) {
    return _owner;
  }

  /**
   * @dev Throws if called by any account other than the owner.
   */
  modifier onlyOwner() {
    require(_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 onlyOwner {
    emit OwnershipTransferred(_owner, address(0));
    _owner = address(0);
  }

  /**
   * @dev Transfers ownership of the contract to a new account (`newOwner`).
   * Can only be called by the current owner.
   */
  function transferOwnership(address newOwner) public onlyOwner {
    _transferOwnership(newOwner);
  }

  /**
   * @dev Transfers ownership of the contract to a new account (`newOwner`).
   */
  function _transferOwnership(address newOwner) internal {
    require(newOwner != address(0), 'Ownable: new owner is the zero address');
    emit OwnershipTransferred(_owner, newOwner);
    _owner = newOwner;
  }
}

File 89 of 104 : Disperse.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.6.12;

import './tge/interfaces/IBEP20.sol';

contract Disperse {
  function disperseBNB(
    address payable[] calldata recipients,
    uint256[] calldata values
  ) external payable {
    for (uint256 i = 0; i < recipients.length; i++)
      recipients[i].transfer(values[i]);
    uint256 balance = address(this).balance;
    address payable change = payable(msg.sender);
    if (balance > 0) change.transfer(balance);
  }

  function disperseToken(
    IBEP20 token,
    address[] calldata recipients,
    uint256[] calldata values
  ) external {
    uint256 total = 0;
    for (uint256 i = 0; i < recipients.length; i++) total += values[i];
    require(token.transferFrom(msg.sender, address(this), total));
    for (uint256 i = 0; i < recipients.length; i++)
      require(token.transfer(recipients[i], values[i]));
  }

  function disperseTokenSimple(
    IBEP20 token,
    address[] calldata recipients,
    uint256[] calldata values
  ) external {
    for (uint256 i = 0; i < recipients.length; i++)
      require(token.transferFrom(msg.sender, recipients[i], values[i]));
  }
}

File 90 of 104 : ERC1155Auction.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/GSN/Context.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
import "../tge/interfaces/IBEP20.sol";
import "../proxy/ServiceFeeProxy.sol";
import "../roles/AdminRole.sol";
import "../libs/BidLibrary.sol";
import "../managers/TradeTokenManager.sol";
import "../managers/NftTokenManager.sol";
import "../service_fee/RoyaltiesStrategy.sol";
import "../interfaces/ICreator.sol";

/**
 * @notice Primary sale auction contract for Refinable NFTs
 */
contract ERC1155Auction is Context, ReentrancyGuard, AdminRole, RoyaltiesStrategy {
    using SafeMath for uint256;
    using Address for address payable;
    using BidLibrary for BidLibrary.Bid[];
    /// @notice Event emitted only on construction. To be used by indexers
    event AuctionContractDeployed();

    event PauseToggled(bool isPaused);

    event Destroy();

    event AuctionCreated(bytes32 auctionId, address token, uint256 indexed tokenId, address owner, address payToken);

    event AuctionCreateTimeLimitUpdated(uint256 auctionCreateTimeLimit);

    event AuctionEndTimeUpdated(bytes32 auctionId, address token, uint256 indexed tokenId, address owner, uint256 endTime);

    event AuctionStartTimeUpdated(bytes32 auctionId, address token, uint256 indexed tokenId, address owner, uint256 startTime);

    event MinBidIncrementBpsUpdated(uint256 minBidIncrementBps);

    event MaxBidStackCountUpdated(uint256 maxBidStackCount);

    event BidWithdrawalLockTimeUpdated(uint256 bidWithdrawalLockTime);

    event BidPlaced(
        bytes32 auctionId,
        address token,
        uint256 indexed tokenId,
        address owner,
        address payToken,
        address indexed bidder,
        uint256 bidAmount,
        uint256 actualBidAmount
    );

    event BidWithdrawn(
        bytes32 auctionId,
        address token,
        uint256 indexed tokenId,
        address owner,
        address payToken,
        address indexed bidder,
        uint256 bidAmount
    );

    event BidRefunded(
        address indexed bidder,
        uint256 bidAmount,
        address payToken
    );

    event AuctionResulted(
        bytes32 auctionId,
        address token,
        uint256 indexed tokenId,
        address owner,
        address payToken,
        address indexed winner,
        uint256 winningBidAmount
    );

    event AuctionCancelled(bytes32 auctionId, address token, uint256 indexed tokenId, address owner);

    /// @notice Parameters of an auction
    struct Auction {
        address token;
        address royaltyToken;
        uint256 tokenId;
        address owner;
        address payToken;
        uint256 startPrice;
        uint256 startTime;
        uint256 endTime;
        bool created;
    }

    address public serviceFeeProxy;

    address public tradeTokenManager;

    /// @notice ERC1155 Auction ID -> Auction Parameters
    mapping(bytes32 => Auction) public auctions;

    /// @notice ERC1155 Auction ID -> Bid Parameters
    mapping(bytes32 => BidLibrary.Bid[]) public bids;

    /// @notice globally and across all auctions, the amount by which a bid has to increase
    uint256 public minBidIncrementBps = 250;

    //@notice global auction create time limit
    uint256 public auctionCreateTimeLimit = 30 days;

    /// @notice global bid withdrawal lock time
    uint256 public bidWithdrawalLockTime = 3 days;

    /// @notice global limit time between bid time and auction end time
    uint256 public bidLimitBeforeEndTime = 5 minutes;

    /// @notice max bidders stack count
    uint256 public maxBidStackCount = 1;

    /// @notice for switching off auction creations, bids and withdrawals
    bool public isPaused;

    bytes4 private constant _INTERFACE_ID_ERC1155 = 0xd9b67a26;
    bytes4 private constant _INTERFACE_ID_FEES = 0xb7799584;
    bytes4 private constant _INTERFACE_ID_ROYALTY = 0x7b296bd9;
    bytes4 private constant _INTERFACE_ID_ROYALTY_V2 = 0x9e4a83d4;

    modifier whenNotPaused() {
        require(!isPaused, "Auction: Function is currently paused");
        _;
    }

    modifier onlyCreatedAuction(bytes32 _auctionId) {
        require(
            auctions[_auctionId].created == true,
            "Auction: Auction does not exist"
        );
        _;
    }

    /**
     * @notice Auction Constructor
    * @param _serviceFeeProxy service fee proxy
     */
    constructor(
        address _serviceFeeProxy,
        address _tradeTokenManager
    ) public {
        serviceFeeProxy = _serviceFeeProxy;
        tradeTokenManager = _tradeTokenManager;
        _setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
        emit AuctionContractDeployed();
    }

    /**
     * @notice Creates a new auction for a given token
     * @dev Only the owner of a token can create an auction and must have approved the contract
     * @dev End time for the auction must be in the future.
     * @param _token Token Address that follows ERC1155 standard
     * @param _tokenId Token ID of the token being auctioned
     * @param _startPrice Starting bid price of the token being auctioned
     * @param _startTimestamp Unix epoch in seconds for the auction start time
     * @param _endTimestamp Unix epoch in seconds for the auction end time.
     */
    function createAuction(
        address _token,
        address _royaltyToken,
        uint256 _tokenId,
        address _payToken,
        uint256 _startPrice,
        uint256 _startTimestamp,
        uint256 _endTimestamp
    ) external whenNotPaused {
        require(
            _startTimestamp <= _getNow().add(auctionCreateTimeLimit),
            "Auction: Exceed auction start time limit"
        );
        require(
            IERC1155(_token).supportsInterface(_INTERFACE_ID_ERC1155),
            "Auction: Invalid NFT"
        );

        if (_royaltyToken != address(0)) {
            require(
                IERC1155(_royaltyToken).supportsInterface(_INTERFACE_ID_ROYALTY_V2),
                "Auction: Invalid royalty contract"
            );
            require(
                IRoyalty(_royaltyToken).getTokenContract() == _token,
                "Auction: Royalty Token address does not match buy token"
            );
        }

        // Check owner has token and approved
        require(
            IERC1155(_token).balanceOf(msg.sender, _tokenId) > 0,
            "Auction: Caller does not have the token"
        );
        require(
            IERC1155(_token).isApprovedForAll(_msgSender(), address(this)),
            "Auction: Owner has not approved"
        );

        if (_payToken != address(0)) {
            require(
                TradeTokenManager(tradeTokenManager).supportToken(_payToken) == true,
                "Auction: Pay Token is not allowed"
            );
        }

        bytes32 auctionId = getAuctionId(_token, _tokenId, msg.sender);

        // Check the auction already created, can only list 1 token at a time
        require(
            auctions[auctionId].created == false,
            "Auction: Auction has been already created"
        );
        // Check end time not before start time and that end is in the future
        require(
            _endTimestamp > _startTimestamp && _endTimestamp > _getNow(),
            "Auction: Auction time is incorrect"
        );

        // Setup the auction
        auctions[auctionId] = Auction({
        token : _token,
        royaltyToken : _royaltyToken,
        tokenId : _tokenId,
        owner : msg.sender,
        payToken : _payToken,
        startPrice : _startPrice,
        startTime : _startTimestamp,
        endTime : _endTimestamp,
        created : true
        });

        emit AuctionCreated(auctionId, _token, _tokenId, msg.sender, _payToken);
    }

    /**
     * @notice Places a new bid, out bidding the existing bidder if found and criteria is reached
     * @dev Only callable when the auction is open
     * @dev Bids from smart contracts are prohibited to prevent griefing with always reverting receiver
     * @param _auctionId Auction ID the id can be obtained from the getAuctionId function
     */
    function placeBid(bytes32 _auctionId)
    external
    payable
    nonReentrant
    whenNotPaused
    onlyCreatedAuction(_auctionId)
    {
        require(
            _msgSender().isContract() == false,
            "Auction: No contracts permitted"
        );

        // Ensure auction is in flight
        require(
            _getNow() >= auctions[_auctionId].startTime && _getNow() <= auctions[_auctionId].endTime,
            "Auction: Bidding outside of the auction window"
        );

        uint256 bidAmount;

        if (auctions[_auctionId].payToken == address(0)) {
            bidAmount = msg.value;
        } else {
            bidAmount = IBEP20(auctions[_auctionId].payToken).allowance(msg.sender, address(this));
            require(
                IBEP20(auctions[_auctionId].payToken).transferFrom(msg.sender, address(this), bidAmount) == true,
                "Auction: Token transfer failed"
            );
        }

        // Ensure bid adheres to outbid increment and threshold
        uint256 actualBidAmount = bidAmount.mul(10 ** 4).div(ServiceFeeProxy(serviceFeeProxy).getBuyServiceFeeBps(msg.sender).add(10 ** 4));
        uint256 minBidRequired;
        BidLibrary.Bid[] storage bidList = bids[_auctionId];

        if (bidList.length != 0) {
            minBidRequired =
            bidList[bidList.length - 1].actualBidAmount.mul(minBidIncrementBps.add(10 ** 4)).div(10 ** 4);
        } else {
            minBidRequired = auctions[_auctionId].startPrice;
        }

        require(
            actualBidAmount >= minBidRequired,
            "Auction: Failed to outbid min price"
        );

        // assign top bidder and bid time
        BidLibrary.Bid memory newHighestBid = BidLibrary.Bid({
        bidder : _msgSender(),
        bidAmount : bidAmount,
        actualBidAmount : actualBidAmount,
        bidTime : _getNow()
        });

        bidList.push(newHighestBid);

        //Refund old bid if bidlist overflows thans max bid stack count
        if (bidList.length > maxBidStackCount) {
            BidLibrary.Bid memory oldBid = bidList[0];
            if (oldBid.bidder != address(0)) {
                _refundBid(oldBid.bidder, oldBid.bidAmount, auctions[_auctionId].payToken);
            }

            bidList.removeByIndex(0);
        }

        //Increase auction end time if bid time is within 5 mins after auction end time
        if (auctions[_auctionId].endTime <= newHighestBid.bidTime.add(bidLimitBeforeEndTime)) {
            _updateAuctionEndTime(_auctionId, auctions[_auctionId].endTime.add(bidLimitBeforeEndTime));
        }

        emit BidPlaced(
            _auctionId,
            auctions[_auctionId].token,
            auctions[_auctionId].tokenId,
            auctions[_auctionId].owner,
            auctions[_auctionId].payToken,
            _msgSender(),
            bidAmount,
            actualBidAmount
        );
    }

    /**
     * @notice Given a sender who is in the bid list of auction, allows them to withdraw their bid
     * @dev Only callable by the existing top bidder
     * @param _auctionId Auction ID the id can be obtained from the getAuctionId function
     */
    function withdrawBid(bytes32 _auctionId)
    external
    nonReentrant
    whenNotPaused
    onlyCreatedAuction(_auctionId)
    {
        BidLibrary.Bid[] storage bidList = bids[_auctionId];
        require(bidList.length > 0, "Auction: There is no bid");

        uint256 withdrawIndex = bidList.length;
        for (uint256 i = 0; i < bidList.length; i++) {
            if (bidList[i].bidder == _msgSender()) {
                withdrawIndex = i;
            }
        }

        require(withdrawIndex != bidList.length, "Auction: Caller is not bidder");

        BidLibrary.Bid storage withdrawableBid = bidList[withdrawIndex];

        // Check withdrawal after delay time
        require(
            _getNow() >= auctions[_auctionId].endTime.add(bidWithdrawalLockTime),
            "Auction: Cannot withdraw until auction ends"
        );

        if (withdrawableBid.bidder != address(0)) {
            _refundBid(withdrawableBid.bidder, withdrawableBid.bidAmount, auctions[_auctionId].payToken);
        }

        bidList.removeByIndex(withdrawIndex);

        emit BidWithdrawn(
            _auctionId,
            auctions[_auctionId].token,
            auctions[_auctionId].tokenId,
            auctions[_auctionId].owner,
            auctions[_auctionId].payToken,
            _msgSender(),
            withdrawableBid.bidAmount
        );
    }

    /**
     * @notice Results a finished auction
     * @dev Only admin or smart contract
     * @dev Auction can only be resulted if there has been a bidder and reserve met.
     * @dev If there have been no bids, the auction needs to be cancelled instead using `cancelAuction()`
     * @param _auctionId Auction ID the id can be obtained from the getAuctionId function
     */
    function endAuction(bytes32 _auctionId)
    external
    nonReentrant
    onlyCreatedAuction(_auctionId)
    {
        Auction memory auction = auctions[_auctionId];

        require(
            isAdmin(msg.sender) || (auction.owner == msg.sender),
            "Auction: Only admin or auction owner can result the auction"
        );

        // Check the auction has ended
        require(
            _getNow() > auction.endTime,
            "Auction: Auction has not ended"
        );

        // Ensure this contract is approved to move the token
        require(
            IERC1155(auction.token).isApprovedForAll(auction.owner, address(this)),
            "Auction: Auction not approved"
        );

        // Get info on who the highest bidder is
        BidLibrary.Bid[] storage bidList = bids[_auctionId];

        require(bidList.length > 0, "Auction: There is no bid");

        BidLibrary.Bid memory highestBid = bidList[bidList.length - 1];

        // Send platform fee
        address payable serviceFeeRecipient = ServiceFeeProxy(serviceFeeProxy).getServiceFeeRecipient();
        bool platformTransferSuccess;
        bool ownerTransferSuccess;

        uint256 totalServiceFee;
        uint256 royalties;
        if (
            IERC165(auction.token).supportsInterface(_INTERFACE_ID_FEES)
            || IERC165(auction.token).supportsInterface(_INTERFACE_ID_ROYALTY)
            || IERC165(auction.token).supportsInterface(_INTERFACE_ID_ROYALTY_V2)
        ) {
            bool isSecondarySale = _isSecondarySale(auction.token, auction.tokenId, auction.owner);
            // Work out platform fee from above reserve amount
            totalServiceFee = highestBid.bidAmount.sub(highestBid.actualBidAmount).add(
                highestBid.actualBidAmount.mul(
                    ServiceFeeProxy(serviceFeeProxy).getSellServiceFeeBps(auction.owner, isSecondarySale)
                ).div(10 ** 4)
            );
            royalties = _payOutRoyaltiesByStrategy(
                auction.token,
                auction.tokenId,
                auction.payToken,
                address(this),
                highestBid.bidAmount.sub(totalServiceFee),
                isSecondarySale
            );
        } else if (auction.royaltyToken != address(0) && IERC165(auction.royaltyToken).supportsInterface(_INTERFACE_ID_ROYALTY_V2)) {
            require(
                IRoyalty(auction.royaltyToken).getTokenContract() == auction.token,
                "Auction: Royalty Token address does not match buy token"
            );
            bool isSecondarySale = _isSecondarySale(auction.royaltyToken, auction.tokenId, auction.owner);
            // Work out platform fee from above reserve amount
            totalServiceFee = highestBid.bidAmount.sub(highestBid.actualBidAmount).add(
                highestBid.actualBidAmount.mul(
                    ServiceFeeProxy(serviceFeeProxy).getSellServiceFeeBps(auction.owner, isSecondarySale)
                ).div(10 ** 4)
            );
            royalties = _payOutRoyaltiesByStrategy(
                auction.royaltyToken,
                auction.tokenId,
                auction.payToken,
                address(this),
                highestBid.bidAmount.sub(totalServiceFee),
                isSecondarySale
            );
        } else {
            totalServiceFee = highestBid.bidAmount.sub(highestBid.actualBidAmount).add(
                highestBid.actualBidAmount.mul(
                    ServiceFeeProxy(serviceFeeProxy).getSellServiceFeeBps(auction.owner, true)
                ).div(10 ** 4)
            );
        }

        uint256 remain = highestBid.bidAmount.sub(totalServiceFee).sub(royalties);
        if (auction.payToken == address(0)) {
            (platformTransferSuccess,) =
            serviceFeeRecipient.call{value : totalServiceFee}("");
            // Send remaining to designer
            if (remain > 0) {
                (ownerTransferSuccess,) =
                auction.owner.call{
                value : remain
                }("");
            }
        } else {
            platformTransferSuccess = IBEP20(auction.payToken).transfer(serviceFeeRecipient, totalServiceFee);
            if (remain > 0) {
                ownerTransferSuccess = IBEP20(auction.payToken).transfer(auction.owner, remain);
            }
        }
        require(
            platformTransferSuccess,
            "Auction: Failed to send fee"
        );
        if (remain > 0) {
            require(
                ownerTransferSuccess,
                "Auction: Failed to send winning bid"
            );
        }

        // Transfer the token to the winner
        IERC1155(auction.token).safeTransferFrom(auction.owner, highestBid.bidder, auction.tokenId, 1, "");

        // Refund bid amount to bidders who isn't the top unfortunately
        for (uint256 i = 0; i < bidList.length - 1; i++) {
            _refundBid(bidList[i].bidder, bidList[i].bidAmount, auction.payToken);
        }

        // Remove auction and bids
        delete bids[_auctionId];
        delete auctions[_auctionId];

        emit AuctionResulted(
            _auctionId,
            auction.token,
            auction.tokenId,
            auction.owner,
            auction.payToken,
            highestBid.bidder,
            highestBid.bidAmount
        );
    }

    /**
     * @notice Cancels and inflight and un-resulted auctions, returning the funds to bidders if found
     * @dev Only admin
     * @param _auctionId Auction ID the id can be obtained from the getAuctionId function
     */
    function cancelAuction(bytes32 _auctionId)
    external
    nonReentrant
    onlyCreatedAuction(_auctionId)
    {
        Auction memory auction = auctions[_auctionId];

        require(
            isAdmin(msg.sender) || (auction.owner == msg.sender),
            "Auction: Only admin or auction owner can result the auction"
        );

        // refund bid amount to existing bidders
        BidLibrary.Bid[] storage bidList = bids[_auctionId];

        if (bidList.length > 0) {
            for (uint256 i = 0; i < bidList.length; i++) {
                _refundBid(bidList[i].bidder, bidList[i].bidAmount, auction.payToken);
            }
        }

        // Remove auction and bids
        delete bids[_auctionId];
        delete auctions[_auctionId];

        emit AuctionCancelled(_auctionId, auction.token, auction.tokenId, auction.owner);
    }

    /**
     * @notice Update the amount by which bids have to increase, across all auctions
     * @dev Only admin
     * @param _minBidIncrementBps New bid step in WEI
     */
    function updateMinBidIncrementBps(uint256 _minBidIncrementBps)
    external
    onlyAdmin
    {
        minBidIncrementBps = _minBidIncrementBps;
        emit MinBidIncrementBpsUpdated(_minBidIncrementBps);
    }

    /**
     * @notice Update the auction create time limit by which how far ahead can auctions be created
     * @dev Only admin
     * @param _auctionCreateTimeLimit New auction create time limit
     */
    function updateAuctionCreateTimeLimit(uint256 _auctionCreateTimeLimit)
    external
    onlyAdmin
    {
        auctionCreateTimeLimit = _auctionCreateTimeLimit;
        emit AuctionCreateTimeLimitUpdated(_auctionCreateTimeLimit);
    }

    /**
     * @notice Update the global max bid stack count
     * @dev Only admin
     * @param _maxBidStackCount max bid stack count
     */
    function updateMaxBidStackCount(uint256 _maxBidStackCount)
    external
    onlyAdmin
    {
        maxBidStackCount = _maxBidStackCount;
        emit MaxBidStackCountUpdated(_maxBidStackCount);
    }

    /**
     * @notice Update the global bid withdrawal lockout time
     * @dev Only admin
     * @param _bidWithdrawalLockTime New bid withdrawal lock time
     */
    function updateBidWithdrawalLockTime(uint256 _bidWithdrawalLockTime)
    external
    onlyAdmin
    {
        bidWithdrawalLockTime = _bidWithdrawalLockTime;
        emit BidWithdrawalLockTimeUpdated(_bidWithdrawalLockTime);
    }

    /**
     * @notice Update the current start time for an auction
     * @dev Only admin
     * @dev Auction must exist
     * @param _auctionId Auction ID the id can be obtained from the getAuctionId function
     * @param _startTime New start time (unix epoch in seconds)
     */
    function updateAuctionStartTime(bytes32 _auctionId, uint256 _startTime)
    external
    onlyAdmin
    onlyCreatedAuction(_auctionId)
    {
        auctions[_auctionId].startTime = _startTime;
        emit AuctionStartTimeUpdated(_auctionId, auctions[_auctionId].token, auctions[_auctionId].tokenId, auctions[_auctionId].owner, _startTime);
    }

    /**
     * @notice Update the current end time for an auction
     * @dev Only admin
     * @dev Auction must exist
     * @param _auctionId Auction ID the id can be obtained from the getAuctionId function
     * @param _endTimestamp New end time (unix epoch in seconds)
     */
    function updateAuctionEndTime(bytes32 _auctionId, uint256 _endTimestamp)
    external
    onlyAdmin
    onlyCreatedAuction(_auctionId)
    {
        require(
            auctions[_auctionId].startTime < _endTimestamp && _endTimestamp > _getNow(),
            "Auction: Auction time is incorrect"
        );

        _updateAuctionEndTime(_auctionId, _endTimestamp);
    }

    /**
     * @notice Method for getting all info about the auction
     * @param _auctionId Auction ID the id can be obtained from the getAuctionId function
     */
    function getAuction(bytes32 _auctionId)
    external
    view
    returns (Auction memory)
    {
        return auctions[_auctionId];
    }

    /**
     * @notice Method for getting all info about the bids
     * @param _auctionId Auction ID the id can be obtained from the getAuctionId function
     */
    function getBidList(bytes32 _auctionId) public view returns (BidLibrary.Bid[] memory) {
        return bids[_auctionId];
    }

    /**
     * @notice Method for getting auction id to query the auctions mapping
     * @param _token Token Address that follows ERC1155 standard
     * @param _tokenId Token ID of the token being auctioned
     * @param _owner Owner address of the token Id
    */
    function getAuctionId(address _token, uint256 _tokenId, address _owner) public pure returns (bytes32) {
        return sha256(abi.encodePacked(_token, _tokenId, _owner));
    }

    /**
     * @notice Method for the block timestamp
    */
    function _getNow() internal view virtual returns (uint256) {
        return block.timestamp;
    }

    function _isSecondarySale(address _token, uint256 _tokenId, address _seller) internal returns (bool){
        if (IERC165(_token).supportsInterface(type(ICreator).interfaceId)) {
            address creator = ICreator(_token).getCreator(_tokenId);
            return (creator != _seller);
        } else {
            return true;
        }
    }

    /**
     * @notice Private method used for sending back escrowed funds from a previous bid
     * @param _bidder Address of the last highest bidder
     * @param _bidAmount Ether amount in WEI that the bidder sent when placing their bid
     */
    function _refundBid(address payable _bidder, uint256 _bidAmount, address _payToken) private {
        // refund previous best (if bid exists)
        bool successRefund;
        if (_payToken == address(0)) {
            (successRefund,) = _bidder.call{value : _bidAmount}("");
        } else {
            successRefund = IBEP20(_payToken).transfer(_bidder, _bidAmount);
        }
        require(
            successRefund,
            "Auction: Failed to refund"
        );
        emit BidRefunded(_bidder, _bidAmount, _payToken);
    }

    /**
     * @notice Private method used for update auction end time
     * @param _auctionId Auction ID the id can be obtained from the getAuctionId function
     * @param _endTimestamp timestamp of end time
     */
    function _updateAuctionEndTime(bytes32 _auctionId, uint256 _endTimestamp) private {
        auctions[_auctionId].endTime = _endTimestamp;
        emit AuctionEndTimeUpdated(_auctionId, auctions[_auctionId].token, auctions[_auctionId].tokenId, auctions[_auctionId].owner, _endTimestamp);
    }

    /**
     * @notice Toggling the pause of the contract
     * @dev Only admin
    */
    function toggleIsPaused() external onlyAdmin {
        isPaused = !isPaused;
        emit PauseToggled(isPaused);
    }

    /**
     * @notice Destroy the smart contract
     * @dev Only admin
     */
    function destroy() external onlyAdmin {
        address payable serviceFeeRecipient = ServiceFeeProxy(serviceFeeProxy).getServiceFeeRecipient();
        selfdestruct(serviceFeeRecipient);
        emit Destroy();
    }
}

File 91 of 104 : ERC1155AuctionMock.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "../ERC1155Auction.sol";

/**
 * @notice Mock Contract of ERC1155Auction
 */
contract ERC1155AuctionMock is ERC1155Auction {
    uint256 public fakeBlockTimeStamp = 100;

    /**
     * @notice Auction Constructor
     * @param _serviceFeeProxy service fee proxy
     */
    constructor(
        address _serviceFeeProxy,
        address _tradeTokenManager
    ) ERC1155Auction(_serviceFeeProxy, _tradeTokenManager)
    public {}

    function setBlockTimeStamp(uint256 _now) external {
        fakeBlockTimeStamp = _now;
    }

    function _getNow() internal override view returns (uint256) {
        return fakeBlockTimeStamp;
    }
}

File 92 of 104 : ServiceFeeMatic.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "../interfaces/IRefinableToken.sol";
import "../interfaces/IServiceFee.sol";

/**
 * @notice Service Fee contract for Refinable NFT Marketplace
 */
contract ServiceFeeMatic is AccessControl, IServiceFee {
    using Address for address;

    /// @notice service fee contract
    IRefinableToken public refinableTokenContract;

    bytes32 public constant PROXY_ROLE = keccak256("PROXY_ROLE");

    /// @notice Service fee recipient address
    address payable public serviceFeeRecipient;

    event ServiceFeeRecipientChanged(address payable serviceFeeRecipient);

    event RefinableTokenContractUpdated(address refinableTokenContract);

    modifier onlyAdmin() {
        require(
            hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
            "Ownable: caller is not the admin"
        );
        _;
    }

    modifier onlyProxy() {
        require(
            hasRole(PROXY_ROLE, _msgSender()),
            "Ownable: caller is not the proxy"
        );
        _;
    }

    /**
     * @dev Constructor Function
    */
    constructor() public {
        require(
            _msgSender() != address(0),
            "Auction: Invalid Platform Fee Recipient"
        );

        _setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
    }

    /**
     * @notice Lets admin set the refinable token contract
     * @param _refinableTokenContract address of refinable token contract
     */
    function setRefinableTokenContract(address _refinableTokenContract) onlyAdmin external override {
        require(
            _refinableTokenContract != address(0),
            "ServiceFee.setRefinableTokenContract: Zero address"
        );
        refinableTokenContract = IRefinableToken(_refinableTokenContract);
        emit RefinableTokenContractUpdated(_refinableTokenContract);
    }

    /**
     * @notice Admin can add proxy address
     * @param _proxyAddr address of proxy
     */
    function addProxy(address _proxyAddr) onlyAdmin external override {
        require(
            _proxyAddr.isContract(),
            "ServiceFee.addProxy: address is not a contract address"
        );
        grantRole(PROXY_ROLE, _proxyAddr);
    }

    /**
     * @notice Admin can remove proxy address
     * @param _proxyAddr address of proxy
     */
    function removeProxy(address _proxyAddr) onlyAdmin external override{
        require(
            _proxyAddr.isContract(),
            "ServiceFee.removeProxy: address is not a contract address"
        );
        revokeRole(PROXY_ROLE, _proxyAddr);
    }

    /**
     * @notice Calculate the seller service fee in according to the business logic and returns it
     * @param _seller address of seller
     * @param _isSecondarySale sale is primary or secondary
     */
    function getSellServiceFeeBps(address _seller, bool _isSecondarySale) external view onlyProxy override returns (uint256) {
        require(
            _seller != address(0),
            "ServiceFee.getSellServiceFeeBps: Zero address"
        );

        // We cannot check the FINE balance since it's not deployed to Matic yet. Everything is set to 1.5% for now.
        // TODO: Add the bridge token so the service fee can check FINE balance on Matic

        //        uint256 balance = refinableTokenContract.balanceOf(_seller);
        
//        if(_isSecondarySale) {
//            if(balance >= 10000 * 10 ** 18)
//                return 150;
//            else if(balance >= 2500 * 10 ** 18)
//                return 175;
//            else if(balance >= 250 * 10 ** 18)
//                return 200;
//            else if(balance >= 20 * 10 ** 18)
//                return 225;
//        } else {
//            if(balance >= 250 * 10 ** 18)
//                return 200;
//            else if(balance >= 20 * 10 ** 18)
//                return 225;
//        }
        return 150;
    }

    /**
     * @notice Calculate the buyer service fee in according to the business logic and returns it
     * @param _buyer address of buyer
     */
    function getBuyServiceFeeBps(address _buyer) onlyProxy external view override returns (uint256) {
        require(
            _buyer != address(0),
            "ServiceFee.getBuyServiceFeeBps: Zero address"
        );
//        uint256 balance = refinableTokenContract.balanceOf(_buyer);
//
//        if(balance >= 10000 * 10 ** 18)
//            return 150;
//        else if(balance >= 2500 * 10 ** 18)
//            return 175;
//        else if(balance >= 250 * 10 ** 18)
//            return 200;
//        else if(balance >= 20 * 10 ** 18)
//            return 225;
        return 0;
    }

    /**
     * @notice Get service fee recipient address
     */
    function getServiceFeeRecipient() onlyProxy external view override returns (address payable) {
        return serviceFeeRecipient;
    }

    /**
     * @notice Set service fee recipient address
     * @param _serviceFeeRecipient address of recipient
     */
    function setServiceFeeRecipient(address payable _serviceFeeRecipient) onlyProxy external override {
        require(
            _serviceFeeRecipient != address(0),
            "ServiceFee.setServiceFeeRecipient: Zero address"
        );

        serviceFeeRecipient = _serviceFeeRecipient;
        emit ServiceFeeRecipientChanged(_serviceFeeRecipient);
    }
}

File 93 of 104 : IRefinableToken.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.6.12;

interface IRefinableToken {

  /**
   * @dev Returns the bep token owner.
   */
  function getOwner() external view returns (address);

  /**
   * @dev Returns the token decimals.
   */
  function decimals() external view returns (uint8);

  /**
   * @dev Returns the token symbol.
   */
  function symbol() external view returns (string memory);

  /**
   * @dev Returns the token name.
   */
  function name() external view returns (string memory);

  /**
   * @dev See {BEP20-totalSupply}.
   */
  function totalSupply() external view returns (uint256);

  /**
   * @dev See {BEP20-balanceOf}.
   */
  function balanceOf(address account)
    external
    view
    returns (uint256);

  /**
   * @dev See {BEP20-transfer}.
   *
   * Requirements:
   *
   * - `recipient` cannot be the zero address.
   * - the caller must have a balance of at least `amount`.
   */
  function transfer(address recipient, uint256 amount)
    external
    returns (bool);

  /**
   * @dev See {BEP20-allowance}.
   */
  function allowance(address owner, address spender)
    external
    view
    returns (uint256);

  /**
   * @dev See {BEP20-approve}.
   *
   * Requirements:
   *
   * - `spender` cannot be the zero address.
   */
  function approve(address spender, uint256 amount)
    external
    returns (bool);

  /**
   * @dev See {BEP20-transferFrom}.
   *
   * Emits an {Approval} event indicating the updated allowance. This is not
   * required by the EIP. See the note at the beginning of {BEP20};
   *
   * Requirements:
   * - `sender` and `recipient` cannot be the zero address.
   * - `sender` must have a balance of at least `amount`.
   * - the caller must have allowance for `sender`'s tokens of at least
   * `amount`.
   */
  function transferFrom(
    address sender,
    address recipient,
    uint256 amount
  ) external returns (bool);
}

File 94 of 104 : ServiceFee.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "../interfaces/IRefinableToken.sol";
import "../interfaces/IServiceFee.sol";

/**
 * @notice Service Fee contract for Refinable NFT Marketplace
 */
contract ServiceFee is AccessControl, IServiceFee {
    using Address for address;

    /// @notice service fee contract
    IRefinableToken public refinableTokenContract;

    bytes32 public constant PROXY_ROLE = keccak256("PROXY_ROLE");

    /// @notice Service fee recipient address
    address payable public serviceFeeRecipient;

    event ServiceFeeRecipientChanged(address payable serviceFeeRecipient);

    event RefinableTokenContractUpdated(address refinableTokenContract);

    modifier onlyAdmin() {
        require(
            hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
            "Ownable: caller is not the admin"
        );
        _;
    }

    modifier onlyProxy() {
        require(
            hasRole(PROXY_ROLE, _msgSender()),
            "Ownable: caller is not the proxy"
        );
        _;
    }

    /**
     * @dev Constructor Function
    */
    constructor() public {
        require(
            _msgSender() != address(0),
            "Auction: Invalid Platform Fee Recipient"
        );

        _setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
    }

    /**
     * @notice Lets admin set the refinable token contract
     * @param _refinableTokenContract address of refinable token contract
     */
    function setRefinableTokenContract(address _refinableTokenContract) onlyAdmin external override {
        require(
            _refinableTokenContract != address(0),
            "ServiceFee.setRefinableTokenContract: Zero address"
        );
        refinableTokenContract = IRefinableToken(_refinableTokenContract);
        emit RefinableTokenContractUpdated(_refinableTokenContract);
    }

    /**
     * @notice Admin can add proxy address
     * @param _proxyAddr address of proxy
     */
    function addProxy(address _proxyAddr) onlyAdmin external override {
        require(
            _proxyAddr.isContract(),
            "ServiceFee.addProxy: address is not a contract address"
        );
        grantRole(PROXY_ROLE, _proxyAddr);
    }

    /**
     * @notice Admin can remove proxy address
     * @param _proxyAddr address of proxy
     */
    function removeProxy(address _proxyAddr) onlyAdmin external override{
        require(
            _proxyAddr.isContract(),
            "ServiceFee.removeProxy: address is not a contract address"
        );
        revokeRole(PROXY_ROLE, _proxyAddr);
    }

    /**
     * @notice Calculate the seller service fee in according to the business logic and returns it
     * @param _seller address of seller
     * @param _isSecondarySale sale is primary or secondary
     */
    function getSellServiceFeeBps(address _seller, bool _isSecondarySale) external view onlyProxy override returns (uint256) {
        require(
            _seller != address(0),
            "ServiceFee.getSellServiceFeeBps: Zero address"
        );

        uint256 balance = refinableTokenContract.balanceOf(_seller);

        if(_isSecondarySale) {
            if(balance >= 10000 * 10 ** 18)
                return 150;
            else if(balance >= 2500 * 10 ** 18)
                return 175;
            else if(balance >= 250 * 10 ** 18)
                return 200;
            else if(balance >= 20 * 10 ** 18)
                return 225;
        } else {
            if(balance >= 250 * 10 ** 18)
                return 200;
            else if(balance >= 20 * 10 ** 18)
                return 225;
        }
        return 250;
    }

    /**
     * @notice Calculate the buyer service fee in according to the business logic and returns it
     * @param _buyer address of buyer
     */
    function getBuyServiceFeeBps(address _buyer) onlyProxy external view override returns (uint256) {
        require(
            _buyer != address(0),
            "ServiceFee.getBuyServiceFeeBps: Zero address"
        );
        uint256 balance = refinableTokenContract.balanceOf(_buyer);

        if(balance >= 10000 * 10 ** 18)
            return 150;
        else if(balance >= 2500 * 10 ** 18)
            return 175;
        else if(balance >= 250 * 10 ** 18)
            return 200;
        else if(balance >= 20 * 10 ** 18)
            return 225;
        return 250;
    }

    /**
     * @notice Get service fee recipient address
     */
    function getServiceFeeRecipient() onlyProxy external view override returns (address payable) {
        return serviceFeeRecipient;
    }

    /**
     * @notice Set service fee recipient address
     * @param _serviceFeeRecipient address of recipient
     */
    function setServiceFeeRecipient(address payable _serviceFeeRecipient) onlyProxy external override {
        require(
            _serviceFeeRecipient != address(0),
            "ServiceFee.setServiceFeeRecipient: Zero address"
        );

        serviceFeeRecipient = _serviceFeeRecipient;
        emit ServiceFeeRecipientChanged(_serviceFeeRecipient);
    }
}

File 95 of 104 : RefinableERC721WhiteListedTokenV2.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/cryptography/ECDSA.sol";
import "./ERC721BaseV2.sol";
/**
 * @title RefinableERC721TokenWhiteListed
 * @dev only minters can mint token.

 */
contract RefinableERC721WhiteListedTokenV2 is ERC721BaseV2 {
    using ECDSA for bytes32;

    address payable public defaultRoyaltyReceiver = address(0);
    uint256 public defaultRoyaltyReceiverBps = 0;

    /**
     * @dev Constructor Function
     * @param _name name of the token ex: Rarible
     * @param _symbol symbol of the token ex: RARI
     * @param _root address of admin account
     * @param _signer address of signer account
     * @param _contractURI URI of contract ex: https://api-mainnet.rarible.com/contractMetadata/{address}
     * @param _baseURI ex: https://ipfs.daonomic.com
    */
    constructor(
        string memory _name,
        string memory _symbol,
        address _root,
        address _signer,
        string memory _contractURI,
        string memory _baseURI
    ) public ERC721BaseV2(_name, _symbol, _contractURI, _baseURI) {
        addAdmin(_root);
        addSigner(_signer);
    }

    function mint(
        uint256 _tokenId,
        bytes memory _signature,
        RoyaltyLibrary.RoyaltyShareDetails[] memory _royaltyShares,
        string memory _uri,
        uint256 _royaltyBps,
        RoyaltyLibrary.Strategy _royaltyStrategy
    ) public onlyMinter {
        require(
            isSigner(
                keccak256(abi.encodePacked(address(this), _tokenId, msg.sender)).toEthSignedMessageHash().recover(_signature)
            ),
            "invalid signer"
        );
        RoyaltyLibrary.RoyaltyShareDetails[] memory newRoyaltyShares;

        //add the default royalties if the contract has set
        if (defaultRoyaltyReceiver != address(0) && defaultRoyaltyReceiverBps != 0) {
            newRoyaltyShares = new RoyaltyLibrary.RoyaltyShareDetails[](_royaltyShares.length + 1);
            for (uint256 i = 0; i < _royaltyShares.length; i++) {
                newRoyaltyShares[i] = _royaltyShares[i];
            }
            newRoyaltyShares[_royaltyShares.length] = RoyaltyLibrary.RoyaltyShareDetails({
            recipient : defaultRoyaltyReceiver,
            value : defaultRoyaltyReceiverBps
            });
        } else {
            newRoyaltyShares = _royaltyShares;
        }

        _mint(msg.sender, _tokenId, newRoyaltyShares, _uri, _royaltyBps, _royaltyStrategy);
    }

    function setDefaultRoyaltyReceiver(address payable _receiver) public onlyAdmin {
        defaultRoyaltyReceiver = _receiver;
    }

    function setDefaultRoyaltyReceiverBps(uint256 _bps) public onlyAdmin {
        require(_bps <= 10**4, "ERC721: Fee bps should not exceed 10000");
        defaultRoyaltyReceiverBps = _bps;
    }
}

File 96 of 104 : RefinableERC721TokenV2.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/cryptography/ECDSA.sol";
import "./ERC721BaseV2.sol";

/**
 * @title RefinableERC721Token
 * @dev anyone can mint token.
 */
contract RefinableERC721TokenV2 is ERC721BaseV2 {
    using ECDSA for bytes32;

    /**
     * @dev Constructor Function
     * @param _name name of the token ex: Rarible
     * @param _symbol symbol of the token ex: RARI
     * @param _root address of admin account
     * @param _signer address of signer account
     * @param _contractURI URI of contract ex: https://api-mainnet.rarible.com/contractMetadata/{address}
     * @param _baseURI ex: https://ipfs.daonomic.com
    */
    constructor(
        string memory _name,
        string memory _symbol,
        address _root,
        address _signer,
        string memory _contractURI,
        string memory _baseURI
    ) public ERC721BaseV2(_name, _symbol, _contractURI, _baseURI) {
        addAdmin(_root);
        addSigner(_signer);
    }

    function mint(
        uint256 _tokenId,
        bytes memory _signature,
        RoyaltyLibrary.RoyaltyShareDetails[] memory _royaltyShares,
        string memory _uri,
        uint256 _royaltyBps,
        RoyaltyLibrary.Strategy _royaltyStrategy
    ) public {
        require(
            isSigner(
                keccak256(abi.encodePacked(address(this), _tokenId, msg.sender))
                .toEthSignedMessageHash()
                .recover(_signature)
            ),
            "invalid signer"
        );
        _mint(msg.sender, _tokenId, _royaltyShares, _uri, _royaltyBps, _royaltyStrategy);
    }
}

File 97 of 104 : ERC721AirdropMatic.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/GSN/Context.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";

/**
 * @notice Airdrop contract for Refinable NFT Marketplace
 */
contract ERC721AirdropMatic is Context, ReentrancyGuard {

    /// @notice ERC721 NFT
    IERC721 public token;

    event AirdropContractDeployed();
    event AirdropFinished(
        uint256[] tokenIds,
        address[] recipients
    );

    /**
     * @dev Constructor Function
    */
    constructor(
        IERC721 _token
    ) public {
        require(address(_token) != address(0), "Invalid NFT");

        token = _token;

        emit AirdropContractDeployed();
    }

    /**
     * @dev Owner of token can airdrop tokens to recipients
     * @param _tokenIds array of token id
     * @param _recipients addresses of recipients
     */
    function airdrop(IERC721 _token, uint256[] memory _tokenIds, address[] memory _recipients) external nonReentrant {
        require(
            _token == token,
            "ERC721Airdrop: Token is not allowed"
        );
        require(
            _recipients.length == _tokenIds.length,
            "ERC721Airdrop: Count of recipients should be same as count of token ids"
        );

        for (uint256 i = 0; i < _tokenIds.length; i++) {
            require(
                _token.ownerOf(_tokenIds[i]) == _msgSender(),
                "ERC721Airdrop: Caller is not the owner"
            );
        }

        require(
            _token.isApprovedForAll(_msgSender(), address(this)),
            "ERC721Airdrop: Owner has not approved"
        );

        for (uint256 i = 0; i < _tokenIds.length; i++) {
            _token.safeTransferFrom(_msgSender(), _recipients[i], _tokenIds[i]);
        }

        emit AirdropFinished(_tokenIds, _recipients);
    }
}

File 98 of 104 : IRefinableERC721Token.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/token/ERC721/IERC721.sol";

/**
 * @title RefinableERC721Token Interface
 */
interface IRefinableERC721Token is IERC721 {
    struct Fee {
        address payable recipient;
        uint256 value;
    }

    function mint(
        uint256 _tokenId,
        bytes memory _signature,
        Fee[] memory _fees,
        string memory _tokenURI
    ) external;

    function setBaseURI(string memory _baseURI) external;

    function setContractURI(string memory _contractURI) external;
}

File 99 of 104 : RefinableNFTFactory.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "../interfaces/IRefinableERC721Token.sol";
import "../interfaces/IRefinableERC1155Token.sol";
import "../libs/Ownable.sol";

/**
 * @title RefinableNFTFactory Contract
 */
contract RefinableNFTFactory is Ownable
{
    /// @notice Event emitted only on construction. To be used by indexers
    event RefinableNFTFactoryContractDeployed();

    event ERC721TokenBulkMinted(
        address indexed minter,
        uint256[] tokenIds,
        IRefinableERC721Token.Fee[][] fees,
        string[] tokenURIs
    );

    /// @notice Max bulk mint count
    uint256 public maxBulkCount = 100;

    /// @notice RefinableERC721 Token
    IRefinableERC721Token public refinableERC721Token;

    /// @notice RefinableERC1155 Token
    IRefinableERC1155Token public refinableERC1155Token;

    /**
     * @notice Auction Constructor
     * @param _refinableERC721Token RefinableERC721Token Interface
     * @param _refinableERC1155Token RefinableERC1155Token Interface
     */
    constructor(
        IRefinableERC721Token _refinableERC721Token,
        IRefinableERC1155Token _refinableERC1155Token
    ) public {
        require(
            address(_refinableERC721Token) != address(0),
            "Invalid NFT"
        );

        require(
            address(_refinableERC1155Token) != address(0),
            "Invalid NFT"
        );

        refinableERC721Token = _refinableERC721Token;
        refinableERC1155Token = _refinableERC1155Token;

        emit RefinableNFTFactoryContractDeployed();
    }

    function bulk_mint_erc721_token(
        uint256[] memory _tokenIds,
        bytes[] memory _signatures,
        IRefinableERC721Token.Fee[][] memory _fees,
        string[] memory _tokenURIs
    ) public onlyOwner {
        require(
            _tokenIds.length > 0,
            "Empty array is provided"
        );

        require(
            _tokenIds.length < maxBulkCount,
            "Too big array is provided"
        );

        require(
            _tokenIds.length == _signatures.length && _signatures.length == _fees.length && _fees.length == _tokenURIs.length,
            "Size of params are not same"
        );

        for(uint256 i = 0; i < _tokenIds.length; i++) {
            refinableERC721Token.mint(_tokenIds[i], _signatures[i], _fees[i],  _tokenURIs[i]);
            refinableERC721Token.safeTransferFrom(address(this), msg.sender, _tokenIds[i]);
        }

        emit ERC721TokenBulkMinted(msg.sender, _tokenIds, _fees, _tokenURIs);
    }
}

File 100 of 104 : IRefinableERC1155Token.sol
pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;
// SPDX-License-Identifier: UNLICENSED

/**
 * @title RefinableERC1155Token Interface
 */
interface IRefinableERC1155Token {
    struct Fee {
        address payable recipient;
        uint256 value;
    }

    function mint(uint256 _tokenId, bytes memory _signature, Fee[] memory _fees, uint256 _supply, string memory _uri) external;
}

File 101 of 104 : ERC721Airdrop.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/GSN/Context.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";

/**
 * @notice Airdrop contract for Refinable NFT Marketplace
 */
contract ERC721Airdrop is Context, ReentrancyGuard {

    /// @notice ERC721 NFT
    IERC721 public token;
    IERC721 public tokenV2;

    event AirdropContractDeployed();
    event AirdropFinished(
        uint256[] tokenIds,
        address[] recipients
    );

    /**
     * @dev Constructor Function
    */
    constructor(
        IERC721 _token,
        IERC721 _tokenV2
    ) public {
        require(address(_token) != address(0), "Invalid NFT");
        require(address(_tokenV2) != address(0), "Invalid NFT");

        token = _token;
        tokenV2 = _tokenV2;

        emit AirdropContractDeployed();
    }

    /**
     * @dev Owner of token can airdrop tokens to recipients
     * @param _tokenIds array of token id
     * @param _recipients addresses of recipients
     */
    function airdrop(IERC721 _token, uint256[] memory _tokenIds, address[] memory _recipients) external nonReentrant {
        require(
            _token == token || _token == tokenV2,
            "ERC721Airdrop: Token is not allowed"
        );
        require(
            _recipients.length == _tokenIds.length,
            "ERC721Airdrop: Count of recipients should be same as count of token ids"
        );

        for (uint256 i = 0; i < _tokenIds.length; i++) {
            require(
                _token.ownerOf(_tokenIds[i]) == _msgSender(),
                "ERC721Airdrop: Caller is not the owner"
            );
        }

        require(
            _token.isApprovedForAll(_msgSender(), address(this)),
            "ERC721Airdrop: Owner has not approved"
        );

        for (uint256 i = 0; i < _tokenIds.length; i++) {
            _token.safeTransferFrom(_msgSender(), _recipients[i], _tokenIds[i]);
        }

        emit AirdropFinished(_tokenIds, _recipients);
    }
}

File 102 of 104 : ERC1155AirdropMatic.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
import "@openzeppelin/contracts/GSN/Context.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";

/**
 * @notice Airdrop contract for Refinable NFT Marketplace
 */
contract ERC1155AirdropMatic is Context, ReentrancyGuard {

    /// @notice ERC1155 NFT
    IERC1155 public token;

    event AirdropContractDeployed();
    event AirdropFinished(
        uint256 tokenId,
        address[] recipients
    );

    /**
     * @dev Constructor Function
    */
    constructor(
        IERC1155 _token
    ) public {
        require(address(_token) != address(0), "Invalid NFT");

        token = _token;

        emit AirdropContractDeployed();
    }

    /**
     * @dev Owner of token can airdrop tokens to recipients
     * @param _tokenId id of the token
     * @param _recipients addresses of recipients
     */
    function airdrop(IERC1155 _token, uint256 _tokenId, address[] memory _recipients) external nonReentrant {
        require(
            _token == token,
            "ERC1155Airdrop: Token is not allowed"
        );
        require(
            _token.balanceOf(_msgSender(), _tokenId) >= _recipients.length,
            "ERC1155Airdrop: Caller does not have amount of tokens"
        );
        require(
            _token.isApprovedForAll(_msgSender(), address(this)),
            "ERC1155Airdrop: Owner has not approved"
        );

        for (uint256 i = 0; i < _recipients.length; i++) {
            _token.safeTransferFrom(_msgSender(), _recipients[i], _tokenId, 1, "");
        }

        emit AirdropFinished(_tokenId, _recipients);
    }
}

File 103 of 104 : DAFERC721WhiteListedTokenV3.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/cryptography/ECDSA.sol";
import "../ERC721BaseV3.sol";
/**
 * @title RefinableERC721TokenWhiteListed
 * @dev only minters can mint token.

 */
contract DAFERC721WhiteListedTokenV3 is ERC721BaseV3 {
    using ECDSA for bytes32;

    address payable public defaultRoyaltyReceiver = address(0);
    uint256 public defaultRoyaltyReceiverBps = 0;

    /**
     * @dev Constructor Function
     * @param _name name of the token ex: Rarible
     * @param _symbol symbol of the token ex: RARI
     * @param _root address of admin account
     * @param _signer address of signer account
     * @param _contractURI URI of contract ex: https://api-mainnet.rarible.com/contractMetadata/{address}
     * @param _baseURI ex: https://ipfs.daonomic.com
    */
    constructor(
        string memory _name,
        string memory _symbol,
        address _root,
        address _signer,
        string memory _contractURI,
        string memory _baseURI
    ) public ERC721BaseV3(_name, _symbol, _contractURI, _baseURI) {
        addAdmin(_root);
        addSigner(_signer);
    }

    function mint(
        uint256 _tokenId,
        bytes memory _signature,
        RoyaltyLibrary.RoyaltyShareDetails[] memory _royaltyShares,
        string memory _uri,
        uint256 _royaltyBps,
        RoyaltyLibrary.Strategy _royaltyStrategy,
        RoyaltyLibrary.RoyaltyShareDetails[] memory _primaryRoyaltyShares
    ) public onlyMinter {
        require(
            isSigner(
                keccak256(abi.encodePacked(address(this), _tokenId, msg.sender)).toEthSignedMessageHash().recover(_signature)
            ),
            "invalid signer"
        );

        RoyaltyLibrary.RoyaltyShareDetails[] memory defaultPrimaryRoyaltyShares = new RoyaltyLibrary.RoyaltyShareDetails[](1);
        if (defaultRoyaltyReceiver != address(0) && defaultRoyaltyReceiverBps != 0)
            defaultPrimaryRoyaltyShares[0] = RoyaltyLibrary.RoyaltyShareDetails({
            recipient : defaultRoyaltyReceiver,
            value : defaultRoyaltyReceiverBps
            });
        _mint(msg.sender, _tokenId, _royaltyShares, _uri, _royaltyBps, RoyaltyLibrary.Strategy.PRIMARY_SALE_STRATEGY, defaultPrimaryRoyaltyShares);
    }

    function setDefaultRoyaltyReceiver(address payable _receiver) public onlyAdmin {
        defaultRoyaltyReceiver = _receiver;
    }

    function setDefaultRoyaltyReceiverBps(uint256 _bps) public onlyAdmin {
        require(_bps <= 10 ** 4, "ERC721: Fee bps should not exceed 10000");
        defaultRoyaltyReceiverBps = _bps;
    }
}

File 104 of 104 : CoralERC721WhiteListedTokenV3.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/cryptography/ECDSA.sol";
import "../ERC721BaseV3.sol";
/**
 * @title RefinableERC721TokenWhiteListed
 * @dev only minters can mint token.

 */
contract CoralERC721WhiteListedTokenV3 is ERC721BaseV3 {
    using ECDSA for bytes32;

    RoyaltyLibrary.RoyaltyShareDetails[] public defaultPrimaryRoyaltyReceivers;

    /**
     * @dev Constructor Function
     * @param _name name of the token ex: Rarible
     * @param _symbol symbol of the token ex: RARI
     * @param _root address of admin account
     * @param _signer address of signer account
     * @param _contractURI URI of contract ex: https://api-mainnet.rarible.com/contractMetadata/{address}
     * @param _baseURI ex: https://ipfs.daonomic.com
    */
    constructor(
        string memory _name,
        string memory _symbol,
        address _root,
        address _signer,
        string memory _contractURI,
        string memory _baseURI
    ) public ERC721BaseV3(_name, _symbol, _contractURI, _baseURI) {
        addAdmin(_root);
        addSigner(_signer);
    }

    function mint(
        uint256 _tokenId,
        bytes memory _signature,
        RoyaltyLibrary.RoyaltyShareDetails[] memory _royaltyShares,
        string memory _uri,
        uint256 _royaltyBps,
        RoyaltyLibrary.Strategy _royaltyStrategy,
        RoyaltyLibrary.RoyaltyShareDetails[] memory _primaryRoyaltyShares
    ) public onlyMinter {
        require(
            isSigner(
                keccak256(abi.encodePacked(address(this), _tokenId, msg.sender)).toEthSignedMessageHash().recover(_signature)
            ),
            "invalid signer"
        );

        _mint(msg.sender, _tokenId, _royaltyShares, _uri, _royaltyBps, RoyaltyLibrary.Strategy.PRIMARY_SALE_STRATEGY, defaultPrimaryRoyaltyReceivers);
    }

    function setPrimaryDefaultRoyaltyReceivers(RoyaltyLibrary.RoyaltyShareDetails[] memory _receivers) public onlyAdmin {
        delete defaultPrimaryRoyaltyReceivers;
        for (uint256 i = 0; i < _receivers.length; i++) {
            defaultPrimaryRoyaltyReceivers.push(_receivers[i]);
        }
    }
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "metadata": {
    "useLiteralContent": true
  },
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"address","name":"_root","type":"address"},{"internalType":"address","name":"_signer","type":"address"},{"internalType":"string","name":"_contractURI","type":"string"},{"internalType":"string","name":"_baseURI","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"address[]","name":"recipients","type":"address[]"},{"indexed":false,"internalType":"uint256[]","name":"bp","type":"uint256[]"}],"name":"SetPrimaryRoyaltyShares","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"},{"indexed":false,"internalType":"enum RoyaltyLibrary.Strategy","name":"strategy","type":"uint8"}],"name":"SetRoyalty","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"address[]","name":"recipients","type":"address[]"},{"indexed":false,"internalType":"uint256[]","name":"bp","type":"uint256[]"}],"name":"SetRoyaltyShares","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MINTER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SIGNER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"addAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"addMinter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_accounts","type":"address[]"}],"name":"addMinterBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"addSigner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"baseURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"burn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"checkSecondarySale","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"contractURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"defaultRoyaltyReceiver","outputs":[{"internalType":"address payable","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"defaultRoyaltyReceiverBps","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"getCreator","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"getPrimaryRoyaltyShares","outputs":[{"components":[{"internalType":"address payable","name":"recipient","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"internalType":"struct RoyaltyLibrary.RoyaltyShareDetails[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getRoleMember","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleMemberCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"getRoyalty","outputs":[{"components":[{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"enum RoyaltyLibrary.Strategy","name":"strategy","type":"uint8"}],"internalType":"struct RoyaltyLibrary.RoyaltyInfo","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"getRoyaltyShares","outputs":[{"components":[{"internalType":"address payable","name":"recipient","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"internalType":"struct RoyaltyLibrary.RoyaltyShareDetails[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTokenContract","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"isSecondarySale","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"bytes","name":"_signature","type":"bytes"},{"components":[{"internalType":"address payable","name":"recipient","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"internalType":"struct RoyaltyLibrary.RoyaltyShareDetails[]","name":"_royaltyShares","type":"tuple[]"},{"internalType":"string","name":"_uri","type":"string"},{"internalType":"uint256","name":"_royaltyBps","type":"uint256"},{"internalType":"enum RoyaltyLibrary.Strategy","name":"_royaltyStrategy","type":"uint8"},{"components":[{"internalType":"address payable","name":"recipient","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"internalType":"struct RoyaltyLibrary.RoyaltyShareDetails[]","name":"_primaryRoyaltyShares","type":"tuple[]"}],"name":"mint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"_tokenIds","type":"uint256[]"},{"internalType":"bytes[]","name":"_signatures","type":"bytes[]"},{"components":[{"internalType":"address payable","name":"recipient","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"internalType":"struct RoyaltyLibrary.RoyaltyShareDetails[]","name":"_royaltyShares","type":"tuple[]"},{"internalType":"string[]","name":"_uris","type":"string[]"},{"internalType":"uint256","name":"_royaltyBps","type":"uint256"},{"internalType":"enum RoyaltyLibrary.Strategy","name":"_royaltyStrategy","type":"uint8"},{"components":[{"internalType":"address payable","name":"recipient","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"internalType":"struct RoyaltyLibrary.RoyaltyShareDetails[]","name":"_primaryRoyaltyShares","type":"tuple[]"}],"name":"mintSimilarBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"removeAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"removeMinter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"removeSigner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"royalty","outputs":[{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"enum RoyaltyLibrary.Strategy","name":"strategy","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"royaltyShares","outputs":[{"internalType":"address payable","name":"recipient","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_baseURI","type":"string"}],"name":"setBaseURI","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_contractURI","type":"string"}],"name":"setContractURI","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"_receiver","type":"address"}],"name":"setDefaultRoyaltyReceiver","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_bps","type":"uint256"}],"name":"setDefaultRoyaltyReceiverBps","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"setSecondarySale","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"tokenByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"tokenOfOwnerByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"}]

60806040526064601055601280546001600160a01b031916905560006013553480156200002b57600080fd5b5060405162004a6538038062004a658339810160408190526200004e91620005a9565b85858383838383620000676301ffc9a760e01b6200019c565b62000079632aca9c0560e11b6200019c565b80516200008e9060019060208401906200044e565b50620000a163e8a3d48560e01b6200019c565b508151620000b79060079060208501906200044e565b508051620000cd9060089060208401906200044e565b50620000e06380ac58cd60e01b6200019c565b620000f2635b5e139f60e01b6200019c565b6200010463780e9d6360e01b6200019c565b506200011d9050600062000117620001f7565b620001fb565b6200012f632792a0f560e21b6200019c565b620001416320b029a560e01b6200019c565b62000153636a4731c560e11b6200019c565b620001656371b921f960e11b6200019c565b62000170816200020b565b5050505062000185846200022060201b60201c565b620001908362000263565b5050505050506200073e565b6001600160e01b03198082161415620001d25760405162461bcd60e51b8152600401620001c990620006d2565b60405180910390fd5b6001600160e01b0319166000908152602081905260409020805460ff19166001179055565b3390565b620002078282620002bc565b5050565b80516200020790600a9060208401906200044e565b620002346200022e620001f7565b62000337565b620002535760405162461bcd60e51b8152600401620001c99062000709565b62000260600082620001fb565b50565b620002716200022e620001f7565b620002905760405162461bcd60e51b8152600401620001c99062000709565b620002607fe2f4eaae4a9751e85a3e4a7b9587827a877f29914755229b07a7b2da98285f70826200034b565b6000828152600b60209081526040909120620002e39183906200160362000391821b17901c565b156200020757620002f3620001f7565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000620003458183620003af565b92915050565b6000828152600b602052604090206002015462000372906200036c620001f7565b620003af565b620001fb5760405162461bcd60e51b8152600401620001c99062000683565b6000620003a8836001600160a01b038416620003d5565b9392505050565b6000828152600b602090815260408220620003a89184906200161862000424821b17901c565b6000620003e3838362000436565b6200041b5750815460018181018455600084815260208082209093018490558454848252828601909352604090209190915562000345565b50600062000345565b6000620003a8836001600160a01b0384165b60009081526001919091016020526040902054151590565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106200049157805160ff1916838001178555620004c1565b82800160010185558215620004c1579182015b82811115620004c1578251825591602001919060010190620004a4565b50620004cf929150620004d3565b5090565b5b80821115620004cf5760008155600101620004d4565b80516001600160a01b03811681146200034557600080fd5b600082601f83011262000513578081fd5b81516001600160401b03808211156200052a578283fd5b6040516020601f8401601f19168201810183811183821017156200054c578586fd5b806040525081945083825286818588010111156200056957600080fd5b600092505b838310156200058d57858301810151828401820152918201916200056e565b838311156200059f5760008185840101525b5050505092915050565b60008060008060008060c08789031215620005c2578182fd5b86516001600160401b0380821115620005d9578384fd5b620005e78a838b0162000502565b97506020890151915080821115620005fd578384fd5b6200060b8a838b0162000502565b96506200061c8a60408b01620004ea565b95506200062d8a60608b01620004ea565b9450608089015191508082111562000643578384fd5b620006518a838b0162000502565b935060a089015191508082111562000667578283fd5b506200067689828a0162000502565b9150509295509295509295565b6020808252602f908201527f416363657373436f6e74726f6c3a2073656e646572206d75737420626520616e60408201526e0818591b5a5b881d1bc819dc985b9d608a1b606082015260800190565b6020808252601c908201527f4552433136353a20696e76616c696420696e7465726661636520696400000000604082015260600190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f74207468652061646d696e604082015260600190565b614317806200074e6000396000f3fe608060405234801561001057600080fd5b50600436106103425760003560e01c806370480275116101b8578063ac04f24311610104578063d5391393116100a2578063e814cb711161007c578063e814cb71146106f6578063e8a3d48514610717578063e985e9c51461071f578063eb12d61e1461073257610342565b8063d5391393146106d3578063d547741f146106db578063e461aa23146106ee57610342565b8063c87b56dd116100de578063c87b56dd14610687578063ca15c8731461069a578063d48e638a146106ad578063d4e6b3c4146106c057610342565b8063ac04f2431461064e578063b88d4fde14610661578063b9d4949d1461067457610342565b806393c3f80b11610171578063a000429e1161014b578063a000429e1461060a578063a1ebf35d1461062b578063a217fddf14610633578063a22cb4651461063b57610342565b806393c3f80b146105dc57806395d89b41146105ef578063983b2d56146105f757610342565b8063704802751461057557806370a082311461058857806380b11f1b1461059b5780639010d07c146105a357806391d14854146105b6578063938e3d7b146105c957610342565b806328b7bede1161029257806342966c68116102305780635b1d0f4d1161020a5780635b1d0f4d146105345780635b45a13c146105475780636352211e1461055a5780636c0360eb1461056d57610342565b806342966c68146104fb5780634f6ccce71461050e57806355f804b31461052157610342565b80633092afd51161026c5780633092afd5146104af57806336568abe146104c25780633ebc82c5146104d557806342842e0e146104e857610342565b806328b7bede146104815780632f2ff15d146104895780632f745c591461049c57610342565b80631785f53c116102ff57806320b029a5116102d957806320b029a51461042857806323b872dd1461044857806323c969711461045b578063248a9ca31461046e57610342565b80631785f53c146103e057806318160ddd146103f35780631af9cf491461040857610342565b806301ffc9a71461034757806306fdde0314610370578063081812fc14610385578063095ea7b3146103a55780630e316ab7146103ba5780630e883747146103cd575b600080fd5b61035a610355366004613190565b610745565b60405161036791906134de565b60405180910390f35b610378610768565b6040516103679190613510565b610398610393366004613133565b6107fe565b6040516103679190613369565b6103b86103b3366004612f8b565b61084a565b005b6103b86103c8366004612e5d565b6108e2565b61035a6103db366004613133565b610929565b6103b86103ee366004612e5d565b61093e565b6103fb610970565b60405161036791906134e9565b61041b610416366004613133565b610981565b6040516103679190614161565b61043b610436366004613133565b6109d3565b6040516103679190613486565b6103b8610456366004612eb1565b610a5b565b6103b8610469366004612fb6565b610a93565b6103fb61047c366004613133565b610afd565b610398610b12565b6103b861049736600461314b565b610b16565b6103fb6104aa366004612f8b565b610b5a565b6103b86104bd366004612e5d565b610b85565b6103b86104d036600461314b565b610bc4565b6103b86104e3366004612e5d565b610c06565b6103b86104f6366004612eb1565b610c4f565b6103b8610509366004613133565b610c6a565b6103fb61051c366004613133565b610c9a565b6103b861052f3660046131c8565b610cb0565b6103b8610542366004613133565b610ce0565b6103b86105553660046131fa565b610cfb565b610398610568366004613133565b610e2f565b610378610e57565b6103b8610583366004612e5d565b610eb8565b6103fb610596366004612e5d565b610eea565b6103fb610f33565b6103986105b136600461316f565b610f39565b61035a6105c436600461314b565b610f51565b6103b86105d73660046131c8565b610f69565b6103b86105ea366004613133565b610f99565b610378610fe7565b6103b8610605366004612e5d565b611048565b61061d61061836600461316f565b611087565b6040516103679291906133b0565b6103fb6110ca565b6103fb6110dc565b6103b8610649366004612f5a565b6110e1565b61043b61065c366004613133565b6111af565b6103b861066f366004612ef1565b611222565b6103b861068236600461304d565b611261565b610378610695366004613133565b611305565b6103fb6106a8366004613133565b61144b565b6103986106bb366004613133565b611462565b61035a6106ce366004613133565b61147d565b6103fb611492565b6103b86106e936600461314b565b6114a4565b6103986114de565b610709610704366004613133565b6114ed565b604051610367929190614183565b610378611509565b61035a61072d366004612e79565b611596565b6103b8610740366004612e5d565b6115c4565b6001600160e01b0319811660009081526020819052604090205460ff165b919050565b60078054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156107f45780601f106107c9576101008083540402835291602001916107f4565b820191906000526020600020905b8154815290600101906020018083116107d757829003601f168201915b5050505050905090565b60006108098261162d565b61082e5760405162461bcd60e51b815260040161082590613ce4565b60405180910390fd5b506000908152600560205260409020546001600160a01b031690565b600061085582610e2f565b9050806001600160a01b0316836001600160a01b031614156108895760405162461bcd60e51b815260040161082590613e14565b806001600160a01b031661089b61163a565b6001600160a01b031614806108b757506108b78161072d61163a565b6108d35760405162461bcd60e51b815260040161082590613a2f565b6108dd838361163e565b505050565b6108f26108ed61163a565b6116ac565b61090e5760405162461bcd60e51b815260040161082590613b7a565b6109266000805160206142a2833981519152826114a4565b50565b60009081526011602052604090205460ff1690565b6109496108ed61163a565b6109655760405162461bcd60e51b815260040161082590613b7a565b6109266000826114a4565b600061097c60036116b8565b905090565b610989612b90565b6000828152600c60209081526040918290208251808401909352805483526001810154909183019060ff1660028111156109bf57fe5b60028111156109ca57fe5b90525092915050565b6060600f6000838152602001908152602001600020805480602002602001604051908101604052809291908181526020016000905b82821015610a50576000848152602090819020604080518082019091526002850290910180546001600160a01b03168252600190810154828401529083529092019101610a08565b505050509050919050565b610a6c610a6661163a565b826116c3565b610a885760405162461bcd60e51b815260040161082590613e96565b6108dd838383611748565b610a9e6108ed61163a565b610aba5760405162461bcd60e51b815260040161082590613b7a565b60005b8151811015610af957610af16000805160206142c2833981519152838381518110610ae457fe5b6020026020010151610b50565b600101610abd565b5050565b6000908152600b602052604090206002015490565b3090565b6000828152600b6020526040902060020154610b34906105c461163a565b610b505760405162461bcd60e51b81526004016108259061359c565b610af98282611856565b6001600160a01b0382166000908152600260205260408120610b7c90836118bf565b90505b92915050565b610b906108ed61163a565b610bac5760405162461bcd60e51b815260040161082590613b7a565b6109266000805160206142c2833981519152826114a4565b610bcc61163a565b6001600160a01b0316816001600160a01b031614610bfc5760405162461bcd60e51b815260040161082590614112565b610af982826118cb565b610c116108ed61163a565b610c2d5760405162461bcd60e51b815260040161082590613b7a565b601280546001600160a01b0319166001600160a01b0392909216919091179055565b6108dd83838360405180602001604052806000815250611222565b610c75610a6661163a565b610c915760405162461bcd60e51b81526004016108259061402e565b61092681611934565b600080610ca8600384611a01565b509392505050565b610cbb6108ed61163a565b610cd75760405162461bcd60e51b815260040161082590613b7a565b61092681611a1d565b6000908152601160205260409020805460ff19166001179055565b610d0b610d0661163a565b611a30565b610d275760405162461bcd60e51b815260040161082590613e55565b610d6c610d6787610d61308b33604051602001610d46939291906132c0565b60405160208183030381529060405280519060200120611a4a565b90611a7a565b611ac5565b610d885760405162461bcd60e51b815260040161082590613740565b604080516001808252818301909252606091816020015b610da7612b90565b815260200190600190039081610d9f5750506012549091506001600160a01b031615801590610dd7575060135415155b15610e1557604080518082019091526012546001600160a01b03168152601354602082015281518290600090610e0957fe5b60200260200101819052505b610e253389888888600287611adf565b5050505050505050565b6000610b7f826040518060600160405280602981526020016142796029913960039190611cf6565b600a8054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156107f45780601f106107c9576101008083540402835291602001916107f4565b610ec36108ed61163a565b610edf5760405162461bcd60e51b815260040161082590613b7a565b610926600082610b50565b60006001600160a01b038216610f125760405162461bcd60e51b815260040161082590613ad3565b6001600160a01b0382166000908152600260205260409020610b7f906116b8565b60135481565b6000828152600b60205260408120610b7c90836118bf565b6000828152600b60205260408120610b7c9083611618565b610f746108ed61163a565b610f905760405162461bcd60e51b815260040161082590613b7a565b61092681611d0d565b610fa46108ed61163a565b610fc05760405162461bcd60e51b815260040161082590613b7a565b612710811115610fe25760405162461bcd60e51b815260040161082590613a8c565b601355565b60088054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156107f45780601f106107c9576101008083540402835291602001916107f4565b6110536108ed61163a565b61106f5760405162461bcd60e51b815260040161082590613b7a565b6109266000805160206142c283398151915282610b50565b600d60205281600052604060002081815481106110a057fe5b6000918252602090912060029091020180546001909101546001600160a01b039091169250905082565b6000805160206142a283398151915281565b600081565b6110e961163a565b6001600160a01b0316826001600160a01b0316141561111a5760405162461bcd60e51b815260040161082590613830565b806006600061112761163a565b6001600160a01b03908116825260208083019390935260409182016000908120918716808252919093529120805460ff19169215159290921790915561116b61163a565b6001600160a01b03167f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31836040516111a391906134de565b60405180910390a35050565b6000818152600d60209081526040808320805482518185028101850190935280835260609492939192909184018215610a50576000848152602090819020604080518082019091526002850290910180546001600160a01b03168252600190810154828401529083529092019101610a08565b61123361122d61163a565b836116c3565b61124f5760405162461bcd60e51b815260040161082590613e96565b61125b84848484611d20565b50505050565b61126c610d0661163a565b6112885760405162461bcd60e51b815260040161082590613e55565b60658751106112a95760405162461bcd60e51b8152600401610825906140d0565b60005b8751811015610e25576112fd8882815181106112c457fe5b60200260200101518883815181106112d857fe5b6020026020010151888885815181106112ed57fe5b6020026020010151888888610cfb565b6001016112ac565b60606113108261162d565b61132c5760405162461bcd60e51b815260040161082590613dc5565b60008281526009602090815260409182902080548351601f60026000196101006001861615020190931692909204918201849004840281018401909452808452606093928301828280156113c15780601f10611396576101008083540402835291602001916113c1565b820191906000526020600020905b8154815290600101906020018083116113a457829003601f168201915b5050505050905060606113d2610e57565b90508051600014156113e657509050610763565b815115611418578082604051602001611400929190613309565b60405160208183030381529060405292505050610763565b8061142285611d53565b604051602001611433929190613309565b60405160208183030381529060405292505050919050565b6000818152600b60205260408120610b7f906116b8565b6000908152600e60205260409020546001600160a01b031690565b60116020526000908152604090205460ff1681565b6000805160206142c283398151915281565b6000828152600b60205260409020600201546114c2906105c461163a565b610bfc5760405162461bcd60e51b81526004016108259061399a565b6012546001600160a01b031681565b600c602052600090815260409020805460019091015460ff1682565b60018054604080516020600284861615610100026000190190941693909304601f8101849004840282018401909252818152929183018282801561158e5780601f106115635761010080835404028352916020019161158e565b820191906000526020600020905b81548152906001019060200180831161157157829003601f168201915b505050505081565b6001600160a01b03918216600090815260066020908152604080832093909416825291909152205460ff1690565b6115cf6108ed61163a565b6115eb5760405162461bcd60e51b815260040161082590613b7a565b6109266000805160206142a283398151915282610b16565b6000610b7c836001600160a01b038416611e2d565b6000610b7c836001600160a01b038416611e77565b6000610b7f600383611e8f565b3390565b600081815260056020526040902080546001600160a01b0319166001600160a01b038416908117909155819061167382610e2f565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000610b7f8183610f51565b6000610b7f82611e9b565b60006116ce8261162d565b6116ea5760405162461bcd60e51b81526004016108259061394e565b60006116f583610e2f565b9050806001600160a01b0316846001600160a01b031614806117305750836001600160a01b0316611725846107fe565b6001600160a01b0316145b8061174057506117408185611596565b949350505050565b826001600160a01b031661175b82610e2f565b6001600160a01b0316146117815760405162461bcd60e51b815260040161082590613d7c565b6001600160a01b0382166117a75760405162461bcd60e51b8152600401610825906137ec565b6117b28383836108dd565b6117bd60008261163e565b6001600160a01b03831660009081526002602052604090206117df9082611e9f565b506001600160a01b03821660009081526002602052604090206118029082611eab565b5061180f60038284611eb7565b5080826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a4505050565b6000828152600b6020526040902061186e9082611603565b15610af95761187b61163a565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000610b7c8383611ecd565b6000828152600b602052604090206118e39082611f12565b15610af9576118f061163a565b6001600160a01b0316816001600160a01b0316837ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b60405160405180910390a45050565b600061193f82610e2f565b905061194d816000846108dd565b61195860008361163e565b600082815260096020526040902054600260001961010060018416150201909116041561199657600082815260096020526040812061199691612ba7565b6001600160a01b03811660009081526002602052604090206119b89083611e9f565b506119c4600383611f27565b5060405182906000906001600160a01b038416907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908390a45050565b6000808080611a108686611f33565b9097909650945050505050565b8051610af990600a906020840190612beb565b6000610b7f6000805160206142c283398151915283610f51565b600081604051602001611a5d9190613338565b604051602081830303815290604052805190602001209050919050565b60008151604114611a9d5760405162461bcd60e51b8152600401610825906135eb565b60208201516040830151606084015160001a611abb86828585611f8f565b9695505050505050565b6000610b7f6000805160206142a283398151915283610f51565b611ae88661162d565b15611b055760405162461bcd60e51b815260040161082590613baf565b6000845111611b265760405162461bcd60e51b815260040161082590613674565b611b308787612085565b611b3a8685612149565b6000868152600e6020526040812080546001600160a01b0319166001600160a01b038a16179055805b8651811015611ba057611b96878281518110611b7b57fe5b6020026020010151602001518361218d90919063ffffffff16565b9150600101611b63565b506000836002811115611baf57fe5b1415611be857612710811115611bd75760405162461bcd60e51b81526004016108259061379f565b611be3878260006121b2565b611cec565b6001836002811115611bf657fe5b1415611c29578061271014611c1d5760405162461bcd60e51b815260040161082590613c6a565b611be3878560016121b2565b6002836002811115611c3757fe5b1415611cd4576000805b8351811015611c7357838181518110611c5657fe5b602002602001015160200151820191508080600101915050611c41565b50612710821115611c965760405162461bcd60e51b815260040161082590613b1d565b612710811115611cb85760405162461bcd60e51b8152600401610825906136ab565b611cc4888360026121b2565b611cce8884612278565b50611cec565b60405162461bcd60e51b8152600401610825906139ea565b610e2587876124df565b6000611d03848484612738565b90505b9392505050565b8051610af9906001906020840190612beb565b611d2b848484611748565b611d3784848484612797565b61125b5760405162461bcd60e51b815260040161082590613622565b606081611d7857506040805180820190915260018152600360fc1b6020820152610763565b8160005b8115611d9057600101600a82049150611d7c565b6060816001600160401b0381118015611da857600080fd5b506040519080825280601f01601f191660200182016040528015611dd3576020820181803683370190505b50859350905060001982015b8315611e2457600a840660300160f81b82828060019003935081518110611e0257fe5b60200101906001600160f81b031916908160001a905350600a84049350611ddf565b50949350505050565b6000611e398383611e77565b611e6f57508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610b7f565b506000610b7f565b60009081526001919091016020526040902054151590565b6000610b7c8383611e77565b5490565b6000610b7c8383612876565b6000610b7c8383611e2d565b6000611d0384846001600160a01b03851661293c565b81546000908210611ef05760405162461bcd60e51b81526004016108259061355a565b826000018281548110611eff57fe5b9060005260206000200154905092915050565b6000610b7c836001600160a01b038416612876565b6000610b7c83836129d3565b815460009081908310611f585760405162461bcd60e51b815260040161082590613c28565b6000846000018481548110611f6957fe5b906000526020600020906002020190508060000154816001015492509250509250929050565b60007f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0821115611fd15760405162461bcd60e51b81526004016108259061390c565b8360ff16601b1480611fe657508360ff16601c145b6120025760405162461bcd60e51b815260040161082590613be6565b60006001868686866040516000815260200160405260405161202794939291906134f2565b6020604051602081039080840390855afa158015612049573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b03811661207c5760405162461bcd60e51b815260040161082590613523565b95945050505050565b6001600160a01b0382166120ab5760405162461bcd60e51b815260040161082590613caf565b6120b48161162d565b156120d15760405162461bcd60e51b815260040161082590613709565b6120dd600083836108dd565b6001600160a01b03821660009081526002602052604090206120ff9082611eab565b5061210c60038284611eb7565b5060405181906001600160a01b038416906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b6121528261162d565b61216e5760405162461bcd60e51b815260040161082590613d30565b600082815260096020908152604090912082516108dd92840190612beb565b600082820183811015610b7c5760405162461bcd60e51b815260040161082590613768565b6127108211156121d45760405162461bcd60e51b81526004016108259061407e565b60405180604001604052808381526020018260028111156121f157fe5b90526000848152600c60209081526040909120825181559082015160018083018054909160ff199091169083600281111561222857fe5b0217905550905050827f7c15b0acb23db9f4281ba028b4cf5b3d435df4d8ac490fdf795a17f1435ef89a61225a61163a565b848460405161226b939291906133c9565b60405180910390a2505050565b6010548151111561229b5760405162461bcd60e51b815260040161082590613f7b565b606081516001600160401b03811180156122b457600080fd5b506040519080825280602002602001820160405280156122de578160200160208202803683370190505b509050606082516001600160401b03811180156122fa57600080fd5b50604051908082528060200260200182016040528015612324578160200160208202803683370190505b50905060005b83518110156124975760006001600160a01b031684828151811061234a57fe5b6020026020010151600001516001600160a01b0316141561237d5760405162461bcd60e51b815260040161082590613f1e565b83818151811061238957fe5b602002602001015160200151600014156123b55760405162461bcd60e51b815260040161082590613fd1565b6000858152600f6020526040902084518590839081106123d157fe5b602090810291909101810151825460018082018555600094855293839020825160029092020180546001600160a01b0319166001600160a01b03909216919091178155910151910155835184908290811061242857fe5b60200260200101516000015183828151811061244057fe5b60200260200101906001600160a01b031690816001600160a01b03168152505083818151811061246c57fe5b60200260200101516020015182828151811061248457fe5b602090810291909101015260010161232a565b5082511561125b57837f7911445b722d4bf6bf1efef2425f53c71d6342daa3183597bfce5a1dbb51a63583836040516124d19291906133f8565b60405180910390a250505050565b601054815111156125025760405162461bcd60e51b815260040161082590613f7b565b606081516001600160401b038111801561251b57600080fd5b50604051908082528060200260200182016040528015612545578160200160208202803683370190505b509050606082516001600160401b038111801561256157600080fd5b5060405190808252806020026020018201604052801561258b578160200160208202803683370190505b50905060005b83518110156126fe5760006001600160a01b03168482815181106125b157fe5b6020026020010151600001516001600160a01b031614156125e45760405162461bcd60e51b8152600401610825906138ba565b8381815181106125f057fe5b6020026020010151602001516000141561261c5760405162461bcd60e51b815260040161082590613867565b6000858152600d60205260409020845185908390811061263857fe5b602090810291909101810151825460018082018555600094855293839020825160029092020180546001600160a01b0319166001600160a01b03909216919091178155910151910155835184908290811061268f57fe5b6020026020010151600001518382815181106126a757fe5b60200260200101906001600160a01b031690816001600160a01b0316815250508381815181106126d357fe5b6020026020010151602001518282815181106126eb57fe5b6020908102919091010152600101612591565b5082511561125b57837fd672d091f9d14b86226f12fd03c70639dd2b95d617a4c768e654dbe8ac42e4c683836040516124d19291906133f8565b600082815260018401602052604081205482816127685760405162461bcd60e51b81526004016108259190613510565b5084600001600182038154811061277b57fe5b9060005260206000209060020201600101549150509392505050565b60006127ab846001600160a01b0316612aa7565b6127b757506001611740565b606061283f630a85bd0160e11b6127cc61163a565b8887876040516024016127e2949392919061337d565b604051602081830303815290604052906001600160e01b0319166020820180516001600160e01b038381831617835250505050604051806060016040528060328152602001614247603291396001600160a01b0388169190612aad565b905060008180602001905181019061285791906131ac565b6001600160e01b031916630a85bd0160e11b1492505050949350505050565b6000818152600183016020526040812054801561293257835460001980830191908101906000908790839081106128a957fe5b90600052602060002001549050808760000184815481106128c657fe5b6000918252602080832090910192909255828152600189810190925260409020908401905586548790806128f657fe5b60019003818190600052602060002001600090559055866001016000878152602001908152602001600020600090556001945050505050610b7f565b6000915050610b7f565b6000828152600184016020526040812054806129a1575050604080518082018252838152602080820184815286546001818101895560008981528481209551600290930290950191825591519082015586548684528188019092529290912055611d06565b828560000160018303815481106129b457fe5b9060005260206000209060020201600101819055506000915050611d06565b600081815260018301602052604081205480156129325783546000198083019190810190600090879083908110612a0657fe5b9060005260206000209060020201905080876000018481548110612a2657fe5b600091825260208083208454600290930201918255600193840154918401919091558354825289830190526040902090840190558654879080612a6557fe5b6000828152602080822060026000199094019384020182815560019081018390559290935588815289820190925260408220919091559450610b7f9350505050565b3b151590565b6060611d03848460008585612ac185612aa7565b612add5760405162461bcd60e51b815260040161082590613ee7565b60006060866001600160a01b03168587604051612afa91906132ed565b60006040518083038185875af1925050503d8060008114612b37576040519150601f19603f3d011682016040523d82523d6000602084013e612b3c565b606091505b5091509150612b4c828286612b57565b979650505050505050565b60608315612b66575081611d06565b825115612b765782518084602001fd5b8160405162461bcd60e51b81526004016108259190613510565b604080518082019091526000808252602082015290565b50805460018160011615610100020316600290046000825580601f10612bcd5750610926565b601f0160209004906000526020600020908101906109269190612c69565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10612c2c57805160ff1916838001178555612c59565b82800160010185558215612c59579182015b82811115612c59578251825591602001919060010190612c3e565b50612c65929150612c69565b5090565b5b80821115612c655760008155600101612c6a565b8035610b7f8161421b565b600082601f830112612c99578081fd5b8135612cac612ca7826141c5565b61419f565b818152915060208083019084810160005b84811015612ce657612cd4888484358a0101612de6565b84529282019290820190600101612cbd565b505050505092915050565b600082601f830112612d01578081fd5b8135612d0f612ca7826141c5565b8181529150602080830190848101604080850287018301881015612d3257600080fd5b6000805b86811015612d7b5782848b031215612d4c578182fd5b612d558361419f565b612d5f8b86612c7e565b8152848601358682015286529484019492820192600101612d36565b5050505050505092915050565b600082601f830112612d98578081fd5b8135612da6612ca7826141c5565b818152915060208083019084810181840286018201871015612dc757600080fd5b60005b84811015612ce657813584529282019290820190600101612dca565b600082601f830112612df6578081fd5b81356001600160401b03811115612e0b578182fd5b612e1e601f8201601f191660200161419f565b9150808252836020828501011115612e3557600080fd5b8060208401602084013760009082016020015292915050565b803560038110610b7f57600080fd5b600060208284031215612e6e578081fd5b8135610b7c8161421b565b60008060408385031215612e8b578081fd5b8235612e968161421b565b91506020830135612ea68161421b565b809150509250929050565b600080600060608486031215612ec5578081fd5b8335612ed08161421b565b92506020840135612ee08161421b565b929592945050506040919091013590565b60008060008060808587031215612f06578081fd5b8435612f118161421b565b93506020850135612f218161421b565b92506040850135915060608501356001600160401b03811115612f42578182fd5b612f4e87828801612de6565b91505092959194509250565b60008060408385031215612f6c578182fd5b8235612f778161421b565b915060208301358015158114612ea6578182fd5b60008060408385031215612f9d578182fd5b8235612fa88161421b565b946020939093013593505050565b60006020808385031215612fc8578182fd5b82356001600160401b03811115612fdd578283fd5b8301601f81018513612fed578283fd5b8035612ffb612ca7826141c5565b8181528381019083850185840285018601891015613017578687fd5b8694505b838510156130415761302d8982612c7e565b83526001949094019391850191850161301b565b50979650505050505050565b600080600080600080600060e0888a031215613067578485fd5b87356001600160401b038082111561307d578687fd5b6130898b838c01612d88565b985060208a013591508082111561309e578687fd5b6130aa8b838c01612c89565b975060408a01359150808211156130bf578687fd5b6130cb8b838c01612cf1565b965060608a01359150808211156130e0578485fd5b6130ec8b838c01612c89565b955060808a013594506131028b60a08c01612e4e565b935060c08a0135915080821115613117578283fd5b506131248a828b01612cf1565b91505092959891949750929550565b600060208284031215613144578081fd5b5035919050565b6000806040838503121561315d578182fd5b823591506020830135612ea68161421b565b60008060408385031215613181578182fd5b50508035926020909101359150565b6000602082840312156131a1578081fd5b8135610b7c81614230565b6000602082840312156131bd578081fd5b8151610b7c81614230565b6000602082840312156131d9578081fd5b81356001600160401b038111156131ee578182fd5b61174084828501612de6565b600080600080600080600060e0888a031215613214578081fd5b8735965060208801356001600160401b0380821115613231578283fd5b61323d8b838c01612de6565b975060408a0135915080821115613252578283fd5b61325e8b838c01612cf1565b965060608a0135915080821115613273578283fd5b6130ec8b838c01612de6565b815260200190565b6001600160a01b03169052565b600081518084526132ac8160208601602086016141ef565b601f01601f19169290920160200192915050565b6bffffffffffffffffffffffff19606094851b811682526014820193909352921b16603482015260480190565b600082516132ff8184602087016141ef565b9190910192915050565b6000835161331b8184602088016141ef565b83519083019061332f8183602088016141ef565b01949350505050565b7f19457468657265756d205369676e6564204d6573736167653a0a3332000000008152601c810191909152603c0190565b6001600160a01b0391909116815260200190565b6001600160a01b0385811682528416602082015260408101839052608060608201819052600090611abb90830184613294565b6001600160a01b03929092168252602082015260400190565b6001600160a01b03841681526020810183905260608101600383106133ea57fe5b826040830152949350505050565b604080825283519082018190526000906020906060840190828701845b8281101561343857613428848351613287565b9284019290840190600101613415565b5050508381038285015280855161344f81846134e9565b91508387019250845b818110156134795761346b83855161327f565b938501939250600101613458565b5090979650505050505050565b602080825282518282018190526000919060409081850190868401855b828110156134d157815180516001600160a01b031685528601518685015292840192908501906001016134a3565b5091979650505050505050565b901515815260200190565b90815260200190565b93845260ff9290921660208401526040830152606082015260800190565b600060208252610b7c6020830184613294565b60208082526018908201527f45434453413a20696e76616c6964207369676e61747572650000000000000000604082015260600190565b60208082526022908201527f456e756d657261626c655365743a20696e646578206f7574206f6620626f756e604082015261647360f01b606082015260800190565b6020808252602f908201527f416363657373436f6e74726f6c3a2073656e646572206d75737420626520616e60408201526e0818591b5a5b881d1bc819dc985b9d608a1b606082015260800190565b6020808252601f908201527f45434453413a20696e76616c6964207369676e6174757265206c656e67746800604082015260600190565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b60208082526019908201527f4552433732313a205572692073686f756c642062652073657400000000000000604082015260600190565b602080825260409082018190527f526f79616c74793a20546f74616c207072696d61727920726f79616c74792073908201527f68617265206270732073686f756c64206e6f7420657863656564203130303030606082015260800190565b6020808252601c908201527f4552433732313a20746f6b656e20616c7265616479206d696e74656400000000604082015260600190565b6020808252600e908201526d34b73b30b634b21039b4b3b732b960911b604082015260600190565b6020808252601b908201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604082015260600190565b6020808252602d908201527f4552433732313a20546f74616c20666565206270732073686f756c64206e6f7460408201526c02065786365656420313030303609c1b606082015260800190565b60208082526024908201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646040820152637265737360e01b606082015260800190565b60208082526019908201527f4552433732313a20617070726f766520746f2063616c6c657200000000000000604082015260600190565b60208082526033908201527f526f79616c74793a20526f79616c7479207368617265206270732076616c75656040820152722073686f756c6420626520706f73697469766560681b606082015260800190565b60208082526032908201527f526f79616c74793a20526f79616c747920736861726520726563697069656e74604082015271081cda1bdd5b19081899481c1c995cd95b9d60721b606082015260800190565b60208082526022908201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604082015261756560f01b606082015260800190565b6020808252602c908201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860408201526b34b9ba32b73a103a37b5b2b760a11b606082015260800190565b60208082526030908201527f416363657373436f6e74726f6c3a2073656e646572206d75737420626520616e60408201526f2061646d696e20746f207265766f6b6560801b606082015260800190565b60208082526025908201527f4552433732313a20526f79616c7479206f7074696f6e20646f6573206e6f7420604082015264195e1a5cdd60da1b606082015260800190565b60208082526038908201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760408201527f6e6572206e6f7220617070726f76656420666f7220616c6c0000000000000000606082015260800190565b60208082526027908201527f4552433732313a20466565206270732073686f756c64206e6f742065786365656040820152660642031303030360cc1b606082015260800190565b6020808252602a908201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604082015269726f206164647265737360b01b606082015260800190565b60208082526038908201527f526f79616c74793a20546f74616c20726f79616c74792073686172652062707360408201527f2073686f756c64206e6f74206578636565642031303030300000000000000000606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f74207468652061646d696e604082015260600190565b6020808252601f908201527f4552433732313a20546f6b656e20697320616c7265616479206d696e74656400604082015260600190565b60208082526022908201527f45434453413a20696e76616c6964207369676e6174757265202776272076616c604082015261756560f01b606082015260800190565b60208082526022908201527f456e756d657261626c654d61703a20696e646578206f7574206f6620626f756e604082015261647360f01b606082015260800190565b60208082526025908201527f4552433732313a20546f74616c20666565206270732073686f756c6420626520604082015264031303030360dc1b606082015260800190565b6020808252818101527f4552433732313a206d696e7420746f20746865207a65726f2061646472657373604082015260600190565b6020808252602c908201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860408201526b34b9ba32b73a103a37b5b2b760a11b606082015260800190565b6020808252602c908201527f4552433732314d657461646174613a2055524920736574206f66206e6f6e657860408201526b34b9ba32b73a103a37b5b2b760a11b606082015260800190565b60208082526029908201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960408201526839903737ba1037bbb760b91b606082015260800190565b6020808252602f908201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60408201526e3732bc34b9ba32b73a103a37b5b2b760891b606082015260800190565b60208082526021908201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656040820152603960f91b606082015260800190565b60208082526021908201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206d696e74656040820152603960f91b606082015260800190565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b6020808252601d908201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604082015260600190565b6020808252603a908201527f526f79616c74793a205072696d61727920726f79616c7479207368617265207260408201527f6563697069656e742073686f756c642062652070726573656e74000000000000606082015260800190565b60208082526036908201527f526f79616c74793a20416d6f756e74206f6620726f79616c7479207265636970604082015275069656e74732063616e277420657863656564203130360541b606082015260800190565b6020808252603b908201527f526f79616c74793a205072696d61727920726f79616c7479207368617265206260408201527f70732076616c75652073686f756c6420626520706f7369746976650000000000606082015260800190565b60208082526030908201527f4552433732314275726e61626c653a2063616c6c6572206973206e6f74206f7760408201526f1b995c881b9bdc88185c1c1c9bdd995960821b606082015260800190565b60208082526032908201527f526f79616c74793a20546f74616c20726f79616c7479206270732073686f756c604082015271064206e6f74206578636565642031303030360741b606082015260800190565b60208082526022908201527f596f752063616e206f6e6c79206261746368206d696e742031303020746f6b656040820152616e7360f01b606082015260800190565b6020808252602f908201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560408201526e103937b632b9903337b91039b2b63360891b606082015260800190565b8151815260208201516040820190614178906141e4565b602083015292915050565b82815260408101614193836141e4565b60208301529392505050565b6040518181016001600160401b03811182821017156141bd57600080fd5b604052919050565b60006001600160401b038211156141da578081fd5b5060209081020190565b806003811061076357fe5b60005b8381101561420a5781810151838201526020016141f2565b8381111561125b5750506000910152565b6001600160a01b038116811461092657600080fd5b6001600160e01b03198116811461092657600080fdfe4552433732313a207472616e7366657220746f206e6f6e20455243373231526563656976657220696d706c656d656e7465724552433732313a206f776e657220717565727920666f72206e6f6e6578697374656e7420746f6b656ee2f4eaae4a9751e85a3e4a7b9587827a877f29914755229b07a7b2da98285f709f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a6a2646970667358221220711b2ad3ba3c5ab353b7dd06ad602fc3b77f1f7e23960f046333959e7916ffe364736f6c634300060c003300000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001000000000000000000000000003f231e09f6e4e97e8fec2f1e507414460c866f23000000000000000000000000d2e49cfd5c03a72a838a2fc6bb5f6b46927e731a000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000001a0000000000000000000000000000000000000000000000000000000000000001f4e65696c204261727265747420436f6c6c656374696f6e206279204d4f44410000000000000000000000000000000000000000000000000000000000000000114e45494c5f424152524554545f4d4f4441000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003468747470733a2f2f6170692e726566696e61626c652e636f6d2f636f6e74726163744d657461646174612f7b616464726573737d000000000000000000000000000000000000000000000000000000000000000000000000000000000000002068747470733a2f2f697066732e726566696e61626c652e636f6d2f697066732f

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106103425760003560e01c806370480275116101b8578063ac04f24311610104578063d5391393116100a2578063e814cb711161007c578063e814cb71146106f6578063e8a3d48514610717578063e985e9c51461071f578063eb12d61e1461073257610342565b8063d5391393146106d3578063d547741f146106db578063e461aa23146106ee57610342565b8063c87b56dd116100de578063c87b56dd14610687578063ca15c8731461069a578063d48e638a146106ad578063d4e6b3c4146106c057610342565b8063ac04f2431461064e578063b88d4fde14610661578063b9d4949d1461067457610342565b806393c3f80b11610171578063a000429e1161014b578063a000429e1461060a578063a1ebf35d1461062b578063a217fddf14610633578063a22cb4651461063b57610342565b806393c3f80b146105dc57806395d89b41146105ef578063983b2d56146105f757610342565b8063704802751461057557806370a082311461058857806380b11f1b1461059b5780639010d07c146105a357806391d14854146105b6578063938e3d7b146105c957610342565b806328b7bede1161029257806342966c68116102305780635b1d0f4d1161020a5780635b1d0f4d146105345780635b45a13c146105475780636352211e1461055a5780636c0360eb1461056d57610342565b806342966c68146104fb5780634f6ccce71461050e57806355f804b31461052157610342565b80633092afd51161026c5780633092afd5146104af57806336568abe146104c25780633ebc82c5146104d557806342842e0e146104e857610342565b806328b7bede146104815780632f2ff15d146104895780632f745c591461049c57610342565b80631785f53c116102ff57806320b029a5116102d957806320b029a51461042857806323b872dd1461044857806323c969711461045b578063248a9ca31461046e57610342565b80631785f53c146103e057806318160ddd146103f35780631af9cf491461040857610342565b806301ffc9a71461034757806306fdde0314610370578063081812fc14610385578063095ea7b3146103a55780630e316ab7146103ba5780630e883747146103cd575b600080fd5b61035a610355366004613190565b610745565b60405161036791906134de565b60405180910390f35b610378610768565b6040516103679190613510565b610398610393366004613133565b6107fe565b6040516103679190613369565b6103b86103b3366004612f8b565b61084a565b005b6103b86103c8366004612e5d565b6108e2565b61035a6103db366004613133565b610929565b6103b86103ee366004612e5d565b61093e565b6103fb610970565b60405161036791906134e9565b61041b610416366004613133565b610981565b6040516103679190614161565b61043b610436366004613133565b6109d3565b6040516103679190613486565b6103b8610456366004612eb1565b610a5b565b6103b8610469366004612fb6565b610a93565b6103fb61047c366004613133565b610afd565b610398610b12565b6103b861049736600461314b565b610b16565b6103fb6104aa366004612f8b565b610b5a565b6103b86104bd366004612e5d565b610b85565b6103b86104d036600461314b565b610bc4565b6103b86104e3366004612e5d565b610c06565b6103b86104f6366004612eb1565b610c4f565b6103b8610509366004613133565b610c6a565b6103fb61051c366004613133565b610c9a565b6103b861052f3660046131c8565b610cb0565b6103b8610542366004613133565b610ce0565b6103b86105553660046131fa565b610cfb565b610398610568366004613133565b610e2f565b610378610e57565b6103b8610583366004612e5d565b610eb8565b6103fb610596366004612e5d565b610eea565b6103fb610f33565b6103986105b136600461316f565b610f39565b61035a6105c436600461314b565b610f51565b6103b86105d73660046131c8565b610f69565b6103b86105ea366004613133565b610f99565b610378610fe7565b6103b8610605366004612e5d565b611048565b61061d61061836600461316f565b611087565b6040516103679291906133b0565b6103fb6110ca565b6103fb6110dc565b6103b8610649366004612f5a565b6110e1565b61043b61065c366004613133565b6111af565b6103b861066f366004612ef1565b611222565b6103b861068236600461304d565b611261565b610378610695366004613133565b611305565b6103fb6106a8366004613133565b61144b565b6103986106bb366004613133565b611462565b61035a6106ce366004613133565b61147d565b6103fb611492565b6103b86106e936600461314b565b6114a4565b6103986114de565b610709610704366004613133565b6114ed565b604051610367929190614183565b610378611509565b61035a61072d366004612e79565b611596565b6103b8610740366004612e5d565b6115c4565b6001600160e01b0319811660009081526020819052604090205460ff165b919050565b60078054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156107f45780601f106107c9576101008083540402835291602001916107f4565b820191906000526020600020905b8154815290600101906020018083116107d757829003601f168201915b5050505050905090565b60006108098261162d565b61082e5760405162461bcd60e51b815260040161082590613ce4565b60405180910390fd5b506000908152600560205260409020546001600160a01b031690565b600061085582610e2f565b9050806001600160a01b0316836001600160a01b031614156108895760405162461bcd60e51b815260040161082590613e14565b806001600160a01b031661089b61163a565b6001600160a01b031614806108b757506108b78161072d61163a565b6108d35760405162461bcd60e51b815260040161082590613a2f565b6108dd838361163e565b505050565b6108f26108ed61163a565b6116ac565b61090e5760405162461bcd60e51b815260040161082590613b7a565b6109266000805160206142a2833981519152826114a4565b50565b60009081526011602052604090205460ff1690565b6109496108ed61163a565b6109655760405162461bcd60e51b815260040161082590613b7a565b6109266000826114a4565b600061097c60036116b8565b905090565b610989612b90565b6000828152600c60209081526040918290208251808401909352805483526001810154909183019060ff1660028111156109bf57fe5b60028111156109ca57fe5b90525092915050565b6060600f6000838152602001908152602001600020805480602002602001604051908101604052809291908181526020016000905b82821015610a50576000848152602090819020604080518082019091526002850290910180546001600160a01b03168252600190810154828401529083529092019101610a08565b505050509050919050565b610a6c610a6661163a565b826116c3565b610a885760405162461bcd60e51b815260040161082590613e96565b6108dd838383611748565b610a9e6108ed61163a565b610aba5760405162461bcd60e51b815260040161082590613b7a565b60005b8151811015610af957610af16000805160206142c2833981519152838381518110610ae457fe5b6020026020010151610b50565b600101610abd565b5050565b6000908152600b602052604090206002015490565b3090565b6000828152600b6020526040902060020154610b34906105c461163a565b610b505760405162461bcd60e51b81526004016108259061359c565b610af98282611856565b6001600160a01b0382166000908152600260205260408120610b7c90836118bf565b90505b92915050565b610b906108ed61163a565b610bac5760405162461bcd60e51b815260040161082590613b7a565b6109266000805160206142c2833981519152826114a4565b610bcc61163a565b6001600160a01b0316816001600160a01b031614610bfc5760405162461bcd60e51b815260040161082590614112565b610af982826118cb565b610c116108ed61163a565b610c2d5760405162461bcd60e51b815260040161082590613b7a565b601280546001600160a01b0319166001600160a01b0392909216919091179055565b6108dd83838360405180602001604052806000815250611222565b610c75610a6661163a565b610c915760405162461bcd60e51b81526004016108259061402e565b61092681611934565b600080610ca8600384611a01565b509392505050565b610cbb6108ed61163a565b610cd75760405162461bcd60e51b815260040161082590613b7a565b61092681611a1d565b6000908152601160205260409020805460ff19166001179055565b610d0b610d0661163a565b611a30565b610d275760405162461bcd60e51b815260040161082590613e55565b610d6c610d6787610d61308b33604051602001610d46939291906132c0565b60405160208183030381529060405280519060200120611a4a565b90611a7a565b611ac5565b610d885760405162461bcd60e51b815260040161082590613740565b604080516001808252818301909252606091816020015b610da7612b90565b815260200190600190039081610d9f5750506012549091506001600160a01b031615801590610dd7575060135415155b15610e1557604080518082019091526012546001600160a01b03168152601354602082015281518290600090610e0957fe5b60200260200101819052505b610e253389888888600287611adf565b5050505050505050565b6000610b7f826040518060600160405280602981526020016142796029913960039190611cf6565b600a8054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156107f45780601f106107c9576101008083540402835291602001916107f4565b610ec36108ed61163a565b610edf5760405162461bcd60e51b815260040161082590613b7a565b610926600082610b50565b60006001600160a01b038216610f125760405162461bcd60e51b815260040161082590613ad3565b6001600160a01b0382166000908152600260205260409020610b7f906116b8565b60135481565b6000828152600b60205260408120610b7c90836118bf565b6000828152600b60205260408120610b7c9083611618565b610f746108ed61163a565b610f905760405162461bcd60e51b815260040161082590613b7a565b61092681611d0d565b610fa46108ed61163a565b610fc05760405162461bcd60e51b815260040161082590613b7a565b612710811115610fe25760405162461bcd60e51b815260040161082590613a8c565b601355565b60088054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156107f45780601f106107c9576101008083540402835291602001916107f4565b6110536108ed61163a565b61106f5760405162461bcd60e51b815260040161082590613b7a565b6109266000805160206142c283398151915282610b50565b600d60205281600052604060002081815481106110a057fe5b6000918252602090912060029091020180546001909101546001600160a01b039091169250905082565b6000805160206142a283398151915281565b600081565b6110e961163a565b6001600160a01b0316826001600160a01b0316141561111a5760405162461bcd60e51b815260040161082590613830565b806006600061112761163a565b6001600160a01b03908116825260208083019390935260409182016000908120918716808252919093529120805460ff19169215159290921790915561116b61163a565b6001600160a01b03167f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31836040516111a391906134de565b60405180910390a35050565b6000818152600d60209081526040808320805482518185028101850190935280835260609492939192909184018215610a50576000848152602090819020604080518082019091526002850290910180546001600160a01b03168252600190810154828401529083529092019101610a08565b61123361122d61163a565b836116c3565b61124f5760405162461bcd60e51b815260040161082590613e96565b61125b84848484611d20565b50505050565b61126c610d0661163a565b6112885760405162461bcd60e51b815260040161082590613e55565b60658751106112a95760405162461bcd60e51b8152600401610825906140d0565b60005b8751811015610e25576112fd8882815181106112c457fe5b60200260200101518883815181106112d857fe5b6020026020010151888885815181106112ed57fe5b6020026020010151888888610cfb565b6001016112ac565b60606113108261162d565b61132c5760405162461bcd60e51b815260040161082590613dc5565b60008281526009602090815260409182902080548351601f60026000196101006001861615020190931692909204918201849004840281018401909452808452606093928301828280156113c15780601f10611396576101008083540402835291602001916113c1565b820191906000526020600020905b8154815290600101906020018083116113a457829003601f168201915b5050505050905060606113d2610e57565b90508051600014156113e657509050610763565b815115611418578082604051602001611400929190613309565b60405160208183030381529060405292505050610763565b8061142285611d53565b604051602001611433929190613309565b60405160208183030381529060405292505050919050565b6000818152600b60205260408120610b7f906116b8565b6000908152600e60205260409020546001600160a01b031690565b60116020526000908152604090205460ff1681565b6000805160206142c283398151915281565b6000828152600b60205260409020600201546114c2906105c461163a565b610bfc5760405162461bcd60e51b81526004016108259061399a565b6012546001600160a01b031681565b600c602052600090815260409020805460019091015460ff1682565b60018054604080516020600284861615610100026000190190941693909304601f8101849004840282018401909252818152929183018282801561158e5780601f106115635761010080835404028352916020019161158e565b820191906000526020600020905b81548152906001019060200180831161157157829003601f168201915b505050505081565b6001600160a01b03918216600090815260066020908152604080832093909416825291909152205460ff1690565b6115cf6108ed61163a565b6115eb5760405162461bcd60e51b815260040161082590613b7a565b6109266000805160206142a283398151915282610b16565b6000610b7c836001600160a01b038416611e2d565b6000610b7c836001600160a01b038416611e77565b6000610b7f600383611e8f565b3390565b600081815260056020526040902080546001600160a01b0319166001600160a01b038416908117909155819061167382610e2f565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000610b7f8183610f51565b6000610b7f82611e9b565b60006116ce8261162d565b6116ea5760405162461bcd60e51b81526004016108259061394e565b60006116f583610e2f565b9050806001600160a01b0316846001600160a01b031614806117305750836001600160a01b0316611725846107fe565b6001600160a01b0316145b8061174057506117408185611596565b949350505050565b826001600160a01b031661175b82610e2f565b6001600160a01b0316146117815760405162461bcd60e51b815260040161082590613d7c565b6001600160a01b0382166117a75760405162461bcd60e51b8152600401610825906137ec565b6117b28383836108dd565b6117bd60008261163e565b6001600160a01b03831660009081526002602052604090206117df9082611e9f565b506001600160a01b03821660009081526002602052604090206118029082611eab565b5061180f60038284611eb7565b5080826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a4505050565b6000828152600b6020526040902061186e9082611603565b15610af95761187b61163a565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000610b7c8383611ecd565b6000828152600b602052604090206118e39082611f12565b15610af9576118f061163a565b6001600160a01b0316816001600160a01b0316837ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b60405160405180910390a45050565b600061193f82610e2f565b905061194d816000846108dd565b61195860008361163e565b600082815260096020526040902054600260001961010060018416150201909116041561199657600082815260096020526040812061199691612ba7565b6001600160a01b03811660009081526002602052604090206119b89083611e9f565b506119c4600383611f27565b5060405182906000906001600160a01b038416907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908390a45050565b6000808080611a108686611f33565b9097909650945050505050565b8051610af990600a906020840190612beb565b6000610b7f6000805160206142c283398151915283610f51565b600081604051602001611a5d9190613338565b604051602081830303815290604052805190602001209050919050565b60008151604114611a9d5760405162461bcd60e51b8152600401610825906135eb565b60208201516040830151606084015160001a611abb86828585611f8f565b9695505050505050565b6000610b7f6000805160206142a283398151915283610f51565b611ae88661162d565b15611b055760405162461bcd60e51b815260040161082590613baf565b6000845111611b265760405162461bcd60e51b815260040161082590613674565b611b308787612085565b611b3a8685612149565b6000868152600e6020526040812080546001600160a01b0319166001600160a01b038a16179055805b8651811015611ba057611b96878281518110611b7b57fe5b6020026020010151602001518361218d90919063ffffffff16565b9150600101611b63565b506000836002811115611baf57fe5b1415611be857612710811115611bd75760405162461bcd60e51b81526004016108259061379f565b611be3878260006121b2565b611cec565b6001836002811115611bf657fe5b1415611c29578061271014611c1d5760405162461bcd60e51b815260040161082590613c6a565b611be3878560016121b2565b6002836002811115611c3757fe5b1415611cd4576000805b8351811015611c7357838181518110611c5657fe5b602002602001015160200151820191508080600101915050611c41565b50612710821115611c965760405162461bcd60e51b815260040161082590613b1d565b612710811115611cb85760405162461bcd60e51b8152600401610825906136ab565b611cc4888360026121b2565b611cce8884612278565b50611cec565b60405162461bcd60e51b8152600401610825906139ea565b610e2587876124df565b6000611d03848484612738565b90505b9392505050565b8051610af9906001906020840190612beb565b611d2b848484611748565b611d3784848484612797565b61125b5760405162461bcd60e51b815260040161082590613622565b606081611d7857506040805180820190915260018152600360fc1b6020820152610763565b8160005b8115611d9057600101600a82049150611d7c565b6060816001600160401b0381118015611da857600080fd5b506040519080825280601f01601f191660200182016040528015611dd3576020820181803683370190505b50859350905060001982015b8315611e2457600a840660300160f81b82828060019003935081518110611e0257fe5b60200101906001600160f81b031916908160001a905350600a84049350611ddf565b50949350505050565b6000611e398383611e77565b611e6f57508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610b7f565b506000610b7f565b60009081526001919091016020526040902054151590565b6000610b7c8383611e77565b5490565b6000610b7c8383612876565b6000610b7c8383611e2d565b6000611d0384846001600160a01b03851661293c565b81546000908210611ef05760405162461bcd60e51b81526004016108259061355a565b826000018281548110611eff57fe5b9060005260206000200154905092915050565b6000610b7c836001600160a01b038416612876565b6000610b7c83836129d3565b815460009081908310611f585760405162461bcd60e51b815260040161082590613c28565b6000846000018481548110611f6957fe5b906000526020600020906002020190508060000154816001015492509250509250929050565b60007f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0821115611fd15760405162461bcd60e51b81526004016108259061390c565b8360ff16601b1480611fe657508360ff16601c145b6120025760405162461bcd60e51b815260040161082590613be6565b60006001868686866040516000815260200160405260405161202794939291906134f2565b6020604051602081039080840390855afa158015612049573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b03811661207c5760405162461bcd60e51b815260040161082590613523565b95945050505050565b6001600160a01b0382166120ab5760405162461bcd60e51b815260040161082590613caf565b6120b48161162d565b156120d15760405162461bcd60e51b815260040161082590613709565b6120dd600083836108dd565b6001600160a01b03821660009081526002602052604090206120ff9082611eab565b5061210c60038284611eb7565b5060405181906001600160a01b038416906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b6121528261162d565b61216e5760405162461bcd60e51b815260040161082590613d30565b600082815260096020908152604090912082516108dd92840190612beb565b600082820183811015610b7c5760405162461bcd60e51b815260040161082590613768565b6127108211156121d45760405162461bcd60e51b81526004016108259061407e565b60405180604001604052808381526020018260028111156121f157fe5b90526000848152600c60209081526040909120825181559082015160018083018054909160ff199091169083600281111561222857fe5b0217905550905050827f7c15b0acb23db9f4281ba028b4cf5b3d435df4d8ac490fdf795a17f1435ef89a61225a61163a565b848460405161226b939291906133c9565b60405180910390a2505050565b6010548151111561229b5760405162461bcd60e51b815260040161082590613f7b565b606081516001600160401b03811180156122b457600080fd5b506040519080825280602002602001820160405280156122de578160200160208202803683370190505b509050606082516001600160401b03811180156122fa57600080fd5b50604051908082528060200260200182016040528015612324578160200160208202803683370190505b50905060005b83518110156124975760006001600160a01b031684828151811061234a57fe5b6020026020010151600001516001600160a01b0316141561237d5760405162461bcd60e51b815260040161082590613f1e565b83818151811061238957fe5b602002602001015160200151600014156123b55760405162461bcd60e51b815260040161082590613fd1565b6000858152600f6020526040902084518590839081106123d157fe5b602090810291909101810151825460018082018555600094855293839020825160029092020180546001600160a01b0319166001600160a01b03909216919091178155910151910155835184908290811061242857fe5b60200260200101516000015183828151811061244057fe5b60200260200101906001600160a01b031690816001600160a01b03168152505083818151811061246c57fe5b60200260200101516020015182828151811061248457fe5b602090810291909101015260010161232a565b5082511561125b57837f7911445b722d4bf6bf1efef2425f53c71d6342daa3183597bfce5a1dbb51a63583836040516124d19291906133f8565b60405180910390a250505050565b601054815111156125025760405162461bcd60e51b815260040161082590613f7b565b606081516001600160401b038111801561251b57600080fd5b50604051908082528060200260200182016040528015612545578160200160208202803683370190505b509050606082516001600160401b038111801561256157600080fd5b5060405190808252806020026020018201604052801561258b578160200160208202803683370190505b50905060005b83518110156126fe5760006001600160a01b03168482815181106125b157fe5b6020026020010151600001516001600160a01b031614156125e45760405162461bcd60e51b8152600401610825906138ba565b8381815181106125f057fe5b6020026020010151602001516000141561261c5760405162461bcd60e51b815260040161082590613867565b6000858152600d60205260409020845185908390811061263857fe5b602090810291909101810151825460018082018555600094855293839020825160029092020180546001600160a01b0319166001600160a01b03909216919091178155910151910155835184908290811061268f57fe5b6020026020010151600001518382815181106126a757fe5b60200260200101906001600160a01b031690816001600160a01b0316815250508381815181106126d357fe5b6020026020010151602001518282815181106126eb57fe5b6020908102919091010152600101612591565b5082511561125b57837fd672d091f9d14b86226f12fd03c70639dd2b95d617a4c768e654dbe8ac42e4c683836040516124d19291906133f8565b600082815260018401602052604081205482816127685760405162461bcd60e51b81526004016108259190613510565b5084600001600182038154811061277b57fe5b9060005260206000209060020201600101549150509392505050565b60006127ab846001600160a01b0316612aa7565b6127b757506001611740565b606061283f630a85bd0160e11b6127cc61163a565b8887876040516024016127e2949392919061337d565b604051602081830303815290604052906001600160e01b0319166020820180516001600160e01b038381831617835250505050604051806060016040528060328152602001614247603291396001600160a01b0388169190612aad565b905060008180602001905181019061285791906131ac565b6001600160e01b031916630a85bd0160e11b1492505050949350505050565b6000818152600183016020526040812054801561293257835460001980830191908101906000908790839081106128a957fe5b90600052602060002001549050808760000184815481106128c657fe5b6000918252602080832090910192909255828152600189810190925260409020908401905586548790806128f657fe5b60019003818190600052602060002001600090559055866001016000878152602001908152602001600020600090556001945050505050610b7f565b6000915050610b7f565b6000828152600184016020526040812054806129a1575050604080518082018252838152602080820184815286546001818101895560008981528481209551600290930290950191825591519082015586548684528188019092529290912055611d06565b828560000160018303815481106129b457fe5b9060005260206000209060020201600101819055506000915050611d06565b600081815260018301602052604081205480156129325783546000198083019190810190600090879083908110612a0657fe5b9060005260206000209060020201905080876000018481548110612a2657fe5b600091825260208083208454600290930201918255600193840154918401919091558354825289830190526040902090840190558654879080612a6557fe5b6000828152602080822060026000199094019384020182815560019081018390559290935588815289820190925260408220919091559450610b7f9350505050565b3b151590565b6060611d03848460008585612ac185612aa7565b612add5760405162461bcd60e51b815260040161082590613ee7565b60006060866001600160a01b03168587604051612afa91906132ed565b60006040518083038185875af1925050503d8060008114612b37576040519150601f19603f3d011682016040523d82523d6000602084013e612b3c565b606091505b5091509150612b4c828286612b57565b979650505050505050565b60608315612b66575081611d06565b825115612b765782518084602001fd5b8160405162461bcd60e51b81526004016108259190613510565b604080518082019091526000808252602082015290565b50805460018160011615610100020316600290046000825580601f10612bcd5750610926565b601f0160209004906000526020600020908101906109269190612c69565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10612c2c57805160ff1916838001178555612c59565b82800160010185558215612c59579182015b82811115612c59578251825591602001919060010190612c3e565b50612c65929150612c69565b5090565b5b80821115612c655760008155600101612c6a565b8035610b7f8161421b565b600082601f830112612c99578081fd5b8135612cac612ca7826141c5565b61419f565b818152915060208083019084810160005b84811015612ce657612cd4888484358a0101612de6565b84529282019290820190600101612cbd565b505050505092915050565b600082601f830112612d01578081fd5b8135612d0f612ca7826141c5565b8181529150602080830190848101604080850287018301881015612d3257600080fd5b6000805b86811015612d7b5782848b031215612d4c578182fd5b612d558361419f565b612d5f8b86612c7e565b8152848601358682015286529484019492820192600101612d36565b5050505050505092915050565b600082601f830112612d98578081fd5b8135612da6612ca7826141c5565b818152915060208083019084810181840286018201871015612dc757600080fd5b60005b84811015612ce657813584529282019290820190600101612dca565b600082601f830112612df6578081fd5b81356001600160401b03811115612e0b578182fd5b612e1e601f8201601f191660200161419f565b9150808252836020828501011115612e3557600080fd5b8060208401602084013760009082016020015292915050565b803560038110610b7f57600080fd5b600060208284031215612e6e578081fd5b8135610b7c8161421b565b60008060408385031215612e8b578081fd5b8235612e968161421b565b91506020830135612ea68161421b565b809150509250929050565b600080600060608486031215612ec5578081fd5b8335612ed08161421b565b92506020840135612ee08161421b565b929592945050506040919091013590565b60008060008060808587031215612f06578081fd5b8435612f118161421b565b93506020850135612f218161421b565b92506040850135915060608501356001600160401b03811115612f42578182fd5b612f4e87828801612de6565b91505092959194509250565b60008060408385031215612f6c578182fd5b8235612f778161421b565b915060208301358015158114612ea6578182fd5b60008060408385031215612f9d578182fd5b8235612fa88161421b565b946020939093013593505050565b60006020808385031215612fc8578182fd5b82356001600160401b03811115612fdd578283fd5b8301601f81018513612fed578283fd5b8035612ffb612ca7826141c5565b8181528381019083850185840285018601891015613017578687fd5b8694505b838510156130415761302d8982612c7e565b83526001949094019391850191850161301b565b50979650505050505050565b600080600080600080600060e0888a031215613067578485fd5b87356001600160401b038082111561307d578687fd5b6130898b838c01612d88565b985060208a013591508082111561309e578687fd5b6130aa8b838c01612c89565b975060408a01359150808211156130bf578687fd5b6130cb8b838c01612cf1565b965060608a01359150808211156130e0578485fd5b6130ec8b838c01612c89565b955060808a013594506131028b60a08c01612e4e565b935060c08a0135915080821115613117578283fd5b506131248a828b01612cf1565b91505092959891949750929550565b600060208284031215613144578081fd5b5035919050565b6000806040838503121561315d578182fd5b823591506020830135612ea68161421b565b60008060408385031215613181578182fd5b50508035926020909101359150565b6000602082840312156131a1578081fd5b8135610b7c81614230565b6000602082840312156131bd578081fd5b8151610b7c81614230565b6000602082840312156131d9578081fd5b81356001600160401b038111156131ee578182fd5b61174084828501612de6565b600080600080600080600060e0888a031215613214578081fd5b8735965060208801356001600160401b0380821115613231578283fd5b61323d8b838c01612de6565b975060408a0135915080821115613252578283fd5b61325e8b838c01612cf1565b965060608a0135915080821115613273578283fd5b6130ec8b838c01612de6565b815260200190565b6001600160a01b03169052565b600081518084526132ac8160208601602086016141ef565b601f01601f19169290920160200192915050565b6bffffffffffffffffffffffff19606094851b811682526014820193909352921b16603482015260480190565b600082516132ff8184602087016141ef565b9190910192915050565b6000835161331b8184602088016141ef565b83519083019061332f8183602088016141ef565b01949350505050565b7f19457468657265756d205369676e6564204d6573736167653a0a3332000000008152601c810191909152603c0190565b6001600160a01b0391909116815260200190565b6001600160a01b0385811682528416602082015260408101839052608060608201819052600090611abb90830184613294565b6001600160a01b03929092168252602082015260400190565b6001600160a01b03841681526020810183905260608101600383106133ea57fe5b826040830152949350505050565b604080825283519082018190526000906020906060840190828701845b8281101561343857613428848351613287565b9284019290840190600101613415565b5050508381038285015280855161344f81846134e9565b91508387019250845b818110156134795761346b83855161327f565b938501939250600101613458565b5090979650505050505050565b602080825282518282018190526000919060409081850190868401855b828110156134d157815180516001600160a01b031685528601518685015292840192908501906001016134a3565b5091979650505050505050565b901515815260200190565b90815260200190565b93845260ff9290921660208401526040830152606082015260800190565b600060208252610b7c6020830184613294565b60208082526018908201527f45434453413a20696e76616c6964207369676e61747572650000000000000000604082015260600190565b60208082526022908201527f456e756d657261626c655365743a20696e646578206f7574206f6620626f756e604082015261647360f01b606082015260800190565b6020808252602f908201527f416363657373436f6e74726f6c3a2073656e646572206d75737420626520616e60408201526e0818591b5a5b881d1bc819dc985b9d608a1b606082015260800190565b6020808252601f908201527f45434453413a20696e76616c6964207369676e6174757265206c656e67746800604082015260600190565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b60208082526019908201527f4552433732313a205572692073686f756c642062652073657400000000000000604082015260600190565b602080825260409082018190527f526f79616c74793a20546f74616c207072696d61727920726f79616c74792073908201527f68617265206270732073686f756c64206e6f7420657863656564203130303030606082015260800190565b6020808252601c908201527f4552433732313a20746f6b656e20616c7265616479206d696e74656400000000604082015260600190565b6020808252600e908201526d34b73b30b634b21039b4b3b732b960911b604082015260600190565b6020808252601b908201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604082015260600190565b6020808252602d908201527f4552433732313a20546f74616c20666565206270732073686f756c64206e6f7460408201526c02065786365656420313030303609c1b606082015260800190565b60208082526024908201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646040820152637265737360e01b606082015260800190565b60208082526019908201527f4552433732313a20617070726f766520746f2063616c6c657200000000000000604082015260600190565b60208082526033908201527f526f79616c74793a20526f79616c7479207368617265206270732076616c75656040820152722073686f756c6420626520706f73697469766560681b606082015260800190565b60208082526032908201527f526f79616c74793a20526f79616c747920736861726520726563697069656e74604082015271081cda1bdd5b19081899481c1c995cd95b9d60721b606082015260800190565b60208082526022908201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604082015261756560f01b606082015260800190565b6020808252602c908201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860408201526b34b9ba32b73a103a37b5b2b760a11b606082015260800190565b60208082526030908201527f416363657373436f6e74726f6c3a2073656e646572206d75737420626520616e60408201526f2061646d696e20746f207265766f6b6560801b606082015260800190565b60208082526025908201527f4552433732313a20526f79616c7479206f7074696f6e20646f6573206e6f7420604082015264195e1a5cdd60da1b606082015260800190565b60208082526038908201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760408201527f6e6572206e6f7220617070726f76656420666f7220616c6c0000000000000000606082015260800190565b60208082526027908201527f4552433732313a20466565206270732073686f756c64206e6f742065786365656040820152660642031303030360cc1b606082015260800190565b6020808252602a908201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604082015269726f206164647265737360b01b606082015260800190565b60208082526038908201527f526f79616c74793a20546f74616c20726f79616c74792073686172652062707360408201527f2073686f756c64206e6f74206578636565642031303030300000000000000000606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f74207468652061646d696e604082015260600190565b6020808252601f908201527f4552433732313a20546f6b656e20697320616c7265616479206d696e74656400604082015260600190565b60208082526022908201527f45434453413a20696e76616c6964207369676e6174757265202776272076616c604082015261756560f01b606082015260800190565b60208082526022908201527f456e756d657261626c654d61703a20696e646578206f7574206f6620626f756e604082015261647360f01b606082015260800190565b60208082526025908201527f4552433732313a20546f74616c20666565206270732073686f756c6420626520604082015264031303030360dc1b606082015260800190565b6020808252818101527f4552433732313a206d696e7420746f20746865207a65726f2061646472657373604082015260600190565b6020808252602c908201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860408201526b34b9ba32b73a103a37b5b2b760a11b606082015260800190565b6020808252602c908201527f4552433732314d657461646174613a2055524920736574206f66206e6f6e657860408201526b34b9ba32b73a103a37b5b2b760a11b606082015260800190565b60208082526029908201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960408201526839903737ba1037bbb760b91b606082015260800190565b6020808252602f908201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60408201526e3732bc34b9ba32b73a103a37b5b2b760891b606082015260800190565b60208082526021908201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656040820152603960f91b606082015260800190565b60208082526021908201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206d696e74656040820152603960f91b606082015260800190565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b6020808252601d908201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604082015260600190565b6020808252603a908201527f526f79616c74793a205072696d61727920726f79616c7479207368617265207260408201527f6563697069656e742073686f756c642062652070726573656e74000000000000606082015260800190565b60208082526036908201527f526f79616c74793a20416d6f756e74206f6620726f79616c7479207265636970604082015275069656e74732063616e277420657863656564203130360541b606082015260800190565b6020808252603b908201527f526f79616c74793a205072696d61727920726f79616c7479207368617265206260408201527f70732076616c75652073686f756c6420626520706f7369746976650000000000606082015260800190565b60208082526030908201527f4552433732314275726e61626c653a2063616c6c6572206973206e6f74206f7760408201526f1b995c881b9bdc88185c1c1c9bdd995960821b606082015260800190565b60208082526032908201527f526f79616c74793a20546f74616c20726f79616c7479206270732073686f756c604082015271064206e6f74206578636565642031303030360741b606082015260800190565b60208082526022908201527f596f752063616e206f6e6c79206261746368206d696e742031303020746f6b656040820152616e7360f01b606082015260800190565b6020808252602f908201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560408201526e103937b632b9903337b91039b2b63360891b606082015260800190565b8151815260208201516040820190614178906141e4565b602083015292915050565b82815260408101614193836141e4565b60208301529392505050565b6040518181016001600160401b03811182821017156141bd57600080fd5b604052919050565b60006001600160401b038211156141da578081fd5b5060209081020190565b806003811061076357fe5b60005b8381101561420a5781810151838201526020016141f2565b8381111561125b5750506000910152565b6001600160a01b038116811461092657600080fd5b6001600160e01b03198116811461092657600080fdfe4552433732313a207472616e7366657220746f206e6f6e20455243373231526563656976657220696d706c656d656e7465724552433732313a206f776e657220717565727920666f72206e6f6e6578697374656e7420746f6b656ee2f4eaae4a9751e85a3e4a7b9587827a877f29914755229b07a7b2da98285f709f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a6a2646970667358221220711b2ad3ba3c5ab353b7dd06ad602fc3b77f1f7e23960f046333959e7916ffe364736f6c634300060c0033

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

00000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001000000000000000000000000003f231e09f6e4e97e8fec2f1e507414460c866f23000000000000000000000000d2e49cfd5c03a72a838a2fc6bb5f6b46927e731a000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000001a0000000000000000000000000000000000000000000000000000000000000001f4e65696c204261727265747420436f6c6c656374696f6e206279204d4f44410000000000000000000000000000000000000000000000000000000000000000114e45494c5f424152524554545f4d4f4441000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003468747470733a2f2f6170692e726566696e61626c652e636f6d2f636f6e74726163744d657461646174612f7b616464726573737d000000000000000000000000000000000000000000000000000000000000000000000000000000000000002068747470733a2f2f697066732e726566696e61626c652e636f6d2f697066732f

-----Decoded View---------------
Arg [0] : _name (string): Neil Barrett Collection by MODA
Arg [1] : _symbol (string): NEIL_BARRETT_MODA
Arg [2] : _root (address): 0x3F231E09f6e4e97E8fEc2F1E507414460C866F23
Arg [3] : _signer (address): 0xD2E49cfd5c03a72a838a2fC6bB5f6b46927e731A
Arg [4] : _contractURI (string): https://api.refinable.com/contractMetadata/{address}
Arg [5] : _baseURI (string): https://ipfs.refinable.com/ipfs/

-----Encoded View---------------
15 Constructor Arguments found :
Arg [0] : 00000000000000000000000000000000000000000000000000000000000000c0
Arg [1] : 0000000000000000000000000000000000000000000000000000000000000100
Arg [2] : 0000000000000000000000003f231e09f6e4e97e8fec2f1e507414460c866f23
Arg [3] : 000000000000000000000000d2e49cfd5c03a72a838a2fc6bb5f6b46927e731a
Arg [4] : 0000000000000000000000000000000000000000000000000000000000000140
Arg [5] : 00000000000000000000000000000000000000000000000000000000000001a0
Arg [6] : 000000000000000000000000000000000000000000000000000000000000001f
Arg [7] : 4e65696c204261727265747420436f6c6c656374696f6e206279204d4f444100
Arg [8] : 0000000000000000000000000000000000000000000000000000000000000011
Arg [9] : 4e45494c5f424152524554545f4d4f4441000000000000000000000000000000
Arg [10] : 0000000000000000000000000000000000000000000000000000000000000034
Arg [11] : 68747470733a2f2f6170692e726566696e61626c652e636f6d2f636f6e747261
Arg [12] : 63744d657461646174612f7b616464726573737d000000000000000000000000
Arg [13] : 0000000000000000000000000000000000000000000000000000000000000020
Arg [14] : 68747470733a2f2f697066732e726566696e61626c652e636f6d2f697066732f


Loading...
Loading
Loading...
Loading
[ Download: CSV Export  ]
[ Download: CSV Export  ]

A token is a representation of an on-chain or off-chain asset. The token page shows information such as price, total supply, holders, transfers and social links. Learn more about this page in our Knowledge Base.