文件 1 的 12:Address.sol
pragma solidity ^0.8.0;
library Address {
function isContract(address account) internal view returns (bool) {
uint256 size;
assembly {
size := extcodesize(account)
}
return size > 0;
}
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
文件 2 的 12:Context.sol
pragma solidity ^0.8.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
文件 3 的 12: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 {
require(_msgSender() != operator, "ERC1155: setting approval status for self");
_operatorApprovals[_msgSender()][operator] = approved;
emit ApprovalForAll(_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 account,
uint256 id,
uint256 amount,
bytes memory data
) internal virtual {
require(account != address(0), "ERC1155: mint to the zero address");
address operator = _msgSender();
_beforeTokenTransfer(operator, address(0), account, _asSingletonArray(id), _asSingletonArray(amount), data);
_balances[id][account] += amount;
emit TransferSingle(operator, address(0), account, id, amount);
_doSafeTransferAcceptanceCheck(operator, address(0), account, 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 account,
uint256 id,
uint256 amount
) internal virtual {
require(account != address(0), "ERC1155: burn from the zero address");
address operator = _msgSender();
_beforeTokenTransfer(operator, account, address(0), _asSingletonArray(id), _asSingletonArray(amount), "");
uint256 accountBalance = _balances[id][account];
require(accountBalance >= amount, "ERC1155: burn amount exceeds balance");
unchecked {
_balances[id][account] = accountBalance - amount;
}
emit TransferSingle(operator, account, address(0), id, amount);
}
function _burnBatch(
address account,
uint256[] memory ids,
uint256[] memory amounts
) internal virtual {
require(account != address(0), "ERC1155: burn from the zero address");
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
address operator = _msgSender();
_beforeTokenTransfer(operator, account, address(0), ids, amounts, "");
for (uint256 i = 0; i < ids.length; i++) {
uint256 id = ids[i];
uint256 amount = amounts[i];
uint256 accountBalance = _balances[id][account];
require(accountBalance >= amount, "ERC1155: burn amount exceeds balance");
unchecked {
_balances[id][account] = accountBalance - amount;
}
}
emit TransferBatch(operator, account, address(0), ids, amounts);
}
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;
}
}
文件 4 的 12: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 _mint(
address account,
uint256 id,
uint256 amount,
bytes memory data
) internal virtual override {
super._mint(account, id, amount, data);
_totalSupply[id] += amount;
}
function _mintBatch(
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual override {
super._mintBatch(to, ids, amounts, data);
for (uint256 i = 0; i < ids.length; ++i) {
_totalSupply[ids[i]] += amounts[i];
}
}
function _burn(
address account,
uint256 id,
uint256 amount
) internal virtual override {
super._burn(account, id, amount);
_totalSupply[id] -= amount;
}
function _burnBatch(
address account,
uint256[] memory ids,
uint256[] memory amounts
) internal virtual override {
super._burnBatch(account, ids, amounts);
for (uint256 i = 0; i < ids.length; ++i) {
_totalSupply[ids[i]] -= amounts[i];
}
}
}
文件 5 的 12: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;
}
}
文件 6 的 12: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;
}
文件 7 的 12:IERC1155MetadataURI.sol
pragma solidity ^0.8.0;
import "../IERC1155.sol";
interface IERC1155MetadataURI is IERC1155 {
function uri(uint256 id) external view returns (string memory);
}
文件 8 的 12: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);
}
文件 9 的 12:IERC165.sol
pragma solidity ^0.8.0;
interface IERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
文件 10 的 12:Ownable.sol
pragma solidity ^0.8.0;
import "../utils/Context.sol";
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
_setOwner(_msgSender());
}
function owner() public view virtual returns (address) {
return _owner;
}
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
function renounceOwnership() public virtual onlyOwner {
_setOwner(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_setOwner(newOwner);
}
function _setOwner(address newOwner) private {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
文件 11 的 12:PortalHelpers.sol
pragma solidity ^0.8.9;
library TokenHolder {
struct Holders {
address[] accounts;
mapping(address => uint256) indexes;
}
function addHolder(Holders storage _holders, address _account) internal {
if (_holders.indexes[_account] != 0) return;
_holders.accounts.push(_account);
_holders.indexes[_account] = _holders.accounts.length;
}
function removeHolder(Holders storage _holders, address _account) internal {
uint256 valueIndex = _holders.indexes[_account];
if (valueIndex == 0) return;
uint256 toDeleteIndex = valueIndex - 1;
uint256 lastIndex = _holders.accounts.length - 1;
if (lastIndex != toDeleteIndex) {
address lastvalue = _holders.accounts[lastIndex];
_holders.accounts[toDeleteIndex] = lastvalue;
_holders.indexes[lastvalue] = valueIndex;
}
_holders.accounts.pop();
_holders.indexes[_account] = 0;
}
function containsHolder(Holders storage _holders, address _account) internal view returns (bool) {
return _holders.indexes[_account] != 0;
}
}
文件 12 的 12:RedVillagePortals.sol
pragma solidity ^0.8.6;
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { ERC1155, ERC1155Supply } from "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Supply.sol";
import { TokenHolder } from "./PortalHelpers.sol";
contract RedVillagePortal is ERC1155Supply, Ownable {
using TokenHolder for TokenHolder.Holders;
struct TokenBalance {
uint16[] paymentRatios;
address[] paymentWallets;
}
struct TokenConfig {
address TEAM_WALLET;
uint256 MAX_PUBLIC_SALE_SUPPLY;
uint256 MAX_PRESALE_SUPPLY;
uint256 MAX_TEAM_SUPPLY;
uint256 MAX_PUBLIC_PER_WALLET;
uint256 MAX_PUBLIC_PER_TXN;
uint256 MAX_PRESALE_PER_WALLET;
uint256 MAX_PRESALE_PER_TXN;
uint256 PRICE;
string baseURI;
}
struct TokenWhitelist {
uint8[] standards;
uint256[] erc1155Ids;
address[] contracts;
mapping(address => uint256) allocated;
}
struct TokenInfo {
bool salesActive;
bool presalesActive;
bool teamClaimed;
uint256 presaleClaimed;
uint256 publicClaimed;
TokenConfig config;
}
mapping(uint256 => bool) public tradingPaused;
mapping(uint256 => TokenInfo) public tokens;
mapping(uint256 => TokenWhitelist) whitelists;
mapping(uint256 => TokenHolder.Holders) holders;
mapping(uint256 => TokenBalance) tokenBalances;
constructor() ERC1155("") {
TokenConfig storage config = tokens[1].config;
config.MAX_PUBLIC_SALE_SUPPLY = 5965;
config.MAX_PRESALE_SUPPLY = 2000;
config.MAX_TEAM_SUPPLY = 35;
config.MAX_PUBLIC_PER_WALLET = 28;
config.MAX_PUBLIC_PER_TXN = 14;
config.MAX_PRESALE_PER_WALLET = 0;
config.MAX_PRESALE_PER_TXN = 0;
config.PRICE = 0.1 ether;
config.TEAM_WALLET = 0xCD38B6d9c4b12654aD06Aae2842a0FC3D861188b;
config.baseURI = "";
tokenBalances[1].paymentRatios = [900, 100];
tokenBalances[1].paymentWallets = [0xCBf7f6b967c2314Ed0694D39512AA18AD4d01878, 0x909680a5E46a3401D4dD75148B61E129451fa266];
}
function presaleClaim(uint256 _tokenId, uint16 _amount) external payable {
TokenInfo storage token = tokens[_tokenId];
TokenConfig memory config = token.config;
require(token.presalesActive, "Claim is not active");
require(tx.origin == msg.sender, "Not allowed");
require(tokenEligible(_tokenId, msg.sender) || whitelistAllocated(_tokenId, msg.sender) >= _amount, "Not eligible");
require(whitelistAllocated(_tokenId, msg.sender) == 0 || whitelistAllocated(_tokenId, msg.sender) >= _amount, "Exceed max");
require(config.MAX_PRESALE_PER_TXN == 0 || _amount <= config.MAX_PRESALE_PER_TXN, "Exceed max");
require(config.MAX_PRESALE_PER_WALLET == 0 || balanceOf(msg.sender, _tokenId) + _amount <= config.MAX_PRESALE_PER_WALLET, "Exceed max");
require(token.presaleClaimed + _amount <= config.MAX_PRESALE_SUPPLY, "Exceed total");
require(msg.value >= (_amount * config.PRICE), "Ether value incorrect");
if (whitelistAllocated(_tokenId, msg.sender) >= _amount) {
whitelists[_tokenId].allocated[msg.sender] -= _amount;
}
_mint(msg.sender, _tokenId, _amount, "");
tokens[_tokenId].presaleClaimed += _amount;
}
function claim(uint256 _tokenId, uint16 _amount) external payable {
TokenInfo storage token = tokens[_tokenId];
TokenConfig memory config = token.config;
require(token.salesActive, "Claim is not active");
require(tx.origin == msg.sender, "Not allowed");
require(_amount <= config.MAX_PUBLIC_PER_TXN, "Exceed max");
require(balanceOf(msg.sender, _tokenId) + _amount <= config.MAX_PUBLIC_PER_WALLET, "Exceed max");
require(token.publicClaimed + token.presaleClaimed + _amount <= config.MAX_PUBLIC_SALE_SUPPLY, "Exceed total");
require(msg.value >= (_amount * config.PRICE), "Ether value incorrect");
_mint(msg.sender, _tokenId, _amount, "");
token.publicClaimed += _amount;
}
function whitelistAllocated(uint256 _tokenId, address _account) public view returns (uint256) {
return whitelists[_tokenId].allocated[_account];
}
function tokenEligible(uint256 _tokenId, address _account) public view returns (bool) {
uint256 size = whitelists[_tokenId].standards.length;
for (uint256 i = 0; i < size; i++) {
if (whitelists[_tokenId].standards[i] == 0 && IERC721(whitelists[_tokenId].contracts[i]).balanceOf(_account) > 0) {
return true;
}
else if (whitelists[_tokenId].standards[i] == 1 && IERC1155(whitelists[_tokenId].contracts[i]).balanceOf(_account, whitelists[_tokenId].erc1155Ids[i]) > 0) {
return true;
}
}
return false;
}
function getHoldersLength(uint256 _tokenId) public view returns (uint256) {
return holders[_tokenId].accounts.length;
}
function getHolders(
uint256 _tokenId,
uint256 _start,
uint256 _end
) external view returns (address[] memory, uint256[] memory) {
uint256 maxSize = getHoldersLength(_tokenId);
_end = _end > maxSize ? maxSize : _end;
uint256 size = _end - _start;
address[] memory accounts = new address[](size);
uint256[] memory balances = new uint256[](size);
for (uint256 i = 0; i < size; i++) {
address holder = holders[_tokenId].accounts[_start + i];
accounts[i] = holder;
balances[i] = balanceOf(holder, _tokenId);
}
return (accounts, balances);
}
function uri(uint256 _tokenId) public view override returns (string memory) {
require(exists(_tokenId), "Non exists token");
return tokens[_tokenId].config.baseURI;
}
function getPaymentDetail(uint256 _tokenId) public view returns (uint16[] memory, address[] memory) {
return (tokenBalances[_tokenId].paymentRatios, tokenBalances[_tokenId].paymentWallets);
}
function setTokenInfo(
uint256 _tokenId,
uint256 _maxPublicSale,
uint256 _maxPresale,
uint256 _maxTeamSupply,
uint256 _maxPerAccount,
uint256 _maxPerTxn,
uint256 _maxPresalePerAccount,
uint256 _maxPresalePerTxn,
address _teamWallet,
uint256 _price
) external onlyOwner {
require(!exists(_tokenId), "Token exist");
TokenConfig storage config = tokens[_tokenId].config;
config.MAX_PUBLIC_SALE_SUPPLY = _maxPublicSale;
config.MAX_PRESALE_SUPPLY = _maxPresale;
config.MAX_TEAM_SUPPLY = _maxTeamSupply;
config.MAX_PUBLIC_PER_WALLET = _maxPerAccount;
config.MAX_PUBLIC_PER_TXN = _maxPerTxn;
config.MAX_PRESALE_PER_WALLET = _maxPresalePerAccount;
config.MAX_PRESALE_PER_TXN = _maxPresalePerTxn;
config.PRICE = _price;
config.TEAM_WALLET = _teamWallet;
}
function setExternalContract(
uint256 _tokenId,
uint8[] calldata _standards,
address[] calldata _contracts,
uint256[] calldata _ids
) external onlyOwner {
require(_standards.length == _contracts.length, "Input mismatch");
require(_ids.length == _contracts.length, "Input mismatch");
for (uint256 i = 0; i < _standards.length; i++) {
require(_standards[i] == 0 || _standards[i] == 1, "Incorrect value");
}
whitelists[_tokenId].standards = _standards;
whitelists[_tokenId].contracts = _contracts;
whitelists[_tokenId].erc1155Ids = _ids;
}
function setBaseURI(uint256[] calldata _tokenIds, string[] calldata _baseURI) external onlyOwner {
require(_tokenIds.length == _baseURI.length, "Input mismatch");
for (uint256 i = 0; i < _tokenIds.length; i++) {
tokens[_tokenIds[i]].config.baseURI = _baseURI[i];
}
}
function setTradingPause(uint256[] calldata _tokenIds, bool _status) external onlyOwner {
for (uint256 i = 0; i < _tokenIds.length; i++) {
tradingPaused[_tokenIds[i]] = _status;
}
}
function togglePresaleActive(uint256[] calldata _tokenIds, bool _status) external onlyOwner {
for (uint256 i = 0; i < _tokenIds.length; i++) {
tokens[_tokenIds[i]].presalesActive = _status;
}
}
function toggleSaleActive(uint256[] calldata _tokenIds, bool _status) external onlyOwner {
for (uint256 i = 0; i < _tokenIds.length; i++) {
tokens[_tokenIds[i]].salesActive = _status;
}
}
function addWhitelist(
uint256 _tokenId,
address[] calldata _accounts,
uint256[] calldata _amount
) external onlyOwner {
require(_accounts.length == _amount.length, "Input mismatch");
for (uint256 i = 0; i < _accounts.length; i++) {
whitelists[_tokenId].allocated[_accounts[i]] = _amount[i];
}
}
function teamClaim(uint256 _tokenId) external onlyOwner {
TokenInfo storage token = tokens[_tokenId];
TokenConfig memory config = token.config;
require(!token.teamClaimed, "Team claimed");
_mint(config.TEAM_WALLET, _tokenId, config.MAX_TEAM_SUPPLY, "");
token.teamClaimed = true;
}
function updatePayment(
uint256 _tokenId,
uint16[] calldata _ratios,
address[] calldata _accounts
) external onlyOwner {
require(_ratios.length == _accounts.length, "Input mismatch");
uint256 percentage = 0;
for (uint256 i = 0; i < _ratios.length; i++) {
percentage += _ratios[i];
}
require(percentage == 1000, "Invalid percentage");
tokenBalances[_tokenId].paymentRatios = _ratios;
tokenBalances[_tokenId].paymentWallets = _accounts;
}
function withdraw(uint256 _tokenId) public onlyOwner {
TokenBalance storage tokenBalance = tokenBalances[_tokenId];
uint256 maxBalance = address(this).balance;
for (uint256 i = 0; i < tokenBalance.paymentRatios.length; i++) {
uint256 balance = (maxBalance * tokenBalance.paymentRatios[i]) / 1000;
payable(tokenBalance.paymentWallets[i]).transfer(balance);
}
}
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);
for (uint256 i = 0; i < ids.length; i++) {
uint256 tokenId = ids[i];
require(from == address(0) || !tradingPaused[tokenId], "Token paused");
if (amounts[i] == 0) continue;
if (from != address(0) && balanceOf(from, tokenId) == amounts[i]) {
holders[tokenId].removeHolder(from);
}
if (to != address(0)) {
holders[tokenId].addHolder(to);
}
}
}
}
interface IERC721 {
function balanceOf(address) external view returns (uint256);
}
interface IERC1155 {
function balanceOf(address, uint256) external view returns (uint256);
}
{
"compilationTarget": {
"contracts/mystic/RedVillagePortals.sol": "RedVillagePortal"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"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":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"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":"value","type":"string"},{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"}],"name":"URI","type":"event"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"address[]","name":"_accounts","type":"address[]"},{"internalType":"uint256[]","name":"_amount","type":"uint256[]"}],"name":"addWhitelist","outputs":[],"stateMutability":"nonpayable","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":"_tokenId","type":"uint256"},{"internalType":"uint16","name":"_amount","type":"uint16"}],"name":"claim","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"exists","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"uint256","name":"_start","type":"uint256"},{"internalType":"uint256","name":"_end","type":"uint256"}],"name":"getHolders","outputs":[{"internalType":"address[]","name":"","type":"address[]"},{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"getHoldersLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"getPaymentDetail","outputs":[{"internalType":"uint16[]","name":"","type":"uint16[]"},{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"uint16","name":"_amount","type":"uint16"}],"name":"presaleClaim","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","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":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"_tokenIds","type":"uint256[]"},{"internalType":"string[]","name":"_baseURI","type":"string[]"}],"name":"setBaseURI","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"uint8[]","name":"_standards","type":"uint8[]"},{"internalType":"address[]","name":"_contracts","type":"address[]"},{"internalType":"uint256[]","name":"_ids","type":"uint256[]"}],"name":"setExternalContract","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"uint256","name":"_maxPublicSale","type":"uint256"},{"internalType":"uint256","name":"_maxPresale","type":"uint256"},{"internalType":"uint256","name":"_maxTeamSupply","type":"uint256"},{"internalType":"uint256","name":"_maxPerAccount","type":"uint256"},{"internalType":"uint256","name":"_maxPerTxn","type":"uint256"},{"internalType":"uint256","name":"_maxPresalePerAccount","type":"uint256"},{"internalType":"uint256","name":"_maxPresalePerTxn","type":"uint256"},{"internalType":"address","name":"_teamWallet","type":"address"},{"internalType":"uint256","name":"_price","type":"uint256"}],"name":"setTokenInfo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"_tokenIds","type":"uint256[]"},{"internalType":"bool","name":"_status","type":"bool"}],"name":"setTradingPause","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":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"teamClaim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"_tokenIds","type":"uint256[]"},{"internalType":"bool","name":"_status","type":"bool"}],"name":"togglePresaleActive","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"_tokenIds","type":"uint256[]"},{"internalType":"bool","name":"_status","type":"bool"}],"name":"toggleSaleActive","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"address","name":"_account","type":"address"}],"name":"tokenEligible","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"tokens","outputs":[{"internalType":"bool","name":"salesActive","type":"bool"},{"internalType":"bool","name":"presalesActive","type":"bool"},{"internalType":"bool","name":"teamClaimed","type":"bool"},{"internalType":"uint256","name":"presaleClaimed","type":"uint256"},{"internalType":"uint256","name":"publicClaimed","type":"uint256"},{"components":[{"internalType":"address","name":"TEAM_WALLET","type":"address"},{"internalType":"uint256","name":"MAX_PUBLIC_SALE_SUPPLY","type":"uint256"},{"internalType":"uint256","name":"MAX_PRESALE_SUPPLY","type":"uint256"},{"internalType":"uint256","name":"MAX_TEAM_SUPPLY","type":"uint256"},{"internalType":"uint256","name":"MAX_PUBLIC_PER_WALLET","type":"uint256"},{"internalType":"uint256","name":"MAX_PUBLIC_PER_TXN","type":"uint256"},{"internalType":"uint256","name":"MAX_PRESALE_PER_WALLET","type":"uint256"},{"internalType":"uint256","name":"MAX_PRESALE_PER_TXN","type":"uint256"},{"internalType":"uint256","name":"PRICE","type":"uint256"},{"internalType":"string","name":"baseURI","type":"string"}],"internalType":"struct RedVillagePortal.TokenConfig","name":"config","type":"tuple"}],"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":"uint256","name":"","type":"uint256"}],"name":"tradingPaused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"uint16[]","name":"_ratios","type":"uint16[]"},{"internalType":"address[]","name":"_accounts","type":"address[]"}],"name":"updatePayment","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"},{"internalType":"address","name":"_account","type":"address"}],"name":"whitelistAllocated","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"}]