编译器
0.8.17+commit.8df45f5f
文件 1 的 11: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 的 11: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");
} else if (error == RecoverError.InvalidSignatureV) {
revert("ECDSA: invalid signature 'v' 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);
}
if (v != 27 && v != 28) {
return (address(0), RecoverError.InvalidSignatureV);
}
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 的 11:IBaleNFT.sol
pragma solidity ^0.8.17;
interface IBaleNFT {
function mint(address walletAddress, uint256 quantity) external;
function totalSupply() external view returns (uint256);
}
文件 4 的 11:IERC165.sol
pragma solidity ^0.8.0;
interface IERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
文件 5 的 11:IERC20.sol
pragma solidity ^0.8.0;
interface IERC20 {
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
}
文件 6 的 11:IERC721.sol
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
interface IERC721 is IERC165 {
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
function balanceOf(address owner) external view returns (uint256 balance);
function ownerOf(uint256 tokenId) external view returns (address owner);
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external;
function transferFrom(
address from,
address to,
uint256 tokenId
) external;
function approve(address to, uint256 tokenId) external;
function setApprovalForAll(address operator, bool _approved) external;
function getApproved(uint256 tokenId) external view returns (address operator);
function isApprovedForAll(address owner, address operator) external view returns (bool);
}
文件 7 的 11:ITrunkNFT.sol
pragma solidity ^0.8.17;
interface ITrunkNFT {
function mint(address walletAddress, uint256 quantity) external;
function totalSupply() external view returns (uint256);
}
文件 8 的 11: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 的 11:ReentrancyGuard.sol
pragma solidity ^0.8.0;
abstract contract ReentrancyGuard {
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
modifier nonReentrant() {
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
_status = _ENTERED;
_;
_status = _NOT_ENTERED;
}
}
文件 10 的 11:SWMint.sol
pragma solidity ^0.8.17;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "./interfaces/ITrunkNFT.sol";
import "./interfaces/IBaleNFT.sol";
contract SWMint is ReentrancyGuard, Ownable {
using ECDSA for bytes32;
uint256 public MINT_PRICE = 0.197 ether;
IERC721 public passes;
ITrunkNFT public trunkNFT;
IBaleNFT public baleNFT;
string public tokenUriBase;
address public signer;
mapping(uint256 => bool) public tokensMinted;
mapping(uint256 => bool) public tokensClaimed;
mapping(address => bool) public walletsMinted;
bool public MINT_ENABLED = false;
bool public CLAIM_ENABLED = false;
uint256 public TRUNK_MINT_SUPPLY = 1500;
uint256 public TRUNK_CLAIM_SUPPLY = TRUNK_MINT_SUPPLY + 1600;
uint256 public BALE_SUPPLY = 100;
event EtherWithdrawn(address _to, uint256 _amount);
constructor(
IERC721 _passes,
ITrunkNFT _trunkNFT,
IBaleNFT _baleNFT,
address _signer
) {
passes = _passes;
trunkNFT = _trunkNFT;
baleNFT = _baleNFT;
signer = _signer;
}
modifier noContract() {
require(msg.sender == tx.origin, "Contract not allowed");
_;
}
function setTrunkNFT(ITrunkNFT _address) external onlyOwner {
trunkNFT = _address;
}
function setBaleNFT(IBaleNFT _adderss) external onlyOwner {
baleNFT = _adderss;
}
function setPassesAddress(IERC721 _address) external onlyOwner {
passes = _address;
}
function setMintPrice(uint256 _price) external onlyOwner {
MINT_PRICE = _price;
}
function setSigner(address _signer) external onlyOwner {
signer = _signer;
}
function setClaimEnabled(bool _bool) external onlyOwner {
CLAIM_ENABLED = _bool;
}
function setMintEnabled(bool _bool) external onlyOwner {
MINT_ENABLED = _bool;
}
function setTrunkMintSupply(uint256 _supply) external onlyOwner {
TRUNK_MINT_SUPPLY = _supply;
}
function setTrunkClaimSupply(uint256 _supply) external onlyOwner {
TRUNK_CLAIM_SUPPLY = _supply;
}
function setBaleSupply(uint256 _supply) external onlyOwner {
BALE_SUPPLY = _supply;
}
function getSupply() public view returns (uint256, uint256) {
return (baleNFT.totalSupply(), trunkNFT.totalSupply());
}
function _verify(
bytes memory _encoded,
bytes memory _signature,
address _signer
) public pure returns (bool) {
return keccak256(_encoded).toEthSignedMessageHash().recover(_signature) == _signer;
}
function mint(bytes memory _encoded, bytes memory _signature) external payable nonReentrant noContract {
require(MINT_ENABLED, "mint is not open");
(address wallet, address contractAddress, bool general, uint256[] memory tokens) = abi.decode(
_encoded,
(address, address, bool, uint256[])
);
require(wallet == msg.sender, "invalid wallet");
require(contractAddress == address(this), "invalid contract");
require(_verify(_encoded, _signature, signer), "invalid signature");
if (general == true) {
require(trunkNFT.totalSupply() + 1 <= TRUNK_MINT_SUPPLY, "mint is sold out");
require(MINT_PRICE == msg.value, "wrong ether amount sent");
require(!walletsMinted[msg.sender], "already minted");
walletsMinted[msg.sender] = true;
trunkNFT.mint(msg.sender, 1);
return;
} else {
require(trunkNFT.totalSupply() + tokens.length <= TRUNK_MINT_SUPPLY, "mint is sold out");
require(MINT_PRICE * tokens.length == msg.value, "wrong ether amount sent");
unchecked {
for (uint256 i = 0; i < tokens.length; i++) {
require(passes.ownerOf(tokens[i]) == msg.sender, "you do not own this token");
require(!tokensMinted[tokens[i]], "token has already minted");
tokensMinted[tokens[i]] = true;
}
}
trunkNFT.mint(msg.sender, tokens.length);
return;
}
}
function claim(bytes memory _encoded, bytes memory _signature) external nonReentrant noContract {
require(CLAIM_ENABLED, "claim is not open");
(address wallet, address contractAddress, uint256[] memory tokens, uint256 amountBales, uint256 amountTrunks) = abi
.decode(_encoded, (address, address, uint256[], uint256, uint256));
require(wallet == msg.sender, "invalid wallet");
require(contractAddress == address(this), "invalid contract");
require(_verify(_encoded, _signature, signer), "invalid signature");
require(baleNFT.totalSupply() + amountBales <= BALE_SUPPLY, "all bales have been claimed");
require(trunkNFT.totalSupply() + amountTrunks <= TRUNK_CLAIM_SUPPLY, "all trunks have been claimed");
unchecked {
for (uint256 i = 0; i < tokens.length; i++) {
require(passes.ownerOf(tokens[i]) == msg.sender, "you do not own this token");
require(!tokensClaimed[tokens[i]], "token has already claimed");
tokensClaimed[tokens[i]] = true;
}
}
if (amountBales > 0) baleNFT.mint(msg.sender, amountBales);
trunkNFT.mint(msg.sender, amountTrunks);
}
function withdrawAll(address recipient) public onlyOwner {
uint256 balance = address(this).balance;
payable(recipient).transfer(balance);
emit EtherWithdrawn(recipient, balance);
}
function withdrawAllViaCall(address payable _to) public onlyOwner {
uint256 balance = address(this).balance;
(bool sent, bytes memory data) = _to.call{value: balance}("");
require(sent, "Failed to send Ether");
emit EtherWithdrawn(_to, balance);
}
}
文件 11 的 11:Strings.sol
pragma solidity ^0.8.0;
library Strings {
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
function toString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
value /= 10;
}
return string(buffer);
}
function toHexString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0x00";
}
uint256 temp = value;
uint256 length = 0;
while (temp != 0) {
length++;
temp >>= 8;
}
return toHexString(value, length);
}
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] = _HEX_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);
}
}
{
"compilationTarget": {
"contracts/SWMint.sol": "SWMint"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"contract IERC721","name":"_passes","type":"address"},{"internalType":"contract ITrunkNFT","name":"_trunkNFT","type":"address"},{"internalType":"contract IBaleNFT","name":"_baleNFT","type":"address"},{"internalType":"address","name":"_signer","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_to","type":"address"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"EtherWithdrawn","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"},{"inputs":[],"name":"BALE_SUPPLY","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"CLAIM_ENABLED","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MINT_ENABLED","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MINT_PRICE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TRUNK_CLAIM_SUPPLY","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TRUNK_MINT_SUPPLY","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"_encoded","type":"bytes"},{"internalType":"bytes","name":"_signature","type":"bytes"},{"internalType":"address","name":"_signer","type":"address"}],"name":"_verify","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"baleNFT","outputs":[{"internalType":"contract IBaleNFT","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"_encoded","type":"bytes"},{"internalType":"bytes","name":"_signature","type":"bytes"}],"name":"claim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"_encoded","type":"bytes"},{"internalType":"bytes","name":"_signature","type":"bytes"}],"name":"mint","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"passes","outputs":[{"internalType":"contract IERC721","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IBaleNFT","name":"_adderss","type":"address"}],"name":"setBaleNFT","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_supply","type":"uint256"}],"name":"setBaleSupply","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_bool","type":"bool"}],"name":"setClaimEnabled","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_bool","type":"bool"}],"name":"setMintEnabled","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_price","type":"uint256"}],"name":"setMintPrice","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC721","name":"_address","type":"address"}],"name":"setPassesAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_signer","type":"address"}],"name":"setSigner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_supply","type":"uint256"}],"name":"setTrunkClaimSupply","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_supply","type":"uint256"}],"name":"setTrunkMintSupply","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract ITrunkNFT","name":"_address","type":"address"}],"name":"setTrunkNFT","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"signer","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tokenUriBase","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"tokensClaimed","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"tokensMinted","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"trunkNFT","outputs":[{"internalType":"contract ITrunkNFT","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"walletsMinted","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"}],"name":"withdrawAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"_to","type":"address"}],"name":"withdrawAllViaCall","outputs":[],"stateMutability":"nonpayable","type":"function"}]