{"sources":{"CompuzMarket.sol":{"content":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.24;\n\nimport \"@openzeppelin/contracts/token/ERC721/IERC721.sol\";\nimport \"@openzeppelin/contracts/interfaces/IERC2981.sol\";\nimport \"@openzeppelin/contracts/utils/ReentrancyGuard.sol\";\n\n/// @title Compuz Market\n/// @notice Minimal escrow marketplace for Compuz NFTs, priced in BNB.\n///  list(tokenId, price): NFT moves into this contract (approve it first).\n///  cancel(tokenId):      seller gets the NFT back.\n///  buy(tokenId):         pay exactly `price` in BNB; NFT goes to the buyer,\n///                        seller gets price minus the collection's ERC-2981 royalty (0 at launch).\n/// No marketplace fee. No owner, no admin keys. Deliberately not an ERC721Receiver,\n/// so stray safeTransferFrom calls into the market revert instead of locking NFTs.\ncontract CompuzMarket is ReentrancyGuard {\n    struct Listing {\n        address seller;\n        uint256 price;\n    }\n\n    IERC721 public immutable nft;\n\n    mapping(uint256 => Listing) public listings;\n    uint256[] private listed;                    // token ids currently listed\n    mapping(uint256 => uint256) private listedIdx; // tokenId => index+1\n    mapping(address => uint256) public pendingWithdrawals; // fallback if a push payment fails\n\n    event Listed(uint256 indexed tokenId, address indexed seller, uint256 price);\n    event Cancelled(uint256 indexed tokenId, address indexed seller);\n    event Sold(uint256 indexed tokenId, address indexed seller, address indexed buyer, uint256 price, uint256 royalty);\n    event Withdrawn(address indexed to, uint256 amount);\n\n    constructor(address nftAddress) {\n        nft = IERC721(nftAddress);\n    }\n\n    // ------------------------------------------------------------------ trading\n\n    function list(uint256 tokenId, uint256 price) external nonReentrant {\n        require(price > 0, \"price 0\");\n        require(nft.ownerOf(tokenId) == msg.sender, \"not owner\");\n        nft.transferFrom(msg.sender, address(this), tokenId);\n        listings[tokenId] = Listing(msg.sender, price);\n        listed.push(tokenId);\n        listedIdx[tokenId] = listed.length;\n        emit Listed(tokenId, msg.sender, price);\n    }\n\n    function cancel(uint256 tokenId) external nonReentrant {\n        Listing memory l = listings[tokenId];\n        require(l.seller == msg.sender, \"not seller\");\n        _remove(tokenId);\n        nft.transferFrom(address(this), msg.sender, tokenId);\n        emit Cancelled(tokenId, msg.sender);\n    }\n\n    function buy(uint256 tokenId) external payable nonReentrant {\n        Listing memory l = listings[tokenId];\n        require(l.seller != address(0), \"not listed\");\n        require(msg.value == l.price, \"wrong price\");\n        require(msg.sender != l.seller, \"own listing\");\n        _remove(tokenId);\n        nft.transferFrom(address(this), msg.sender, tokenId);\n\n        uint256 royalty;\n        address receiver;\n        try IERC2981(address(nft)).royaltyInfo(tokenId, l.price) returns (address r, uint256 amt) {\n            if (r != address(0) && amt > 0 && amt <= l.price) {\n                receiver = r;\n                royalty = amt;\n            }\n        } catch {}\n        if (royalty > 0) _pay(receiver, royalty);\n        _pay(l.seller, l.price - royalty);\n        emit Sold(tokenId, l.seller, msg.sender, l.price, royalty);\n    }\n\n    function withdraw() external nonReentrant {\n        uint256 amt = pendingWithdrawals[msg.sender];\n        require(amt > 0, \"nothing\");\n        pendingWithdrawals[msg.sender] = 0;\n        (bool ok, ) = payable(msg.sender).call{value: amt}(\"\");\n        require(ok, \"withdraw failed\");\n        emit Withdrawn(msg.sender, amt);\n    }\n\n    // ------------------------------------------------------------------ views\n\n    function listedCount() external view returns (uint256) {\n        return listed.length;\n    }\n\n    /// @notice Page through active listings.\n    function getListings(uint256 offset, uint256 limit)\n        external\n        view\n        returns (uint256[] memory ids, address[] memory sellers, uint256[] memory prices)\n    {\n        uint256 n = listed.length;\n        if (offset >= n) return (new uint256[](0), new address[](0), new uint256[](0));\n        uint256 end = offset + limit > n ? n : offset + limit;\n        uint256 len = end - offset;\n        ids = new uint256[](len);\n        sellers = new address[](len);\n        prices = new uint256[](len);\n        for (uint256 i = 0; i < len; i++) {\n            uint256 id = listed[offset + i];\n            ids[i] = id;\n            sellers[i] = listings[id].seller;\n            prices[i] = listings[id].price;\n        }\n    }\n\n    // ------------------------------------------------------------------ internal\n\n    function _remove(uint256 tokenId) private {\n        delete listings[tokenId];\n        uint256 idx = listedIdx[tokenId];\n        uint256 last = listed[listed.length - 1];\n        listed[idx - 1] = last;\n        listedIdx[last] = idx;\n        listed.pop();\n        delete listedIdx[tokenId];\n    }\n\n    function _pay(address to, uint256 amt) private {\n        (bool ok, ) = payable(to).call{value: amt, gas: 30000}(\"\");\n        if (!ok) pendingWithdrawals[to] += amt;\n    }\n}\n"},"@openzeppelin/contracts/token/ERC721/IERC721.sol":{"content":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC165} from \"../../utils/introspection/IERC165.sol\";\n\n/**\n * @dev Required interface of an ERC721 compliant contract.\n */\ninterface IERC721 is IERC165 {\n    /**\n     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.\n     */\n    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);\n\n    /**\n     * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.\n     */\n    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);\n\n    /**\n     * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.\n     */\n    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);\n\n    /**\n     * @dev Returns the number of tokens in ``owner``'s account.\n     */\n    function balanceOf(address owner) external view returns (uint256 balance);\n\n    /**\n     * @dev Returns the owner of the `tokenId` token.\n     *\n     * Requirements:\n     *\n     * - `tokenId` must exist.\n     */\n    function ownerOf(uint256 tokenId) external view returns (address owner);\n\n    /**\n     * @dev Safely transfers `tokenId` token from `from` to `to`.\n     *\n     * Requirements:\n     *\n     * - `from` cannot be the zero address.\n     * - `to` cannot be the zero address.\n     * - `tokenId` token must exist and be owned by `from`.\n     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.\n     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon\n     *   a safe transfer.\n     *\n     * Emits a {Transfer} event.\n     */\n    function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;\n\n    /**\n     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients\n     * are aware of the ERC721 protocol to prevent tokens from being forever locked.\n     *\n     * Requirements:\n     *\n     * - `from` cannot be the zero address.\n     * - `to` cannot be the zero address.\n     * - `tokenId` token must exist and be owned by `from`.\n     * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or\n     *   {setApprovalForAll}.\n     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon\n     *   a safe transfer.\n     *\n     * Emits a {Transfer} event.\n     */\n    function safeTransferFrom(address from, address to, uint256 tokenId) external;\n\n    /**\n     * @dev Transfers `tokenId` token from `from` to `to`.\n     *\n     * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721\n     * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must\n     * understand this adds an external call which potentially creates a reentrancy vulnerability.\n     *\n     * Requirements:\n     *\n     * - `from` cannot be the zero address.\n     * - `to` cannot be the zero address.\n     * - `tokenId` token must be owned by `from`.\n     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transferFrom(address from, address to, uint256 tokenId) external;\n\n    /**\n     * @dev Gives permission to `to` to transfer `tokenId` token to another account.\n     * The approval is cleared when the token is transferred.\n     *\n     * Only a single account can be approved at a time, so approving the zero address clears previous approvals.\n     *\n     * Requirements:\n     *\n     * - The caller must own the token or be an approved operator.\n     * - `tokenId` must exist.\n     *\n     * Emits an {Approval} event.\n     */\n    function approve(address to, uint256 tokenId) external;\n\n    /**\n     * @dev Approve or remove `operator` as an operator for the caller.\n     * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.\n     *\n     * Requirements:\n     *\n     * - The `operator` cannot be the address zero.\n     *\n     * Emits an {ApprovalForAll} event.\n     */\n    function setApprovalForAll(address operator, bool approved) external;\n\n    /**\n     * @dev Returns the account approved for `tokenId` token.\n     *\n     * Requirements:\n     *\n     * - `tokenId` must exist.\n     */\n    function getApproved(uint256 tokenId) external view returns (address operator);\n\n    /**\n     * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.\n     *\n     * See {setApprovalForAll}\n     */\n    function isApprovedForAll(address owner, address operator) external view returns (bool);\n}\n"},"@openzeppelin/contracts/utils/ReentrancyGuard.sol":{"content":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/ReentrancyGuard.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Contract module that helps prevent reentrant calls to a function.\n *\n * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\n * available, which can be applied to functions to make sure there are no nested\n * (reentrant) calls to them.\n *\n * Note that because there is a single `nonReentrant` guard, functions marked as\n * `nonReentrant` may not call one another. This can be worked around by making\n * those functions `private`, and then adding `external` `nonReentrant` entry\n * points to them.\n *\n * TIP: If you would like to learn more about reentrancy and alternative ways\n * to protect against it, check out our blog post\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\n */\nabstract contract ReentrancyGuard {\n    // Booleans are more expensive than uint256 or any type that takes up a full\n    // word because each write operation emits an extra SLOAD to first read the\n    // slot's contents, replace the bits taken up by the boolean, and then write\n    // back. This is the compiler's defense against contract upgrades and\n    // pointer aliasing, and it cannot be disabled.\n\n    // The values being non-zero value makes deployment a bit more expensive,\n    // but in exchange the refund on every call to nonReentrant will be lower in\n    // amount. Since refunds are capped to a percentage of the total\n    // transaction's gas, it is best to keep them low in cases like this one, to\n    // increase the likelihood of the full refund coming into effect.\n    uint256 private constant NOT_ENTERED = 1;\n    uint256 private constant ENTERED = 2;\n\n    uint256 private _status;\n\n    /**\n     * @dev Unauthorized reentrant call.\n     */\n    error ReentrancyGuardReentrantCall();\n\n    constructor() {\n        _status = NOT_ENTERED;\n    }\n\n    /**\n     * @dev Prevents a contract from calling itself, directly or indirectly.\n     * Calling a `nonReentrant` function from another `nonReentrant`\n     * function is not supported. It is possible to prevent this from happening\n     * by making the `nonReentrant` function external, and making it call a\n     * `private` function that does the actual work.\n     */\n    modifier nonReentrant() {\n        _nonReentrantBefore();\n        _;\n        _nonReentrantAfter();\n    }\n\n    function _nonReentrantBefore() private {\n        // On the first call to nonReentrant, _status will be NOT_ENTERED\n        if (_status == ENTERED) {\n            revert ReentrancyGuardReentrantCall();\n        }\n\n        // Any calls to nonReentrant after this point will fail\n        _status = ENTERED;\n    }\n\n    function _nonReentrantAfter() private {\n        // By storing the original value once again, a refund is triggered (see\n        // https://eips.ethereum.org/EIPS/eip-2200)\n        _status = NOT_ENTERED;\n    }\n\n    /**\n     * @dev Returns true if the reentrancy guard is currently set to \"entered\", which indicates there is a\n     * `nonReentrant` function in the call stack.\n     */\n    function _reentrancyGuardEntered() internal view returns (bool) {\n        return _status == ENTERED;\n    }\n}\n"},"@openzeppelin/contracts/interfaces/IERC2981.sol":{"content":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC2981.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC165} from \"../utils/introspection/IERC165.sol\";\n\n/**\n * @dev Interface for the NFT Royalty Standard.\n *\n * A standardized way to retrieve royalty payment information for non-fungible tokens (NFTs) to enable universal\n * support for royalty payments across all NFT marketplaces and ecosystem participants.\n */\ninterface IERC2981 is IERC165 {\n    /**\n     * @dev Returns how much royalty is owed and to whom, based on a sale price that may be denominated in any unit of\n     * exchange. The royalty amount is denominated and should be paid in that same unit of exchange.\n     */\n    function royaltyInfo(\n        uint256 tokenId,\n        uint256 salePrice\n    ) external view returns (address receiver, uint256 royaltyAmount);\n}\n"},"@openzeppelin/contracts/utils/introspection/IERC165.sol":{"content":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Interface of the ERC165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\n *\n * Implementers can declare support of contract interfaces, which can then be\n * queried by others ({ERC165Checker}).\n *\n * For an implementation, see {ERC165}.\n */\ninterface IERC165 {\n    /**\n     * @dev Returns true if this contract implements the interface defined by\n     * `interfaceId`. See the corresponding\n     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\n     * to learn more about how these ids are created.\n     *\n     * This function call must use less than 30 000 gas.\n     */\n    function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n"}},"abi":[{"type":"constructor","inputs":[{"name":"nftAddress","type":"address","internalType":"address"}],"stateMutability":"nonpayable"},{"name":"ReentrancyGuardReentrantCall","type":"error","inputs":[]},{"name":"Cancelled","type":"event","inputs":[{"name":"tokenId","type":"uint256","indexed":true,"internalType":"uint256"},{"name":"seller","type":"address","indexed":true,"internalType":"address"}],"anonymous":false},{"name":"Listed","type":"event","inputs":[{"name":"tokenId","type":"uint256","indexed":true,"internalType":"uint256"},{"name":"seller","type":"address","indexed":true,"internalType":"address"},{"name":"price","type":"uint256","indexed":false,"internalType":"uint256"}],"anonymous":false},{"name":"Sold","type":"event","inputs":[{"name":"tokenId","type":"uint256","indexed":true,"internalType":"uint256"},{"name":"seller","type":"address","indexed":true,"internalType":"address"},{"name":"buyer","type":"address","indexed":true,"internalType":"address"},{"name":"price","type":"uint256","indexed":false,"internalType":"uint256"},{"name":"royalty","type":"uint256","indexed":false,"internalType":"uint256"}],"anonymous":false},{"name":"Withdrawn","type":"event","inputs":[{"name":"to","type":"address","indexed":true,"internalType":"address"},{"name":"amount","type":"uint256","indexed":false,"internalType":"uint256"}],"anonymous":false},{"name":"buy","type":"function","inputs":[{"name":"tokenId","type":"uint256","internalType":"uint256"}],"outputs":[],"stateMutability":"payable"},{"name":"cancel","type":"function","inputs":[{"name":"tokenId","type":"uint256","internalType":"uint256"}],"outputs":[],"stateMutability":"nonpayable"},{"name":"getListings","type":"function","inputs":[{"name":"offset","type":"uint256","internalType":"uint256"},{"name":"limit","type":"uint256","internalType":"uint256"}],"outputs":[{"name":"ids","type":"uint256[]","internalType":"uint256[]"},{"name":"sellers","type":"address[]","internalType":"address[]"},{"name":"prices","type":"uint256[]","internalType":"uint256[]"}],"stateMutability":"view"},{"name":"list","type":"function","inputs":[{"name":"tokenId","type":"uint256","internalType":"uint256"},{"name":"price","type":"uint256","internalType":"uint256"}],"outputs":[],"stateMutability":"nonpayable"},{"name":"listedCount","type":"function","inputs":[],"outputs":[{"name":"","type":"uint256","internalType":"uint256"}],"stateMutability":"view"},{"name":"listings","type":"function","inputs":[{"name":"","type":"uint256","internalType":"uint256"}],"outputs":[{"name":"seller","type":"address","internalType":"address"},{"name":"price","type":"uint256","internalType":"uint256"}],"stateMutability":"view"},{"name":"nft","type":"function","inputs":[],"outputs":[{"name":"","type":"address","internalType":"contract IERC721"}],"stateMutability":"view"},{"name":"pendingWithdrawals","type":"function","inputs":[{"name":"","type":"address","internalType":"address"}],"outputs":[{"name":"","type":"uint256","internalType":"uint256"}],"stateMutability":"view"},{"name":"withdraw","type":"function","inputs":[],"outputs":[],"stateMutability":"nonpayable"}],"matchId":"57263999","creationMatch":"exact_match","runtimeMatch":"exact_match","verifiedAt":"2026-10-27T16:05:21Z","match":"exact_match","chainId":"56","address":"0xb67517EEC4B51517b4428a8556c06D7419C1c92E"}