Bundle ERC20Detailed (#2161)
* Merge ERC20Detailed into ERC20, make derived contracts abstract * Fix Create2 tests * Fix failing test * Default decimals to 18 * Add tests for setupDecimals * Add changelog entry * Update CHANGELOG.md * Update CHANGELOG.md * Replace isConstructor for !isContract * Update CHANGELOG.md Co-Authored-By: Francisco Giordano <frangio.1@gmail.com> Co-authored-by: Francisco Giordano <frangio.1@gmail.com>
This commit is contained in:
@ -3,6 +3,7 @@ pragma solidity ^0.6.0;
|
||||
import "../../GSN/Context.sol";
|
||||
import "./IERC20.sol";
|
||||
import "../../math/SafeMath.sol";
|
||||
import "../../utils/Address.sol";
|
||||
|
||||
/**
|
||||
* @dev Implementation of the {IERC20} interface.
|
||||
@ -30,6 +31,7 @@ import "../../math/SafeMath.sol";
|
||||
*/
|
||||
contract ERC20 is Context, IERC20 {
|
||||
using SafeMath for uint256;
|
||||
using Address for address;
|
||||
|
||||
mapping (address => uint256) private _balances;
|
||||
|
||||
@ -37,6 +39,57 @@ contract ERC20 is Context, IERC20 {
|
||||
|
||||
uint256 private _totalSupply;
|
||||
|
||||
string private _name;
|
||||
string private _symbol;
|
||||
uint8 private _decimals;
|
||||
|
||||
/**
|
||||
* @dev Sets the values for {name} and {symbol}, initializes {decimals} with
|
||||
* a default value of 18.
|
||||
*
|
||||
* To select a different value for {decimals}, use {_setupDecimals}.
|
||||
*
|
||||
* All three of these values are immutable: they can only be set once during
|
||||
* construction.
|
||||
*/
|
||||
constructor (string memory name, string memory symbol) public {
|
||||
_name = name;
|
||||
_symbol = symbol;
|
||||
_decimals = 18;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the name of the token.
|
||||
*/
|
||||
function name() public view returns (string memory) {
|
||||
return _name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the symbol of the token, usually a shorter version of the
|
||||
* name.
|
||||
*/
|
||||
function symbol() public view returns (string memory) {
|
||||
return _symbol;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the number of decimals used to get its user representation.
|
||||
* For example, if `decimals` equals `2`, a balance of `505` tokens should
|
||||
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
|
||||
*
|
||||
* Tokens usually opt for a value of 18, imitating the relationship between
|
||||
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
|
||||
* called.
|
||||
*
|
||||
* NOTE: This information is only used for _display_ purposes: it in
|
||||
* no way affects any of the arithmetic of the contract, including
|
||||
* {IERC20-balanceOf} and {IERC20-transfer}.
|
||||
*/
|
||||
function decimals() public view returns (uint8) {
|
||||
return _decimals;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {IERC20-totalSupply}.
|
||||
*/
|
||||
@ -223,6 +276,18 @@ contract ERC20 is Context, IERC20 {
|
||||
emit Approval(owner, spender, amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Sets {decimals} to a value other than the default one of 18.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - this function can only be called from a constructor.
|
||||
*/
|
||||
function _setupDecimals(uint8 decimals_) internal {
|
||||
require(!address(this).isContract(), "ERC20: decimals cannot be changed after construction");
|
||||
_decimals = decimals_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Hook that is called before any transfer of tokens. This includes
|
||||
* minting and burning.
|
||||
|
||||
@ -8,7 +8,7 @@ import "./ERC20.sol";
|
||||
* tokens and those that they have an allowance for, in a way that can be
|
||||
* recognized off-chain (via event analysis).
|
||||
*/
|
||||
contract ERC20Burnable is Context, ERC20 {
|
||||
abstract contract ERC20Burnable is Context, ERC20 {
|
||||
/**
|
||||
* @dev Destroys `amount` tokens from the caller.
|
||||
*
|
||||
|
||||
@ -5,7 +5,7 @@ import "./ERC20.sol";
|
||||
/**
|
||||
* @dev Extension of {ERC20} that adds a cap to the supply of tokens.
|
||||
*/
|
||||
contract ERC20Capped is ERC20 {
|
||||
abstract contract ERC20Capped is ERC20 {
|
||||
uint256 private _cap;
|
||||
|
||||
/**
|
||||
|
||||
@ -1,54 +0,0 @@
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "./IERC20.sol";
|
||||
|
||||
/**
|
||||
* @dev Optional functions from the ERC20 standard.
|
||||
*/
|
||||
abstract contract ERC20Detailed is IERC20 {
|
||||
string private _name;
|
||||
string private _symbol;
|
||||
uint8 private _decimals;
|
||||
|
||||
/**
|
||||
* @dev Sets the values for `name`, `symbol`, and `decimals`. All three of
|
||||
* these values are immutable: they can only be set once during
|
||||
* construction.
|
||||
*/
|
||||
constructor (string memory name, string memory symbol, uint8 decimals) public {
|
||||
_name = name;
|
||||
_symbol = symbol;
|
||||
_decimals = decimals;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the name of the token.
|
||||
*/
|
||||
function name() public view returns (string memory) {
|
||||
return _name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the symbol of the token, usually a shorter version of the
|
||||
* name.
|
||||
*/
|
||||
function symbol() public view returns (string memory) {
|
||||
return _symbol;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the number of decimals used to get its user representation.
|
||||
* For example, if `decimals` equals `2`, a balance of `505` tokens should
|
||||
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
|
||||
*
|
||||
* Tokens usually opt for a value of 18, imitating the relationship between
|
||||
* Ether and Wei.
|
||||
*
|
||||
* NOTE: This information is only used for _display_ purposes: it in
|
||||
* no way affects any of the arithmetic of the contract, including
|
||||
* {IERC20-balanceOf} and {IERC20-transfer}.
|
||||
*/
|
||||
function decimals() public view returns (uint8) {
|
||||
return _decimals;
|
||||
}
|
||||
}
|
||||
@ -11,7 +11,7 @@ import "../../utils/Pausable.sol";
|
||||
* period, or having an emergency switch for freezing all token transfers in the
|
||||
* event of a large bug.
|
||||
*/
|
||||
contract ERC20Pausable is ERC20, Pausable {
|
||||
abstract contract ERC20Pausable is ERC20, Pausable {
|
||||
/**
|
||||
* @dev See {ERC20-_beforeTokenTransfer}.
|
||||
*
|
||||
|
||||
@ -17,7 +17,7 @@ import "./ERC20.sol";
|
||||
* account address.
|
||||
* @author Validity Labs AG <info@validitylabs.org>
|
||||
*/
|
||||
contract ERC20Snapshot is ERC20 {
|
||||
abstract contract ERC20Snapshot is ERC20 {
|
||||
// Inspired by Jordi Baylina's MiniMeToken to record historical balances:
|
||||
// https://github.com/Giveth/minimd/blob/ea04d950eea153a04c51fa510b068b9dded390cb/contracts/MiniMeToken.sol
|
||||
|
||||
|
||||
Reference in New Issue
Block a user