@@ -4,7 +4,7 @@ pragma solidity 0.4.21;
4
4
import "zeppelin-solidity/contracts/token/ERC20/StandardToken.sol " ;
5
5
import "zeppelin-solidity/contracts/token/ERC20/ERC20.sol " ;
6
6
import "zeppelin-solidity/contracts/token/ERC20/DetailedERC20.sol " ;
7
- import "zeppelin-solidity/contracts/math/SafeMath .sol " ;
7
+ import "./external/SafeMathUint256 .sol " ;
8
8
import "./lib/Set.sol " ;
9
9
10
10
@@ -14,10 +14,9 @@ import "./lib/Set.sol";
14
14
* @dev Implementation of the basic {Set} token.
15
15
*/
16
16
contract SetToken is StandardToken , DetailedERC20 ("", "", 18 ), Set {
17
- using SafeMath for uint256 ;
17
+ using SafeMathUint256 for uint256 ;
18
18
19
19
uint256 public totalSupply;
20
-
21
20
address [] public components;
22
21
uint [] public units;
23
22
@@ -26,7 +25,7 @@ contract SetToken is StandardToken, DetailedERC20("", "", 18), Set {
26
25
* @param _components address[] A list of component address which you want to include
27
26
* @param _units uint[] A list of quantities in gWei of each component (corresponds to the {Set} of _components)
28
27
*/
29
- function SetToken (address [] _components , uint [] _units , string _name , string _symbol ) public {
28
+ function SetToken (address [] _components , uint [] _units ) public {
30
29
// There must be component present
31
30
require (_components.length > 0 );
32
31
@@ -54,8 +53,6 @@ contract SetToken is StandardToken, DetailedERC20("", "", 18), Set {
54
53
55
54
components = _components;
56
55
units = _units;
57
- name = _name;
58
- symbol = _symbol;
59
56
}
60
57
61
58
/**
@@ -68,14 +65,16 @@ contract SetToken is StandardToken, DetailedERC20("", "", 18), Set {
68
65
*/
69
66
function issue (uint quantity ) public returns (bool success ) {
70
67
// Transfers the sender's components to the contract
68
+ // Since the component length is defined ahead of time, this is not
69
+ // an unbounded loop
71
70
for (uint i = 0 ; i < components.length ; i++ ) {
72
71
address currentComponent = components[i];
73
72
uint currentUnits = units[i];
74
73
75
74
// Transfer value is defined as the currentUnits (in GWei)
76
75
// multiplied by quantity in Wei divided by the units of gWei.
77
76
// We do this to allow fractional units to be defined
78
- uint transferValue = currentUnits.mul (quantity). div ( 10 ** 9 );
77
+ uint transferValue = currentUnits.fxpMul (quantity, 10 ** 9 );
79
78
80
79
// Protect against the case that the gWei divisor results in a value that is
81
80
// 0 and the user is able to generate Sets without sending a balance
@@ -104,6 +103,8 @@ contract SetToken is StandardToken, DetailedERC20("", "", 18), Set {
104
103
*/
105
104
function redeem (uint quantity ) public returns (bool success ) {
106
105
// Check that the sender has sufficient components
106
+ // Since the component length is defined ahead of time, this is not
107
+ // an unbounded loop
107
108
require (balances[msg .sender ] >= quantity);
108
109
109
110
// To prevent re-entrancy attacks, decrement the user's Set balance
@@ -116,13 +117,16 @@ contract SetToken is StandardToken, DetailedERC20("", "", 18), Set {
116
117
address currentComponent = components[i];
117
118
uint currentUnits = units[i];
118
119
119
- // The transaction will fail if any of the components fail to transfer
120
- uint transferValue = currentUnits.mul (quantity).div (10 ** 9 );
120
+ // Transfer value is defined as the currentUnits (in GWei)
121
+ // multiplied by quantity in Wei divided by the units of gWei.
122
+ // We do this to allow fractional units to be defined
123
+ uint transferValue = currentUnits.fxpMul (quantity, 10 ** 9 );
121
124
122
125
// Protect against the case that the gWei divisor results in a value that is
123
126
// 0 and the user is able to generate Sets without sending a balance
124
127
assert (transferValue > 0 );
125
128
129
+ // The transaction will fail if any of the components fail to transfer
126
130
assert (ERC20 (currentComponent).transfer (msg .sender , transferValue));
127
131
}
128
132
0 commit comments