Added token to convert from ERC20 to ERC721

This commit is contained in:
Richard Ramos 2018-07-31 10:03:31 -04:00
parent e2a4074e29
commit fc6f49523b
2 changed files with 69 additions and 6 deletions

View File

@ -59,13 +59,13 @@
"RootChain": { "RootChain": {
"args": ["$ValidatorManagerContract"] "args": ["$ValidatorManagerContract"]
}, },
"CryptoCards": { "CryptoCards": { "deploy": false },
"args": ["$RootChain"], "PlasmaERC20":{ "deploy": false },
"onDeploy": ["ValidatorManagerContract.methods.toggleToken($CryptoCards).send()"] "PlasmaSNT": {
"instanceOf": "PlasmaERC20",
"args": ["$RootChain", "$SNT", "5000000000000000000", "PlasmaSNT", "PSNT"],
"onDeploy": ["ValidatorManagerContract.methods.toggleToken($PlasmaSNT).send()"]
} }
} }
}, },
"testnet":{ "testnet":{

View File

@ -0,0 +1,63 @@
pragma solidity ^0.4.24;
import "openzeppelin-solidity/contracts/token/ERC721/ERC721Token.sol";
import "../common/Owned.sol";
import "../token/ERC20Token.sol";
contract PlasmaERC20 is ERC721Token, Owned {
address plasma;
ERC20Token token;
uint exchangeRate;
constructor (address _plasma,
address _token,
uint _exchangeRate,
string _name,
string _symbol
)
ERC721Token(_name, _symbol)
public {
plasma = _plasma;
token = ERC20Token(_token);
exchangeRate = _exchangeRate;
}
mapping(uint => uint) ERC20Balances;
function depositERC20() public {
require(token.allowance(msg.sender, address(this)) >= exchangeRate);
require(token.transferFrom(msg.sender, address(this), exchangeRate));
uint256 tokenId = allTokens.length + 1;
ERC20Balances[tokenId] = exchangeRate;
_mint(msg.sender, tokenId);
}
function withdrawERC20(uint tokenId) public {
require(ownerOf(tokenId) == msg.sender);
uint erc20Value = ERC20Balances[tokenId];
ERC20Balances[tokenId] = 0;
_burn(msg.sender, tokenId);
require(token.transferFrom(address(this), msg.sender, erc20Value));
}
function depositToPlasmaWithData(uint tokenId, bytes _data) public {
require(plasma != address(0));
safeTransferFrom(
msg.sender,
plasma,
tokenId,
_data);
}
function depositToPlasma(uint tokenId) public {
require(plasma != address(0));
safeTransferFrom(msg.sender, plasma, tokenId);
}
function setExchangeRate(uint _newRate) onlyOwner public {
exchangeRate = _newRate;
}
}