1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
| pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; import {Pausable} from "@openzeppelin/contracts/security/Pausable.sol"; import {ReentrancyGuard} from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
interface GameNFTStake { function stakeFromMint(address user, uint256 tokenId) external; }
contract GameNFT is ERC1155, Ownable, Pausable, ReentrancyGuard { IERC20 public gameToken; GameNFTStake public stakeContract; address public daoAddress = 0xbA97a5F7b8B662Dc5B34a283faD741dDc615E690; address public burnAddress = 0x000000000000000000000000000000000000dEaD; address public preMintOwner;
uint256 public burnPercentage = 5; uint256 public daoPercentage = 90; uint256 public premiumPercentage = 10;
struct NFTType { uint256 price; bool pause; bool exist; } mapping(uint256 => NFTType) public nftTypes; uint256 public nftTypeCount;
event NFTMinted(address minter, address refer,uint256 tokenId, uint256 amount,uint256 price); event NewNFTTypeAdded(uint256 tokenId, uint256 price);
modifier onlyPreMintOwner() { require(msg.sender == preMintOwner, "only PreMintOwner"); _; }
constructor(address ownerAddress,address _gameToken) ERC1155("") Ownable(ownerAddress) { gameToken = IERC20(_gameToken); preMintOwner = ownerAddress; }
function renouncePreMintOwner() public onlyPreMintOwner { preMintOwner = address(0); }
function changeNFTPause(uint256 _tokenId,bool _pause) external onlyOwner{ NFTType storage nftType = nftTypes[_tokenId]; nftType.pause = _pause; }
function updateDaoAddress(address _daoAddress) external onlyOwner{ daoAddress = _daoAddress; }
function updateBurnPercentage(uint _burnPercentage) external onlyOwner{ burnPercentage = _burnPercentage; }
function updateDaoPercentage(uint _daoPercentage) external onlyOwner{ daoPercentage = _daoPercentage; }
function updatePremiumPercentage(uint _premiumPercentage) external onlyOwner{ premiumPercentage = _premiumPercentage; }
function addNFTType(uint256 _price) external onlyOwner { nftTypeCount++; nftTypes[nftTypeCount] = NFTType(_price, false,true); emit NewNFTTypeAdded(nftTypeCount, _price); }
function setStakingContract(address _stakingContract) external onlyOwner { stakeContract = GameNFTStake(_stakingContract); }
function mintPreNFT(uint256 _tokenId) external nonReentrant onlyPreMintOwner{ require(!nftTypes[_tokenId].pause, "NFT is paused"); require(nftTypes[_tokenId].exist, "NFT is not exist"); uint256 totalPrice = 0;
_mintNFT(totalPrice, burnAddress); _mint(msg.sender, _tokenId, 1, "");
emit NFTMinted(msg.sender,burnAddress, _tokenId, 1,totalPrice); }
function mintOriginNFT(uint256 _tokenId,address _referrer) external nonReentrant whenNotPaused{ require(!nftTypes[_tokenId].pause, "NFT is paused"); require(nftTypes[_tokenId].exist, "NFT is not exist"); uint256 totalPrice = nftTypes[_tokenId].price;
_mintNFT(totalPrice, _referrer);
_mint(msg.sender, _tokenId, 1, "");
emit NFTMinted(msg.sender,_referrer, _tokenId, 1,totalPrice); }
function mintPremiumNFT(uint256 _tokenId,address _referrer) external nonReentrant whenNotPaused{ require(!nftTypes[_tokenId].pause, "NFT is paused"); require(nftTypes[_tokenId].exist, "NFT is not exist"); uint256 totalPrice = nftTypes[_tokenId].price * (100 + premiumPercentage) / 100;
_mintNFT(totalPrice, _referrer); _mint(address(stakeContract), _tokenId, 1, ""); stakeContract.stakeFromMint(msg.sender,_tokenId);
emit NFTMinted(msg.sender,_referrer, _tokenId, 1,totalPrice); }
function _mintNFT(uint totalPrice,address _referrer) internal { require(gameToken.balanceOf(msg.sender) >= totalPrice, "Game is not enough"); require(gameToken.allowance(msg.sender, address(this)) >= totalPrice, "Game approve is not enough");
require(gameToken.transferFrom(msg.sender, address(this), totalPrice), "transfer fail"); uint256 burnAmount = (totalPrice * burnPercentage) / 100; uint256 daoAmount = (totalPrice * daoPercentage) / 100; uint256 referralAmount = totalPrice - burnAmount - daoAmount;
gameToken.transfer(burnAddress, burnAmount);
gameToken.transfer(daoAddress, daoAmount);
if (_referrer != address(0) && _referrer != msg.sender) { gameToken.transfer(_referrer, referralAmount); } else { gameToken.transfer(daoAddress, referralAmount); } }
function setURI(string memory newuri) external onlyOwner { _setURI(newuri); } }
|