1
- pragma solidity ^ 0.4.11 ;
1
+ pragma solidity 0.4.18 ;
2
+
3
+
4
+ import "zeppelin-solidity/contracts/token/ERC20/StandardToken.sol " ;
5
+ import "zeppelin-solidity/contracts/token/ERC20/ERC20.sol " ;
6
+ import "zeppelin-solidity/contracts/token/ERC20/DetailedERC20.sol " ;
7
+ import "zeppelin-solidity/contracts/math/SafeMath.sol " ;
8
+ import "./lib/Set.sol " ;
2
9
3
- import './lib/StandardToken.sol ' ;
4
- import './lib/ERC20.sol ' ;
5
- import './lib/SafeMath.sol ' ;
6
- import './lib/Set.sol ' ;
7
10
8
11
/**
9
12
* @title {Set}
10
13
* @author Felix Feng
11
14
* @dev Implementation of the basic {Set} token.
12
15
*/
13
- contract SetToken is Set , StandardToken {
16
+ contract SetToken is StandardToken , DetailedERC20 ("", "", 18 ), Set {
17
+ uint256 public totalSupply;
18
+
14
19
address [] public tokens;
15
20
uint [] public units;
16
21
17
22
/**
18
23
* @dev Constructor Function for the issuance of an {Set} token
19
24
* @param _tokens address[] A list of token address which you want to include
20
25
* @param _units uint[] A list of quantities of each token (corresponds to the {Set} of _tokens)
21
- */
22
- function SetToken (address [] _tokens , uint [] _units ) {
26
+ */
27
+ function SetToken (address [] _tokens , uint [] _units , string _name , string _symbol ) public {
23
28
// There must be tokens present
24
29
require (_tokens.length > 0 );
25
-
30
+
26
31
// There must be an array of units
27
32
require (_units.length > 0 );
28
-
33
+
29
34
// The number of tokens must equal the number of units
30
35
require (_tokens.length == _units.length );
31
36
37
+ for (uint i = 0 ; i < _units.length ; i++ ) {
38
+ // Check that all units are non-zero. Negative numbers will underflow
39
+ uint currentUnits = _units[i];
40
+ require (currentUnits > 0 );
41
+
42
+ // Check that all addresses are non-zero
43
+ address currentToken = _tokens[i];
44
+ require (currentToken != address (0 ));
45
+ }
46
+
32
47
// As looping operations are expensive, checking for duplicates will be
33
48
// on the onus of the application developer
34
49
@@ -37,25 +52,26 @@ contract SetToken is Set, StandardToken {
37
52
38
53
tokens = _tokens;
39
54
units = _units;
55
+ name = _name;
56
+ symbol = _symbol;
40
57
}
41
58
42
-
43
59
/**
44
60
* @dev Function to convert tokens into {Set} Tokens
45
61
*
46
- * Please note that the user's ERC20 tokens must be approved by
62
+ * Please note that the user's ERC20 tokens must be approved by
47
63
* their ERC20 contract to transfer their tokens to this contract.
48
64
*
49
65
* @param quantity uint The quantity of tokens desired to convert
50
- */
66
+ */
51
67
function issue (uint quantity ) public returns (bool success ) {
52
68
// Transfers the sender's tokens to the contract
53
69
for (uint i = 0 ; i < tokens.length ; i++ ) {
54
70
address currentToken = tokens[i];
55
71
uint currentUnits = units[i];
56
72
57
73
// The transaction will fail if any of the tokens fail to transfer
58
- assert (ERC20 (currentToken).transferFrom (msg .sender , this , currentUnits * quantity));
74
+ assert (ERC20 (currentToken).transferFrom (msg .sender , this , currentUnits * quantity));
59
75
}
60
76
61
77
// If successful, increment the balance of the user’s {Set} token
@@ -75,27 +91,39 @@ contract SetToken is Set, StandardToken {
75
91
* The ERC20 tokens do not need to be approved to call this function
76
92
*
77
93
* @param quantity uint The quantity of tokens desired to redeem
78
- */
94
+ */
79
95
function redeem (uint quantity ) public returns (bool success ) {
80
96
// Check that the sender has sufficient tokens
81
97
require (balances[msg .sender ] >= quantity);
82
98
99
+ // If successful, decrement the balance of the user’s {Set} token
100
+ balances[msg .sender ] = SafeMath.sub (balances[msg .sender ], quantity);
101
+
102
+ // Decrement the total token supply
103
+ totalSupply = SafeMath.sub (totalSupply, quantity);
104
+
83
105
for (uint i = 0 ; i < tokens.length ; i++ ) {
84
106
address currentToken = tokens[i];
85
107
uint currentUnits = units[i];
86
-
108
+
87
109
// The transaction will fail if any of the tokens fail to transfer
88
110
assert (ERC20 (currentToken).transfer (msg .sender , currentUnits * quantity));
89
111
}
90
112
91
- // If successful, decrement the balance of the user’s {Set} token
92
- balances[msg .sender ] = SafeMath.sub (balances[msg .sender ], quantity);
93
-
94
- // Decrement the total token supply
95
- totalSupply = SafeMath.sub (totalSupply, quantity);
96
-
97
113
LogRedemption (msg .sender , quantity);
98
114
99
115
return true ;
100
116
}
117
+
118
+ function tokenCount () public view returns (uint tokensLength ) {
119
+ return tokens.length ;
120
+ }
121
+
122
+ function getTokens () public view returns (address []) {
123
+ return tokens;
124
+ }
125
+
126
+ function getUnits () public view returns (uint []) {
127
+ return units;
128
+ }
101
129
}
0 commit comments