🗺️Deposit/Withdraw

PhiMap contract allows users to manage Philand

Overview

To put your objects on your land, you have to deposit the objects to PHI's Map Contract, and switch to edit mode by clicking "EDIT" button. When you want to get back your objects to your wallet, you have to remove your objects from your land and withdraw those.

Contract

PhiMap: '0xe8b6395d223C9D3D85e162f2cb2023bC9088a908', https://polygonscan.com/address/0xe8b6395d223C9D3D85e162f2cb2023bC9088a908

Deposit Struct

/* --------------------------------- DEPOSIT -------------------------------- */
    struct Deposit {
        address contractAddress;
        uint256 tokenId;
    }
    struct DepositInfo {
        address contractAddress;
        uint256 tokenId;
        uint256 amount;
        uint256 used;
    }

Deposit

When writing, it is necessary to deposit the appropriate number of objects in advance.

The deposit function in the phimap contract is implemented as follows:

    /*
     * @title deposit
     * @notice Functions for deposit token to this(map) contract
     * @param name : ens name
     * @param contractAddress : deposit contract address
     * @param tokenId : deposit token id
     * @param amount : deposit amount
     * @dev Need approve. With deposit, ENS transfer allows user to transfer philand with token.
     */
    function _depositObject(
        string memory name,
        address msgSender,
        address contractAddress,
        uint256 tokenId,
        uint256 amount
    ) internal {
        uint256 currentDepositAmount = depositInfo[name][contractAddress][tokenId].amount;
        uint256 updateDepositAmount = currentDepositAmount + amount;
        uint256 currentDepositUsed = depositInfo[name][contractAddress][tokenId].used;

        if (!_whitelist[contractAddress]) revert InvalidWhitelist();
        IObject _object = IObject(contractAddress);
        uint256 userBalance = _object.balanceOf(msgSender, tokenId);
        if (userBalance < updateDepositAmount - currentDepositAmount) {
            revert NotBalanceEnough({
                name: name,
                sender: msgSender,
                contractAddress: contractAddress,
                tokenId: tokenId,
                currentDepositAmount: currentDepositAmount,
                currentDepositUsed: currentDepositUsed,
                updateDepositAmount: updateDepositAmount,
                userBalance: userBalance
            });
        }
        // Update the deposit amount.
        depositInfo[name][contractAddress][tokenId] = DepositInfo(
            contractAddress,
            tokenId,
            updateDepositAmount,
            currentDepositUsed
        );

        // Maintain a list of deposited contract addresses and token ids for checkAllDepositStatus.
        Deposit memory depositObjectInfo = Deposit(contractAddress, tokenId);
        uint256 userObjectDepositLength = userObjectDeposit[name].length;
        bool check = false;
        for (uint256 i = 0; i < userObjectDepositLength; ++i) {
            Deposit memory depositObjectToken = userObjectDeposit[name][i];
            if (depositObjectToken.contractAddress == contractAddress && depositObjectToken.tokenId == tokenId) {
                check = true;
                break;
            }
        }
        // If user want to deposit new tokenId , add it.
        if (!check) {
            userObjectDeposit[name].push(depositObjectInfo);
        }

        _object.safeTransferFrom(msgSender, address(this), tokenId, amount, "0x00");
        emit DepositSuccess(msgSender, name, contractAddress, tokenId, amount);
    }

Withdraw

By performing a withdrawal operation, you can return the objectNFT to your wallet.

You should be aware that you can only withdraw the amount that is remaining after subtracting the amount that you have already used.

    /*
     * @title withdrawObject
     * @notice Functions for deposit token from this(map) contract
     * @param name : ens name
     * @param contractAddress : deposit contract address
     * @param tokenId : deposit token id
     * @param amount : deposit amount
     * @dev Return ERROR when attempting to withdraw over unused
     */
    function _withdrawObject(
        string memory name,
        address contractAddress,
        uint256 tokenId,
        uint256 amount
    ) internal {
        uint256 used = depositInfo[name][contractAddress][tokenId].used;
        uint256 mapUnusedAmount = depositInfo[name][contractAddress][tokenId].amount - used;
        // Cannot withdraw already used objects.
        if (amount > mapUnusedAmount) {
            revert withdrawError(amount, mapUnusedAmount);
        }
        IObject _object = IObject(contractAddress);
        depositInfo[name][contractAddress][tokenId].amount =
            depositInfo[name][contractAddress][tokenId].amount -
            amount;
        _object.safeTransferFrom(address(this), msg.sender, tokenId, amount, "0x00");
        emit WithdrawSuccess(msg.sender, name, contractAddress, tokenId, amount);
    }

To edit your land, you need to specify the land and deposit an object.

Check Deposit Status

The current deposit status for each land can be checked by executing the following function. If you have access to the philand's frontend, you can also easily check the deposit status for each land from there.

    /*
     * @title checkDepositStatus
     * @notice Functions for check deposit status for specific token
     * @param name : ens name
     * @param contractAddress : contract address you want to check
     * @param tokenId : token id you want to check
     * @dev Check deposit information
     */
    function checkDepositStatus(
        string memory name,
        address contractAddress,
        uint256 tokenId
    ) external view returns (DepositInfo memory) {
        return depositInfo[name][contractAddress][tokenId];
    }

    /*
     * @title checkAllDepositStatus
     * @notice Functions for check deposit status for all token
     * @param name : ens name
     * @dev Check users' all deposit information
     */
    function checkAllDepositStatus(string memory name) external view returns (DepositInfo[] memory) {
        uint256 userObjectDepositLength = userObjectDeposit[name].length;
        DepositInfo[] memory deposits = new DepositInfo[](userObjectDepositLength);
        for (uint256 i = 0; i < userObjectDepositLength; ++i) {
            Deposit memory depositObjectInfo = userObjectDeposit[name][i];
            DepositInfo memory tempItem = depositInfo[name][depositObjectInfo.contractAddress][
                depositObjectInfo.tokenId
            ];
            deposits[i] = tempItem;
        }
        return deposits;
    }

Why we need deposit Object to Philand?

There are several reasons for this, but the main reason is that if writing is allowed simply by having an object in a wallet, an unlimited number of writings can be made to the land by transferring the NFT after writing.

Philand can transfer to Other player with Deposit Objects

You can gift Philand to your friend by sending your ENS

Last updated