[Ethereum] How to swap old tokens with new ones on a new Solidity contract and restrict a particular wallet

contract-designcontract-developmentremixsolidity

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 🙂

Best Answer

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.

Related Topic