{ "language": "Solidity", "sources": { "contracts/NeptunityEnglishAuction.sol": { "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.9;\n\nimport \"./interfaces/INeptunity.sol\";\nimport \"@openzeppelin/contracts/utils/Counters.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\n\n// ███ ██ ███████ ██████ ████████ ██ ██ ███ ██ ██ ████████ ██ ██\n// ████ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██ ██ ██\n// ██ ██ ██ █████ ██████ ██ ██ ██ ██ ██ ██ ██ ██ ████\n// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██\n// ██ ████ ███████ ██ ██ ██████ ██ ████ ██ ██ ██\n\ncontract NeptunityEnglishAuction is Ownable {\n using Counters for Counters.Counter;\n\n Counters.Counter private auctionId;\n // solhint-disable-next-line\n INeptunity private NeptunityERC721;\n\n uint256 private constant DURATION = 1 days; // How long an auction lasts for once the first bid has been received.\n uint256 private constant EXTENSION_DURATION = 15 minutes; // The window for auction extensions, any bid placed in the final 15 minutes of an auction will reset the time remaining to 15 minutes.\n uint256 private constant MIN_BID_RAISE = 50; // next bid should be 2% more than last price\n\n mapping(uint256 => Auction) private auctions; // The auction id for a specific NFT. This is deleted when an auction is finalized or canceled.\n\n /// @notice Stores the auction configuration for a specific NFT.\n struct Auction {\n uint256 tokenId;\n address payable seller; // auction beneficiary, needs to be payable in order to receive funds from the auction sale\n address payable bidder; // highest bidder, needs to be payable in order to receive refund in case of being outbid\n uint256 price; // reserve price or highest bid\n uint256 end; // The time at which this auction will not accept any new bids. This is `0` until the first bid is placed.\n }\n\n /**\n * @notice Emitted when an NFT is listed for auction.\n * @param seller The address of the seller.\n * @param tokenId The id of the NFT.\n * @param price The reserve price to kick off the auction.\n * @param auctionId The id of the auction that was created.\n */\n event Created(\n uint256 indexed tokenId,\n address indexed seller,\n uint256 indexed auctionId,\n uint256 price\n );\n\n /**\n * @notice Emitted when an auction is cancelled.\n * @dev This is only possible if the auction has not received any bids.\n * @param auctionId The id of the auction that was cancelled.\n */\n event Canceled(uint256 indexed auctionId);\n\n /**\n * @notice Emitted when a bid is placed.\n * @param bidder The address of the bidder.\n * @param tokenId nft id\n * @param auctionId The id of the auction this bid was for.\n * @param price The amount of the bid.\n * @param end The new end time of the auction (which may have been set or extended by this bid).\n */\n event Bid(\n address indexed bidder,\n uint256 indexed tokenId,\n uint256 indexed auctionId,\n uint256 price,\n uint256 end\n );\n\n /**\n * @notice Emitted when the auction's reserve price is changed.\n * @dev This is only possible if the auction has not received any bids.\n * @param auctionId The id of the auction that was updated.\n * @param price The new reserve price for the auction.\n */\n event Updated(uint256 indexed auctionId, uint256 price);\n\n /**\n * @notice Emitted when an auction that has already ended is finalized,\n * indicating that the NFT has been transferred and revenue from the sale distributed.\n * @dev The amount of the highest bid/final sale price for this auction\n * is `marketplace` + `creatorFee` + `sellerRev`.\n * @param tokenId nft id\n * @param bidder The address of the highest bidder that won the NFT.\n * @param seller The address of the seller.\n * @param auctionId The id of the auction that was finalized.\n * @param price wei amount sold for.\n */\n event Finalized(\n uint256 indexed tokenId,\n address indexed bidder,\n uint256 price,\n address seller,\n uint256 auctionId\n );\n\n /********************************/\n /*********** MODIFERS ***********/\n /********************************/\n\n modifier auctionRequirements(uint256 _auctionId) {\n Auction memory _auction = auctions[_auctionId];\n\n require(_auction.seller == msg.sender, \"must be auction creator\"); // implicitly also checks that the auction exists\n require(_auction.end == 0, \"auction already started\");\n _;\n }\n\n /**\n * @notice Creates an auction for the given NFT. The NFT is held in escrow until the auction is finalized or canceled.\n * @param _tokenId The id of the NFT.\n * @param _price The initial reserve price for the auction.\n */\n function createAuction(uint256 _tokenId, uint256 _price) external {\n require(_price > 0);\n\n auctionId.increment(); // start counter at 1\n\n NeptunityERC721.transferFrom(msg.sender, address(this), _tokenId);\n\n auctions[auctionId.current()] = Auction(\n _tokenId,\n payable(msg.sender), // // auction beneficiary, needs to be payable in order to receive funds from the auction sale\n payable(0), // bidder is only known once a bid has been placed. // highest bidder, needs to be payable in order to receive refund in case of being outbid\n _price, // The time at which this auction will not accept any new bids. This is `0` until the first bid is placed.\n 0 // end is only known once the reserve price is met,\n );\n\n emit Created(_tokenId, msg.sender, auctionId.current(), _price);\n }\n\n function finalize(uint256 _auctionId) external {\n Auction memory _auction = auctions[_auctionId];\n\n require(_auction.end > 0, \"auction not started\"); // there must be at least one bid higher than the reserve price in order to execute the trade, no bids mean no end time\n require(block.timestamp > _auction.end, \"auction in progress\");\n\n // Remove the auction.\n delete auctions[_auctionId];\n\n // transfer nft to auction winner\n NeptunityERC721.transferFrom(\n address(this),\n _auction.bidder,\n _auction.tokenId\n );\n // pay seller, royalties and fees\n\n _trade(_auction.seller, _auction.tokenId, _auction.price);\n\n emit Finalized(\n _auction.tokenId,\n _auction.bidder,\n _auction.price,\n _auction.seller,\n _auctionId\n );\n }\n\n /**\n * @notice Place a bid in an auction\n * @dev If this is the first bid on the auction, the countdown will begin. If there is already an outstanding bid, the previous bidder will be refunded at this time and if the bid is placed in the final moments of the auction, the countdown may be extended.\n * @param _auctionId The id of the auction to bid on\n */\n function placeBid(uint256 _auctionId) external payable {\n Auction storage _auction = auctions[_auctionId];\n\n require(_auction.price > 0, \"nonexistent auction\");\n\n if (_auction.bidder == address(0x0)) {\n require(msg.value > _auction.price, \"value < reserve price\");\n // if the auction price has been set but there is no bidder yet, set the auction timer. On the first bid, set the end to now + duration. Duration is always set to 24hrs so the below can't overflow.\n unchecked {\n _auction.end = block.timestamp + DURATION;\n }\n } else {\n require(block.timestamp < _auction.end, \"ended\");\n require(_auction.bidder != msg.sender, \"cannot bid twice\"); // We currently do not allow a bidder to increase their bid unless another user has outbid them first.\n require(msg.value > _auction.price); // the bid must be bigger than highest bid divided by `MIN_BID_RAISE`.\n // if there is less than 15 minutes left, increment end time by 15 more. EXTENSION_DURATION is always set to 15 minutes so the below can't overflow.\n if (block.timestamp + EXTENSION_DURATION > _auction.end) {\n unchecked {\n _auction.end += EXTENSION_DURATION;\n }\n }\n // if there is a previous highest bidder, refund the previous bid\n // solhint-disable-next-line avoid-low-level-calls\n (bool success, ) = payable(_auction.bidder).call{\n value: _auction.price\n }(\"\");\n require(success);\n }\n\n _auction.price = msg.value; // new highest bit\n _auction.bidder = payable(msg.sender); // new highest bidder\n\n emit Bid(\n msg.sender,\n _auction.tokenId,\n _auctionId,\n msg.value,\n _auction.end\n );\n }\n\n /**\n * @notice If an auction has been created but has not yet received bids, the reservePrice may be\n * changed by the seller.\n * @param _auctionId The id of the auction to change.\n * @param _price The new reserve price for this auction.\n */\n function updateAuction(uint256 _auctionId, uint256 _price)\n external\n auctionRequirements(_auctionId)\n {\n require(_price > 0, \"Price must be more than 0\"); // can't set to zero or else it will not be possible to take bids because the auction will be considered nonexistent.\n\n // Update the current reserve price.\n auctions[_auctionId].price = _price;\n\n emit Updated(_auctionId, _price);\n }\n\n /**\n * @notice If an auction has been created but has not yet received bids, it may be canceled by the seller.\n * @dev The NFT is transferred back to the owner unless there is still a buy price set.\n * @param _auctionId The id of the auction to cancel.\n */\n function cancelAuction(uint256 _auctionId)\n external\n auctionRequirements(_auctionId)\n {\n Auction memory _auction = auctions[_auctionId];\n\n delete auctions[_auctionId];\n\n NeptunityERC721.transferFrom(\n address(this),\n _auction.seller,\n _auction.tokenId\n );\n\n emit Canceled(_auctionId);\n }\n\n /**\n * @dev to pay royalties and sales amount\n */\n function _trade(\n address _seller,\n uint256 _tokenId,\n uint256 _price\n ) private {\n uint256 sellerAmount = _price;\n uint256 marketplaceAmount;\n uint256 royaltiesFee;\n bool success;\n\n // extract data from neptunitySate\n (\n address feeAccount,\n bool isSecondarySale,\n uint24 artistFee,\n uint24 marketplaceFee,\n address artist\n ) = NeptunityERC721.getStateInfo(_tokenId);\n\n marketplaceAmount = (sellerAmount * marketplaceFee) / 10000;\n sellerAmount -= marketplaceAmount; // subtracting primary or secondary fee amount\n // solhint-disable-next-line avoid-low-level-calls\n (success, ) = feeAccount.call{value: marketplaceAmount}(\"\"); // pay marketplaceFee\n // solhint-disable-next-line\n require(success);\n\n if (!isSecondarySale) {\n NeptunityERC721.setSecondarySale(_tokenId);\n } else {\n royaltiesFee = (sellerAmount * artistFee) / 10000; // Fee paid by the user that fills the order, a.k.a. msg.sender.\n sellerAmount -= royaltiesFee;\n\n // solhint-disable-next-line avoid-low-level-calls\n (success, ) = payable(artist).call{value: royaltiesFee}(\"\"); // transfer secondary sale fees to fee artist\n // solhint-disable-next-line reason-string\n require(success);\n }\n\n // solhint-disable-next-line avoid-low-level-calls\n (success, ) = _seller.call{value: sellerAmount}(\"\"); // pay the seller fee (price - marketplaceFee - royaltiesFee )\n // solhint-disable-next-line\n require(success);\n }\n\n /**\n * @dev Grants `DEFAULT_ADMIN_ROLE` to the account that deploys the contract.\n */\n constructor(address neptunityERC721) {\n require(neptunityERC721 != address(0), \"Invalid address\");\n\n NeptunityERC721 = INeptunity(neptunityERC721);\n }\n}\n" }, "contracts/interfaces/INeptunity.sol": { "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.9;\n\ninterface INeptunity {\n /**\n * @dev Transfers `tokenId` token from `from` to `to`.\n *\n * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.\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(\n address from,\n address to,\n uint256 tokenId\n ) external;\n\n function mint(\n string memory _tokenURI,\n address _to,\n uint24 _artistFee\n ) external;\n\n /**\n * @dev Returns the total amount of tokens stored by the contract.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns whether `tokenId` exists.\n *\n * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.\n *\n * Tokens start existing when they are minted (`_mint`),\n * and stop existing when they are burned (`_burn`).\n */\n function exists(uint256 tokenId) external view returns (bool);\n\n /**\n * @dev See {IERC721-ownerOf}.\n */\n function ownerOf(uint256 tokenId) external view returns (address);\n\n /**\n * @dev returns the artist wallet address for the token Id\n */\n function artists(uint256 _tokenId) external view returns (address);\n\n /**\n * @dev only either auction or marketplace contract can call it to set tokenId as secondary sale.\n */\n function setSecondarySale(uint256 _tokenId) external;\n\n /**\n * @dev returns basic information about the token, and marketplace*/\n function getStateInfo(uint256 _tokenId)\n external\n view\n returns (\n address,\n bool,\n uint24,\n uint24,\n address\n );\n}\n" }, "@openzeppelin/contracts/utils/Counters.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Counters.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @title Counters\n * @author Matt Condon (@shrugs)\n * @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number\n * of elements in a mapping, issuing ERC721 ids, or counting request ids.\n *\n * Include with `using Counters for Counters.Counter;`\n */\nlibrary Counters {\n struct Counter {\n // This variable should never be directly accessed by users of the library: interactions must be restricted to\n // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add\n // this feature: see https://github.com/ethereum/solidity/issues/4637\n uint256 _value; // default: 0\n }\n\n function current(Counter storage counter) internal view returns (uint256) {\n return counter._value;\n }\n\n function increment(Counter storage counter) internal {\n unchecked {\n counter._value += 1;\n }\n }\n\n function decrement(Counter storage counter) internal {\n uint256 value = counter._value;\n require(value > 0, \"Counter: decrement overflow\");\n unchecked {\n counter._value = value - 1;\n }\n }\n\n function reset(Counter storage counter) internal {\n counter._value = 0;\n }\n}\n" }, "@openzeppelin/contracts/access/Ownable.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n address private _owner;\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the deployer as the initial owner.\n */\n constructor() {\n _transferOwnership(_msgSender());\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n _checkOwner();\n _;\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function owner() public view virtual returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if the sender is not the owner.\n */\n function _checkOwner() internal view virtual {\n require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions anymore. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby removing any functionality that is only available to the owner.\n */\n function renounceOwnership() public virtual onlyOwner {\n _transferOwnership(address(0));\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public virtual onlyOwner {\n require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n _transferOwnership(newOwner);\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Internal function without access restriction.\n */\n function _transferOwnership(address newOwner) internal virtual {\n address oldOwner = _owner;\n _owner = newOwner;\n emit OwnershipTransferred(oldOwner, newOwner);\n }\n}\n" }, "@openzeppelin/contracts/utils/Context.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n}\n" } }, "settings": { "optimizer": { "enabled": false, "runs": 200 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "libraries": {} } }