编译器
0.8.18+commit.87f61d96
文件 1 的 12: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 的 12:ECDSA.sol
pragma solidity ^0.8.0;
import "../Strings.sol";
library ECDSA {
enum RecoverError {
NoError,
InvalidSignature,
InvalidSignatureLength,
InvalidSignatureS,
InvalidSignatureV
}
function _throwError(RecoverError error) private pure {
if (error == RecoverError.NoError) {
return;
} else if (error == RecoverError.InvalidSignature) {
revert("ECDSA: invalid signature");
} else if (error == RecoverError.InvalidSignatureLength) {
revert("ECDSA: invalid signature length");
} else if (error == RecoverError.InvalidSignatureS) {
revert("ECDSA: invalid signature 's' value");
}
}
function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return tryRecover(hash, v, r, s);
} else {
return (address(0), RecoverError.InvalidSignatureLength);
}
}
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, signature);
_throwError(error);
return recovered;
}
function tryRecover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address, RecoverError) {
bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
uint8 v = uint8((uint256(vs) >> 255) + 27);
return tryRecover(hash, v, r, s);
}
function recover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, r, vs);
_throwError(error);
return recovered;
}
function tryRecover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address, RecoverError) {
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
return (address(0), RecoverError.InvalidSignatureS);
}
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) {
return (address(0), RecoverError.InvalidSignature);
}
return (signer, RecoverError.NoError);
}
function recover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, v, r, s);
_throwError(error);
return recovered;
}
function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
}
function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s));
}
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
}
}
文件 3 的 12:HoodieMint.sol
pragma solidity ^0.8.18;
import {IERC721Mintable} from "./interfaces/IERC721Mintable.sol";
import {IERC1155Mintable} from "./interfaces/IERC1155Mintable.sol";
import {SupplyControl} from "./libraries/SupplyControl.sol";
import {LimitPerWallet} from "./libraries/LimitPerWallet.sol";
import {SignatureProtectedCrossmint} from "./libraries/SignatureProtectedCrossmint.sol";
import {RandomGenerator} from "./libraries/RandomGenerator.sol";
contract HoodieMint is SupplyControl, LimitPerWallet, SignatureProtectedCrossmint, RandomGenerator {
uint256 public constant RECEIPT_ID = 1;
IERC721Mintable public hoodiesContract;
IERC1155Mintable public receiptContract;
mapping(uint256 => uint256) private tokenMatrix;
mapping(address => bool) public allowedWithdrawers;
address private withdrawalReceiptAddress;
constructor(
uint256 _maxSupply,
address _signerAddress,
address _withdrawerAddress,
address _withdrawalReceiptAddress,
address _hoodiesContractAddress,
address _receiptContractAddress
) SupplyControl(_maxSupply) SignatureProtectedCrossmint(_signerAddress) {
allowedWithdrawers[_withdrawerAddress] = true;
withdrawalReceiptAddress = _withdrawalReceiptAddress;
hoodiesContract = IERC721Mintable(_hoodiesContractAddress);
receiptContract = IERC1155Mintable(_receiptContractAddress);
}
function ownerMint(address _recipient, uint256 _amount) external onlyOwner {
uint256 totalSupply = hoodiesContract.totalSupply();
_amount = getAvailableTokens(_amount, totalSupply);
_mint(_recipient, _amount, totalSupply);
}
function ownerMintWithIds(address _recipient, uint256[] memory _ids) external onlyOwner {
uint256 totalSupply = hoodiesContract.totalSupply();
for (uint256 i; i < _ids.length; i++) {
require(_ids[i] < maxSupply, "The id to mint can not be bigger than the max supply");
uint256 maxIndex = maxSupply - totalSupply;
flagIdAsUsed(_ids[i], maxIndex);
totalSupply++;
}
hoodiesContract.mint(_recipient, _ids);
uint256[] memory receiptIds = new uint256[](1);
uint256[] memory receiptAmounts = new uint256[](1);
receiptIds[0] = RECEIPT_ID;
receiptAmounts[0] = _ids.length;
receiptContract.mint(_recipient, receiptIds, receiptAmounts);
}
function mint(
address _recipient,
uint256 _amount,
uint256 _maxPerWallet,
uint256 _pricePerToken,
bytes calldata _signature
) external payable {
validateSignature(abi.encodePacked(_recipient, _maxPerWallet, _pricePerToken), _signature);
uint256 totalSupply = hoodiesContract.totalSupply();
_amount = getAvailableTokens(_amount, totalSupply);
_amount = getAvailableForWallet(_recipient, _amount, _maxPerWallet);
checkSentEther(_amount * _pricePerToken);
_mint(_recipient, _amount, totalSupply);
}
function _mint(address _recipient, uint256 _amount, uint256 _totalSupply) internal {
uint256[] memory ids = new uint256[](_amount);
for (uint256 i; i < ids.length; i++) {
ids[i] = getTokenToBeMinted(_totalSupply, maxSupply);
_totalSupply++;
}
hoodiesContract.mint(_recipient, ids);
uint256[] memory receiptIds = new uint256[](1);
uint256[] memory receiptAmounts = new uint256[](1);
receiptIds[0] = RECEIPT_ID;
receiptAmounts[0] = _amount;
receiptContract.mint(_recipient, receiptIds, receiptAmounts);
}
function getAvailableTokens() public view returns (uint256 total) {
(bool success, bytes memory totalSupply) = address(hoodiesContract).staticcall(
abi.encodeWithSignature("totalSupply()")
);
require(success, "Call to totalSupply failed");
total = maxSupply - abi.decode(totalSupply, (uint256));
}
function getTokenToBeMinted(uint256 _totalSupply, uint256 _maxSupply) internal returns (uint256) {
uint256 maxIndex = _maxSupply - _totalSupply;
uint256 random = getRandomNumber(maxIndex, _totalSupply);
uint256 tokenId = tokenMatrix[random];
if (tokenMatrix[random] == 0) {
tokenId = random;
}
flagIdAsUsed(random, maxIndex);
return tokenId;
}
function flagIdAsUsed(uint256 _id, uint256 _maxIndex) internal {
tokenMatrix[_maxIndex - 1] == 0 ? tokenMatrix[_id] = _maxIndex - 1 : tokenMatrix[_id] = tokenMatrix[
_maxIndex - 1
];
}
function checkSentEther(uint256 _totalPrice) internal {
require(msg.value >= _totalPrice, "HoodieMint: Not enough Ether provided to mint");
if (msg.value > _totalPrice) {
payable(msg.sender).transfer(msg.value - _totalPrice);
}
}
modifier onlyWithdrawerOrOwner() {
require(
allowedWithdrawers[msg.sender] || owner() == msg.sender,
"Access Protected: The caller is not the withdrawer"
);
_;
}
function withdraw() external onlyWithdrawerOrOwner {
(bool success, ) = address(withdrawalReceiptAddress).call{value: address(this).balance}("");
require(success, "HoodieMint: Transfer failed");
}
function addWithdrawer(address _withdrawerAddress) external onlyOwner {
allowedWithdrawers[_withdrawerAddress] = true;
}
function removeWithdrawer(address _withdrawerAddress) external onlyOwner {
allowedWithdrawers[_withdrawerAddress] = false;
}
function setWithdrawalReceipt(address _withdrawalReceiptAddress) external onlyOwner {
withdrawalReceiptAddress = _withdrawalReceiptAddress;
}
}
文件 4 的 12:IERC1155Mintable.sol
pragma solidity ^0.8.18;
interface IERC1155Mintable {
function mint(
address _to,
uint256[] memory _ids,
uint256[] memory _amounts
) external;
}
文件 5 的 12:IERC721Mintable.sol
pragma solidity ^0.8.18;
interface IERC721Mintable {
function mint(address _to, uint256[] memory _ids) external;
function totalSupply() external returns (uint256);
}
文件 6 的 12:LimitPerWallet.sol
pragma solidity ^0.8.18;
abstract contract LimitPerWallet {
mapping(address => uint256) public mintsPerWallet;
function getAvailableForWallet(
address _recipient,
uint256 _amount,
uint256 _maxPerWallet
) internal returns (uint256) {
if (_maxPerWallet == 0) {
return _amount;
}
if (mintsPerWallet[_recipient] + _amount > _maxPerWallet) {
_amount = _maxPerWallet - mintsPerWallet[_recipient];
}
require(_amount > 0, "LimitPerWallet: The caller address can not mint more tokens");
mintsPerWallet[_recipient] += _amount;
return _amount;
}
}
文件 7 的 12:Math.sol
pragma solidity ^0.8.0;
library Math {
enum Rounding {
Down,
Up,
Zero
}
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
function average(uint256 a, uint256 b) internal pure returns (uint256) {
return (a & b) + (a ^ b) / 2;
}
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
return a == 0 ? 0 : (a - 1) / b + 1;
}
function mulDiv(
uint256 x,
uint256 y,
uint256 denominator
) internal pure returns (uint256 result) {
unchecked {
uint256 prod0;
uint256 prod1;
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
if (prod1 == 0) {
return prod0 / denominator;
}
require(denominator > prod1);
uint256 remainder;
assembly {
remainder := mulmod(x, y, denominator)
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
uint256 twos = denominator & (~denominator + 1);
assembly {
denominator := div(denominator, twos)
prod0 := div(prod0, twos)
twos := add(div(sub(0, twos), twos), 1)
}
prod0 |= prod1 * twos;
uint256 inverse = (3 * denominator) ^ 2;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
result = prod0 * inverse;
return result;
}
}
function mulDiv(
uint256 x,
uint256 y,
uint256 denominator,
Rounding rounding
) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 result = 1 << (log2(a) >> 1);
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10**64) {
value /= 10**64;
result += 64;
}
if (value >= 10**32) {
value /= 10**32;
result += 32;
}
if (value >= 10**16) {
value /= 10**16;
result += 16;
}
if (value >= 10**8) {
value /= 10**8;
result += 8;
}
if (value >= 10**4) {
value /= 10**4;
result += 4;
}
if (value >= 10**2) {
value /= 10**2;
result += 2;
}
if (value >= 10**1) {
result += 1;
}
}
return result;
}
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);
}
}
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);
}
}
}
文件 8 的 12: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);
}
}
文件 9 的 12:RandomGenerator.sol
pragma solidity ^0.8.18;
abstract contract RandomGenerator {
function getRandomNumber(
uint256 _upper,
uint256 _variable
) internal view returns (uint256) {
uint256 random = uint256(
keccak256(
abi.encodePacked(
_variable,
blockhash(block.number - 1),
block.coinbase,
block.prevrandao,
msg.sender
)
)
);
return (random % _upper);
}
}
文件 10 的 12:SignatureProtectedCrossmint.sol
pragma solidity ^0.8.18;
import "@openzeppelin/contracts/access/Ownable.sol";
import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
abstract contract SignatureProtectedCrossmint is Ownable {
address public signerAddress;
constructor(address _signerAddress) {
signerAddress = _signerAddress;
}
function setSignerAddress(address _signerAddress) external onlyOwner {
signerAddress = _signerAddress;
}
function validateSignature(bytes memory packedParams, bytes calldata signature) internal view {
require(
ECDSA.recover(generateHash(packedParams), signature) == signerAddress,
"SignatureProtected: Invalid signature for the caller"
);
}
function generateHash(bytes memory packedParams) private view returns (bytes32) {
bytes32 _hash = keccak256(bytes.concat(abi.encodePacked(address(this)), packedParams));
bytes memory result = abi.encodePacked("\x19Ethereum Signed Message:\n32", _hash);
return keccak256(result);
}
}
文件 11 的 12:Strings.sol
pragma solidity ^0.8.0;
import "./math/Math.sol";
library Strings {
bytes16 private constant _SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
assembly {
mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
}
文件 12 的 12:SupplyControl.sol
pragma solidity ^0.8.18;
abstract contract SupplyControl {
uint256 public maxSupply;
constructor(uint256 _maxSupply) {
maxSupply = _maxSupply;
}
function getAvailableTokens(
uint256 _amountToMint,
uint256 _totalSupply
) internal view returns (uint256) {
uint256 availableTokens = maxSupply - _totalSupply;
require(availableTokens > 0, "SupplyControl: No tokens left to mint");
if (availableTokens < _amountToMint) {
return availableTokens;
}
return _amountToMint;
}
}
{
"compilationTarget": {
"contracts/HoodieMint.sol": "HoodieMint"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs",
"useLiteralContent": true
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"uint256","name":"_maxSupply","type":"uint256"},{"internalType":"address","name":"_signerAddress","type":"address"},{"internalType":"address","name":"_withdrawerAddress","type":"address"},{"internalType":"address","name":"_withdrawalReceiptAddress","type":"address"},{"internalType":"address","name":"_hoodiesContractAddress","type":"address"},{"internalType":"address","name":"_receiptContractAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"RECEIPT_ID","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_withdrawerAddress","type":"address"}],"name":"addWithdrawer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"allowedWithdrawers","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getAvailableTokens","outputs":[{"internalType":"uint256","name":"total","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"hoodiesContract","outputs":[{"internalType":"contract IERC721Mintable","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_recipient","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"uint256","name":"_maxPerWallet","type":"uint256"},{"internalType":"uint256","name":"_pricePerToken","type":"uint256"},{"internalType":"bytes","name":"_signature","type":"bytes"}],"name":"mint","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"mintsPerWallet","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_recipient","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"ownerMint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_recipient","type":"address"},{"internalType":"uint256[]","name":"_ids","type":"uint256[]"}],"name":"ownerMintWithIds","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"receiptContract","outputs":[{"internalType":"contract IERC1155Mintable","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_withdrawerAddress","type":"address"}],"name":"removeWithdrawer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_signerAddress","type":"address"}],"name":"setSignerAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_withdrawalReceiptAddress","type":"address"}],"name":"setWithdrawalReceipt","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"signerAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"}]