Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Workflow
- `old_token_contract` is ERC20 compliant.
- `new_token_contract` is `TokenSwap`
- #### Token swap contract
- ```
- import "zeppelin-solidity/contracts/token/ERC20/StandardToken.sol";
- contract TokenSwap is StandardToken {
- event Swap(address indexed to, uint256 amount);
- address public old_token_contract;
- function TokenSwap(address _old) public {
- old_token_contract = _old;
- }
- function swapTokens(uint256 amount) public {
- // require: balanceOf msg.sender in old_token_contract is at least "amount"
- // require: allowance of new_token_contract to spend "amount" tokens of msg.sender
- // require: burn old tokens (transferFrom new_token_contract to 0x0)
- // mint new_token_contract "amount" tokens to msg.sender
- }
- function mintTokens(address _to, uint256 _amount) internal {
- // add "amount" to totalSupply_ of this token
- // add "amount" to balances[_to]
- }
- }
- ```
- 1. `new_token_contract` inherits `TokenSwap` contract
- 2. Users `approve` the `new_token_contract` to spend their `old_token_contract` tokens
- `approve(new_token_contract_address, amount)`
- 3. Users call `swapTokens` in the `TokenSwap.sol` contract, with the amount they want to swap
- `TokenSwap.swapTokens(amount)`
Add Comment
Please, Sign In to add comment