编译器
0.8.15+commit.e14f2714
文件 1 的 8:BoredAndDangerous.sol
pragma solidity ^0.8.15;
import {ERC721} from "solmate/tokens/ERC721.sol";
import {ERC2981} from "openzeppelin-contracts/contracts/token/common/ERC2981.sol";
import {MerkleProof} from "openzeppelin-contracts/contracts/utils/cryptography/MerkleProof.sol";
import {Strings} from "openzeppelin-contracts/contracts/utils/Strings.sol";
interface IERC721 {
function ownerOf(uint tokenId) external view returns (address);
}
contract BoredAndDangerous is ERC721, ERC2981 {
address public constant WRITERS_ROOM = 0x880644ddF208E471C6f2230d31f9027578FA6FcC;
uint public constant DUTCH_AUCTION_GRACE_PERIOD = 12 hours;
uint public constant DUTCH_AUCTION_MINT_CAP = 2;
uint public immutable DUTCH_AUCTION_START_ID;
uint public immutable DUTCH_AUCTION_END_ID;
uint public writelistPrice;
address public mintingOwner;
address public metadataOwner;
address public royaltyOwner;
struct DutchAuctionFinalization {
uint128 price;
uint128 time;
}
DutchAuctionFinalization public dutchEnd;
uint public dutchAuctionNextId;
uint public writelistMintNextId;
struct Writelist {
uint128 remaining;
bool used;
}
bool public writelistMintWritersRoomFreeOpen;
bool public writelistMintWritersRoomOpen;
bytes32 public giveawayMerkleRoot;
mapping(address => Writelist) public giveawayWritelist;
bytes32 public apeMerkleRoot;
mapping(bytes32 => bool) public apeWritelistUsed;
mapping(uint => bool) public writersroomWritelistUsed;
uint public totalSupply = 0;
string public baseTokenURI;
struct DutchAuctionMintHistory {
uint128 amount;
uint128 price;
}
mapping(address => DutchAuctionMintHistory) public mintHistory;
struct DutchAuctionParams {
uint64 startPrice;
uint64 endPrice;
uint64 priceIncrement;
uint32 startTime;
uint32 timeIncrement;
}
DutchAuctionParams public params;
event Mint(address indexed owner, uint indexed tokenId);
event DutchAuctionRefund(address indexed account);
error AccessControl();
error OnlyEOA(address msgSender);
error ExceededUserMintCap();
error MintNotOpen();
error DoesNotOwnToken(uint tokenId);
error DutchAuctionOver();
error DutchAuctionGracePeriod(uint endPrice, uint endTime);
error DutchAuctionNotOver();
error DutchAuctionNotOverAdmin();
error DutchAuctionBadParamsAdmin();
error FailedToSendEther(address sender, address recipient);
error WritelistUsed();
error MismatchedArrays();
error MintZero();
constructor(uint _DUTCH_AUCTION_START_ID, uint _DUTCH_AUCTION_END_ID) ERC721("Bored & Dangerous", "BOOK") {
DUTCH_AUCTION_START_ID = _DUTCH_AUCTION_START_ID;
DUTCH_AUCTION_END_ID = _DUTCH_AUCTION_END_ID;
dutchAuctionNextId = _DUTCH_AUCTION_START_ID;
writelistMintNextId = _DUTCH_AUCTION_END_ID + 1;
mintingOwner = msg.sender;
metadataOwner = msg.sender;
royaltyOwner = msg.sender;
}
function ownerMint(address recipient, uint tokenId) external {
if (msg.sender != mintingOwner) {
revert AccessControl();
}
if (DUTCH_AUCTION_START_ID <= tokenId && tokenId <= DUTCH_AUCTION_END_ID) {
revert DutchAuctionNotOverAdmin();
}
unchecked {
++totalSupply;
}
_mint(recipient, tokenId);
}
function ownerMintBatch(address[] calldata recipients, uint[] calldata tokenIds) external {
if (msg.sender != mintingOwner) {
revert AccessControl();
}
if (recipients.length != tokenIds.length) {
revert MismatchedArrays();
}
unchecked {
totalSupply += tokenIds.length;
for (uint i = 0; i < tokenIds.length; ++i) {
if (DUTCH_AUCTION_START_ID <= tokenIds[i] && tokenIds[i] <= DUTCH_AUCTION_END_ID) {
revert DutchAuctionNotOverAdmin();
}
_mint(recipients[i], tokenIds[i]);
}
}
}
function dutchAuctionPrice() public view returns (uint) {
DutchAuctionParams memory _params = params;
uint numIncrements = (block.timestamp - _params.startTime) / _params.timeIncrement;
uint price = _params.startPrice - numIncrements * _params.priceIncrement;
if (price < _params.endPrice) {
price = _params.endPrice;
}
return price;
}
function dutchAuctionMint(uint amount) external payable {
_onlyEOA(msg.sender);
if (amount == 0) {
revert MintZero();
}
DutchAuctionMintHistory memory userMintHistory = mintHistory[msg.sender];
if (userMintHistory.amount + amount > DUTCH_AUCTION_MINT_CAP) {
revert ExceededUserMintCap();
}
uint256 _dutchAuctionNextId = dutchAuctionNextId;
if (_dutchAuctionNextId + amount > DUTCH_AUCTION_END_ID + 1) {
revert DutchAuctionOver();
}
DutchAuctionParams memory _params = params;
if (block.timestamp < _params.startTime || _params.startPrice == 0) {
revert MintNotOpen();
}
uint numIncrements = (block.timestamp - _params.startTime) / _params.timeIncrement;
uint price = _params.startPrice - numIncrements * _params.priceIncrement;
if (price < _params.endPrice) {
price = _params.endPrice;
}
if (msg.value != amount * price) {
revert FailedToSendEther(msg.sender, address(this));
}
unchecked {
uint128 newPrice = (userMintHistory.amount * userMintHistory.price + uint128(amount * price)) / uint128(userMintHistory.amount + amount);
mintHistory[msg.sender] = DutchAuctionMintHistory({
amount: userMintHistory.amount + uint128(amount),
price: newPrice
});
for (uint i = 0; i < amount; ++i) {
_mint(msg.sender, _dutchAuctionNextId++);
}
totalSupply += amount;
if (_dutchAuctionNextId > DUTCH_AUCTION_END_ID) {
dutchEnd = DutchAuctionFinalization({
price: uint128(price),
time: uint128(block.timestamp)
});
}
dutchAuctionNextId = _dutchAuctionNextId;
}
}
function claimDutchAuctionRefund(address[] calldata accounts) external {
if (dutchEnd.price == 0) {
revert DutchAuctionNotOver();
}
for (uint i = 0; i < accounts.length; ++i) {
address account = accounts[i];
DutchAuctionMintHistory memory mint = mintHistory[account];
if (mint.price > 0) {
uint refundAmount = mint.amount * (mint.price - dutchEnd.price);
delete mintHistory[account];
(bool sent,) = account.call{value: refundAmount}("");
if (!sent) {
revert FailedToSendEther(address(this), account);
}
}
}
}
function writelistMintWritersRoomFree(uint[] calldata tokenIds) external {
if (!writelistMintWritersRoomFreeOpen) {
revert MintNotOpen();
}
for (uint i = 0; i < tokenIds.length; ++i) {
address tokenOwner = IERC721(WRITERS_ROOM).ownerOf(tokenIds[i]);
_mint(tokenOwner, tokenIds[i]);
}
totalSupply += tokenIds.length;
}
function writelistMintWritersRoom(uint[] calldata tokenIds) external payable {
if (!writelistMintWritersRoomOpen) {
revert MintNotOpen();
}
if (msg.value != tokenIds.length * writelistPrice) {
revert FailedToSendEther(msg.sender, address(this));
}
for (uint i = 0; i < tokenIds.length; ++i) {
if (writersroomWritelistUsed[tokenIds[i]]) {
revert WritelistUsed();
}
writersroomWritelistUsed[tokenIds[i]] = true;
address tokenOwner = IERC721(WRITERS_ROOM).ownerOf(tokenIds[i]);
_mint(tokenOwner, writelistMintNextId++);
}
totalSupply += tokenIds.length;
}
function writelistMintApes(address tokenContract, uint tokenId, bytes32 leaf, bytes32[] calldata proof) external payable {
if (msg.value != writelistPrice) {
revert FailedToSendEther(msg.sender, address(this));
}
bytes32 tokenHash = keccak256(abi.encodePacked(tokenContract, tokenId));
if (apeWritelistUsed[tokenHash]) {
revert WritelistUsed();
}
require(tokenHash == leaf, "Token contract and id don't match Merkle leaf");
require(verify(apeMerkleRoot, leaf, proof), "Not a valid leaf in the Merkle tree");
address tokenOwner = IERC721(tokenContract).ownerOf(tokenId);
apeWritelistUsed[tokenHash] = true;
++totalSupply;
_mint(tokenOwner, writelistMintNextId++);
}
function writelistMintGiveaway(address tokenOwner, uint8 amount, uint8 totalAllocation, bytes32 leaf, bytes32[] memory proof) external payable {
if (msg.value != amount * writelistPrice) {
revert FailedToSendEther(msg.sender, address(this));
}
Writelist memory writelist = giveawayWritelist[tokenOwner];
if (!writelist.used) {
require(keccak256(abi.encodePacked(tokenOwner, totalAllocation)) == leaf, "Sender and amount don't match Merkle leaf");
require(verify(giveawayMerkleRoot, leaf, proof), "Not a valid leaf in the Merkle tree");
writelist.used = true;
if (amount != totalAllocation) {
writelist.remaining = totalAllocation - amount;
}
}
else {
writelist.remaining -= amount;
}
giveawayWritelist[tokenOwner] = writelist;
totalSupply += amount;
for (uint i = 0; i < amount; ++i) {
_mint(tokenOwner, writelistMintNextId++);
}
}
function verify(bytes32 root, bytes32 leaf, bytes32[] memory proof) public pure returns (bool) {
return MerkleProof.verify(proof, root, leaf);
}
function setBaseTokenURI(string memory _baseTokenURI) external {
if (msg.sender != metadataOwner) {
revert AccessControl();
}
baseTokenURI = _baseTokenURI;
}
function setGiveawayMerkleRoot(bytes32 _giveawayMerkleRoot) external {
if (msg.sender != mintingOwner) {
revert AccessControl();
}
giveawayMerkleRoot = _giveawayMerkleRoot;
}
function setApeMerkleRoot(bytes32 _apeMerkleRoot) external {
if (msg.sender != mintingOwner) {
revert AccessControl();
}
apeMerkleRoot = _apeMerkleRoot;
}
function setDutchAuctionStruct(DutchAuctionParams calldata _params) external {
if (msg.sender != mintingOwner) {
revert AccessControl();
}
if (!(_params.startPrice >= _params.endPrice && _params.endPrice > 0 && _params.startTime > 0 && _params.timeIncrement > 0)) {
revert DutchAuctionBadParamsAdmin();
}
params = DutchAuctionParams({
startPrice: _params.startPrice,
endPrice: _params.endPrice,
priceIncrement: _params.priceIncrement,
startTime: _params.startTime,
timeIncrement: _params.timeIncrement
});
}
function setWritelistMintNextId(uint _writelistMintNextId) external {
if (msg.sender != mintingOwner) {
revert AccessControl();
}
writelistMintNextId = _writelistMintNextId;
}
function setWritelistMintWritersRoomFreeOpen(bool _value) external {
if (msg.sender != mintingOwner) {
revert AccessControl();
}
writelistMintWritersRoomFreeOpen = _value;
}
function setWritelistMintWritersRoomOpen(bool _value) external {
if (msg.sender != mintingOwner) {
revert AccessControl();
}
writelistMintWritersRoomOpen = _value;
}
function setWritelistPrice(uint _price) external {
if (msg.sender != mintingOwner) {
revert AccessControl();
}
writelistPrice = _price;
}
function claimFunds(address payable recipient) external {
if (!(msg.sender == mintingOwner || msg.sender == metadataOwner || msg.sender == royaltyOwner)) {
revert AccessControl();
}
if (!(dutchEnd.price > 0 && block.timestamp >= dutchEnd.time + DUTCH_AUCTION_GRACE_PERIOD)) {
revert DutchAuctionGracePeriod(dutchEnd.price, dutchEnd.time);
}
(bool sent,) = recipient.call{value: address(this).balance}("");
if (!sent) {
revert FailedToSendEther(address(this), recipient);
}
}
function setMintingOwner(address _mintingOwner) external {
if (msg.sender != mintingOwner) {
revert AccessControl();
}
mintingOwner = _mintingOwner;
}
function setMetadataOwner(address _metadataOwner) external {
if (msg.sender != metadataOwner) {
revert AccessControl();
}
metadataOwner = _metadataOwner;
}
function setRoyaltyOwner(address _royaltyOwner) external {
if (msg.sender != royaltyOwner) {
revert AccessControl();
}
royaltyOwner = _royaltyOwner;
}
function owner() external view returns (address) {
return royaltyOwner;
}
function supportsInterface(bytes4 interfaceId) public view override(ERC721, ERC2981) returns (bool) {
return
interfaceId == 0x2a55205a ||
interfaceId == 0x01ffc9a7 ||
interfaceId == 0x80ac58cd ||
interfaceId == 0x5b5e139f;
}
function setDefaultRoyalty(address receiver, uint96 feeNumerator) external {
if (msg.sender != royaltyOwner) {
revert AccessControl();
}
_setDefaultRoyalty(receiver, feeNumerator);
}
function deleteDefaultRoyalty() external {
if (msg.sender != royaltyOwner) {
revert AccessControl();
}
_deleteDefaultRoyalty();
}
function setTokenRoyalty(uint256 tokenId, address receiver, uint96 feeNumerator) external {
if (msg.sender != royaltyOwner) {
revert AccessControl();
}
_setTokenRoyalty(tokenId, receiver, feeNumerator);
}
function resetTokenRoyalty(uint256 tokenId) external {
if (msg.sender != royaltyOwner) {
revert AccessControl();
}
_resetTokenRoyalty(tokenId);
}
function tokenURI(uint256 tokenId) public view override returns (string memory) {
return string(abi.encodePacked(baseTokenURI, Strings.toString(tokenId)));
}
function _onlyEOA(address account) internal view {
if (msg.sender != tx.origin || account.code.length > 0) {
revert OnlyEOA(account);
}
}
}
文件 2 的 8:ERC165.sol
pragma solidity ^0.8.0;
import "./IERC165.sol";
abstract contract ERC165 is IERC165 {
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
文件 3 的 8:ERC2981.sol
pragma solidity ^0.8.0;
import "../../interfaces/IERC2981.sol";
import "../../utils/introspection/ERC165.sol";
abstract contract ERC2981 is IERC2981, ERC165 {
struct RoyaltyInfo {
address receiver;
uint96 royaltyFraction;
}
RoyaltyInfo private _defaultRoyaltyInfo;
mapping(uint256 => RoyaltyInfo) private _tokenRoyaltyInfo;
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC165) returns (bool) {
return interfaceId == type(IERC2981).interfaceId || super.supportsInterface(interfaceId);
}
function royaltyInfo(uint256 _tokenId, uint256 _salePrice) public view virtual override returns (address, uint256) {
RoyaltyInfo memory royalty = _tokenRoyaltyInfo[_tokenId];
if (royalty.receiver == address(0)) {
royalty = _defaultRoyaltyInfo;
}
uint256 royaltyAmount = (_salePrice * royalty.royaltyFraction) / _feeDenominator();
return (royalty.receiver, royaltyAmount);
}
function _feeDenominator() internal pure virtual returns (uint96) {
return 10000;
}
function _setDefaultRoyalty(address receiver, uint96 feeNumerator) internal virtual {
require(feeNumerator <= _feeDenominator(), "ERC2981: royalty fee will exceed salePrice");
require(receiver != address(0), "ERC2981: invalid receiver");
_defaultRoyaltyInfo = RoyaltyInfo(receiver, feeNumerator);
}
function _deleteDefaultRoyalty() internal virtual {
delete _defaultRoyaltyInfo;
}
function _setTokenRoyalty(
uint256 tokenId,
address receiver,
uint96 feeNumerator
) internal virtual {
require(feeNumerator <= _feeDenominator(), "ERC2981: royalty fee will exceed salePrice");
require(receiver != address(0), "ERC2981: Invalid parameters");
_tokenRoyaltyInfo[tokenId] = RoyaltyInfo(receiver, feeNumerator);
}
function _resetTokenRoyalty(uint256 tokenId) internal virtual {
delete _tokenRoyaltyInfo[tokenId];
}
}
文件 4 的 8:ERC721.sol
pragma solidity >=0.8.0;
abstract contract ERC721 {
event Transfer(address indexed from, address indexed to, uint256 indexed id);
event Approval(address indexed owner, address indexed spender, uint256 indexed id);
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
string public name;
string public symbol;
function tokenURI(uint256 id) public view virtual returns (string memory);
mapping(uint256 => address) internal _ownerOf;
mapping(address => uint256) internal _balanceOf;
function ownerOf(uint256 id) public view virtual returns (address owner) {
require((owner = _ownerOf[id]) != address(0), "NOT_MINTED");
}
function balanceOf(address owner) public view virtual returns (uint256) {
require(owner != address(0), "ZERO_ADDRESS");
return _balanceOf[owner];
}
mapping(uint256 => address) public getApproved;
mapping(address => mapping(address => bool)) public isApprovedForAll;
constructor(string memory _name, string memory _symbol) {
name = _name;
symbol = _symbol;
}
function approve(address spender, uint256 id) public virtual {
address owner = _ownerOf[id];
require(msg.sender == owner || isApprovedForAll[owner][msg.sender], "NOT_AUTHORIZED");
getApproved[id] = spender;
emit Approval(owner, spender, id);
}
function setApprovalForAll(address operator, bool approved) public virtual {
isApprovedForAll[msg.sender][operator] = approved;
emit ApprovalForAll(msg.sender, operator, approved);
}
function transferFrom(
address from,
address to,
uint256 id
) public virtual {
require(from == _ownerOf[id], "WRONG_FROM");
require(to != address(0), "INVALID_RECIPIENT");
require(
msg.sender == from || isApprovedForAll[from][msg.sender] || msg.sender == getApproved[id],
"NOT_AUTHORIZED"
);
unchecked {
_balanceOf[from]--;
_balanceOf[to]++;
}
_ownerOf[id] = to;
delete getApproved[id];
emit Transfer(from, to, id);
}
function safeTransferFrom(
address from,
address to,
uint256 id
) public virtual {
transferFrom(from, to, id);
require(
to.code.length == 0 ||
ERC721TokenReceiver(to).onERC721Received(msg.sender, from, id, "") ==
ERC721TokenReceiver.onERC721Received.selector,
"UNSAFE_RECIPIENT"
);
}
function safeTransferFrom(
address from,
address to,
uint256 id,
bytes calldata data
) public virtual {
transferFrom(from, to, id);
require(
to.code.length == 0 ||
ERC721TokenReceiver(to).onERC721Received(msg.sender, from, id, data) ==
ERC721TokenReceiver.onERC721Received.selector,
"UNSAFE_RECIPIENT"
);
}
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return
interfaceId == 0x01ffc9a7 ||
interfaceId == 0x80ac58cd ||
interfaceId == 0x5b5e139f;
}
function _mint(address to, uint256 id) internal virtual {
require(to != address(0), "INVALID_RECIPIENT");
require(_ownerOf[id] == address(0), "ALREADY_MINTED");
unchecked {
_balanceOf[to]++;
}
_ownerOf[id] = to;
emit Transfer(address(0), to, id);
}
function _burn(uint256 id) internal virtual {
address owner = _ownerOf[id];
require(owner != address(0), "NOT_MINTED");
unchecked {
_balanceOf[owner]--;
}
delete _ownerOf[id];
delete getApproved[id];
emit Transfer(owner, address(0), id);
}
function _safeMint(address to, uint256 id) internal virtual {
_mint(to, id);
require(
to.code.length == 0 ||
ERC721TokenReceiver(to).onERC721Received(msg.sender, address(0), id, "") ==
ERC721TokenReceiver.onERC721Received.selector,
"UNSAFE_RECIPIENT"
);
}
function _safeMint(
address to,
uint256 id,
bytes memory data
) internal virtual {
_mint(to, id);
require(
to.code.length == 0 ||
ERC721TokenReceiver(to).onERC721Received(msg.sender, address(0), id, data) ==
ERC721TokenReceiver.onERC721Received.selector,
"UNSAFE_RECIPIENT"
);
}
}
abstract contract ERC721TokenReceiver {
function onERC721Received(
address,
address,
uint256,
bytes calldata
) external virtual returns (bytes4) {
return ERC721TokenReceiver.onERC721Received.selector;
}
}
文件 5 的 8:IERC165.sol
pragma solidity ^0.8.0;
interface IERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
文件 6 的 8:IERC2981.sol
pragma solidity ^0.8.0;
import "../utils/introspection/IERC165.sol";
interface IERC2981 is IERC165 {
function royaltyInfo(uint256 tokenId, uint256 salePrice)
external
view
returns (address receiver, uint256 royaltyAmount);
}
文件 7 的 8: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)
}
}
}
文件 8 的 8: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": {
"src/BoredAndDangerous.sol": "BoredAndDangerous"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": [
":@rari-capital/solmate/=lib/solmate/",
":contracts/=contracts/",
":ds-test/=lib/ds-test/src/",
":forge-std/=lib/forge-std/src/",
":murky/=lib/murky/src/",
":openzeppelin-contracts/=lib/openzeppelin-contracts/",
":script/=script/",
":solmate/=lib/solmate/src/",
":src/=src/"
]
}
[{"inputs":[{"internalType":"uint256","name":"_DUTCH_AUCTION_START_ID","type":"uint256"},{"internalType":"uint256","name":"_DUTCH_AUCTION_END_ID","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AccessControl","type":"error"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"DoesNotOwnToken","type":"error"},{"inputs":[],"name":"DutchAuctionBadParamsAdmin","type":"error"},{"inputs":[{"internalType":"uint256","name":"endPrice","type":"uint256"},{"internalType":"uint256","name":"endTime","type":"uint256"}],"name":"DutchAuctionGracePeriod","type":"error"},{"inputs":[],"name":"DutchAuctionNotOver","type":"error"},{"inputs":[],"name":"DutchAuctionNotOverAdmin","type":"error"},{"inputs":[],"name":"DutchAuctionOver","type":"error"},{"inputs":[],"name":"ExceededUserMintCap","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"}],"name":"FailedToSendEther","type":"error"},{"inputs":[],"name":"MintNotOpen","type":"error"},{"inputs":[],"name":"MintZero","type":"error"},{"inputs":[],"name":"MismatchedArrays","type":"error"},{"inputs":[{"internalType":"address","name":"msgSender","type":"address"}],"name":"OnlyEOA","type":"error"},{"inputs":[],"name":"WritelistUsed","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"}],"name":"DutchAuctionRefund","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Mint","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[],"name":"DUTCH_AUCTION_END_ID","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DUTCH_AUCTION_GRACE_PERIOD","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DUTCH_AUCTION_MINT_CAP","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DUTCH_AUCTION_START_ID","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"WRITERS_ROOM","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"apeMerkleRoot","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"apeWritelistUsed","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"baseTokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"accounts","type":"address[]"}],"name":"claimDutchAuctionRefund","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"recipient","type":"address"}],"name":"claimFunds","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"deleteDefaultRoyalty","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"dutchAuctionMint","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"dutchAuctionNextId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"dutchAuctionPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"dutchEnd","outputs":[{"internalType":"uint128","name":"price","type":"uint128"},{"internalType":"uint128","name":"time","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"giveawayMerkleRoot","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"giveawayWritelist","outputs":[{"internalType":"uint128","name":"remaining","type":"uint128"},{"internalType":"bool","name":"used","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"metadataOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"mintHistory","outputs":[{"internalType":"uint128","name":"amount","type":"uint128"},{"internalType":"uint128","name":"price","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"mintingOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"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":"tokenId","type":"uint256"}],"name":"ownerMint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"recipients","type":"address[]"},{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"}],"name":"ownerMintBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"owner","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"params","outputs":[{"internalType":"uint64","name":"startPrice","type":"uint64"},{"internalType":"uint64","name":"endPrice","type":"uint64"},{"internalType":"uint64","name":"priceIncrement","type":"uint64"},{"internalType":"uint32","name":"startTime","type":"uint32"},{"internalType":"uint32","name":"timeIncrement","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"resetTokenRoyalty","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"uint256","name":"_salePrice","type":"uint256"}],"name":"royaltyInfo","outputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"royaltyOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_apeMerkleRoot","type":"bytes32"}],"name":"setApeMerkleRoot","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_baseTokenURI","type":"string"}],"name":"setBaseTokenURI","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint96","name":"feeNumerator","type":"uint96"}],"name":"setDefaultRoyalty","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint64","name":"startPrice","type":"uint64"},{"internalType":"uint64","name":"endPrice","type":"uint64"},{"internalType":"uint64","name":"priceIncrement","type":"uint64"},{"internalType":"uint32","name":"startTime","type":"uint32"},{"internalType":"uint32","name":"timeIncrement","type":"uint32"}],"internalType":"struct BoredAndDangerous.DutchAuctionParams","name":"_params","type":"tuple"}],"name":"setDutchAuctionStruct","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_giveawayMerkleRoot","type":"bytes32"}],"name":"setGiveawayMerkleRoot","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_metadataOwner","type":"address"}],"name":"setMetadataOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_mintingOwner","type":"address"}],"name":"setMintingOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_royaltyOwner","type":"address"}],"name":"setRoyaltyOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint96","name":"feeNumerator","type":"uint96"}],"name":"setTokenRoyalty","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_writelistMintNextId","type":"uint256"}],"name":"setWritelistMintNextId","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_value","type":"bool"}],"name":"setWritelistMintWritersRoomFreeOpen","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_value","type":"bool"}],"name":"setWritelistMintWritersRoomOpen","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_price","type":"uint256"}],"name":"setWritelistPrice","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"root","type":"bytes32"},{"internalType":"bytes32","name":"leaf","type":"bytes32"},{"internalType":"bytes32[]","name":"proof","type":"bytes32[]"}],"name":"verify","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"tokenContract","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes32","name":"leaf","type":"bytes32"},{"internalType":"bytes32[]","name":"proof","type":"bytes32[]"}],"name":"writelistMintApes","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"tokenOwner","type":"address"},{"internalType":"uint8","name":"amount","type":"uint8"},{"internalType":"uint8","name":"totalAllocation","type":"uint8"},{"internalType":"bytes32","name":"leaf","type":"bytes32"},{"internalType":"bytes32[]","name":"proof","type":"bytes32[]"}],"name":"writelistMintGiveaway","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"writelistMintNextId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"}],"name":"writelistMintWritersRoom","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"}],"name":"writelistMintWritersRoomFree","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"writelistMintWritersRoomFreeOpen","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"writelistMintWritersRoomOpen","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"writelistPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"writersroomWritelistUsed","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"}]