Guest User

Untitled

a guest
Mar 18th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. ## Workflow
  2.  
  3. `old_token_contract` is ERC20 compliant.
  4. `new_token_contract` is `TokenSwap`
  5.  
  6. #### Token swap contract
  7.  
  8. ```
  9. import "zeppelin-solidity/contracts/token/ERC20/StandardToken.sol";
  10.  
  11. contract TokenSwap is StandardToken {
  12. event Swap(address indexed to, uint256 amount);
  13.  
  14. address public old_token_contract;
  15.  
  16. function TokenSwap(address _old) public {
  17. old_token_contract = _old;
  18. }
  19.  
  20. function swapTokens(uint256 amount) public {
  21. // require: balanceOf msg.sender in old_token_contract is at least "amount"
  22. // require: allowance of new_token_contract to spend "amount" tokens of msg.sender
  23. // require: burn old tokens (transferFrom new_token_contract to 0x0)
  24. // mint new_token_contract "amount" tokens to msg.sender
  25. }
  26.  
  27. function mintTokens(address _to, uint256 _amount) internal {
  28. // add "amount" to totalSupply_ of this token
  29. // add "amount" to balances[_to]
  30. }
  31. }
  32. ```
  33.  
  34. 1. `new_token_contract` inherits `TokenSwap` contract
  35.  
  36. 2. Users `approve` the `new_token_contract` to spend their `old_token_contract` tokens
  37.  
  38. `approve(new_token_contract_address, amount)`
  39.  
  40. 3. Users call `swapTokens` in the `TokenSwap.sol` contract, with the amount they want to swap
  41.  
  42. `TokenSwap.swapTokens(amount)`
Add Comment
Please, Sign In to add comment