文件 1 的 30: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, _msgSender());
_;
}
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, 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 的 30: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);
}
}
}
}
文件 3 的 30:AdminPermissionable.sol
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
abstract contract AdminPermissionable is AccessControl, Ownable
{
error NotAdminOrOwner();
error NotAdminOrModerator();
error ZeroAdminAddress();
bytes32 public constant MODERATOR_ROLE = keccak256("MODERATOR_ROLE");
modifier onlyAdmin() {
if (!(owner() == _msgSender() || hasRole(DEFAULT_ADMIN_ROLE, _msgSender())))
revert NotAdminOrOwner();
_;
}
modifier onlyAdminOrModerator() {
if (!(owner() == _msgSender() ||
hasRole(DEFAULT_ADMIN_ROLE, _msgSender()) ||
hasRole(MODERATOR_ROLE, _msgSender())))
revert NotAdminOrModerator();
_;
}
modifier checkAdminAddress(address _address) {
if (_address == address(0)){
revert ZeroAdminAddress();
}
_;
}
function setAdminPermission(address _address) external onlyAdmin checkAdminAddress(_address) {
_grantRole(DEFAULT_ADMIN_ROLE, _address);
}
function removeAdminPermission(address _address) external onlyAdmin checkAdminAddress(_address) {
_revokeRole(DEFAULT_ADMIN_ROLE, _address);
}
}
文件 4 的 30: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;
}
}
文件 5 的 30:ECDSA.sol
pragma solidity ^0.8.0;
import "../Strings.sol";
library ECDSA {
enum RecoverError {
NoError,
InvalidSignature,
InvalidSignatureLength,
InvalidSignatureS,
InvalidSignatureV
}
function _throwError(RecoverError error) private pure {
if (error == RecoverError.NoError) {
return;
} else if (error == RecoverError.InvalidSignature) {
revert("ECDSA: invalid signature");
} else if (error == RecoverError.InvalidSignatureLength) {
revert("ECDSA: invalid signature length");
} else if (error == RecoverError.InvalidSignatureS) {
revert("ECDSA: invalid signature 's' value");
} else if (error == RecoverError.InvalidSignatureV) {
revert("ECDSA: invalid signature 'v' value");
}
}
function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return tryRecover(hash, v, r, s);
} else if (signature.length == 64) {
bytes32 r;
bytes32 vs;
assembly {
r := mload(add(signature, 0x20))
vs := mload(add(signature, 0x40))
}
return tryRecover(hash, r, vs);
} else {
return (address(0), RecoverError.InvalidSignatureLength);
}
}
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, signature);
_throwError(error);
return recovered;
}
function tryRecover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address, RecoverError) {
bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
uint8 v = uint8((uint256(vs) >> 255) + 27);
return tryRecover(hash, v, r, s);
}
function recover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, r, vs);
_throwError(error);
return recovered;
}
function tryRecover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address, RecoverError) {
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
return (address(0), RecoverError.InvalidSignatureS);
}
if (v != 27 && v != 28) {
return (address(0), RecoverError.InvalidSignatureV);
}
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) {
return (address(0), RecoverError.InvalidSignature);
}
return (signer, RecoverError.NoError);
}
function recover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, v, r, s);
_throwError(error);
return recovered;
}
function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
}
function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s));
}
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
}
}
文件 6 的 30:ERC1155.sol
pragma solidity ^0.8.0;
import "./IERC1155.sol";
import "./IERC1155Receiver.sol";
import "./extensions/IERC1155MetadataURI.sol";
import "../../utils/Address.sol";
import "../../utils/Context.sol";
import "../../utils/introspection/ERC165.sol";
contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
using Address for address;
mapping(uint256 => mapping(address => uint256)) private _balances;
mapping(address => mapping(address => bool)) private _operatorApprovals;
string private _uri;
constructor(string memory uri_) {
_setURI(uri_);
}
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return
interfaceId == type(IERC1155).interfaceId ||
interfaceId == type(IERC1155MetadataURI).interfaceId ||
super.supportsInterface(interfaceId);
}
function uri(uint256) public view virtual override returns (string memory) {
return _uri;
}
function balanceOf(address account, uint256 id) public view virtual override returns (uint256) {
require(account != address(0), "ERC1155: balance query for the zero address");
return _balances[id][account];
}
function balanceOfBatch(address[] memory accounts, uint256[] memory ids)
public
view
virtual
override
returns (uint256[] memory)
{
require(accounts.length == ids.length, "ERC1155: accounts and ids length mismatch");
uint256[] memory batchBalances = new uint256[](accounts.length);
for (uint256 i = 0; i < accounts.length; ++i) {
batchBalances[i] = balanceOf(accounts[i], ids[i]);
}
return batchBalances;
}
function setApprovalForAll(address operator, bool approved) public virtual override {
_setApprovalForAll(_msgSender(), operator, approved);
}
function isApprovedForAll(address account, address operator) public view virtual override returns (bool) {
return _operatorApprovals[account][operator];
}
function safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
) public virtual override {
require(
from == _msgSender() || isApprovedForAll(from, _msgSender()),
"ERC1155: caller is not owner nor approved"
);
_safeTransferFrom(from, to, id, amount, data);
}
function safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) public virtual override {
require(
from == _msgSender() || isApprovedForAll(from, _msgSender()),
"ERC1155: transfer caller is not owner nor approved"
);
_safeBatchTransferFrom(from, to, ids, amounts, data);
}
function _safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
) internal virtual {
require(to != address(0), "ERC1155: transfer to the zero address");
address operator = _msgSender();
_beforeTokenTransfer(operator, from, to, _asSingletonArray(id), _asSingletonArray(amount), data);
uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: insufficient balance for transfer");
unchecked {
_balances[id][from] = fromBalance - amount;
}
_balances[id][to] += amount;
emit TransferSingle(operator, from, to, id, amount);
_doSafeTransferAcceptanceCheck(operator, from, to, id, amount, data);
}
function _safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual {
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
require(to != address(0), "ERC1155: transfer to the zero address");
address operator = _msgSender();
_beforeTokenTransfer(operator, from, to, ids, amounts, data);
for (uint256 i = 0; i < ids.length; ++i) {
uint256 id = ids[i];
uint256 amount = amounts[i];
uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: insufficient balance for transfer");
unchecked {
_balances[id][from] = fromBalance - amount;
}
_balances[id][to] += amount;
}
emit TransferBatch(operator, from, to, ids, amounts);
_doSafeBatchTransferAcceptanceCheck(operator, from, to, ids, amounts, data);
}
function _setURI(string memory newuri) internal virtual {
_uri = newuri;
}
function _mint(
address to,
uint256 id,
uint256 amount,
bytes memory data
) internal virtual {
require(to != address(0), "ERC1155: mint to the zero address");
address operator = _msgSender();
_beforeTokenTransfer(operator, address(0), to, _asSingletonArray(id), _asSingletonArray(amount), data);
_balances[id][to] += amount;
emit TransferSingle(operator, address(0), to, id, amount);
_doSafeTransferAcceptanceCheck(operator, address(0), to, id, amount, data);
}
function _mintBatch(
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual {
require(to != address(0), "ERC1155: mint to the zero address");
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
address operator = _msgSender();
_beforeTokenTransfer(operator, address(0), to, ids, amounts, data);
for (uint256 i = 0; i < ids.length; i++) {
_balances[ids[i]][to] += amounts[i];
}
emit TransferBatch(operator, address(0), to, ids, amounts);
_doSafeBatchTransferAcceptanceCheck(operator, address(0), to, ids, amounts, data);
}
function _burn(
address from,
uint256 id,
uint256 amount
) internal virtual {
require(from != address(0), "ERC1155: burn from the zero address");
address operator = _msgSender();
_beforeTokenTransfer(operator, from, address(0), _asSingletonArray(id), _asSingletonArray(amount), "");
uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: burn amount exceeds balance");
unchecked {
_balances[id][from] = fromBalance - amount;
}
emit TransferSingle(operator, from, address(0), id, amount);
}
function _burnBatch(
address from,
uint256[] memory ids,
uint256[] memory amounts
) internal virtual {
require(from != address(0), "ERC1155: burn from the zero address");
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
address operator = _msgSender();
_beforeTokenTransfer(operator, from, address(0), ids, amounts, "");
for (uint256 i = 0; i < ids.length; i++) {
uint256 id = ids[i];
uint256 amount = amounts[i];
uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: burn amount exceeds balance");
unchecked {
_balances[id][from] = fromBalance - amount;
}
}
emit TransferBatch(operator, from, address(0), ids, amounts);
}
function _setApprovalForAll(
address owner,
address operator,
bool approved
) internal virtual {
require(owner != operator, "ERC1155: setting approval status for self");
_operatorApprovals[owner][operator] = approved;
emit ApprovalForAll(owner, operator, approved);
}
function _beforeTokenTransfer(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual {}
function _doSafeTransferAcceptanceCheck(
address operator,
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
) private {
if (to.isContract()) {
try IERC1155Receiver(to).onERC1155Received(operator, from, id, amount, data) returns (bytes4 response) {
if (response != IERC1155Receiver.onERC1155Received.selector) {
revert("ERC1155: ERC1155Receiver rejected tokens");
}
} catch Error(string memory reason) {
revert(reason);
} catch {
revert("ERC1155: transfer to non ERC1155Receiver implementer");
}
}
}
function _doSafeBatchTransferAcceptanceCheck(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) private {
if (to.isContract()) {
try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, amounts, data) returns (
bytes4 response
) {
if (response != IERC1155Receiver.onERC1155BatchReceived.selector) {
revert("ERC1155: ERC1155Receiver rejected tokens");
}
} catch Error(string memory reason) {
revert(reason);
} catch {
revert("ERC1155: transfer to non ERC1155Receiver implementer");
}
}
}
function _asSingletonArray(uint256 element) private pure returns (uint256[] memory) {
uint256[] memory array = new uint256[](1);
array[0] = element;
return array;
}
}
文件 7 的 30:ERC1155Burnable.sol
pragma solidity ^0.8.0;
import "../ERC1155.sol";
abstract contract ERC1155Burnable is ERC1155 {
function burn(
address account,
uint256 id,
uint256 value
) public virtual {
require(
account == _msgSender() || isApprovedForAll(account, _msgSender()),
"ERC1155: caller is not owner nor approved"
);
_burn(account, id, value);
}
function burnBatch(
address account,
uint256[] memory ids,
uint256[] memory values
) public virtual {
require(
account == _msgSender() || isApprovedForAll(account, _msgSender()),
"ERC1155: caller is not owner nor approved"
);
_burnBatch(account, ids, values);
}
}
文件 8 的 30:ERC1155Supply.sol
pragma solidity ^0.8.0;
import "../ERC1155.sol";
abstract contract ERC1155Supply is ERC1155 {
mapping(uint256 => uint256) private _totalSupply;
function totalSupply(uint256 id) public view virtual returns (uint256) {
return _totalSupply[id];
}
function exists(uint256 id) public view virtual returns (bool) {
return ERC1155Supply.totalSupply(id) > 0;
}
function _beforeTokenTransfer(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual override {
super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
if (from == address(0)) {
for (uint256 i = 0; i < ids.length; ++i) {
_totalSupply[ids[i]] += amounts[i];
}
}
if (to == address(0)) {
for (uint256 i = 0; i < ids.length; ++i) {
_totalSupply[ids[i]] -= amounts[i];
}
}
}
}
文件 9 的 30: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;
}
}
文件 10 的 30:FalloutCrystal.sol
pragma solidity 0.8.4;
import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Supply.sol";
import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Burnable.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@massless.io/smart-contract-library/contracts/royalty/Royalty.sol";
import "@massless.io/smart-contract-library/contracts/interfaces/IContractURI.sol";
import "@massless.io/smart-contract-library/contracts/sale/SaleState.sol";
import "@massless.io/smart-contract-library/contracts/signature/Signature.sol";
import "@massless.io/smart-contract-library/contracts/utils/PreAuthorisable.sol";
import "@massless.io/smart-contract-library/contracts/utils/AdminPermissionable.sol";
import "@massless.io/smart-contract-library/contracts/utils/WithdrawalSplittable.sol";
import "./interfaces/IJungle.sol";
import "./PackTokenIds.sol";
error NotModeratorOrOwner();
error MustMintMinimumOne();
error SoldOut();
error TransactionMintLimit(uint256 limit);
error IncorrectValueJungle();
error IncorrectEthValue();
error NotYourToken();
error NotHoldingAnyTokens();
error UsedToken(uint256 jfgId);
error DeployerIsAdmin();
error NoTrailingSlash();
contract FalloutCrystal is
AdminPermissionable,
WithdrawalSplittable,
PreAuthorisable,
PackTokenIds,
ERC1155Supply,
ERC1155Burnable,
Royalty,
Signature,
SaleState
{
string private _name;
string private _symbol;
mapping(uint256 => uint256) public MAX_SUPPLY;
uint256 public constant MAX_BATCH_MINT = 5;
address[] private BENEFICIARY_WALLETS = [
address(0x8e5F332a0662C8c06BDD1Eed105Ba1C4800d4c2f),
address(0x954BfE5137c8D2816cE018EFd406757f9a060e5f),
address(0x2E7D93e2AdFC4a36E2B3a3e23dE7c35212471CfB),
address(0xd196e0aFacA3679C27FC05ba8C9D3ABBCD353b5D)
];
uint256[] private BENEFICIARIES_PRIMARY = [5500, 2000, 500, 2000];
IJungle private _jungleContract;
IERC721 private _jfgContract;
address public constant JUNGLE_BANK =
0x8e5F332a0662C8c06BDD1Eed105Ba1C4800d4c2f;
event Phase1MintBegins();
event Phase2MintBegins();
event MintEnds();
event URIUpdated(string uri_);
constructor(
address signer_,
address admin_,
address royaltyReceiver_,
IJungle jungleContract_,
IERC721 jfgContract_,
address[] memory _preAuthorized
)
ERC1155(
"https://massless-ipfs-public-gateway.mypinata.cloud/ipfs/QmZiZUjvFBKXU3hJ1iJ9bwPQcNNMBBrFQUv7FZybYgqLcD/"
)
Signature(signer_)
PreAuthorisable(_preAuthorized)
{
if (_msgSender() == admin_) revert DeployerIsAdmin();
_name = "Fallout Crystal";
_symbol = "FCR";
MAX_SUPPLY[1] = 7000;
MAX_SUPPLY[2] = 2992;
MAX_SUPPLY[3] = 8;
_jungleContract = jungleContract_;
_jfgContract = jfgContract_;
setRoyaltyReceiver(royaltyReceiver_);
setRoyaltyBasisPoints(500);
setBeneficiaries(BENEFICIARY_WALLETS, BENEFICIARIES_PRIMARY);
_grantRole(DEFAULT_ADMIN_ROLE, _msgSender());
_grantRole(DEFAULT_ADMIN_ROLE, admin_);
}
modifier maxSupplyLimit(uint256 quantity_) {
(, , uint256 supplyLimit) = _sumMintablesUntilLevels();
if (quantity_ == 0) revert MustMintMinimumOne();
if (quantity_ > supplyLimit) revert SoldOut();
_;
}
function phase1Mint(
bytes calldata signature_,
bytes32 salt_,
uint256 jungle_,
uint256[] calldata jfgIds_
)
external
payable
whenSaleIsActive("Phase1Mint")
maxSupplyLimit(jfgIds_.length)
onlySignedTx(
keccak256(abi.encodePacked(_msgSender(), salt_, jungle_, jfgIds_)),
signature_
)
{
for (uint256 i = 0; i < jfgIds_.length; i++) {
address staker = _jungleContract.getStaker(jfgIds_[i]);
address owner = _jfgContract.ownerOf(jfgIds_[i]);
if (staker != _msgSender() && owner != _msgSender())
revert NotYourToken();
bool isUsedToken = usedTokenId(jfgIds_[i]);
if (isUsedToken) revert UsedToken(jfgIds_[i]);
}
_setUsedTokenIds(jfgIds_);
_processMint(salt_, jungle_, jfgIds_.length);
}
function phase2Mint(
bytes calldata signature_,
bytes32 salt_,
uint256 jungle_,
uint256 quantity_
)
external
payable
whenSaleIsActive("Phase2Mint")
maxSupplyLimit(quantity_)
onlySignedTx(
keccak256(
abi.encodePacked(_msgSender(), salt_, jungle_, quantity_)
),
signature_
)
{
if (quantity_ > MAX_BATCH_MINT)
revert TransactionMintLimit(MAX_BATCH_MINT);
if (
_jfgContract.balanceOf(_msgSender()) == 0 &&
_jungleContract.getStakedAmount(_msgSender()) == 0
) revert NotHoldingAnyTokens();
_processMint(salt_, jungle_, quantity_);
}
function startPhase1Mint() external onlyAdminOrModerator {
_setSaleType("Phase1Mint");
_setSaleState(State.ACTIVE);
emit Phase1MintBegins();
}
function startPhase2Mint() external onlyAdminOrModerator {
_setSaleType("Phase2Mint");
_setSaleState(State.ACTIVE);
emit Phase2MintBegins();
}
function unpauseMint() external onlyAdminOrModerator {
_unpause();
}
function pauseMint() external onlyAdminOrModerator {
_pause();
}
function endMint() external onlyAdmin {
if (getSaleState() != State.ACTIVE) revert NoActiveSale();
_setSaleState(State.FINISHED);
_retainSpecialTokens();
emit MintEnds();
}
function _retainSpecialTokens() private {
uint256 mintsLevel2 = MAX_SUPPLY[2] > totalSupply(2)
? MAX_SUPPLY[2] - totalSupply(2)
: 0;
uint256 mintsLevel3 = MAX_SUPPLY[3] > totalSupply(3)
? MAX_SUPPLY[3] - totalSupply(3)
: 0;
if (mintsLevel2 > 0) _mint(JUNGLE_BANK, 2, mintsLevel2, "");
if (mintsLevel3 > 0) _mint(JUNGLE_BANK, 3, mintsLevel3, "");
}
function _processMint(
bytes32 randomness_,
uint256 jungle_,
uint256 quantity_
) internal {
uint256 ethPrice = holdersEthPrice(jungle_, quantity_);
if (msg.value != ethPrice) revert IncorrectEthValue();
if (jungle_ > 0) {
_jungleContract.transferFrom(_msgSender(), JUNGLE_BANK, jungle_);
}
(
uint256 mintsLevel1,
uint256 mintsLevel2,
uint256 mintsLevel3
) = _decideMintsPerLevel(randomness_, quantity_);
if (mintsLevel1 > 0) _mint(_msgSender(), 1, mintsLevel1, "");
if (mintsLevel2 > 0) _mint(_msgSender(), 2, mintsLevel2, "");
if (mintsLevel3 > 0) _mint(_msgSender(), 3, mintsLevel3, "");
}
function _beforeTokenTransfer(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual override(ERC1155Supply, ERC1155) {
ERC1155Supply._beforeTokenTransfer(
operator,
from,
to,
ids,
amounts,
data
);
}
function _sumMintablesUntilLevels()
private
view
returns (
uint256,
uint256,
uint256
)
{
uint256 totalMintablesBy1 = MAX_SUPPLY[1] > totalSupply(1)
? MAX_SUPPLY[1] - totalSupply(1)
: 0;
uint256 totalMintablesBy2 = MAX_SUPPLY[2] > totalSupply(2)
? MAX_SUPPLY[2] - totalSupply(2) + totalMintablesBy1
: totalMintablesBy1;
uint256 totalMintablesBy3 = MAX_SUPPLY[3] > totalSupply(3)
? MAX_SUPPLY[3] - totalSupply(3) + totalMintablesBy2
: totalMintablesBy2;
return (totalMintablesBy1, totalMintablesBy2, totalMintablesBy3);
}
function _decideMintsPerLevel(bytes32 randomness_, uint256 quantity_)
private
view
returns (
uint256,
uint256,
uint256
)
{
uint32[] memory randomNumbers = new uint32[](quantity_);
for (uint8 i; i < quantity_; i++) {
randomNumbers[i] = uint32(
uint256(
keccak256(
abi.encodePacked(
quantity_ + i,
randomness_,
block.difficulty
)
)
)
);
}
uint256 mintsLevel1 = 0;
uint256 mintsLevel2 = 0;
uint256 mintsLevel3 = 0;
(
uint256 totalMintablesBy1,
uint256 totalMintablesBy2,
uint256 totalMintablesBy3
) = _sumMintablesUntilLevels();
for (uint256 i = 0; i < quantity_; i++) {
uint256 totalMintables = totalMintablesBy3 -
(mintsLevel1 + mintsLevel2 + mintsLevel3);
uint256 selectedNum = (randomNumbers[i] * totalMintables) /
type(uint32).max;
if (selectedNum < totalMintablesBy1 - mintsLevel1) {
mintsLevel1++;
} else if (
selectedNum < totalMintablesBy2 - (mintsLevel1 + mintsLevel2)
) {
mintsLevel2++;
} else if (
selectedNum <
totalMintablesBy3 - (mintsLevel1 + mintsLevel2 + mintsLevel3)
) {
mintsLevel3++;
}
}
return (mintsLevel1, mintsLevel2, mintsLevel3);
}
function holdersEthPrice(uint256 j_, uint256 q_)
public
pure
returns (uint256)
{
if (j_ == 0 ether) return 0.13 ether * q_;
if (j_ == 150 ether * q_) return 0.065 ether * q_;
if (j_ == 300 ether * q_) return 0 ether;
revert IncorrectValueJungle();
}
function setURI(string memory uri_) public onlyAdminOrModerator {
if (bytes(uri_)[bytes(uri_).length - 1] != bytes1("/"))
revert NoTrailingSlash();
_setURI(uri_);
emit URIUpdated(uri_);
}
function uri(uint256 tokenId_)
public
view
override
returns (string memory)
{
return
string(abi.encodePacked(ERC1155.uri(tokenId_), "token/{id}.json"));
}
function contractURI() public view returns (string memory) {
return string(abi.encodePacked(ERC1155.uri(0), "contract.json"));
}
function setSignerAddress(address signerAddress_)
public
onlyAdminOrModerator
{
_setSignerAddress(signerAddress_);
}
function setRoyaltyReceiver(address royaltyReceiver_) public onlyAdmin {
_setRoyaltyReceiver(royaltyReceiver_);
}
function setRoyaltyBasisPoints(uint32 royaltyBasisPoints_)
public
onlyAdmin
{
_setRoyaltyBasisPoints(royaltyBasisPoints_);
}
function setAuthorizedAddress(address authorizedAddress_, bool authorized_)
public
onlyAdmin
{
_setAuthorizedAddress(authorizedAddress_, authorized_);
}
function transferOwnership(address newOwner)
public
virtual
override
onlyOwner
{
require(
newOwner != address(0),
"Ownable: new owner is the zero address"
);
_grantRole(DEFAULT_ADMIN_ROLE, newOwner);
_revokeRole(DEFAULT_ADMIN_ROLE, owner());
_transferOwnership(newOwner);
}
function supportsInterface(bytes4 interfaceId)
public
view
override(ERC1155, Royalty, AccessControl)
returns (bool)
{
return
interfaceId == type(IAccessControl).interfaceId ||
interfaceId == type(IERC2981).interfaceId ||
interfaceId == type(IContractURI).interfaceId ||
interfaceId == type(IERC1155).interfaceId ||
super.supportsInterface(interfaceId);
}
function isApprovedForAll(address _owner, address _operator)
public
view
override
returns (bool isOperator)
{
if (_isAuthorizedAddress(_operator)) {
return true;
}
return super.isApprovedForAll(_owner, _operator);
}
function name() public view virtual returns (string memory) {
return _name;
}
function symbol() public view virtual returns (string memory) {
return _symbol;
}
}
文件 11 的 30: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;
}
文件 12 的 30:IContractURI.sol
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
interface IContractURI is IERC165 {
function contractURI() external view returns (string memory);
}
文件 13 的 30:IERC1155.sol
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
interface IERC1155 is IERC165 {
event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);
event TransferBatch(
address indexed operator,
address indexed from,
address indexed to,
uint256[] ids,
uint256[] values
);
event ApprovalForAll(address indexed account, address indexed operator, bool approved);
event URI(string value, uint256 indexed id);
function balanceOf(address account, uint256 id) external view returns (uint256);
function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids)
external
view
returns (uint256[] memory);
function setApprovalForAll(address operator, bool approved) external;
function isApprovedForAll(address account, address operator) external view returns (bool);
function safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes calldata data
) external;
function safeBatchTransferFrom(
address from,
address to,
uint256[] calldata ids,
uint256[] calldata amounts,
bytes calldata data
) external;
}
文件 14 的 30:IERC1155MetadataURI.sol
pragma solidity ^0.8.0;
import "../IERC1155.sol";
interface IERC1155MetadataURI is IERC1155 {
function uri(uint256 id) external view returns (string memory);
}
文件 15 的 30:IERC1155Receiver.sol
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
interface IERC1155Receiver is IERC165 {
function onERC1155Received(
address operator,
address from,
uint256 id,
uint256 value,
bytes calldata data
) external returns (bytes4);
function onERC1155BatchReceived(
address operator,
address from,
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
) external returns (bytes4);
}
文件 16 的 30:IERC165.sol
pragma solidity ^0.8.0;
interface IERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
文件 17 的 30:IERC20.sol
pragma solidity ^0.8.0;
interface IERC20 {
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);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
文件 18 的 30:IERC20Metadata.sol
pragma solidity ^0.8.0;
import "../IERC20.sol";
interface IERC20Metadata is IERC20 {
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
}
文件 19 的 30:IERC2981.sol
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
interface IERC2981 is IERC165 {
function royaltyInfo(uint256 _tokenId, uint256 _salePrice)
external
view
returns (address receiver, uint256 royaltyAmount);
}
文件 20 的 30:IERC721.sol
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
interface IERC721 is IERC165 {
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
function balanceOf(address owner) external view returns (uint256 balance);
function ownerOf(uint256 tokenId) external view returns (address owner);
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external;
function transferFrom(
address from,
address to,
uint256 tokenId
) external;
function approve(address to, uint256 tokenId) external;
function getApproved(uint256 tokenId) external view returns (address operator);
function setApprovalForAll(address operator, bool _approved) external;
function isApprovedForAll(address owner, address operator) external view returns (bool);
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;
}
文件 21 的 30:IJungle.sol
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
interface IJungle is IERC1155, IERC20, IERC20Metadata {
function getStakedTokens(address staker)
external
view
returns (uint256[] memory);
function getStakedAmount(address staker) external view returns (uint256);
function getStaker(uint256 tokenId) external view returns (address);
function getAllRewards(address staker) external view returns (uint256);
function getLegendariesRewards(address staker)
external
view
returns (uint256);
function stakeById(uint256[] calldata tokenIds) external;
function legendariesStaked(address)
external
view
returns (
uint32 cotfAccumulatedTime,
uint32 mtfmAccumulatedTime,
uint32 cotfLastStaked,
uint32 mtfmLastStaked,
uint8 cotfStaked,
uint8 mtfmStaked
);
function stakeLegendaries(uint8 cotf, uint8 mtfm) external;
function unstakeLegendaries(uint8 cotf, uint8 mtfm) external;
function claimLegendaries() external;
function unstakeByIds(uint256[] calldata tokenIds) external;
function unstakeAll() external;
function claimAll() external;
function mint(address to, uint256 amount) external;
function burn(address from, uint256 amount) external;
function setController(address controller, bool authorized) external;
function setAuthorizedAddress(address authorizedAddress, bool authorized)
external;
}
文件 22 的 30: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);
}
}
文件 23 的 30:PackTokenIds.sol
pragma solidity ^0.8.4;
abstract contract PackTokenIds {
mapping(uint256 => uint256) private _DataStore;
function usedTokenId(uint256 tokenId) public view returns (bool used) {
(uint256 boolRow, uint256 boolColumn) = _tokenPosition(tokenId);
uint256 packedBools = _DataStore[boolRow];
used = (packedBools & (uint256(1) << boolColumn)) > 0 ? true : false;
}
function _tokenPosition(uint256 tokenId)
internal
pure
returns (uint256 boolRow, uint256 boolColumn)
{
boolRow = (tokenId << 1) / 256;
boolColumn = (tokenId << 1) % 256;
}
function _packBool(
uint256 _packedBools,
uint256 _boolIndex,
bool _value
) internal pure returns (uint256) {
return
_value
? _packedBools | (uint256(1) << _boolIndex)
: _packedBools & ~(uint256(1) << _boolIndex);
}
function _setUsedTokenIds(uint256[] calldata tokenIds) internal {
uint256 cRow;
uint256 cPackedBools = _DataStore[0];
for (uint256 i; i < tokenIds.length; i++) {
(uint256 boolRow, uint256 boolColumn) = _tokenPosition(tokenIds[i]);
if (boolRow != cRow) {
_DataStore[cRow] = cPackedBools;
cRow = boolRow;
cPackedBools = _DataStore[boolRow];
}
cPackedBools = _packBool(cPackedBools, boolColumn, true);
if (i + 1 == tokenIds.length) {
_DataStore[cRow] = cPackedBools;
}
}
}
}
文件 24 的 30:PreAuthorisable.sol
pragma solidity ^0.8.4;
abstract contract PreAuthorisable {
mapping(address => bool) private authorizedAddresses;
constructor(address[] memory _preAuthorized) {
for (uint256 i = 0; i < _preAuthorized.length; i++) {
_setAuthorizedAddress(_preAuthorized[i], true);
}
}
function _setAuthorizedAddress(address authorizedAddress, bool authorized) internal {
authorizedAddresses[authorizedAddress] = authorized;
}
function _isAuthorizedAddress(address operator) internal view returns (bool) {
return authorizedAddresses[operator];
}
}
文件 25 的 30:ReentrancyGuard.sol
pragma solidity ^0.8.0;
abstract contract ReentrancyGuard {
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
modifier nonReentrant() {
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
_status = _ENTERED;
_;
_status = _NOT_ENTERED;
}
}
文件 26 的 30:Royalty.sol
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/utils/introspection/ERC165.sol";
import "./IERC2981.sol";
abstract contract Royalty is ERC165, IERC2981 {
address public royaltyReceiver;
uint32 public royaltyBasisPoints;
function _setRoyaltyReceiver(address receiver_) internal {
royaltyReceiver = receiver_;
}
function _setRoyaltyBasisPoints(uint32 basisPoints_)
internal
{
royaltyBasisPoints = basisPoints_;
}
function royaltyInfo(uint256, uint256 salePrice_)
public
view
virtual
override
returns (address receiver, uint256 amount)
{
uint256 royaltyAmount = (salePrice_ * royaltyBasisPoints) / 10000;
return (royaltyReceiver, royaltyAmount);
}
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(ERC165, IERC165)
returns (bool)
{
return
interfaceId == type(IERC2981).interfaceId ||
super.supportsInterface(interfaceId);
}
}
文件 27 的 30:SaleState.sol
pragma solidity ^0.8.4;
error NoActiveSale();
error IncorrectSaleType();
error AllSalesFinished();
error NoPausedSale();
abstract contract SaleState {
enum State {
NOT_STARTED,
ACTIVE,
PAUSED,
FINISHED
}
struct Sale{
State state;
string saleType;
}
event StateOfSale(State _state);
event TypeOfSale(string _saleType);
event IsPaused(bool _paused);
Sale private _sale = Sale({saleType: "None", state: State.NOT_STARTED});
modifier whenSaleIsActive(string memory saleType) {
if (_sale.state != State.ACTIVE) revert NoActiveSale();
if (keccak256(bytes(_sale.saleType)) != keccak256(bytes(saleType))) revert IncorrectSaleType();
_;
}
function _setSaleState(State state) internal {
if (_sale.state == State.FINISHED) revert AllSalesFinished();
_sale.state = state;
if (state == State.FINISHED) {
_sale.saleType = "Finished";
emit TypeOfSale(_sale.saleType);
}
emit StateOfSale(_sale.state);
}
function _setSaleType(string memory saleType) internal {
if (_sale.state == State.FINISHED) revert AllSalesFinished();
_sale.saleType = saleType;
_sale.state = State.NOT_STARTED;
emit TypeOfSale(_sale.saleType);
}
function getSaleState() public view returns (State) {
return _sale.state;
}
function getSaleType() public view returns (string memory) {
return _sale.saleType;
}
function _pause() internal {
if (_sale.state != State.ACTIVE) revert NoActiveSale();
_sale.state = State.PAUSED;
emit IsPaused(true);
}
function _unpause() internal {
if (_sale.state != State.PAUSED) revert NoPausedSale();
_sale.state = State.ACTIVE;
emit IsPaused(false);
}
}
文件 28 的 30:Signature.sol
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
error HashUsed();
error SignatureFailed(address signatureAddress, address signer);
abstract contract Signature {
using ECDSA for bytes32;
address private _signer;
mapping(bytes32 => bool) private _isHashUsed;
constructor(address signerAddress_){
_signer = signerAddress_;
}
function _setSignerAddress(address signerAddress_) internal {
_signer = signerAddress_;
}
function signerAddress() public view returns(address) {
return _signer;
}
modifier onlySignedTx(
bytes32 hash_,
bytes calldata signature_
) {
if (_isHashUsed[hash_]) revert HashUsed();
address signatureAddress = hash_
.toEthSignedMessageHash()
.recover(signature_);
if (signatureAddress != _signer) revert SignatureFailed(signatureAddress, _signer);
_isHashUsed[hash_] = true;
_;
}
}
文件 29 的 30: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);
}
}
文件 30 的 30:WithdrawalSplittable.sol
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
abstract contract WithdrawalSplittable is Ownable, ReentrancyGuard {
struct Beneficiary {
address wallet;
uint256 basisPoints;
}
Beneficiary[] public beneficiaries;
error WithdrawalFailedBeneficiary(uint256 index, address beneficiary);
error ZeroBeneficiaryAddress();
error ArrayLengthMismatch();
error ZeroArrayLength();
error ZeroBalance();
error ZeroWithdrawalAddress();
error ZeroWithdrawalBasisPoints();
receive() external payable {}
modifier checkWithdrawalBasisPoints(address[] memory _wallets, uint256[] memory _basisPoints) {
if (_wallets.length != _basisPoints.length)
revert ArrayLengthMismatch();
if (_wallets.length == 0)
revert ZeroArrayLength();
for (uint256 i; i < _wallets.length; i++) {
if(_wallets[i] == address(0)) revert ZeroWithdrawalAddress();
if(_basisPoints[i] == 0) revert ZeroWithdrawalBasisPoints();
}
_;
}
function setBeneficiaries(address[] memory _wallets, uint256[] memory _basisPoints)
public
onlyOwner
checkWithdrawalBasisPoints(_wallets, _basisPoints)
{
delete beneficiaries;
for (uint256 i; i < _wallets.length; i++) {
if (_wallets[i] == address(0))
revert ZeroBeneficiaryAddress();
beneficiaries.push(Beneficiary(_wallets[i], _basisPoints[i]));
}
}
function calculateSplit(uint256 balance)
public view
returns (uint256[] memory)
{
uint256[] memory amounts = new uint256[](beneficiaries.length);
for (uint256 i; i < beneficiaries.length; i++) {
uint256 amount = (balance * beneficiaries[i].basisPoints) / 10000;
amounts[i] = amount;
}
return amounts;
}
function withdrawErc20(IERC20 token) public nonReentrant {
uint256 totalBalance = token.balanceOf(address(this));
if (totalBalance == 0)
revert ZeroBalance();
uint256[] memory amounts = calculateSplit(totalBalance);
for (uint256 i; i < beneficiaries.length; i++) {
if (!token.transfer(beneficiaries[i].wallet, amounts[i]))
revert WithdrawalFailedBeneficiary(i, beneficiaries[i].wallet);
}
}
function withdrawEth() public nonReentrant {
uint256 totalBalance = address(this).balance;
if (totalBalance == 0)
revert ZeroBalance();
uint256[] memory amounts = calculateSplit(totalBalance);
for (uint256 i; i < beneficiaries.length; i++) {
if (!payable(beneficiaries[i].wallet).send(amounts[i]))
revert WithdrawalFailedBeneficiary(i, beneficiaries[i].wallet);
}
}
}
{
"compilationTarget": {
"contracts/FalloutCrystal.sol": "FalloutCrystal"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 1
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"signer_","type":"address"},{"internalType":"address","name":"admin_","type":"address"},{"internalType":"address","name":"royaltyReceiver_","type":"address"},{"internalType":"contract IJungle","name":"jungleContract_","type":"address"},{"internalType":"contract IERC721","name":"jfgContract_","type":"address"},{"internalType":"address[]","name":"_preAuthorized","type":"address[]"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AllSalesFinished","type":"error"},{"inputs":[],"name":"ArrayLengthMismatch","type":"error"},{"inputs":[],"name":"DeployerIsAdmin","type":"error"},{"inputs":[],"name":"HashUsed","type":"error"},{"inputs":[],"name":"IncorrectEthValue","type":"error"},{"inputs":[],"name":"IncorrectSaleType","type":"error"},{"inputs":[],"name":"IncorrectValueJungle","type":"error"},{"inputs":[],"name":"MustMintMinimumOne","type":"error"},{"inputs":[],"name":"NoActiveSale","type":"error"},{"inputs":[],"name":"NoPausedSale","type":"error"},{"inputs":[],"name":"NoTrailingSlash","type":"error"},{"inputs":[],"name":"NotAdminOrModerator","type":"error"},{"inputs":[],"name":"NotAdminOrOwner","type":"error"},{"inputs":[],"name":"NotHoldingAnyTokens","type":"error"},{"inputs":[],"name":"NotYourToken","type":"error"},{"inputs":[{"internalType":"address","name":"signatureAddress","type":"address"},{"internalType":"address","name":"signer","type":"address"}],"name":"SignatureFailed","type":"error"},{"inputs":[],"name":"SoldOut","type":"error"},{"inputs":[{"internalType":"uint256","name":"limit","type":"uint256"}],"name":"TransactionMintLimit","type":"error"},{"inputs":[{"internalType":"uint256","name":"jfgId","type":"uint256"}],"name":"UsedToken","type":"error"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"},{"internalType":"address","name":"beneficiary","type":"address"}],"name":"WithdrawalFailedBeneficiary","type":"error"},{"inputs":[],"name":"ZeroAdminAddress","type":"error"},{"inputs":[],"name":"ZeroArrayLength","type":"error"},{"inputs":[],"name":"ZeroBalance","type":"error"},{"inputs":[],"name":"ZeroBeneficiaryAddress","type":"error"},{"inputs":[],"name":"ZeroWithdrawalAddress","type":"error"},{"inputs":[],"name":"ZeroWithdrawalBasisPoints","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","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":"bool","name":"_paused","type":"bool"}],"name":"IsPaused","type":"event"},{"anonymous":false,"inputs":[],"name":"MintEnds","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":[],"name":"Phase1MintBegins","type":"event"},{"anonymous":false,"inputs":[],"name":"Phase2MintBegins","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"enum SaleState.State","name":"_state","type":"uint8"}],"name":"StateOfSale","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"indexed":false,"internalType":"uint256[]","name":"values","type":"uint256[]"}],"name":"TransferBatch","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"TransferSingle","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"_saleType","type":"string"}],"name":"TypeOfSale","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"value","type":"string"},{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"}],"name":"URI","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"uri_","type":"string"}],"name":"URIUpdated","type":"event"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"JUNGLE_BANK","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_BATCH_MINT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"MAX_SUPPLY","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MODERATOR_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"accounts","type":"address[]"},{"internalType":"uint256[]","name":"ids","type":"uint256[]"}],"name":"balanceOfBatch","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"beneficiaries","outputs":[{"internalType":"address","name":"wallet","type":"address"},{"internalType":"uint256","name":"basisPoints","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"burn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"internalType":"uint256[]","name":"values","type":"uint256[]"}],"name":"burnBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"balance","type":"uint256"}],"name":"calculateSplit","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":"endMint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"exists","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getSaleState","outputs":[{"internalType":"enum SaleState.State","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getSaleType","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"j_","type":"uint256"},{"internalType":"uint256","name":"q_","type":"uint256"}],"name":"holdersEthPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"address","name":"_operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"isOperator","type":"bool"}],"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":[],"name":"pauseMint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"signature_","type":"bytes"},{"internalType":"bytes32","name":"salt_","type":"bytes32"},{"internalType":"uint256","name":"jungle_","type":"uint256"},{"internalType":"uint256[]","name":"jfgIds_","type":"uint256[]"}],"name":"phase1Mint","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes","name":"signature_","type":"bytes"},{"internalType":"bytes32","name":"salt_","type":"bytes32"},{"internalType":"uint256","name":"jungle_","type":"uint256"},{"internalType":"uint256","name":"quantity_","type":"uint256"}],"name":"phase2Mint","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"removeAdminPermission","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"royaltyBasisPoints","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"salePrice_","type":"uint256"}],"name":"royaltyInfo","outputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"royaltyReceiver","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeBatchTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"setAdminPermission","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":"address","name":"authorizedAddress_","type":"address"},{"internalType":"bool","name":"authorized_","type":"bool"}],"name":"setAuthorizedAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_wallets","type":"address[]"},{"internalType":"uint256[]","name":"_basisPoints","type":"uint256[]"}],"name":"setBeneficiaries","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"royaltyBasisPoints_","type":"uint32"}],"name":"setRoyaltyBasisPoints","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"royaltyReceiver_","type":"address"}],"name":"setRoyaltyReceiver","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"signerAddress_","type":"address"}],"name":"setSignerAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"uri_","type":"string"}],"name":"setURI","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"signerAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"startPhase1Mint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"startPhase2Mint","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":"id","type":"uint256"}],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unpauseMint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId_","type":"uint256"}],"name":"uri","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"usedTokenId","outputs":[{"internalType":"bool","name":"used","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"}],"name":"withdrawErc20","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawEth","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]