Last active
April 16, 2022 10:15
-
-
Save jahvi/acc40afc98f4c06045e2b47e94f66ca9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
import "erc721a/contracts/ERC721A.sol"; | |
import "erc721a/contracts/extensions/ERC721AQueryable.sol"; | |
contract Token is ERC721A, ERC721AQueryable { | |
enum TokenTypes { | |
None, | |
Fist, | |
Second, | |
Third | |
} | |
uint16 firstCount = 600; | |
uint16 secondCount = 300; | |
uint16 thirdCount = 100; | |
uint16 constant MAX_SUPPLY = 1000; | |
mapping(uint256 => TokenTypes) public tokenType; | |
constructor() ERC721A("Token", "T") {} | |
function mint(uint256 _quantity) external payable { | |
uint256 _totalSupply = _currentIndex; | |
uint256 _supplyCount = _totalSupply + _quantity; | |
require(_supplyCount <= MAX_SUPPLY, "Exceeds supply"); | |
unchecked { | |
for (uint256 i = _totalSupply; i < _supplyCount; ++i) { | |
uint256 _rand = random(); | |
if (_rand <= thirdCount) { | |
tokenType[i] = TokenTypes.Third; | |
thirdCount--; | |
} else if (_rand <= secondCount) { | |
tokenType[i] = TokenTypes.Second; | |
secondCount--; | |
} else if (_rand <= firstCount) { | |
tokenType[i] = TokenTypes.First; | |
firstCount--; | |
} | |
} | |
} | |
_safeMint(msg.sender, _quantity); | |
} | |
function random() internal view returns (uint256) { | |
uint256 _totalSupply = getLargestSupply(); | |
return | |
(uint256( | |
keccak256( | |
abi.encodePacked( | |
msg.sender, | |
block.difficulty, | |
block.timestamp, | |
_totalSupply | |
) | |
) | |
) % _totalSupply) + 1; | |
} | |
function getLargestSupply() internal view returns (uint16) { | |
if (firstCount >= secondCount && firstCount >= thirdCount) { | |
return firstCount; | |
} else if (studioCount >= firstCount && secondCount >= thirdCount) { | |
return secondCount; | |
} else { | |
return thirdCount; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment