Untitled

mail@pastecode.io avatar
unknown
plain_text
9 months ago
2.3 kB
6
Indexable
Never
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract LoyalNFT is ERC721, Ownable {
    using Counters for Counters.Counter;
    Counters.Counter private _tokenIdCounter;

    IERC20 token;
    
    uint256 MAX_SUPPLY = 14000;
    uint256 private constant PRIVATE_SALE_PRICE = 1000;
    uint256 private PUBLIC_SALE_PRICE = 1000;
    address private devAddress = 0xe42B1F6BE2DDb834615943F2b41242B172788E7E;

    uint256 totalSoldPrivate;
    uint256 totalSoldPublic;
    constructor(address _token) ERC721("LoyalNFT", "LNFT") Ownable(msg.sender) {
        token = IERC20(_token);
    }
    
    function mintPrivate() external{
        require(
            token.transferFrom(msg.sender, address(this), PRIVATE_SALE_PRICE),
            "Not enough ERC20 tokens transfered"
        );
        mint(msg.sender);
        totalSoldPrivate ++;

        dropNFTForTeam(totalSoldPrivate);
    }

    function mintPublic() external{
        uint256 currentPrice = getCurrentPublicPrice();
        require(
            token.transferFrom(msg.sender, address(this), currentPrice),
            "Not enough ERC20 tokens transfered"
        );

        mint(msg.sender);
        totalSoldPublic++;

        dropNFTForTeam(totalSoldPublic);
    }

    function withdraw() onlyOwner external{
        bool success = token.transferFrom(address(this),msg.sender,token.balanceOf(address(this)));
        require(success,"Transfer failed");
    }

    function mint(address _to) private {
        require(_tokenIdCounter.current() < MAX_SUPPLY,"Exceed mint quantity");
        _safeMint(_to, _tokenIdCounter.current());
        _tokenIdCounter.increment();
    }

    function dropNFTForTeam(uint256 totalSold) private{
        if(totalSold % 400 == 0){
             for(uint256 i=0; i< 40 ; i++){
                mint(devAddress);
            }   
        }
    }

    function getCurrentPublicPrice() private returns(uint256){
        if(totalSoldPublic % 40 == 0){
            PUBLIC_SALE_PRICE += 20;
        }
        return PUBLIC_SALE_PRICE;
    }
}
Leave a Comment