├── ITRC20.sol ├── Roles.sol ├── MinterRole.sol ├── SafeMath.sol ├── CryptoxChain.sol └── TRC20.sol /ITRC20.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.23; 2 | 3 | /** 4 | * @title TRC20 interface (compatible with ERC20 interface) 5 | * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md 6 | */ 7 | interface ITRC20 { 8 | function totalSupply() external view returns (uint256); 9 | 10 | function balanceOf(address who) external view returns (uint256); 11 | 12 | function allowance(address owner, address spender) 13 | external view returns (uint256); 14 | 15 | function transfer(address to, uint256 value) external returns (bool); 16 | 17 | function approve(address spender, uint256 value) 18 | external returns (bool); 19 | 20 | function transferFrom(address from, address to, uint256 value) 21 | external returns (bool); 22 | 23 | event Transfer( 24 | address indexed from, 25 | address indexed to, 26 | uint256 value 27 | ); 28 | 29 | event Approval( 30 | address indexed owner, 31 | address indexed spender, 32 | uint256 value 33 | ); 34 | } 35 | -------------------------------------------------------------------------------- /Roles.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.23; 2 | 3 | /** 4 | * @title Roles 5 | * @dev Library for managing addresses assigned to a Role. 6 | */ 7 | library Roles { 8 | struct Role { 9 | mapping (address => bool) bearer; 10 | } 11 | 12 | /** 13 | * @dev give an account access to this role 14 | */ 15 | function add(Role storage role, address account) internal { 16 | require(account != address(0)); 17 | require(!has(role, account)); 18 | 19 | role.bearer[account] = true; 20 | } 21 | 22 | /** 23 | * @dev remove an account's access to this role 24 | */ 25 | function remove(Role storage role, address account) internal { 26 | require(account != address(0)); 27 | require(has(role, account)); 28 | 29 | role.bearer[account] = false; 30 | } 31 | 32 | /** 33 | * @dev check if an account has this role 34 | * @return bool 35 | */ 36 | function has(Role storage role, address account) internal view returns (bool) { 37 | require(account != address(0)); 38 | return role.bearer[account]; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /MinterRole.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.23; 2 | 3 | import "./Roles.sol"; 4 | 5 | contract MinterRole { 6 | using Roles for Roles.Role; 7 | 8 | event MinterAdded(address indexed account); 9 | event MinterRemoved(address indexed account); 10 | 11 | Roles.Role private _minters; 12 | 13 | constructor () internal { 14 | _addMinter(msg.sender); 15 | } 16 | 17 | modifier onlyMinter() { 18 | require(isMinter(msg.sender)); 19 | _; 20 | } 21 | 22 | function isMinter(address account) public view returns (bool) { 23 | return _minters.has(account); 24 | } 25 | 26 | function addMinter(address account) public onlyMinter { 27 | _addMinter(account); 28 | } 29 | 30 | function renounceMinter() public { 31 | _removeMinter(msg.sender); 32 | } 33 | 34 | function _addMinter(address account) internal { 35 | _minters.add(account); 36 | emit MinterAdded(account); 37 | } 38 | 39 | function _removeMinter(address account) internal { 40 | _minters.remove(account); 41 | emit MinterRemoved(account); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /SafeMath.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.23; 2 | 3 | /** 4 | * @title SafeMath 5 | * @dev Math operations with safety checks that revert on error 6 | */ 7 | library SafeMath { 8 | 9 | /** 10 | * @dev Multiplies two numbers, reverts on overflow. 11 | */ 12 | function mul(uint256 a, uint256 b) internal pure returns (uint256) { 13 | // Gas optimization: this is cheaper than requiring 'a' not being zero, but the 14 | // benefit is lost if 'b' is also tested. 15 | // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522 16 | if (a == 0) { 17 | return 0; 18 | } 19 | 20 | uint256 c = a * b; 21 | require(c / a == b); 22 | 23 | return c; 24 | } 25 | 26 | /** 27 | * @dev Integer division of two numbers truncating the quotient, reverts on division by zero. 28 | */ 29 | function div(uint256 a, uint256 b) internal pure returns (uint256) { 30 | require(b > 0); // Solidity only automatically asserts when dividing by 0 31 | uint256 c = a / b; 32 | // assert(a == b * c + a % b); // There is no case in which this doesn't hold 33 | 34 | return c; 35 | } 36 | 37 | /** 38 | * @dev Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend). 39 | */ 40 | function sub(uint256 a, uint256 b) internal pure returns (uint256) { 41 | require(b <= a); 42 | uint256 c = a - b; 43 | 44 | return c; 45 | } 46 | 47 | /** 48 | * @dev Adds two numbers, reverts on overflow. 49 | */ 50 | function add(uint256 a, uint256 b) internal pure returns (uint256) { 51 | uint256 c = a + b; 52 | require(c >= a); 53 | 54 | return c; 55 | } 56 | 57 | /** 58 | * @dev Divides two numbers and returns the remainder (unsigned integer modulo), 59 | * reverts when dividing by zero. 60 | */ 61 | function mod(uint256 a, uint256 b) internal pure returns (uint256) { 62 | require(b != 0); 63 | return a % b; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /CryptoxChain.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.23; 2 | 3 | import "./TRC20.sol"; 4 | import "./MinterRole.sol"; 5 | 6 | /** 7 | * @title TRC20Detailed token 8 | * Speed test 9 | * @dev The decimals are only for visualization purposes. 10 | * All the operations are done using the smallest and indivisible token unit, 11 | * just as on TRON all the operations are done in sun. 12 | * 13 | * Example inherits from basic TRC20 implementation but can be modified to 14 | * extend from other ITRC20-based tokens: 15 | * https://github.com/OpenZeppelin/openzeppelin-solidity/issues/1536 16 | */ 17 | contract CryptoxChain is TRC20, MinterRole { 18 | string private _name; 19 | string private _symbol; 20 | uint8 private _decimals; 21 | 22 | constructor (string name, string symbol, uint8 decimals) public { 23 | _name = name; 24 | _symbol = symbol; 25 | _decimals = decimals; 26 | } 27 | 28 | /** 29 | * @return the name of the token. 30 | */ 31 | function name() public view returns (string) { 32 | return _name; 33 | } 34 | 35 | /** 36 | * @return the symbol of the token. 37 | */ 38 | function symbol() public view returns (string) { 39 | return _symbol; 40 | } 41 | 42 | /** 43 | * @return the number of decimals of the token. 44 | */ 45 | function decimals() public view returns (uint8) { 46 | return _decimals; 47 | } 48 | 49 | /** 50 | * @dev Function to mint tokens 51 | * @param to The address that will receive the minted tokens. 52 | * @param value The amount of tokens to mint. 53 | * @return A boolean that indicates if the operation was successful. 54 | */ 55 | function mint(address to, uint256 value) public onlyMinter returns (bool) { 56 | _mint(to, value); 57 | return true; 58 | } 59 | 60 | /** 61 | * @dev Burns a specific amount of tokens. 62 | * @param value The amount of token to be burned. 63 | */ 64 | function burn(uint256 value) public { 65 | _burn(msg.sender, value); 66 | } 67 | 68 | /** 69 | * @dev Burns a specific amount of tokens from the target address and decrements allowance 70 | * @param from address The address which you want to send tokens from 71 | * @param value uint256 The amount of token to be burned 72 | */ 73 | function burnFrom(address from, uint256 value) public { 74 | _burnFrom(from, value); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /TRC20.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.23; 2 | 3 | import "./ITRC20.sol"; 4 | import "./SafeMath.sol"; 5 | 6 | /** 7 | * @title Standard TRC20 token (compatible with ERC20 token) 8 | * 9 | * @dev Implementation of the basic standard token. 10 | * https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md 11 | * Originally based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol 12 | */ 13 | contract TRC20 is ITRC20 { 14 | using SafeMath for uint256; 15 | 16 | mapping (address => uint256) private _balances; 17 | 18 | mapping (address => mapping (address => uint256)) private _allowed; 19 | 20 | uint256 private _totalSupply; 21 | 22 | /** 23 | * @dev Total number of tokens in existence 24 | */ 25 | function totalSupply() public view returns (uint256) { 26 | return _totalSupply; 27 | } 28 | 29 | /** 30 | * @dev Gets the balance of the specified address. 31 | * @param owner The address to query the balance of. 32 | * @return An uint256 representing the amount owned by the passed address. 33 | */ 34 | function balanceOf(address owner) public view returns (uint256) { 35 | return _balances[owner]; 36 | } 37 | 38 | /** 39 | * @dev Function to check the amount of tokens that an owner allowed to a spender. 40 | * @param owner address The address which owns the funds. 41 | * @param spender address The address which will spend the funds. 42 | * @return A uint256 specifying the amount of tokens still available for the spender. 43 | */ 44 | function allowance( 45 | address owner, 46 | address spender 47 | ) 48 | public 49 | view 50 | returns (uint256) 51 | { 52 | return _allowed[owner][spender]; 53 | } 54 | 55 | /** 56 | * @dev Transfer token for a specified address 57 | * @param to The address to transfer to. 58 | * @param value The amount to be transferred. 59 | */ 60 | function transfer(address to, uint256 value) public returns (bool) { 61 | _transfer(msg.sender, to, value); 62 | return true; 63 | } 64 | 65 | /** 66 | * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. 67 | * Beware that changing an allowance with this method brings the risk that someone may use both the old 68 | * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this 69 | * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: 70 | * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 71 | * @param spender The address which will spend the funds. 72 | * @param value The amount of tokens to be spent. 73 | */ 74 | function approve(address spender, uint256 value) public returns (bool) { 75 | require(spender != address(0)); 76 | 77 | _allowed[msg.sender][spender] = value; 78 | emit Approval(msg.sender, spender, value); 79 | return true; 80 | } 81 | 82 | /** 83 | * @dev Transfer tokens from one address to another 84 | * @param from address The address which you want to send tokens from 85 | * @param to address The address which you want to transfer to 86 | * @param value uint256 the amount of tokens to be transferred 87 | */ 88 | function transferFrom( 89 | address from, 90 | address to, 91 | uint256 value 92 | ) 93 | public 94 | returns (bool) 95 | { 96 | _allowed[from][msg.sender] = _allowed[from][msg.sender].sub(value); 97 | _transfer(from, to, value); 98 | return true; 99 | } 100 | 101 | /** 102 | * @dev Increase the amount of tokens that an owner allowed to a spender. 103 | * approve should be called when allowed_[_spender] == 0. To increment 104 | * allowed value is better to use this function to avoid 2 calls (and wait until 105 | * the first transaction is mined) 106 | * From MonolithDAO Token.sol 107 | * @param spender The address which will spend the funds. 108 | * @param addedValue The amount of tokens to increase the allowance by. 109 | */ 110 | function increaseAllowance( 111 | address spender, 112 | uint256 addedValue 113 | ) 114 | public 115 | returns (bool) 116 | { 117 | require(spender != address(0)); 118 | 119 | _allowed[msg.sender][spender] = ( 120 | _allowed[msg.sender][spender].add(addedValue)); 121 | emit Approval(msg.sender, spender, _allowed[msg.sender][spender]); 122 | return true; 123 | } 124 | 125 | /** 126 | * @dev Decrease the amount of tokens that an owner allowed to a spender. 127 | * approve should be called when allowed_[_spender] == 0. To decrement 128 | * allowed value is better to use this function to avoid 2 calls (and wait until 129 | * the first transaction is mined) 130 | * From MonolithDAO Token.sol 131 | * @param spender The address which will spend the funds. 132 | * @param subtractedValue The amount of tokens to decrease the allowance by. 133 | */ 134 | function decreaseAllowance( 135 | address spender, 136 | uint256 subtractedValue 137 | ) 138 | public 139 | returns (bool) 140 | { 141 | require(spender != address(0)); 142 | 143 | _allowed[msg.sender][spender] = ( 144 | _allowed[msg.sender][spender].sub(subtractedValue)); 145 | emit Approval(msg.sender, spender, _allowed[msg.sender][spender]); 146 | return true; 147 | } 148 | 149 | /** 150 | * @dev Transfer token for a specified addresses 151 | * @param from The address to transfer from. 152 | * @param to The address to transfer to. 153 | * @param value The amount to be transferred. 154 | */ 155 | function _transfer(address from, address to, uint256 value) internal { 156 | require(to != address(0)); 157 | 158 | _balances[from] = _balances[from].sub(value); 159 | _balances[to] = _balances[to].add(value); 160 | emit Transfer(from, to, value); 161 | } 162 | 163 | /** 164 | * @dev Internal function that mints an amount of the token and assigns it to 165 | * an account. This encapsulates the modification of balances such that the 166 | * proper events are emitted. 167 | * @param account The account that will receive the created tokens. 168 | * @param value The amount that will be created. 169 | */ 170 | function _mint(address account, uint256 value) internal { 171 | require(account != address(0)); 172 | 173 | _totalSupply = _totalSupply.add(value); 174 | _balances[account] = _balances[account].add(value); 175 | emit Transfer(address(0), account, value); 176 | } 177 | 178 | /** 179 | * @dev Internal function that burns an amount of the token of a given 180 | * account. 181 | * @param account The account whose tokens will be burnt. 182 | * @param value The amount that will be burnt. 183 | */ 184 | function _burn(address account, uint256 value) internal { 185 | require(account != address(0)); 186 | 187 | _totalSupply = _totalSupply.sub(value); 188 | _balances[account] = _balances[account].sub(value); 189 | emit Transfer(account, address(0), value); 190 | } 191 | 192 | /** 193 | * @dev Internal function that burns an amount of the token of a given 194 | * account, deducting from the sender's allowance for said account. Uses the 195 | * internal burn function. 196 | * @param account The account whose tokens will be burnt. 197 | * @param value The amount that will be burnt. 198 | */ 199 | function _burnFrom(address account, uint256 value) internal { 200 | // Should https://github.com/OpenZeppelin/zeppelin-solidity/issues/707 be accepted, 201 | // this function needs to emit an event with the updated approval. 202 | _allowed[account][msg.sender] = _allowed[account][msg.sender].sub( 203 | value); 204 | _burn(account, value); 205 | } 206 | } 207 | --------------------------------------------------------------------------------