pragma solidity 0.5.10;
/**
* MINA PROTOCOL
*
*
* The world's lightest blockchain, powered by participants.
*
* By design, the entire Mina blockchain is and will always be about 22kb - the size of a couple of tweets.
* So anyone with a smartphone will be able to sync and verify the network in seconds.
*
* About the Tech: https://minaprotocol.com/tech
* Knowledge Base: https://minaprotocol.com/get-started#knowledge-base
*
* Technical Whitepaper: https://minaprotocol.com/static/pdf/technicalWhitepaper.pdf
* Economics Whitepaper: https://minaprotocol.com/static/pdf/economicsWhitepaper.pdf
*
* Mina Protocol-media
* Official Website: https://minaprotocol.com
* Github: https://github.com/MinaProtocol/mina
* Twitter: https://twitter.com/minaprotocol
* Telegram: https://t.me/minaprotocol
* Forums: https://forums.minaprotocol.com/t/mina-protocol-chinese-resources/200
* Discord: https://discord.com/invite/RDQc43H
* Facebook: https://www.facebook.com/Mina-Protocol-108885454193665
* Reddit: https://www.reddit.com/r/MinaProtocol
* Wiki: https://minawiki.com/Main_Page
*/
/**
* @title SafeMath
* @dev Unsigned math operations with safety checks that revert on error.
*/
library SafeMath {
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a);
uint256 c = a - b;
return c;
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a);
return c;
}
}
/**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/
contract Ownable {
address internal _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() internal {
_owner = msg.sender;
emit OwnershipTransferred(address(0), _owner);
}
function owner() public view returns (address) {
return _owner;
}
modifier onlyOwner() {
require(isOwner(msg.sender), "Caller is not the owner");
_;
}
function isOwner(address account) public view returns (bool) {
return account == _owner;
}
function renounceOwnership() public onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0), "New owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
/**
* @title Roles
* @dev Library for managing addresses assigned to a Role.
*/
library Roles {
struct Role {
mapping (address => bool) bearer;
}
function add(Role storage role, address account) internal {
require(!has(role, account), "Roles: account already has role");
role.bearer[account] = true;
}
function remove(Role storage role, address account) internal {
require(has(role, account), "Roles: account does not have role");
role.bearer[account] = false;
}
function has(Role storage role, address account) internal view returns (bool) {
require(account != address(0), "Roles: account is the zero address");
return role.bearer[account];
}
}
/**
* @title MinterRole
* @dev role for addresses who has permission to mint tokens.
*/
contract MinterRole is Ownable {
using Roles for Roles.Role;
event MinterAdded(address indexed account);
event MinterRemoved(address indexed account);
Roles.Role private _minters;
modifier onlyMinter() {
require(isMinter(msg.sender), "Caller has no permission");
_;
}
function isMinter(address account) public view returns (bool) {
return(_minters.has(account) || isOwner(account));
}
function addMinter(address account) public onlyOwner {
_minters.add(account);
emit MinterAdded(account);
}
function removeMinter(address account) public onlyOwner {
_minters.remove(account);
emit MinterRemoved(account);
}
}
/**
* @title HalterRole
* @dev role for addresses who has permission to pause any token movement.
*/
contract HalterRole is Ownable {
using Roles for Roles.Role;
event HalterAdded(address indexed account);
event HalterRemoved(address indexed account);
Roles.Role private _halters;
modifier onlyHalter() {
require(isHalter(msg.sender), "Caller has no permission");
_;
}
function isHalter(address account) public view returns (bool) {
return(_halters.has(account) || isOwner(account));
}
function addHalter(address account) public onlyOwner {
_halters.add(account);
emit HalterAdded(account);
}
function removeHalter(address account) public onlyOwner {
_halters.remove(account);
emit HalterRemoved(account);
}
}
/**
* @title ERC20 interface
* @dev see https://eips.ethereum.org/EIPS/eip-20
*/
interface IERC20 {
function transfer(address to, uint256 value) external returns (bool);
function approve(address spender, uint256 value) external returns (bool);
function transferFrom(address from, address to, uint256 value) external returns (bool);
function totalSupply() external view returns (uint256);
function balanceOf(address who) external view returns (uint256);
function allowance(address owner, address spender) external view returns (uint256);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
/**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* See https://eips.ethereum.org/EIPS/eip-20
*/
contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowed;
uint256 private _totalSupply;
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
function balanceOf(address owner) public view returns (uint256) {
return _balances[owner];
}
function allowance(address owner, address spender) public view returns (uint256) {
return _allowed[owner][spender];
}
function transfer(address to, uint256 value) public returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
function transferFrom(address from, address to, uint256 value) public returns (bool) {
_transfer(from, to, value);
_approve(from, msg.sender, _allowed[from][msg.sender].sub(value));
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowed[msg.sender][spender].add(addedValue));
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowed[msg.sender][spender].sub(subtractedValue));
return true;
}
function _transfer(address from, address to, uint256 value) internal {
require(to != address(0));
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(from, to, value);
}
function _mint(address account, uint256 value) internal {
require(account != address(0));
_totalSupply = _totalSupply.add(value);
_balances[account] = _balances[account].add(value);
emit Transfer(address(0), account, value);
}
function _approve(address owner, address spender, uint256 value) internal {
require(spender != address(0));
require(owner != address(0));
_allowed[owner][spender] = value;
emit Approval(owner, spender, value);
}
function _burn(address account, uint256 amount) internal {
require(account != address(0));
_balances[account] = _balances[account].sub(amount);
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
function _burnFrom(address account, uint256 amount) internal {
_burn(account, amount);
_approve(account, msg.sender, _allowed[account][msg.sender].sub(amount));
}
}
/**
* @dev Extension of {ERC20} that allows token holders to destroy both their own
* tokens and those that they have an allowance for.
*/
contract ERC20Burnable is ERC20 {
function burn(uint256 amount) public {
_burn(msg.sender, amount);
}
function burnFrom(address account, uint256 amount) public {
_burnFrom(account, amount);
}
}
/**
* @dev Extension of {ERC20} that adds a set of accounts with the {MinterRole},
* which have permission to mint (create) new tokens as they see fit.
*/
contract ERC20Mintable is ERC20Burnable, MinterRole {
function mint(address account, uint256 amount) public onlyMinter returns (bool) {
_mint(account, amount);
return true;
}
}
/**
* @dev Extension of {ERC20} that adds a possibility to temporary prevent any token movements.
*/
contract ERC20Haltable is ERC20Mintable, HalterRole {
bool public paused;
event Paused(address by);
event Unpaused(address by);
modifier notPaused() {
require(!paused);
_;
}
function pause() public onlyHalter {
paused = true;
emit Paused(msg.sender);
}
function unpause() public onlyHalter {
paused = false;
emit Unpaused(msg.sender);
}
function _transfer(address from, address to, uint256 value) internal notPaused {
super._transfer(from, to, value);
}
function _mint(address account, uint256 value) internal notPaused {
super._mint(account, value);
}
function _burn(address account, uint256 amount) internal notPaused {
super._burn(account, amount);
}
}
/**
* @title ApproveAndCall Interface.
* @dev ApproveAndCall system allows to communicate with smart-contracts.
*/
interface IApproveAndCallFallBack {
function receiveApproval(address from, uint256 amount, address token, bytes calldata extraData) external;
}
/**
* @title The main project contract.
*/
contract MINAToken is ERC20Haltable {
string private _name = "Mina Protocol";
string private _symbol = "MINA";
uint8 private _decimals = 9;
uint256 internal constant _emission = 1000000000 * (10 ** 9);
mapping (address => bool) private _contracts;
bool public mintingFinished;
mapping (address => uint256) internal holderMap;
address[] public holderList;
modifier onlyMinter() {
if (mintingFinished) {
revert();
}
require(isMinter(msg.sender), "Caller has no permission");
_;
}
constructor() public {
_addHolder(address(0));
}
function _transfer(address from, address to, uint256 value) internal {
if (value != 0) {
if (holderMap[to] == 0) {
_addHolder(to);
}
if (balanceOf(from).sub(value) == 0) {
_removeHolder(from);
}
}
super._transfer(from, to, value);
}
function _mint(address account, uint256 value) internal {
require(totalSupply().add(value) <= _emission);
if (value != 0 && holderMap[account] == 0) {
_addHolder(account);
}
super._mint(account, value);
}
function _burn(address account, uint256 amount) internal {
if (balanceOf(account).sub(amount) == 0) {
_removeHolder(account);
}
super._burn(account, amount);
}
function _addHolder(address account) internal {
holderList.push(account);
holderMap[account] = holderList.length.sub(1);
}
function _removeHolder(address account) internal {
if (holderList.length > 1) {
holderList[holderMap[account]] = holderList[holderList.length.sub(1)];
holderMap[holderList[holderList.length.sub(1)]] = holderMap[account];
}
holderMap[account] = 0;
holderList.length = holderList.length.sub(1);
}
function approveAndCall(address spender, uint256 amount, bytes memory extraData) public returns (bool) {
require(approve(spender, amount));
IApproveAndCallFallBack(spender).receiveApproval(msg.sender, amount, address(this), extraData);
return true;
}
function transfer(address to, uint256 value) public returns (bool) {
if (_contracts[to]) {
approveAndCall(to, value, new bytes(0));
} else {
super.transfer(to, value);
}
return true;
}
function registerContract(address addr) public onlyOwner {
require(isContract(addr));
_contracts[addr] = true;
}
function unregisterContract(address addr) external onlyOwner {
_contracts[addr] = false;
}
function finishMinting() external onlyMinter {
mintingFinished = true;
}
function name() public view returns (string memory) {
return _name;
}
function symbol() public view returns (string memory) {
return _symbol;
}
function decimals() public view returns (uint8) {
return _decimals;
}
function isRegistered(address addr) public view returns (bool) {
return _contracts[addr];
}
function isContract(address addr) internal view returns (bool) {
uint size;
assembly { size := extcodesize(addr) }
return size > 0;
}
function amountOfHolders() public view returns (uint256) {
return holderList.length.sub(1);
}
function holders() public view returns (address[] memory) {
return holderList;
}
}
{
"compilationTarget": {
"MINAToken.sol": "MINAToken"
},
"evmVersion": "petersburg",
"libraries": {},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}
[{"constant":true,"inputs":[],"name":"mintingFinished","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"spender","type":"address"},{"name":"value","type":"uint256"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"holderList","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"addr","type":"address"}],"name":"registerContract","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"from","type":"address"},{"name":"to","type":"address"},{"name":"value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"account","type":"address"}],"name":"isOwner","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"account","type":"address"}],"name":"removeMinter","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"spender","type":"address"},{"name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"unpause","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"account","type":"address"},{"name":"amount","type":"uint256"}],"name":"mint","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"amount","type":"uint256"}],"name":"burn","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"paused","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"account","type":"address"}],"name":"isHalter","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"renounceOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"account","type":"address"},{"name":"amount","type":"uint256"}],"name":"burnFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"finishMinting","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"holders","outputs":[{"name":"","type":"address[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"pause","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"account","type":"address"}],"name":"addMinter","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"account","type":"address"}],"name":"removeHalter","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"spender","type":"address"},{"name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"amountOfHolders","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"to","type":"address"},{"name":"value","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"account","type":"address"}],"name":"isMinter","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"addr","type":"address"}],"name":"isRegistered","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"account","type":"address"}],"name":"addHalter","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"spender","type":"address"},{"name":"amount","type":"uint256"},{"name":"extraData","type":"bytes"}],"name":"approveAndCall","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"},{"name":"spender","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"addr","type":"address"}],"name":"unregisterContract","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"by","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"by","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"account","type":"address"}],"name":"HalterAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"account","type":"address"}],"name":"HalterRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"account","type":"address"}],"name":"MinterAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"account","type":"address"}],"name":"MinterRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"previousOwner","type":"address"},{"indexed":true,"name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"}]