编译器
0.8.13+commit.abaa5c0e
文件 1 的 28:AccessControl.sol
pragma solidity ^0.8.0;
import "./IAccessControl.sol";
import "../utils/Context.sol";
import "../utils/Strings.sol";
import "../utils/introspection/ERC165.sol";
abstract contract AccessControl is Context, IAccessControl, ERC165 {
struct RoleData {
mapping(address => bool) members;
bytes32 adminRole;
}
mapping(bytes32 => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
modifier onlyRole(bytes32 role) {
_checkRole(role);
_;
}
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
}
function hasRole(bytes32 role, address account) public view virtual override returns (bool) {
return _roles[role].members[account];
}
function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender());
}
function _checkRole(bytes32 role, address account) internal view virtual {
if (!hasRole(role, account)) {
revert(
string(
abi.encodePacked(
"AccessControl: account ",
Strings.toHexString(uint160(account), 20),
" is missing role ",
Strings.toHexString(uint256(role), 32)
)
)
);
}
}
function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {
return _roles[role].adminRole;
}
function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
function renounceRole(bytes32 role, address account) public virtual override {
require(account == _msgSender(), "AccessControl: can only renounce roles for self");
_revokeRole(role, account);
}
function _setupRole(bytes32 role, address account) internal virtual {
_grantRole(role, account);
}
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
bytes32 previousAdminRole = getRoleAdmin(role);
_roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
function _grantRole(bytes32 role, address account) internal virtual {
if (!hasRole(role, account)) {
_roles[role].members[account] = true;
emit RoleGranted(role, account, _msgSender());
}
}
function _revokeRole(bytes32 role, address account) internal virtual {
if (hasRole(role, account)) {
_roles[role].members[account] = false;
emit RoleRevoked(role, account, _msgSender());
}
}
}
文件 2 的 28:AccessControlEnumerable.sol
pragma solidity ^0.8.0;
import "./IAccessControlEnumerable.sol";
import "./AccessControl.sol";
import "../utils/structs/EnumerableSet.sol";
abstract contract AccessControlEnumerable is IAccessControlEnumerable, AccessControl {
using EnumerableSet for EnumerableSet.AddressSet;
mapping(bytes32 => EnumerableSet.AddressSet) private _roleMembers;
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControlEnumerable).interfaceId || super.supportsInterface(interfaceId);
}
function getRoleMember(bytes32 role, uint256 index) public view virtual override returns (address) {
return _roleMembers[role].at(index);
}
function getRoleMemberCount(bytes32 role) public view virtual override returns (uint256) {
return _roleMembers[role].length();
}
function _grantRole(bytes32 role, address account) internal virtual override {
super._grantRole(role, account);
_roleMembers[role].add(account);
}
function _revokeRole(bytes32 role, address account) internal virtual override {
super._revokeRole(role, account);
_roleMembers[role].remove(account);
}
}
文件 3 的 28:Address.sol
pragma solidity ^0.8.1;
library Address {
function isContract(address account) internal view returns (bool) {
return account.code.length > 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);
}
}
}
}
文件 4 的 28:BlackHolePrevention.sol
pragma solidity 0.8.13;
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract BlackHolePrevention is Ownable {
function retrieveETH() external onlyOwner {
payable(msg.sender).transfer(address(this).balance);
}
function retrieveERC20(address _tracker, uint256 amount) external onlyOwner {
IERC20(_tracker).transfer(msg.sender, amount);
}
function retrieve721(address _tracker, uint256 id) external onlyOwner {
IERC721(_tracker).transferFrom(address(this), msg.sender, id);
}
}
文件 5 的 28:CommunityList.sol
pragma solidity 0.8.13;
import "@openzeppelin/contracts/access/AccessControlEnumerable.sol";
contract CommunityList is AccessControlEnumerable {
bytes32 public constant CONTRACT_ADMIN = keccak256("CONTRACT_ADMIN");
uint256 public numberOfEntries;
struct community_entry {
string name;
address registry;
uint32 id;
}
mapping(uint32 => community_entry) public communities;
mapping(uint256 => uint32) public index;
event CommunityAdded(uint256 pos, string community_name, address community_registry, uint32 community_id);
constructor() {
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
_setupRole(CONTRACT_ADMIN,msg.sender);
}
function addCommunity(uint32 community_id, string memory community_name, address community_registry) external onlyRole(CONTRACT_ADMIN) {
uint256 pos = numberOfEntries++;
index[pos] = community_id;
communities[community_id] = community_entry(community_name, community_registry, community_id);
emit CommunityAdded(pos, community_name, community_registry, community_id);
}
}
文件 6 的 28:CommunityRegistry.sol
pragma solidity 0.8.13;
import "@openzeppelin/contracts/access/AccessControlEnumerable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
interface IOwnable {
function owner() external view returns (address);
}
contract CommunityRegistry is AccessControlEnumerable {
bytes32 public constant COMMUNITY_REGISTRY_ADMIN = keccak256("COMMUNITY_REGISTRY_ADMIN");
uint32 public community_id;
string public community_name;
address public community_admin;
mapping(bytes32 => address) addresses;
mapping(bytes32 => uint256) uints;
mapping(bytes32 => bool) booleans;
mapping(bytes32 => string) strings;
mapping(address => mapping(address => bool)) public app_admins;
mapping (uint => string) public addressEntries;
mapping (uint => string) public uintEntries;
mapping (uint => string) public boolEntries;
mapping (uint => string) public stringEntries;
uint public numberOfAddresses;
uint public numberOfUINTs;
uint public numberOfBooleans;
uint public numberOfStrings;
uint public nextAdmin;
mapping(address => bool) public adminHas;
mapping(uint256 => address) public adminEntries;
mapping(address => uint256) public appAdminCounter;
mapping(address =>mapping(uint256 =>address)) public appAdminEntries;
address public owner;
bool initialised;
bool public independant;
event IndependanceDay(bool gain_independance);
modifier onlyAdmin() {
require(isCommunityAdmin(COMMUNITY_REGISTRY_ADMIN),"CommunityRegistry : Unauthorised");
_;
}
function isCommunityAdmin(bytes32 role) internal view returns (bool) {
return isUserCommunityAdmin( role, msg.sender);
}
function isUserCommunityAdmin(bytes32 role, address user) public view returns (bool) {
if (user == owner || hasRole(DEFAULT_ADMIN_ROLE,user) ) return true;
if (independant){
return(
hasRole(role,user)
);
} else {
IAccessControlEnumerable ac = IAccessControlEnumerable(owner);
return(
ac.hasRole(role,user));
}
}
function grantRole(bytes32 key, address user) public override(AccessControl,IAccessControl) onlyAdmin {
_grantRole(key,user);
}
constructor (
uint32 _community_id,
address _community_admin,
string memory _community_name
) {
_init(_community_id,_community_admin,_community_name);
}
function init(
uint32 _community_id,
address _community_admin,
string memory _community_name
) external {
_init(_community_id,_community_admin,_community_name);
}
function _init(
uint32 _community_id,
address _community_admin,
string memory _community_name
) internal {
require(!initialised,"This can only be called once");
initialised = true;
community_id = _community_id;
community_name = _community_name;
community_admin = _community_admin;
_setupRole(DEFAULT_ADMIN_ROLE, community_admin);
owner = msg.sender;
}
event AdminUpdated(address user, bool isAdmin);
event AppAdminChanged(address app,address user,bool state);
event AddressChanged(string key, address value);
event UintChanged(string key, uint256 value);
event BooleanChanged(string key, bool value);
event StringChanged(string key, string value);
function setIndependant(bool gain_independance) external onlyAdmin {
if (independant != gain_independance) {
independant = gain_independance;
emit IndependanceDay(gain_independance);
}
}
function setAdmin(address user,bool status ) external onlyAdmin {
if (status)
_grantRole(COMMUNITY_REGISTRY_ADMIN,user);
else
_revokeRole(COMMUNITY_REGISTRY_ADMIN,user);
}
function hash(string memory field) internal pure returns (bytes32) {
return keccak256(abi.encode(field));
}
function setRegistryAddress(string memory fn, address value) external onlyAdmin {
bytes32 hf = hash(fn);
addresses[hf] = value;
addressEntries[numberOfAddresses++] = fn;
emit AddressChanged(fn,value);
}
function setRegistryBool(string memory fn, bool value) external onlyAdmin {
bytes32 hf = hash(fn);
booleans[hf] = value;
boolEntries[numberOfBooleans++] = fn;
emit BooleanChanged(fn,value);
}
function setRegistryString(string memory fn, string memory value) external onlyAdmin {
bytes32 hf = hash(fn);
strings[hf] = value;
stringEntries[numberOfStrings++] = fn;
emit StringChanged(fn,value);
}
function setRegistryUINT(string memory fn, uint value) external onlyAdmin {
bytes32 hf = hash(fn);
uints[hf] = value;
uintEntries[numberOfUINTs++] = fn;
emit UintChanged(fn,value);
}
function setAppAdmin(address app, address user, bool state) external {
require(
msg.sender == IOwnable(app).owner() ||
app_admins[app][msg.sender],
"You do not have access permission"
);
app_admins[app][user] = state;
if (state)
appAdminEntries[app][appAdminCounter[app]++] = user;
emit AppAdminChanged(app,user,state);
}
function getRegistryAddress(string memory key) external view returns (address) {
return addresses[hash(key)];
}
function getRegistryBool(string memory key) external view returns (bool) {
return booleans[hash(key)];
}
function getRegistryUINT(string memory key) external view returns (uint256) {
return uints[hash(key)];
}
function getRegistryString(string memory key) external view returns (string memory) {
return strings[hash(key)];
}
function isAppAdmin(address app, address user) external view returns (bool) {
return
user == IOwnable(app).owner() ||
app_admins[app][user];
}
}
文件 7 的 28: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;
}
}
文件 8 的 28: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;
}
}
文件 9 的 28:ERC721.sol
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/utils/Context.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "@openzeppelin/contracts/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;
bool private _initialized;
function setup(string memory name_, string memory symbol_) public {
require(!_initialized, "ERC721: Contract already initialized");
_name = name_;
_symbol = symbol_;
_initialized = true;
}
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 {
_setApprovalForAll(_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 || isApprovedForAll(owner, spender) || getApproved(tokenId) == 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);
_afterTokenTransfer(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);
_afterTokenTransfer(owner, address(0), tokenId);
}
function _transfer(
address from,
address to,
uint256 tokenId
) internal virtual {
require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner");
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);
_afterTokenTransfer(from, to, tokenId);
}
function _approve(address to, uint256 tokenId) internal virtual {
_tokenApprovals[tokenId] = to;
emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
}
function _setApprovalForAll(
address owner,
address operator,
bool approved
) internal virtual {
require(owner != operator, "ERC721: approve to caller");
_operatorApprovals[owner][operator] = approved;
emit ApprovalForAll(owner, operator, approved);
}
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 {}
function _afterTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual {}
}
文件 10 的 28:ERC721Enumerable.sol
pragma solidity ^0.8.0;
import "./ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol";
abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
mapping(address => mapping(uint256 => uint256)) private _ownedTokens;
mapping(uint256 => uint256) private _ownedTokensIndex;
uint256[] private _allTokens;
mapping(uint256 => uint256) private _allTokensIndex;
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721) returns (bool) {
return interfaceId == type(IERC721Enumerable).interfaceId || super.supportsInterface(interfaceId);
}
function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) {
require(index < ERC721.balanceOf(owner), "ERC721Enumerable: owner index out of bounds");
return _ownedTokens[owner][index];
}
function totalSupply() public view virtual override returns (uint256) {
return _allTokens.length;
}
function tokenByIndex(uint256 index) public view virtual override returns (uint256) {
require(index < ERC721Enumerable.totalSupply(), "ERC721Enumerable: global index out of bounds");
return _allTokens[index];
}
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual override {
super._beforeTokenTransfer(from, to, tokenId);
if (from == address(0)) {
_addTokenToAllTokensEnumeration(tokenId);
} else if (from != to) {
_removeTokenFromOwnerEnumeration(from, tokenId);
}
if (to == address(0)) {
_removeTokenFromAllTokensEnumeration(tokenId);
} else if (to != from) {
_addTokenToOwnerEnumeration(to, tokenId);
}
}
function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
uint256 length = ERC721.balanceOf(to);
_ownedTokens[to][length] = tokenId;
_ownedTokensIndex[tokenId] = length;
}
function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
_allTokensIndex[tokenId] = _allTokens.length;
_allTokens.push(tokenId);
}
function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private {
uint256 lastTokenIndex = ERC721.balanceOf(from) - 1;
uint256 tokenIndex = _ownedTokensIndex[tokenId];
if (tokenIndex != lastTokenIndex) {
uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];
_ownedTokens[from][tokenIndex] = lastTokenId;
_ownedTokensIndex[lastTokenId] = tokenIndex;
}
delete _ownedTokensIndex[tokenId];
delete _ownedTokens[from][lastTokenIndex];
}
function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
uint256 lastTokenIndex = _allTokens.length - 1;
uint256 tokenIndex = _allTokensIndex[tokenId];
uint256 lastTokenId = _allTokens[lastTokenIndex];
_allTokens[tokenIndex] = lastTokenId;
_allTokensIndex[lastTokenId] = tokenIndex;
delete _allTokensIndex[tokenId];
_allTokens.pop();
}
}
文件 11 的 28:EnumerableSet.sol
pragma solidity ^0.8.0;
library EnumerableSet {
struct Set {
bytes32[] _values;
mapping(bytes32 => uint256) _indexes;
}
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
set._indexes[value] = set._values.length;
return true;
} else {
return false;
}
}
function _remove(Set storage set, bytes32 value) private returns (bool) {
uint256 valueIndex = set._indexes[value];
if (valueIndex != 0) {
uint256 toDeleteIndex = valueIndex - 1;
uint256 lastIndex = set._values.length - 1;
if (lastIndex != toDeleteIndex) {
bytes32 lastValue = set._values[lastIndex];
set._values[toDeleteIndex] = lastValue;
set._indexes[lastValue] = valueIndex;
}
set._values.pop();
delete set._indexes[value];
return true;
} else {
return false;
}
}
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._indexes[value] != 0;
}
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
function _at(Set storage set, uint256 index) private view returns (bytes32) {
return set._values[index];
}
function _values(Set storage set) private view returns (bytes32[] memory) {
return set._values;
}
struct Bytes32Set {
Set _inner;
}
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
return _values(set._inner);
}
struct AddressSet {
Set _inner;
}
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
function values(AddressSet storage set) internal view returns (address[] memory) {
bytes32[] memory store = _values(set._inner);
address[] memory result;
assembly {
result := store
}
return result;
}
struct UintSet {
Set _inner;
}
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
function values(UintSet storage set) internal view returns (uint256[] memory) {
bytes32[] memory store = _values(set._inner);
uint256[] memory result;
assembly {
result := store
}
return result;
}
}
文件 12 的 28:IAccessControl.sol
pragma solidity ^0.8.0;
interface IAccessControl {
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
function hasRole(bytes32 role, address account) external view returns (bool);
function getRoleAdmin(bytes32 role) external view returns (bytes32);
function grantRole(bytes32 role, address account) external;
function revokeRole(bytes32 role, address account) external;
function renounceRole(bytes32 role, address account) external;
}
文件 13 的 28:IAccessControlEnumerable.sol
pragma solidity ^0.8.0;
import "./IAccessControl.sol";
interface IAccessControlEnumerable is IAccessControl {
function getRoleMember(bytes32 role, uint256 index) external view returns (address);
function getRoleMemberCount(bytes32 role) external view returns (uint256);
}
文件 14 的 28:IERC165.sol
pragma solidity ^0.8.0;
interface IERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
文件 15 的 28:IERC20.sol
pragma solidity ^0.8.0;
interface IERC20 {
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
}
文件 16 的 28:IERC721.sol
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
interface IERC721 is IERC165 {
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
function balanceOf(address owner) external view returns (uint256 balance);
function ownerOf(uint256 tokenId) external view returns (address owner);
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external;
function transferFrom(
address from,
address to,
uint256 tokenId
) external;
function approve(address to, uint256 tokenId) external;
function setApprovalForAll(address operator, bool _approved) external;
function getApproved(uint256 tokenId) external view returns (address operator);
function isApprovedForAll(address owner, address operator) external view returns (bool);
}
文件 17 的 28:IERC721Enumerable.sol
pragma solidity ^0.8.0;
import "../IERC721.sol";
interface IERC721Enumerable is IERC721 {
function totalSupply() external view returns (uint256);
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256);
function tokenByIndex(uint256 index) external view returns (uint256);
}
文件 18 的 28: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);
}
文件 19 的 28:IERC721Receiver.sol
pragma solidity ^0.8.0;
interface IERC721Receiver {
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
文件 20 的 28:IOperatorFilterRegistry.sol
pragma solidity ^0.8.13;
interface IOperatorFilterRegistry {
function isOperatorAllowed(address registrant, address operator) external view returns (bool);
function register(address registrant) external;
function registerAndSubscribe(address registrant, address subscription) external;
function registerAndCopyEntries(address registrant, address registrantToCopy) external;
function unregister(address addr) external;
function updateOperator(address registrant, address operator, bool filtered) external;
function updateOperators(address registrant, address[] calldata operators, bool filtered) external;
function updateCodeHash(address registrant, bytes32 codehash, bool filtered) external;
function updateCodeHashes(address registrant, bytes32[] calldata codeHashes, bool filtered) external;
function subscribe(address registrant, address registrantToSubscribe) external;
function unsubscribe(address registrant, bool copyExistingEntries) external;
function subscriptionOf(address addr) external returns (address registrant);
function subscribers(address registrant) external returns (address[] memory);
function subscriberAt(address registrant, uint256 index) external returns (address);
function copyEntriesOf(address registrant, address registrantToCopy) external;
function isOperatorFiltered(address registrant, address operator) external returns (bool);
function isCodeHashOfFiltered(address registrant, address operatorWithCode) external returns (bool);
function isCodeHashFiltered(address registrant, bytes32 codeHash) external returns (bool);
function filteredOperators(address addr) external returns (address[] memory);
function filteredCodeHashes(address addr) external returns (bytes32[] memory);
function filteredOperatorAt(address registrant, uint256 index) external returns (address);
function filteredCodeHashAt(address registrant, uint256 index) external returns (bytes32);
function isRegistered(address addr) external returns (bool);
function codeHashOf(address addr) external returns (bytes32);
}
文件 21 的 28:IRandomNumberProvider.sol
pragma solidity 0.8.13;
interface IRandomNumberProvider {
function requestRandomNumber() external returns (uint256 requestId);
function requestRandomNumberWithCallback() external returns (uint256);
function isRequestComplete(uint256 requestId) external view returns (bool isCompleted);
function randomNumber(uint256 requestId) external view returns (uint256 randomNum);
function setAuth(address user, bool grant) external;
}
文件 22 的 28:IRandomNumberRequester.sol
pragma solidity 0.8.13;
interface IRandomNumberRequester {
function process(uint256 rand, uint256 requestId) external;
}
文件 23 的 28:IRegistryConsumer.sol
pragma solidity 0.8.13;
interface IRegistryConsumer {
function getRegistryAddress(string memory key) external view returns (address) ;
function getRegistryBool(string memory key) external view returns (bool);
function getRegistryUINT(string memory key) external view returns (uint256) ;
function getRegistryString(string memory key) external view returns (string memory) ;
function isAdmin(address user) external view returns (bool);
}
文件 24 的 28:IToken.sol
pragma solidity 0.8.13;
struct revealStruct {
uint256 REQUEST_ID;
uint256 RANDOM_NUM;
uint256 SHIFT;
uint256 RANGE_START;
uint256 RANGE_END;
bool processed;
}
struct TokenInfoForSale {
uint256 projectID;
uint256 maxSupply;
uint256 reservedSupply;
}
struct TokenInfo {
string name;
string symbol;
uint256 projectID;
uint256 maxSupply;
uint256 mintedSupply;
uint256 mintedReserve;
uint256 reservedSupply;
uint256 giveawaySupply;
string tokenPreRevealURI;
string tokenRevealURI;
bool transferLocked;
bool lastRevealRequested;
uint256 totalSupply;
revealStruct[] reveals;
address owner;
address[] managers;
address[] controllers;
}
struct TokenConstructorConfig {
uint256 projectID;
uint256 maxSupply;
string erc721name;
string erc721symbol;
string tokenPreRevealURI;
string tokenRevealURI;
bool transferLocked;
uint256 reservedSupply;
uint256 giveawaySupply;
}
interface IToken {
function TOKEN_CONTRACT_GIVEAWAY() external returns (bytes32);
function TOKEN_CONTRACT_ACCESS_SALE() external returns (bytes32);
function TOKEN_CONTRACT_ACCESS_ADMIN() external returns (bytes32);
function TOKEN_CONTRACT_ACCESS_LOCK() external returns (bytes32);
function TOKEN_CONTRACT_ACCESS_REVEAL() external returns (bytes32);
function mintIncrementalCards(uint256, address) external;
function mintReservedCards(uint256, address) external;
function mintGiveawayCard(uint256, address) external;
function setPreRevealURI(string calldata) external;
function setRevealURI(string calldata) external;
function revealAtCurrentSupply() external;
function lastReveal() external;
function process(uint256, uint256) external;
function uri(uint256) external view returns (uint256);
function tokenURI(uint256) external view returns (string memory);
function setTransferLock(bool) external;
function hasRole(bytes32, address) external view returns (bool);
function isAllowed(bytes32, address) external view returns (bool);
function getFirstGiveawayCardId() external view returns (uint256);
function tellEverything() external view returns (TokenInfo memory);
function getTokenInfoForSale() external view returns (TokenInfoForSale memory);
}
文件 25 的 28:LockableRevealERC721EnumerableToken.sol
pragma solidity 0.8.13;
import "./IToken.sol";
import "../interfaces/IRegistryConsumer.sol";
import "../interfaces/IRandomNumberProvider.sol";
import "../interfaces/IRandomNumberRequester.sol";
import "../extras/recovery/BlackHolePrevention.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "../../@galaxis/registries/contracts/CommunityList.sol";
import "../../@galaxis/registries/contracts/CommunityRegistry.sol";
import "../overrides/ERC721Enumerable.sol";
contract LockableRevealERC721EnumerableToken is IToken, ERC721Enumerable, Ownable, BlackHolePrevention {
using Strings for uint256;
bytes32 public constant TOKEN_CONTRACT_GIVEAWAY = keccak256("TOKEN_CONTRACT_GIVEAWAY");
bytes32 public constant TOKEN_CONTRACT_ACCESS_SALE = keccak256("TOKEN_CONTRACT_ACCESS_SALE");
bytes32 public constant TOKEN_CONTRACT_ACCESS_ADMIN = keccak256("TOKEN_CONTRACT_ACCESS_ADMIN");
bytes32 public constant TOKEN_CONTRACT_ACCESS_LOCK = keccak256("TOKEN_CONTRACT_ACCESS_LOCK");
bytes32 public constant TOKEN_CONTRACT_ACCESS_REVEAL = keccak256("TOKEN_CONTRACT_ACCESS_REVEAL");
IRegistryConsumer public TheRegistry;
string constant public REGISTRY_KEY_RANDOM_CONTRACT = "RANDOMV2_SSP";
uint256 public projectID;
uint256 public maxSupply;
uint256 public mintedSupply;
uint256 public mintedReserve;
uint256 public reservedSupply;
uint256 public giveawaySupply;
string public tokenPreRevealURI;
string public tokenRevealURI;
bool public transferLocked;
bool public lastRevealRequested;
mapping(uint16 => revealStruct) public reveals;
mapping(uint256 => uint16) public requestToRevealId;
string public revealURI;
uint16 public currentRevealCount;
string public contractURI;
bool _initialized;
CommunityRegistry public myCommunityRegistry;
using EnumerableSet for EnumerableSet.AddressSet;
EnumerableSet.AddressSet contractControllers;
event contractControllerEvent(address _address, bool mode);
EnumerableSet.AddressSet contractManagers;
event contractManagerEvent(address _address, bool mode);
event Locked(bool);
event RandomProcessed(uint256 stage, uint256 randNumber, uint256 _shiftsBy, uint256 _start, uint256 _end);
event ContractURIset(string contractURI);
function setup(TokenConstructorConfig memory config) public virtual onlyOwner {
require(!_initialized, "Token: Contract already initialized");
ERC721.setup(config.erc721name, config.erc721symbol);
uint256 chainId;
assembly {
chainId := chainid()
}
if(chainId == 1 || chainId == 5 || chainId == 1337 || chainId == 31337) {
TheRegistry = IRegistryConsumer(0x1e8150050A7a4715aad42b905C08df76883f396F);
} else {
require(false, "Token: invalid chainId");
}
projectID = config.projectID;
tokenPreRevealURI = config.tokenPreRevealURI;
tokenRevealURI = config.tokenRevealURI;
maxSupply = config.maxSupply;
transferLocked = config.transferLocked;
reservedSupply = config.reservedSupply;
giveawaySupply = config.giveawaySupply;
CommunityList COMMUNITY_LIST = CommunityList(TheRegistry.getRegistryAddress("COMMUNITY_LIST"));
(,address crAddr,) = COMMUNITY_LIST.communities(uint32(projectID));
myCommunityRegistry = CommunityRegistry(crAddr);
_initialized = true;
}
function _beforeTokenTransfer(
address from,
address to,
uint256 _tokenId
) internal override {
if(from != address(0)) {
require(!transferLocked, "Token: Transfers are not enabled");
}
super._beforeTokenTransfer(from, to, _tokenId);
}
function mintIncrementalCards(uint256 numberOfCards, address recipient) external onlyAllowed(TOKEN_CONTRACT_ACCESS_SALE) {
require(!lastRevealRequested, "Token: Cannot mint after last reveal");
require(mintedSupply + numberOfCards <= maxSupply - reservedSupply, "Token: This would exceed the number of cards available");
uint256 mintId = mintedSupply + 1;
for (uint j = 0; j < numberOfCards; j++) {
_mint(recipient, mintId++);
}
mintedSupply+=numberOfCards;
}
function mintReservedCards(uint256 numberOfCards, address recipient) external onlyAllowed(TOKEN_CONTRACT_ACCESS_ADMIN) {
require(lastRevealRequested, "Token: Last reveal must be requested first");
require(mintedReserve + numberOfCards <= reservedSupply - giveawaySupply, "Token: This would exceed the number of cards reserved cards available");
uint256 mintId = mintedSupply + mintedReserve + 1;
for (uint j = 0; j < numberOfCards; j++) {
_mint(recipient, mintId++);
}
mintedReserve+=numberOfCards;
}
function getFirstGiveawayCardId() public view returns (uint256) {
return mintedSupply + reservedSupply - giveawaySupply + 1;
}
function mintGiveawayCard(uint256 _index, address _recipient) external onlyAllowed(TOKEN_CONTRACT_GIVEAWAY) {
require(lastRevealRequested, "Token: Last reveal must be requested first");
require(mintedReserve == reservedSupply - giveawaySupply, "Token: Must mint reserved cards first");
uint256 firstIndex = getFirstGiveawayCardId();
require( _index >= firstIndex && _index < firstIndex + giveawaySupply, "Token: Card id not in range");
_mint(_recipient, _index);
}
function setPreRevealURI(string calldata _tokenPreRevealURI) external onlyAllowed(TOKEN_CONTRACT_ACCESS_ADMIN) {
tokenPreRevealURI = _tokenPreRevealURI;
}
function setRevealURI(string calldata _tokenRevealURI) external onlyAllowed(TOKEN_CONTRACT_ACCESS_ADMIN) {
tokenRevealURI = _tokenRevealURI;
}
function revealAtCurrentSupply() external onlyAllowed(TOKEN_CONTRACT_ACCESS_REVEAL) {
require(!lastRevealRequested, "Token: Last reveal already requested");
require(reveals[currentRevealCount].RANGE_END < mintedSupply, "Token: Reveal request already exists");
revealStruct storage currentReveal = reveals[++currentRevealCount];
currentReveal.RANGE_END = mintedSupply;
currentReveal.REQUEST_ID = IRandomNumberProvider(TheRegistry.getRegistryAddress(REGISTRY_KEY_RANDOM_CONTRACT)).requestRandomNumberWithCallback();
requestToRevealId[currentReveal.REQUEST_ID] = currentRevealCount;
}
function lastReveal() external onlyAllowed(TOKEN_CONTRACT_ACCESS_REVEAL) {
require(!lastRevealRequested, "Token: Last reveal already requested");
require(reveals[currentRevealCount].RANGE_END < maxSupply, "Token: Reveal request already exists");
lastRevealRequested = true;
revealStruct storage currentReveal = reveals[++currentRevealCount];
currentReveal.RANGE_END = mintedSupply + reservedSupply;
currentReveal.REQUEST_ID = IRandomNumberProvider(TheRegistry.getRegistryAddress(REGISTRY_KEY_RANDOM_CONTRACT)).requestRandomNumberWithCallback();
requestToRevealId[currentReveal.REQUEST_ID] = currentRevealCount;
}
function process(uint256 _random, uint256 _requestId) external {
require(msg.sender == TheRegistry.getRegistryAddress(REGISTRY_KEY_RANDOM_CONTRACT), "Token: process() Unauthorised caller");
uint16 thisRevealId = requestToRevealId[_requestId];
revealStruct storage thisReveal = reveals[thisRevealId];
require(!thisReveal.processed, "Token: reveal already processed.");
if(thisReveal.REQUEST_ID == _requestId) {
thisReveal.RANDOM_NUM = _random / 2;
if(thisReveal.RANDOM_NUM == 0) {
thisReveal.RANDOM_NUM = thisReveal.RANGE_END * (10 ** 5) / 3;
}
thisReveal.RANGE_START = reveals[currentRevealCount-1].RANGE_END;
thisReveal.SHIFT = thisReveal.RANDOM_NUM % ( thisReveal.RANGE_END - thisReveal.RANGE_START );
if(thisReveal.SHIFT == 0) {
thisReveal.RANDOM_NUM = thisReveal.RANDOM_NUM / 3;
thisReveal.SHIFT = thisReveal.RANDOM_NUM % ( thisReveal.RANGE_END - thisReveal.RANGE_START );
}
thisReveal.processed = true;
emit RandomProcessed(
thisRevealId,
thisReveal.RANDOM_NUM,
thisReveal.SHIFT,
thisReveal.RANGE_START,
thisReveal.RANGE_END
);
} else revert("Token: Incorrect requestId received");
}
function findRevealRangeForN(uint256 n) public view returns (uint16) {
for(uint16 i = 1; i <= currentRevealCount; i++) {
if(n <= reveals[i].RANGE_END) {
return i;
}
}
return 0;
}
function uri(uint256 n) public view returns (uint256) {
uint16 rangeId = findRevealRangeForN(n);
if(rangeId == 0) {
return n;
}
revealStruct memory currentReveal = reveals[rangeId];
uint256 shiftedN = n + currentReveal.SHIFT;
if (shiftedN <= currentReveal.RANGE_END) {
return shiftedN;
}
return currentReveal.RANGE_START + shiftedN - currentReveal.RANGE_END;
}
function _reserved(uint256 _tokenId) public view returns (bool) {
if(_tokenId > mintedSupply + mintedReserve && _tokenId <= mintedSupply + reservedSupply) {
return true;
}
return false;
}
function tokenURI(uint256 _tokenId) public view override(IToken, ERC721) returns (string memory) {
require(_exists(_tokenId) || _reserved(_tokenId), 'Token: Token does not exist');
uint16 rangeId = findRevealRangeForN(_tokenId);
if(rangeId == 0) {
return tokenPreRevealURI;
}
revealStruct memory currentReveal = reveals[rangeId];
if(currentReveal.RANDOM_NUM == 0) {
return tokenPreRevealURI;
}
uint256 newTokenId = uri(_tokenId);
string memory folder = (newTokenId % 100).toString();
string memory file = newTokenId.toString();
string memory slash = "/";
return string(abi.encodePacked(tokenRevealURI, folder, slash, file));
}
function setTransferLock(bool _locked) external onlyAllowed(TOKEN_CONTRACT_ACCESS_LOCK) {
transferLocked = _locked;
emit Locked(_locked);
}
function hasRole(bytes32 key, address user) public view returns (bool) {
return myCommunityRegistry.hasRole(key, user);
}
modifier onlyAllowed(bytes32 role) {
require(isAllowed(role, msg.sender), "Token: Unauthorised");
_;
}
function isAllowed(bytes32 role, address user) public view returns (bool) {
return( user == owner() || hasRole(role, user));
}
function tellEverything() external view returns (TokenInfo memory) {
revealStruct[] memory _reveals = new revealStruct[](currentRevealCount);
for(uint16 i = 1; i <= currentRevealCount; i++) {
_reveals[i - 1] = reveals[i];
}
uint256 contractManagers_length = contractManagers.length();
address[] memory _managers = new address[](contractManagers_length);
for(uint16 i = 0; i < contractManagers_length; i++) {
_managers[i] = contractManagers.at(i);
}
uint256 contractControllers_length = contractControllers.length();
address[] memory _controllers = new address[](contractControllers_length);
for(uint16 i = 0; i < contractControllers_length; i++) {
_controllers[i] = contractControllers.at(i);
}
return TokenInfo(
name(),
symbol(),
projectID,
maxSupply,
mintedSupply,
mintedReserve,
reservedSupply,
giveawaySupply,
tokenPreRevealURI,
tokenRevealURI,
transferLocked,
lastRevealRequested,
totalSupply(),
_reveals,
owner(),
_managers,
_controllers
);
}
function getTokenInfoForSale() external view returns (TokenInfoForSale memory) {
return TokenInfoForSale(
projectID,
maxSupply,
reservedSupply
);
}
function setContractURI(string memory _contractURI) external onlyAllowed(TOKEN_CONTRACT_ACCESS_ADMIN) {
contractURI = _contractURI;
emit ContractURIset(_contractURI);
}
}
文件 26 的 28:OperatorFilteredToken.sol
pragma solidity 0.8.13;
import "./LockableRevealERC721EnumerableToken.sol";
import "operator-filter-registry/src/IOperatorFilterRegistry.sol";
contract OperatorFilteredToken is LockableRevealERC721EnumerableToken {
error OperatorNotAllowed(address operator);
bool public OSFiltering = true;
address public DEFAULT_SUBSCRIPTION = address(0x3cc6CddA760b79bAfa08dF41ECFA224f810dCeB6);
IOperatorFilterRegistry public OPERATOR_FILTER_REGISTRY = IOperatorFilterRegistry(0x000000000000AAeB6D7670E522A718067333cd4E);
uint32 constant public version = 2022120701;
function setup(TokenConstructorConfig memory config) public virtual override onlyOwner {
if (address(OPERATOR_FILTER_REGISTRY).code.length > 0) {
OPERATOR_FILTER_REGISTRY.registerAndSubscribe(address(this), DEFAULT_SUBSCRIPTION);
}
super.setup(config);
}
function toggleOSFilterOperatorState() public onlyOwner() {
OSFiltering = !OSFiltering;
}
function setApprovalForAll(address operator, bool approved) public override(ERC721, IERC721) {
if(OSFiltering) {
_checkFilterOperator(operator);
}
super.setApprovalForAll(operator, approved);
}
function approve(address operator, uint256 tokenId) public override(ERC721, IERC721) {
if(OSFiltering) {
_checkFilterOperator(operator);
}
super.approve(operator, tokenId);
}
function transferFrom(address from, address to, uint256 tokenId) public override(ERC721, IERC721) {
if (OSFiltering && from != msg.sender) { _checkFilterOperator(msg.sender); }
super.transferFrom(from, to, tokenId);
}
function safeTransferFrom(address from, address to, uint256 tokenId) public override(ERC721, IERC721) {
if (OSFiltering && from != msg.sender) { _checkFilterOperator(msg.sender); }
super.safeTransferFrom(from, to, tokenId);
}
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public override(ERC721, IERC721) {
if (OSFiltering && from != msg.sender) { _checkFilterOperator(msg.sender); }
super.safeTransferFrom(from, to, tokenId, data);
}
function _checkFilterOperator(address operator) internal view virtual {
if (address(OPERATOR_FILTER_REGISTRY).code.length > 0) {
if (!OPERATOR_FILTER_REGISTRY.isOperatorAllowed(address(this), operator)) {
revert OperatorNotAllowed(operator);
}
}
}
}
文件 27 的 28:Ownable.sol
pragma solidity ^0.8.0;
import "../utils/Context.sol";
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
_transferOwnership(_msgSender());
}
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 {
_transferOwnership(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
文件 28 的 28: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/ssp/token/OperatorFilteredToken.sol": "OperatorFilteredToken"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs",
"useLiteralContent": true
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"operator","type":"address"}],"name":"OperatorNotAllowed","type":"error"},{"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":false,"internalType":"string","name":"contractURI","type":"string"}],"name":"ContractURIset","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"","type":"bool"}],"name":"Locked","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":false,"internalType":"uint256","name":"stage","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"randNumber","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_shiftsBy","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_start","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_end","type":"uint256"}],"name":"RandomProcessed","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"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_address","type":"address"},{"indexed":false,"internalType":"bool","name":"mode","type":"bool"}],"name":"contractControllerEvent","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_address","type":"address"},{"indexed":false,"internalType":"bool","name":"mode","type":"bool"}],"name":"contractManagerEvent","type":"event"},{"inputs":[],"name":"DEFAULT_SUBSCRIPTION","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"OPERATOR_FILTER_REGISTRY","outputs":[{"internalType":"contract IOperatorFilterRegistry","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"OSFiltering","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"REGISTRY_KEY_RANDOM_CONTRACT","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TOKEN_CONTRACT_ACCESS_ADMIN","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TOKEN_CONTRACT_ACCESS_LOCK","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TOKEN_CONTRACT_ACCESS_REVEAL","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TOKEN_CONTRACT_ACCESS_SALE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TOKEN_CONTRACT_GIVEAWAY","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TheRegistry","outputs":[{"internalType":"contract IRegistryConsumer","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"_reserved","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"operator","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":[],"name":"contractURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentRevealCount","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"n","type":"uint256"}],"name":"findRevealRangeForN","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getFirstGiveawayCardId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTokenInfoForSale","outputs":[{"components":[{"internalType":"uint256","name":"projectID","type":"uint256"},{"internalType":"uint256","name":"maxSupply","type":"uint256"},{"internalType":"uint256","name":"reservedSupply","type":"uint256"}],"internalType":"struct TokenInfoForSale","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"giveawaySupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"key","type":"bytes32"},{"internalType":"address","name":"user","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"user","type":"address"}],"name":"isAllowed","outputs":[{"internalType":"bool","name":"","type":"bool"}],"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":[],"name":"lastReveal","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"lastRevealRequested","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_index","type":"uint256"},{"internalType":"address","name":"_recipient","type":"address"}],"name":"mintGiveawayCard","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"numberOfCards","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"}],"name":"mintIncrementalCards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"numberOfCards","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"}],"name":"mintReservedCards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"mintedReserve","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"mintedSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"myCommunityRegistry","outputs":[{"internalType":"contract CommunityRegistry","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":"uint256","name":"tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_random","type":"uint256"},{"internalType":"uint256","name":"_requestId","type":"uint256"}],"name":"process","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"projectID","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"requestToRevealId","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"reservedSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_tracker","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"}],"name":"retrieve721","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_tracker","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"retrieveERC20","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"retrieveETH","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"revealAtCurrentSupply","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"revealURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint16","name":"","type":"uint16"}],"name":"reveals","outputs":[{"internalType":"uint256","name":"REQUEST_ID","type":"uint256"},{"internalType":"uint256","name":"RANDOM_NUM","type":"uint256"},{"internalType":"uint256","name":"SHIFT","type":"uint256"},{"internalType":"uint256","name":"RANGE_START","type":"uint256"},{"internalType":"uint256","name":"RANGE_END","type":"uint256"},{"internalType":"bool","name":"processed","type":"bool"}],"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":"string","name":"_contractURI","type":"string"}],"name":"setContractURI","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_tokenPreRevealURI","type":"string"}],"name":"setPreRevealURI","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_tokenRevealURI","type":"string"}],"name":"setRevealURI","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_locked","type":"bool"}],"name":"setTransferLock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"name_","type":"string"},{"internalType":"string","name":"symbol_","type":"string"}],"name":"setup","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"projectID","type":"uint256"},{"internalType":"uint256","name":"maxSupply","type":"uint256"},{"internalType":"string","name":"erc721name","type":"string"},{"internalType":"string","name":"erc721symbol","type":"string"},{"internalType":"string","name":"tokenPreRevealURI","type":"string"},{"internalType":"string","name":"tokenRevealURI","type":"string"},{"internalType":"bool","name":"transferLocked","type":"bool"},{"internalType":"uint256","name":"reservedSupply","type":"uint256"},{"internalType":"uint256","name":"giveawaySupply","type":"uint256"}],"internalType":"struct TokenConstructorConfig","name":"config","type":"tuple"}],"name":"setup","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":[],"name":"tellEverything","outputs":[{"components":[{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"symbol","type":"string"},{"internalType":"uint256","name":"projectID","type":"uint256"},{"internalType":"uint256","name":"maxSupply","type":"uint256"},{"internalType":"uint256","name":"mintedSupply","type":"uint256"},{"internalType":"uint256","name":"mintedReserve","type":"uint256"},{"internalType":"uint256","name":"reservedSupply","type":"uint256"},{"internalType":"uint256","name":"giveawaySupply","type":"uint256"},{"internalType":"string","name":"tokenPreRevealURI","type":"string"},{"internalType":"string","name":"tokenRevealURI","type":"string"},{"internalType":"bool","name":"transferLocked","type":"bool"},{"internalType":"bool","name":"lastRevealRequested","type":"bool"},{"internalType":"uint256","name":"totalSupply","type":"uint256"},{"components":[{"internalType":"uint256","name":"REQUEST_ID","type":"uint256"},{"internalType":"uint256","name":"RANDOM_NUM","type":"uint256"},{"internalType":"uint256","name":"SHIFT","type":"uint256"},{"internalType":"uint256","name":"RANGE_START","type":"uint256"},{"internalType":"uint256","name":"RANGE_END","type":"uint256"},{"internalType":"bool","name":"processed","type":"bool"}],"internalType":"struct revealStruct[]","name":"reveals","type":"tuple[]"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"address[]","name":"managers","type":"address[]"},{"internalType":"address[]","name":"controllers","type":"address[]"}],"internalType":"struct TokenInfo","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"toggleOSFilterOperatorState","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"tokenByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"tokenOfOwnerByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tokenPreRevealURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tokenRevealURI","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":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"transferLocked","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"n","type":"uint256"}],"name":"uri","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"}]