How to migrate an old token to a new Token

I’m actually working to a smart contract where I migrate an old token to a new token :

First I need to mint with conversion 1:1 and then burn the old token.

I start with this contract but I’m not sure about it :

// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;

import Token from "../Token.sol";

contract MigrationToken {

  // Old Token
  address public tokenV1;

  // New Token
  address public tokenv2;

  uint256 public endBlock;

    address _tokenV1,
    address _tokenV2,
    uint256 _endBlock

  ) public {
    tokenV1 = _tokenV1;
    tokenv2 = _tokenV2;
    endBlock = _endBlock;

  event MigrateToV2(address indexed user,uint256 amount);

  function migratationNewToken(uint256 _inputAmt) public {

    require(block.number < endBlock, "too late :(");

    Token(tokenv2).mint(msg.sender, _inputAmt);
    emit MigrateToV2(msg.sender,_inputAmt);

1 Like

I think this is a great idea and a different solution to the “airdropping” approach.

You will need to call the balanceOf function of the old token. Which will determine how much new token the user will get.

Then burn the old token’s balance found through the balanceOf function.

Then mint the new tokens according to how many were burned.

I think your approach is fine too, as you know the Balance Of, because you are transferring already.

You may want to implement some safeties to stop manipulative users.

For example:

Person A has 1000 Old Token.
Person B has 100 Old Token, but learns about the minting for your New Token.
Person A does not know about the New Token.
Person B asks Person A for his Old Token.
Person B gets more Old Token, because Person A did not know about the New Token

If you don’t care about that then I think your approach is fine.