NativeTokenHelper.sol

NativeTokenHelper is a helper contract that enables users to interact with NFT sales contracts that accept wrapped native tokens (such as WETH) as payment. It wraps the native token and handles the interactions with INFTMintSale and INFTMintSaleMultiple contracts.

Key Functions


constructor
The constructor sets the address of the wrapped native token (WETH) to be used for the NFT sales.

approveSale
The approveSale function approves an NFT sale contract to spend the wrapped native tokens (WETH) on behalf of the NativeTokenHelper contract.

function approveSale(address sale) external {
    WETH.approve(sale, type(uint256).max);
}

buyNFT
The buyNFT function allows a user to buy an NFT from an _INFTMintSale_ contract using native tokens (e.g., Ether) as payment. It deposits the native tokens into the WETH contract, wrapping them into WETH, and then calls the buyNFT function of the _INFTMintSale_ contract for the specified recipient.

function buyNFT(INFTMintSale sale, address recipient) external payable {
    WETH.deposit{value: msg.value}();
    sale.buyNFT(recipient);
}

buyNFT (overloaded) The overloaded buyNFT function allows a user to buy an NFT from an _INFTMintSaleMultiple_ contract using native tokens (e.g., Ether) as payment. It deposits the native tokens into the WETH contract, wrapping them into WETH, and then calls the buyNFT function of the _INFTMintSaleMultiple_ contract for the specified recipient and tier.

function buyNFT(INFTMintSaleMultiple sale, address recipient, uint256 tier) external payable {
    WETH.deposit{value: msg.value}();
    sale.buyNFT(recipient, tier);
}

buyMultipleNFT
The buyMultipleNFT function allows a user to buy multiple NFTs from an _INFTMintSaleMultiple_ contract using native tokens (e.g., Ether) as payment. It deposits the native tokens into the WETH contract, wrapping them into WETH, and then calls the buyMultipleNFT function of the _INFTMintSaleMultiple_ contract for the specified recipient and array of tiers.

function buyMultipleNFT(INFTMintSaleMultiple sale, address recipient, uint256[] calldata tiersToBuy) external payable {
    WETH.deposit{value: msg.value}();
    sale.buyMultipleNFT(recipient, tiersToBuy);
}

Usage


To use NativeTokenHelper, deploy the contract with the address of the wrapped native token (WETH) as a parameter. Users can then approve an NFT sale contract using the approveSale function and interact with NFT sales contracts using the buyNFT and buyMultipleNFT functions.