编译器
0.8.19+commit.7dd6d404
文件 1 的 5: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));
}
}
文件 2 的 5:KillaCubsMinter.sol
pragma solidity ^0.8.19;
import "./SuperOwnable.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
enum MintPhaseType {
Claim,
Redeem,
Private,
Holders,
Public
}
struct MintPhase {
MintPhaseType phaseType;
uint32 start;
uint32 end;
address signer;
}
struct MintCounters {
uint16 linked;
uint16 batched;
uint16 redeems;
uint16 stakes;
}
struct Wallet {
uint16 balance;
uint16 stakes;
uint16 linkedMints;
uint16 batchedMints;
uint16 allowlistMints;
uint16 privateMints;
uint16 holderMints;
uint16 redeems;
}
interface IKillaPasses {
function burn(uint256 typeId, address owner, uint256 n) external;
}
interface IKillaCubs {
function mint(address owner, uint256[] calldata ids, bool staked) external;
function mint(address owner, uint16 n, bool staked) external;
function mintRedeemed(address owner, uint16 n, bool staked) external;
function useAllowance(
address sender,
address main,
uint256 n,
bool holders,
uint256 allowance
) external;
function counters() external returns (MintCounters memory);
function wallets(address) external returns (Wallet memory);
}
interface IERC721 {
function ownerOf(uint256 tokenId) external view returns (address owner);
}
contract KillaCubsMinter is SuperOwnable {
using ECDSA for bytes32;
uint16 constant MINTABLE_SUPPLY = 8888 - 3333 - 333;
uint256 public mintPrice = 0.25 ether;
uint256 public publicMaxPerWallet = 3;
IKillaCubs public immutable cubs;
IERC721 public immutable bears;
IKillaPasses public immutable passes;
IERC721 public immutable kilton;
IERC721 public immutable labs;
mapping(MintPhaseType => MintPhase) public mintPhases;
error NotAllowed();
error UnknownMintPhase();
error MintPhaseNotStarted();
error MintPhaseEnded();
error NotEnoughEth();
error Overflow();
constructor(
address cubsAddress,
address bearsAddress,
address passesAddress,
address kiltonAddress,
address labsAddress,
address superOwner
) SuperOwnable(superOwner) {
cubs = IKillaCubs(cubsAddress);
bears = IERC721(bearsAddress);
passes = IKillaPasses(passesAddress);
kilton = IERC721(kiltonAddress);
labs = IERC721(labsAddress);
}
function claim(uint256[] calldata ids, bool staked) public payable {
for (uint256 i = 0; i < ids.length; i++) {
uint256 id = ids[i];
if (
bears.ownerOf(id) != msg.sender &&
kilton.ownerOf(id) != msg.sender &&
labs.ownerOf(id) != msg.sender
) revert NotAllowed();
}
cubs.mint(msg.sender, ids, staked);
}
function redeem(
uint16 n,
bool staked
) external checkPhase(MintPhaseType.Redeem) {
passes.burn(1, msg.sender, n);
cubs.mintRedeemed(msg.sender, n, staked);
if (cubs.counters().redeems > 333) revert Overflow();
}
function mintPrivate(
uint16 n,
MintPhaseType mintPhase,
address mainWallet,
uint256 allowance,
bytes calldata signature,
bool staked
) external payable checkPayment(n) checkSupply checkPhase(mintPhase) {
cubs.mint(msg.sender, n, staked);
cubs.useAllowance(
msg.sender,
mainWallet,
n,
mintPhase == MintPhaseType.Holders,
allowance
);
MintPhase memory phase = mintPhases[mintPhase];
if (
phase.signer !=
ECDSA
.toEthSignedMessageHash(
abi.encodePacked(
msg.sender,
mainWallet,
mintPhase,
allowance
)
)
.recover(signature)
) revert NotAllowed();
}
function mint(
uint16 n,
bool staked
)
external
payable
checkPayment(n)
checkPhase(MintPhaseType.Public)
checkSupply
{
cubs.mint(msg.sender, n, staked);
Wallet memory w = cubs.wallets(msg.sender);
uint256 minted = w.batchedMints - (w.redeems + w.allowlistMints);
if (minted > publicMaxPerWallet) revert Overflow();
}
function configureMintPhases(
MintPhase[] calldata phases
) external onlyOwner {
for (uint256 i = 0; i < phases.length; i++) {
MintPhase memory phase = phases[i];
mintPhases[phase.phaseType] = phase;
}
}
function setMintPrice(uint256 price) external onlyOwner {
mintPrice = price;
}
function setPublicMaxPerWallet(uint256 max) external onlyOwner {
publicMaxPerWallet = max;
}
function withdraw(address to) external onlyOwner {
if (to == address(0)) revert NotAllowed();
payable(to).transfer(address(this).balance);
}
modifier checkPayment(uint256 n) {
if (msg.value != n * mintPrice) {
revert NotEnoughEth();
}
_;
}
modifier checkPhase(MintPhaseType mintPhase) {
if (msg.sender != owner) {
MintPhase storage phase = mintPhases[mintPhase];
uint256 ts = block.timestamp;
if (phase.start == 0) revert UnknownMintPhase();
if (ts < phase.start) revert MintPhaseNotStarted();
if (phase.end != 0 && ts > phase.end) revert MintPhaseEnded();
}
_;
}
modifier checkSupply() {
_;
MintCounters memory counters = cubs.counters();
if (counters.batched - counters.redeems > MINTABLE_SUPPLY)
revert Overflow();
}
}
文件 3 的 5: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);
}
}
}
文件 4 的 5: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);
}
}
文件 5 的 5:SuperOwnable.sol
pragma solidity ^0.8.19;
abstract contract SuperOwnable {
address public owner;
address public superOwner;
mapping(address => bool) authorities;
error Denied();
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
constructor(address superOwner_) {
_transferOwnership(msg.sender);
superOwner = superOwner_;
}
modifier onlyOwner() {
if (msg.sender != owner && msg.sender != superOwner) revert Denied();
_;
}
modifier onlySuperOwner() {
if (msg.sender != superOwner) revert Denied();
_;
}
modifier onlyAuthority() {
if (!authorities[msg.sender] && msg.sender != owner) revert Denied();
_;
}
function transferOwnership(address addr) public virtual onlyOwner {
_transferOwnership(addr);
}
function _transferOwnership(address addr) internal virtual {
address oldOwner = owner;
owner = addr;
emit OwnershipTransferred(oldOwner, addr);
}
function setSuperOwner(address addr) public onlySuperOwner {
if (addr == address(0)) revert Denied();
superOwner = addr;
}
function toggleAuthority(address addr, bool enabled) public onlyOwner {
authorities[addr] = enabled;
}
}
{
"compilationTarget": {
"contracts/KillaCubsMinter.sol": "KillaCubsMinter"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"cubsAddress","type":"address"},{"internalType":"address","name":"bearsAddress","type":"address"},{"internalType":"address","name":"passesAddress","type":"address"},{"internalType":"address","name":"kiltonAddress","type":"address"},{"internalType":"address","name":"labsAddress","type":"address"},{"internalType":"address","name":"superOwner","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"Denied","type":"error"},{"inputs":[],"name":"MintPhaseEnded","type":"error"},{"inputs":[],"name":"MintPhaseNotStarted","type":"error"},{"inputs":[],"name":"NotAllowed","type":"error"},{"inputs":[],"name":"NotEnoughEth","type":"error"},{"inputs":[],"name":"Overflow","type":"error"},{"inputs":[],"name":"UnknownMintPhase","type":"error"},{"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":"bears","outputs":[{"internalType":"contract IERC721","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"internalType":"bool","name":"staked","type":"bool"}],"name":"claim","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"enum MintPhaseType","name":"phaseType","type":"uint8"},{"internalType":"uint32","name":"start","type":"uint32"},{"internalType":"uint32","name":"end","type":"uint32"},{"internalType":"address","name":"signer","type":"address"}],"internalType":"struct MintPhase[]","name":"phases","type":"tuple[]"}],"name":"configureMintPhases","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"cubs","outputs":[{"internalType":"contract IKillaCubs","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"kilton","outputs":[{"internalType":"contract IERC721","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"labs","outputs":[{"internalType":"contract IERC721","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint16","name":"n","type":"uint16"},{"internalType":"bool","name":"staked","type":"bool"}],"name":"mint","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"enum MintPhaseType","name":"","type":"uint8"}],"name":"mintPhases","outputs":[{"internalType":"enum MintPhaseType","name":"phaseType","type":"uint8"},{"internalType":"uint32","name":"start","type":"uint32"},{"internalType":"uint32","name":"end","type":"uint32"},{"internalType":"address","name":"signer","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"mintPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint16","name":"n","type":"uint16"},{"internalType":"enum MintPhaseType","name":"mintPhase","type":"uint8"},{"internalType":"address","name":"mainWallet","type":"address"},{"internalType":"uint256","name":"allowance","type":"uint256"},{"internalType":"bytes","name":"signature","type":"bytes"},{"internalType":"bool","name":"staked","type":"bool"}],"name":"mintPrivate","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"passes","outputs":[{"internalType":"contract IKillaPasses","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"publicMaxPerWallet","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint16","name":"n","type":"uint16"},{"internalType":"bool","name":"staked","type":"bool"}],"name":"redeem","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"price","type":"uint256"}],"name":"setMintPrice","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"max","type":"uint256"}],"name":"setPublicMaxPerWallet","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"setSuperOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"superOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"},{"internalType":"bool","name":"enabled","type":"bool"}],"name":"toggleAuthority","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"}]