文件 1 的 17:Address.sol
pragma solidity ^0.8.0;
library Address {
function isContract(address account) internal view returns (bool) {
uint256 size;
assembly {
size := extcodesize(account)
}
return size > 0;
}
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
文件 2 的 17: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;
}
}
文件 3 的 17:Counters.sol
pragma solidity ^0.8.0;
library Counters {
struct Counter {
uint256 _value;
}
function current(Counter storage counter) internal view returns (uint256) {
return counter._value;
}
function increment(Counter storage counter) internal {
unchecked {
counter._value += 1;
}
}
function decrement(Counter storage counter) internal {
uint256 value = counter._value;
require(value > 0, "Counter: decrement overflow");
unchecked {
counter._value = value - 1;
}
}
function reset(Counter storage counter) internal {
counter._value = 0;
}
}
文件 4 的 17: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;
}
}
文件 5 的 17:ERC721.sol
pragma solidity ^0.8.0;
import "./IERC721.sol";
import "./IERC721Receiver.sol";
import "./extensions/IERC721Metadata.sol";
import "../../utils/Address.sol";
import "../../utils/Context.sol";
import "../../utils/Strings.sol";
import "../../utils/introspection/ERC165.sol";
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
using Address for address;
using Strings for uint256;
string private _name;
string private _symbol;
mapping(uint256 => address) private _owners;
mapping(address => uint256) private _balances;
mapping(uint256 => address) private _tokenApprovals;
mapping(address => mapping(address => bool)) private _operatorApprovals;
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return
interfaceId == type(IERC721).interfaceId ||
interfaceId == type(IERC721Metadata).interfaceId ||
super.supportsInterface(interfaceId);
}
function balanceOf(address owner) public view virtual override returns (uint256) {
require(owner != address(0), "ERC721: balance query for the zero address");
return _balances[owner];
}
function ownerOf(uint256 tokenId) public view virtual override returns (address) {
address owner = _owners[tokenId];
require(owner != address(0), "ERC721: owner query for nonexistent token");
return owner;
}
function name() public view virtual override returns (string memory) {
return _name;
}
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
string memory baseURI = _baseURI();
return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
}
function _baseURI() internal view virtual returns (string memory) {
return "";
}
function approve(address to, uint256 tokenId) public virtual override {
address owner = ERC721.ownerOf(tokenId);
require(to != owner, "ERC721: approval to current owner");
require(
_msgSender() == owner || isApprovedForAll(owner, _msgSender()),
"ERC721: approve caller is not owner nor approved for all"
);
_approve(to, tokenId);
}
function getApproved(uint256 tokenId) public view virtual override returns (address) {
require(_exists(tokenId), "ERC721: approved query for nonexistent token");
return _tokenApprovals[tokenId];
}
function setApprovalForAll(address operator, bool approved) public virtual override {
require(operator != _msgSender(), "ERC721: approve to caller");
_operatorApprovals[_msgSender()][operator] = approved;
emit ApprovalForAll(_msgSender(), operator, approved);
}
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
return _operatorApprovals[owner][operator];
}
function transferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_transfer(from, to, tokenId);
}
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
safeTransferFrom(from, to, tokenId, "");
}
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes memory _data
) public virtual override {
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_safeTransfer(from, to, tokenId, _data);
}
function _safeTransfer(
address from,
address to,
uint256 tokenId,
bytes memory _data
) internal virtual {
_transfer(from, to, tokenId);
require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
}
function _exists(uint256 tokenId) internal view virtual returns (bool) {
return _owners[tokenId] != address(0);
}
function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
require(_exists(tokenId), "ERC721: operator query for nonexistent token");
address owner = ERC721.ownerOf(tokenId);
return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender));
}
function _safeMint(address to, uint256 tokenId) internal virtual {
_safeMint(to, tokenId, "");
}
function _safeMint(
address to,
uint256 tokenId,
bytes memory _data
) internal virtual {
_mint(to, tokenId);
require(
_checkOnERC721Received(address(0), to, tokenId, _data),
"ERC721: transfer to non ERC721Receiver implementer"
);
}
function _mint(address to, uint256 tokenId) internal virtual {
require(to != address(0), "ERC721: mint to the zero address");
require(!_exists(tokenId), "ERC721: token already minted");
_beforeTokenTransfer(address(0), to, tokenId);
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(address(0), to, tokenId);
}
function _burn(uint256 tokenId) internal virtual {
address owner = ERC721.ownerOf(tokenId);
_beforeTokenTransfer(owner, address(0), tokenId);
_approve(address(0), tokenId);
_balances[owner] -= 1;
delete _owners[tokenId];
emit Transfer(owner, address(0), tokenId);
}
function _transfer(
address from,
address to,
uint256 tokenId
) internal virtual {
require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own");
require(to != address(0), "ERC721: transfer to the zero address");
_beforeTokenTransfer(from, to, tokenId);
_approve(address(0), tokenId);
_balances[from] -= 1;
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(from, to, tokenId);
}
function _approve(address to, uint256 tokenId) internal virtual {
_tokenApprovals[tokenId] = to;
emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
}
function _checkOnERC721Received(
address from,
address to,
uint256 tokenId,
bytes memory _data
) private returns (bool) {
if (to.isContract()) {
try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) {
return retval == IERC721Receiver.onERC721Received.selector;
} catch (bytes memory reason) {
if (reason.length == 0) {
revert("ERC721: transfer to non ERC721Receiver implementer");
} else {
assembly {
revert(add(32, reason), mload(reason))
}
}
}
} else {
return true;
}
}
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual {}
}
文件 6 的 17:IERC165.sol
pragma solidity ^0.8.0;
interface IERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
文件 7 的 17: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
) external;
function transferFrom(
address from,
address to,
uint256 tokenId
) external;
function approve(address to, uint256 tokenId) external;
function getApproved(uint256 tokenId) external view returns (address operator);
function setApprovalForAll(address operator, bool _approved) external;
function isApprovedForAll(address owner, address operator) external view returns (bool);
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;
}
文件 8 的 17:IERC721Metadata.sol
pragma solidity ^0.8.0;
import "../IERC721.sol";
interface IERC721Metadata is IERC721 {
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function tokenURI(uint256 tokenId) external view returns (string memory);
}
文件 9 的 17:IERC721Receiver.sol
pragma solidity ^0.8.0;
interface IERC721Receiver {
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
文件 10 的 17:Kasbeer721.sol
pragma solidity >=0.5.16 <0.9.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "./KasbeerStorage.sol";
import "./KasbeerAccessControl.sol";
import "./LibPart.sol";
contract Kasbeer721 is ERC721, KasbeerAccessControl, KasbeerStorage {
using Counters for Counters.Counter;
using SafeMath for uint256;
event ERC721Minted(uint256 indexed tokenId);
event ERC721Burned(uint256 indexed tokenId);
constructor(string memory temp_name, string memory temp_symbol)
ERC721(temp_name, temp_symbol)
{
_squad[msg.sender] = true;
_squad[0xB9699469c0b4dD7B1Dda11dA7678Fa4eFD51211b] = true;
addToWhitelist(0xB9699469c0b4dD7B1Dda11dA7678Fa4eFD51211b);
}
modifier hashIndexInRange(uint8 idx)
{
require(0 <= idx && idx < NUM_ASSETS, "Kasbeer721: index OOB");
_;
}
modifier groupInRange(uint8 group)
{
require(0 <= group && group <= 2, "Kasbeer721: group OOB");
_;
}
modifier onlyValidTokenId(uint256 tokenId)
{
require(1 <= tokenId && tokenId <= MAX_NUM_TOKENS, "KasbeerMade721: tokenId OOB");
_;
}
function _baseURI()
internal view virtual override returns (string memory)
{
return "ipfs://";
}
function _beforeTokenTransfer(address from, address to, uint256 tokenId)
internal virtual override
{
super._beforeTokenTransfer(from, to, tokenId);
}
function mint(address to)
isSquad public virtual returns (uint256)
{
_tokenIds.increment();
uint256 newId = _tokenIds.current();
_safeMint(to, newId);
emit ERC721Minted(newId);
return newId;
}
function burn(uint256 tokenId)
public virtual
{
require(isInSquad(msg.sender) || msg.sender == ownerOf(tokenId),
"Kasbeer721: not owner or in squad.");
_burn(tokenId);
emit ERC721Burned(tokenId);
}
function supportsInterface(bytes4 interfaceId)
public view virtual override returns (bool)
{
return interfaceId == _INTERFACE_ID_ERC165
|| interfaceId == _INTERFACE_ID_ROYALTIES
|| interfaceId == _INTERFACE_ID_ERC721
|| interfaceId == _INTERFACE_ID_ERC721_METADATA
|| interfaceId == _INTERFACE_ID_ERC721_ENUMERABLE
|| interfaceId == _INTERFACE_ID_EIP2981
|| super.supportsInterface(interfaceId);
}
function getHashByIndex(
uint8 group,
uint8 idx
) groupInRange(group) hashIndexInRange(idx) public view
returns (string memory)
{
if (group == 0) {
return normHashes[idx];
} else if (group == 1) {
return chiHashes[idx];
} else {
return stlHashes[idx];
}
}
function updateHash(
uint8 group,
uint8 hashNum,
string memory str
) isSquad groupInRange(group) hashIndexInRange(hashNum) public
{
if (group == 0) {
normHashes[hashNum] = str;
} else if (group == 1) {
chiHashes[hashNum] = str;
} else {
stlHashes[hashNum] = str;
}
}
function _hashExists(string memory assetHash)
internal view returns (bool)
{
uint8 i;
for (i = 0; i < NUM_ASSETS; i++) {
if (_stringsEqual(assetHash, normHashes[i]) ||
_stringsEqual(assetHash, chiHashes[i]) ||
_stringsEqual(assetHash, stlHashes[i])) {
return true;
}
}
return false;
}
function getCurrentId()
public view returns (uint256)
{
return _tokenIds.current();
}
function withdraw(address payable wallet, uint256 amount)
isSquad public
{
require(amount <= address(this).balance,
"Kasbeer721: Insufficient funds to withdraw");
wallet.transfer(amount);
}
function kill()
onlyOwner public
{
selfdestruct(payable(msg.sender));
}
function contractURI()
public view returns(string memory)
{
return contractUri;
}
function updateContractUri(string memory updatedContractUri)
isSquad public
{
contractUri = updatedContractUri;
}
function getRaribleV2Royalties(uint256 id)
onlyValidTokenId(id) external view returns (LibPart.Part[] memory)
{
LibPart.Part[] memory royalties = new LibPart.Part[](1);
royalties[0] = LibPart.Part({
account: payable(payoutAddress),
value: uint96(royaltyFeeBps)
});
return royalties;
}
function royaltyInfo(uint256 tokenId, uint256 salePrice) external view onlyValidTokenId(tokenId) returns (address receiver, uint256 amount) {
uint256 ourCut = SafeMath.div(SafeMath.mul(salePrice, royaltyFeeBps), 10000);
return (payoutAddress, ourCut);
}
function _stringsEqual(string memory a, string memory b)
internal pure returns (bool)
{
bytes memory A = bytes(a);
bytes memory B = bytes(b);
if (A.length != B.length) {
return false;
} else {
return keccak256(A) == keccak256(B);
}
}
}
文件 11 的 17:KasbeerAccessControl.sol
pragma solidity >=0.5.16 <0.9.0;
import "@openzeppelin/contracts/access/Ownable.sol";
contract KasbeerAccessControl is Ownable {
mapping (address => bool) internal _squad;
modifier isSquad()
{
require(isInSquad(msg.sender), "KasbeerAccessControl: Caller not part of squad.");
_;
}
function isInSquad(address a)
public view returns (bool)
{
return _squad[a];
}
function addToSquad(address a)
onlyOwner public
{
require(!isInSquad(a), "KasbeerAccessControl: Address already in squad.");
_squad[a] = true;
}
function removeFromSquad(address a)
onlyOwner public
{
require(isInSquad(a), "KasbeerAccessControl: Address already not in squad.");
_squad[a] = false;
}
mapping (address => bool) internal _whitelist;
bool whitelistActive;
modifier onlyWhitelist(address a)
{
require(isInWhitelist(a));
_;
}
modifier whitelistDisabled()
{
require(whitelistActive == false, "KasbeerAccessControl: whitelist still active");
_;
}
modifier whitelistEnabled()
{
require(whitelistActive == true, "KasbeerAccessControl: whitelist not active");
_;
}
function activateWhitelist()
isSquad whitelistDisabled public
{
whitelistActive = true;
}
function deactivateWhitelist()
isSquad whitelistEnabled public
{
whitelistActive = false;
}
function isInWhitelist(address a)
public view returns (bool)
{
return _whitelist[a];
}
function addToWhitelist(address a)
isSquad public
{
require(!isInWhitelist(a), "KasbeerAccessControl: already whitelisted");
_whitelist[a] = true;
}
function removeFromWhitelist(address a)
isSquad public
{
require(isInWhitelist(a), "KasbeerAccessControl: not in whitelist");
_whitelist[a] = false;
}
function bulkAddToWhitelist(address[] memory addys)
isSquad public
{
require(addys.length > 1, "KasbeerAccessControl: use `addToWhitelist` instead");
uint8 i;
for (i = 0; i < addys.length; i++) {
if (!_whitelist[addys[i]]) {
_whitelist[addys[i]] = true;
}
}
}
}
文件 12 的 17:KasbeerStorage.sol
pragma solidity >=0.5.16 <0.9.0;
import "@openzeppelin/contracts/utils/Counters.sol";
contract KasbeerStorage {
using Counters for Counters.Counter;
Counters.Counter internal _tokenIds;
uint256 constant public royaltyFeeBps = 1500;
bytes4 internal constant _INTERFACE_ID_ERC165 = 0x01ffc9a7;
bytes4 internal constant _INTERFACE_ID_ERC721 = 0x80ac58cd;
bytes4 internal constant _INTERFACE_ID_ERC721_METADATA = 0x5b5e139f;
bytes4 internal constant _INTERFACE_ID_ERC721_ENUMERABLE = 0x780e9d63;
bytes4 internal constant _INTERFACE_ID_EIP2981 = 0x2a55205a;
bytes4 internal constant _INTERFACE_ID_ROYALTIES = 0xcad96cca;
uint constant NUM_ASSETS = 8;
uint constant MAX_NUM_TOKENS = 888;
uint constant TOKEN_WEI_PRICE = 88800000000000000;
string internal contractUri;
address public payoutAddress;
string [NUM_ASSETS] normHashes = ["QmZzB15bPgTqyHzULMFK1jNdbbDGVGCX4PJNbyGGMqLCjL",
"QmeXZGeywxRRDK5mSBHNVnUzGv7Kv2ATfLHydPfT5LpbZr",
"QmYTf2HE8XycQD9uXshiVtXqNedS83WycJvS2SpWAPfx5b",
"QmYXjEkeio2nbMqy3DA7z2LwYFDyq1itbzdujGSoCsFwpN",
"QmWmvRqpT59QU9rDT28fiKgK6g8vUjRD2TSSeeBPr9aBNm",
"QmWtMb73QgSgkL7mY8PQEt6tgufMovXWF8ecurp2RD7X6R",
"Qmbd4uEwtPBfw1XASkgPijqhZDL2nZcRwPbueYaETuAfGt",
"QmayAeQafrWUHV3xb8DnXTGLn97xnh7X2Z957Ss9AtfkAD"];
string [NUM_ASSETS] chiHashes = ["QmNsSUji2wX4E8xmv8vynmSUCACPdCh7NznVSGMQ3hwLC3",
"QmYPq4zFLyREaZsPwZzXB3w94JVYdgFHGgRAuM6CK6PMes",
"QmbrATHXTkiyNijkfQcEMGT7ujpunsoLNTaupMYW922jp3",
"QmWaj5VHcBXgAQnct88tbthVmv1ecX7ft2aGGqMAt4N52p",
"QmTyFgbJXX2vUCZSjraKubXfE4NVr4nVrKtg3GK4ysscDX",
"QmQxQoAe47CUXtGY9NTA6dRgTJuDtM4HDqz9kW2UK1VHtU",
"QmaXYexRBrbr6Uv89cGyWXWCbyaoQDhy3hHJuktSTWFXtJ",
"QmeSQdMYLECcSfCSkMenPYuNL2v42YQEEA4HJiP36Zn7Z6"];
string [NUM_ASSETS] stlHashes = ["QmcB5AqhpNA8o5RT3VTeDsqNBn6VGEaXzeTKuomakTNueM",
"QmcjP9d54RcmPXgGt6XxNavr7dtQDAhAnatKjJ5a1Bqbmc",
"QmV3uFvGgGQdN4Ub81LWVnp3qjwMpKDvVwQmBzBNzAjWxB",
"Qmc3fWuQTxAgsBYK2g4z5VrK47nvfCrWHFNa5zA8DDoUbs",
"QmWRPStH4RRMrFzAJcTs2znP7hbVctbLHPUvEn9vXWSTfk",
"QmVobnLvtSvgrWssFyWAPCUQFvKsonRMYMYRQPsPSaQHTK",
"QmQvGuuRgKxqTcAA7xhGdZ5u2EzDKvWGYb1dMXz2ECwyZi",
"QmdurJn1GYVz1DcNgqbMTqnCKKFxpjsFuhoS7bnfBp2YGk"];
}
文件 13 的 17:LibPart.sol
pragma solidity >=0.5.16 <0.9.0;
library LibPart {
bytes32 public constant TYPE_HASH = keccak256("Part(address account,uint96 value)");
struct Part {
address payable account;
uint96 value;
}
function hash(Part memory part) internal pure returns (bytes32) {
return keccak256(abi.encode(TYPE_HASH, part.account, part.value));
}
}
文件 14 的 17: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() {
_setOwner(_msgSender());
}
function owner() public view virtual returns (address) {
return _owner;
}
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
function renounceOwnership() public virtual onlyOwner {
_setOwner(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_setOwner(newOwner);
}
function _setOwner(address newOwner) private {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
文件 15 的 17:Plug.sol
pragma solidity >=0.5.16 <0.9.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "./Kasbeer721.sol";
contract Plug is Kasbeer721 {
using Counters for Counters.Counter;
using SafeMath for uint256;
event PlugTransferred(address indexed from, address indexed to);
mapping(uint256 => uint) internal _birthdays;
constructor() Kasbeer721("the Plug", "PLUG") {
whitelistActive = true;
contractUri = "ipfs://QmYUDei8kuEHrPTyEMrWDQSLEtQwzDS16bpFwZab6RZN5j";
payoutAddress = 0x6b8C6E15818C74895c31A1C91390b3d42B336799;
_squad[payoutAddress] = true;
addToWhitelist(payoutAddress);
}
modifier batchLimit(uint256 numToMint)
{
require(1 <= numToMint && numToMint <= 8, "Plug: mint between 1 and 8");
_;
}
modifier plugsAvailable(uint256 numToMint)
{
require(_tokenIds.current() + numToMint <= MAX_NUM_TOKENS,
"Plug: not enough Plugs remaining to mint");
_;
}
modifier tokenExists(uint256 tokenId)
{
require(_exists(tokenId), "Plug: nonexistent token");
_;
}
function tokenURI(uint256 tokenId)
tokenExists(tokenId) public view virtual override returns (string memory)
{
string memory baseURI = _baseURI();
string memory hash = _tokenHash(tokenId);
return string(abi.encodePacked(baseURI, hash));
}
function _tokenHash(uint256 tokenId)
internal virtual view
returns (string memory)
{
if (!_exists(tokenId)) {
return "";
}
uint daysPassed = countDaysPassed(tokenId);
if (daysPassed >= 557) {
if (tokenId <= 176) {
return chiHashes[7];
} else if (tokenId % 88 == 0) {
return stlHashes[7];
} else {
return normHashes[7];
}
} else if (daysPassed >= 360) {
if (tokenId <= 176) {
return chiHashes[6];
} else if (tokenId % 88 == 0) {
return stlHashes[6];
} else {
return normHashes[6];
}
} else if (daysPassed >= 300) {
if (tokenId <= 176) {
return chiHashes[5];
} else if (tokenId % 88 == 0) {
return stlHashes[5];
} else {
return normHashes[5];
}
} else if (daysPassed >= 240) {
if (tokenId <= 176) {
return chiHashes[4];
} else if (tokenId % 88 == 0) {
return stlHashes[4];
} else {
return normHashes[4];
}
} else if (daysPassed >= 180) {
if (tokenId <= 176) {
return chiHashes[3];
} else if (tokenId % 88 == 0) {
return stlHashes[3];
} else {
return normHashes[3];
}
} else if (daysPassed >= 120) {
if (tokenId <= 176) {
return chiHashes[2];
} else if (tokenId % 88 == 0) {
return stlHashes[2];
} else {
return normHashes[2];
}
} else if (daysPassed >= 60) {
if (tokenId <= 176) {
return chiHashes[1];
} else if (tokenId % 88 == 0) {
return stlHashes[1];
} else {
return normHashes[1];
}
} else {
if (tokenId <= 176) {
return chiHashes[0];
} else if (tokenId % 88 == 0) {
return stlHashes[0];
} else {
return normHashes[0];
}
}
}
function _beforeTokenTransfer(address from, address to, uint256 tokenId)
internal virtual override
{
if (_exists(tokenId) && countDaysPassed(tokenId) < 557) {
_setBirthday(tokenId);
}
emit PlugTransferred(from, to);
}
function _setBirthday(uint256 tokenId)
private
{
_birthdays[tokenId] = block.timestamp;
}
function listPlugOwnersForHash(string memory assetHash)
public view returns (address[] memory)
{
require(_hashExists(assetHash), "Plug: nonexistent hash");
address[] memory levelOwners = new address[](MAX_NUM_TOKENS);
uint16 tokenId;
uint16 counter;
for (tokenId = 1; tokenId <= _tokenIds.current(); tokenId++) {
if (_stringsEqual(_tokenHash(tokenId), assetHash)) {
levelOwners[counter] = ownerOf(tokenId);
counter++;
}
}
return levelOwners;
}
function listPlugOwnersForType(uint8 group)
groupInRange(group) public view returns (address[] memory)
{
address[] memory typeOwners = new address[](MAX_NUM_TOKENS);
uint16 tokenId;
uint16 counter;
if (group == 0) {
for (tokenId = 177; tokenId <= MAX_NUM_TOKENS; tokenId++) {
if (tokenId % 88 != 0 && _exists(tokenId)) {
typeOwners[counter] = ownerOf(tokenId);
counter++;
}
}
} else if (group == 1) {
for (tokenId = 1; tokenId <= 176; tokenId++) {
if (_exists(tokenId)) {
typeOwners[counter] = ownerOf(tokenId);
counter++;
}
}
} else {
for (tokenId = 177; tokenId <= MAX_NUM_TOKENS; tokenId++) {
if (tokenId % 88 == 0 && _exists(tokenId)) {
typeOwners[counter] = ownerOf(tokenId);
counter++;
}
}
}
return typeOwners;
}
function mint(address to)
isSquad public virtual override returns (uint256)
{
return _mintInternal(to);
}
function purchase(
address payable to,
uint256 numToMint
) whitelistDisabled batchLimit(numToMint) plugsAvailable(numToMint)
public payable
returns (bool)
{
require(msg.value >= numToMint * TOKEN_WEI_PRICE, "Plug: not enough ether");
if (msg.value > 0) {
uint256 diff = msg.value.sub(TOKEN_WEI_PRICE * numToMint);
if (diff > 0) {
to.transfer(diff);
}
}
uint8 i;
for (i = 0; i < numToMint; i++) {
_mintInternal(to);
}
return true;
}
function whitelistPurchase(
address payable to,
uint256 numToMint
) whitelistEnabled onlyWhitelist(to) batchLimit(numToMint) plugsAvailable(numToMint)
public payable
returns (bool)
{
require(msg.value >= numToMint * TOKEN_WEI_PRICE, "Plug: not enough ether");
if (msg.value > 0) {
uint256 diff = msg.value.sub(TOKEN_WEI_PRICE * numToMint);
if (diff > 0) {
to.transfer(diff);
}
}
uint8 i;
for (i = 0; i < numToMint; i++) {
_mintInternal(to);
}
return true;
}
function _mintInternal(address to)
plugsAvailable(1) internal virtual returns (uint256)
{
_tokenIds.increment();
uint256 newId = _tokenIds.current();
_safeMint(to, newId);
_setBirthday(newId);
emit ERC721Minted(newId);
return newId;
}
function countDaysPassed(uint256 tokenId)
tokenExists(tokenId) public view returns (uint256)
{
return uint256((block.timestamp - _birthdays[tokenId]) / 1 days);
}
}
文件 16 的 17:SafeMath.sol
pragma solidity ^0.8.0;
library SafeMath {
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
}
文件 17 的 17:Strings.sol
pragma solidity ^0.8.0;
library Strings {
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
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);
}
}
{
"compilationTarget": {
"contracts/Plug.sol": "Plug"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","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":"uint256","name":"tokenId","type":"uint256"}],"name":"ERC721Burned","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ERC721Minted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"}],"name":"PlugTransferred","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":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[],"name":"activateWhitelist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"a","type":"address"}],"name":"addToSquad","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"a","type":"address"}],"name":"addToWhitelist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","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":[{"internalType":"address[]","name":"addys","type":"address[]"}],"name":"bulkAddToWhitelist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"burn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"contractURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"countDaysPassed","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"deactivateWhitelist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCurrentId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint8","name":"group","type":"uint8"},{"internalType":"uint8","name":"idx","type":"uint8"}],"name":"getHashByIndex","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"getRaribleV2Royalties","outputs":[{"components":[{"internalType":"address payable","name":"account","type":"address"},{"internalType":"uint96","name":"value","type":"uint96"}],"internalType":"struct LibPart.Part[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"a","type":"address"}],"name":"isInSquad","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"a","type":"address"}],"name":"isInWhitelist","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"kill","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"assetHash","type":"string"}],"name":"listPlugOwnersForHash","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint8","name":"group","type":"uint8"}],"name":"listPlugOwnersForType","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"mint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","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":"uint256","name":"tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"payoutAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address payable","name":"to","type":"address"},{"internalType":"uint256","name":"numToMint","type":"uint256"}],"name":"purchase","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"a","type":"address"}],"name":"removeFromSquad","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"a","type":"address"}],"name":"removeFromWhitelist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"royaltyFeeBps","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"salePrice","type":"uint256"}],"name":"royaltyInfo","outputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","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":"tokenId","type":"uint256"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"safeTransferFrom","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":"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":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"updatedContractUri","type":"string"}],"name":"updateContractUri","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint8","name":"group","type":"uint8"},{"internalType":"uint8","name":"hashNum","type":"uint8"},{"internalType":"string","name":"str","type":"string"}],"name":"updateHash","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"to","type":"address"},{"internalType":"uint256","name":"numToMint","type":"uint256"}],"name":"whitelistPurchase","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address payable","name":"wallet","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"}]