Contract 0xcC57Ce4Dc70F6535618df7B6705159d6F8064C7E

 

Contract Overview

Balance:
0 MATIC

MATIC Value:
$0.00

Token:
 
Txn Hash Method
Block
From
To
Value [Txn Fee]
0x676a7cc41e4a49ef26ee8cbcd98b4621feb93760167c6e05abf9f72e8bd41c79Find Treasure210060922021-11-05 9:06:01239 days 15 hrs agoThe Wall: Deployer IN  0xcc57ce4dc70f6535618df7b6705159d6f8064c7e0 MATIC0.0053170830
0xd1d679567c3462f6135cac0b72474eee341dd90bb0b52484d962b4c160743095Hide Treasure208325552021-10-31 20:46:55244 days 3 hrs agoThe Wall: Deployer IN  0xcc57ce4dc70f6535618df7b6705159d6f8064c7e0 MATIC0.0009001830
0xc8708032705f57c49a9a4476fc61cebae18fabd1ebcd221efa937c7f44d5aed4Hide Treasure208317802021-10-31 20:11:45244 days 4 hrs agoThe Wall: Deployer IN  0xcc57ce4dc70f6535618df7b6705159d6f8064c7e0 MATIC0.0014131830
0x02b11048ff81641864c05e7f3bd528479428ca46fa475c02adc11a244a02f257Find Treasure205365512021-10-23 21:34:01252 days 2 hrs agoThe Wall: Deployer IN  0xcc57ce4dc70f6535618df7b6705159d6f8064c7e0 MATIC0.0019359930
0xa7560aa53e7165389b9134e8bdd49e7ae830358bd1e0fa9ca20d319b7283cbe7Hide Treasure205365342021-10-23 21:33:27252 days 2 hrs agoThe Wall: Deployer IN  0xcc57ce4dc70f6535618df7b6705159d6f8064c7e0 MATIC0.0014131830
0x0aff33353bdb5394b97c49a97c954cef14e89c33d9d0272bde6f2ba842a11db10x60806040198754392021-10-05 15:23:10270 days 9 hrs agoThe Wall: Deployer IN  Create: Treasure0 MATIC0.00954692412
[ Download CSV Export 
Parent Txn Hash Block From To Value
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
Treasure

Compiler Version
v0.8.7+commit.e28d00a7

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion, GNU LGPLv3 license

Contract Source Code (Solidity Multiple files format)

File 1 of 18: treasure.sol
/*
This file is part of the TheWall project.

The TheWall Contract is free software: you can redistribute it and/or
modify it under the terms of the GNU lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

The TheWall Contract is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU lesser General Public License for more details.

You should have received a copy of the GNU lesser General Public License
along with the TheWall Contract. If not, see <http://www.gnu.org/licenses/>.

@author Ilya Svirin <[email protected]>
*/
// SPDX-License-Identifier: GNU lesser General Public License

pragma solidity ^0.8.0;

import "Address.sol";
import "Ownable.sol";
import "IERC20.sol";
import "thewall.sol";

contract Treasure is Ownable
{
    event TreasureSet(address treasureContract, uint256 treasureAmount);
    event TreasureHidden(bytes32 hash);
    event TreasureFound(int256 [] coords);
    event Rewarded(address indexed user, uint256 indexed tokenId, uint256 amount);

    bytes32     public _hash;
    TheWall     public _thewall;
    TheWallCore public _thewallcore;
    IERC20      public _treasureContract;
    uint256     public _treasuredAmount;
    
    constructor(address payable thewall, address thewallcore, address treasureContract, uint256 treasureAmount)
    {
        _thewall = TheWall(thewall);
        _thewallcore = TheWallCore(thewallcore);
        setTreasure(treasureContract, treasureAmount);
    }
    
    function setTreasure(address treasureContract, uint256 treasureAmount) onlyOwner public
    {
        _treasureContract = IERC20(treasureContract);
        _treasuredAmount = treasureAmount;
        emit TreasureSet(treasureContract, treasureAmount);
    }
    
    function hideTreasure(bytes32 hash) onlyOwner public
    {
        _hash = hash;
        emit TreasureHidden(hash);
    }
    
    function findTreasure(int256 [] memory coords, uint256 salt) onlyOwner public
    {
        bytes32 hash = keccak256(abi.encodePacked(keccak256(abi.encodePacked(coords)), salt));
        require(hash == _hash, "Treasure: Invalid data");
        emit TreasureFound(coords);
        delete _hash;

        for(uint i = 0; i < coords.length;)
        {
            int256 x = coords[i++];
            int256 y = coords[i++];
            uint256 tokenId = _thewallcore._areaOnTheWall(x, y);
            if (tokenId != 0)
            {
                address user = _thewall.ownerOf(tokenId);
                if (_treasureContract.transfer(user, _treasuredAmount))
                {
                    emit Rewarded(user, tokenId, _treasuredAmount);
                }
            }
        }
    }
    
    function gameOver() onlyOwner public
    {
        uint256 balance = _treasureContract.balanceOf(address(this));
        if (balance > 0)
        {
            _treasureContract.transfer(_msgSender(), balance);
        }
        selfdestruct(payable(_msgSender()));
    }
}

File 2 of 18: Address.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        assembly {
            size := extcodesize(account)
        }
        return size > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    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");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCall(target, data, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    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");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    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);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    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);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    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);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

File 3 of 18: Context.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}

File 4 of 18: ERC165.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "IERC165.sol";

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 *
 * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
 */
abstract contract ERC165 is IERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}

File 5 of 18: ERC721.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "IERC721.sol";
import "IERC721Receiver.sol";
import "IERC721Metadata.sol";
import "Address.sol";
import "Context.sol";
import "Strings.sol";
import "ERC165.sol";

/**
 * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
 * the Metadata extension, but not including the Enumerable extension, which is available separately as
 * {ERC721Enumerable}.
 */
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
    using Address for address;
    using Strings for uint256;

    // Token name
    string private _name;

    // Token symbol
    string private _symbol;

    // Mapping from token ID to owner address
    mapping(uint256 => address) private _owners;

    // Mapping owner address to token count
    mapping(address => uint256) private _balances;

    // Mapping from token ID to approved address
    mapping(uint256 => address) private _tokenApprovals;

    // Mapping from owner to operator approvals
    mapping(address => mapping(address => bool)) private _operatorApprovals;

    /**
     * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
        return
            interfaceId == type(IERC721).interfaceId ||
            interfaceId == type(IERC721Metadata).interfaceId ||
            super.supportsInterface(interfaceId);
    }

    /**
     * @dev See {IERC721-balanceOf}.
     */
    function balanceOf(address owner) public view virtual override returns (uint256) {
        require(owner != address(0), "ERC721: balance query for the zero address");
        return _balances[owner];
    }

    /**
     * @dev See {IERC721-ownerOf}.
     */
    function ownerOf(uint256 tokenId) public view virtual override returns (address) {
        address owner = _owners[tokenId];
        require(owner != address(0), "ERC721: owner query for nonexistent token");
        return owner;
    }

    /**
     * @dev See {IERC721Metadata-name}.
     */
    function name() public view virtual override returns (string memory) {
        return _name;
    }

    /**
     * @dev See {IERC721Metadata-symbol}.
     */
    function symbol() public view virtual override returns (string memory) {
        return _symbol;
    }

    /**
     * @dev See {IERC721Metadata-tokenURI}.
     */
    function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
        require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");

        string memory baseURI = _baseURI();
        return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
    }

    /**
     * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
     * token will be the concatenation of the `baseURI` and the `tokenId`. Empty
     * by default, can be overriden in child contracts.
     */
    function _baseURI() internal view virtual returns (string memory) {
        return "";
    }

    /**
     * @dev See {IERC721-approve}.
     */
    function approve(address to, uint256 tokenId) public virtual override {
        address owner = ERC721.ownerOf(tokenId);
        require(to != owner, "ERC721: approval to current owner");

        require(
            _msgSender() == owner || isApprovedForAll(owner, _msgSender()),
            "ERC721: approve caller is not owner nor approved for all"
        );

        _approve(to, tokenId);
    }

    /**
     * @dev See {IERC721-getApproved}.
     */
    function getApproved(uint256 tokenId) public view virtual override returns (address) {
        require(_exists(tokenId), "ERC721: approved query for nonexistent token");

        return _tokenApprovals[tokenId];
    }

    /**
     * @dev See {IERC721-setApprovalForAll}.
     */
    function setApprovalForAll(address operator, bool approved) public virtual override {
        require(operator != _msgSender(), "ERC721: approve to caller");

        _operatorApprovals[_msgSender()][operator] = approved;
        emit ApprovalForAll(_msgSender(), operator, approved);
    }

    /**
     * @dev See {IERC721-isApprovedForAll}.
     */
    function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
        return _operatorApprovals[owner][operator];
    }

    /**
     * @dev See {IERC721-transferFrom}.
     */
    function transferFrom(
        address from,
        address to,
        uint256 tokenId
    ) public virtual override {
        //solhint-disable-next-line max-line-length
        require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");

        _transfer(from, to, tokenId);
    }

    /**
     * @dev See {IERC721-safeTransferFrom}.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId
    ) public virtual override {
        safeTransferFrom(from, to, tokenId, "");
    }

    /**
     * @dev See {IERC721-safeTransferFrom}.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId,
        bytes memory _data
    ) public virtual override {
        require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
        _safeTransfer(from, to, tokenId, _data);
    }

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
     * are aware of the ERC721 protocol to prevent tokens from being forever locked.
     *
     * `_data` is additional data, it has no specified format and it is sent in call to `to`.
     *
     * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
     * implement alternative mechanisms to perform token transfer, such as signature-based.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function _safeTransfer(
        address from,
        address to,
        uint256 tokenId,
        bytes memory _data
    ) internal virtual {
        _transfer(from, to, tokenId);
        require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
    }

    /**
     * @dev Returns whether `tokenId` exists.
     *
     * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
     *
     * Tokens start existing when they are minted (`_mint`),
     * and stop existing when they are burned (`_burn`).
     */
    function _exists(uint256 tokenId) internal view virtual returns (bool) {
        return _owners[tokenId] != address(0);
    }

    /**
     * @dev Returns whether `spender` is allowed to manage `tokenId`.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
        require(_exists(tokenId), "ERC721: operator query for nonexistent token");
        address owner = ERC721.ownerOf(tokenId);
        return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender));
    }

    /**
     * @dev Safely mints `tokenId` and transfers it to `to`.
     *
     * Requirements:
     *
     * - `tokenId` must not exist.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function _safeMint(address to, uint256 tokenId) internal virtual {
        _safeMint(to, tokenId, "");
    }

    /**
     * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
     * forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
     */
    function _safeMint(
        address to,
        uint256 tokenId,
        bytes memory _data
    ) internal virtual {
        _mint(to, tokenId);
        require(
            _checkOnERC721Received(address(0), to, tokenId, _data),
            "ERC721: transfer to non ERC721Receiver implementer"
        );
    }

    /**
     * @dev Mints `tokenId` and transfers it to `to`.
     *
     * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
     *
     * Requirements:
     *
     * - `tokenId` must not exist.
     * - `to` cannot be the zero address.
     *
     * Emits a {Transfer} event.
     */
    function _mint(address to, uint256 tokenId) internal virtual {
        require(to != address(0), "ERC721: mint to the zero address");
        require(!_exists(tokenId), "ERC721: token already minted");

        _beforeTokenTransfer(address(0), to, tokenId);

        _balances[to] += 1;
        _owners[tokenId] = to;

        emit Transfer(address(0), to, tokenId);
    }

    /**
     * @dev Destroys `tokenId`.
     * The approval is cleared when the token is burned.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     *
     * Emits a {Transfer} event.
     */
    function _burn(uint256 tokenId) internal virtual {
        address owner = ERC721.ownerOf(tokenId);

        _beforeTokenTransfer(owner, address(0), tokenId);

        // Clear approvals
        _approve(address(0), tokenId);

        _balances[owner] -= 1;
        delete _owners[tokenId];

        emit Transfer(owner, address(0), tokenId);
    }

    /**
     * @dev Transfers `tokenId` from `from` to `to`.
     *  As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     *
     * Emits a {Transfer} event.
     */
    function _transfer(
        address from,
        address to,
        uint256 tokenId
    ) internal virtual {
        require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own");
        require(to != address(0), "ERC721: transfer to the zero address");

        _beforeTokenTransfer(from, to, tokenId);

        // Clear approvals from the previous owner
        _approve(address(0), tokenId);

        _balances[from] -= 1;
        _balances[to] += 1;
        _owners[tokenId] = to;

        emit Transfer(from, to, tokenId);
    }

    /**
     * @dev Approve `to` to operate on `tokenId`
     *
     * Emits a {Approval} event.
     */
    function _approve(address to, uint256 tokenId) internal virtual {
        _tokenApprovals[tokenId] = to;
        emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
    }

    /**
     * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
     * The call is not executed if the target address is not a contract.
     *
     * @param from address representing the previous owner of the given token ID
     * @param to target address that will receive the tokens
     * @param tokenId uint256 ID of the token to be transferred
     * @param _data bytes optional data to send along with the call
     * @return bool whether the call correctly returned the expected magic value
     */
    function _checkOnERC721Received(
        address from,
        address to,
        uint256 tokenId,
        bytes memory _data
    ) private returns (bool) {
        if (to.isContract()) {
            try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) {
                return retval == IERC721Receiver.onERC721Received.selector;
            } catch (bytes memory reason) {
                if (reason.length == 0) {
                    revert("ERC721: transfer to non ERC721Receiver implementer");
                } else {
                    assembly {
                        revert(add(32, reason), mload(reason))
                    }
                }
            }
        } else {
            return true;
        }
    }

    /**
     * @dev Hook that is called before any token transfer. This includes minting
     * and burning.
     *
     * Calling conditions:
     *
     * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
     * transferred to `to`.
     * - When `from` is zero, `tokenId` will be minted for `to`.
     * - When `to` is zero, ``from``'s `tokenId` will be burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 tokenId
    ) internal virtual {}
}

File 6 of 18: IERC165.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

File 7 of 18: IERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `recipient`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address recipient, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `sender` to `recipient` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address sender,
        address recipient,
        uint256 amount
    ) external returns (bool);

    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);
}

File 8 of 18: IERC721.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "IERC165.sol";

/**
 * @dev Required interface of an ERC721 compliant contract.
 */
interface IERC721 is IERC165 {
    /**
     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
     */
    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
     */
    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
     */
    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);

    /**
     * @dev Returns the number of tokens in ``owner``'s account.
     */
    function balanceOf(address owner) external view returns (uint256 balance);

    /**
     * @dev Returns the owner of the `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function ownerOf(uint256 tokenId) external view returns (address owner);

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
     * are aware of the ERC721 protocol to prevent tokens from being forever locked.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId
    ) external;

    /**
     * @dev Transfers `tokenId` token from `from` to `to`.
     *
     * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address from,
        address to,
        uint256 tokenId
    ) external;

    /**
     * @dev Gives permission to `to` to transfer `tokenId` token to another account.
     * The approval is cleared when the token is transferred.
     *
     * Only a single account can be approved at a time, so approving the zero address clears previous approvals.
     *
     * Requirements:
     *
     * - The caller must own the token or be an approved operator.
     * - `tokenId` must exist.
     *
     * Emits an {Approval} event.
     */
    function approve(address to, uint256 tokenId) external;

    /**
     * @dev Returns the account approved for `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function getApproved(uint256 tokenId) external view returns (address operator);

    /**
     * @dev Approve or remove `operator` as an operator for the caller.
     * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
     *
     * Requirements:
     *
     * - The `operator` cannot be the caller.
     *
     * Emits an {ApprovalForAll} event.
     */
    function setApprovalForAll(address operator, bool _approved) external;

    /**
     * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
     *
     * See {setApprovalForAll}
     */
    function isApprovedForAll(address owner, address operator) external view returns (bool);

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId,
        bytes calldata data
    ) external;
}

File 9 of 18: IERC721Metadata.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "IERC721.sol";

/**
 * @title ERC-721 Non-Fungible Token Standard, optional metadata extension
 * @dev See https://eips.ethereum.org/EIPS/eip-721
 */
interface IERC721Metadata is IERC721 {
    /**
     * @dev Returns the token collection name.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the token collection symbol.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
     */
    function tokenURI(uint256 tokenId) external view returns (string memory);
}

File 10 of 18: IERC721Receiver.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @title ERC721 token receiver interface
 * @dev Interface for any contract that wants to support safeTransfers
 * from ERC721 asset contracts.
 */
interface IERC721Receiver {
    /**
     * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
     * by `operator` from `from`, this function is called.
     *
     * It must return its Solidity selector to confirm the token transfer.
     * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
     *
     * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.
     */
    function onERC721Received(
        address operator,
        address from,
        uint256 tokenId,
        bytes calldata data
    ) external returns (bytes4);
}

File 11 of 18: Ownable.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _setOwner(_msgSender());
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
        _;
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _setOwner(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    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);
    }
}

File 12 of 18: SafeMath.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.

/**
 * @dev Wrappers over Solidity's arithmetic operations.
 *
 * NOTE: `SafeMath` is no longer needed starting with Solidity 0.8. The compiler
 * now has built in overflow checking.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the substraction of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b > a) return (false, 0);
            return (true, a - b);
        }
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
            // benefit is lost if 'b' is also tested.
            // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
            if (a == 0) return (true, 0);
            uint256 c = a * b;
            if (c / a != b) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the division of two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a / b);
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a % b);
        }
    }

    /**
     * @dev Returns the addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     *
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        return a + b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        return a - b;
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     *
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        return a * b;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator.
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b) internal pure returns (uint256) {
        return a % b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {trySub}.
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        unchecked {
            require(b <= a, errorMessage);
            return a - b;
        }
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting with custom message on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        unchecked {
            require(b > 0, errorMessage);
            return a / b;
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting with custom message when dividing by zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryMod}.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        unchecked {
            require(b > 0, errorMessage);
            return a % b;
        }
    }
}

File 13 of 18: SignedSafeMath.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Wrappers over Solidity's arithmetic operations.
 *
 * NOTE: `SignedSafeMath` is no longer needed starting with Solidity 0.8. The compiler
 * now has built in overflow checking.
 */
library SignedSafeMath {
    /**
     * @dev Returns the multiplication of two signed integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     *
     * - Multiplication cannot overflow.
     */
    function mul(int256 a, int256 b) internal pure returns (int256) {
        return a * b;
    }

    /**
     * @dev Returns the integer division of two signed integers. Reverts on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator.
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(int256 a, int256 b) internal pure returns (int256) {
        return a / b;
    }

    /**
     * @dev Returns the subtraction of two signed integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(int256 a, int256 b) internal pure returns (int256) {
        return a - b;
    }

    /**
     * @dev Returns the addition of two signed integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     *
     * - Addition cannot overflow.
     */
    function add(int256 a, int256 b) internal pure returns (int256) {
        return a + b;
    }
}

File 14 of 18: Strings.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        // Inspired by OraclizeAPI's implementation - MIT licence
        // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol

        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);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    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);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed 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);
    }
}

File 15 of 18: thewall.sol
/*
This file is part of the TheWall project.

The TheWall Contract is free software: you can redistribute it and/or
modify it under the terms of the GNU lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

The TheWall Contract is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU lesser General Public License for more details.

You should have received a copy of the GNU lesser General Public License
along with the TheWall Contract. If not, see <http://www.gnu.org/licenses/>.

@author Ilya Svirin <[email protected]>
*/
// SPDX-License-Identifier: GNU lesser General Public License

pragma solidity ^0.8.0;

import "ERC721.sol";
import "Ownable.sol";
import "SafeMath.sol";
import "thewallcore.sol";


contract TheWall is ERC721, Ownable, IERC721Receiver
{
    using SafeMath for uint256;

    event Payment(address indexed sender, uint256 amountWei);

    event AreaCreated(uint256 indexed tokenId, address indexed owner, int256 x, int256 y, uint256 nonce, bytes32 hashOfSecret, bytes content);
    event ClusterCreated(uint256 indexed tokenId, address indexed owner, bytes content);
    event ClusterRemoved(uint256 indexed tokenId);

    event AreaAddedToCluster(uint256 indexed areaTokenId, uint256 indexed clusterTokenId, uint256 revision);
    event AreaRemovedFromCluster(uint256 indexed areaTokenId, uint256 indexed clusterTokenId, uint256 revision);

    event AreaImageChanged(uint256 indexed tokenId, bytes image);
    event ItemLinkChanged(uint256 indexed tokenId, string link);
    event ItemTagsChanged(uint256 indexed tokenId, string tags);
    event ItemTitleChanged(uint256 indexed tokenId, string title);
    event ItemContentChanged(uint256 indexed tokenId, bytes content);

    event ItemTransferred(uint256 indexed tokenId, address indexed from, address indexed to);
    event ItemForRent(uint256 indexed tokenId, uint256 priceWei, uint256 durationSeconds);
    event ItemForSale(uint256 indexed tokenId, uint256 priceWei);
    event ItemRented(uint256 indexed tokenId, address indexed tenant, uint256 finishTime);
    event ItemBought(uint256 indexed tokenId, address indexed buyer);
    event ItemReset(uint256 indexed tokenId);
    event ItemRentFinished(uint256 indexed tokenId);
    
    event ReceivedExternalNFT(uint256 indexed externalTokenId, address indexed contractAddress, address indexed owner, string tokenURI);
    event WithdrawExternalNFT(uint256 indexed externalTokenId, address indexed contractAddress, address indexed to);
    event AttachedExternalNFT(uint256 indexed externalTokenId, address indexed contractAddress, uint256 areaId);
    event DetachedExternalNFT(uint256 indexed externalTokenId, address indexed contractAddress);

    TheWallCore private _core;
    uint256     private _minterCounter;
    uint256     private _externalTokensCounter;
    string      private _base;

    struct ExternalToken
    {
        address contractAddress;
        uint256 externalTokenId;
        address owner;
        uint256 attachedAreaId;
    }

    // internalId => ExternalToken
    mapping (uint256 => ExternalToken) private _externalTokens;

    // contractAddress => externalTokenId => internalId
    mapping (address => mapping (uint256 => uint256)) private _externalTokensId;
    
    // area => internalId
    mapping (uint256 => uint256) private _attachedExternalTokens;

    constructor(address core) ERC721("TheWall", "TWG")
    {
        _core = TheWallCore(core);
        _core.setTheWall(address(this));
        setBaseURI("https://thewall.global/erc721/");
    }

    function setBaseURI(string memory baseURI) public onlyOwner
    {
        _base = baseURI;
    }
    
    function _baseURI() internal view override returns (string memory)
    {
        return _base;
    }
    
    function safeTransferFrom(address from, address to, uint256 tokenId) public override
    {
        safeTransferFrom(from, to, tokenId, "");
    }

    function transferFrom(address from, address to, uint256 tokenId) public override
    {
        require(_isApprovedOrOwner(_msgSender(), tokenId));
        _core._canBeTransferred(tokenId);
        _transfer(from, to, tokenId);
        emit ItemTransferred(tokenId, from, to);
    }

    function safeTransferFromKeepingControl(address from, address to, uint256 tokenId) public onlyOwner
    {
        safeTransferFrom(from, to, tokenId);
        _approve(from, tokenId);
    }

    function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public override
    {
        require(_isApprovedOrOwner(_msgSender(), tokenId));
        _core._canBeTransferred(tokenId);
        _safeTransfer(from, to, tokenId, data);
        emit ItemTransferred(tokenId, from, to);
    }

    function forSale(uint256 tokenId, uint256 priceWei) public
    {
        require(_isApprovedOrOwner(_msgSender(), tokenId));
        _core._forSale(tokenId, priceWei);
        emit ItemForSale(tokenId, priceWei);
    }

    function forRent(uint256 tokenId, uint256 priceWei, uint256 durationSeconds) public
    {
        require(_isApprovedOrOwner(_msgSender(), tokenId));
        _core._forRent(tokenId, priceWei, durationSeconds);
        emit ItemForRent(tokenId, priceWei, durationSeconds);
    }

    function createCluster(bytes memory content) public returns (uint256)
    {
        address me = _msgSender();

        _minterCounter = _minterCounter.add(1);
        uint256 tokenId = _minterCounter;
        _safeMint(me, tokenId);
        _core._createCluster(tokenId, content);

        emit ClusterCreated(tokenId, me, content);
        return tokenId;
    }

    function removeCluster(uint256 tokenId) public
    {
        require(_isApprovedOrOwner(_msgSender(), tokenId));
        uint256[] memory tokens = _core._areasInCluster(tokenId);
        address clusterOwner = ownerOf(tokenId);
        for(uint i = 0; i < tokens.length; ++i)
        {
            address oldOwner = ownerOf(tokens[i]);
            if (oldOwner != clusterOwner)
            {
                uint256 token = tokens[i];
                _safeTransfer(oldOwner, clusterOwner, token, "");
            }
        }
        _core._removeCluster(tokenId);
        _burn(tokenId);
        emit ClusterRemoved(tokenId);
    }
    
    function _create(address owner, int256 x, int256 y, uint256 clusterId, uint256 nonce, bytes memory content) internal returns (uint256)
    {
        _minterCounter = _minterCounter.add(1);
        uint256 tokenId = _minterCounter;
        _safeMint(owner, tokenId);
        
        uint256 revision;
        bytes32 hashOfSecret;
        (revision, hashOfSecret) = _core._create(tokenId, x, y, clusterId, nonce, content);
        
        emit AreaCreated(tokenId, owner, x, y, nonce, hashOfSecret, content);
        if (clusterId != 0)
        {
            emit AreaAddedToCluster(tokenId, clusterId, revision);
        }
        
        return tokenId;
    }

    function create(int256 x, int256 y, uint256 clusterId, address payable referrerCandidate, uint256 nonce, bytes memory content) public payable returns (uint256)
    {
        address me = _msgSender();
        _core._canBeCreated(x, y);
        uint256 area = _create(me, x, y, clusterId, nonce, content);
        
        uint256 payValue = _core._processPaymentCreate{value: msg.value}(me, msg.value, 1, referrerCandidate);
        if (payValue > 0)
        {
            emit Payment(me, payValue);
        }

        return area;
    }

    function createMulti(int256 x, int256 y, int256 width, int256 height, address payable referrerCandidate, uint256 nonce) public payable returns (uint256)
    {
        bytes memory emptyContent;
        uint256 cluster =  createCluster(emptyContent);
        _createMulti(x, y, width, height, cluster, referrerCandidate, nonce);
        return cluster;
    }

    function createMultiNoCluster(int256 x, int256 y, int256 width, int256 height, address payable referrerCandidate, uint256 nonce) public payable
    {
        _createMulti(x, y, width, height, 0, referrerCandidate, nonce);
    }

    function _createMulti(int256 x, int256 y, int256 width, int256 height, uint256 cluster, address payable referrerCandidate, uint256 nonce) internal
    {
        address me = _msgSender();
        _core._canBeCreatedMulti(x, y, width, height);

        uint256 areasNum = 0;
        int256 i;
        int256 j;
        bytes memory emptyContent;
        for(i = 0; i < width; ++i)
        {
            for(j = 0; j < height; ++j)
            {
                if (_core._areaOnTheWall(x + i, y + j) == uint256(0))
                {
                    areasNum = areasNum.add(1);
                    _create(me, x + i, y + j, cluster, nonce, emptyContent);
                }
            }
        }

        uint256 payValue = _core._processPaymentCreate{value: msg.value}(me, msg.value, areasNum, referrerCandidate);
        if (payValue > 0)
        {
            emit Payment(me, payValue);
        }
    }

    function buy(uint256 tokenId, uint256 revision, address payable referrerCandidate) payable public
    {
        address me = _msgSender();
        address payable tokenOwner = payable(actualOwnerOf(tokenId));
        _core._buy{value: msg.value}(tokenOwner, tokenId, me, msg.value, revision, referrerCandidate);
        emit Payment(me, msg.value);
        _safeTransfer(tokenOwner, me, tokenId, "");
        emit ItemBought(tokenId, me);
        emit ItemTransferred(tokenId, tokenOwner, me);
        emit ItemReset(tokenId);
    }

    function rent(uint256 tokenId, uint256 revision, address payable referrerCandidate) payable public
    {
        address me = _msgSender();
        address payable tokenOwner = payable(actualOwnerOf(tokenId));
        uint256 rentDuration;
        rentDuration = _core._rent{value: msg.value}(tokenOwner, tokenId, me, msg.value, revision, referrerCandidate);
        emit Payment(me, msg.value);
        emit ItemRented(tokenId, me, rentDuration);
    }
    
    function rentTo(uint256 tokenId, address tenant, uint256 durationSeconds) public
    {
        require(_isApprovedOrOwner(_msgSender(), tokenId));
        uint256 rentDuration;
        rentDuration = _core._rentTo(tokenId, tenant, durationSeconds);
        emit ItemRented(tokenId, tenant, rentDuration);
    }
    
    function cancel(uint256 tokenId) public
    {
        require(_isApprovedOrOwner(_msgSender(), tokenId));
        _core._cancel(tokenId);
        emit ItemReset(tokenId);
    }
    
    function finishRent(uint256 tokenId) public
    {
        _core._finishRent(_msgSender(), tokenId);
        emit ItemRentFinished(tokenId);
    }
    
    function addToCluster(uint256 areaId, uint256 clusterId) public
    {
        uint256 revision = _core._addToCluster(_msgSender(), actualOwnerOf(areaId), ownerOf(clusterId), areaId, clusterId);
        emit AreaAddedToCluster(areaId, clusterId, revision);
    }

    function removeFromCluster(uint256 areaId, uint256 clusterId) public
    {
        address me = _msgSender();
        uint256 revision = _core._removeFromCluster(me, actualOwnerOf(areaId), ownerOf(clusterId), areaId, clusterId);
        if (ownerOf(areaId) != me)
        {
            _safeTransfer(ownerOf(areaId), me, areaId, "");
        }
        emit AreaRemovedFromCluster(areaId, clusterId, revision);
    }

    function setAttributesComplete(uint256 tokenId, bytes memory image, string memory link, string memory tags, string memory title) public
    {
        _core._setAttributesComplete(_msgSender(), actualOwnerOf(tokenId), tokenId, image, link, tags, title);
        emit AreaImageChanged(tokenId, image);
        emit ItemLinkChanged(tokenId, link);
        emit ItemTagsChanged(tokenId, tags);
        emit ItemTitleChanged(tokenId, title);
    }

    function setAttributes(uint256 tokenId, string memory link, string memory tags, string memory title) public
    {
        _core._setAttributes(_msgSender(), actualOwnerOf(tokenId), tokenId, link, tags, title);
        emit ItemLinkChanged(tokenId, link);
        emit ItemTagsChanged(tokenId, tags);
        emit ItemTitleChanged(tokenId, title);
    }

    function setImage(uint256 tokenId, bytes memory image) public
    {
        _core._setImage(_msgSender(), actualOwnerOf(tokenId), tokenId, image);
        emit AreaImageChanged(tokenId, image);
    }

    function setLink(uint256 tokenId, string memory link) public
    {
        _core._setLink(_msgSender(), actualOwnerOf(tokenId), tokenId, link);
        emit ItemLinkChanged(tokenId, link);
    }

    function setTags(uint256 tokenId, string memory tags) public
    {
        _core._setTags(_msgSender(), actualOwnerOf(tokenId), tokenId, tags);
        emit ItemTagsChanged(tokenId, tags);
    }

    function setTitle(uint256 tokenId, string memory title) public
    {
        _core._setTitle(_msgSender(), actualOwnerOf(tokenId), tokenId, title);
        emit ItemTitleChanged(tokenId, title);
    }

    function setContent(uint256 tokenId, bytes memory content) public
    {
        _core._setContent(_msgSender(), actualOwnerOf(tokenId), tokenId, content);
        emit ItemContentChanged(tokenId, content);
    }

    function setContentMulti(uint256[] memory tokens, bytes[] memory contents) public
    {
        require(tokens.length == contents.length, "TheWall: length must be equal");
        for(uint i = 0; i < tokens.length; ++i)
        {
            uint256 tokenId = tokens[i];
            bytes memory content = contents[i];
            _core._setContent(_msgSender(), actualOwnerOf(tokenId), tokenId, content);
            emit ItemContentChanged(tokenId, content);
        }
    }
    
    function buyCoupons(address payable referrerCandidate) payable public
    {
        address me = _msgSender();
        uint256 payValue = _core._buyCoupons{value: msg.value}(me, msg.value, referrerCandidate);
        if (payValue > 0)
        {
            emit Payment(me, payValue);
        }
    }
    
    receive () payable external
    {
        buyCoupons(payable(address(0)));
    }
    
    function actualOwnerOf(uint256 tokenId) public view returns (address)
    {
        uint256 clusterId = _core._clusterOf(tokenId);
        if (clusterId != 0)
        {
            tokenId = clusterId;
        }
        return ownerOf(tokenId);
    }
    
    function onERC721Received(address operator, address /*from*/, uint256 tokenId, bytes calldata /*data*/) public override returns (bytes4)
    {
        ExternalToken memory nft;
        nft.contractAddress = _msgSender();
        nft.owner = operator;
        nft.externalTokenId = tokenId;
        nft.attachedAreaId = 0;
        
        require(_externalTokensId[nft.contractAddress][tokenId] == 0, "TheWall: External NFT already exists");

        _externalTokensCounter = _externalTokensCounter.add(1);
        uint256 internalId = _externalTokensCounter;
        _externalTokens[internalId] = nft;
        _externalTokensId[nft.contractAddress][tokenId] = internalId;

        string memory uri = "";
        if (IERC165(nft.contractAddress).supportsInterface(type(IERC721Metadata).interfaceId))
        {
            uri = IERC721Metadata(nft.contractAddress).tokenURI(tokenId);
        }
        emit ReceivedExternalNFT(tokenId, nft.contractAddress, nft.owner, uri);
        return this.onERC721Received.selector;
    }
    
    function withdrawExternalNFT(uint256 externalTokenId, address contractAddress, address to) public
    {
        uint256 internalId = _externalTokensId[contractAddress][externalTokenId];
        require(internalId != 0, "TheWall: No external token found");
        ExternalToken storage nft = _externalTokens[internalId];
        if (nft.attachedAreaId != 0)
        {
            _core._isOrdinaryArea(nft.attachedAreaId);
            require(actualOwnerOf(nft.attachedAreaId) == _msgSender(), "TheWall: Permission denied");
            delete _attachedExternalTokens[nft.attachedAreaId];
        }
        else
        {
            require(nft.owner == _msgSender(), "TheWall: Permission denied");
        }
        delete _externalTokens[internalId];
        delete _externalTokensId[contractAddress][externalTokenId];
        IERC721(contractAddress).safeTransferFrom(address(this), to, externalTokenId);
        emit WithdrawExternalNFT(externalTokenId, contractAddress, to);
    }
    
    function ownerWithdrawExternalNFT(uint256 externalTokenId, address contractAddress, address to) public onlyOwner
    {
        uint256 internalId = _externalTokensId[contractAddress][externalTokenId];
        require(internalId == 0 || _externalTokens[internalId].owner == address(this), "TheWall: External token has owner");
        IERC721(contractAddress).safeTransferFrom(address(this), to, externalTokenId);
    }

    function attachExternalNFT(uint256 externalTokenId, address contractAddress, uint256 areaId) public
    {
        _core._isOrdinaryArea(areaId);
        uint256 internalId = _attachedExternalTokens[areaId];
        if (internalId != 0)
        {
            ExternalToken storage pnft = _externalTokens[internalId];
            pnft.owner = actualOwnerOf(pnft.attachedAreaId);
            delete pnft.attachedAreaId;
            emit DetachedExternalNFT(pnft.externalTokenId, pnft.contractAddress);
        }
        internalId = _externalTokensId[contractAddress][externalTokenId];
        require(internalId != 0, "TheWall: No external token found");
        ExternalToken storage nft = _externalTokens[internalId];
        require(nft.attachedAreaId == 0, "TheWall: Already attached");
        require(nft.owner == _msgSender(), "TheWall: Permission denied");
        require(actualOwnerOf(areaId) == _msgSender(), "TheWall: Not owner of area");
        _attachedExternalTokens[areaId] = internalId;
        nft.attachedAreaId = areaId;
        emit AttachedExternalNFT(externalTokenId, contractAddress, areaId);
    }

    function detachExternalNFT(uint256 externalTokenId, address contractAddress) public
    {
        uint256 internalId = _externalTokensId[contractAddress][externalTokenId];
        require(internalId != 0, "TheWall: No external token found");
        ExternalToken storage nft = _externalTokens[internalId];
        require(nft.attachedAreaId != 0, "TheWall: No attached area");
        nft.owner = actualOwnerOf(nft.attachedAreaId);
        require(nft.owner == _msgSender(), "TheWall: Permission denied");
        _core._isOrdinaryArea(nft.attachedAreaId);
        delete _attachedExternalTokens[nft.attachedAreaId];
        delete nft.attachedAreaId;
        emit DetachedExternalNFT(externalTokenId, contractAddress);
    }
}

File 16 of 18: thewallcore.sol
/*
This file is part of the TheWall project.

The TheWall Contract is free software: you can redistribute it and/or
modify it under the terms of the GNU lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

The TheWall Contract is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU lesser General Public License for more details.

You should have received a copy of the GNU lesser General Public License
along with the TheWall Contract. If not, see <http://www.gnu.org/licenses/>.

@author Ilya Svirin <[email protected]>
*/
// SPDX-License-Identifier: GNU lesser General Public License

pragma solidity ^0.8.0;

import "SafeMath.sol";
import "SignedSafeMath.sol";
import "Address.sol";
import "Strings.sol";
import "thewallusers.sol";


contract TheWallCore is TheWallUsers
{
    using SafeMath for uint256;
    using SignedSafeMath for int256;
    using Address for address;
    using Address for address payable;
    using Strings for uint256;

    event SizeChanged(int256 wallWidth, int256 wallHeight);
    event AreaCostChanged(uint256 costWei);
    event FeeChanged(uint256 feePercents);
    event FundsReceiverChanged(address fundsReceiver);
    event SecretCommited(uint256 secret, bytes32 hashOfSecret);
    event SecretUpdated(bytes32 hashOfNewSecret);

    enum Status
    {
        None,
        ForSale,
        ForRent,
        Rented
    }

    enum TokenType
    {
        Unknown,
        Area,
        Cluster
    }

    struct Token
    {
        TokenType  tt;
        Status     status;
        string     link;
        string     tags;
        string     title;
        uint256    cost;
        uint256    rentDuration;
        address    tenant;
        bytes      content;
    }
    
    struct Area
    {
        int256     x;
        int256     y;
        bool       premium;
        uint256    cluster;
        bytes      image;
        bytes32    hashOfSecret;
        uint256    nonce;
    }

    struct Cluster
    {
        uint256[]  areas;
        mapping (uint256 => uint256) areaToIndex;
        uint256    revision;
    }

    // x => y => area erc-721
    mapping (int256 => mapping (int256 => uint256)) private _areasOnTheWall;

    // erc-721 => Token, Area or Cluster
    mapping (uint256 => Token) private _tokens;
    mapping (uint256 => Area) private _areas;
    mapping (uint256 => Cluster) private _clusters;

    mapping (bytes32 => uint256) private _secrets;
    bytes32 private _hashOfSecret;
    bytes32 private _hashOfSecretToCommit;

    int256  public  _wallWidth;
    int256  public  _wallHeight;
    uint256 public  _costWei;
    uint256 public  _feePercents;
    address payable private _fundsReceiver;
    address private _thewall;

    constructor (address coupons) TheWallUsers(coupons)
    {
        _wallWidth = 500;
        _wallHeight = 500;
        _costWei = 1 ether / 10;
        _feePercents = 30;
        _fundsReceiver = payable(_msgSender());
        emit SizeChanged(_wallWidth, _wallHeight);
        emit AreaCostChanged(_costWei);
        emit FeeChanged(_feePercents);
        emit FundsReceiverChanged(_fundsReceiver);
    }

    function setTheWall(address thewall) public
    {
        require(thewall != address(0) && _thewall == address(0));
        _thewall = thewall;
    }

    modifier onlyTheWall()
    {
        require(_msgSender() == _thewall);
        _;
    }
    
    function setWallSize(int256 wallWidth, int256 wallHeight) public onlyOwner
    {
        require(_wallWidth <= wallWidth && _wallHeight <= wallHeight);
        _wallWidth = wallWidth;
        _wallHeight = wallHeight;
        emit SizeChanged(wallWidth, wallHeight);
    }

    function setCostWei(uint256 costWei) public onlyOwner
    {
        _costWei = costWei;
        emit AreaCostChanged(costWei);
    }

    function setFee(uint256 feePercents) public onlyOwner
    {
        _feePercents = feePercents;
        emit FeeChanged(feePercents);
    }

    function setFundsReceiver(address payable fundsReceiver) public onlyOwner
    {
        require(fundsReceiver != address(0));
        _fundsReceiver = fundsReceiver;
        emit FundsReceiverChanged(fundsReceiver);
    }

    function commitSecret(uint256 secret) public onlyOwner
    {
        require(_hashOfSecretToCommit == keccak256(abi.encodePacked(secret)));
        _secrets[_hashOfSecretToCommit] = secret;
        emit SecretCommited(secret, _hashOfSecretToCommit);
        delete _hashOfSecretToCommit;
    }

    function updateSecret(bytes32 hashOfNewSecret) public onlyOwner
    {
        _hashOfSecretToCommit = _hashOfSecret;
        _hashOfSecret = hashOfNewSecret;
        emit SecretUpdated(hashOfNewSecret);
    }

    function _canBeTransferred(uint256 tokenId) public view returns(TokenType)
    {
        Token storage token = _tokens[tokenId];
        require(token.tt != TokenType.Unknown, "TheWallCore: No such token found");
        require(token.status != Status.Rented || token.rentDuration < block.timestamp, "TheWallCore: Can't transfer rented item");
        if (token.tt == TokenType.Area)
        {
            Area memory area = _areas[tokenId];
            require(area.cluster == uint256(0), "TheWallCore: Can't transfer area owned by cluster");
        }
        else
        {
            Cluster storage cluster = _clusters[tokenId];
            require(cluster.areas.length > 0, "TheWallCore: Can't transfer empty cluster");
        }
        return token.tt;
    }

    function _isOrdinaryArea(uint256 areaId) public view
    {
        Token storage token = _tokens[areaId];
        require(token.tt == TokenType.Area, "TheWallCore: Token is not area");
        require(token.status != Status.Rented || token.rentDuration < block.timestamp, "TheWallCore: Unordinary status");
        Area memory area = _areas[areaId];
        require(area.cluster == uint256(0), "TheWallCore: Area is owned by cluster");
    }

    function _areasInCluster(uint256 clusterId) public view returns(uint256[] memory)
    {
        return _clusters[clusterId].areas;
    }

    function _forSale(uint256 tokenId, uint256 priceWei) onlyTheWall public
    {
        _canBeTransferred(tokenId);
        Token storage token = _tokens[tokenId];
        token.cost = priceWei;
        token.status = Status.ForSale;
    }

    function _forRent(uint256 tokenId, uint256 priceWei, uint256 durationSeconds) onlyTheWall public
    {
        _canBeTransferred(tokenId);
        Token storage token = _tokens[tokenId];
        token.cost = priceWei;
        token.status = Status.ForRent;
        token.rentDuration = durationSeconds;
    }

    function _createCluster(uint256 tokenId, bytes memory content) onlyTheWall public
    {
        Token storage token = _tokens[tokenId];
        token.tt = TokenType.Cluster;
        token.status = Status.None;
        token.content = content;

        Cluster storage cluster = _clusters[tokenId];
        cluster.revision = 1;
    }

    function _removeCluster(uint256 tokenId) onlyTheWall public
    {
        Token storage token = _tokens[tokenId];
        require(token.tt == TokenType.Cluster, "TheWallCore: no cluster found for remove");
        require(token.status != Status.Rented || token.rentDuration < block.timestamp, "TheWallCore: can't remove rented cluster");

        Cluster storage cluster = _clusters[tokenId];
        for(uint i=0; i<cluster.areas.length; ++i)
        {
            uint256 areaId = cluster.areas[i];
            
            Token storage areaToken = _tokens[areaId];
            areaToken.status = token.status;
            areaToken.link = token.link;
            areaToken.tags = token.tags;
            areaToken.title = token.title;

            Area storage area = _areas[areaId];
            area.cluster = 0;
        }
        delete _clusters[tokenId];
        delete _tokens[tokenId];
    }
    
    function _abs(int256 v) pure public returns (int256)
    {
        if (v < 0)
        {
            v = -v;
        }
        return v;
    }

    function _create(uint256 tokenId, int256 x, int256 y, uint256 clusterId, uint256 nonce, bytes memory content) onlyTheWall public returns (uint256 revision, bytes32 hashOfSecret)
    {
        _areasOnTheWall[x][y] = tokenId;

        Token storage token = _tokens[tokenId];
        token.tt = TokenType.Area;
        token.status = Status.None;
        token.content = content;

        Area storage area = _areas[tokenId];
        area.x = x;
        area.y = y;
        if (_abs(x) <= 100 && _abs(y) <= 100)
        {
            area.premium = true;
        }
        else
        {
            area.nonce = nonce;
            area.hashOfSecret = _hashOfSecret;
        }

        revision = 0;
        if (clusterId !=0)
        {
            area.cluster = clusterId;
        
            Cluster storage cluster = _clusters[clusterId];
            cluster.revision += 1;
            revision = cluster.revision;
            cluster.areas.push(tokenId);
            cluster.areaToIndex[tokenId] = cluster.areas.length - 1;
        }
        
        return (revision, area.hashOfSecret);
    }

    function _areaOnTheWall(int256 x, int256 y) public view returns(uint256)
    {
        return _areasOnTheWall[x][y];
    }

    function _buy(address payable tokenOwner, uint256 tokenId, address me, uint256 weiAmount, uint256 revision, address payable referrerCandidate) payable onlyTheWall public
    {
        Token storage token = _tokens[tokenId];
        require(token.tt != TokenType.Unknown, "TheWallCore: No token found");
        require(token.status == Status.ForSale, "TheWallCore: Item is not for sale");
        require(weiAmount == token.cost, string(abi.encodePacked("TheWallCore: Invalid amount of wei ", weiAmount.toString(), "/", token.cost.toString())));

        bool premium = false;
        if (token.tt == TokenType.Area)
        {
            Area storage area = _areas[tokenId];
            require(area.cluster == 0, "TheWallCore: Owned by cluster area can't be sold");
            premium = _isPremium(area, tokenId);
        }
        else
        {
            require(_clusters[tokenId].revision == revision, "TheWallCore: Incorrect cluster's revision");
        }
        
        token.status = Status.None;

        uint256 fee;
        if (!premium)
        {
            fee = msg.value.mul(_feePercents).div(100);
            uint256 alreadyPayed = _processRef(me, referrerCandidate, fee);
            _fundsReceiver.sendValue(fee.sub(alreadyPayed));
        }
        tokenOwner.sendValue(msg.value.sub(fee));
    }
    
    function _rent(address payable tokenOwner, uint256 tokenId, address me, uint256 weiAmount, uint256 revision, address payable referrerCandidate) payable onlyTheWall public returns(uint256 rentDuration)
    {
        Token storage token = _tokens[tokenId];
        require(token.tt != TokenType.Unknown, "TheWallCore: No token found");
        require(token.status == Status.ForRent, "TheWallCore: Item is not for rent");
        require(weiAmount == token.cost, string(abi.encodePacked("TheWallCore: Invalid amount of wei ", weiAmount.toString(), "/", token.cost.toString())));

        bool premium = false;
        if (token.tt == TokenType.Area)
        {
            Area storage area = _areas[tokenId];
            require(area.cluster == 0, "TheWallCore: Owned by cluster area can't be rented");
            premium = _isPremium(area, tokenId);
        }
        else
        {
            require(_clusters[tokenId].revision == revision, "TheWall: Incorrect cluster's revision");
        }

        rentDuration = block.timestamp.add(token.rentDuration);
        token.status = Status.Rented;
        token.cost = 0;
        token.rentDuration = rentDuration;
        token.tenant = me;
        
        uint256 fee;
        if (!premium)
        {
            fee = msg.value.mul(_feePercents).div(100);
            uint256 alreadyPayed = _processRef(me, referrerCandidate, fee);
            _fundsReceiver.sendValue(fee.sub(alreadyPayed));
        }
        tokenOwner.sendValue(msg.value.sub(fee));

        return rentDuration;
    }

    function _isPremium(Area storage area, uint256 tokenId) internal returns(bool)
    {
        if (area.hashOfSecret != bytes32(0))
        {
            uint256 secret = _secrets[area.hashOfSecret];
            if (secret != 0)
            {
                uint256 factor = uint256(keccak256(abi.encodePacked(secret, tokenId, area.nonce)));
                area.premium = ((factor % 1000) == 1);
                area.hashOfSecret = bytes32(0);
            }
        }
        return area.premium;
    }

    function _rentTo(uint256 tokenId, address tenant, uint256 durationSeconds) onlyTheWall public returns(uint256 rentDuration)
    {
        _canBeTransferred(tokenId);
        rentDuration = block.timestamp.add(durationSeconds);
        Token storage token = _tokens[tokenId];
        token.status = Status.Rented;
        token.cost = 0;
        token.rentDuration = rentDuration;
        token.tenant = tenant;
        return rentDuration;
    }

    function _cancel(uint256 tokenId) onlyTheWall public
    {
        Token storage token = _tokens[tokenId];
        require(token.tt != TokenType.Unknown, "TheWallCore: No token found");
        require(token.status == Status.ForRent || token.status == Status.ForSale, "TheWallCore: item is not for rent or for sale");
        token.cost = 0;
        token.status = Status.None;
        token.rentDuration = 0;
    }
    
    function _finishRent(address who, uint256 tokenId) onlyTheWall public
    {
        Token storage token = _tokens[tokenId];
        require(token.tt != TokenType.Unknown, "TheWallCore: No token found");
        require(token.tenant == who, "TheWall: Only tenant can finish rent");
        require(token.status == Status.Rented && token.rentDuration > block.timestamp, "TheWallCore: item is not rented");
        token.status = Status.None;
        token.rentDuration = 0;
        token.cost = 0;
        token.tenant = address(0);
    }
    
    function _addToCluster(address me, address areaOwner, address clusterOwner, uint256 areaId, uint256 clusterId) onlyTheWall public returns(uint256 revision)
    {
        require(areaOwner == clusterOwner, "TheWallCore: Area and Cluster have different owners");
        require(areaOwner == me, "TheWallCore: Can be called from owner only");

        Token storage areaToken = _tokens[areaId];
        Token storage clusterToken = _tokens[clusterId];
        require(areaToken.tt == TokenType.Area, "TheWallCore: Area not found");
        require(clusterToken.tt == TokenType.Cluster, "TheWallCore: Cluster not found");
        require(areaToken.status != Status.Rented || areaToken.rentDuration < block.timestamp, "TheWallCore: Area is rented");
        require(clusterToken.status != Status.Rented || clusterToken.rentDuration < block.timestamp, "TheWallCore: Cluster is rented");

        Area storage area = _areas[areaId];
        require(area.cluster == 0, "TheWallCore: Area already in cluster");
        area.cluster = clusterId;
        
        areaToken.status = Status.None;
        areaToken.rentDuration = 0;
        areaToken.cost = 0;
        
        Cluster storage cluster = _clusters[clusterId];
        cluster.revision += 1;
        cluster.areas.push(areaId);
        cluster.areaToIndex[areaId] = cluster.areas.length - 1;
        return cluster.revision;
    }

    function _removeFromCluster(address me, address areaOwner, address clusterOwner, uint256 areaId, uint256 clusterId) onlyTheWall public returns(uint256 revision)
    {
        require(areaOwner == clusterOwner, "TheWallCore: Area and Cluster have different owners");
        require(areaOwner == me, "TheWallCore: Can be called from owner only");

        Token storage areaToken = _tokens[areaId];
        Token storage clusterToken = _tokens[clusterId];
        require(areaToken.tt == TokenType.Area, "TheWallCore: Area not found");
        require(clusterToken.tt == TokenType.Cluster, "TheWallCore: Cluster not found");
        require(clusterToken.status != Status.Rented || clusterToken.rentDuration < block.timestamp, "TheWallCore: Cluster is rented");

        Area storage area = _areas[areaId];
        require(area.cluster == clusterId, "TheWallCore: Area is not in cluster");
        area.cluster = 0;

        Cluster storage cluster = _clusters[clusterId];
        cluster.revision += 1;
        uint index = cluster.areaToIndex[areaId];
        if (index != cluster.areas.length - 1)
        {
            uint256 movedAreaId = cluster.areas[cluster.areas.length - 1];
            cluster.areaToIndex[movedAreaId] = index;
            cluster.areas[index] = movedAreaId;
        }
        delete cluster.areaToIndex[areaId];
        cluster.areas.pop();
        return cluster.revision;
    }

    function _canBeManaged(address who, address owner, uint256 tokenId) internal view returns (TokenType t)
    {
        Token storage token = _tokens[tokenId];
        t = token.tt;
        require(t != TokenType.Unknown, "TheWallCore: No token found");
        if (t == TokenType.Area)
        {
            Area storage area = _areas[tokenId];
            if (area.cluster != uint256(0))
            {
                token = _tokens[area.cluster];
                require(token.tt == TokenType.Cluster, "TheWallCore: No cluster token found");
            }
        }
        
        if (token.status == Status.Rented && token.rentDuration > block.timestamp)
        {
            require(who == token.tenant, "TheWallCore: Rented token can be managed by tenant only");
        }
        else
        {
            require(who == owner, "TheWallCore: Only owner can manager token");
        }
    }

    function _setContent(address who, address owner, uint256 tokenId, bytes memory content) onlyTheWall public
    {
        _canBeManaged(who, owner, tokenId);
        Token storage token = _tokens[tokenId];
        token.content = content;
    }

    function _setAttributesComplete(address who, address owner, uint256 tokenId, bytes memory image, string memory link, string memory tags, string memory title) onlyTheWall public
    {
        TokenType tt = _canBeManaged(who, owner, tokenId);
        require(tt == TokenType.Area, "TheWallCore: Image can be set to area only");
        Area storage area = _areas[tokenId];
        area.image = image;
        Token storage token = _tokens[tokenId];
        token.link = link;
        token.tags = tags;
        token.title = title;
        delete token.content;
    }

    function _setAttributes(address who, address owner, uint256 tokenId, string memory link, string memory tags, string memory title) onlyTheWall public
    {
        _canBeManaged(who, owner, tokenId);
        Token storage token = _tokens[tokenId];
        token.link = link;
        token.tags = tags;
        token.title = title;
        delete token.content;
    }

    function _setImage(address who, address owner, uint256 tokenId, bytes memory image) onlyTheWall public
    {
        TokenType tt = _canBeManaged(who, owner, tokenId);
        require(tt == TokenType.Area, "TheWallCore: Image can be set to area only");
        Area storage area = _areas[tokenId];
        area.image = image;
        delete _tokens[tokenId].content;
    }

    function _setLink(address who, address owner, uint256 tokenId, string memory link) onlyTheWall public
    {
        _canBeManaged(who, owner, tokenId);
        Token storage token = _tokens[tokenId];
        token.link = link;
        delete token.content;
    }

    function _setTags(address who, address owner, uint256 tokenId, string memory tags) onlyTheWall public
    {
        _canBeManaged(who, owner, tokenId);
        Token storage token = _tokens[tokenId];
        token.tags = tags;
        delete token.content;
    }

    function _setTitle(address who, address owner, uint256 tokenId, string memory title) onlyTheWall public
    {
        _canBeManaged(who, owner, tokenId);
        Token storage token = _tokens[tokenId];
        token.title = title;
        delete token.content;
    }

    function tokenInfo(uint256 tokenId) public view returns(bytes memory, string memory, string memory, string memory, bytes memory)
    {
        Token memory token = _tokens[tokenId];
        bytes memory image;
        if (token.tt == TokenType.Area)
        {
            Area storage area = _areas[tokenId];
            image = area.image;
        }
        return (image, token.link, token.tags, token.title, token.content);
    }

    function _canBeCreated(int256 x, int256 y) view public
    {
        require(_abs(x) < _wallWidth && _abs(y) < _wallHeight, "TheWallCore: Out of wall");
        require(_areaOnTheWall(x, y) == uint256(0), "TheWallCore: Area is busy");
    }

    function _processPaymentCreate(address me, uint256 weiAmount, uint256 areasNum, address payable referrerCandidate) onlyTheWall public payable returns(uint256)
    {
        uint256 usedCoupons = _useCoupons(me, areasNum);
        areasNum -= usedCoupons;
        return _processPayment(me, weiAmount, areasNum, referrerCandidate);
    }
    
    function _processPayment(address me, uint256 weiAmount, uint256 itemsAmount, address payable referrerCandidate) internal returns (uint256)
    {
        uint256 payValue = _costWei.mul(itemsAmount);
        require(payValue <= weiAmount, string(abi.encodePacked("TheWallCore: Invalid amount of wei ", payValue.toString(), "/", weiAmount.toString())));
        if (weiAmount > payValue)
        {
            payable(me).sendValue(weiAmount.sub(payValue));
        }
        if (payValue > 0)
        {
            uint256 alreadyPayed = _processRef(me, referrerCandidate, payValue);
            _fundsReceiver.sendValue(payValue.sub(alreadyPayed));
        }
        return payValue;
    }

    function _canBeCreatedMulti(int256 x, int256 y, int256 width, int256 height) view public
    {
        require(_abs(x) < _wallWidth &&
                _abs(y) < _wallHeight &&
                _abs(x.add(width)) < _wallWidth &&
                _abs(y.add(height)) < _wallHeight,                
                "TheWallCpre: Out of wall");
        require(width > 0 && height > 0, "TheWallCore: dimensions must be greater than zero");
    }

    function _buyCoupons(address me, uint256 weiAmount, address payable referrerCandidate) public payable onlyTheWall returns (uint256)
    {
        uint256 couponsAmount = weiAmount.div(_costWei);
        uint payValue = _processPayment(me, weiAmount, couponsAmount, referrerCandidate);
        if (payValue > 0)
        {
            _giveCoupons(me, couponsAmount);
        }
        return payValue;
    }
    
    function _clusterOf(uint256 tokenId) view public returns (uint256)
    {
        return _areas[tokenId].cluster;
    }
}

File 17 of 18: thewallcoupons.sol
/*
This file is part of the TheWall project.

The TheWall Contract is free software: you can redistribute it and/or
modify it under the terms of the GNU lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

The TheWall Contract is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU lesser General Public License for more details.

You should have received a copy of the GNU lesser General Public License
along with the TheWall Contract. If not, see <http://www.gnu.org/licenses/>.

@author Ilya Svirin <[email protected]>
*/
// SPDX-License-Identifier: GNU lesser General Public License

pragma solidity ^0.8.0;

import "Context.sol";
import "SafeMath.sol";
import "Address.sol";


abstract contract ERC223ReceivingContract
{
    function tokenFallback(address sender, uint amount, bytes memory data) public virtual;
}


contract TheWallCoupons is Context
{
    using SafeMath for uint256;
    using Address for address;

    string public standard='Token 0.1';
    string public name='TheWall';
    string public symbol='TWC';
    uint8 public decimals=0;
    
    event Transfer(address indexed sender, address indexed receiver, uint256 amount, bytes data);

    mapping(address => uint256) public balanceOf;
    uint256 public totalSupply;

    address private _thewallusers;

    function setTheWallUsers(address thewallusers) public
    {
        require(thewallusers != address(0), "TheWallCoupons: non-zero address is required");
        require(_thewallusers == address(0), "TheWallCoupons: _thewallusers can be initialized only once");
        _thewallusers = thewallusers;
    }

    modifier onlyTheWallUsers()
    {
        require(_msgSender() == _thewallusers, "TheWallCoupons: can be called from _theWallusers only");
        _;
    }

    function transfer(address receiver, uint256 amount, bytes memory data) public returns(bool)
    {
        _transfer(_msgSender(), receiver, amount, data);
        return true;
    }
    
    function transfer(address receiver, uint256 amount) public returns(bool)
    {
        bytes memory empty = hex"00000000";
         _transfer(_msgSender(), receiver, amount, empty);
         return true;
    }

    function _transfer(address sender, address receiver, uint amount, bytes memory data) internal
    {
        require(receiver != address(0), "TheWallCoupons: Transfer to zero-address is forbidden");

        balanceOf[sender] = balanceOf[sender].sub(amount);
        balanceOf[receiver] = balanceOf[receiver].add(amount);
        
        if (receiver.isContract())
        {
            ERC223ReceivingContract r = ERC223ReceivingContract(receiver);
            r.tokenFallback(sender, amount, data);
        }
        emit Transfer(sender, receiver, amount, data);
    }

    function _mint(address account, uint256 amount) onlyTheWallUsers public
    {
        require(account != address(0), "TheWallCoupons: mint to the zero address");

        totalSupply = totalSupply.add(amount);
        balanceOf[account] = balanceOf[account].add(amount);
        bytes memory empty = hex"00000000";
        emit Transfer(address(0), account, amount, empty);
    }

    function _burn(address account, uint256 amount) onlyTheWallUsers public
    {
        require(account != address(0), "TheWallCoupons: burn from the zero address");

        balanceOf[account] = balanceOf[account].sub(amount, "TheWallCoupons: burn amount exceeds balance");
        totalSupply = totalSupply.sub(amount);
        bytes memory empty = hex"00000000";
        emit Transfer(account, address(0), amount, empty);
    }
}

File 18 of 18: thewallusers.sol
/*
This file is part of the TheWall project.

The TheWall Contract is free software: you can redistribute it and/or
modify it under the terms of the GNU lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

The TheWall Contract is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU lesser General Public License for more details.

You should have received a copy of the GNU lesser General Public License
along with the TheWall Contract. If not, see <http://www.gnu.org/licenses/>.

@author Ilya Svirin <[email protected]>
*/
// SPDX-License-Identifier: GNU lesser General Public License

pragma solidity ^0.8.0;

import "Ownable.sol";
import "SafeMath.sol";
import "Address.sol";
import "thewallcoupons.sol";


contract TheWallUsers is Ownable
{
    using SafeMath for uint256;
    using Address for address payable;

    struct User
    {
        string          nickname;
        bytes           avatar;
        address payable referrer;
    }
    
    TheWallCoupons private _coupons;

    mapping (address => User) public _users;
    
    event NicknameChanged(address indexed user, string nickname);
    event AvatarChanged(address indexed user, bytes avatar);

    event CouponsCreated(address indexed owner, uint256 created);
    event CouponsUsed(address indexed owner, uint256 used);

    event ReferrerChanged(address indexed me, address indexed referrer);
    event ReferralPayment(address indexed referrer, address indexed referral, uint256 amountWei);

    constructor (address coupons)
    {
        _coupons = TheWallCoupons(coupons);
        _coupons.setTheWallUsers(address(this));
    }

    function setNickname(string memory nickname) public
    {
        _users[_msgSender()].nickname = nickname;
        emit NicknameChanged(_msgSender(), nickname);
    }

    function setAvatar(bytes memory avatar) public
    {
        _users[_msgSender()].avatar = avatar;
        emit AvatarChanged(_msgSender(), avatar);
    }
    
    function setNicknameAvatar(string memory nickname, bytes memory avatar) public
    {
        setNickname(nickname);
        setAvatar(avatar);
    }
    
    function _useCoupons(address owner, uint256 count) internal returns(uint256 used)
    {
        used = _coupons.balanceOf(owner);
        if (count < used)
        {
            used = count;
        }
        if (used > 0)
        {
            _coupons._burn(owner, used);
            emit CouponsUsed(owner, used);
        }
    }

    function giveCoupons(address owner, uint256 count) public onlyOwner
    {
        _giveCoupons(owner, count);
    }
    
    function giveCouponsMulti(address[] memory owners, uint256 count) public onlyOwner
    {
        for(uint i = 0; i < owners.length; ++i)
        {
            _giveCoupons(owners[i], count);
        }
    }
    
    function _giveCoupons(address owner, uint256 count) internal
    {
        require(owner != address(0));
        _coupons._mint(owner, count);
        emit CouponsCreated(owner, count);
    }
    
    function _processRef(address me, address payable referrerCandidate, uint256 amountWei) internal returns(uint256)
    {
        User storage user = _users[me];
        if (referrerCandidate != address(0) && !referrerCandidate.isContract() && user.referrer == address(0))
        {
            user.referrer = referrerCandidate;
            emit ReferrerChanged(me, referrerCandidate);
        }
        
        uint256 alreadyPayed = 0;
        uint256 refPayment = amountWei.mul(6).div(100);

        address payable ref = user.referrer;
        if (ref != address(0))
        {
            ref.sendValue(refPayment);
            alreadyPayed = refPayment;
            emit ReferralPayment(ref, me, refPayment);
            
            ref = _users[ref].referrer;
            if (ref != address(0))
            {
                ref.sendValue(refPayment);
                alreadyPayed = refPayment.mul(2);
                emit ReferralPayment(ref, me, refPayment);
            }
        }
        
        return alreadyPayed;
    }
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address payable","name":"thewall","type":"address"},{"internalType":"address","name":"thewallcore","type":"address"},{"internalType":"address","name":"treasureContract","type":"address"},{"internalType":"uint256","name":"treasureAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"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":"user","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Rewarded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"int256[]","name":"coords","type":"int256[]"}],"name":"TreasureFound","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"hash","type":"bytes32"}],"name":"TreasureHidden","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"treasureContract","type":"address"},{"indexed":false,"internalType":"uint256","name":"treasureAmount","type":"uint256"}],"name":"TreasureSet","type":"event"},{"inputs":[],"name":"_hash","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"_thewall","outputs":[{"internalType":"contract TheWall","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"_thewallcore","outputs":[{"internalType":"contract TheWallCore","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"_treasureContract","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"_treasuredAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"int256[]","name":"coords","type":"int256[]"},{"internalType":"uint256","name":"salt","type":"uint256"}],"name":"findTreasure","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"gameOver","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"hash","type":"bytes32"}],"name":"hideTreasure","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"treasureContract","type":"address"},{"internalType":"uint256","name":"treasureAmount","type":"uint256"}],"name":"setTreasure","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}]

608060405234801561001057600080fd5b50604051610d37380380610d3783398101604081905261002f91610189565b6100383361007b565b600280546001600160a01b038087166001600160a01b031992831617909255600380549286169290911691909117905561007282826100cb565b505050506101f4565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6000546001600160a01b031633146101295760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640160405180910390fd5b600480546001600160a01b0319166001600160a01b038416908117909155600582905560408051918252602082018390527f7e7041e6358fe6bc6eace4a713b5c04cd3c5ea43c4e6ae8c4ea280cdf1032345910160405180910390a15050565b6000806000806080858703121561019f57600080fd5b84516101aa816101dc565b60208601519094506101bb816101dc565b60408601519093506101cc816101dc565b6060959095015193969295505050565b6001600160a01b03811681146101f157600080fd5b50565b610b34806102036000396000f3fe608060405234801561001057600080fd5b50600436106100b45760003560e01c8063735877901161007157806373587790146101435780638da5cb5b1461014c578063902b63ef1461015d57806398c842f014610170578063bdb337d114610183578063f2fde38b1461018b57600080fd5b80630b140ca3146100b95780634f4ab1b0146100ce5780635872b231146100fe5780636291564614610111578063715018a61461012457806372ed9ef91461012c575b600080fd5b6100cc6100c73660046109b3565b61019e565b005b6003546100e1906001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b6004546100e1906001600160a01b031681565b6100cc61011f36600461089a565b61020c565b6100cc610296565b61013560015481565b6040519081526020016100f5565b61013560055481565b6000546001600160a01b03166100e1565b6002546100e1906001600160a01b031681565b6100cc61017e3660046108c6565b6102cc565b6100cc610624565b6100cc610199366004610859565b61076e565b6000546001600160a01b031633146101d15760405162461bcd60e51b81526004016101c890610a5f565b60405180910390fd5b60018190556040518181527ffc07a26e4641625d43c6c55edfcf9a524689eab4d25432df612681f1bfab7fae9060200160405180910390a150565b6000546001600160a01b031633146102365760405162461bcd60e51b81526004016101c890610a5f565b600480546001600160a01b0319166001600160a01b038416908117909155600582905560408051918252602082018390527f7e7041e6358fe6bc6eace4a713b5c04cd3c5ea43c4e6ae8c4ea280cdf1032345910160405180910390a15050565b6000546001600160a01b031633146102c05760405162461bcd60e51b81526004016101c890610a5f565b6102ca6000610809565b565b6000546001600160a01b031633146102f65760405162461bcd60e51b81526004016101c890610a5f565b60008260405160200161030991906109e5565b60408051601f198184030181528282528051602091820120908301528101839052606001604051602081830303815290604052805190602001209050600154811461038f5760405162461bcd60e51b815260206004820152601660248201527554726561737572653a20496e76616c6964206461746160501b60448201526064016101c8565b7fa21fa8342558f246023b35e27a6af048f2f714529dda8902319d3f6104fb08ae836040516103be9190610a1b565b60405180910390a160016000905560005b835181101561061e57600084826103e581610a94565b9350815181106103f7576103f7610abd565b60200260200101519050600085838061040f90610a94565b94508151811061042157610421610abd565b60209081029190910101516003546040516308974d9f60e11b815260048101859052602481018390529192506000916001600160a01b039091169063112e9b3e9060440160206040518083038186803b15801561047d57600080fd5b505afa158015610491573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104b591906109cc565b90508015610616576002546040516331a9108f60e11b8152600481018390526000916001600160a01b031690636352211e9060240160206040518083038186803b15801561050257600080fd5b505afa158015610516573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061053a919061087d565b6004805460055460405163a9059cbb60e01b81526001600160a01b03808616948201949094526024810191909152929350169063a9059cbb90604401602060405180830381600087803b15801561059057600080fd5b505af11580156105a4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105c89190610991565b156106145781816001600160a01b03167f291e8ba3c0f4b0bd86e6e2346fcee1e7ca0975b1cc1886bfbc722d34f3f24d9160055460405161060b91815260200190565b60405180910390a35b505b5050506103cf565b50505050565b6000546001600160a01b0316331461064e5760405162461bcd60e51b81526004016101c890610a5f565b600480546040516370a0823160e01b815230928101929092526000916001600160a01b03909116906370a082319060240160206040518083038186803b15801561069757600080fd5b505afa1580156106ab573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106cf91906109cc565b9050801561076b576004546001600160a01b031663a9059cbb336040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260248101849052604401602060405180830381600087803b15801561073157600080fd5b505af1158015610745573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107699190610991565b505b33ff5b6000546001600160a01b031633146107985760405162461bcd60e51b81526004016101c890610a5f565b6001600160a01b0381166107fd5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016101c8565b61080681610809565b50565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60006020828403121561086b57600080fd5b813561087681610ae9565b9392505050565b60006020828403121561088f57600080fd5b815161087681610ae9565b600080604083850312156108ad57600080fd5b82356108b881610ae9565b946020939093013593505050565b600080604083850312156108d957600080fd5b823567ffffffffffffffff808211156108f157600080fd5b818501915085601f83011261090557600080fd5b813560208282111561091957610919610ad3565b8160051b604051601f19603f8301168101818110868211171561093e5761093e610ad3565b604052838152828101945085830182870184018b101561095d57600080fd5b600096505b84871015610980578035865260019690960195948301948301610962565b509997909101359750505050505050565b6000602082840312156109a357600080fd5b8151801515811461087657600080fd5b6000602082840312156109c557600080fd5b5035919050565b6000602082840312156109de57600080fd5b5051919050565b815160009082906020808601845b83811015610a0f578151855293820193908201906001016109f3565b50929695505050505050565b6020808252825182820181905260009190848201906040850190845b81811015610a5357835183529284019291840191600101610a37565b50909695505050505050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b6000600019821415610ab657634e487b7160e01b600052601160045260246000fd5b5060010190565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b038116811461080657600080fdfea2646970667358221220ff196ff1f48023ccd8bcce660458cdf38cacd14f049e0d44c9fa48108771a29064736f6c63430008070033000000000000000000000000f94b52bf30cec985991edfb6deda4fb48f4f56f50000000000000000000000001cda9d9b8838a6ea02d5c81d39d1ec696b25e2b10000000000000000000000001b105935beb596fab2e00866509af1dc39147048000000000000000000000000000000000000000000000000000000000000000a

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

000000000000000000000000f94b52bf30cec985991edfb6deda4fb48f4f56f50000000000000000000000001cda9d9b8838a6ea02d5c81d39d1ec696b25e2b10000000000000000000000001b105935beb596fab2e00866509af1dc39147048000000000000000000000000000000000000000000000000000000000000000a

-----Decoded View---------------
Arg [0] : thewall (address): 0xf94b52bf30cec985991edfb6deda4fb48f4f56f5
Arg [1] : thewallcore (address): 0x1cda9d9b8838a6ea02d5c81d39d1ec696b25e2b1
Arg [2] : treasureContract (address): 0x1b105935beb596fab2e00866509af1dc39147048
Arg [3] : treasureAmount (uint256): 10

-----Encoded View---------------
4 Constructor Arguments found :
Arg [0] : 000000000000000000000000f94b52bf30cec985991edfb6deda4fb48f4f56f5
Arg [1] : 0000000000000000000000001cda9d9b8838a6ea02d5c81d39d1ec696b25e2b1
Arg [2] : 0000000000000000000000001b105935beb596fab2e00866509af1dc39147048
Arg [3] : 000000000000000000000000000000000000000000000000000000000000000a


Deployed ByteCode Sourcemap

950:2272:17:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1976:125;;;;;;:::i;:::-;;:::i;:::-;;1297:31;;;;;-1:-1:-1;;;;;1297:31:17;;;;;;-1:-1:-1;;;;;3660:32:18;;;3642:51;;3630:2;3615:18;1297:31:17;;;;;;;;1335:36;;;;;-1:-1:-1;;;;;1335:36:17;;;1703:261;;;;;;:::i;:::-;;:::i;1596:92:9:-;;;:::i;1232:24:17:-;;;;;;;;;4764:25:18;;;4752:2;4737:18;1232:24:17;4618:177:18;1378:35:17;;;;;;964:85:9;1010:7;1036:6;-1:-1:-1;;;;;1036:6:9;964:85;;1263:27:17;;;;;-1:-1:-1;;;;;1263:27:17;;;2113:815;;;;;;:::i;:::-;;:::i;2940:279::-;;;:::i;1837:189:9:-;;;;;;:::i;:::-;;:::i;1976:125:17:-;1010:7:9;1036:6;-1:-1:-1;;;;;1036:6:9;666:10:1;1176:23:9;1168:68;;;;-1:-1:-1;;;1168:68:9;;;;;;;:::i;:::-;;;;;;;;;2045:5:17::1;:12:::0;;;2073:20:::1;::::0;4764:25:18;;;2073:20:17::1;::::0;4752:2:18;4737:18;2073:20:17::1;;;;;;;1976:125:::0;:::o;1703:261::-;1010:7:9;1036:6;-1:-1:-1;;;;;1036:6:9;666:10:1;1176:23:9;1168:68;;;;-1:-1:-1;;;1168:68:9;;;;;;;:::i;:::-;1807:17:17::1;:44:::0;;-1:-1:-1;;;;;;1807:44:17::1;-1:-1:-1::0;;;;;1807:44:17;::::1;::::0;;::::1;::::0;;;1862:16:::1;:33:::0;;;1911:45:::1;::::0;;3878:51:18;;;3960:2;3945:18;;3938:34;;;1911:45:17::1;::::0;3851:18:18;1911:45:17::1;;;;;;;1703:261:::0;;:::o;1596:92:9:-;1010:7;1036:6;-1:-1:-1;;;;;1036:6:9;666:10:1;1176:23:9;1168:68;;;;-1:-1:-1;;;1168:68:9;;;;;;;:::i;:::-;1660:21:::1;1678:1;1660:9;:21::i;:::-;1596:92::o:0;2113:815:17:-;1010:7:9;1036:6;-1:-1:-1;;;;;1036:6:9;666:10:1;1176:23:9;1168:68;;;;-1:-1:-1;;;1168:68:9;;;;;;;:::i;:::-;2207:12:17::1;2276:6;2259:24;;;;;;;;:::i;:::-;;::::0;;-1:-1:-1;;2259:24:17;;::::1;::::0;;;;;;2249:35;;2259:24:::1;2249:35:::0;;::::1;::::0;2232:59;;::::1;3401:19:18::0;3436:12;;3429:28;;;3473:12;;2232:59:17::1;;;;;;;;;;;;2222:70;;;;;;2207:85;;2319:5;;2311:4;:13;2303:48;;;::::0;-1:-1:-1;;;2303:48:17;;5934:2:18;2303:48:17::1;::::0;::::1;5916:21:18::0;5973:2;5953:18;;;5946:30;-1:-1:-1;;;5992:18:18;;;5985:52;6054:18;;2303:48:17::1;5732:346:18::0;2303:48:17::1;2367:21;2381:6;2367:21;;;;;;:::i;:::-;;;;;;;;2406:5;2399:12;;;2428:6;2424:497;2444:6;:13;2440:1;:17;2424:497;;;2484:8;2495:6:::0;2502:3;::::1;::::0;::::1;:::i;:::-;;;2495:11;;;;;;;;:::i;:::-;;;;;;;2484:22;;2521:8;2532:6;2539:3;;;;;:::i;:::-;;;2532:11;;;;;;;;:::i;:::-;;::::0;;::::1;::::0;;;;;;2576:12:::1;::::0;:33:::1;::::0;-1:-1:-1;;;2576:33:17;;::::1;::::0;::::1;5653:25:18::0;;;5694:18;;;5687:34;;;2532:11:17;;-1:-1:-1;2558:15:17::1;::::0;-1:-1:-1;;;;;2576:12:17;;::::1;::::0;:27:::1;::::0;5626:18:18;;2576:33:17::1;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;2558:51:::0;-1:-1:-1;2628:12:17;;2624:286:::1;;2689:8;::::0;:25:::1;::::0;-1:-1:-1;;;2689:25:17;;::::1;::::0;::::1;4764::18::0;;;2674:12:17::1;::::0;-1:-1:-1;;;;;2689:8:17::1;::::0;:16:::1;::::0;4737:18:18;;2689:25:17::1;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;2737:17;::::0;;2770:16:::1;::::0;2737:50:::1;::::0;-1:-1:-1;;;2737:50:17;;-1:-1:-1;;;;;3896:32:18;;;2737:50:17;;::::1;3878:51:18::0;;;;3945:18;;;3938:34;;;;2674:40:17;;-1:-1:-1;2737:17:17::1;::::0;:26:::1;::::0;3851:18:18;;2737:50:17::1;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;2733:162;;;2849:7;2843:4;-1:-1:-1::0;;;;;2834:41:17::1;;2858:16;;2834:41;;;;4764:25:18::0;;4752:2;4737:18;;4618:177;2834:41:17::1;;;;;;;;2733:162;2655:255;2624:286;2469:452;;;2424:497;;;;2196:732;2113:815:::0;;:::o;2940:279::-;1010:7:9;1036:6;-1:-1:-1;;;;;1036:6:9;666:10:1;1176:23:9;1168:68;;;;-1:-1:-1;;;1168:68:9;;;;;;;:::i;:::-;3011:17:17::1;::::0;;:42:::1;::::0;-1:-1:-1;;;3011:42:17;;3047:4:::1;3011:42:::0;;::::1;3642:51:18::0;;;;2993:15:17::1;::::0;-1:-1:-1;;;;;3011:17:17;;::::1;::::0;:27:::1;::::0;3615:18:18;;3011:42:17::1;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;2993:60:::0;-1:-1:-1;3068:11:17;;3064:102:::1;;3105:17;::::0;-1:-1:-1;;;;;3105:17:17::1;:26;666:10:1::0;3105:49:17::1;::::0;-1:-1:-1;;;;;;3105:49:17::1;::::0;;;;;;-1:-1:-1;;;;;3896:32:18;;;3105:49:17::1;::::0;::::1;3878:51:18::0;3945:18;;;3938:34;;;3851:18;;3105:49:17::1;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;3064:102;666:10:1::0;3176:35:17::1;1837:189:9::0;1010:7;1036:6;-1:-1:-1;;;;;1036:6:9;666:10:1;1176:23:9;1168:68;;;;-1:-1:-1;;;1168:68:9;;;;;;;:::i;:::-;-1:-1:-1;;;;;1925:22:9;::::1;1917:73;;;::::0;-1:-1:-1;;;1917:73:9;;6285:2:18;1917:73:9::1;::::0;::::1;6267:21:18::0;6324:2;6304:18;;;6297:30;6363:34;6343:18;;;6336:62;-1:-1:-1;;;6414:18:18;;;6407:36;6460:19;;1917:73:9::1;6083:402:18::0;1917:73:9::1;2000:19;2010:8;2000:9;:19::i;:::-;1837:189:::0;:::o;2032:169::-;2087:16;2106:6;;-1:-1:-1;;;;;2122:17:9;;;-1:-1:-1;;;;;;2122:17:9;;;;;;2154:40;;2106:6;;;;;;;2154:40;;2087:16;2154:40;2077:124;2032:169;:::o;14:247:18:-;73:6;126:2;114:9;105:7;101:23;97:32;94:52;;;142:1;139;132:12;94:52;181:9;168:23;200:31;225:5;200:31;:::i;:::-;250:5;14:247;-1:-1:-1;;;14:247:18:o;266:251::-;336:6;389:2;377:9;368:7;364:23;360:32;357:52;;;405:1;402;395:12;357:52;437:9;431:16;456:31;481:5;456:31;:::i;522:315::-;590:6;598;651:2;639:9;630:7;626:23;622:32;619:52;;;667:1;664;657:12;619:52;706:9;693:23;725:31;750:5;725:31;:::i;:::-;775:5;827:2;812:18;;;;799:32;;-1:-1:-1;;;522:315:18:o;842:1195::-;934:6;942;995:2;983:9;974:7;970:23;966:32;963:52;;;1011:1;1008;1001:12;963:52;1051:9;1038:23;1080:18;1121:2;1113:6;1110:14;1107:34;;;1137:1;1134;1127:12;1107:34;1175:6;1164:9;1160:22;1150:32;;1220:7;1213:4;1209:2;1205:13;1201:27;1191:55;;1242:1;1239;1232:12;1191:55;1278:2;1265:16;1300:4;1323:2;1319;1316:10;1313:36;;;1329:18;;:::i;:::-;1375:2;1372:1;1368:10;1407:2;1401:9;1470:2;1466:7;1461:2;1457;1453:11;1449:25;1441:6;1437:38;1525:6;1513:10;1510:22;1505:2;1493:10;1490:18;1487:46;1484:72;;;1536:18;;:::i;:::-;1572:2;1565:22;1622:18;;;1656:15;;;;-1:-1:-1;1691:11:18;;;1721;;;1717:20;;1714:33;-1:-1:-1;1711:53:18;;;1760:1;1757;1750:12;1711:53;1782:1;1773:10;;1792:163;1806:2;1803:1;1800:9;1792:163;;;1863:17;;1851:30;;1824:1;1817:9;;;;;1901:12;;;;1933;;1792:163;;;-1:-1:-1;1974:6:18;2012:18;;;;1999:32;;-1:-1:-1;;;;;;;842:1195:18:o;2042:277::-;2109:6;2162:2;2150:9;2141:7;2137:23;2133:32;2130:52;;;2178:1;2175;2168:12;2130:52;2210:9;2204:16;2263:5;2256:13;2249:21;2242:5;2239:32;2229:60;;2285:1;2282;2275:12;2324:180;2383:6;2436:2;2424:9;2415:7;2411:23;2407:32;2404:52;;;2452:1;2449;2442:12;2404:52;-1:-1:-1;2475:23:18;;2324:180;-1:-1:-1;2324:180:18:o;2509:184::-;2579:6;2632:2;2620:9;2611:7;2607:23;2603:32;2600:52;;;2648:1;2645;2638:12;2600:52;-1:-1:-1;2671:16:18;;2509:184;-1:-1:-1;2509:184:18:o;2698:541::-;2914:13;;2857:3;;2888;;2967:4;2994:15;;;2857:3;3037:175;3051:6;3048:1;3045:13;3037:175;;;3114:13;;3100:28;;3150:14;;;;3187:15;;;;3073:1;3066:9;3037:175;;;-1:-1:-1;3228:5:18;;2698:541;-1:-1:-1;;;;;;2698:541:18:o;3983:630::-;4152:2;4204:21;;;4274:13;;4177:18;;;4296:22;;;4123:4;;4152:2;4375:15;;;;4349:2;4334:18;;;4123:4;4418:169;4432:6;4429:1;4426:13;4418:169;;;4493:13;;4481:26;;4562:15;;;;4527:12;;;;4454:1;4447:9;4418:169;;;-1:-1:-1;4604:3:18;;3983:630;-1:-1:-1;;;;;;3983:630:18:o;6490:356::-;6692:2;6674:21;;;6711:18;;;6704:30;6770:34;6765:2;6750:18;;6743:62;6837:2;6822:18;;6490:356::o;7033:232::-;7072:3;-1:-1:-1;;7093:17:18;;7090:140;;;7152:10;7147:3;7143:20;7140:1;7133:31;7187:4;7184:1;7177:15;7215:4;7212:1;7205:15;7090:140;-1:-1:-1;7257:1:18;7246:13;;7033:232::o;7270:127::-;7331:10;7326:3;7322:20;7319:1;7312:31;7362:4;7359:1;7352:15;7386:4;7383:1;7376:15;7402:127;7463:10;7458:3;7454:20;7451:1;7444:31;7494:4;7491:1;7484:15;7518:4;7515:1;7508:15;7534:131;-1:-1:-1;;;;;7609:31:18;;7599:42;;7589:70;;7655:1;7652;7645:12

Swarm Source

ipfs://ff196ff1f48023ccd8bcce660458cdf38cacd14f049e0d44c9fa48108771a290
Block Transaction Gas Used Reward
Age Block Fee Address BC Fee Address Voting Power Jailed Incoming
Block Uncle Number Difficulty Gas Used Reward
Loading
Loading
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.