文件 1 的 19:Address.sol
pragma solidity >=0.6.2 <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) private 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 的 19:Context.sol
pragma solidity >=0.6.0 <0.8.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address payable) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes memory) {
this;
return msg.data;
}
}
文件 3 的 19:ERC165.sol
pragma solidity >=0.6.0 <0.8.0;
import "./IERC165.sol";
abstract contract ERC165 is IERC165 {
bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7;
mapping(bytes4 => bool) private _supportedInterfaces;
constructor () internal {
_registerInterface(_INTERFACE_ID_ERC165);
}
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return _supportedInterfaces[interfaceId];
}
function _registerInterface(bytes4 interfaceId) internal virtual {
require(interfaceId != 0xffffffff, "ERC165: invalid interface id");
_supportedInterfaces[interfaceId] = true;
}
}
文件 4 的 19:ERC721.sol
pragma solidity >=0.6.0 <0.8.0;
import "../../utils/Context.sol";
import "./IERC721.sol";
import "./IERC721Metadata.sol";
import "./IERC721Enumerable.sol";
import "./IERC721Receiver.sol";
import "../../introspection/ERC165.sol";
import "../../math/SafeMath.sol";
import "../../utils/Address.sol";
import "../../utils/EnumerableSet.sol";
import "../../utils/EnumerableMap.sol";
import "../../utils/Strings.sol";
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Enumerable {
using SafeMath for uint256;
using Address for address;
using EnumerableSet for EnumerableSet.UintSet;
using EnumerableMap for EnumerableMap.UintToAddressMap;
using Strings for uint256;
bytes4 private constant _ERC721_RECEIVED = 0x150b7a02;
mapping (address => EnumerableSet.UintSet) private _holderTokens;
EnumerableMap.UintToAddressMap private _tokenOwners;
mapping (uint256 => address) private _tokenApprovals;
mapping (address => mapping (address => bool)) private _operatorApprovals;
string private _name;
string private _symbol;
mapping (uint256 => string) private _tokenURIs;
string private _baseURI;
bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd;
bytes4 private constant _INTERFACE_ID_ERC721_METADATA = 0x5b5e139f;
bytes4 private constant _INTERFACE_ID_ERC721_ENUMERABLE = 0x780e9d63;
constructor (string memory name_, string memory symbol_) public {
_name = name_;
_symbol = symbol_;
_registerInterface(_INTERFACE_ID_ERC721);
_registerInterface(_INTERFACE_ID_ERC721_METADATA);
_registerInterface(_INTERFACE_ID_ERC721_ENUMERABLE);
}
function balanceOf(address owner) public view virtual override returns (uint256) {
require(owner != address(0), "ERC721: balance query for the zero address");
return _holderTokens[owner].length();
}
function ownerOf(uint256 tokenId) public view virtual override returns (address) {
return _tokenOwners.get(tokenId, "ERC721: owner query for nonexistent token");
}
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 _tokenURI = _tokenURIs[tokenId];
string memory base = baseURI();
if (bytes(base).length == 0) {
return _tokenURI;
}
if (bytes(_tokenURI).length > 0) {
return string(abi.encodePacked(base, _tokenURI));
}
return string(abi.encodePacked(base, tokenId.toString()));
}
function baseURI() public view virtual returns (string memory) {
return _baseURI;
}
function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) {
return _holderTokens[owner].at(index);
}
function totalSupply() public view virtual override returns (uint256) {
return _tokenOwners.length();
}
function tokenByIndex(uint256 index) public view virtual override returns (uint256) {
(uint256 tokenId, ) = _tokenOwners.at(index);
return tokenId;
}
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 || ERC721.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 _tokenOwners.contains(tokenId);
}
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 || ERC721.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);
_holderTokens[to].add(tokenId);
_tokenOwners.set(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);
if (bytes(_tokenURIs[tokenId]).length != 0) {
delete _tokenURIs[tokenId];
}
_holderTokens[owner].remove(tokenId);
_tokenOwners.remove(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);
_holderTokens[from].remove(tokenId);
_holderTokens[to].add(tokenId);
_tokenOwners.set(tokenId, to);
emit Transfer(from, to, tokenId);
}
function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual {
require(_exists(tokenId), "ERC721Metadata: URI set of nonexistent token");
_tokenURIs[tokenId] = _tokenURI;
}
function _setBaseURI(string memory baseURI_) internal virtual {
_baseURI = baseURI_;
}
function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory _data)
private returns (bool)
{
if (!to.isContract()) {
return true;
}
bytes memory returndata = to.functionCall(abi.encodeWithSelector(
IERC721Receiver(to).onERC721Received.selector,
_msgSender(),
from,
tokenId,
_data
), "ERC721: transfer to non ERC721Receiver implementer");
bytes4 retval = abi.decode(returndata, (bytes4));
return (retval == _ERC721_RECEIVED);
}
function _approve(address to, uint256 tokenId) internal virtual {
_tokenApprovals[tokenId] = to;
emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
}
function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual { }
}
文件 5 的 19:EnumerableMap.sol
pragma solidity >=0.6.0 <0.8.0;
library EnumerableMap {
struct MapEntry {
bytes32 _key;
bytes32 _value;
}
struct Map {
MapEntry[] _entries;
mapping (bytes32 => uint256) _indexes;
}
function _set(Map storage map, bytes32 key, bytes32 value) private returns (bool) {
uint256 keyIndex = map._indexes[key];
if (keyIndex == 0) {
map._entries.push(MapEntry({ _key: key, _value: value }));
map._indexes[key] = map._entries.length;
return true;
} else {
map._entries[keyIndex - 1]._value = value;
return false;
}
}
function _remove(Map storage map, bytes32 key) private returns (bool) {
uint256 keyIndex = map._indexes[key];
if (keyIndex != 0) {
uint256 toDeleteIndex = keyIndex - 1;
uint256 lastIndex = map._entries.length - 1;
MapEntry storage lastEntry = map._entries[lastIndex];
map._entries[toDeleteIndex] = lastEntry;
map._indexes[lastEntry._key] = toDeleteIndex + 1;
map._entries.pop();
delete map._indexes[key];
return true;
} else {
return false;
}
}
function _contains(Map storage map, bytes32 key) private view returns (bool) {
return map._indexes[key] != 0;
}
function _length(Map storage map) private view returns (uint256) {
return map._entries.length;
}
function _at(Map storage map, uint256 index) private view returns (bytes32, bytes32) {
require(map._entries.length > index, "EnumerableMap: index out of bounds");
MapEntry storage entry = map._entries[index];
return (entry._key, entry._value);
}
function _tryGet(Map storage map, bytes32 key) private view returns (bool, bytes32) {
uint256 keyIndex = map._indexes[key];
if (keyIndex == 0) return (false, 0);
return (true, map._entries[keyIndex - 1]._value);
}
function _get(Map storage map, bytes32 key) private view returns (bytes32) {
uint256 keyIndex = map._indexes[key];
require(keyIndex != 0, "EnumerableMap: nonexistent key");
return map._entries[keyIndex - 1]._value;
}
function _get(Map storage map, bytes32 key, string memory errorMessage) private view returns (bytes32) {
uint256 keyIndex = map._indexes[key];
require(keyIndex != 0, errorMessage);
return map._entries[keyIndex - 1]._value;
}
struct UintToAddressMap {
Map _inner;
}
function set(UintToAddressMap storage map, uint256 key, address value) internal returns (bool) {
return _set(map._inner, bytes32(key), bytes32(uint256(uint160(value))));
}
function remove(UintToAddressMap storage map, uint256 key) internal returns (bool) {
return _remove(map._inner, bytes32(key));
}
function contains(UintToAddressMap storage map, uint256 key) internal view returns (bool) {
return _contains(map._inner, bytes32(key));
}
function length(UintToAddressMap storage map) internal view returns (uint256) {
return _length(map._inner);
}
function at(UintToAddressMap storage map, uint256 index) internal view returns (uint256, address) {
(bytes32 key, bytes32 value) = _at(map._inner, index);
return (uint256(key), address(uint160(uint256(value))));
}
function tryGet(UintToAddressMap storage map, uint256 key) internal view returns (bool, address) {
(bool success, bytes32 value) = _tryGet(map._inner, bytes32(key));
return (success, address(uint160(uint256(value))));
}
function get(UintToAddressMap storage map, uint256 key) internal view returns (address) {
return address(uint160(uint256(_get(map._inner, bytes32(key)))));
}
function get(UintToAddressMap storage map, uint256 key, string memory errorMessage) internal view returns (address) {
return address(uint160(uint256(_get(map._inner, bytes32(key), errorMessage))));
}
}
文件 6 的 19:EnumerableSet.sol
pragma solidity >=0.6.0 <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;
bytes32 lastvalue = set._values[lastIndex];
set._values[toDeleteIndex] = lastvalue;
set._indexes[lastvalue] = toDeleteIndex + 1;
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) {
require(set._values.length > index, "EnumerableSet: index out of bounds");
return set._values[index];
}
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);
}
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))));
}
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));
}
}
文件 7 的 19:HelperFunctions.sol
pragma solidity >=0.6.0 <0.8.0;
pragma experimental ABIEncoderV2;
library HelperFunctions {
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);
uint256 index = digits - 1;
temp = value;
while (temp != 0) {
buffer[index--] = bytes1(uint8(48 + temp % 10));
temp /= 10;
}
return string(buffer);
}
function safeParseInt(string memory _a) internal pure returns (uint _parsedInt) {
return safeParseInt(_a, 0);
}
function safeParseInt(string memory _a, uint _b) internal pure returns (uint _parsedInt) {
bytes memory bresult = bytes(_a);
uint mint = 0;
bool decimals = false;
for (uint i = 0; i < bresult.length; i++) {
if ((uint(uint8(bresult[i])) >= 48) && (uint(uint8(bresult[i])) <= 57)) {
if (decimals) {
if (_b == 0) break;
else _b--;
}
mint *= 10;
mint += uint(uint8(bresult[i])) - 48;
} else if (uint(uint8(bresult[i])) == 46) {
require(!decimals, 'ERR: More than one decimal');
decimals = true;
} else {
revert("ERR: Non-numeral character");
}
}
if (_b > 0) {
mint *= 10 ** _b;
}
return mint;
}
function substring(string memory str, uint startIndex, uint endIndex) internal pure returns (string memory) {
bytes memory strBytes = bytes(str);
bytes memory result = new bytes(endIndex-startIndex);
for(uint i = startIndex; i < endIndex; i++) {
result[i-startIndex] = strBytes[i];
}
return string(result);
}
function addressToString(address _address) internal pure returns(string memory) {
bytes32 _bytes = bytes32(uint256(_address));
bytes memory HEX = "0123456789abcdef";
bytes memory _string = new bytes(42);
_string[0] = '0';
_string[1] = 'x';
for(uint i = 0; i < 20; i++) {
_string[2+i*2] = HEX[uint8(_bytes[i + 12] >> 4)];
_string[3+i*2] = HEX[uint8(_bytes[i + 12] & 0x0f)];
}
return string(_string);
}
}
文件 8 的 19:IERC165.sol
pragma solidity >=0.6.0 <0.8.0;
interface IERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
文件 9 的 19:IERC721.sol
pragma solidity >=0.6.2 <0.8.0;
import "../../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;
}
文件 10 的 19:IERC721Enumerable.sol
pragma solidity >=0.6.2 <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 tokenId);
function tokenByIndex(uint256 index) external view returns (uint256);
}
文件 11 的 19:IERC721Metadata.sol
pragma solidity >=0.6.2 <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);
}
文件 12 的 19:IERC721Receiver.sol
pragma solidity >=0.6.0 <0.8.0;
interface IERC721Receiver {
function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) external returns (bytes4);
}
文件 13 的 19:IPacks.sol
pragma solidity >=0.6.0 <0.8.0;
pragma experimental ABIEncoderV2;
import './LibPackStorage.sol';
import "@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol";
interface IPacks is IERC721Enumerable {
function transferDAOownership(address payable _daoAddress) external;
function createNewCollection(string memory _baseURI, bool _editioned, uint256[] memory _initParams, string[] memory _metadataKeys, string memory _licenseURI, address _mintPass, uint256 _mintPassDuration, bool[] memory _mintPassParams) external;
function bulkAddCollectible(uint256 cID, string[][] memory _coreData, uint16[] memory _editions, string[][] memory _assets, LibPackStorage.MetadataStore[][] memory _metadataValues, LibPackStorage.Fee[][] memory _fees) external;
function mintPack(uint256 cID, uint256 mintPassTokenId) external payable;
function bulkMintPack(uint256 cID, uint256 amount) external payable;
function mintPassClaimed(uint256 cID, uint256 tokenId) external view returns (bool);
function remainingTokens(uint256 cID) external view returns (uint256);
function updateMetadata(uint256 cID, uint256 collectibleId, uint256 propertyIndex, string memory value) external;
function addVersion(uint256 cID, uint256 collectibleId, string memory asset) external;
function addNewLicense(uint256 cID, string memory _license) external;
function getLicense(uint256 cID, uint256 versionNumber) external view returns (string memory);
function getCollectionCount() external view returns (uint256);
function getCollectionInfo(uint256 cID) external view returns (string memory);
function tokenURI(uint256 tokenId) external view returns (string memory);
function getFeeRecipients(uint256 tokenId) external view returns (address payable[] memory);
function getFeeBps(uint256 tokenId) external view returns (uint256[] memory);
function royaltyInfo(uint256 tokenId, uint256 value) external view returns (address recipient, uint256 amount);
}
文件 14 的 19:LibPackStorage.sol
pragma solidity >=0.6.0 <0.8.0;
pragma experimental ABIEncoderV2;
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import 'base64-sol/base64.sol';
import './HelperFunctions.sol';
library LibPackStorage {
using SafeMath for uint256;
bytes32 constant STORAGE_POSITION = keccak256("com.universe.packs.storage");
struct Fee {
address payable recipient;
uint256 value;
}
struct SingleCollectible {
uint16 count;
uint16 totalVersionCount;
uint16 currentVersion;
string title;
string description;
string[] assets;
}
struct Metadata {
uint8[] name;
string[] value;
bool[] modifiable;
uint16 propertyCount;
}
struct MetadataStore {
uint8 propertyKey;
string value;
bool modifiable;
}
struct Collection {
uint16 collectibleCount;
uint16 bulkBuyLimit;
uint16 licenseVersion;
uint256 totalTokenCount;
uint256 tokenPrice;
uint256 saleStartTime;
string baseURI;
bool initialized;
bool editioned;
bool mintPass;
bool mintPassOnly;
bool mintPassFree;
bool mintPassBurn;
uint256 mintPassDuration;
address mintPassAddress;
ERC721 mintPassContract;
uint32[] shuffleIDs;
uint16 metadataKeysLength;
mapping (uint256 => SingleCollectible) collectibles;
mapping (uint256 => string) metadataKeys;
mapping (uint256 => Metadata) metadata;
mapping (uint256 => Fee[]) secondaryFees;
mapping (uint256 => string) licenseURI;
mapping (uint256 => bool) mintPassClaims;
}
struct Storage {
address relicsAddress;
address payable daoAddress;
bool daoInitialized;
uint256 collectionCount;
mapping (uint256 => Collection) collection;
}
function packStorage() internal pure returns (Storage storage ds) {
bytes32 position = STORAGE_POSITION;
assembly {
ds.slot := position
}
}
event LogMintPack(
address minter,
uint256 tokenID
);
event LogCreateNewCollection(
uint256 index
);
event LogAddCollectible(
uint256 cID,
string title
);
event LogUpdateMetadata(
uint256 cID,
uint256 collectibleId,
uint256 propertyIndex,
string value
);
event LogAddVersion(
uint256 cID,
uint256 collectibleId,
string asset
);
event LogUpdateVersion(
uint256 cID,
uint256 collectibleId,
uint256 versionNumber
);
event LogAddNewLicense(
uint256 cID,
string license
);
function random(uint256 cID) internal view returns (uint) {
return uint(keccak256(abi.encodePacked(block.difficulty, block.timestamp, packStorage().collection[cID].totalTokenCount)));
}
function randomTokenID(address relics, uint256 cID) external relicSafety(relics) returns (uint256, uint256) {
Storage storage ds = packStorage();
uint256 randomID = random(cID) % ds.collection[cID].shuffleIDs.length;
uint256 tokenID = ds.collection[cID].shuffleIDs[randomID];
emit LogMintPack(msg.sender, tokenID);
return (randomID, tokenID);
}
modifier onlyDAO() {
require(msg.sender == packStorage().daoAddress, "Wrong address");
_;
}
modifier relicSafety(address relics) {
Storage storage ds = packStorage();
require(relics == ds.relicsAddress);
_;
}
function createTokenIDs(uint256 cID, uint256 collectibleCount, uint16 editions) private {
Storage storage ds = packStorage();
for (uint16 i = 0; i < editions; i++) {
uint32 tokenID = uint32((cID + 1) * 100000000) + uint32((collectibleCount + 1) * 100000) + uint32(i + 1);
ds.collection[cID].shuffleIDs.push(tokenID);
}
}
function createNewCollection(
string memory _baseURI,
bool _editioned,
uint256[] memory _initParams,
string[] memory _metadataKeys,
string memory _licenseURI,
address _mintPass,
uint256 _mintPassDuration,
bool[] memory _mintPassParams
) external onlyDAO {
require(_initParams[1] <= 50, "Limit of 50");
Storage storage ds = packStorage();
ds.collection[ds.collectionCount].baseURI = _baseURI;
ds.collection[ds.collectionCount].editioned = _editioned;
ds.collection[ds.collectionCount].tokenPrice = _initParams[0];
ds.collection[ds.collectionCount].bulkBuyLimit = uint16(_initParams[1]);
ds.collection[ds.collectionCount].saleStartTime = _initParams[2];
ds.collection[ds.collectionCount].licenseURI[0] = _licenseURI;
ds.collection[ds.collectionCount].licenseVersion = 1;
if (_mintPass != address(0)) {
ds.collection[ds.collectionCount].mintPass = true;
ds.collection[ds.collectionCount].mintPassAddress = _mintPass;
ds.collection[ds.collectionCount].mintPassContract = ERC721(_mintPass);
ds.collection[ds.collectionCount].mintPassDuration = _mintPassDuration;
ds.collection[ds.collectionCount].mintPassOnly = _mintPassParams[0];
ds.collection[ds.collectionCount].mintPassFree = _mintPassParams[1];
ds.collection[ds.collectionCount].mintPassBurn = _mintPassParams[2];
} else {
ds.collection[ds.collectionCount].mintPass = false;
ds.collection[ds.collectionCount].mintPassDuration = 0;
ds.collection[ds.collectionCount].mintPassOnly = false;
ds.collection[ds.collectionCount].mintPassFree = false;
ds.collection[ds.collectionCount].mintPassBurn = false;
}
for (uint8 i; i < _metadataKeys.length; i++) {
ds.collection[ds.collectionCount].metadataKeys[i] = _metadataKeys[i];
}
ds.collection[ds.collectionCount].metadataKeysLength = uint16(_metadataKeys.length);
ds.collectionCount++;
emit LogCreateNewCollection(ds.collectionCount);
}
function addCollectible(uint256 cID, string[] memory _coreData, uint16 _editions, string[] memory _assets, MetadataStore[] memory _metadataValues, Fee[] memory _fees) external onlyDAO {
Storage storage ds = packStorage();
Collection storage collection = ds.collection[cID];
uint256 collectibleCount = collection.collectibleCount;
uint256 sum = 0;
for (uint256 i = 0; i < _fees.length; i++) {
require(_fees[i].recipient != address(0x0), "No recipient");
require(_fees[i].value != 0, "Fee negative");
collection.secondaryFees[collectibleCount].push(Fee({
recipient: _fees[i].recipient,
value: _fees[i].value
}));
sum = sum.add(_fees[i].value);
}
require(sum < 10000, "Fee GT 100%");
require(_editions > 0, "GT 0");
collection.collectibles[collectibleCount] = SingleCollectible({
title: _coreData[0],
description: _coreData[1],
count: _editions,
currentVersion: uint16(_assets.length),
assets: _assets,
totalVersionCount: uint16(_assets.length)
});
uint8[] memory propertyNames = new uint8[](_metadataValues.length);
string[] memory propertyValues = new string[](_metadataValues.length);
bool[] memory modifiables = new bool[](_metadataValues.length);
for (uint256 i = 0; i < _metadataValues.length; i++) {
propertyNames[i] = _metadataValues[i].propertyKey;
propertyValues[i] = _metadataValues[i].value;
modifiables[i] = _metadataValues[i].modifiable;
}
collection.metadata[collectibleCount] = Metadata({
name: propertyNames,
value: propertyValues,
modifiable: modifiables,
propertyCount: uint16(_metadataValues.length)
});
uint16 editions = _editions;
createTokenIDs(cID, collectibleCount, editions);
collection.collectibleCount++;
collection.totalTokenCount = collection.totalTokenCount.add(editions);
emit LogAddCollectible(cID, _coreData[0]);
}
function checkTokensForMintPass(uint256 cID, uint256 mintPassTokenId, address minter) private returns (bool) {
Storage storage ds = packStorage();
if (ds.collection[cID].mintPassContract.ownerOf(mintPassTokenId) == minter &&
ds.collection[cID].mintPassClaims[mintPassTokenId] != true) {
ds.collection[cID].mintPassClaims[mintPassTokenId] = true;
if (ds.collection[cID].mintPassBurn) ds.collection[cID].mintPassContract.safeTransferFrom(msg.sender, address(0xdEaD), mintPassTokenId);
return true;
} else return false;
}
function checkMintPass(address relics, uint256 cID, uint256 mintPassTokenId, address users) external relicSafety(relics) returns (bool) {
Storage storage ds = packStorage();
bool canMintPass = false;
if (ds.collection[cID].mintPass && checkTokensForMintPass(cID, mintPassTokenId, users)) canMintPass = true;
if (ds.collection[cID].mintPassOnly) {
require(canMintPass, "Mint pass only");
require(block.timestamp > ds.collection[cID].saleStartTime - ds.collection[cID].mintPassDuration, "ERR: Sale start");
} else {
if (canMintPass) require (block.timestamp > (ds.collection[cID].saleStartTime - ds.collection[cID].mintPassDuration), "ERR: Sale start");
else require(block.timestamp > ds.collection[cID].saleStartTime, "ERR: Sale start");
}
return canMintPass;
}
function bulkMintChecks(uint256 cID, uint256 amount) external {
Storage storage ds = packStorage();
require(amount > 0, 'Missing amount');
require(!ds.collection[cID].mintPassOnly, 'Mint pass only');
require(amount <= ds.collection[cID].bulkBuyLimit, "Over limit");
require(amount <= ds.collection[cID].shuffleIDs.length, "Total supply reached");
require((block.timestamp > ds.collection[cID].saleStartTime), "ERR: Sale start");
}
function mintPassClaimed(uint256 cID, uint256 tokenId) public view returns (bool) {
Storage storage ds = packStorage();
return (ds.collection[cID].mintPassClaims[tokenId] == true);
}
function remainingTokens(uint256 cID) public view returns (uint256) {
Storage storage ds = packStorage();
return ds.collection[cID].shuffleIDs.length;
}
function updateMetadata(uint256 cID, uint256 collectibleId, uint256 propertyIndex, string memory value) external onlyDAO {
Storage storage ds = packStorage();
require(ds.collection[cID].metadata[collectibleId - 1].modifiable[propertyIndex], 'Uneditable');
ds.collection[cID].metadata[collectibleId - 1].value[propertyIndex] = value;
emit LogUpdateMetadata(cID, collectibleId, propertyIndex, value);
}
function addVersion(uint256 cID, uint256 collectibleId, string memory asset) public onlyDAO {
Storage storage ds = packStorage();
ds.collection[cID].collectibles[collectibleId - 1].assets[ds.collection[cID].collectibles[collectibleId - 1].totalVersionCount - 1] = asset;
ds.collection[cID].collectibles[collectibleId - 1].totalVersionCount++;
emit LogAddVersion(cID, collectibleId, asset);
}
function addNewLicense(uint256 cID, string memory _license) public onlyDAO {
Storage storage ds = packStorage();
require(cID < ds.collectionCount, 'ID DNE');
ds.collection[cID].licenseURI[ds.collection[cID].licenseVersion] = _license;
ds.collection[cID].licenseVersion++;
emit LogAddNewLicense(cID, _license);
}
function getLicense(uint256 cID, uint256 versionNumber) public view returns (string memory) {
Storage storage ds = packStorage();
return ds.collection[cID].licenseURI[versionNumber - 1];
}
function getCurrentLicense(uint256 cID) public view returns (string memory) {
Storage storage ds = packStorage();
return ds.collection[cID].licenseURI[ds.collection[cID].licenseVersion - 1];
}
function getCollectionInfo(uint256 cID) public view returns (string memory) {
Storage storage ds = packStorage();
string memory encodedMetadata = '';
for (uint i = 0; i < ds.collection[cID].metadataKeysLength; i++) {
encodedMetadata = string(abi.encodePacked(
encodedMetadata,
'{"index":"',
HelperFunctions.toString(i),
'", "name":"',
ds.collection[cID].metadataKeys[i],
'"}',
i == ds.collection[cID].metadataKeysLength - 1 ? '' : ',')
);
}
return string(
abi.encodePacked(
'{"weiPrice": "',
HelperFunctions.toString(ds.collection[cID].tokenPrice),
'", "saleStart": "',
HelperFunctions.toString(ds.collection[cID].saleStartTime),
'", "mintPass": "',
ds.collection[cID].mintPass ? 'true' : 'false',
'", "passAddress": "',
HelperFunctions.addressToString(ds.collection[cID].mintPassAddress),
'", "passDuration": "',
HelperFunctions.toString(ds.collection[cID].mintPassDuration),
'", "passOnly": "',
ds.collection[cID].mintPassOnly ? 'true' : 'false',
'", "passBurn": "',
ds.collection[cID].mintPassBurn ? 'true' : 'false',
'", "metadata": [',
encodedMetadata,
'] }'
)
);
}
function tokenURI(uint256 tokenId) public view returns (string memory) {
Storage storage ds = packStorage();
uint256 edition = HelperFunctions.safeParseInt(HelperFunctions.substring(HelperFunctions.toString(tokenId), bytes(HelperFunctions.toString(tokenId)).length - 5, bytes(HelperFunctions.toString(tokenId)).length)) - 1;
uint256 collectibleId = HelperFunctions.safeParseInt(HelperFunctions.substring(HelperFunctions.toString(tokenId), bytes(HelperFunctions.toString(tokenId)).length - 8, bytes(HelperFunctions.toString(tokenId)).length - 5)) - 1;
uint256 cID = ((tokenId - ((collectibleId + 1) * 100000)) - (edition + 1)) / 100000000 - 1;
string memory encodedMetadata = '';
Collection storage collection = ds.collection[cID];
for (uint i = 0; i < collection.metadata[collectibleId].propertyCount; i++) {
encodedMetadata = string(abi.encodePacked(
encodedMetadata,
'{"trait_type":"',
collection.metadataKeys[collection.metadata[collectibleId].name[i]],
'", "value":"',
collection.metadata[collectibleId].value[i],
'", "permanent":"',
collection.metadata[collectibleId].modifiable[i] ? 'false' : 'true',
'"}',
i == collection.metadata[collectibleId].propertyCount - 1 ? '' : ',')
);
}
SingleCollectible storage collectible = collection.collectibles[collectibleId];
uint256 asset = collectible.currentVersion - 1;
string memory encoded = string(
abi.encodePacked(
'data:application/json;base64,',
Base64.encode(
bytes(
abi.encodePacked(
'{"name":"',
collectible.title,
collection.editioned ? ' #' : '',
collection.editioned ? HelperFunctions.toString(edition + 1) : '',
'", "description":"',
collectible.description,
'", "image": "',
collection.baseURI,
collectible.assets[asset],
'", "license": "',
getCurrentLicense(cID),
'", "attributes": [',
encodedMetadata,
'] }'
)
)
)
)
);
return encoded;
}
function getFeeRecipients(uint256 tokenId) public view returns (address payable[] memory) {
Storage storage ds = packStorage();
uint256 edition = HelperFunctions.safeParseInt(HelperFunctions.substring(HelperFunctions.toString(tokenId), bytes(HelperFunctions.toString(tokenId)).length - 5, bytes(HelperFunctions.toString(tokenId)).length)) - 1;
uint256 collectibleId = HelperFunctions.safeParseInt(HelperFunctions.substring(HelperFunctions.toString(tokenId), bytes(HelperFunctions.toString(tokenId)).length - 8, bytes(HelperFunctions.toString(tokenId)).length - 5)) - 1;
uint256 cID = ((tokenId - ((collectibleId + 1) * 100000)) - (edition + 1)) / 100000000 - 1;
Fee[] memory _fees = ds.collection[cID].secondaryFees[collectibleId];
address payable[] memory result = new address payable[](_fees.length);
for (uint i = 0; i < _fees.length; i++) {
result[i] = _fees[i].recipient;
}
return result;
}
function getFeeBps(uint256 tokenId) public view returns (uint[] memory) {
Storage storage ds = packStorage();
uint256 edition = HelperFunctions.safeParseInt(HelperFunctions.substring(HelperFunctions.toString(tokenId), bytes(HelperFunctions.toString(tokenId)).length - 5, bytes(HelperFunctions.toString(tokenId)).length)) - 1;
uint256 collectibleId = HelperFunctions.safeParseInt(HelperFunctions.substring(HelperFunctions.toString(tokenId), bytes(HelperFunctions.toString(tokenId)).length - 8, bytes(HelperFunctions.toString(tokenId)).length - 5)) - 1;
uint256 cID = ((tokenId - ((collectibleId + 1) * 100000)) - (edition + 1)) / 100000000 - 1;
Fee[] memory _fees = ds.collection[cID].secondaryFees[collectibleId];
uint[] memory result = new uint[](_fees.length);
for (uint i = 0; i < _fees.length; i++) {
result[i] = _fees[i].value;
}
return result;
}
function royaltyInfo(uint256 tokenId, uint256 value) public view returns (address recipient, uint256 amount){
address payable[] memory rec = getFeeRecipients(tokenId);
require(rec.length <= 1, "More than 1 royalty recipient");
if (rec.length == 0) return (address(this), 0);
return (rec[0], getFeeBps(tokenId)[0] * value / 10000);
}
}
文件 15 的 19:Packs.sol
pragma solidity >=0.6.0 <0.8.0;
pragma experimental ABIEncoderV2;
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "./IPacks.sol";
import "./LibPackStorage.sol";
contract Packs is IPacks, ERC721, ReentrancyGuard {
using SafeMath for uint256;
constructor(
string memory name,
string memory symbol,
string memory _baseURI,
bool _editioned,
uint256[] memory _initParams,
string[] memory _metadataKeys,
string memory _licenseURI,
address _mintPass,
uint256 _mintPassDuration,
bool[] memory _mintPassParams
) ERC721(name, symbol) {
LibPackStorage.Storage storage ds = LibPackStorage.packStorage();
ds.relicsAddress = address(this);
ds.daoAddress = msg.sender;
ds.daoInitialized = true;
ds.collectionCount = 0;
createNewCollection(_baseURI, _editioned, _initParams, _metadataKeys, _licenseURI, _mintPass, _mintPassDuration, _mintPassParams);
_setBaseURI(_baseURI);
}
bytes4 private constant _INTERFACE_ID_ROYALTIES_RARIBLE = 0xb7799584;
bytes4 private constant _INTERFACE_ID_ROYALTIES_EIP2981 = 0x2a55205a;
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return interfaceId == _INTERFACE_ID_ROYALTIES_RARIBLE || interfaceId == _INTERFACE_ID_ROYALTIES_EIP2981 || super.supportsInterface(interfaceId);
}
modifier onlyDAO() {
LibPackStorage.Storage storage ds = LibPackStorage.packStorage();
require(msg.sender == ds.daoAddress, "Wrong address");
_;
}
function transferDAOownership(address payable _daoAddress) public override onlyDAO {
LibPackStorage.Storage storage ds = LibPackStorage.packStorage();
ds.daoAddress = _daoAddress;
ds.daoInitialized = true;
}
function createNewCollection(string memory _baseURI, bool _editioned, uint256[] memory _initParams, string[] memory _metadataKeys, string memory _licenseURI, address _mintPass, uint256 _mintPassDuration, bool[] memory _mintPassParams) public override onlyDAO {
LibPackStorage.createNewCollection(_baseURI, _editioned, _initParams, _metadataKeys, _licenseURI, _mintPass, _mintPassDuration, _mintPassParams);
}
function bulkAddCollectible(uint256 cID, string[][] memory _coreData, uint16[] memory _editions, string[][] memory _assets, LibPackStorage.MetadataStore[][] memory _metadataValues, LibPackStorage.Fee[][] memory _fees) public override onlyDAO {
for (uint256 i = 0; i < _coreData.length; i++) {
LibPackStorage.addCollectible(cID, _coreData[i], _editions[i], _assets[i], _metadataValues[i], _fees[i]);
}
}
function randomTokenID(uint256 cID) private returns (uint256) {
LibPackStorage.Storage storage ds = LibPackStorage.packStorage();
(uint256 randomID, uint256 tokenID) = LibPackStorage.randomTokenID(address(this), cID);
ds.collection[cID].shuffleIDs[randomID] = ds.collection[cID].shuffleIDs[ds.collection[cID].shuffleIDs.length - 1];
ds.collection[cID].shuffleIDs.pop();
return tokenID;
}
function mintPack(uint256 cID, uint256 mintPassTokenId) public override payable nonReentrant {
LibPackStorage.Storage storage ds = LibPackStorage.packStorage();
bool canMintPass = LibPackStorage.checkMintPass(address(this), cID, mintPassTokenId, msg.sender);
uint256 excessAmount;
if (canMintPass && ds.collection[cID].mintPassFree) excessAmount = msg.value.sub(0);
else excessAmount = msg.value.sub(ds.collection[cID].tokenPrice);
if (excessAmount > 0) {
(bool returnExcessStatus, ) = _msgSender().call{value: excessAmount}("");
require(returnExcessStatus, "Failed to return excess.");
}
uint256 tokenID = randomTokenID(cID);
_mint(_msgSender(), tokenID);
}
function bulkMintPack(uint256 cID, uint256 amount) public override payable nonReentrant {
LibPackStorage.Storage storage ds = LibPackStorage.packStorage();
LibPackStorage.bulkMintChecks(cID, amount);
uint256 excessAmount = msg.value.sub(ds.collection[cID].tokenPrice.mul(amount));
if (excessAmount > 0) {
(bool returnExcessStatus, ) = _msgSender().call{value: excessAmount}("");
require(returnExcessStatus, "Failed to return excess.");
}
for (uint256 i = 0; i < amount; i++) {
uint256 tokenID = randomTokenID(cID);
_mint(_msgSender(), tokenID);
}
}
function mintPassClaimed(uint256 cID, uint256 tokenId) public override view returns (bool) {
return LibPackStorage.mintPassClaimed(cID, tokenId);
}
function remainingTokens(uint256 cID) public override view returns (uint256) {
return LibPackStorage.remainingTokens(cID);
}
function updateMetadata(uint256 cID, uint256 collectibleId, uint256 propertyIndex, string memory value) public override onlyDAO {
LibPackStorage.updateMetadata(cID, collectibleId, propertyIndex, value);
}
function addVersion(uint256 cID, uint256 collectibleId, string memory asset) public override onlyDAO {
LibPackStorage.addVersion(cID, collectibleId, asset);
}
function addNewLicense(uint256 cID, string memory _license) public override onlyDAO {
LibPackStorage.addNewLicense(cID, _license);
}
function getLicense(uint256 cID, uint256 versionNumber) public override view returns (string memory) {
return LibPackStorage.getLicense(cID, versionNumber);
}
function getCollectionCount() public override view returns (uint256) {
return LibPackStorage.packStorage().collectionCount;
}
function getCollectionInfo(uint256 cID) public override view returns (string memory) {
return LibPackStorage.getCollectionInfo(cID);
}
function tokenURI(uint256 tokenId) public view virtual override(ERC721, IPacks) returns (string memory) {
return LibPackStorage.tokenURI(tokenId);
}
function getFeeRecipients(uint256 tokenId) public override view returns (address payable[] memory) {
require(_exists(tokenId), "Nonexistent token");
return LibPackStorage.getFeeRecipients(tokenId);
}
function getFeeBps(uint256 tokenId) public override view returns (uint256[] memory) {
require(_exists(tokenId), "Nonexistent token");
return LibPackStorage.getFeeBps(tokenId);
}
function royaltyInfo(uint256 tokenId, uint256 value) public override view returns (address recipient, uint256 amount){
require(_exists(tokenId), "Nonexistent token");
return LibPackStorage.royaltyInfo(tokenId, value);
}
function withdraw(address _to, uint amount) public onlyDAO {
payable(_to).call{value:amount, gas:200000}("");
}
}
文件 16 的 19:ReentrancyGuard.sol
pragma solidity >=0.6.0 <0.8.0;
abstract contract ReentrancyGuard {
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor () internal {
_status = _NOT_ENTERED;
}
modifier nonReentrant() {
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
_status = _ENTERED;
_;
_status = _NOT_ENTERED;
}
}
文件 17 的 19:SafeMath.sol
pragma solidity >=0.6.0 <0.8.0;
library SafeMath {
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b > a) return (false, 0);
return (true, a - b);
}
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
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) {
if (b == 0) return (false, 0);
return (true, a / b);
}
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a % b);
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
return a - b;
}
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) return 0;
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: division by zero");
return a / b;
}
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: modulo by zero");
return a % b;
}
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
return a - b;
}
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a / b;
}
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a % b;
}
}
文件 18 的 19:Strings.sol
pragma solidity >=0.6.0 <0.8.0;
library Strings {
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);
uint256 index = digits - 1;
temp = value;
while (temp != 0) {
buffer[index--] = bytes1(uint8(48 + temp % 10));
temp /= 10;
}
return string(buffer);
}
}
文件 19 的 19:base64.sol
library Base64 {
string internal constant TABLE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
function encode(bytes memory data) internal pure returns (string memory) {
if (data.length == 0) return '';
string memory table = TABLE;
uint256 encodedLen = 4 * ((data.length + 2) / 3);
string memory result = new string(encodedLen + 32);
assembly {
mstore(result, encodedLen)
let tablePtr := add(table, 1)
let dataPtr := data
let endPtr := add(dataPtr, mload(data))
let resultPtr := add(result, 32)
for {} lt(dataPtr, endPtr) {}
{
dataPtr := add(dataPtr, 3)
let input := mload(dataPtr)
mstore(resultPtr, shl(248, mload(add(tablePtr, and(shr(18, input), 0x3F)))))
resultPtr := add(resultPtr, 1)
mstore(resultPtr, shl(248, mload(add(tablePtr, and(shr(12, input), 0x3F)))))
resultPtr := add(resultPtr, 1)
mstore(resultPtr, shl(248, mload(add(tablePtr, and(shr( 6, input), 0x3F)))))
resultPtr := add(resultPtr, 1)
mstore(resultPtr, shl(248, mload(add(tablePtr, and( input, 0x3F)))))
resultPtr := add(resultPtr, 1)
}
switch mod(mload(data), 3)
case 1 { mstore(sub(resultPtr, 2), shl(240, 0x3d3d)) }
case 2 { mstore(sub(resultPtr, 1), shl(248, 0x3d)) }
}
return result;
}
}
{
"compilationTarget": {
"contracts/Packs.sol": "Packs"
},
"evmVersion": "istanbul",
"libraries": {
"LibPackStorage": "0x3e0a32e80e4dbf13c74feb384cce4fbe01d90784"
},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"symbol","type":"string"},{"internalType":"string","name":"_baseURI","type":"string"},{"internalType":"bool","name":"_editioned","type":"bool"},{"internalType":"uint256[]","name":"_initParams","type":"uint256[]"},{"internalType":"string[]","name":"_metadataKeys","type":"string[]"},{"internalType":"string","name":"_licenseURI","type":"string"},{"internalType":"address","name":"_mintPass","type":"address"},{"internalType":"uint256","name":"_mintPassDuration","type":"uint256"},{"internalType":"bool[]","name":"_mintPassParams","type":"bool[]"}],"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":"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":[{"internalType":"uint256","name":"cID","type":"uint256"},{"internalType":"string","name":"_license","type":"string"}],"name":"addNewLicense","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"cID","type":"uint256"},{"internalType":"uint256","name":"collectibleId","type":"uint256"},{"internalType":"string","name":"asset","type":"string"}],"name":"addVersion","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":[],"name":"baseURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"cID","type":"uint256"},{"internalType":"string[][]","name":"_coreData","type":"string[][]"},{"internalType":"uint16[]","name":"_editions","type":"uint16[]"},{"internalType":"string[][]","name":"_assets","type":"string[][]"},{"components":[{"internalType":"uint8","name":"propertyKey","type":"uint8"},{"internalType":"string","name":"value","type":"string"},{"internalType":"bool","name":"modifiable","type":"bool"}],"internalType":"struct LibPackStorage.MetadataStore[][]","name":"_metadataValues","type":"tuple[][]"},{"components":[{"internalType":"address payable","name":"recipient","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"internalType":"struct LibPackStorage.Fee[][]","name":"_fees","type":"tuple[][]"}],"name":"bulkAddCollectible","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"cID","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"bulkMintPack","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"string","name":"_baseURI","type":"string"},{"internalType":"bool","name":"_editioned","type":"bool"},{"internalType":"uint256[]","name":"_initParams","type":"uint256[]"},{"internalType":"string[]","name":"_metadataKeys","type":"string[]"},{"internalType":"string","name":"_licenseURI","type":"string"},{"internalType":"address","name":"_mintPass","type":"address"},{"internalType":"uint256","name":"_mintPassDuration","type":"uint256"},{"internalType":"bool[]","name":"_mintPassParams","type":"bool[]"}],"name":"createNewCollection","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":"getCollectionCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"cID","type":"uint256"}],"name":"getCollectionInfo","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getFeeBps","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getFeeRecipients","outputs":[{"internalType":"address payable[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"cID","type":"uint256"},{"internalType":"uint256","name":"versionNumber","type":"uint256"}],"name":"getLicense","outputs":[{"internalType":"string","name":"","type":"string"}],"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":"uint256","name":"cID","type":"uint256"},{"internalType":"uint256","name":"mintPassTokenId","type":"uint256"}],"name":"mintPack","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"cID","type":"uint256"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"mintPassClaimed","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"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":"cID","type":"uint256"}],"name":"remainingTokens","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"royaltyInfo","outputs":[{"internalType":"address","name":"recipient","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":"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":[{"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 payable","name":"_daoAddress","type":"address"}],"name":"transferDAOownership","outputs":[],"stateMutability":"nonpayable","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":"uint256","name":"cID","type":"uint256"},{"internalType":"uint256","name":"collectibleId","type":"uint256"},{"internalType":"uint256","name":"propertyIndex","type":"uint256"},{"internalType":"string","name":"value","type":"string"}],"name":"updateMetadata","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"}]