NFTMintSale.sol

NFTMintSale is a contract that handles the sale and minting of NFTs. It allows users to buy NFTs using a specified payment token and mints the NFTs using a VibeERC721 contract. The contract also handles the distribution of sale proceeds and fees.

Inherited Contracts


Ownable

NFTMintSale inherits OpenZeppelin's Ownable contract, which provides basic authorization control functions such as onlyOwner modifier and transferring contract ownership.

Key Functions


init
The init function initializes the NFTMintSale contract with the necessary parameters such as maximum mint count, sale start and end times, NFT price, and payment token. It also sets the VibeFees for the sale.

    function init(bytes calldata data) public payable {
        (address proxy, uint64 maxMint_, uint32 beginTime_, uint32 endTime_, uint128 price_, IERC20 paymentToken_, address owner_) = abi.decode(data, (address, uint64, uint32, uint32, uint128, IERC20, address));

setVibeFees
The setVibeFees function allows setting the fees for the sale, including the Vibe treasury address and the fee percentage. It can only be called by the master contract owner.

    function setVibeFees(address vibeTreasury_, uint96 feeTake_) external onlyMasterContractOwner {
        fees = VibeFees(vibeTreasury_, feeTake_);
    }

_preBuyCheck The _preBuyCheck internal function can be overridden in derived contracts to add custom checks before minting an NFT.

_buyNFT The _buyNFT internal function mints an NFT for the specified recipient. It performs a pre-buy check and requires that the current time is within the sale period and the total supply of NFTs is below the maximum mint count.

buyNFT
The buyNFT function allows a user to buy and mint an NFT for a specified recipient. It calls the _buyNFT internal function and transfers the required payment amount from the user to the contract.

    function buyNFT(address recipient) public {
        _buyNFT(recipient);
        paymentToken.safeTransferFrom(msg.sender, address(this), price);
    }

buyMultipleNFT
The buyMultipleNFT function allows a user to buy and mint multiple NFTs for a specified recipient. It calls the _buyNFT internal function for each NFT and transfers the required payment amount from the user to the contract.

    function buyMultipleNFT(address recipient, uint256 number) public {
        for (uint i; i < number; i++) {
            _buyNFT(recipient);
        }
        paymentToken.safeTransferFrom(msg.sender, address(this), price * number);
    }

removeTokensAndReclaimOwnership The removeTokensAndReclaimOwnership function allows the owner to end the sale early or after the sale has ended, distribute the proceeds and fees, and renounce minter role of the NFT contract. It also checks if the proceeds recipient is a contract that supports the IDistributor interface and calls the distribute function if it does.

function removeTokensAndReclaimOwnership(address proceedRecipient) external onlyOwner {
    if(block.timestamp < endTime){
        endTime = uint32(block.timestamp);

extendEndTime The extendEndTime function allows the owner to extend the sale end time. It requires that the new end time is in the future.

function extendEndTime(uint32 newEndTime) external onlyOwner {
    require(newEndTime > block.timestamp);
    endTime = newEndTime;

Events


Created
The Created event is emitted when the contract is initialized with the sale parameters.

LogNFTBuy
The LogNFTBuy event is emitted when an NFT is bought and minted. It includes the recipient address and the tokenId.

SaleExtended
The SaleExtended event is emitted when the sale end time is extended. It includes the new end time.

SaleEnded The SaleEnded event is emitted when the sale ends as per the original schedule.

SaleEndedEarly
The SaleEndedEarly event is emitted when the sale is ended early by the contract owner.

TokensClaimed
The TokensClaimed event is emitted when the sale proceeds are claimed. It includes the total amount, fee, and proceed recipient address.

Usage
To use NFTMintSale, deploy the contract and initialize it with the necessary parameters such as maximum mint count, sale start and end times, NFT price, and payment token. Users can then buy NFTs using the buyNFT or buyMultipleNFT functions during the sale period. The contract owner can extend the sale end time using the extendEndTime

Usage


To use NFTMintSale, deploy the contract and initialize it with the necessary parameters such as maximum mint count, sale start and end times, NFT price, and payment token. Users can then buy NFTs using the buyNFT or buyMultipleNFT functions during the sale period. The contract owner can extend the sale end time using the extendEndTime