-
Notifications
You must be signed in to change notification settings - Fork 1
/
YBT.sol
90 lines (90 loc) · 2.76 KB
/
YBT.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
pragma solidity ^0.4.24;
contract YellowBetterToken
{
string public constant name = "Yellow Better";
string public constant symbol = "YBT";
uint8 public constant decimals = 18;
uint public constant _totalSupply = 2000000000000000000000000000;
uint public totalSupply = _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
event Transfer(address indexed, address indexed, uint);
event Approval(address indexed, address indexed, uint);
event Burn(address indexed, uint);
constructor()
{
balances[msg.sender] = totalSupply;
}
function sub(uint a, uint b) private pure returns (uint)
{
require(a >= b);
return a - b;
}
function balanceOf(address tokenOwner) view returns (uint)
{
return balances[tokenOwner];
}
function transfer(address to, uint tokens) returns (bool)
{
balances[msg.sender] = sub(balances[msg.sender], tokens);
balances[to] += tokens;
emit Transfer(msg.sender, to, tokens);
return true;
}
function transferFrom(address from, address to, uint tokens) returns (bool)
{
// subtract tokens from both balance and allowance, fail if any is smaller
balances[from] = sub(balances[from], tokens);
allowed[from][msg.sender] = sub(allowed[from][msg.sender], tokens);
balances[to] += tokens;
emit Transfer(from, to, tokens);
return true;
}
function approve(address spender, uint tokens) returns (bool)
{
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
function allowance(address tokenOwner, address spender) view returns (uint)
{
return allowed[tokenOwner][spender];
}
function burn(uint tokens)
{
balances[msg.sender] = sub(balances[msg.sender], tokens);
totalSupply -= tokens;
emit Burn(msg.sender, tokens);
}
}
contract TokenSale
{
address public creator;
address public tokenContract;
uint public tokenPrice; // in wei
uint public deadline;
constructor(address source)
{
creator = msg.sender;
tokenContract = source;
}
function setPrice(uint price)
{
if (msg.sender == creator) tokenPrice = price;
}
function setDeadline(uint timestamp)
{
if (msg.sender == creator) deadline = timestamp;
}
function buyTokens(address beneficiary) payable
{
require(
block.timestamp < deadline
&& tokenPrice > 0
&& YellowBetterToken(tokenContract).transfer(beneficiary, 1000000000000000000 * msg.value / tokenPrice));
}
function payout()
{
creator.transfer(this.balance);
}
}