Skip to content

Commit

Permalink
Make migration contract not to depend from standard token
Browse files Browse the repository at this point in the history
  • Loading branch information
facuspagnuolo committed Jul 11, 2018
1 parent 624cf45 commit db9db8e
Show file tree
Hide file tree
Showing 4 changed files with 1,768 additions and 1,747 deletions.
24 changes: 24 additions & 0 deletions contracts/mocks/MigratedERC20Mock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
pragma solidity ^0.4.24;

import "../token/ERC20/StandardToken.sol";
import "../token/ERC20/MigratableERC20.sol";

/**
* @title MigratedERC20Mock
* @dev This contract is a mock to test how a token could be migrated using the MigratableERC20 contract
*/
contract MigratedERC20Mock is MigratableERC20, StandardToken {

constructor(ERC20 _legacyToken) MigratableERC20(_legacyToken) public {}

/**
* @dev Internal minting function
* This function will be removed in favour of our new upcoming version of StandardToken
*/
function _mint(address _to, uint256 _amount) internal {
require(_to != address(0));
totalSupply_ = totalSupply_.add(_amount);
balances[_to] = balances[_to].add(_amount);
emit Transfer(address(0), _to, _amount);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ pragma solidity ^0.4.24;

import "./ERC20.sol";
import "./SafeERC20.sol";
import "./StandardToken.sol";

/**
* @title Opt in ERC20 migration
* @title MigratableERC20
* @dev This strategy carries out an optional migration of the token balances. This migration is performed and paid for
* @dev by the token holders. The new token contract starts with no initial supply and no balances. The only way to
* @dev "mint" the new tokens is for users to "turn in" their old ones. This is done by first approving the amount they
* @dev want to migrate via `ERC20.approve(newTokenAddress, amountToMigrate)` and then calling a function of the new
* @dev token called `migrateTokens`. The old tokens are sent to a burn address, and the holder receives an equal amount
* @dev in the new contract.
*/
contract OptInERC20Migration is StandardToken {
contract MigratableERC20 {
using SafeERC20 for ERC20;

/// Burn address where the old tokens are going to be transferred
Expand Down Expand Up @@ -56,17 +55,12 @@ contract OptInERC20Migration is StandardToken {
*/
function migrateTokenTo(address _to, uint256 _amount) public {
_mint(_to, _amount);
legacyToken.transferFrom(msg.sender, BURN_ADDRESS, _amount);
legacyToken.safeTransferFrom(msg.sender, BURN_ADDRESS, _amount);
}

/**
* @dev Private minting function
* This function will be removed in favour of our new upcoming version of StandardToken
* @dev Internal minting function
* This function must be overwritten by the implementation
*/
function _mint(address _to, uint256 _amount) private {
require(_to != address(0));
totalSupply_ = totalSupply_.add(_amount);
balances[_to] = balances[_to].add(_amount);
emit Transfer(address(0), _to, _amount);
}
function _mint(address _to, uint256 _amount) internal;
}
Loading

0 comments on commit db9db8e

Please sign in to comment.