编译器
0.8.17+commit.8df45f5f
文件 1 的 4:Context.sol
pragma solidity ^0.8.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
文件 2 的 4:MerkleProof.sol
pragma solidity ^0.8.0;
library MerkleProof {
function verify(
bytes32[] memory proof,
bytes32 root,
bytes32 leaf
) internal pure returns (bool) {
return processProof(proof, leaf) == root;
}
function verifyCalldata(
bytes32[] calldata proof,
bytes32 root,
bytes32 leaf
) internal pure returns (bool) {
return processProofCalldata(proof, leaf) == root;
}
function processProof(bytes32[] memory proof, bytes32 leaf) internal pure returns (bytes32) {
bytes32 computedHash = leaf;
for (uint256 i = 0; i < proof.length; i++) {
computedHash = _hashPair(computedHash, proof[i]);
}
return computedHash;
}
function processProofCalldata(bytes32[] calldata proof, bytes32 leaf) internal pure returns (bytes32) {
bytes32 computedHash = leaf;
for (uint256 i = 0; i < proof.length; i++) {
computedHash = _hashPair(computedHash, proof[i]);
}
return computedHash;
}
function multiProofVerify(
bytes32[] memory proof,
bool[] memory proofFlags,
bytes32 root,
bytes32[] memory leaves
) internal pure returns (bool) {
return processMultiProof(proof, proofFlags, leaves) == root;
}
function multiProofVerifyCalldata(
bytes32[] calldata proof,
bool[] calldata proofFlags,
bytes32 root,
bytes32[] memory leaves
) internal pure returns (bool) {
return processMultiProofCalldata(proof, proofFlags, leaves) == root;
}
function processMultiProof(
bytes32[] memory proof,
bool[] memory proofFlags,
bytes32[] memory leaves
) internal pure returns (bytes32 merkleRoot) {
uint256 leavesLen = leaves.length;
uint256 totalHashes = proofFlags.length;
require(leavesLen + proof.length - 1 == totalHashes, "MerkleProof: invalid multiproof");
bytes32[] memory hashes = new bytes32[](totalHashes);
uint256 leafPos = 0;
uint256 hashPos = 0;
uint256 proofPos = 0;
for (uint256 i = 0; i < totalHashes; i++) {
bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
bytes32 b = proofFlags[i] ? leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++] : proof[proofPos++];
hashes[i] = _hashPair(a, b);
}
if (totalHashes > 0) {
return hashes[totalHashes - 1];
} else if (leavesLen > 0) {
return leaves[0];
} else {
return proof[0];
}
}
function processMultiProofCalldata(
bytes32[] calldata proof,
bool[] calldata proofFlags,
bytes32[] memory leaves
) internal pure returns (bytes32 merkleRoot) {
uint256 leavesLen = leaves.length;
uint256 totalHashes = proofFlags.length;
require(leavesLen + proof.length - 1 == totalHashes, "MerkleProof: invalid multiproof");
bytes32[] memory hashes = new bytes32[](totalHashes);
uint256 leafPos = 0;
uint256 hashPos = 0;
uint256 proofPos = 0;
for (uint256 i = 0; i < totalHashes; i++) {
bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
bytes32 b = proofFlags[i] ? leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++] : proof[proofPos++];
hashes[i] = _hashPair(a, b);
}
if (totalHashes > 0) {
return hashes[totalHashes - 1];
} else if (leavesLen > 0) {
return leaves[0];
} else {
return proof[0];
}
}
function _hashPair(bytes32 a, bytes32 b) private pure returns (bytes32) {
return a < b ? _efficientHash(a, b) : _efficientHash(b, a);
}
function _efficientHash(bytes32 a, bytes32 b) private pure returns (bytes32 value) {
assembly {
mstore(0x00, a)
mstore(0x20, b)
value := keccak256(0x00, 0x40)
}
}
}
文件 3 的 4:NAGOMIMinterHalfYear.sol
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
interface iNAGOMIHappyBirthday {
function externalMint(address _to, uint256 _id, uint256 _amount) external;
function sumOfTotalSupply() external view returns (uint256);
function totalSupply(uint256 id) external view returns (uint256);
}
contract NAGOMIMinterHalfYear is Ownable {
iNAGOMIHappyBirthday public NAGOMIHappyBirthday;
bytes32 public freeMintMerkleRoot;
bytes32 public allowlistMintMerkleRoot;
uint256 public constant MAX_SUPPLY = 1299;
uint256 public constant TOKEN_ID_ZERO_MAX_SUPPLY = 433;
uint256 public constant TOKEN_ID_ONE_MAX_SUPPLY = 433;
uint256 public constant TOKEN_ID_TWO_MAX_SUPPLY = 433;
uint256 public constant MINT_COST = 0.005 ether;
uint256[4] public withdrawShare = [40, 20, 20, 20];
address[4] public withdrawAddress = [
0x445513cd8ECA1E98b0C70f1Cdc52C4d986dDC987,
0xF185B303775958C93AcFFa1231A8d14b38c049ac,
0xCF8706F4aF69310c7372B5e9e91EF5fbc8d02C5a,
0xe273eF71274926b7Dec32546Af84dB6e37eFADbF
];
mapping(address => uint256) public freeMintCount;
mapping(address => uint256) public allowlistMintCount;
enum SalePhase {
Locked,
FreeMint,
AllowlistMint,
PublicMint
}
SalePhase public phase = SalePhase.Locked;
event Minted(address _to, uint256 _amount);
event PhaseChanged(SalePhase _phase);
constructor() {}
modifier callerIsUser() {
require(tx.origin == msg.sender, "called by contract");
_;
}
modifier notZeroMint(uint256 _mintAmount) {
require(_mintAmount != 0, "mintAmount is zero");
_;
}
modifier enoughEth(uint256 _mintAmount) {
require(MINT_COST * _mintAmount <= msg.value, "not enough eth");
_;
}
modifier notOverMaxSupply(uint256 _mintAmount) {
require(_mintAmount + sumOfTotalSupply() <= MAX_SUPPLY, "exceeds max supply");
_;
}
function setWithdrawAddress(uint256 _index, address _withdrawAddress) external onlyOwner {
require(_withdrawAddress != address(0), "withdrawAddress can't be 0");
withdrawAddress[_index] = _withdrawAddress;
}
function setWithdrawShare(uint256 _index, uint256 _withdrawShare) external onlyOwner {
withdrawShare[_index] = _withdrawShare;
}
function withdraw() external payable onlyOwner {
uint256 initialBalance = address(this).balance;
for (uint256 index; index < withdrawAddress.length; index++) {
require(withdrawAddress[index] != address(0), "withdrawAddress can't be 0");
uint256 sharedAmount = (initialBalance * withdrawShare[index]) / 100;
(bool sent,) = payable(withdrawAddress[index]).call{value: sharedAmount}("");
require(sent, "failed to withdraw");
}
}
function freeMint(uint256 _mintAmount, bytes32[] calldata _merkleProof)
external
callerIsUser
notZeroMint(_mintAmount)
notOverMaxSupply(_mintAmount)
{
require(phase == SalePhase.FreeMint, "FreeMint is disabled");
bytes32 leaf = keccak256(abi.encodePacked(msg.sender));
require(MerkleProof.verify(_merkleProof, freeMintMerkleRoot, leaf), "Invalid Merkle Proof");
require(freeMintCount[msg.sender] + _mintAmount <= 1, "exceeds allocation");
randomMint(msg.sender, _mintAmount);
unchecked {
freeMintCount[msg.sender] += _mintAmount;
}
}
function allowlistMint(uint256 _mintAmount, bytes32[] calldata _merkleProof)
external
payable
callerIsUser
notZeroMint(_mintAmount)
enoughEth(_mintAmount)
notOverMaxSupply(_mintAmount)
{
require(phase == SalePhase.AllowlistMint, "AllowlistMint is disabled");
bytes32 leaf = keccak256(abi.encodePacked(msg.sender));
require(MerkleProof.verify(_merkleProof, allowlistMintMerkleRoot, leaf), "Invalid Merkle Proof");
require(allowlistMintCount[msg.sender] + _mintAmount <= 2, "exceeds allocation");
randomMint(msg.sender, _mintAmount);
unchecked {
allowlistMintCount[msg.sender] += _mintAmount;
}
}
function publicMint(uint256 _mintAmount)
external
payable
callerIsUser
notZeroMint(_mintAmount)
enoughEth(_mintAmount)
notOverMaxSupply(_mintAmount)
{
require(phase == SalePhase.PublicMint, "PublicMint is disabled");
randomMint(msg.sender, _mintAmount);
}
function adminMint(address[] calldata _airdropAddresses, uint256[] calldata _userMintAmount) external onlyOwner {
require(_airdropAddresses.length == _userMintAmount.length, "array length mismatch");
uint256 _totalMintAmmount;
for (uint256 i = 0; i < _userMintAmount.length; i++) {
require(_userMintAmount[i] > 0, "amount 0 address exists!");
unchecked {
_totalMintAmmount += _userMintAmount[i];
}
require(_totalMintAmmount + sumOfTotalSupply() <= MAX_SUPPLY, "exceeds max supply");
randomMint(_airdropAddresses[i], _userMintAmount[i]);
}
}
function randomMint(address _to, uint256 _amount) private {
uint256 remaining;
for (uint256 i = 0; i < _amount; i++) {
unchecked {
remaining = MAX_SUPPLY - sumOfTotalSupply();
}
uint256 random = uint256(keccak256(abi.encodePacked(block.timestamp, msg.sender))) % remaining;
if (0 <= random && random < (TOKEN_ID_ZERO_MAX_SUPPLY - NAGOMIHappyBirthday.totalSupply(0))) {
NAGOMIHappyBirthday.externalMint(_to, 0, 1);
} else if (
(TOKEN_ID_ZERO_MAX_SUPPLY - NAGOMIHappyBirthday.totalSupply(0)) <= random
&& random
< (
(TOKEN_ID_ZERO_MAX_SUPPLY - NAGOMIHappyBirthday.totalSupply(0))
+ (TOKEN_ID_ONE_MAX_SUPPLY - NAGOMIHappyBirthday.totalSupply(1))
)
) {
NAGOMIHappyBirthday.externalMint(_to, 1, 1);
} else {
NAGOMIHappyBirthday.externalMint(_to, 2, 1);
}
}
emit Minted(_to, _amount);
}
function setNAGOMIHappyBirthday(address _contractAddress) external onlyOwner {
NAGOMIHappyBirthday = iNAGOMIHappyBirthday(_contractAddress);
}
function setPhase(SalePhase _phase) external onlyOwner {
if (_phase != phase) {
phase = _phase;
emit PhaseChanged(_phase);
}
}
function setFreeMintMerkleRoot(bytes32 _merkleRoot) public onlyOwner {
freeMintMerkleRoot = _merkleRoot;
}
function setAllowlistMintMerkleRoot(bytes32 _merkleRoot) public onlyOwner {
allowlistMintMerkleRoot = _merkleRoot;
}
function sumOfTotalSupply() public view returns (uint256) {
return NAGOMIHappyBirthday.sumOfTotalSupply();
}
}
文件 4 的 4:Ownable.sol
pragma solidity ^0.8.0;
import "../utils/Context.sol";
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
_transferOwnership(_msgSender());
}
modifier onlyOwner() {
_checkOwner();
_;
}
function owner() public view virtual returns (address) {
return _owner;
}
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
{
"compilationTarget": {
"contracts/NAGOMIMinterHalfYear.sol": "NAGOMIMinterHalfYear"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_to","type":"address"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"Minted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"enum NAGOMIMinterHalfYear.SalePhase","name":"_phase","type":"uint8"}],"name":"PhaseChanged","type":"event"},{"inputs":[],"name":"MAX_SUPPLY","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MINT_COST","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"NAGOMIHappyBirthday","outputs":[{"internalType":"contract iNAGOMIHappyBirthday","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TOKEN_ID_ONE_MAX_SUPPLY","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TOKEN_ID_TWO_MAX_SUPPLY","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TOKEN_ID_ZERO_MAX_SUPPLY","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"_airdropAddresses","type":"address[]"},{"internalType":"uint256[]","name":"_userMintAmount","type":"uint256[]"}],"name":"adminMint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_mintAmount","type":"uint256"},{"internalType":"bytes32[]","name":"_merkleProof","type":"bytes32[]"}],"name":"allowlistMint","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"allowlistMintCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"allowlistMintMerkleRoot","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_mintAmount","type":"uint256"},{"internalType":"bytes32[]","name":"_merkleProof","type":"bytes32[]"}],"name":"freeMint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"freeMintCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"freeMintMerkleRoot","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"phase","outputs":[{"internalType":"enum NAGOMIMinterHalfYear.SalePhase","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_mintAmount","type":"uint256"}],"name":"publicMint","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_merkleRoot","type":"bytes32"}],"name":"setAllowlistMintMerkleRoot","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_merkleRoot","type":"bytes32"}],"name":"setFreeMintMerkleRoot","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_contractAddress","type":"address"}],"name":"setNAGOMIHappyBirthday","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"enum NAGOMIMinterHalfYear.SalePhase","name":"_phase","type":"uint8"}],"name":"setPhase","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_index","type":"uint256"},{"internalType":"address","name":"_withdrawAddress","type":"address"}],"name":"setWithdrawAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_index","type":"uint256"},{"internalType":"uint256","name":"_withdrawShare","type":"uint256"}],"name":"setWithdrawShare","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"sumOfTotalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdraw","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"withdrawAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"withdrawShare","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]