Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
blockchain/contracts/contracts/token/TrustlinesNetworkToken.sol
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
189 lines (163 sloc)
5.74 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.8.0; | |
contract TrustlinesNetworkToken { | |
// We use MAX_UINT value for an approval of infinite value | |
uint constant MAX_UINT = type(uint).max; | |
string public name; | |
string public symbol; | |
uint8 public decimals; | |
uint256 private _totalSupply; | |
mapping(address => uint256) private _balances; | |
mapping(address => mapping(address => uint256)) private _allowances; | |
event Transfer(address indexed from, address indexed to, uint256 value); | |
event Approval( | |
address indexed owner, | |
address indexed spender, | |
uint256 value | |
); | |
constructor( | |
string memory _name, | |
string memory _symbol, | |
uint8 _decimals, | |
address preMintAddress, | |
uint256 preMintAmount | |
) { | |
name = _name; | |
symbol = _symbol; | |
decimals = _decimals; | |
_mint(preMintAddress, preMintAmount); | |
} | |
/** | |
* @dev Returns the amount of tokens owned by `account`. | |
*/ | |
function balanceOf(address account) public view returns (uint256) { | |
return _balances[account]; | |
} | |
/** | |
* @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) | |
public | |
view | |
returns (uint256) | |
{ | |
return _allowances[owner][spender]; | |
} | |
/** | |
* @dev Returns the amount of tokens in existence. | |
*/ | |
function totalSupply() public view returns (uint256) { | |
return _totalSupply; | |
} | |
/** | |
* @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) public returns (bool) { | |
_transfer(msg.sender, recipient, amount); | |
return true; | |
} | |
/** | |
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens. | |
* | |
* Returns a boolean value indicating whether the operation succeeded. | |
* | |
* Approve with a value of `MAX_UINT = 2 ** 256 - 1` will symbolize | |
* an approval of infinite value. | |
* | |
* IMPORTANT:to prevent the risk that someone may use both the old and | |
* the new allowance by unfortunate transaction ordering, | |
* the approval must be set to 0 before it can be changed to any | |
* different desired value. | |
* | |
* see: https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 | |
* | |
* Emits an {Approval} event. | |
*/ | |
function approve(address spender, uint256 value) public returns (bool) { | |
require( | |
value == 0 || _allowances[msg.sender][spender] == 0, | |
"ERC20: approve only to or from 0 value" | |
); | |
_approve(msg.sender, spender, value); | |
return true; | |
} | |
/** | |
* @dev Moves `amount` tokens from `sender` to `recipient` using the | |
* allowance mechanism. `amount` is then deducted from the caller's | |
* allowance unless the allowance is `MAX_UINT = 2 ** 256 - 1`. | |
* | |
* Returns a boolean value indicating whether the operation succeeded. | |
* | |
* Emits a {Transfer} event. | |
*/ | |
function transferFrom( | |
address sender, | |
address recipient, | |
uint256 amount | |
) public returns (bool) { | |
_transfer(sender, recipient, amount); | |
uint _allowance = _allowances[sender][msg.sender]; | |
if (_allowance < MAX_UINT) { | |
uint updatedAllowance = _allowance - amount; | |
_approve(sender, msg.sender, updatedAllowance); | |
} | |
return true; | |
} | |
function burn(uint256 amount) public { | |
_burn(msg.sender, amount); | |
} | |
function _mint(address account, uint256 amount) internal { | |
require(account != address(0), "ERC20: mint to the zero address"); | |
_totalSupply += amount; | |
_balances[account] += amount; | |
emit Transfer(address(0), account, 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] -= amount; | |
_balances[recipient] += amount; | |
emit Transfer(sender, recipient, amount); | |
} | |
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); | |
} | |
function _burn(address account, uint256 value) internal { | |
require(account != address(0), "ERC20: burn from the zero address"); | |
_totalSupply -= value; | |
_balances[account] -= value; | |
emit Transfer(account, address(0), value); | |
} | |
} | |
/* | |
The MIT License (MIT) | |
Copyright (c) 2016-2019 zOS Global Limited | |
Permission is hereby granted, free of charge, to any person obtaining | |
a copy of this software and associated documentation files (the | |
"Software"), to deal in the Software without restriction, including | |
without limitation the rights to use, copy, modify, merge, publish, | |
distribute, sublicense, and/or sell copies of the Software, and to | |
permit persons to whom the Software is furnished to do so, subject to | |
the following conditions: | |
The above copyright notice and this permission notice shall be included | |
in all copies or substantial portions of the Software. | |
*/ | |
// SPDX-License-Identifier: MIT |