Address Details
contract

0x4e3e9AC6B6AD04f29e47cEDDA5067D12473108A7

Contract Name
KolorMarketplace
Creator
0x4db2de–3726d2 at 0x7f4933–1b7bf2
Balance
0 CELO ( )
Locked CELO Balance
0.00 CELO
Voting CELO Balance
0.00 CELO
Pending Unlocked Gold
0.00 CELO
Tokens
Fetching tokens...
Transactions
68 Transactions
Transfers
5 Transfers
Gas Used
26,975,594
Last Balance Update
19423994
This contract has been verified via Sourcify. View contract in Sourcify repository
Contract name:
KolorMarketplace




Optimization enabled
true
Compiler version
v0.8.17+commit.8df45f5f




Optimization runs
1000
EVM Version
london




Verified at
2022-11-08T15:04:51.379181Z

project:/contracts/KolorMarketplace.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

import "./KolorLandNFT.sol";
import "./KolorLandToken.sol";

contract KolorMarketplace is Ownable, ReentrancyGuard, IERC721Receiver {
    // Address of the nft contract and kolor
    address public KolorLandNFTAddress;
    address public KolorLandTokenAddress;
    address public cUSDAddress;
    address public kolorAddress;

    uint256 public oneETH = 1 ether;

    mapping(address => bool) public isAuthorized;

    constructor() {
        isAuthorized[msg.sender] = true;
        kolorAddress = msg.sender;
    }

    modifier onlyAuthorized() {
        require(
            isAuthorized[msg.sender],
            "KMarketplace: You're not allowed to do that"
        );
        _;
    }

    function setNFTAddress(address _NFTAddress) public onlyOwner {
        ERC721 kNFT = ERC721(_NFTAddress);
        if (_NFTAddress != KolorLandNFTAddress) {
            // deauthorize
            authorize(KolorLandNFTAddress);

            KolorLandNFTAddress = _NFTAddress;
            authorize(_NFTAddress);

            kNFT.setApprovalForAll(_NFTAddress, true);
        }
    }

    function setLandTokenAddress(address _landTokenAddress) public onlyOwner {
        if (_landTokenAddress != KolorLandTokenAddress) {
            // deauthorize
            authorize(KolorLandTokenAddress);

            KolorLandTokenAddress = _landTokenAddress;
            authorize(_landTokenAddress);
        }
    }

    function setcUSDAddress(address _cUSDAddress) public onlyOwner {
        if (_cUSDAddress != cUSDAddress) {
            // deauthorize
            authorize(cUSDAddress);

            cUSDAddress = _cUSDAddress;
            authorize(_cUSDAddress);
        }
    }

    function setKolorAddress(address _kolorAddress) public onlyOwner {
        if (_kolorAddress != kolorAddress) {
            // deauthorize
            authorize(kolorAddress);

            kolorAddress = _kolorAddress;
            authorize(_kolorAddress);
        }
    }

    /**
        @dev Withdraw a published land from the marketplace

     */
    function removeLand(uint256 tokenId) public onlyAuthorized nonReentrant {
        IKolorLandNFT ilandInterface = IKolorLandNFT(KolorLandNFTAddress);

        ERC721 erc721 = ERC721(KolorLandNFTAddress);
        erc721.safeTransferFrom(address(this), owner(), tokenId);

        // update the land state to paused
        ilandInterface.updateLandState(tokenId, State.Paused);
    }

    /** 
        @dev Proxy function to buy land tokens from the land token contract

     */
    function buyLandTokens(uint256 tokenId, uint256 amount)
        public
        nonReentrant
    {
        KolorLandNFT _kNFT = KolorLandNFT(KolorLandNFTAddress);

        require(
            _kNFT.isPublished(tokenId),
            "KMarketplace: Land is not published yet!"
        );
        require(
            _kNFT.ownerOf(tokenId) == address(this),
            "KMarketplace: Land is not available (marketplace not owning)!"
        );

        ERC20 _cUSD = ERC20(cUSDAddress);
        KolorLandToken _kolorLT = KolorLandToken(KolorLandTokenAddress);

        uint256 price = _kolorLT.priceOf(tokenId);

        bool success = _cUSD.transferFrom(
            msg.sender,
            kolorAddress,
            amount * price * oneETH
        );

        require(success, "KMarketplace: not enough cUSD funds!");

        _kolorLT.newInvestment(msg.sender, tokenId, amount);
    }

    function authorize(address manager) public onlyOwner {
        isAuthorized[manager] = !isAuthorized[manager];
    }

    function onERC721Received(
        address operator,
        address from,
        uint256 tokenId,
        bytes calldata data
    ) external override returns (bytes4) {
        return this.onERC721Received.selector;
    }
}
        

/_openzeppelin/contracts/access/Ownable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/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() {
        _transferOwnership(_msgSender());
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

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

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        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 {
        _transferOwnership(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");
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}
          

/_openzeppelin/contracts/security/ReentrancyGuard.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        // On the first call to nonReentrant, _notEntered will be true
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;

        _;

        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }
}
          

/_openzeppelin/contracts/token/ERC20/ERC20.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/ERC20.sol)

pragma solidity ^0.8.0;

import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 * For a generic mechanism see {ERC20PresetMinterPauser}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * We have followed general OpenZeppelin Contracts guidelines: functions revert
 * instead returning `false` on failure. This behavior is nonetheless
 * conventional and does not conflict with the expectations of ERC20
 * applications.
 *
 * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
 * This allows applications to reconstruct the allowance for all accounts just
 * by listening to said events. Other implementations of the EIP may not emit
 * these events, as it isn't required by the specification.
 *
 * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
 * functions have been added to mitigate the well-known issues around setting
 * allowances. See {IERC20-approve}.
 */
contract ERC20 is Context, IERC20, IERC20Metadata {
    mapping(address => uint256) private _balances;

    mapping(address => mapping(address => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * The default value of {decimals} is 18. To select a different value for
     * {decimals} you should overload it.
     *
     * All two of these values are immutable: they can only be set once during
     * construction.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view virtual override returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view virtual override returns (string memory) {
        return _symbol;
    }

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5.05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei. This is the value {ERC20} uses, unless this function is
     * overridden;
     *
     * NOTE: This information is only used for _display_ purposes: it in
     * no way affects any of the arithmetic of the contract, including
     * {IERC20-balanceOf} and {IERC20-transfer}.
     */
    function decimals() public view virtual override returns (uint8) {
        return 18;
    }

    /**
     * @dev See {IERC20-totalSupply}.
     */
    function totalSupply() public view virtual override returns (uint256) {
        return _totalSupply;
    }

    /**
     * @dev See {IERC20-balanceOf}.
     */
    function balanceOf(address account) public view virtual override returns (uint256) {
        return _balances[account];
    }

    /**
     * @dev See {IERC20-transfer}.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - the caller must have a balance of at least `amount`.
     */
    function transfer(address to, uint256 amount) public virtual override returns (bool) {
        address owner = _msgSender();
        _transfer(owner, to, amount);
        return true;
    }

    /**
     * @dev See {IERC20-allowance}.
     */
    function allowance(address owner, address spender) public view virtual override returns (uint256) {
        return _allowances[owner][spender];
    }

    /**
     * @dev See {IERC20-approve}.
     *
     * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
     * `transferFrom`. This is semantically equivalent to an infinite approval.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, amount);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20}.
     *
     * NOTE: Does not update the allowance if the current allowance
     * is the maximum `uint256`.
     *
     * Requirements:
     *
     * - `from` and `to` cannot be the zero address.
     * - `from` must have a balance of at least `amount`.
     * - the caller must have allowance for ``from``'s tokens of at least
     * `amount`.
     */
    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) public virtual override returns (bool) {
        address spender = _msgSender();
        _spendAllowance(from, spender, amount);
        _transfer(from, to, amount);
        return true;
    }

    /**
     * @dev Atomically increases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, allowance(owner, spender) + addedValue);
        return true;
    }

    /**
     * @dev Atomically decreases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `spender` must have allowance for the caller of at least
     * `subtractedValue`.
     */
    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        address owner = _msgSender();
        uint256 currentAllowance = allowance(owner, spender);
        require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
        unchecked {
            _approve(owner, spender, currentAllowance - subtractedValue);
        }

        return true;
    }

    /**
     * @dev Moves `amount` of tokens from `from` to `to`.
     *
     * This internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `from` must have a balance of at least `amount`.
     */
    function _transfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {
        require(from != address(0), "ERC20: transfer from the zero address");
        require(to != address(0), "ERC20: transfer to the zero address");

        _beforeTokenTransfer(from, to, amount);

        uint256 fromBalance = _balances[from];
        require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
        unchecked {
            _balances[from] = fromBalance - amount;
        }
        _balances[to] += amount;

        emit Transfer(from, to, amount);

        _afterTokenTransfer(from, to, amount);
    }

    /** @dev Creates `amount` tokens and assigns them to `account`, increasing
     * the total supply.
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function _mint(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: mint to the zero address");

        _beforeTokenTransfer(address(0), account, amount);

        _totalSupply += amount;
        _balances[account] += amount;
        emit Transfer(address(0), account, amount);

        _afterTokenTransfer(address(0), account, amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, reducing the
     * total supply.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - `account` must have at least `amount` tokens.
     */
    function _burn(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: burn from the zero address");

        _beforeTokenTransfer(account, address(0), amount);

        uint256 accountBalance = _balances[account];
        require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
        unchecked {
            _balances[account] = accountBalance - amount;
        }
        _totalSupply -= amount;

        emit Transfer(account, address(0), amount);

        _afterTokenTransfer(account, address(0), amount);
    }

    /**
     * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     */
    function _approve(
        address owner,
        address spender,
        uint256 amount
    ) internal virtual {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");

        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }

    /**
     * @dev Updates `owner` s allowance for `spender` based on spent `amount`.
     *
     * Does not update the allowance amount in case of infinite allowance.
     * Revert if not enough allowance is available.
     *
     * Might emit an {Approval} event.
     */
    function _spendAllowance(
        address owner,
        address spender,
        uint256 amount
    ) internal virtual {
        uint256 currentAllowance = allowance(owner, spender);
        if (currentAllowance != type(uint256).max) {
            require(currentAllowance >= amount, "ERC20: insufficient allowance");
            unchecked {
                _approve(owner, spender, currentAllowance - amount);
            }
        }
    }

    /**
     * @dev Hook that is called before any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * will be transferred to `to`.
     * - when `from` is zero, `amount` tokens will be minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens 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 amount
    ) internal virtual {}

    /**
     * @dev Hook that is called after any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * has been transferred to `to`.
     * - when `from` is zero, `amount` tokens have been minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens have been 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 _afterTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {}
}
          

/_openzeppelin/contracts/token/ERC20/IERC20.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @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);

    /**
     * @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 `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, 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 `from` to `to` 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 from,
        address to,
        uint256 amount
    ) external returns (bool);
}
          

/_openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

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

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}
          

/_openzeppelin/contracts/token/ERC721/ERC721.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC721/ERC721.sol)

pragma solidity ^0.8.0;

import "./IERC721.sol";
import "./IERC721Receiver.sol";
import "./extensions/IERC721Metadata.sol";
import "../../utils/Address.sol";
import "../../utils/Context.sol";
import "../../utils/Strings.sol";
import "../../utils/introspection/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: address zero is not a valid owner");
        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: invalid token ID");
        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) {
        _requireMinted(tokenId);

        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 overridden 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 token owner nor approved for all"
        );

        _approve(to, tokenId);
    }

    /**
     * @dev See {IERC721-getApproved}.
     */
    function getApproved(uint256 tokenId) public view virtual override returns (address) {
        _requireMinted(tokenId);

        return _tokenApprovals[tokenId];
    }

    /**
     * @dev See {IERC721-setApprovalForAll}.
     */
    function setApprovalForAll(address operator, bool approved) public virtual override {
        _setApprovalForAll(_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: caller is not token 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: caller is not token 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) {
        address owner = ERC721.ownerOf(tokenId);
        return (spender == owner || isApprovedForAll(owner, spender) || getApproved(tokenId) == 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);

        _afterTokenTransfer(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);

        _afterTokenTransfer(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 from incorrect owner");
        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);

        _afterTokenTransfer(from, to, tokenId);
    }

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

    /**
     * @dev Approve `operator` to operate on all of `owner` tokens
     *
     * Emits an {ApprovalForAll} event.
     */
    function _setApprovalForAll(
        address owner,
        address operator,
        bool approved
    ) internal virtual {
        require(owner != operator, "ERC721: approve to caller");
        _operatorApprovals[owner][operator] = approved;
        emit ApprovalForAll(owner, operator, approved);
    }

    /**
     * @dev Reverts if the `tokenId` has not been minted yet.
     */
    function _requireMinted(uint256 tokenId) internal view virtual {
        require(_exists(tokenId), "ERC721: invalid token ID");
    }

    /**
     * @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 {
                    /// @solidity memory-safe-assembly
                    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 {}

    /**
     * @dev Hook that is called after any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _afterTokenTransfer(
        address from,
        address to,
        uint256 tokenId
    ) internal virtual {}
}
          

/_openzeppelin/contracts/token/ERC721/IERC721.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC721/IERC721.sol)

pragma solidity ^0.8.0;

import "../../utils/introspection/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`.
     *
     * 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;

    /**
     * @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 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 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 the account approved for `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function getApproved(uint256 tokenId) external view returns (address operator);

    /**
     * @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);
}
          

/_openzeppelin/contracts/token/ERC721/IERC721Receiver.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol)

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 `IERC721Receiver.onERC721Received.selector`.
     */
    function onERC721Received(
        address operator,
        address from,
        uint256 tokenId,
        bytes calldata data
    ) external returns (bytes4);
}
          

/_openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol)

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

/_openzeppelin/contracts/utils/Address.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @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
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 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
                /// @solidity memory-safe-assembly
                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}
          

/_openzeppelin/contracts/utils/Context.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

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

/_openzeppelin/contracts/utils/Counters.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Counters.sol)

pragma solidity ^0.8.0;

/**
 * @title Counters
 * @author Matt Condon (@shrugs)
 * @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number
 * of elements in a mapping, issuing ERC721 ids, or counting request ids.
 *
 * Include with `using Counters for Counters.Counter;`
 */
library Counters {
    struct Counter {
        // This variable should never be directly accessed by users of the library: interactions must be restricted to
        // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add
        // this feature: see https://github.com/ethereum/solidity/issues/4637
        uint256 _value; // default: 0
    }

    function current(Counter storage counter) internal view returns (uint256) {
        return counter._value;
    }

    function increment(Counter storage counter) internal {
        unchecked {
            counter._value += 1;
        }
    }

    function decrement(Counter storage counter) internal {
        uint256 value = counter._value;
        require(value > 0, "Counter: decrement overflow");
        unchecked {
            counter._value = value - 1;
        }
    }

    function reset(Counter storage counter) internal {
        counter._value = 0;
    }
}
          

/_openzeppelin/contracts/utils/Strings.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Strings.sol)

pragma solidity ^0.8.0;

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

    /**
     * @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);
    }

    /**
     * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
     */
    function toHexString(address addr) internal pure returns (string memory) {
        return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
    }
}
          

/_openzeppelin/contracts/utils/introspection/ERC165.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)

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

/_openzeppelin/contracts/utils/introspection/IERC165.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)

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

/project_/contracts/IKolorLandNFT.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

enum State {
    Created,
    Paused,
    Removed,
    Published
}

interface IKolorLandNFT {
    /**
        @dev Updates the availibility of tokenized land to be
        purchased in a marketplace
    
     */
    function updateLandState(uint256 tokenId, State state) external;

    function updateName(uint256 tokenId, string memory name) external;

    function landOwnerOf(uint256 tokenId)
        external
        view
        returns (address landOwner);

    function initialTCO2Of(uint256 tokenId)
        external
        view
        returns (uint256 initialTCO2);

    function stateOf(uint256 tokenId) external view returns (State state);

    function safeTransferToMarketplace(uint256 tokenId) external;

    function getVCUSLeft(uint256 tokenId) external view returns (uint256 vcus);
}
          

/project_/contracts/KolorLandNFT.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "./IKolorLandNFT.sol";

struct GeoSpatialPoint {
    int256 latitude;
    int256 longitude;
    uint256 decimals;
    uint256 creationDate;
    uint256 updateDate;
}

struct Species {
    string speciesAlias;
    string scientificName;
    uint256 density;
    uint256 size;
    uint256 decimals;
    uint256 TCO2perSecond;
    uint256 TCO2perYear;
    uint256 landId;
    uint256 creationDate;
    uint256 updateDate;
}

struct NFTInfo {
    string name;
    string identifier;
    address landOwner;
    string landOwnerAlias;
    uint256 decimals;
    uint256 size;
    string country;
    string stateOrRegion;
    string city;
    State state;
    uint256 initialTCO2perYear;
    uint256 soldTCO2;
    uint256 creationDate;
    string unit;
}

contract KolorLandNFT is ERC721, Ownable, IKolorLandNFT {
    using Counters for Counters.Counter;

    Counters.Counter private _tokenIdCounter;
    address public marketplace;

    constructor() ERC721("Kolor Land NFT", "KLand") {
        isAuthorized[msg.sender] = true;
        setApprovalForAll(address(this), true);
    }

    string public baseURI;
    uint256 public totalLands;

    // NFT info
    mapping(uint256 => NFTInfo) private mintedNFTSInfo;

    // Owned lands to use in enumeration
    mapping(address => mapping(uint256 => uint256)) private ownedLands;
    mapping(uint256 => uint256) private landIndex;
    mapping(address => uint256) private _totalLandOwned;

    // mappings of conflictive data such as species and location
    mapping(uint256 => mapping(uint256 => Species)) public species;
    mapping(uint256 => uint256) public totalSpecies;

    mapping(uint256 => mapping(uint256 => GeoSpatialPoint)) public points;
    mapping(uint256 => uint256) public totalPoints;

    mapping(address => bool) public isAuthorized; //hot wallet, owner is cold wallet

    function safeMint(
        address to,
        string memory name,
        string memory identifier,
        address landOwner,
        string memory landOwnerAlias,
        uint256 decimals,
        uint256 size,
        string memory country,
        string memory stateOrRegion,
        string memory city,
        uint256 initialTCO2,
        string memory unit
    ) public onlyAuthorized {
        uint256 currentTokenId = _tokenIdCounter.current();
        _tokenIdCounter.increment();
        _safeMint(to, currentTokenId);

        // Set all NFT information
        mintedNFTSInfo[currentTokenId].name = name;
        mintedNFTSInfo[currentTokenId].identifier = identifier;
        mintedNFTSInfo[currentTokenId].landOwner = landOwner;
        mintedNFTSInfo[currentTokenId].landOwnerAlias = landOwnerAlias;
        mintedNFTSInfo[currentTokenId].decimals = decimals;
        mintedNFTSInfo[currentTokenId].size = size;
        mintedNFTSInfo[currentTokenId].country = country;
        mintedNFTSInfo[currentTokenId].stateOrRegion = stateOrRegion;
        mintedNFTSInfo[currentTokenId].city = city;
        mintedNFTSInfo[currentTokenId].initialTCO2perYear = initialTCO2;
        mintedNFTSInfo[currentTokenId].unit = unit;
        mintedNFTSInfo[currentTokenId].creationDate = block.timestamp;
        mintedNFTSInfo[currentTokenId].state = State.Created;

        uint256 _landsOwned = _totalLandOwned[landOwner];
        // set the tokenId to current landowner collection index
        ownedLands[landOwner][_landsOwned] = currentTokenId;

        // update the tokenId index in landowner collection
        landIndex[currentTokenId] = _landsOwned;

        // increase total lands owned by address
        _totalLandOwned[landOwner]++;

        totalLands++;
    }

    function authorize(address manager) public onlyOwner {
        isAuthorized[manager] = !isAuthorized[manager];
    }

    function setMarketplace(address _marketplace) public onlyAuthorized {
        marketplace = _marketplace;

        if (_marketplace != marketplace) {
            // deauthorize
            authorize(marketplace);

            marketplace = _marketplace;
            authorize(_marketplace);
        }
    }

    modifier onlyMarketplace() {
        require(
            marketplace == msg.sender,
            "Kolor Land NFT: You're not allowed to do that!"
        );
        _;
    }

    modifier onlyAuthorized() {
        require(
            isAuthorized[msg.sender],
            "Kolor Land NFT: You're not allowed to do that!"
        );
        _;
    }

    modifier notBurned(uint256 tokenId) {
        require(_exists(tokenId), "ERC721Metadata: operation on burned token!");
        _;
    }

    modifier notPublishedNorRemoved(uint256 tokenId) {
        require(
            !isRemoved(tokenId) && !isPublished(tokenId),
            "Kolor Land NFT:  This land can't be transfered to Marketplace"
        );
        _;
    }

    function isLandOwner(address landOwner, uint256 tokenId)
        public
        view
        returns (bool)
    {
        return mintedNFTSInfo[tokenId].landOwner == landOwner;
    }

    function isRemoved(uint256 tokenId) public view returns (bool) {
        return mintedNFTSInfo[tokenId].state == State.Removed;
    }

    function isPublished(uint256 tokenId) public view returns (bool) {
        return mintedNFTSInfo[tokenId].state == State.Published;
    }

    /**
        @dev Override of functions defined on interface ILandNFT
    
     */
    function updateLandState(uint256 tokenId, State _state)
        public
        override
        notBurned(tokenId)
        onlyAuthorized
    {
        require(_state != State.Created, "Kolor Land NFT: Invalid State");
        mintedNFTSInfo[tokenId].state = _state;
    }

    function updateName(uint256 tokenId, string memory newName)
        public
        override
        onlyAuthorized
        notBurned(tokenId)
    {
        mintedNFTSInfo[tokenId].name = newName;
    }

    function _totalLands() public view returns (uint256) {
        return totalLands;
    }

    function landOwnerOf(uint256 tokenId)
        public
        view
        override
        returns (address)
    {
        address landOwner = mintedNFTSInfo[tokenId].landOwner;

        return landOwner;
    }

    function landIndexOf(uint256 tokenId) public view returns (uint256) {
        return landIndex[tokenId];
    }

    function initialTCO2Of(uint256 tokenId)
        public
        view
        override
        returns (uint256)
    {
        return mintedNFTSInfo[tokenId].initialTCO2perYear;
    }

    function stateOf(uint256 tokenId) public view override returns (State) {
        return mintedNFTSInfo[tokenId].state;
    }

    /**
        @dev transfers the token to the marketplace and marks it
        as published for buyers to invest

     */
    function safeTransferToMarketplace(uint256 tokenId)
        public
        override
        notBurned(tokenId)
        onlyOwner
        notPublishedNorRemoved(tokenId)
    {
        // Transfer to the marketplace
        updateLandState(tokenId, State.Published);
        safeTransferFrom(msg.sender, marketplace, tokenId);
    }

    function getNFTInfo(uint256 tokenId) public view returns (NFTInfo memory) {
        return mintedNFTSInfo[tokenId];
    }

    function landOfOwnerByIndex(address landOwner, uint256 index)
        public
        view
        returns (uint256)
    {
        require(
            index < totalLandOwnedOf(landOwner), // TODO: REPLACE FOR TOTALLANDOWNED OF
            "landowner index out of bounds"
        );

        return ownedLands[landOwner][index];
    }

    function totalLandOwnedOf(address landOwner) public view returns (uint256) {
        return _totalLandOwned[landOwner];
    }

    function totalSpeciesOf(uint256 tokenId) public view returns (uint256) {
        return totalSpecies[tokenId];
    }

    function totalPointsOf(uint256 tokenId) public view returns (uint256) {
        return totalPoints[tokenId];
    }

    /** @dev set all species of a certain land */
    function setSpecies(uint256 tokenId, Species[] memory _species)
        public
        onlyAuthorized
        notBurned(tokenId)
    {
        require(
            totalSpeciesOf(tokenId) == 0,
            "Kolor Land NFT: Species of this land already been set"
        );
        uint256 _totalSpecies = _species.length;
        for (uint256 i = 0; i < _totalSpecies; i++) {
            species[tokenId][i].speciesAlias = _species[i].speciesAlias;
            species[tokenId][i].scientificName = _species[i].scientificName;
            species[tokenId][i].density = _species[i].density;
            species[tokenId][i].size = _species[i].size;
            species[tokenId][i].decimals = _species[i].decimals;
            species[tokenId][i].TCO2perSecond = _species[i].TCO2perSecond;
            species[tokenId][i].TCO2perYear = _species[i].TCO2perYear;
            species[tokenId][i].landId = tokenId;
            species[tokenId][i].creationDate = block.timestamp;
        }

        totalSpecies[tokenId] = _totalSpecies;
    }

    function addSpecies(uint256 tokenId, Species memory _species)
        public
        onlyAuthorized
        notBurned(tokenId)
    {
        uint256 _totalSpecies = totalSpeciesOf(tokenId);
        species[tokenId][_totalSpecies].speciesAlias = _species.speciesAlias;
        species[tokenId][_totalSpecies].scientificName = _species
            .scientificName;
        species[tokenId][_totalSpecies].density = _species.density;
        species[tokenId][_totalSpecies].size = _species.size;
        species[tokenId][_totalSpecies].decimals = _species.decimals;
        species[tokenId][_totalSpecies].TCO2perYear = _species.TCO2perYear;
        species[tokenId][_totalSpecies].landId = tokenId;
        species[tokenId][_totalSpecies].creationDate = block.timestamp;
        species[tokenId][_totalSpecies].TCO2perSecond = _species.TCO2perSecond;

        totalSpecies[tokenId]++;
    }

    function updateSpecies(
        uint256 tokenId,
        uint256 speciesIndex,
        Species memory _species
    ) public onlyAuthorized notBurned(tokenId) {
        require(
            validSpecie(speciesIndex, tokenId),
            "Kolor Land NFT: Invalid specie to update"
        );

        species[tokenId][speciesIndex].speciesAlias = _species.speciesAlias;
        species[tokenId][speciesIndex].scientificName = _species.scientificName;
        species[tokenId][speciesIndex].density = _species.density;
        species[tokenId][speciesIndex].size = _species.size;
        species[tokenId][speciesIndex].TCO2perYear = _species.TCO2perYear;
        species[tokenId][speciesIndex].landId = tokenId;
        species[tokenId][speciesIndex].updateDate = block.timestamp;
        species[tokenId][speciesIndex].TCO2perSecond = _species.TCO2perSecond;
    }

    function setPoints(uint256 tokenId, GeoSpatialPoint[] memory _points)
        public
        onlyAuthorized
        notBurned(tokenId)
    {
        require(
            totalPointsOf(tokenId) == 0,
            "Kolor Land NFT: Geospatial points of this land already been set"
        );
        uint256 _totalPoints = _points.length;

        for (uint256 i = 0; i < _totalPoints; i++) {
            points[tokenId][i].latitude = _points[i].latitude;
            points[tokenId][i].longitude = _points[i].longitude;
            points[tokenId][i].decimals = _points[i].decimals;
            points[tokenId][i].creationDate = block.timestamp;

            totalPoints[tokenId]++;
        }
    }

    function addPoint(uint256 tokenId, GeoSpatialPoint memory point)
        public
        onlyAuthorized
        notBurned(tokenId)
    {
        uint256 _totalPoints = totalPoints[tokenId];

        points[tokenId][_totalPoints].latitude = point.latitude;
        points[tokenId][_totalPoints].longitude = point.longitude;
        points[tokenId][_totalPoints].decimals = point.decimals;

        totalPoints[tokenId]++;
    }

    function updatePoint(
        uint256 tokenId,
        uint256 pointIndex,
        GeoSpatialPoint memory point
    ) public onlyAuthorized notBurned(tokenId) {
        require(
            validPoint(pointIndex, tokenId),
            "Kolor Land NFT: Invalid point to update"
        );

        points[tokenId][pointIndex].latitude = point.latitude;
        points[tokenId][pointIndex].longitude = point.longitude;
        points[tokenId][pointIndex].decimals = point.decimals;
    }

    function validSpecie(uint256 specieIndex, uint256 tokenId)
        internal
        view
        returns (bool)
    {
        if (specieIndex >= 0 && specieIndex < totalSpeciesOf(tokenId)) {
            return true;
        }

        return false;
    }

    function validPoint(uint256 pointIndex, uint256 tokenId)
        internal
        view
        returns (bool)
    {
        if (pointIndex >= 0 && pointIndex < totalPointsOf(tokenId)) {
            return true;
        }

        return false;
    }

    function totalVCUBySpecies(uint256 tokenId, uint256 index)
        public
        view
        returns (uint256)
    {
        // Get the seconds elapsed until now
        uint256 speciesCreationDate = species[tokenId][index].creationDate;

        uint256 secondsElapsed = timestampDifference(
            speciesCreationDate,
            block.timestamp
        );

        // now we get the total vcus emitted until now
        return secondsElapsed * species[tokenId][index].TCO2perSecond;
    }

    function totalVCUSEmitedBy(uint256 tokenId) public view returns (uint256) {
        // Get total species of a land
        uint256 _totalSpecies = totalSpeciesOf(tokenId);

        uint256 totalVCUSEmitted = 0;
        // Iterate over all species and calculate its total vcu
        for (uint256 i = 0; i < _totalSpecies; i++) {
            uint256 currentVCUSEmitted = totalVCUBySpecies(tokenId, i);
            totalVCUSEmitted += currentVCUSEmitted;
        }

        return totalVCUSEmitted;
    }

    /**
        @dev returns vcus emitted from this land that are available
        for sale
    
     */
    function getVCUSLeft(uint256 tokenId)
        public
        view
        override
        returns (uint256)
    {
        // Get the ideal vcutokens from creation date until now
        uint256 totalVCUSEmited = totalVCUSEmitedBy(tokenId);

        // get the difference between the ideal minus the sold TCO2
        return totalVCUSEmited - mintedNFTSInfo[tokenId].soldTCO2;
    }

    function timestampDifference(uint256 timestamp1, uint256 timestamp2)
        public
        pure
        returns (uint256)
    {
        return timestamp2 - timestamp1;
    }

    function setBaseURI(string memory _baseURI) public onlyOwner {
        baseURI = _baseURI;
    }

    function tokenURI(uint256 tokenId)
        public
        view
        override
        returns (string memory)
    {
        require(
            _exists(tokenId),
            "ERC721Metadata: URI query for nonexistent token"
        );

        return
            string(
                abi.encodePacked(baseURI, mintedNFTSInfo[tokenId].identifier)
            );
    }
}
          

/project_/contracts/KolorLandToken.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

import "./KolorLandNFT.sol";

struct LandTokensInfo {
    uint256 initialAmount;
    uint256 currentAmount;
    uint256 available;
    uint256 sold;
    uint256 creationDate;
    uint256 lastUpdate;
    uint256 tokenPrice;
    string unit;
}

struct Investment {
    uint256 tokenId;
    address account;
    uint256 amount;
    uint256 tokenPrice;
    string unit;
    uint256 creationDate;
}

contract KolorLandToken is Ownable {
    event NewInvestment(
        address investor,
        uint256 tokenId,
        uint256 amount,
        uint256 tokenPrice
    );

    // address of kolorLandNFT
    address public kolorLandNFT;
    address public marketplaceAddress;

    address private devAddress;

    // authorized addresses
    mapping(address => bool) public isAuthorized;

    // Investments by address
    mapping(address => mapping(uint256 => Investment))
        public investmentsByAddress;
    mapping(address => uint256) public totalInvestmentsByAddress;

    //Investments by land
    mapping(uint256 => mapping(uint256 => Investment)) public investmentsByLand;
    mapping(uint256 => uint256) public totalInvestmentsByLand;

    // total investments in this platform
    uint256 public totalInvestments;

    // info of each land
    mapping(uint256 => LandTokensInfo) public landTokensInfo;

    // checks if address owns a certain token
    mapping(uint256 => mapping(address => uint256)) public balances;

    // total holders of a given land token
    mapping(uint256 => uint256) public holders;

    // Mapping from account to operator approvals
    mapping(address => mapping(address => bool)) private operatorApprovals;

    constructor(address kolorNFTAddress, address _marketplaceAddress) {
        isAuthorized[msg.sender] = true;
        devAddress = msg.sender;

        setKolorLandAddress(kolorNFTAddress);
        setMarketplaceAddress(_marketplaceAddress);

        setApprovalForAll(address(this), msg.sender, true);
    }

    modifier onlyAuthorized() {
        require(
            isAuthorized[msg.sender],
            "Kolor Land token: You're not allowed to do that!"
        );
        _;
    }

    modifier isOwnerOrApproved(address from) {
        require(
            from == msg.sender || operatorApprovals[from][msg.sender],
            "KolorLandToken: caller is not owner nor approved"
        );
        _;
    }

    function setLandTokenInfo(
        uint256 tokenId,
        uint256 initialAmount,
        uint256 tokenPrice,
        string memory unit
    ) external onlyAuthorized {
        require(
            landTokensInfo[tokenId].initialAmount == 0,
            "KolorLandToken: token info already initialized!"
        );
        require(exists(tokenId), "KolorLandToken: land must exists!");

        landTokensInfo[tokenId].initialAmount = initialAmount;
        landTokensInfo[tokenId].sold = 0;
        landTokensInfo[tokenId].creationDate = block.timestamp;
        landTokensInfo[tokenId].tokenPrice = tokenPrice;
        landTokensInfo[tokenId].unit = unit;

        addNewTokens(tokenId, initialAmount);
    }

    function addNewTokens(uint256 tokenId, uint256 amount)
        public
        onlyAuthorized
    {
        require(exists(tokenId), "KolorLandToken: land must exists!");
        landTokensInfo[tokenId].currentAmount += amount;
        landTokensInfo[tokenId].available += amount;

        mint(address(this), tokenId, amount);
    }

    function mint(
        address to,
        uint256 tokenId,
        uint256 amount
    ) internal onlyAuthorized {
        require(exists(tokenId), "KolorLandToken: land must exists!");
        require(to != address(0), "KolorLandToken: mint to the zero address");

        balances[tokenId][to] += amount;
    }

    function newInvestment(
        address investor,
        uint256 tokenId,
        uint256 amount
    ) public onlyAuthorized {
        require(exists(tokenId), "KolorLandToken: land must exists!");
        require(
            availableTokensOf(tokenId) >= amount,
            "KolorLandToken: exceeds max amount"
        );

        require(isPublished(tokenId), "KolorLandToken: land not published yet");

        uint256 tokenPrice = landTokensInfo[tokenId].tokenPrice;

        addInvestmentOfInvestor(investor, tokenId, amount, tokenPrice);
        addInvestmentOfLand(tokenId, investor, amount, tokenPrice);

        // increase number of holders
        if (balances[tokenId][investor] == 0) {
            holders[tokenId]++;
        }

        // set approval for dev or other operator
        if (!operatorApprovals[investor][devAddress]) {
            setApprovalForAll(investor, devAddress, true);
            setApprovalForAll(investor, address(this), true);
        }

        // updates balances and investments
        safeTransferFrom(address(this), investor, tokenId, amount);
        totalInvestmentsByAddress[investor]++;
        totalInvestmentsByLand[tokenId]++;
        totalInvestments++;

        landTokensInfo[tokenId].available -= amount;
        landTokensInfo[tokenId].sold += amount;

        emit NewInvestment(investor, tokenId, amount, tokenPrice);
    }

    /* add investment on given account */
    function addInvestmentOfInvestor(
        address investor,
        uint256 tokenId,
        uint256 amount,
        uint256 tokenPrice
    ) internal {
        uint256 _totalInvestmentsOf = totalInvestmentsOfAddress(investor);

        // create a new investment object
        investmentsByAddress[investor][_totalInvestmentsOf].tokenId = tokenId;
        investmentsByAddress[investor][_totalInvestmentsOf].amount = amount;
        investmentsByAddress[investor][_totalInvestmentsOf]
            .tokenPrice = tokenPrice;
        investmentsByAddress[investor][_totalInvestmentsOf]
            .unit = landTokenInfoOf(tokenId).unit;
        investmentsByAddress[investor][_totalInvestmentsOf].creationDate = block
            .timestamp;
        investmentsByAddress[investor][_totalInvestmentsOf].account = investor;
    }

    /* add investment on given land */
    function addInvestmentOfLand(
        uint256 tokenId,
        address investor,
        uint256 amount,
        uint256 tokenPrice
    ) internal {
        uint256 _totalInvestmentsOf = totalInvestmentsOfLand(tokenId);
        // create a new investment object
        investmentsByLand[tokenId][_totalInvestmentsOf].tokenId = tokenId;
        investmentsByLand[tokenId][_totalInvestmentsOf].amount = amount;
        investmentsByLand[tokenId][_totalInvestmentsOf].tokenPrice = tokenPrice;
        investmentsByLand[tokenId][_totalInvestmentsOf].unit = landTokenInfoOf(
            tokenId
        ).unit;
        investmentsByLand[tokenId][_totalInvestmentsOf].creationDate = block
            .timestamp;
        investmentsByLand[tokenId][_totalInvestmentsOf].account = investor;
    }

    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId,
        uint256 amount
    ) public isOwnerOrApproved(from) {
        require(
            to != address(0),
            "KolorLandToken: transfer to the zero address"
        );

        uint256 fromBalance = balances[tokenId][from];
        require(
            fromBalance >= amount,
            "ERC1155: insufficient balance for transfer"
        );
        unchecked {
            balances[tokenId][from] = fromBalance - amount;
            if (balances[tokenId][from] == 0) {
                holders[tokenId]--;
            }
        }

        balances[tokenId][to] += amount;

        //emit TransferSingle(operator, from, to, id, amount);
    }

    function setKolorLandAddress(address newAddress) public onlyAuthorized {
        kolorLandNFT = newAddress;
    }

    function setMarketplaceAddress(address newAddress) public onlyAuthorized {
        if (newAddress != marketplaceAddress) {
            // deauthorize
            authorize(marketplaceAddress);

            marketplaceAddress = newAddress;
            authorize(newAddress);

            // set approval for marketplace
            setApprovalForAll(address(this), marketplaceAddress, true);
        }
    }

    function setTokenPrice(uint256 tokenId, uint256 price)
        public
        onlyAuthorized
    {
        landTokensInfo[tokenId].tokenPrice = price;
    }

    function authorize(address operator) public onlyOwner {
        isAuthorized[operator] = !isAuthorized[operator];
    }

    function totalInvestmentsOfAddress(address account)
        public
        view
        returns (uint256)
    {
        return totalInvestmentsByAddress[account];
    }

    function totalInvestmentsOfLand(uint256 tokenId)
        public
        view
        returns (uint256)
    {
        return totalInvestmentsByLand[tokenId];
    }

    function landTokenInfoOf(uint256 tokenId)
        public
        view
        returns (LandTokensInfo memory)
    {
        return landTokensInfo[tokenId];
    }

    function creationOf(uint256 tokenId) public view returns (uint256) {
        return landTokensInfo[tokenId].creationDate;
    }

    function lastUpdateOf(uint256 tokenId) public view returns (uint256) {
        return landTokensInfo[tokenId].lastUpdate;
    }

    function priceOf(uint256 tokenId) public view returns (uint256) {
        return landTokensInfo[tokenId].tokenPrice;
    }

    function unitOf(uint256 tokenId) public view returns (string memory) {
        return landTokensInfo[tokenId].unit;
    }

    function availableTokensOf(uint256 tokenId) public view returns (uint256) {
        return landTokensInfo[tokenId].available;
    }

    function soldTokensOf(uint256 tokenId) public view returns (uint256) {
        return landTokensInfo[tokenId].sold;
    }

    function balanceOf(address account, uint256 tokenId)
        public
        view
        returns (uint256)
    {
        require(
            account != address(0),
            "KolorLandToken: balance query for the zero address"
        );

        return balances[tokenId][account];
    }

    function balancesOf(address account, uint256[] memory tokenIds)
        public
        view
        returns (uint256[] memory)
    {
        require(
            account != address(0),
            "KolorLandToken: balance query for the zero address"
        );

        uint256[] memory _balances = new uint256[](tokenIds.length);

        for (uint256 i = 0; i < tokenIds.length; i++) {
            _balances[i] = balanceOf(account, tokenIds[i]);
        }

        return _balances;
    }

    function balanceOfBatch(address[] memory accounts, uint256[] memory ids)
        public
        view
        returns (uint256[] memory)
    {
        require(
            accounts.length == ids.length,
            "KolorLandToken: accounts and ids length mismatch"
        );

        uint256[] memory batchBalances = new uint256[](accounts.length);

        for (uint256 i = 0; i < accounts.length; ++i) {
            batchBalances[i] = balanceOf(accounts[i], ids[i]);
        }

        return batchBalances;
    }

    /* Return all investments made by an address */
    function investmentsOfAddress(address account)
        public
        view
        returns (Investment[] memory)
    {
        uint256 _totalInvestmentsOf = totalInvestmentsOfAddress(account);

        Investment[] memory investments = new Investment[](_totalInvestmentsOf);

        for (uint256 i = 0; i < _totalInvestmentsOf; i++) {
            investments[i] = investmentOfAddress(account, i);
        }

        return investments;
    }

    /* Return all investments made on a certain land */
    function investmentsOfLand(uint256 tokenId)
        public
        view
        returns (Investment[] memory)
    {
        uint256 _totalInvestmentsOf = totalInvestmentsOfLand(tokenId);

        Investment[] memory investments = new Investment[](_totalInvestmentsOf);

        for (uint256 i = 0; i < _totalInvestmentsOf; i++) {
            investments[i] = investmentOfLand(tokenId, i);
        }

        return investments;
    }

    function investmentOfAddress(address account, uint256 index)
        public
        view
        returns (Investment memory)
    {
        return investmentsByAddress[account][index];
    }

    function investmentOfLand(uint256 tokenId, uint256 index)
        public
        view
        returns (Investment memory)
    {
        return investmentsByLand[tokenId][index];
    }

    function exists(uint256 tokenId) internal view returns (bool) {
        ERC721 kolorNFT = ERC721(kolorLandNFT);

        return kolorNFT.ownerOf(tokenId) != address(0);
    }

    function isPublished(uint256 tokenId) internal view returns (bool) {
        KolorLandNFT kolorLand = KolorLandNFT(kolorLandNFT);

        return kolorLand.isPublished(tokenId);
    }

    function getLandTokenBalance(uint256 tokenId)
        public
        view
        returns (uint256)
    {
        return balanceOf(address(this), tokenId);
    }

    function getLandTokenBalances(uint256[] memory tokenIds)
        public
        view
        returns (uint256[] memory)
    {
        return balancesOf(address(this), tokenIds);
    }

    /**
     * @dev Approve `operator` to operate on all of `owner` tokens
     *
     * Emits a {ApprovalForAll} event.
     */
    function setApprovalForAll(
        address owner,
        address operator,
        bool approved
    ) internal virtual {
        require(owner != operator, "ERC1155: setting approval status for self");
        operatorApprovals[owner][operator] = approved;
        //emit ApprovalForAll(owner, operator, approved);
    }

    function setDevAddress(address operator) public onlyAuthorized {
        devAddress = operator;
    }
}
          

Contract ABI

[{"type":"constructor","stateMutability":"nonpayable","inputs":[]},{"type":"event","name":"OwnershipTransferred","inputs":[{"type":"address","name":"previousOwner","internalType":"address","indexed":true},{"type":"address","name":"newOwner","internalType":"address","indexed":true}],"anonymous":false},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"KolorLandNFTAddress","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"KolorLandTokenAddress","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"authorize","inputs":[{"type":"address","name":"manager","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"buyLandTokens","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256"},{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"cUSDAddress","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isAuthorized","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"kolorAddress","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bytes4","name":"","internalType":"bytes4"}],"name":"onERC721Received","inputs":[{"type":"address","name":"operator","internalType":"address"},{"type":"address","name":"from","internalType":"address"},{"type":"uint256","name":"tokenId","internalType":"uint256"},{"type":"bytes","name":"data","internalType":"bytes"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"oneETH","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"removeLand","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceOwnership","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setKolorAddress","inputs":[{"type":"address","name":"_kolorAddress","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setLandTokenAddress","inputs":[{"type":"address","name":"_landTokenAddress","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setNFTAddress","inputs":[{"type":"address","name":"_NFTAddress","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setcUSDAddress","inputs":[{"type":"address","name":"_cUSDAddress","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferOwnership","inputs":[{"type":"address","name":"newOwner","internalType":"address"}]}]
              

Contract Creation Code

0x6080604052670de0b6b3a764000060065534801561001c57600080fd5b506100263361005e565b6001808055336000818152600760205260409020805460ff1916909217909155600580546001600160a01b03191690911790556100ae565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b610f05806100bd6000396000f3fe608060405234801561001057600080fd5b506004361061011b5760003560e01c80638da5cb5b116100b2578063c812fe4b11610081578063eb313eb711610066578063eb313eb714610296578063f2fde38b146102a9578063fe9fbb80146102bc57600080fd5b8063c812fe4b14610270578063caddb4211461028357600080fd5b80638da5cb5b14610226578063b2688d3414610237578063b6a5d7de1461024a578063bd03e5121461025d57600080fd5b80633ff574b6116100ee5780633ff574b6146101e557806369d03738146101f8578063715018a61461020b57806377d90c661461021357600080fd5b8063150b7a021461012057806337ab83bb1461018e57806337ffeffa146101b95780633a6e1dfb146101d0575b600080fd5b61015861012e366004610d1c565b7f150b7a020000000000000000000000000000000000000000000000000000000095945050505050565b6040517fffffffff0000000000000000000000000000000000000000000000000000000090911681526020015b60405180910390f35b6003546101a1906001600160a01b031681565b6040516001600160a01b039091168152602001610185565b6101c260065481565b604051908152602001610185565b6101e36101de366004610dbb565b6102ef565b005b6004546101a1906001600160a01b031681565b6101e3610206366004610dbb565b610348565b6101e3610420565b6101e3610221366004610ddf565b610434565b6000546001600160a01b03166101a1565b6005546101a1906001600160a01b031681565b6101e3610258366004610dbb565b61063d565b6101e361026b366004610dbb565b61066e565b6002546101a1906001600160a01b031681565b6101e3610291366004610df8565b6106c4565b6101e36102a4366004610dbb565b610b7a565b6101e36102b7366004610dbb565b610bd0565b6102df6102ca366004610dbb565b60076020526000908152604090205460ff1681565b6040519015158152602001610185565b6102f7610c5d565b6004546001600160a01b0382811691161461034557600454610321906001600160a01b031661063d565b600480546001600160a01b0319166001600160a01b0383161790556103458161063d565b50565b610350610c5d565b60025481906001600160a01b0380831691161461041c5760025461037c906001600160a01b031661063d565b600280546001600160a01b0319166001600160a01b0384161790556103a08261063d565b6040517fa22cb4650000000000000000000000000000000000000000000000000000000081526001600160a01b0383811660048301526001602483015282169063a22cb46590604401600060405180830381600087803b15801561040357600080fd5b505af1158015610417573d6000803e3d6000fd5b505050505b5050565b610428610c5d565b6104326000610cb7565b565b3360009081526007602052604090205460ff166104be5760405162461bcd60e51b815260206004820152602b60248201527f4b4d61726b6574706c6163653a20596f75277265206e6f7420616c6c6f77656460448201527f20746f20646f207468617400000000000000000000000000000000000000000060648201526084015b60405180910390fd5b6002600154036105105760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016104b5565b60026001819055546001600160a01b031680806342842e0e3061053b6000546001600160a01b031690565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e085901b1681526001600160a01b0392831660048201529116602482015260448101869052606401600060405180830381600087803b1580156105a257600080fd5b505af11580156105b6573d6000803e3d6000fd5b50506040517f4f69ab8c0000000000000000000000000000000000000000000000000000000081526001600160a01b0385169250634f69ab8c9150610602908690600190600401610e1a565b600060405180830381600087803b15801561061c57600080fd5b505af1158015610630573d6000803e3d6000fd5b5050600180555050505050565b610645610c5d565b6001600160a01b03166000908152600760205260409020805460ff19811660ff90911615179055565b610676610c5d565b6003546001600160a01b03828116911614610345576003546106a0906001600160a01b031661063d565b600380546001600160a01b0319166001600160a01b0383161790556103458161063d565b6002600154036107165760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016104b5565b60026001819055546040517f7b156fb5000000000000000000000000000000000000000000000000000000008152600481018490526001600160a01b03909116908190637b156fb590602401602060405180830381865afa15801561077f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107a39190610e4c565b6108155760405162461bcd60e51b815260206004820152602860248201527f4b4d61726b6574706c6163653a204c616e64206973206e6f74207075626c697360448201527f686564207965742100000000000000000000000000000000000000000000000060648201526084016104b5565b6040517f6352211e0000000000000000000000000000000000000000000000000000000081526004810184905230906001600160a01b03831690636352211e90602401602060405180830381865afa158015610875573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108999190610e6e565b6001600160a01b0316146109155760405162461bcd60e51b815260206004820152603d60248201527f4b4d61726b6574706c6163653a204c616e64206973206e6f7420617661696c6160448201527f626c6520286d61726b6574706c616365206e6f74206f776e696e67292100000060648201526084016104b5565b600480546003546040517fb9186d7d0000000000000000000000000000000000000000000000000000000081529283018690526001600160a01b0391821692911690600090829063b9186d7d90602401602060405180830381865afa158015610982573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109a69190610e8b565b90506000836001600160a01b03166323b872dd33600560009054906101000a90046001600160a01b0316600654868b6109df9190610ea4565b6109e99190610ea4565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e086901b1681526001600160a01b03938416600482015292909116602483015260448201526064016020604051808303816000875af1158015610a55573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a799190610e4c565b905080610aed5760405162461bcd60e51b8152602060048201526024808201527f4b4d61726b6574706c6163653a206e6f7420656e6f756768206355534420667560448201527f6e6473210000000000000000000000000000000000000000000000000000000060648201526084016104b5565b6040517f7a415e6900000000000000000000000000000000000000000000000000000000815233600482015260248101889052604481018790526001600160a01b03841690637a415e6990606401600060405180830381600087803b158015610b5557600080fd5b505af1158015610b69573d6000803e3d6000fd5b505060018055505050505050505050565b610b82610c5d565b6005546001600160a01b0382811691161461034557600554610bac906001600160a01b031661063d565b600580546001600160a01b0319166001600160a01b0383161790556103458161063d565b610bd8610c5d565b6001600160a01b038116610c545760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f646472657373000000000000000000000000000000000000000000000000000060648201526084016104b5565b61034581610cb7565b6000546001600160a01b031633146104325760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016104b5565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6001600160a01b038116811461034557600080fd5b600080600080600060808688031215610d3457600080fd5b8535610d3f81610d07565b94506020860135610d4f81610d07565b935060408601359250606086013567ffffffffffffffff80821115610d7357600080fd5b818801915088601f830112610d8757600080fd5b813581811115610d9657600080fd5b896020828501011115610da857600080fd5b9699959850939650602001949392505050565b600060208284031215610dcd57600080fd5b8135610dd881610d07565b9392505050565b600060208284031215610df157600080fd5b5035919050565b60008060408385031215610e0b57600080fd5b50508035926020909101359150565b8281526040810160048310610e3f57634e487b7160e01b600052602160045260246000fd5b8260208301529392505050565b600060208284031215610e5e57600080fd5b81518015158114610dd857600080fd5b600060208284031215610e8057600080fd5b8151610dd881610d07565b600060208284031215610e9d57600080fd5b5051919050565b8082028115828204841417610ec957634e487b7160e01b600052601160045260246000fd5b9291505056fea26469706673582212203fda2a8698913721fa9ae68399f2f5058f6ac7536b84bde82d7b0f5f59756bbf64736f6c63430008110033

Deployed ByteCode

0x608060405234801561001057600080fd5b506004361061011b5760003560e01c80638da5cb5b116100b2578063c812fe4b11610081578063eb313eb711610066578063eb313eb714610296578063f2fde38b146102a9578063fe9fbb80146102bc57600080fd5b8063c812fe4b14610270578063caddb4211461028357600080fd5b80638da5cb5b14610226578063b2688d3414610237578063b6a5d7de1461024a578063bd03e5121461025d57600080fd5b80633ff574b6116100ee5780633ff574b6146101e557806369d03738146101f8578063715018a61461020b57806377d90c661461021357600080fd5b8063150b7a021461012057806337ab83bb1461018e57806337ffeffa146101b95780633a6e1dfb146101d0575b600080fd5b61015861012e366004610d1c565b7f150b7a020000000000000000000000000000000000000000000000000000000095945050505050565b6040517fffffffff0000000000000000000000000000000000000000000000000000000090911681526020015b60405180910390f35b6003546101a1906001600160a01b031681565b6040516001600160a01b039091168152602001610185565b6101c260065481565b604051908152602001610185565b6101e36101de366004610dbb565b6102ef565b005b6004546101a1906001600160a01b031681565b6101e3610206366004610dbb565b610348565b6101e3610420565b6101e3610221366004610ddf565b610434565b6000546001600160a01b03166101a1565b6005546101a1906001600160a01b031681565b6101e3610258366004610dbb565b61063d565b6101e361026b366004610dbb565b61066e565b6002546101a1906001600160a01b031681565b6101e3610291366004610df8565b6106c4565b6101e36102a4366004610dbb565b610b7a565b6101e36102b7366004610dbb565b610bd0565b6102df6102ca366004610dbb565b60076020526000908152604090205460ff1681565b6040519015158152602001610185565b6102f7610c5d565b6004546001600160a01b0382811691161461034557600454610321906001600160a01b031661063d565b600480546001600160a01b0319166001600160a01b0383161790556103458161063d565b50565b610350610c5d565b60025481906001600160a01b0380831691161461041c5760025461037c906001600160a01b031661063d565b600280546001600160a01b0319166001600160a01b0384161790556103a08261063d565b6040517fa22cb4650000000000000000000000000000000000000000000000000000000081526001600160a01b0383811660048301526001602483015282169063a22cb46590604401600060405180830381600087803b15801561040357600080fd5b505af1158015610417573d6000803e3d6000fd5b505050505b5050565b610428610c5d565b6104326000610cb7565b565b3360009081526007602052604090205460ff166104be5760405162461bcd60e51b815260206004820152602b60248201527f4b4d61726b6574706c6163653a20596f75277265206e6f7420616c6c6f77656460448201527f20746f20646f207468617400000000000000000000000000000000000000000060648201526084015b60405180910390fd5b6002600154036105105760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016104b5565b60026001819055546001600160a01b031680806342842e0e3061053b6000546001600160a01b031690565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e085901b1681526001600160a01b0392831660048201529116602482015260448101869052606401600060405180830381600087803b1580156105a257600080fd5b505af11580156105b6573d6000803e3d6000fd5b50506040517f4f69ab8c0000000000000000000000000000000000000000000000000000000081526001600160a01b0385169250634f69ab8c9150610602908690600190600401610e1a565b600060405180830381600087803b15801561061c57600080fd5b505af1158015610630573d6000803e3d6000fd5b5050600180555050505050565b610645610c5d565b6001600160a01b03166000908152600760205260409020805460ff19811660ff90911615179055565b610676610c5d565b6003546001600160a01b03828116911614610345576003546106a0906001600160a01b031661063d565b600380546001600160a01b0319166001600160a01b0383161790556103458161063d565b6002600154036107165760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016104b5565b60026001819055546040517f7b156fb5000000000000000000000000000000000000000000000000000000008152600481018490526001600160a01b03909116908190637b156fb590602401602060405180830381865afa15801561077f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107a39190610e4c565b6108155760405162461bcd60e51b815260206004820152602860248201527f4b4d61726b6574706c6163653a204c616e64206973206e6f74207075626c697360448201527f686564207965742100000000000000000000000000000000000000000000000060648201526084016104b5565b6040517f6352211e0000000000000000000000000000000000000000000000000000000081526004810184905230906001600160a01b03831690636352211e90602401602060405180830381865afa158015610875573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108999190610e6e565b6001600160a01b0316146109155760405162461bcd60e51b815260206004820152603d60248201527f4b4d61726b6574706c6163653a204c616e64206973206e6f7420617661696c6160448201527f626c6520286d61726b6574706c616365206e6f74206f776e696e67292100000060648201526084016104b5565b600480546003546040517fb9186d7d0000000000000000000000000000000000000000000000000000000081529283018690526001600160a01b0391821692911690600090829063b9186d7d90602401602060405180830381865afa158015610982573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109a69190610e8b565b90506000836001600160a01b03166323b872dd33600560009054906101000a90046001600160a01b0316600654868b6109df9190610ea4565b6109e99190610ea4565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e086901b1681526001600160a01b03938416600482015292909116602483015260448201526064016020604051808303816000875af1158015610a55573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a799190610e4c565b905080610aed5760405162461bcd60e51b8152602060048201526024808201527f4b4d61726b6574706c6163653a206e6f7420656e6f756768206355534420667560448201527f6e6473210000000000000000000000000000000000000000000000000000000060648201526084016104b5565b6040517f7a415e6900000000000000000000000000000000000000000000000000000000815233600482015260248101889052604481018790526001600160a01b03841690637a415e6990606401600060405180830381600087803b158015610b5557600080fd5b505af1158015610b69573d6000803e3d6000fd5b505060018055505050505050505050565b610b82610c5d565b6005546001600160a01b0382811691161461034557600554610bac906001600160a01b031661063d565b600580546001600160a01b0319166001600160a01b0383161790556103458161063d565b610bd8610c5d565b6001600160a01b038116610c545760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f646472657373000000000000000000000000000000000000000000000000000060648201526084016104b5565b61034581610cb7565b6000546001600160a01b031633146104325760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016104b5565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6001600160a01b038116811461034557600080fd5b600080600080600060808688031215610d3457600080fd5b8535610d3f81610d07565b94506020860135610d4f81610d07565b935060408601359250606086013567ffffffffffffffff80821115610d7357600080fd5b818801915088601f830112610d8757600080fd5b813581811115610d9657600080fd5b896020828501011115610da857600080fd5b9699959850939650602001949392505050565b600060208284031215610dcd57600080fd5b8135610dd881610d07565b9392505050565b600060208284031215610df157600080fd5b5035919050565b60008060408385031215610e0b57600080fd5b50508035926020909101359150565b8281526040810160048310610e3f57634e487b7160e01b600052602160045260246000fd5b8260208301529392505050565b600060208284031215610e5e57600080fd5b81518015158114610dd857600080fd5b600060208284031215610e8057600080fd5b8151610dd881610d07565b600060208284031215610e9d57600080fd5b5051919050565b8082028115828204841417610ec957634e487b7160e01b600052601160045260246000fd5b9291505056fea26469706673582212203fda2a8698913721fa9ae68399f2f5058f6ac7536b84bde82d7b0f5f59756bbf64736f6c63430008110033