-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy path0xa9666166d3c7fd15e874801f99e9ad5bfb70c5cf-GBP_S-GBP_Static.sol
456 lines (397 loc) · 18.3 KB
/
0xa9666166d3c7fd15e874801f99e9ad5bfb70c5cf-GBP_S-GBP_Static.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
pragma solidity ^0.4.16;
//https://github.com/genkifs/staticoin
contract owned {
address owner;
function owned() {
owner = msg.sender;
}
function changeOwner(address newOwner) onlyOwner {
owner = newOwner;
}
modifier onlyOwner() {
if (msg.sender==owner)
_;
}
}
contract mortal is owned() {
function kill() onlyOwner {
if (msg.sender == owner) selfdestruct(owner);
}
}
library ERC20Lib {
//Inspired by https://blog.aragon.one/library-driven-development-in-solidity-2bebcaf88736
struct TokenStorage {
mapping (address => uint256) balances;
mapping (address => mapping (address => uint256)) allowed;
uint256 totalSupply;
}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
modifier onlyPayloadSize(uint numwords) {
/**
* @dev Checks for short addresses
* @param numwords number of parameters passed
*/
assert(msg.data.length >= numwords * 32 + 4);
_;
}
modifier validAddress(address _address) {
/**
* @dev validates an address.
* @param _address checks that it isn't null or this contract address
*/
require(_address != 0x0);
require(_address != address(msg.sender));
_;
}
modifier IsWallet(address _address) {
/**
* @dev Transfer tokens from msg.sender to another address.
* Cannot Allows execution if the transfer to address code size is 0
* @param _address address to check that its not a contract
*/
uint codeLength;
assembly {
// Retrieve the size of the code on target address, this needs assembly .
codeLength := extcodesize(_address)
}
assert(codeLength==0);
_;
}
function safeMul(uint a, uint b) returns (uint) {
uint c = a * b;
assert(a == 0 || c / a == b);
return c;
}
function safeSub(uint a, uint b) returns (uint) {
assert(b <= a);
return a - b;
}
function safeAdd(uint a, uint b) returns (uint) {
uint c = a + b;
assert(c>=a && c>=b);
return c;
}
function init(TokenStorage storage self, uint _initial_supply) {
self.totalSupply = _initial_supply;
self.balances[msg.sender] = _initial_supply;
}
function transfer(TokenStorage storage self, address _to, uint256 _value)
onlyPayloadSize(3)
IsWallet(_to)
returns (bool success) {
/**
* @dev Transfer tokens from msg.sender to another address.
* Cannot be used to send tokens to a contract, this means contracts cannot mint coins to themselves
* Contracts have to use the approve and transfer method
* this is based on https://github.com/Dexaran/ERC223-token-standard
* @param _to address The address where the coin is to be transfered
* @param _value uint256 the amount of tokens to be transferred
*/
if (self.balances[msg.sender] >= _value && self.balances[_to] + _value > self.balances[_to]) {
self.balances[msg.sender] = safeSub(self.balances[msg.sender], _value);
self.balances[_to] = safeAdd(self.balances[_to], _value);
Transfer(msg.sender, _to, _value);
return true;
} else { return false; }
}
function transferFrom(TokenStorage storage self, address _from, address _to, uint256 _value)
onlyPayloadSize(4)
validAddress(_from)
validAddress(_to)
returns (bool success) {
/**
* @dev Transfer tokens from one address to another. Requires allowance to be set.
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
if (self.balances[_from] >= _value && self.allowed[_from][msg.sender] >= _value && self.balances[_to] + _value > self.balances[_to]) {
var _allowance = self.allowed[_from][msg.sender];
self.balances[_to] = safeAdd(self.balances[_to], _value);
self.balances[_from] = safeSub(self.balances[_from], _value);
self.allowed[_from][msg.sender] = safeSub(_allowance, _value);
Transfer(_from, _to, _value);
return true;
} else { return false; }
}
function balanceOf(TokenStorage storage self, address _owner) constant
onlyPayloadSize(2)
validAddress(_owner)
returns (uint256 balance) {
/**
* @dev returns the amount given to an account
* @param _owner The address to be queried
* @return Balance of _owner.
*/
return self.balances[_owner];
}
function approve(TokenStorage storage self, address _spender, uint256 _value)
onlyPayloadSize(3)
validAddress(_spender)
returns (bool success) {
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
//require user to set to zero before resetting to nonzero
if ((_value != 0) && (self.allowed[msg.sender][_spender] != 0)) {
return false;
} else {
self.allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
}
function allowance(TokenStorage storage self, address _owner, address _spender) constant
onlyPayloadSize(3)
validAddress(_owner)
validAddress(_spender)
returns (uint256 remaining) {
/**
* @dev allows queries of how much a given address is allowed to spend on behalf of another account
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return remaining uint256 specifying the amount of tokens still available for the spender.
*/
return self.allowed[_owner][_spender];
}
function increaseApproval(TokenStorage storage self, address _spender, uint256 _addedValue)
onlyPayloadSize(3)
validAddress(_spender)
returns (bool success) {
/**
* @dev Allows to increment allowed value
* better to use this function to avoid 2 calls
* @param _spender address The address which will spend the funds.
* @param _addedValue amount to increase alowance by.
* @return True if allowance increased
*/
uint256 oldValue = self.allowed[msg.sender][_spender];
self.allowed[msg.sender][_spender] = safeAdd(oldValue, _addedValue);
return true;
}
function decreaseApproval(TokenStorage storage self,address _spender, uint256 _subtractedValue)
onlyPayloadSize(3)
validAddress(_spender)
returns (bool success) {
/**
* @dev Allows to decrement allowed value
* better to use this function to avoid 2 calls
* @param _spender address The address which will spend the funds.
* @param _subtractedValue amount to decrease allowance by.
* @return True if allowance decreased
*/
uint256 oldValue = self.allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
self.allowed[msg.sender][_spender] = 0;
} else {
self.allowed[msg.sender][_spender] = safeSub(oldValue, _subtractedValue);
}
return true;
}
/* Approves and then calls the receiving contract with any additional paramteres*/
function approveAndCall(TokenStorage storage self, address _spender, uint256 _value, bytes _extraData)
onlyPayloadSize(4)
validAddress(_spender)
returns (bool success) {
//require user to set to zero before resetting to nonzero
/**
* @dev Approves and then calls the receiving contract with any additional paramteres
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @param _value address The address which will spend the funds.
* @param _extraData is the additional paramters passed
* @return True if successful.
*/
if ((_value != 0) && (self.allowed[msg.sender][_spender] != 0)) {
return false;
} else {
self.allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
//call the receiveApproval function on the contract you want to be notified.
//This crafts the function signature manually so one doesn't have to include a contract in here just for this.
//it is assumed that when does this that the call *should* succeed, otherwise one would use vanilla approve instead.
if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { revert(); }
return true;
}
}
function mintCoin(TokenStorage storage self, address target, uint256 mintedAmount, address owner)
internal
returns (bool success) {
/**
* @dev Approves and then calls the receiving contract with any additional paramteres
* @param target address the address which will receive the funds.
* @param mintedAmount the amount of funds to be sent.
* @param owner the contract responsable for controling the amount of funds.
* @return True if successful.
*/
self.balances[target] = safeAdd(self.balances[target], mintedAmount);//balances[target] += mintedAmount;
self.totalSupply = safeAdd(self.totalSupply, mintedAmount);//totalSupply += mintedAmount;
Transfer(0, owner, mintedAmount); // Deliver coin to the mint
Transfer(owner, target, mintedAmount); // mint delivers to address
return true;
}
function meltCoin(TokenStorage storage self, address target, uint256 meltedAmount, address owner)
internal
returns (bool success) {
/**
* @dev Approves and then calls the receiving contract with any additional paramteres
* @param target address the address which will return the funds.
* @param meltedAmount the amount of funds to be returned.
* @param owner the contract responsable for controling the amount of funds.
* @return True if successful.
*/
if(self.balances[target]<meltedAmount){
return false;
}
self.balances[target] = safeSub(self.balances[target], meltedAmount); //balances[target] -= meltedAmount;
self.totalSupply = safeSub(self.totalSupply, meltedAmount); //totalSupply -= meltedAmount;
Transfer(target, owner, meltedAmount); // address delivers to minter
Transfer(owner, 0, meltedAmount); // minter delivers coin to the burn address
return true;
}
}
/** @title StandardToken. */
contract StandardToken is owned{
using ERC20Lib for ERC20Lib.TokenStorage;
ERC20Lib.TokenStorage public token;
string public name; //Long token name
uint8 public decimals=18; //How many decimals to show. ie. There could 1000 base units with 3 decimals. Meaning 0.980 SBX = 980 base units. It's like comparing 1 wei to 1 ether.
string public symbol; //An identifier: eg SBX
string public version = 'H0.1'; //human 0.1 standard. Just an arbitrary versioning scheme.
uint public INITIAL_SUPPLY = 0; // mintable coin has zero inital supply (and can fall back to zero)
event Transfer(address indexed _from, address indexed _to, uint _value);
event Approval(address indexed _owner, address indexed _spender, uint _value);
function StandardToken() {
token.init(INITIAL_SUPPLY);
}
function totalSupply() constant returns (uint) {
return token.totalSupply;
}
function balanceOf(address who) constant returns (uint) {
return token.balanceOf(who);
}
function allowance(address owner, address _spender) constant returns (uint) {
return token.allowance(owner, _spender);
}
function transfer(address to, uint value) returns (bool ok) {
return token.transfer(to, value);
}
function transferFrom(address _from, address _to, uint _value) returns (bool ok) {
return token.transferFrom(_from, _to, _value);
}
function approve(address _spender, uint value) returns (bool ok) {
return token.approve(_spender, value);
}
function increaseApproval(address _spender, uint256 _addedValue) returns (bool ok) {
return token.increaseApproval(_spender, _addedValue);
}
function decreaseApproval(address _spender, uint256 _subtractedValue) returns (bool ok) {
return token.decreaseApproval(_spender, _subtractedValue);
}
function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool ok){
return token.approveAndCall(_spender,_value,_extraData);
}
function mintCoin(address target, uint256 mintedAmount) onlyOwner returns (bool ok) {
return token.mintCoin(target,mintedAmount,owner);
}
function meltCoin(address target, uint256 meltedAmount) onlyOwner returns (bool ok) {
return token.meltCoin(target,meltedAmount,owner);
}
}
/** @title Coin. */
contract Coin is StandardToken, mortal{
I_minter public mint; //Minter interface
event EventClear();
function Coin(string _tokenName, string _tokenSymbol, address _minter) {
name = _tokenName; // Set the name for display purposes
symbol = _tokenSymbol; // Set the symbol for display purposes
changeOwner(_minter);
mint=I_minter(_minter);
}
}
/** @title RiskCoin. */
contract RiskCoin is Coin{
function RiskCoin(string _tokenName, string _tokenSymbol, address _minter)
Coin(_tokenName,_tokenSymbol,_minter) {}
function() payable {
/** @dev direct any ETH sent to this RiskCoin address to the minter.NewRisk function
*/
mint.NewRiskAdr.value(msg.value)(msg.sender);
}
}
/** @title StatiCoin. */
contract StatiCoin is Coin{
function StatiCoin(string _tokenName, string _tokenSymbol, address _minter)
Coin(_tokenName,_tokenSymbol,_minter) {}
function() payable {
/** @dev direct any ETH sent to this StatiCoin address to the minter.NewStatic function
*/
mint.NewStaticAdr.value(msg.value)(msg.sender);
}
}
/** @title I_coin. */
contract I_coin is mortal {
event EventClear();
I_minter public mint;
string public name; //fancy name: eg Simon Bucks
uint8 public decimals=18; //How many decimals to show. ie. There could 1000 base units with 3 decimals. Meaning 0.980 SBX = 980 base units. It's like comparing 1 wei to 1 ether.
string public symbol; //An identifier: eg SBX
string public version = ''; //human 0.1 standard. Just an arbitrary versioning scheme.
function mintCoin(address target, uint256 mintedAmount) returns (bool success) {}
function meltCoin(address target, uint256 meltedAmount) returns (bool success) {}
function approveAndCall(address _spender, uint256 _value, bytes _extraData){}
function setMinter(address _minter) {}
function increaseApproval (address _spender, uint256 _addedValue) returns (bool success) {}
function decreaseApproval (address _spender, uint256 _subtractedValue) returns (bool success) {}
// @param _owner The address from which the balance will be retrieved
// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance) {}
// @notice send `_value` token to `_to` from `msg.sender`
// @param _to The address of the recipient
// @param _value The amount of token to be transferred
// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success) {}
// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
// @param _from The address of the sender
// @param _to The address of the recipient
// @param _value The amount of token to be transferred
// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
// @notice `msg.sender` approves `_addr` to spend `_value` tokens
// @param _spender The address of the account able to transfer the tokens
// @param _value The amount of wei to be approved for transfer
// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success) {}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
// @param _owner The address of the account owning tokens
// @param _spender The address of the account able to transfer the tokens
// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
mapping (address => uint256) balances;
mapping (address => mapping (address => uint256)) allowed;
// @return total amount of tokens
uint256 public totalSupply;
}
/** @title I_minter. */
contract I_minter {
event EventCreateStatic(address indexed _from, uint128 _value, uint _transactionID, uint _Price);
event EventRedeemStatic(address indexed _from, uint128 _value, uint _transactionID, uint _Price);
event EventCreateRisk(address indexed _from, uint128 _value, uint _transactionID, uint _Price);
event EventRedeemRisk(address indexed _from, uint128 _value, uint _transactionID, uint _Price);
event EventBankrupt();
function Leverage() constant returns (uint128) {}
function RiskPrice(uint128 _currentPrice,uint128 _StaticTotal,uint128 _RiskTotal, uint128 _ETHTotal) constant returns (uint128 price) {}
function RiskPrice(uint128 _currentPrice) constant returns (uint128 price) {}
function PriceReturn(uint _TransID,uint128 _Price) {}
function NewStatic() external payable returns (uint _TransID) {}
function NewStaticAdr(address _Risk) external payable returns (uint _TransID) {}
function NewRisk() external payable returns (uint _TransID) {}
function NewRiskAdr(address _Risk) external payable returns (uint _TransID) {}
function RetRisk(uint128 _Quantity) external payable returns (uint _TransID) {}
function RetStatic(uint128 _Quantity) external payable returns (uint _TransID) {}
function Strike() constant returns (uint128) {}
}