0

Is it possible to wrap and track a ERC20 token amount in another token? Would I need to use ERC-721 to do this? Let's say I send my ERC20 token to a specific smart contract which will wrap it in a new token and send that new token back to me (this new token only tracks the balance of the ERC20 token that it is wrapping around).

0

Is it possible to wrap and track a ERC20 token amount in another token?

Yep, that's exactly what this wrapper does, it wraps an ERC1155 token in an ERC20 token contract:

https://github.com/yashnaman/augur_foundry

the relevant part:

contract ERC20Wrapper is ERC20, ERC1155Receiver {
    uint256 public tokenId;
    IShareToken public shareToken;
    IERC20 public cash;
    address public augurFoundry;

    /**
     * @dev sets values for
     * @param _augurFoundry A trusted factory contract so that users can wrap multiple tokens in one
     * transaction without giving individual approvals
     * @param _shareToken address of shareToken for which this wrapper is for
     * @param _cash DAI
     * @param _tokenId id of market outcome this wrapper is for
     * @param _name a descriptive name mentioning market and outcome
     * @param _symbol symbol
     * @param _decimals decimals
     */
    constructor(
        address _augurFoundry,
        IShareToken _shareToken,
        IERC20 _cash,
        uint256 _tokenId,
        string memory _name,
        string memory _symbol,
        uint8 _decimals
    ) public ERC20(_name, _symbol) {
        _setupDecimals(_decimals);
        augurFoundry = _augurFoundry;
        tokenId = _tokenId;
        shareToken = _shareToken;
        cash = _cash;
    }

    /**@dev A function that gets ERC1155s and mints ERC20s
     * Requirements:
     *
     * - if the msg.sender is not augurFoundry then it needs to have given setApprovalForAll
     *  to this contract (if the msg.sender is augur foundry then we trust it and know that
     *  it would have transferred the ERC1155s to this contract before calling it)
     * @param _account account the newly minted ERC20s will go to
     * @param _amount amount of tokens to be wrapped
     */
    function wrapTokens(address _account, uint256 _amount) public {
        if (msg.sender != augurFoundry) {
            shareToken.safeTransferFrom(
                msg.sender,
                address(this),
                tokenId,
                _amount,
                ""
            );
        }
        _mint(_account, _amount);
    }

    /**@dev A function that burns ERC20s and gives back ERC1155s
     * Requirements:
     *
     * - if the msg.sender is not augurFoundry or _account then the caller must have allowance for ``_account``'s tokens of at least
     * `amount`.
     * - if the market has finalized then claim() function should be called.
     * @param _account account the newly minted ERC20s will go to
     * @param _amount amount of tokens to be unwrapped
     */
    function unWrapTokens(address _account, uint256 _amount) public {
        if (msg.sender != _account && msg.sender != augurFoundry) {
            uint256 decreasedAllowance = allowance(_account, msg.sender).sub(
                _amount,
                "ERC20: burn amount exceeds allowance"
            );
            _approve(_account, msg.sender, decreasedAllowance);
        }
        _burn(_account, _amount);

        shareToken.safeTransferFrom(
            address(this),
            _account,
            tokenId,
            _amount,
            ""
        );
    }

which will wrap it in a new token and send that new token back to me

I hope you are aware that tokens aren't things that you could send from one contract to annother via some medium. A token is a contract, it is not moving anywhere. When we say we send tokens, what happens is that inside this contract the map of balances is updated with new value. Neither any actual transfer of some funds is going in or out when we say Transfer a token, everything is happening inside that contract only.

2
  • Yes I understand, however, I'm not sure if this is the answer I was looking for. Is It possible to wrap i.e. a regular ERC20 into a wrappedERC20, without using ERC1155 or ERC721? or is a token ID necessary? – NowsyMe Jan 29 at 17:30
  • @NowsyMe any token is wrapped the same way, would it be ERC721 or ERC1155 or ERC20 the answer describes the standard way to wrap tokens. The tokens are wrapped by creating another contract that buys source token and holding source token forever until unwrap back is executed. All the exchange is taking place in the "wrapped" form. I am not sure what kind of answer you was looking for? – Nulik Jan 30 at 12:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.