pragma solidity ^0.6.12;
interface tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes calldata _extraData) external; }
/// @title ICONOMI Daa token
contract DaaToken {
//
// events
//
// ERC20 events
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
// mint/burn events
event Mint(address indexed _to, uint256 _amount, uint256 _newTotalSupply);
event Burn(address indexed _from, uint256 _amount, uint256 _newTotalSupply);
// admin events
event BlockLockSet(uint256 _value);
event NewOwner(address _newOwner);
event NewMinter(address _minter);
modifier onlyOwner {
if (msg.sender == owner) {
_;
}
}
modifier minterOrOwner {
if (msg.sender == minter || msg.sender == owner) {
_;
}
}
modifier blockLock(address _sender) {
if (!isLocked() || _sender == owner) {
_;
}
}
modifier validTransfer(address _from, address _to, uint256 _amount) {
if (isTransferValid(_from, _to, _amount)) {
_;
}
}
uint256 public totalSupply;
string public name;
uint8 public decimals;
string public symbol;
string public version = '0.0.1';
address public owner;
address public minter;
uint256 public lockedUntilBlock;
constructor(
string memory _tokenName,
uint8 _decimalUnits,
string memory _tokenSymbol,
address _owner,
address _minter,
uint256 _lockedUntilBlock
) public {
name = _tokenName;
decimals = _decimalUnits;
symbol = _tokenSymbol;
owner = _owner;
minter = _minter;
lockedUntilBlock = _lockedUntilBlock;
}
function transfer(address _to, uint256 _value)
public
blockLock(msg.sender)
validTransfer(msg.sender, _to, _value)
returns (bool success)
{
// transfer tokens
balances[msg.sender] -= _value;
balances[_to] += _value;
emit Transfer(msg.sender, _to, _value);
return true;
}
function approve(address _spender, uint256 _value)
public
returns (bool success)
{
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
function transferFrom(address _from, address _to, uint256 _value)
public
blockLock(_from)
validTransfer(_from, _to, _value)
returns (bool success)
{
// check sufficient allowance
if (_value > allowed[_from][msg.sender]) {
return false;
}
// transfer tokens
balances[_from] -= _value;
balances[_to] += _value;
allowed[_from][msg.sender] -= _value;
emit Transfer(_from, _to, _value);
return true;
}
function approveAndCall(address _spender, uint256 _value, bytes calldata _extraData)
public
returns (bool success)
{
if (approve(_spender, _value)) {
tokenRecipient(_spender).receiveApproval(msg.sender, _value, address(this), _extraData);
return true;
}
}
/// @notice Mint new tokens. Can only be called by minter or owner
function mint(address _to, uint256 _value)
public
minterOrOwner
blockLock(msg.sender)
returns (bool success)
{
// ensure _value is greater than zero and
// doesn't overflow
if (totalSupply + _value <= totalSupply) {
return false;
}
balances[_to] += _value;
totalSupply += _value;
emit Mint(_to, _value, totalSupply);
emit Transfer(address(0x0), _to, _value);
return true;
}
/// @notice Burn tokens. Can be called by any account
function burn(uint256 _value)
public
blockLock(msg.sender)
returns (bool success)
{
if (_value == 0 || _value > balances[msg.sender]) {
return false;
}
balances[msg.sender] -= _value;
totalSupply -= _value;
Burn(msg.sender, _value, totalSupply);
emit Transfer(msg.sender, address(0x0), _value);
return true;
}
/// @notice Set block lock. Until that block (exclusive) transfers are disallowed
function setBlockLock(uint256 _lockedUntilBlock)
public
onlyOwner
returns (bool success)
{
lockedUntilBlock = _lockedUntilBlock;
BlockLockSet(_lockedUntilBlock);
return true;
}
/// @notice Replace current owner with new one
function replaceOwner(address _newOwner)
public
onlyOwner
returns (bool success)
{
owner = _newOwner;
NewOwner(_newOwner);
return true;
}
/// @notice Set account that can mint new tokens
function setMinter(address _newMinter)
public
onlyOwner
returns (bool success)
{
minter = _newMinter;
NewMinter(_newMinter);
return true;
}
function balanceOf(address _owner)
public
view
returns (uint256 balance)
{
return balances[_owner];
}
function allowance(address _owner, address _spender)
public
view
returns (uint256 remaining)
{
return allowed[_owner][_spender];
}
/// @notice Are transfers currently disallowed
function isLocked()
public
view
returns (bool success)
{
return lockedUntilBlock > block.number;
}
/// @dev Checks if transfer parameters are valid
function isTransferValid(address _from, address _to, uint256 _amount)
private
view
returns (bool isValid)
{
return balances[_from] >= _amount && // sufficient balance
_amount > 0 && // amount is positive
_to != address(this) && // prevent sending tokens to contract
_to != address(0x0) // prevent sending token to 0x0 address
;
}
mapping (address => uint256) balances;
mapping (address => mapping (address => uint256)) allowed;
}
{
"compilationTarget": {
"DaaToken.sol": "DaaToken"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"string","name":"_tokenName","type":"string"},{"internalType":"uint8","name":"_decimalUnits","type":"uint8"},{"internalType":"string","name":"_tokenSymbol","type":"string"},{"internalType":"address","name":"_owner","type":"address"},{"internalType":"address","name":"_minter","type":"address"},{"internalType":"uint256","name":"_lockedUntilBlock","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":true,"internalType":"address","name":"_spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"BlockLockSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_newTotalSupply","type":"uint256"}],"name":"Burn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_newTotalSupply","type":"uint256"}],"name":"Mint","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_minter","type":"address"}],"name":"NewMinter","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_newOwner","type":"address"}],"name":"NewOwner","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"address","name":"_spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"remaining","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_spender","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_spender","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"},{"internalType":"bytes","name":"_extraData","type":"bytes"}],"name":"approveAndCall","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"balance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"burn","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isLocked","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lockedUntilBlock","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"mint","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"minter","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_newOwner","type":"address"}],"name":"replaceOwner","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_lockedUntilBlock","type":"uint256"}],"name":"setBlockLock","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_newMinter","type":"address"}],"name":"setMinter","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_from","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"}]