Skip to content
This repository was archived by the owner on Jan 18, 2023. It is now read-only.

Commit de1e3ab

Browse files
authored
Merge pull request #1 from SetProtocol/justin_chen-update-contracts
Update Contracts
2 parents 6281254 + 74042d8 commit de1e3ab

14 files changed

+373
-304
lines changed

contracts/Migrations.sol

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
pragma solidity ^0.4.11;
1+
pragma solidity 0.4.18;
2+
23

34
contract Migrations {
45
address public owner;
5-
uint public last_completed_migration;
6+
uint public lastCompletedMigration;
67

78
modifier restricted() {
89
if (msg.sender == owner) _;
910
}
1011

11-
function Migrations() {
12+
function Migrations() public {
1213
owner = msg.sender;
1314
}
1415

15-
function setCompleted(uint completed) restricted {
16-
last_completed_migration = completed;
16+
function setCompleted(uint completed) public restricted {
17+
lastCompletedMigration = completed;
1718
}
1819

19-
function upgrade(address new_address) restricted {
20-
Migrations upgraded = Migrations(new_address);
21-
upgraded.setCompleted(last_completed_migration);
20+
function upgrade(address newAddress) public restricted {
21+
Migrations upgraded = Migrations(newAddress);
22+
upgraded.setCompleted(lastCompletedMigration);
2223
}
2324
}

contracts/SetToken.sol

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,49 @@
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";
29

3-
import './lib/StandardToken.sol';
4-
import './lib/ERC20.sol';
5-
import './lib/SafeMath.sol';
6-
import './lib/Set.sol';
710

811
/**
912
* @title {Set}
1013
* @author Felix Feng
1114
* @dev Implementation of the basic {Set} token.
1215
*/
13-
contract SetToken is Set, StandardToken {
16+
contract SetToken is StandardToken, DetailedERC20("", "", 18), Set {
17+
uint256 public totalSupply;
18+
1419
address[] public tokens;
1520
uint[] public units;
1621

1722
/**
1823
* @dev Constructor Function for the issuance of an {Set} token
1924
* @param _tokens address[] A list of token address which you want to include
2025
* @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 {
2328
// There must be tokens present
2429
require(_tokens.length > 0);
25-
30+
2631
// There must be an array of units
2732
require(_units.length > 0);
28-
33+
2934
// The number of tokens must equal the number of units
3035
require(_tokens.length == _units.length);
3136

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+
3247
// As looping operations are expensive, checking for duplicates will be
3348
// on the onus of the application developer
3449

@@ -37,25 +52,26 @@ contract SetToken is Set, StandardToken {
3752

3853
tokens = _tokens;
3954
units = _units;
55+
name = _name;
56+
symbol = _symbol;
4057
}
4158

42-
4359
/**
4460
* @dev Function to convert tokens into {Set} Tokens
4561
*
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
4763
* their ERC20 contract to transfer their tokens to this contract.
4864
*
4965
* @param quantity uint The quantity of tokens desired to convert
50-
*/
66+
*/
5167
function issue(uint quantity) public returns (bool success) {
5268
// Transfers the sender's tokens to the contract
5369
for (uint i = 0; i < tokens.length; i++) {
5470
address currentToken = tokens[i];
5571
uint currentUnits = units[i];
5672

5773
// 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));
5975
}
6076

6177
// If successful, increment the balance of the user’s {Set} token
@@ -75,27 +91,39 @@ contract SetToken is Set, StandardToken {
7591
* The ERC20 tokens do not need to be approved to call this function
7692
*
7793
* @param quantity uint The quantity of tokens desired to redeem
78-
*/
94+
*/
7995
function redeem(uint quantity) public returns (bool success) {
8096
// Check that the sender has sufficient tokens
8197
require(balances[msg.sender] >= quantity);
8298

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+
83105
for (uint i = 0; i < tokens.length; i++) {
84106
address currentToken = tokens[i];
85107
uint currentUnits = units[i];
86-
108+
87109
// The transaction will fail if any of the tokens fail to transfer
88110
assert(ERC20(currentToken).transfer(msg.sender, currentUnits * quantity));
89111
}
90112

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-
97113
LogRedemption(msg.sender, quantity);
98114

99115
return true;
100116
}
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+
}
101129
}

contracts/lib/BasicToken.sol

Lines changed: 0 additions & 42 deletions
This file was deleted.

contracts/lib/ERC20.sol

Lines changed: 0 additions & 16 deletions
This file was deleted.

contracts/lib/ERC20Basic.sol

Lines changed: 0 additions & 13 deletions
This file was deleted.

contracts/lib/SafeMath.sol

Lines changed: 0 additions & 32 deletions
This file was deleted.

contracts/lib/Set.sol

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
pragma solidity ^0.4.11;
1+
pragma solidity 0.4.18;
2+
23

34
/**
45
* @title Set interface
56
*/
67
contract Set {
7-
88
function issue(uint quantity) public returns (bool success);
99
function redeem(uint quantity) public returns (bool success);
1010

11-
event LogIssuance(address _sender, uint _quantity);
12-
event LogRedemption(address _sender, uint _quantity);
11+
event LogIssuance(
12+
address indexed _sender,
13+
uint indexed _quantity
14+
);
1315

14-
}
16+
event LogRedemption(
17+
address indexed _sender,
18+
uint indexed _quantity
19+
);
20+
}

contracts/lib/StandardToken.sol

Lines changed: 0 additions & 85 deletions
This file was deleted.

0 commit comments

Comments
 (0)