// File: openzeppelin-solidity/contracts/token/ERC20/IERC20.sol
pragma solidity ^0.5.11;
/**
* @dev Interface of the ERC20 standard as defined in the EIP. Does not include
* the optional functions; to access them see `ERC20Detailed`.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a `Transfer` event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through `transferFrom`. This is
* zero by default.
*
* This value changes when `approve` or `transferFrom` are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* > Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an `Approval` event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a `Transfer` event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to `approve`. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
// File: openzeppelin-solidity/contracts/math/SafeMath.sol
pragma solidity ^0.5.11;
/**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, "SafeMath: division by zero");
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0, "SafeMath: modulo by zero");
return a % b;
}
}
// File: openzeppelin-solidity/contracts/token/ERC20/ERC20.sol
pragma solidity ^0.5.11;
/**
* @dev Implementation of the `IERC20` interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using `_mint`.
* For a generic mechanism see `ERC20Mintable`.
*
* *For a detailed writeup see our guide [How to implement supply
* mechanisms](https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226).*
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an `Approval` event is emitted on calls to `transferFrom`.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard `decreaseAllowance` and `increaseAllowance`
* functions have been added to mitigate the well-known issues around setting
* allowances. See `IERC20.approve`.
*/
contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
/**
* @dev See `IERC20.totalSupply`.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev See `IERC20.balanceOf`.
*/
function balanceOf(address account) public view returns (uint256) {
return _balances[account];
}
/**
* @dev See `IERC20.transfer`.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public returns (bool) {
_transfer(msg.sender, recipient, amount);
return true;
}
/**
* @dev See `IERC20.allowance`.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See `IERC20.approve`.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev See `IERC20.transferFrom`.
*
* Emits an `Approval` event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of `ERC20`;
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `value`.
* - the caller must have allowance for `sender`'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, msg.sender, _allowances[sender][msg.sender].sub(amount));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to `approve` that can be used as a mitigation for
* problems described in `IERC20.approve`.
*
* Emits an `Approval` event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to `approve` that can be used as a mitigation for
* problems described in `IERC20.approve`.
*
* Emits an `Approval` event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to `transfer`, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a `Transfer` event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_balances[sender] = _balances[sender].sub(amount);
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a `Transfer` event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destoys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a `Transfer` event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0), "ERC20: burn from the zero address");
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an `Approval` event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Destoys `amount` tokens from `account`.`amount` is then deducted
* from the caller's allowance.
*
* See `_burn` and `_approve`.
*/
function _burnFrom(address account, uint256 amount) internal {
_burn(account, amount);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(amount));
}
}
// File: openzeppelin-solidity/contracts/access/Roles.sol
pragma solidity ^0.5.11;
/**
* @title Roles
* @dev Library for managing addresses assigned to a Role.
*/
library Roles {
struct Role {
mapping (address => bool) bearer;
}
/**
* @dev Give an account access to this role.
*/
function add(Role storage role, address account) internal {
require(!has(role, account), "Roles: account already has role");
role.bearer[account] = true;
}
/**
* @dev Remove an account's access to this role.
*/
function remove(Role storage role, address account) internal {
require(has(role, account), "Roles: account does not have role");
role.bearer[account] = false;
}
/**
* @dev Check if an account has this role.
* @return bool
*/
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];
}
}
// File: openzeppelin-solidity/contracts/access/roles/MinterRole.sol
pragma solidity ^0.5.11;
contract MinterRole {
using Roles for Roles.Role;
event MinterAdded(address indexed account);
event MinterRemoved(address indexed account);
Roles.Role private _minters;
constructor () internal {
_addMinter(msg.sender);
}
modifier onlyMinter() {
require(isMinter(msg.sender), "MinterRole: caller does not have the Minter role");
_;
}
function isMinter(address account) public view returns (bool) {
return _minters.has(account);
}
function addMinter(address account) public onlyMinter {
_addMinter(account);
}
function renounceMinter() public {
_removeMinter(msg.sender);
}
function _addMinter(address account) internal {
_minters.add(account);
emit MinterAdded(account);
}
function _removeMinter(address account) internal {
_minters.remove(account);
emit MinterRemoved(account);
}
}
// File: openzeppelin-solidity/contracts/token/ERC20/ERC20Mintable.sol
pragma solidity ^0.5.11;
/**
* @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.
*
* At construction, the deployer of the contract is the only minter.
*/
contract ERC20Mintable is ERC20, MinterRole {
/**
* @dev See `ERC20._mint`.
*
* Requirements:
*
* - the caller must have the `MinterRole`.
*/
function mint(address account, uint256 amount) public onlyMinter returns (bool) {
_mint(account, amount);
return true;
}
}
// File: openzeppelin-solidity/contracts/ownership/Ownable.sol
pragma solidity ^0.5.11;
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be aplied to your functions to restrict their use to
* the owner.
*/
contract Ownable {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () internal {
_owner = msg.sender;
emit OwnershipTransferred(address(0), _owner);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(isOwner(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Returns true if the caller is the current owner.
*/
function isOwner() public view returns (bool) {
return msg.sender == _owner;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* > Note: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public onlyOwner {
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
*/
function _transferOwnership(address newOwner) internal {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
// File: contracts/token/ERC884/ERC884.sol
pragma solidity ^0.5.11;
/**
* An `ERC20` compatible token that conforms to Delaware State Senate,
* 149th General Assembly, Senate Bill No. 69: An act to Amend Title 8
* of the Delaware Code Relating to the General Corporation Law.
*
* Implementation Details.
*
* An implementation of this token standard SHOULD provide the following:
*
* `name` - for use by wallets and exchanges.
* `symbol` - for use by wallets and exchanges.
*
* The implementation MUST take care not to allow unauthorised access to share
* transfer functions.
*
* In addition to the above the following optional `ERC20` function MUST be defined.
*
* `decimals` — MUST return `0` as each token represents a single Share and Shares are non-divisible.
*
* @dev Ref https://github.com/ethereum/EIPs/pull/884
*/
contract ERC884 is ERC20 {
/**
* This event is emitted when a verified address and associated identity hash are
* added to the contract.
* @param addr The address that was added.
* @param hash The identity hash associated with the address.
* @param sender The address that caused the address to be added.
*/
event VerifiedAddressAdded(
address indexed addr,
bytes32 hash,
address indexed sender
);
/**
* This event is emitted when a verified address its associated identity hash are
* removed from the contract.
* @param addr The address that was removed.
* @param sender The address that caused the address to be removed.
*/
event VerifiedAddressRemoved(address indexed addr, address indexed sender);
/**
* This event is emitted when the identity hash associated with a verified address is updated.
* @param addr The address whose hash was updated.
* @param oldHash The identity hash that was associated with the address.
* @param hash The hash now associated with the address.
* @param sender The address that caused the hash to be updated.
*/
event VerifiedAddressUpdated(
address indexed addr,
bytes32 oldHash,
bytes32 hash,
address indexed sender
);
/**
* This event is emitted when an address is cancelled and replaced with
* a new address. This happens in the case where a shareholder has
* lost access to their original address and needs to have their share
* reissued to a new address. This is the equivalent of issuing replacement
* share certificates.
* @param original The address being superseded.
* @param replacement The new address.
* @param sender The address that caused the address to be superseded.
*/
event VerifiedAddressSuperseded(
address indexed original,
address indexed replacement,
address indexed sender
);
/**
* Add a verified address, along with an associated verification hash to the contract.
* Upon successful addition of a verified address, the contract must emit
* `VerifiedAddressAdded(addr, hash, msg.sender)`.
* It MUST throw if the supplied address or hash are zero, or if the address has already been supplied.
* @param addr The address of the person represented by the supplied hash.
* @param hash A cryptographic hash of the address holder's verified information.
*/
function addVerified(address addr, bytes32 hash) public;
/**
* Remove a verified address, and the associated verification hash. If the address is
* unknown to the contract then this does nothing. If the address is successfully removed, this
* function must emit `VerifiedAddressRemoved(addr, msg.sender)`.
* It MUST throw if an attempt is made to remove a verifiedAddress that owns Tokens.
* @param addr The verified address to be removed.
*/
function removeVerified(address addr) public;
/**
* Update the hash for a verified address known to the contract.
* Upon successful update of a verified address the contract must emit
* `VerifiedAddressUpdated(addr, oldHash, hash, msg.sender)`.
* If the hash is the same as the value already stored then
* no `VerifiedAddressUpdated` event is to be emitted.
* It MUST throw if the hash is zero, or if the address is unverified.
* @param addr The verified address of the person represented by the supplied hash.
* @param hash A new cryptographic hash of the address holder's updated verified information.
*/
function updateVerified(address addr, bytes32 hash) public;
/**
* Cancel the original address and reissue the Tokens to the replacement address.
* Access to this function MUST be strictly controlled.
* The `original` address MUST be removed from the set of verified addresses.
* Throw if the `original` address supplied is not a shareholder.
* Throw if the `replacement` address is not a verified address.
* Throw if the `replacement` address already holds Tokens.
* This function MUST emit the `VerifiedAddressSuperseded` event.
* @param original The address to be superseded. This address MUST NOT be reused.
*/
function cancelAndReissue(address original, address replacement) public;
/**
* The `transfer` function MUST NOT allow transfers to addresses that
* have not been verified and added to the contract.
* If the `to` address is not currently a shareholder then it MUST become one.
* If the transfer will reduce `msg.sender`'s balance to 0 then that address
* MUST be removed from the list of shareholders.
*/
/**
* The `transferFrom` function MUST NOT allow transfers to addresses that
* have not been verified and added to the contract.
* If the `to` address is not currently a shareholder then it MUST become one.
* If the transfer will reduce `from`'s balance to 0 then that address
* MUST be removed from the list of shareholders.
*/
/**
* Tests that the supplied address is known to the contract.
* @param addr The address to test.
* @return true if the address is known to the contract.
*/
function isVerified(address addr) public view returns (bool);
/**
* Checks to see if the supplied address is a share holder.
* @param addr The address to check.
* @return true if the supplied address owns a token.
*/
function isHolder(address addr) public view returns (bool);
/**
* Checks that the supplied hash is associated with the given address.
* @param addr The address to test.
* @param hash The hash to test.
* @return true if the hash matches the one supplied with the address in `addVerified`, or `updateVerified`.
*/
function hasHash(address addr, bytes32 hash) public view returns (bool);
/**
* The number of addresses that hold tokens.
* @return the number of unique addresses that hold tokens.
*/
function holderCount() public view returns (uint);
/**
* By counting the number of token holders using `holderCount`
* you can retrieve the complete list of token holders, one at a time.
* It MUST throw if `index >= holderCount()`.
* @param index The zero-based index of the holder.
* @return the address of the token holder with the given index.
*/
function holderAt(uint256 index) public view returns (address);
/**
* Checks to see if the supplied address was superseded.
* @param addr The address to check.
* @return true if the supplied address was superseded by another address.
*/
function isSuperseded(address addr) public view returns (bool);
/**
* Gets the most recent address, given a superseded one.
* Addresses may be superseded multiple times, so this function needs to
* follow the chain of addresses until it reaches the final, verified address.
* @param addr The superseded address.
* @return the verified address that ultimately holds the share.
*/
function getCurrentFor(address addr) public view returns (address);
}
// File: contracts/token/ERC884/DwarvesFoundationGem.sol
pragma solidity ^0.5.11;
/**
* An `ERC20` compatible token that conforms to Delaware State Senate,
* 149th General Assembly, Senate Bill No. 69: An act to Amend Title 8
* of the Delaware Code Relating to the General Corporation Law.
*
* Implementation Details.
*
* An implementation of this token standard SHOULD provide the following:
*
* `name` - for use by wallets and exchanges.
* `symbol` - for use by wallets and exchanges.
*
* In addition to the above the following optional `ERC20` function MUST be defined.
*
* `decimals` — MUST return `0` as each token represents a single Share and Shares are non-divisible.
*
* @dev Ref https://github.com/ethereum/EIPs/blob/master/EIPS/eip-884.md
*/
contract DwarvesFoundationGem is ERC884, ERC20Mintable, Ownable {
bytes32 constant private ZERO_BYTES = bytes32(0);
address constant private ZERO_ADDRESS = address(0);
string public name;
string public symbol;
uint256 public decimals;
mapping(address => bytes32) private verified;
mapping(address => address) private cancellations;
mapping(address => uint256) private holderIndices;
mapping(address => uint256) private restrictedStock;
mapping(address => uint256) private restrictedStockSendTime;
address[] public shareholders;
constructor(string memory _name, string memory _symbol) public {
name = _name;
symbol = _symbol;
decimals = 0;
}
/**
* This event is emitted when an transferRestrictedStock
* is called by the owner (only owner can run this command)
* @param owner The address of owner.
* @param receiver The receiver.
* @param amount the amount of transfer.
*/
event TransferRestrictedStock(
address owner,
address indexed receiver,
uint256 indexed amount,
uint256 indexed restrictedSendTime
);
/**
* This event is emitted when an updateRestrictedStockSendTime
* is called by the owner (only owner can run this command)
* @param addr The address will be update restrictedStockSendTime.
* @param newRestrictedSendTime the amount of transfer.
*/
event UpdateRestrictedStockSendTime(
address indexed addr,
uint256 indexed newRestrictedSendTime
);
modifier isVerifiedAddress(address addr) {
require(verified[addr] != ZERO_BYTES);
_;
}
modifier isShareholder(address addr) {
require(holderIndices[addr] != 0);
_;
}
modifier isNotShareholder(address addr) {
require(holderIndices[addr] == 0);
_;
}
modifier isNotCancelled(address addr) {
require(cancellations[addr] == ZERO_ADDRESS);
_;
}
/**
* As each token is minted it is added to the shareholders array.
* @param _to The address that will receive the minted tokens.
* @param _amount The amount of tokens to mint.
* @return A boolean that indicates if the operation was successful.
*/
function mint(address _to, uint256 _amount)
public
onlyOwner
returns (bool)
{
require(verified[_to] != ZERO_BYTES);
// if the address does not already own share then
// add the address to the shareholders array and record the index.
updateShareholders(_to);
return super.mint(_to, _amount);
}
/**
* The number of addresses that own tokens.
* @return the number of unique addresses that own tokens.
*/
function holderCount()
public
onlyOwner
view
returns (uint)
{
return shareholders.length;
}
/**
* By counting the number of token holders using `holderCount`
* you can retrieve the complete list of token holders, one at a time.
* It MUST throw if `index >= holderCount()`.
* @param index The zero-based index of the holder.
* @return the address of the token holder with the given index.
*/
function holderAt(uint256 index)
public
onlyOwner
view
returns (address)
{
require(index < shareholders.length);
return shareholders[index];
}
/**
* Add a verified address, along with an associated verification hash to the contract.
* Upon successful addition of a verified address, the contract must emit
* `VerifiedAddressAdded(addr, hash, msg.sender)`.
* It MUST throw if the supplied address or hash are zero, or if the address has already been supplied.
* @param addr The address of the person represented by the supplied hash.
* @param hash A cryptographic hash of the address holder's verified information.
*/
function addVerified(address addr, bytes32 hash)
public
onlyOwner
isNotCancelled(addr)
{
require(addr != ZERO_ADDRESS);
require(hash != ZERO_BYTES);
require(verified[addr] == ZERO_BYTES);
verified[addr] = hash;
emit VerifiedAddressAdded(addr, hash, msg.sender);
}
/**
* Remove a verified address, and the associated verification hash. If the address is
* unknown to the contract then this does nothing. If the address is successfully removed, this
* function must emit `VerifiedAddressRemoved(addr, msg.sender)`.
* It MUST throw if an attempt is made to remove a verifiedAddress that owns Tokens.
* @param addr The verified address to be removed.
*/
function removeVerified(address addr)
public
onlyOwner
{
require(verified[addr] != ZERO_BYTES);
require(availableBalanceOf(addr) == 0);
verified[addr] = ZERO_BYTES;
emit VerifiedAddressRemoved(addr, msg.sender);
}
/**
* Update the hash for a verified address known to the contract.
* Upon successful update of a verified address the contract must emit
* `VerifiedAddressUpdated(addr, oldHash, hash, msg.sender)`.
* If the hash is the same as the value already stored then
* no `VerifiedAddressUpdated` event is to be emitted.
* It MUST throw if the hash is zero, or if the address is unverified.
* @param addr The verified address of the person represented by the supplied hash.
* @param hash A new cryptographic hash of the address holder's updated verified information.
*/
function updateVerified(address addr, bytes32 hash)
public
onlyOwner
isVerifiedAddress(addr)
{
require(hash != ZERO_BYTES);
bytes32 oldHash = verified[addr];
if (oldHash != hash) {
verified[addr] = hash;
emit VerifiedAddressUpdated(addr, oldHash, hash, msg.sender);
}
}
/**
* Cancel the original address and reissue the Tokens to the replacement address.
* Access to this function MUST be strictly controlled.
* The `original` address MUST be removed from the set of verified addresses.
* Throw if the `original` address supplied is not a shareholder.
* Throw if the replacement address is not a verified address.
* This function MUST emit the `VerifiedAddressSuperseded` event.
* @param original The address to be superseded. This address MUST NOT be reused.
* @param replacement The address that supersedes the original. This address MUST be verified.
*/
function cancelAndReissue(address original, address replacement)
public
onlyOwner
isShareholder(original)
isNotShareholder(replacement)
isVerifiedAddress(replacement)
{
// replace the original address in the shareholders array
// and update all the associated mappings
verified[original] = ZERO_BYTES;
cancellations[original] = replacement;
uint256 holderIndex = holderIndices[original] - 1;
shareholders[holderIndex] = replacement;
holderIndices[replacement] = holderIndices[original];
holderIndices[original] = 0;
_transfer(original,replacement,balanceOf(original));
uint256 restrict = restrictedStock[original];
uint256 restrictTime = restrictedStockSendTime[original];
restrictedStock[replacement] = restrict;
restrictedStockSendTime[replacement] = restrictTime;
restrictedStock[original] = 0;
restrictedStockSendTime[original] = 0;
emit VerifiedAddressSuperseded(original, replacement, msg.sender);
}
/**
* The `transfer` function MUST NOT allow transfers to addresses that
* have not been verified and added to the contract.
* If the `to` address is not currently a shareholder then it MUST become one.
* If the transfer will reduce `msg.sender`'s balance to 0 then that address
* MUST be removed from the list of shareholders.
*/
function transfer(address to, uint256 value)
public
isVerifiedAddress(to)
returns (bool)
{
require(availableBalanceOf(msg.sender) >= value);
updateShareholders(to);
pruneRestrictStock(msg.sender, value);
pruneShareholders(msg.sender, value);
return super.transfer(to, value);
}
/**
* The `transferRestrictedStock` function MUST NOT allow transfers to addresses that
* have not been verified and added to the contract.
* If the `to` address is not currently a shareholder then it MUST become one.
* If the transfer will reduce `msg.sender`'s balance to 0 then that address
* MUST be removed from the list of shareholders.
* Also add restrict stock number to restrictedStock and add restrictedStockSendTime
* if restrictedStockSendTime[to] is not exist
*/
function transferRestrictedStock(address to, uint256 value, uint256 time)
public
onlyOwner
isVerifiedAddress(to)
returns (bool)
{
require(availableBalanceOf(msg.sender) >= value);
require(verified[to] != ZERO_BYTES);
restrictedStock[to] += value;
if (restrictedStockSendTime[to] == 0) {
restrictedStockSendTime[to] = time;
}
emit TransferRestrictedStock(msg.sender, to, value, time);
return transfer(to, value);
}
/**
* The `updateRestrictedStockSendTime` update restrict stock send time
* of a verified address
*/
function updateRestrictedStockSendTime(address to, uint256 time)
public
onlyOwner
isVerifiedAddress(to)
returns (bool)
{
restrictedStockSendTime[to] = time;
emit UpdateRestrictedStockSendTime(to, time);
return true;
}
/**
* The `availableBalanceOf` function show current available amount to spend
* of a verified address (to)
*/
function availableBalanceOf(address to)
public
view
isVerifiedAddress(to)
returns (uint256)
{
uint256 all = balanceOf(to);
uint256 restrict = 0;
if (now < restrictedStockSendTime[to]) {
restrict = restrictedStock[to];
}
return all - restrict;
}
/**
* The `restrictedStockOf` function show current restricted stock owned by (_owner)
*/
function restrictedStockOf(address _owner)
public
view
returns (uint256)
{
return restrictedStock[_owner];
}
/**
* The `restrictedStockSendTimeOf` function show current restrictedStockSendTime owned by (_owner)
*/
function restrictedStockSendTimeOf(address _owner)
public
view
returns (uint256)
{
return restrictedStockSendTime[_owner];
}
/**
* The `transferFrom` function MUST NOT allow transfers to addresses that
* have not been verified and added to the contract.
* If the `to` address is not currently a shareholder then it MUST become one.
* If the transfer will reduce `from`'s balance to 0 then that address
* MUST be removed from the list of shareholders.
*/
function transferFrom(address from, address to, uint256 value)
public
isVerifiedAddress(to)
returns (bool)
{
require(availableBalanceOf(from) >= value);
updateShareholders(to);
pruneRestrictStock(msg.sender, value);
pruneShareholders(from, value);
return super.transferFrom(from, to, value);
}
/**
* Tests that the supplied address is known to the contract.
* @param addr The address to test.
* @return true if the address is known to the contract.
*/
function isVerified(address addr)
public
view
returns (bool)
{
return verified[addr] != ZERO_BYTES;
}
/**
* Checks to see if the supplied address is a share holder.
* @param addr The address to check.
* @return true if the supplied address owns a token.
*/
function isHolder(address addr)
public
view
returns (bool)
{
return holderIndices[addr] != 0;
}
/**
* Checks that the supplied hash is associated with the given address.
* @param addr The address to test.
* @param hash The hash to test.
* @return true if the hash matches the one supplied with the address in `addVerified`, or `updateVerified`.
*/
function hasHash(address addr, bytes32 hash)
public
view
returns (bool)
{
if (addr == ZERO_ADDRESS) {
return false;
}
return verified[addr] == hash;
}
/**
* Checks to see if the supplied address was superseded.
* @param addr The address to check.
* @return true if the supplied address was superseded by another address.
*/
function isSuperseded(address addr)
public
view
onlyOwner
returns (bool)
{
return cancellations[addr] != ZERO_ADDRESS;
}
/**
* Gets the most recent address, given a superseded one.
* Addresses may be superseded multiple times, so this function needs to
* follow the chain of addresses until it reaches the final, verified address.
* @param addr The superseded address.
* @return the verified address that ultimately holds the share.
*/
function getCurrentFor(address addr)
public
view
onlyOwner
returns (address)
{
return findCurrentFor(addr);
}
/**
* Recursively find the most recent address given a superseded one.
* @param addr The superseded address.
* @return the verified address that ultimately holds the share.
*/
function findCurrentFor(address addr)
internal
view
returns (address)
{
address candidate = cancellations[addr];
if (candidate == ZERO_ADDRESS) {
return addr;
}
return findCurrentFor(candidate);
}
/**
* If the address is not in the `shareholders` array then push it
* and update the `holderIndices` mapping.
* @param addr The address to add as a shareholder if it's not already.
*/
function updateShareholders(address addr)
internal
{
if (holderIndices[addr] == 0) {
holderIndices[addr] = shareholders.push(addr);
}
}
/**
* Prune restricted stock if restrictedStockSendTime was ending
* @param addr The address to add as a shareholder if it's not already.
* @param value The value store amount of sender
*/
function pruneRestrictStock(address addr, uint256 value)
internal
{
uint256 restrict = restrictedStock[addr];
if (restrict != 0) {
if (now > restrictedStockSendTime[addr]) {
if (value > restrict) {
// remove restrictedStock and restrictedStockSendTime
restrictedStock[addr] = 0;
restrictedStockSendTime[addr] = 0;
} else {
restrictedStock[addr] = restrict - value;
}
}
}
}
/**
* If the address is in the `shareholders` array and the forthcoming
* transfer or transferFrom will reduce their balance to 0, then
* we need to remove them from the shareholders array.
* @param addr The address to prune if their balance will be reduced to 0.
@ @dev see https://ethereum.stackexchange.com/a/39311
*/
function pruneShareholders(address addr, uint256 value)
internal
{
uint256 balance = balanceOf(addr) - value;
if (balance > 0) {
return;
}
uint256 holderIndex = holderIndices[addr] - 1;
uint256 lastIndex = shareholders.length - 1;
address lastHolder = shareholders[lastIndex];
// overwrite the addr's slot with the last shareholder
shareholders[holderIndex] = lastHolder;
// also copy over the index (thanks @mohoff for spotting this)
// ref https://github.com/davesag/ERC884-reference-implementation/issues/20
holderIndices[lastHolder] = holderIndices[addr];
// trim the shareholders array (which drops the last entry)
shareholders.length--;
// and zero out the index for addr
holderIndices[addr] = 0;
// zero out restricted sendTime
restrictedStockSendTime[addr] = 0;
}
}
{
"compilationTarget": {
"DwarvesFoundationGem.sol": "DwarvesFoundationGem"
},
"evmVersion": "petersburg",
"libraries": {},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}
[{"constant":true,"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"time","type":"uint256"}],"name":"transferRestrictedStock","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"holderAt","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"holderCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"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":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"availableBalanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"isSuperseded","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"addr","type":"address"},{"internalType":"bytes32","name":"hash","type":"bytes32"}],"name":"updateVerified","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"mint","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"removeVerified","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"addr","type":"address"},{"internalType":"bytes32","name":"hash","type":"bytes32"}],"name":"addVerified","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"renounceOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"original","type":"address"},{"internalType":"address","name":"replacement","type":"address"}],"name":"cancelAndReissue","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"isOwner","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"addMinter","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"renounceMinter","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"isMinter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"shareholders","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"_owner","type":"address"}],"name":"restrictedStockSendTimeOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"isVerified","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"getCurrentFor","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"isHolder","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"time","type":"uint256"}],"name":"updateRestrictedStockSendTime","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"_owner","type":"address"}],"name":"restrictedStockOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"addr","type":"address"},{"internalType":"bytes32","name":"hash","type":"bytes32"}],"name":"hasHash","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":true,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"restrictedSendTime","type":"uint256"}],"name":"TransferRestrictedStock","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"addr","type":"address"},{"indexed":true,"internalType":"uint256","name":"newRestrictedSendTime","type":"uint256"}],"name":"UpdateRestrictedStockSendTime","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"}],"name":"MinterAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"}],"name":"MinterRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"addr","type":"address"},{"indexed":false,"internalType":"bytes32","name":"hash","type":"bytes32"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"VerifiedAddressAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"addr","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"VerifiedAddressRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"addr","type":"address"},{"indexed":false,"internalType":"bytes32","name":"oldHash","type":"bytes32"},{"indexed":false,"internalType":"bytes32","name":"hash","type":"bytes32"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"VerifiedAddressUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"original","type":"address"},{"indexed":true,"internalType":"address","name":"replacement","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"VerifiedAddressSuperseded","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"},{"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"}]