-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMerdetoken.sol
175 lines (134 loc) · 5.13 KB
/
Merdetoken.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/**
* Merdetoken
*
* See: https://theethereum.wiki/w/index.php/ERC20_Token_Standard
*
* This ICO allows participants to send ether to this contract in exchange
* for MDT tokens during the presale period (4 weeks).
*
* Once the presale period is over, no addition tokens may be created and the owner is
* able to withdraw the funds in according to a schedule which increases over time:
* - week 1: 1 ether
* - week 2: 2 ether
* - week 3: 4 ether
* - week 4: 8 ether
* ...and so on. This way as the project grows and further funds are required, more can
* be withdrawn, however, by deferring the funding, the owner cannot just cash out and
* skip town.
*
* An entry for a sinister contract...
*
* Content Info:
* http://u.solidity.cc/?t=1&cn=ZmxleGlibGVfcmVjc18y&iid=41e0d6e3f8114ddc86b2bd023e624f01&uid=869384457991671808&nid=244+272699400
*
*
* Licensed under both:
* - MIT License
* - Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
*
* Author information will be added once the contest has ended.
*/
// Not part of the exploit... Just shutting up compiler warnings...
pragma solidity ^0.4.10;
contract Merdetoken {
// ERC-20 constants
string public constant name = "Merdetoken";
string public constant symbol = "MDT";
uint8 public constant decimals = 18;
// The ICO owner
address owner;
// The token balance for each member
mapping (address => uint256) balances;
// Allowances for each member
mapping(address => mapping (address => uint256)) allowed;
// The total supply of these tokens
uint256 _totalSupply;
// The date that the presale ends and the token can be traded
uint256 activationDate;
// The last time the owner issued withdraw(uint256)
uint256 lastWithdrawDate;
/**
* constructor(uint256)
*
* Create a new instance of the Merdetoken, with a given presale
* duration.
*/
constructor(uint256 duration) payable public {
// Set the ICO owner
owner = msg.sender;
// The owner can buy their own tokens with an endowment (if desired)
balances[msg.sender] = msg.value;
_totalSupply = msg.value;
// Set the ICO presale end date
activationDate = now + duration;
}
/**
* withdraw(uint256)
*
* After the presale, the ICO owner may withdraw Ether from the contract
* on a deferred schedule; once per week, the amount doubling each week.
*/
function withdraw(uint256 amount) public {
// Cannot withdraw during the presale
if (now < activationDate) { throw; }
// Only the owner may withdraw funds
if (msg.sender != owner) { throw; }
// Only allow sane values to be sent
if (amount == 0 || amount > this.balance) { throw; }
// Can only withdraw once per week
if (now < lastWithdrawDate + (1 weeks)) { throw; }
lastWithdrawDate = now;
// Deferred withdraw schedule; may only withdraw 1 more ether than has ever
// been withdrawn. See top decription for schedule.
uint256 maxAmount = (_totalSupply - this.balance + (1 ether));
// Cannot withdraw more than the maximum allowed by schedule
if (amount > maxAmount) { throw; }
// Send the funds
if (!owner.send(amount)) { throw; }
}
/**
* fallback function
*
* Exchange Ether for MDT tokens. This may not be called once the presale has ended.
*/
function () payable public {
// Can only buy tokens during the presale
if (now >= activationDate) { throw; }
// Give out the tokens
balances[msg.sender] += msg.value;
_totalSupply += msg.value;
}
/**
* ERC-20 token; nothing sinister below here (if there is, it wasn't intended)
* Mostly just copy and pasted from the de facto existing implmentation; changes marked
*/
function totalSupply() constant public returns (uint totalSupply) {
return _totalSupply;
}
function balanceOf(address _owner) constant public returns (uint256 balance) {
return balances[_owner];
}
function transfer(address _to, uint256 _amount) public returns (bool success) {
// Cannot transfer tokens during the presale
if (now < activationDate) { return false; }
if (balances[msg.sender] < _amount || _amount == 0) { return false; }
balances[msg.sender] -= _amount;
balances[_to] += _amount;
return true;
}
function transferFrom(address _from, address _to, uint256 _amount) public returns (bool success) {
// Cannot transfer tokens during the presale
if (now < activationDate) { return false; }
if (allowed[_from][msg.sender] < _amount || balances[_from] < _amount || _amount == 0) {
return false;
}
balances[_from] -= _amount;
allowed[_from][msg.sender] -= _amount;
balances[_to] += _amount;
return true;
}
function approve(address _spender, uint256 _amount) public returns (bool success) {
allowed[msg.sender][_spender] = _amount;
return true;
}
}