add IERC20Detailed contract and update TestToken constructor

This commit is contained in:
Andrea Franz 2020-03-30 15:43:39 +02:00
parent 35903220cc
commit 88f019e6c6
No known key found for this signature in database
GPG Key ID: 4F0D2F2D9DE7F29D
7 changed files with 61 additions and 38 deletions

View File

@ -1,15 +0,0 @@
pragma solidity ^0.6.1;
// https://github.com/ethereum/EIPs/issues/20
interface ERC20Token {
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
function transfer(address _to, uint256 _value) external returns (bool success);
function approve(address _spender, uint256 _value) external returns (bool success);
function transferFrom(address _from, address _to, uint256 _value) external returns (bool success);
function balanceOf(address _owner) external view returns (uint256 balance);
function allowance(address _owner, address _spender) external view returns (uint256 remaining);
function totalSupply() external view returns (uint256 supply);
}

View File

@ -1,7 +1,7 @@
pragma solidity ^0.6.1;
pragma experimental ABIEncoderV2;
import "./ERC20Token.sol";
import "./IERC20.sol";
contract GiftBucket {
@ -9,7 +9,7 @@ contract GiftBucket {
address payable public owner;
ERC20Token public tokenContract;
IERC20 public tokenContract;
uint256 public expirationTime;
@ -46,7 +46,7 @@ contract GiftBucket {
require(_expirationTime > block.timestamp, "expiration can't be in the past");
tokenContract = ERC20Token(_tokenAddress);
tokenContract = IERC20(_tokenAddress);
expirationTime = _expirationTime;
owner = payable(_owner);

15
contracts/IERC20.sol Normal file
View File

@ -0,0 +1,15 @@
pragma solidity ^0.6.1;
// https://github.com/ethereum/EIPs/issues/20
interface IERC20 {
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
function transfer(address _to, uint256 _value) external returns (bool success);
function approve(address _spender, uint256 _value) external returns (bool success);
function transferFrom(address _from, address _to, uint256 _value) external returns (bool success);
function balanceOf(address _owner) external view returns (uint256 balance);
function allowance(address _owner, address _spender) external view returns (uint256 remaining);
function totalSupply() external view returns (uint256 supply);
}

View File

@ -0,0 +1,9 @@
pragma solidity >=0.5.0 <0.7.0;
import "./IERC20.sol";
abstract contract IERC20Detailed is IERC20 {
function symbol() virtual public view returns (string memory);
function decimals() virtual public view returns (uint8);
}

View File

@ -1,8 +1,8 @@
pragma solidity ^0.6.1;
import "./ERC20Token.sol";
import "./IERC20.sol";
contract StandardToken is ERC20Token {
contract StandardToken is IERC20 {
uint256 private supply;
mapping (address => uint256) balances;
@ -15,7 +15,7 @@ contract StandardToken is ERC20Token {
uint256 _value
)
external
override(ERC20Token)
override(IERC20)
returns (bool success)
{
return transfer(msg.sender, _to, _value);
@ -23,7 +23,7 @@ contract StandardToken is ERC20Token {
function approve(address _spender, uint256 _value)
external
override(ERC20Token)
override(IERC20)
returns (bool success)
{
allowed[msg.sender][_spender] = _value;
@ -37,7 +37,7 @@ contract StandardToken is ERC20Token {
uint256 _value
)
external
override(ERC20Token)
override(IERC20)
returns (bool success)
{
if (balances[_from] >= _value &&
@ -53,7 +53,7 @@ contract StandardToken is ERC20Token {
function allowance(address _owner, address _spender)
external
view
override(ERC20Token)
override(IERC20)
returns (uint256 remaining)
{
return allowed[_owner][_spender];
@ -62,7 +62,7 @@ contract StandardToken is ERC20Token {
function balanceOf(address _owner)
external
view
override(ERC20Token)
override(IERC20)
returns (uint256 balance)
{
return balances[_owner];
@ -71,7 +71,7 @@ contract StandardToken is ERC20Token {
function totalSupply()
external
view
override(ERC20Token)
override(IERC20)
returns(uint256 currentTotalSupply)
{
return supply;

View File

@ -6,18 +6,32 @@ import "./StandardToken.sol";
* @notice ERC20Token for test scripts, can be minted by anyone.
*/
contract TestToken is StandardToken {
string private _symbol;
uint256 private _decimals;
constructor() public { }
constructor(string memory symbol, uint256 decimals) public {
_symbol = symbol;
_decimals = decimals;
}
fallback() external {
mint(1000);
}
fallback() external {
uint256 amount = 5000;
mint(amount * uint256(10)**_decimals);
}
/**
* @notice any caller can mint any `_amount`
* @param _amount how much to be minted
*/
function mint(uint256 _amount) public {
mint(msg.sender, _amount);
}
function symbol() public view returns (string memory) {
return _symbol;
}
function decimals() public view returns (uint256) {
return _decimals;
}
/**
* @notice any caller can mint any `_amount`
* @param _amount how much to be minted
*/
function mint(uint256 _amount) public {
mint(msg.sender, _amount);
}
}

View File

@ -20,7 +20,7 @@ config({
contracts: {
deploy: {
"TestToken": {
args: [],
args: ["TEST", 18],
},
"GiftBucket": {
args: ["$TestToken", EXPIRATION_TIME],