Skip to content
This repository was archived by the owner on Jan 18, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 54 additions & 9 deletions contracts/core/SetToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ pragma solidity 0.4.24;


import { DetailedERC20 } from "zeppelin-solidity/contracts/token/ERC20/DetailedERC20.sol";
import { StandardToken } from "zeppelin-solidity/contracts/token/ERC20/StandardToken.sol";
import { SafeMath } from "zeppelin-solidity/contracts/math/SafeMath.sol";
import { StandardToken } from "zeppelin-solidity/contracts/token/ERC20/StandardToken.sol";
import { ISetFactory } from "./interfaces/ISetFactory.sol";


Expand Down Expand Up @@ -97,6 +97,7 @@ contract SetToken is
}

modifier isPositive(uint _quantity) {
// Require quantity passed is greater than 0
require(
_quantity > 0,
ZERO_QUANTITY
Expand All @@ -105,7 +106,9 @@ contract SetToken is
}

modifier isValidDestination(address _to) {
// Confirm address is not null
require(_to != address(0));
// Confirm address is not this address
require(_to != address(this));
_;
}
Expand All @@ -117,11 +120,12 @@ contract SetToken is
*
* As looping operations are expensive, checking for duplicates will be on the onus of the application developer
*
* @param _components address[] A list of component address which you want to include
* @param _units uint[] A list of quantities in gWei of each component (corresponds to the {Set} of _components)
* @param _naturalUnit uint The minimum multiple of Sets that can be issued or redeeemed
* @param _name string The Set's name
* @param _symbol string the Set's symbol
* @param _factory A list of component address which you want to include
* @param _components A list of component address which you want to include
* @param _units A list of quantities in gWei of each component (corresponds to the {Set} of _components)
* @param _naturalUnit The minimum multiple of Sets that can be issued or redeeemed
* @param _name The Set's name
* @param _symbol The Set's symbol
*/
constructor(
address _factory,
Expand Down Expand Up @@ -172,6 +176,7 @@ contract SetToken is
// add component to isComponent mapping
isComponent[keccak256(abi.encodePacked(currentComponent))] = true;

// Add component data to components struct array
components.push(Component({
address_: currentComponent,
unit_: currentUnits
Expand Down Expand Up @@ -226,34 +231,51 @@ contract SetToken is
isCore
isPositive(_quantity)
{
// Require user has tokens to burn
require(balances[_from] >= _quantity);

// Update token balance of user
balances[_from] = balances[_from].sub(_quantity);

// Update total supply of Set Token
totalSupply_ = totalSupply_.sub(_quantity);

// Emit a transfer log with to address being 0 indicating burn
emit Transfer(_from, address(0), _quantity);
}

/* ============ Getters ============ */

/*
* Get addresses of all components in the Set
*
* @return componentAddresses Array of component tokens
*/
function getComponents()
public
view
returns(address[])
{
address[] memory componentAddresses = new address[](components.length);

// Iterate through components and get address of each component
for (uint16 i = 0; i < components.length; i++) {
componentAddresses[i] = components[i].address_;
}
return componentAddresses;
}

/*
* Get units of all tokens in Set
*
* @return units Array of component units
*/
function getUnits()
public
view
returns(uint[])
{
uint[] memory units = new uint[](components.length);

// Iterate through components and get units of each component
for (uint16 i = 0; i < components.length; i++) {
units[i] = components[i].unit_;
}
Expand All @@ -262,6 +284,13 @@ contract SetToken is

/* ============ Transfer Overrides ============ */

/*
* ERC20 like transfer function but checks destination is valid
*
* @param _to The address to send Set to
* @param _value The number of Sets to send
* @return bool True on successful transfer
*/
function transfer(
address _to,
uint256 _value
Expand All @@ -270,9 +299,18 @@ contract SetToken is
isValidDestination(_to)
returns (bool)
{
// Use inherited transfer function
return super.transfer(_to, _value);
}

/*
* ERC20 like transferFrom function but checks destination is valid
*
* @param _from The address to send Set from
* @param _to The address to send Set to
* @param _value The number of Sets to send
* @return bool True on successful transfer
*/
function transferFrom(
address _from,
address _to,
Expand All @@ -282,11 +320,18 @@ contract SetToken is
isValidDestination(_to)
returns (bool)
{
// Use inherited transferFrom function
return super.transferFrom(_from, _to, _value);
}

/* ============ Private Helpers ============ */
/* ============ Internal Functions ============ */

/*
* Checks to make sure token is component of Set
*
* @param _tokenAddress Address of token being checked
* @return bool True if token is component of Set
*/
function tokenIsComponent(
address _tokenAddress
)
Expand Down
35 changes: 20 additions & 15 deletions contracts/core/SetTokenFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

pragma solidity 0.4.24;

import { SetToken } from "./SetToken.sol";
import { Authorizable } from "../lib/Authorizable.sol";
import { SetToken } from "./SetToken.sol";


/**
Expand All @@ -36,23 +36,21 @@ contract SetTokenFactory
// Address of the Core contract
address public core;

/* ============ No Constructor ============ */

/* ============ Setter Functions ============ */

/**
* Set core. Can only be set by owner of SetTokenFactory's owner.
*
* @param _coreAddress The address of deployed core contract
* @param _core The address of deployed core contract
*/
function setCoreAddress(
address _coreAddress
address _core
)
external
onlyOwner
{
// Commit passed address to vaultAddress state variable
core = _coreAddress;
core = _core;
}

/* ============ Public Functions ============ */
Expand All @@ -61,12 +59,12 @@ contract SetTokenFactory
* Deploys a new SetToken contract.
* Can only be called by authorized core contracts.
*
* @param _components address[] The address of component tokens
* @param _units uint[] The units of each component token
* @param _naturalUnit uint The minimum unit to be issued or redeemed
* @param _name string The name of the new Set
* @param _symbol string The symbol of the new Set
* @return setToken address The address of the newly created SetToken
* @param _components The address of component tokens
* @param _units The units of each component token
* @param _naturalUnit The minimum unit to be issued or redeemed
* @param _name The name of the new Set
* @param _symbol The symbol of the new Set
* @return setToken The address of the newly created SetToken
*/
function create(
address[] _components,
Expand All @@ -77,9 +75,16 @@ contract SetTokenFactory
)
external
onlyAuthorized
returns
(address)
returns (address)
{
return new SetToken(this, _components, _units, _naturalUnit, _name, _symbol);
// Create a new SetToken contract
return new SetToken(
this,
_components,
_units,
_naturalUnit,
_name,
_symbol
);
}
}
19 changes: 8 additions & 11 deletions contracts/core/TransferProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,37 @@

pragma solidity 0.4.24;


import { Authorizable } from "../lib/Authorizable.sol";
import { SafeMath } from "zeppelin-solidity/contracts/math/SafeMath.sol";
import { Authorizable } from "../lib/Authorizable.sol";
import { ERC20Wrapper } from "../lib/ERC20Wrapper.sol";


/**
* @title TransferProxy
* @author Set Protocol
*
* The proxy contract is responsible for updating token balances to assist with issuance
* and filling issuance orders.
* The transferProxy contract is responsible for moving tokens through the system to
* assist with issuance and filling issuance orders.
*/

contract TransferProxy is
Authorizable
{
using SafeMath for uint256;

/* ============ No Constructor ============ */

/* ============ External Functions ============ */

/**
* Transfers tokens from an address (that has set allowance on the proxy).
* Can only be called by authorized core contracts.
*
* @param _tokenAddress The address of the ERC20 token
* @param _token The address of the ERC20 token
* @param _quantity The number of tokens to transfer
* @param _from The address to transfer from
* @param _to The address to transfer to
*/
function transfer(
address _tokenAddress,
address _token,
uint _quantity,
address _from,
address _to
Expand All @@ -59,21 +56,21 @@ contract TransferProxy is
{
// Retrieve current balance of token for the receiver
uint existingBalance = ERC20Wrapper.balanceOf(
_tokenAddress,
_token,
_to
);

// Call specified ERC20 contract to transfer tokens (via proxy).
ERC20Wrapper.transferFrom(
_tokenAddress,
_token,
_from,
_to,
_quantity
);

// Get new balance of transferred token for receiver
uint newBalance = ERC20Wrapper.balanceOf(
_tokenAddress,
_token,
_to
);

Expand Down
Loading