pragmasolidity ^0.5.5;import"./ERC20Basic.sol";
import"./SafeMath.sol";
/**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
*/contractBasicTokenisERC20Basic{
usingSafeMathforuint256;
mapping(address=>uint256) internal balances;
uint256internal totalSupply_;
/**
* @dev Total number of tokens in existence
*/functiontotalSupply() publicviewreturns (uint256) {
return totalSupply_;
}
/**
* @dev Transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/functiontransfer(address _to, uint256 _value) publicreturns (bool) {
require(_value <= balances[msg.sender], "The balance of account is insufficient.");
require(_to !=address(0), "Recipient address is zero address(0). Check the address again.");
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value);
returntrue;
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/functionbalanceOf(address _owner) publicviewreturns (uint256) {
return balances[_owner];
}
}
Contract Source Code
File 2 of 9: DoDreamChain.sol
pragmasolidity ^0.5.5;import"./DoDreamChainBase.sol";
/**
* @dev Collection of functions related to the address type
*/libraryAddress{
/**
* @dev Returns true if `account` is a contract.
*
* This test is non-exhaustive, and there may be false-negatives: during the
* execution of a contract's constructor, its address will be reported as
* not containing a contract.
*
* IMPORTANT: It is unsafe to assume that an address for which this
* function returns false is an externally-owned account (EOA) and not a
* contract.
*/functionisContract(address account) internalviewreturns (bool) {
// This method relies in extcodesize, which returns 0 for contracts in// construction, since the code is only stored at the end of the// constructor execution.// According to EIP-1052, 0x0 is the value returned for not-yet created accounts// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned// for accounts without code, i.e. `keccak256('')`bytes32 codehash;
bytes32 accountHash =0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assemblyassembly { codehash :=extcodehash(account) }
return (codehash !=0x0&& codehash != accountHash);
}
/**
* @dev Converts an `address` into `address payable`. Note that this is
* simply a type cast: the actual underlying value is not changed.
*
* _Available since v2.4.0._
*/functiontoPayable(address account) internalpurereturns (addresspayable) {
returnaddress(uint160(account));
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*
* _Available since v2.4.0._
*/functionsendValue(addresspayable recipient, uint256 amount) internal{
require(address(this).balance>= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-call-value
(bool success, ) = recipient.call.value(amount)("");
require(success, "Address: unable to send value, recipient may have reverted");
}
}
/**
* @title DoDreamChain
*/contractDoDreamChainisDoDreamChainBase{
eventTransferedToDRMDapp(addressindexed owner,
addressindexed spender,
addressindexed to, uint256 value, DRMReceiver.DRMReceiveType receiveType);
stringpublicconstant name ="DoDreamChain";
stringpublicconstant symbol ="DRM";
uint8publicconstant decimals =18;
uint256publicconstant INITIAL_SUPPLY =250*1000*1000* (10**uint256(decimals)); // 250,000,000 DRM/**
* @dev Constructor 생성자에게 DRM토큰을 보냅니다.
*/constructor() public{
totalSupply_ = INITIAL_SUPPLY;
balances[msg.sender] = INITIAL_SUPPLY;
emit Transfer(address(0), msg.sender, INITIAL_SUPPLY);
}
functiondrmTransfer(address _to, uint256 _value, stringmemory _note) publicreturns (bool ret) {
ret =super.drmTransfer(_to, _value, _note);
postTransfer(msg.sender, msg.sender, _to, _value, DRMReceiver.DRMReceiveType.DRM_TRANSFER);
}
functiondrmTransferFrom(address _from, address _to, uint256 _value, stringmemory _note) publicreturns (bool ret) {
ret =super.drmTransferFrom(_from, _to, _value, _note);
postTransfer(_from, msg.sender, _to, _value, DRMReceiver.DRMReceiveType.DRM_TRANSFER);
}
functionpostTransfer(address owner, address spender, address to, uint256 value,
DRMReceiver.DRMReceiveType receiveType) internalreturns (bool) {
if (Address.isContract(to)) {
(bool callOk, bytesmemory data) =address(to).call(abi.encodeWithSignature("onDRMReceived(address,address,uint256,uint8)", owner, spender, value, receiveType));
if (callOk) {
emit TransferedToDRMDapp(owner, spender, to, value, receiveType);
}
}
returntrue;
}
functiondrmMintTo(address to, uint256 amount, stringmemory note) publiconlyOwnerreturns (bool ret) {
ret =super.drmMintTo(to, amount, note);
postTransfer(address(0), msg.sender, to, amount, DRMReceiver.DRMReceiveType.DRM_MINT);
}
functiondrmBurnFrom(addressfrom, uint256 value, stringmemory note) publiconlyOwnerreturns (bool ret) {
ret =super.drmBurnFrom(from, value, note);
postTransfer(address(0), msg.sender, from, value, DRMReceiver.DRMReceiveType.DRM_BURN);
}
}
/**
* @title DRM Receiver
*/contractDRMReceiver{
enumDRMReceiveType { DRM_TRANSFER, DRM_MINT, DRM_BURN }
functiononDRMReceived(address owner, address spender, uint256 value, DRMReceiveType receiveType) publicreturns (bool);
}
Contract Source Code
File 3 of 9: DoDreamChainBase.sol
pragmasolidity ^0.5.5;import"./LockableToken.sol";
/**
* @title DRMBaseToken
* dev 트랜잭션 실행 시 메모를 남길 수 있다.
*/contractDoDreamChainBaseisLockableToken{
eventDRMTransfer(addressindexedfrom, addressindexed to, uint256 value, string note);
eventDRMTransferFrom(addressindexed owner, addressindexed spender, addressindexed to, uint256 value, string note);
eventDRMApproval(addressindexed owner, addressindexed spender, uint256 value, string note);
eventDRMMintTo(addressindexed controller, addressindexed to, uint256 amount, string note);
eventDRMBurnFrom(addressindexed controller, addressindexedfrom, uint256 value, string note);
eventDRMTransferToTeam(addressindexed owner, addressindexed spender, addressindexed to, uint256 value, string note);
eventDRMTransferToPartner(addressindexed owner, addressindexed spender, addressindexed to, uint256 value, string note);
eventDRMTransferToEcosystem(addressindexed owner, addressindexed spender, addressindexed to
, uint256 value, uint256 processIdHash, uint256 userIdHash, string note);
// ERC20 함수들을 오버라이딩 작업 > drm~ 함수를 타게 한다.functiontransfer(address to, uint256 value) publicreturns (bool ret) {
return drmTransfer(to, value, "transfer");
}
functiondrmTransfer(address to, uint256 value, stringmemory note) publicreturns (bool ret) {
require(to !=address(this), "The receive address is the Contact Address of DoDreamChain.");
ret =super.transfer(to, value);
emit DRMTransfer(msg.sender, to, value, note);
}
functiontransferFrom(addressfrom, address to, uint256 value) publicreturns (bool) {
return drmTransferFrom(from, to, value, "");
}
functiondrmTransferFrom(addressfrom, address to, uint256 value, stringmemory note) publicreturns (bool ret) {
require(to !=address(this), "The receive address is the Contact Address of DoDreamChain.");
ret =super.transferFrom(from, to, value);
emit DRMTransferFrom(from, msg.sender, to, value, note);
}
functionapprove(address spender, uint256 value) publicreturns (bool) {
return drmApprove(spender, value, "");
}
functiondrmApprove(address spender, uint256 value, stringmemory note) publicreturns (bool ret) {
ret =super.approve(spender, value);
emit DRMApproval(msg.sender, spender, value, note);
}
functionincreaseApproval(address spender, uint256 addedValue) publicreturns (bool) {
return drmIncreaseApproval(spender, addedValue, "");
}
functiondrmIncreaseApproval(address spender, uint256 addedValue, stringmemory note) publicreturns (bool ret) {
ret =super.increaseApproval(spender, addedValue);
emit DRMApproval(msg.sender, spender, allowed[msg.sender][spender], note);
}
functiondecreaseApproval(address spender, uint256 subtractedValue) publicreturns (bool) {
return drmDecreaseApproval(spender, subtractedValue, "");
}
functiondrmDecreaseApproval(address spender, uint256 subtractedValue, stringmemory note) publicreturns (bool ret) {
ret =super.decreaseApproval(spender, subtractedValue);
emit DRMApproval(msg.sender, spender, allowed[msg.sender][spender], note);
}
/**
* dev 신규 발행시 반드시 주석을 남길수 있도록한다.
*/functionmintTo(address to, uint256 amount) internalreturns (bool) {
require(to !=address(0x0), "This address to be set is zero address(0). Check the input address.");
totalSupply_ = totalSupply_.add(amount);
balances[to] = balances[to].add(amount);
emit Transfer(address(0), to, amount);
returntrue;
}
functiondrmMintTo(address to, uint256 amount, stringmemory note) publiconlyOwnerreturns (bool ret) {
ret = mintTo(to, amount);
emit DRMMintTo(msg.sender, to, amount, note);
}
/**
* dev 화폐 소각시 반드시 주석을 남길수 있도록한다.
*/functionburnFrom(addressfrom, uint256 value) internalreturns (bool) {
require(value <= balances[from], "Your balance is insufficient.");
balances[from] = balances[from].sub(value);
totalSupply_ = totalSupply_.sub(value);
emit Transfer(from, address(0), value);
returntrue;
}
functiondrmBurnFrom(addressfrom, uint256 value, stringmemory note) publiconlyOwnerreturns (bool ret) {
ret = burnFrom(from, value);
emit DRMBurnFrom(msg.sender, from, value, note);
}
/**
* dev DRM 팀에게 전송하는 경우
*/functiondrmTransferToTeam(addressfrom,
address to,
uint256 value,
stringmemory note
) publiconlyOwnerreturns (bool ret) {
require(to !=address(this), "The receive address is the Contact Address of DoDreamChain.");
ret =super.transferFrom(from, to, value);
emit DRMTransferToTeam(from, msg.sender, to, value, note);
return ret;
}
/**
* dev 파트너(어드바이저)에게 전송하는 경우
*/functiondrmTransferToPartner(addressfrom,
address to,
uint256 value,
stringmemory note
) publiconlyOwnerreturns (bool ret) {
require(to !=address(this), "The receive address is the Contact Address of DoDreamChain.");
ret =super.transferFrom(from, to, value);
emit DRMTransferToPartner(from, msg.sender, to, value, note);
}
/**
* dev 보상을 DRM 지급
* dev EOA가 트랜잭션을 일으켜서 처리 * 여러개 계좌를 기준으로 한다. (가스비 아끼기 위함)
*/functiondrmBatchTransferToEcosystem(addressfrom, address[] memory to,
uint256[] memory values,
uint256 processIdHash,
uint256[] memory userIdHash,
stringmemory note
) publiconlyOwnerreturns (bool ret) {
uint256 length = to.length;
require(length == values.length, "The sizes of \'to\' and \'values\' arrays are different.");
require(length == userIdHash.length, "The sizes of \'to\' and \'userIdHash\' arrays are different.");
ret =true;
for (uint256 i =0; i < length; i++) {
require(to[i] !=address(this), "The receive address is the Contact Address of DoDreamChain.");
ret = ret &&super.transferFrom(from, to[i], values[i]);
emit DRMTransferToEcosystem(from, msg.sender, to[i], values[i], processIdHash, userIdHash[i], note);
}
}
functiondestroy() publiconlyRoot{
selfdestruct(msg.sender);
}
}
pragmasolidity ^0.5.5;/**
* @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.
*/librarySafeMath{
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
* - Addition cannot overflow.
*/functionadd(uint256 a, uint256 b) internalpurereturns (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.
*/functionsub(uint256 a, uint256 b) internalpurereturns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot overflow.
*
* _Available since v2.4.0._
*/functionsub(uint256 a, uint256 b, stringmemory errorMessage) internalpurereturns (uint256) {
require(b <= a, errorMessage);
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.
*/functionmul(uint256 a, uint256 b) internalpurereturns (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-contracts/pull/522if (a ==0) {
return0;
}
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.
*/functiondiv(uint256 a, uint256 b) internalpurereturns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message 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.
*
* _Available since v2.4.0._
*/functiondiv(uint256 a, uint256 b, stringmemory errorMessage) internalpurereturns (uint256) {
// Solidity only automatically asserts when dividing by 0require(b >0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't holdreturn 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.
*/functionmod(uint256 a, uint256 b) internalpurereturns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message 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.
*
* _Available since v2.4.0._
*/functionmod(uint256 a, uint256 b, stringmemory errorMessage) internalpurereturns (uint256) {
require(b !=0, errorMessage);
return a % b;
}
}
Contract Source Code
File 9 of 9: StandardToken.sol
pragmasolidity ^0.5.5;import"./BasicToken.sol";
import"./ERC20.sol";
/**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* https://github.com/ethereum/EIPs/issues/20
* Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/contractStandardTokenisERC20, BasicToken{
mapping (address=>mapping (address=>uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/functiontransferFrom(address _from,
address _to,
uint256 _value
)
publicreturns (bool)
{
require(_value <= balances[_from], "Not enough balance.");
require(_value <= allowed[_from][msg.sender], "Not allowed.");
require(_to !=address(0), "Invalid address.");
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
returntrue;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* 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
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/functionapprove(address _spender, uint256 _value) publicreturns (bool) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
returntrue;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/functionallowance(address _owner,
address _spender
)
publicviewreturns (uint256)
{
return allowed[_owner][_spender];
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/functionincreaseApproval(address _spender,
uint256 _addedValue
)
publicreturns (bool)
{
allowed[msg.sender][_spender] = (
allowed[msg.sender][_spender].add(_addedValue));
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
returntrue;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/functiondecreaseApproval(address _spender,
uint256 _subtractedValue
)
publicreturns (bool)
{
uint256 oldValue = allowed[msg.sender][_spender];
if (_subtractedValue >= oldValue) {
allowed[msg.sender][_spender] =0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
returntrue;
}
}