0

hope you can assist me on this scenario

few months ago a token has been created and dispatched to several wallet. Right now, the developer wants to add some better features for the users.

The users need to send same amount (let's call it 100) tokens to a new contract, where those 100 tokens are swapped for 100 new tokens.

The caveat is that the developer has lost a wallet holding some amount (about 30,000 tokens) of tokens which he would want to exclude from getting the new tokensin case if is found by someone.

Now the question is;

  1. How can a new contract receives X amount of old tokens.
  2. How can the amount sent be checked and send back new tokens of same value?.
  3. How restrict a particular wallet from getting the new tokens

So basically, i'm looking for a way to swap new coins from the old contract and exclude a particular wallet address..

(if you can also add a standard code too)

Thank you for helping me out :-)

1
  • I think you left #3 unfinished :P
    – natewelch_
    Feb 1, 2018 at 0:41

2 Answers 2

1

Unfortunately, I cannot comment on flygoing's answer, but here's a few things to notice:

  1. Withdraw old tokens balance by calling oldToken.trasnferFrom. Consider burning oldTokens, if appropriate, or send it to address(this). It'll allow you to perform double checks and ensure correctness.

  2. After exchanging oldToken consider checking changes of "before" and "after" balances. Do not blindly trust oldToken.trasnferFrom return value, check oldToken.balanceOf explicitly.

0

I'm not gonna write out a full contract to use, but here's a simple example contract/workflow using the approve/transferFrom workflow assuming the original token is ERC20 compliant. You'll have to implement the ERC20 aspects of the new token contract. There is also no way to stop people from sending from the missing wallet -> another wallet -> then upgrading the tokens. The best you could do is add a cut off date of when the last upgrade is possible.

import 'ERC20.sol`;

contract NewToken{
    ERC20 public oldToken;
    address public addressToIgnore;

    function NewToken(address _oldTokenAdddress, address _addressToIgnore){
        oldTokenAddress=_oldTokenAddress;
        addressToIgnore=_addressToIgnore;
    }

    function upgradeTokens(uint amountToUpgrade){
        require(amountToUpgrade<=oldToken.balanceOf(msg.sender));
        require(amountToUpgrade<=allowance(msg.sender, this));
        require(msg.sender!=addressToIgnore);
        if(transferFrom(msg.sender, 0x0, amountToUpgrade)){
            //Mint the new tokens
        }
    }
}

Here's the general flow:

  1. User calls approve(newTokenAddress, usersBalance) on the original token to allow the new token contract to take their balance.
  2. The user calls upgradeTokens(amountToUpgrade) on the new token contract.
  3. The new token contract verifies all is good, transfers the tokens from the user to the 0x0 address to burn them, and mints them new tokens

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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