add IERC20Detailed contract and update TestToken constructor
This commit is contained in:
parent
35903220cc
commit
88f019e6c6
|
@ -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);
|
|
||||||
}
|
|
|
@ -1,7 +1,7 @@
|
||||||
pragma solidity ^0.6.1;
|
pragma solidity ^0.6.1;
|
||||||
pragma experimental ABIEncoderV2;
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
import "./ERC20Token.sol";
|
import "./IERC20.sol";
|
||||||
|
|
||||||
contract GiftBucket {
|
contract GiftBucket {
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ contract GiftBucket {
|
||||||
|
|
||||||
address payable public owner;
|
address payable public owner;
|
||||||
|
|
||||||
ERC20Token public tokenContract;
|
IERC20 public tokenContract;
|
||||||
|
|
||||||
uint256 public expirationTime;
|
uint256 public expirationTime;
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ contract GiftBucket {
|
||||||
|
|
||||||
require(_expirationTime > block.timestamp, "expiration can't be in the past");
|
require(_expirationTime > block.timestamp, "expiration can't be in the past");
|
||||||
|
|
||||||
tokenContract = ERC20Token(_tokenAddress);
|
tokenContract = IERC20(_tokenAddress);
|
||||||
expirationTime = _expirationTime;
|
expirationTime = _expirationTime;
|
||||||
owner = payable(_owner);
|
owner = payable(_owner);
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
pragma solidity ^0.6.1;
|
pragma solidity ^0.6.1;
|
||||||
|
|
||||||
import "./ERC20Token.sol";
|
import "./IERC20.sol";
|
||||||
|
|
||||||
contract StandardToken is ERC20Token {
|
contract StandardToken is IERC20 {
|
||||||
|
|
||||||
uint256 private supply;
|
uint256 private supply;
|
||||||
mapping (address => uint256) balances;
|
mapping (address => uint256) balances;
|
||||||
|
@ -15,7 +15,7 @@ contract StandardToken is ERC20Token {
|
||||||
uint256 _value
|
uint256 _value
|
||||||
)
|
)
|
||||||
external
|
external
|
||||||
override(ERC20Token)
|
override(IERC20)
|
||||||
returns (bool success)
|
returns (bool success)
|
||||||
{
|
{
|
||||||
return transfer(msg.sender, _to, _value);
|
return transfer(msg.sender, _to, _value);
|
||||||
|
@ -23,7 +23,7 @@ contract StandardToken is ERC20Token {
|
||||||
|
|
||||||
function approve(address _spender, uint256 _value)
|
function approve(address _spender, uint256 _value)
|
||||||
external
|
external
|
||||||
override(ERC20Token)
|
override(IERC20)
|
||||||
returns (bool success)
|
returns (bool success)
|
||||||
{
|
{
|
||||||
allowed[msg.sender][_spender] = _value;
|
allowed[msg.sender][_spender] = _value;
|
||||||
|
@ -37,7 +37,7 @@ contract StandardToken is ERC20Token {
|
||||||
uint256 _value
|
uint256 _value
|
||||||
)
|
)
|
||||||
external
|
external
|
||||||
override(ERC20Token)
|
override(IERC20)
|
||||||
returns (bool success)
|
returns (bool success)
|
||||||
{
|
{
|
||||||
if (balances[_from] >= _value &&
|
if (balances[_from] >= _value &&
|
||||||
|
@ -53,7 +53,7 @@ contract StandardToken is ERC20Token {
|
||||||
function allowance(address _owner, address _spender)
|
function allowance(address _owner, address _spender)
|
||||||
external
|
external
|
||||||
view
|
view
|
||||||
override(ERC20Token)
|
override(IERC20)
|
||||||
returns (uint256 remaining)
|
returns (uint256 remaining)
|
||||||
{
|
{
|
||||||
return allowed[_owner][_spender];
|
return allowed[_owner][_spender];
|
||||||
|
@ -62,7 +62,7 @@ contract StandardToken is ERC20Token {
|
||||||
function balanceOf(address _owner)
|
function balanceOf(address _owner)
|
||||||
external
|
external
|
||||||
view
|
view
|
||||||
override(ERC20Token)
|
override(IERC20)
|
||||||
returns (uint256 balance)
|
returns (uint256 balance)
|
||||||
{
|
{
|
||||||
return balances[_owner];
|
return balances[_owner];
|
||||||
|
@ -71,7 +71,7 @@ contract StandardToken is ERC20Token {
|
||||||
function totalSupply()
|
function totalSupply()
|
||||||
external
|
external
|
||||||
view
|
view
|
||||||
override(ERC20Token)
|
override(IERC20)
|
||||||
returns(uint256 currentTotalSupply)
|
returns(uint256 currentTotalSupply)
|
||||||
{
|
{
|
||||||
return supply;
|
return supply;
|
||||||
|
|
|
@ -6,18 +6,32 @@ import "./StandardToken.sol";
|
||||||
* @notice ERC20Token for test scripts, can be minted by anyone.
|
* @notice ERC20Token for test scripts, can be minted by anyone.
|
||||||
*/
|
*/
|
||||||
contract TestToken is StandardToken {
|
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 {
|
fallback() external {
|
||||||
mint(1000);
|
uint256 amount = 5000;
|
||||||
}
|
mint(amount * uint256(10)**_decimals);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
function symbol() public view returns (string memory) {
|
||||||
* @notice any caller can mint any `_amount`
|
return _symbol;
|
||||||
* @param _amount how much to be minted
|
}
|
||||||
*/
|
|
||||||
function mint(uint256 _amount) public {
|
function decimals() public view returns (uint256) {
|
||||||
mint(msg.sender, _amount);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ config({
|
||||||
contracts: {
|
contracts: {
|
||||||
deploy: {
|
deploy: {
|
||||||
"TestToken": {
|
"TestToken": {
|
||||||
args: [],
|
args: ["TEST", 18],
|
||||||
},
|
},
|
||||||
"GiftBucket": {
|
"GiftBucket": {
|
||||||
args: ["$TestToken", EXPIRATION_TIME],
|
args: ["$TestToken", EXPIRATION_TIME],
|
||||||
|
|
Loading…
Reference in New Issue