Reorganizing contracts and adding NFTTypes

This commit is contained in:
Richard Ramos 2018-07-31 10:31:49 -04:00
parent fc6f49523b
commit 9309f2bfac
8 changed files with 22 additions and 55 deletions

View File

@ -63,8 +63,11 @@
"PlasmaERC20":{ "deploy": false },
"PlasmaSNT": {
"instanceOf": "PlasmaERC20",
"args": ["$RootChain", "$SNT", "5000000000000000000", "PlasmaSNT", "PSNT"],
"onDeploy": ["ValidatorManagerContract.methods.toggleToken($PlasmaSNT).send()"]
"args": ["$RootChain", "$SNT", "PlasmaSNT", "PSNT"],
"onDeploy": [
"ValidatorManagerContract.methods.toggleToken($PlasmaSNT).send()",
"PlasmaSNT.methods.setExchangeRate(0, 5000000000000000000).send()"
]
}
}
},

View File

@ -1,40 +0,0 @@
pragma solidity ^0.4.24;
import "openzeppelin-solidity/contracts/token/ERC721/ERC721Token.sol";
contract CryptoCards is ERC721Token("CryptoCards", "CCC") {
address plasma;
constructor (address _plasma) public {
plasma = _plasma;
}
function register() external {
// Give each new player 5 cards
for (int j = 0; j < 5; j++) {
create();
}
}
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 create() private {
uint256 tokenId = allTokens.length + 1;
_mint(msg.sender, tokenId);
}
}

View File

@ -8,11 +8,10 @@ contract PlasmaERC20 is ERC721Token, Owned {
address plasma;
ERC20Token token;
uint exchangeRate;
mapping(uint8 => uint) exchangeRate;
constructor (address _plasma,
address _token,
uint _exchangeRate,
string _name,
string _symbol
)
@ -20,17 +19,22 @@ contract PlasmaERC20 is ERC721Token, Owned {
public {
plasma = _plasma;
token = ERC20Token(_token);
exchangeRate = _exchangeRate;
}
mapping(uint => uint8) NFTTypes;
mapping(uint => uint) ERC20Balances;
function depositERC20() public {
require(token.allowance(msg.sender, address(this)) >= exchangeRate);
require(token.transferFrom(msg.sender, address(this), exchangeRate));
function depositERC20(uint8 _NFTType) public {
uint rate = exchangeRate[_NFTType];
require(rate > 0);
require(token.allowance(msg.sender, address(this)) >= rate);
require(token.transferFrom(msg.sender, address(this), rate));
uint256 tokenId = allTokens.length + 1;
ERC20Balances[tokenId] = exchangeRate;
ERC20Balances[tokenId] = rate;
NFTTypes[tokenId] = _NFTType;
_mint(msg.sender, tokenId);
}
@ -56,8 +60,8 @@ contract PlasmaERC20 is ERC721Token, Owned {
safeTransferFrom(msg.sender, plasma, tokenId);
}
function setExchangeRate(uint _newRate) onlyOwner public {
exchangeRate = _newRate;
function setExchangeRate(uint _newRate, uint8 _NFTType) onlyOwner public {
exchangeRate[_NFTType] = _newRate;
}
}

View File

@ -3,13 +3,13 @@ pragma solidity ^0.4.24;
// Zeppelin Imports
import "openzeppelin-solidity/contracts/token/ERC721/ERC721.sol";
import "openzeppelin-solidity/contracts/token/ERC721/ERC721Receiver.sol";
import "openzeppelin-solidity/contracts/math/SafeMath.sol";
// Lib deps
import "./Transaction.sol";
import "./ECVerify.sol";
import "../common/ECVerify.sol";
import "../common/SafeMath.sol";
import "./SparseMerkleTree.sol";
import "../common/SparseMerkleTree.sol";
import "./ValidatorManagerContract.sol";

View File

@ -1,6 +1,6 @@
pragma solidity ^0.4.24;
import "./RLP.sol";
import "../common/RLP.sol";
library Transaction {