Skip to content

change the type of proxy deployment for USDTieredSTO #459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 10, 2018
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ All notable changes to this project will be documented in this file.
## CappedSTO 2.0.1
* `rate` is now accepted as multiplied by 10^18 to allow settting higher price than 1ETH/POLY per token.

## USDTieredSTO 2.0.1
## USDTieredSTO 2.1.0
* Added `buyTokensView` and `getTokensMintedByTier` to USDTSTO.
* Added `getSTODetails` to USDTSTO.
* Added an Array of Tiers that will hold data about every tier in USDTSTO.
* Added `buyWithETHRateLimited`, `buyWithPOLYRateLimited` and `buyWithUSDRateLimited` to USDTSTO.
* Added `getTokensSoldByTier` to return sold (not minted during finalisation) tokens in each tier to USDTSTO.
* Removed individual mappings for tier data removed in UDSTSTO.
* Removed the old Proxy deployment method of USDTieredSTO and adopt the new inherited proxy deployment approach.
* Bump the version to `2.1.0`

## GeneralTransferManager
* `getInvestors`, `getAllInvestorsData`, `getInvestorsData` added to GTM to allow easy data queries.
Expand Down
10 changes: 10 additions & 0 deletions contracts/interfaces/IBoot.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pragma solidity ^0.4.24;

interface IBoot {

/**
* @notice This function returns the signature of configure function
* @return bytes4 Configure function signature
*/
function getInitFunction() external pure returns(bytes4);
}
18 changes: 2 additions & 16 deletions contracts/modules/STO/ISTO.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,16 @@ pragma solidity ^0.4.24;
import "../../Pausable.sol";
import "../Module.sol";
import "../../interfaces/IERC20.sol";
import "./ISTOStorage.sol";
import "openzeppelin-solidity/contracts/math/SafeMath.sol";

/**
* @title Interface to be implemented by all STO modules
*/
contract ISTO is Module, Pausable {
contract ISTO is ISTOStorage, Module, Pausable {
using SafeMath for uint256;

enum FundRaiseType { ETH, POLY, DAI }
mapping (uint8 => bool) public fundRaiseTypes;
mapping (uint8 => uint256) public fundsRaised;

// Start time of the STO
uint256 public startTime;
// End time of the STO
uint256 public endTime;
// Time STO was paused
uint256 public pausedTime;
// Number of individual investors
uint256 public investorCount;
// Address where ETH & POLY funds are delivered
address public wallet;
// Final amount of tokens sold
uint256 public totalTokensSold;

// Event
event SetFundRaiseTypes(FundRaiseType[] _fundRaiseTypes);
Expand Down
24 changes: 24 additions & 0 deletions contracts/modules/STO/ISTOStorage.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
pragma solidity ^0.4.24;

/**
* @title Storage layout for the ISTO contract
*/
contract ISTOStorage {

mapping (uint8 => bool) public fundRaiseTypes;
mapping (uint8 => uint256) public fundsRaised;

// Start time of the STO
uint256 public startTime;
// End time of the STO
uint256 public endTime;
// Time STO was paused
uint256 public pausedTime;
// Number of individual investors
uint256 public investorCount;
// Address where ETH & POLY funds are delivered
address public wallet;
// Final amount of tokens sold
uint256 public totalTokensSold;

}
33 changes: 0 additions & 33 deletions contracts/modules/STO/ProxyFactory/USDTieredSTOProxyFactory.sol

This file was deleted.

89 changes: 10 additions & 79 deletions contracts/modules/STO/USDTieredSTO.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,86 +7,16 @@ import "../../RegistryUpdater.sol";
import "../../libraries/DecimalMath.sol";
import "openzeppelin-solidity/contracts/math/SafeMath.sol";
import "openzeppelin-solidity/contracts/ReentrancyGuard.sol";
import "./USDTieredSTOStorage.sol";

/**
* @title STO module for standard capped crowdsale
*/
contract USDTieredSTO is ISTO, ReentrancyGuard {
contract USDTieredSTO is USDTieredSTOStorage, ISTO, ReentrancyGuard {
using SafeMath for uint256;

/////////////
// Storage //
/////////////
struct Tier {
// How many token units a buyer gets per USD in this tier (multiplied by 10**18)
uint256 rate;

// How many token units a buyer gets per USD in this tier (multiplied by 10**18) when investing in POLY up to tokensDiscountPoly
uint256 rateDiscountPoly;

// How many tokens are available in this tier (relative to totalSupply)
uint256 tokenTotal;

// How many token units are available in this tier (relative to totalSupply) at the ratePerTierDiscountPoly rate
uint256 tokensDiscountPoly;

// How many tokens have been minted in this tier (relative to totalSupply)
uint256 mintedTotal;

// How many tokens have been minted in this tier (relative to totalSupply) for each fund raise type
mapping (uint8 => uint256) minted;

// How many tokens have been minted in this tier (relative to totalSupply) at discounted POLY rate
uint256 mintedDiscountPoly;
}

string public POLY_ORACLE = "PolyUsdOracle";
string public ETH_ORACLE = "EthUsdOracle";
mapping (bytes32 => mapping (bytes32 => string)) oracleKeys;

IERC20 public usdToken;

// Determine whether users can invest on behalf of a beneficiary
bool public allowBeneficialInvestments = false;

// Whether or not the STO has been finalized
bool public isFinalized;

// Address where ETH, POLY & DAI funds are delivered
address public wallet;

// Address of issuer reserve wallet for unsold tokens
address public reserveWallet;

// Current tier
uint256 public currentTier;

// Amount of USD funds raised
uint256 public fundsRaisedUSD;

// Amount in USD invested by each address
mapping (address => uint256) public investorInvestedUSD;

// Amount in fund raise type invested by each investor
mapping (address => mapping (uint8 => uint256)) public investorInvested;

// List of accredited investors
mapping (address => bool) public accredited;

// Default limit in USD for non-accredited investors multiplied by 10**18
uint256 public nonAccreditedLimitUSD;

// Overrides for default limit in USD for non-accredited investors multiplied by 10**18
mapping (address => uint256) public nonAccreditedLimitUSDOverride;

// Minimum investable amount in USD
uint256 public minimumInvestmentUSD;

// Final amount of tokens returned to issuer
uint256 public finalAmountReturned;

// Array of Tiers
Tier[] public tiers;
string public constant POLY_ORACLE = "PolyUsdOracle";
string public constant ETH_ORACLE = "EthUsdOracle";

////////////
// Events //
Expand Down Expand Up @@ -158,11 +88,10 @@ contract USDTieredSTO is ISTO, ReentrancyGuard {
// STO Configuration //
///////////////////////

constructor (address _securityToken, address _polyAddress, address _factory) public Module(_securityToken, _polyAddress) {
require(_factory != address(0), "Invalid factory");
oracleKeys[bytes32("ETH")][bytes32("USD")] = ETH_ORACLE;
oracleKeys[bytes32("POLY")][bytes32("USD")] = POLY_ORACLE;
factory = _factory; //Explicitly setting factory as we are using proxy deployment for this module
constructor (address _securityToken, address _polyAddress)
public
Module(_securityToken, _polyAddress)
{
}

/**
Expand Down Expand Up @@ -192,6 +121,8 @@ contract USDTieredSTO is ISTO, ReentrancyGuard {
address _reserveWallet,
address _usdToken
) public onlyFactory {
oracleKeys[bytes32("ETH")][bytes32("USD")] = ETH_ORACLE;
oracleKeys[bytes32("POLY")][bytes32("USD")] = POLY_ORACLE;
require(endTime == 0, "Already configured");
_modifyTimes(_startTime, _endTime);
_modifyTiers(_ratePerTier, _ratePerTierDiscountPoly, _tokensPerTierTotal, _tokensPerTierDiscountPoly);
Expand Down
18 changes: 9 additions & 9 deletions contracts/modules/STO/USDTieredSTOFactory.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pragma solidity ^0.4.24;

import "../../interfaces/IUSDTieredSTOProxy.sol";
import "../../interfaces/IBoot.sol";
import "../../proxy/USDTieredSTOProxy.sol";
import "../ModuleFactory.sol";
import "../../libraries/Util.sol";

Expand All @@ -9,18 +10,18 @@ import "../../libraries/Util.sol";
*/
contract USDTieredSTOFactory is ModuleFactory {

address public USDTieredSTOProxyAddress;
address public logicContract;

/**
* @notice Constructor
* @param _polyAddress Address of the polytoken
*/
constructor (address _polyAddress, uint256 _setupCost, uint256 _usageCost, uint256 _subscriptionCost, address _proxyFactoryAddress) public
constructor (address _polyAddress, uint256 _setupCost, uint256 _usageCost, uint256 _subscriptionCost, address _logicContract) public
ModuleFactory(_polyAddress, _setupCost, _usageCost, _subscriptionCost)
{
require(_proxyFactoryAddress != address(0), "0x address is not allowed");
USDTieredSTOProxyAddress = _proxyFactoryAddress;
version = "1.0.0";
require(_logicContract != address(0), "0x address is not allowed");
logicContract = _logicContract;
version = "2.1.0";
name = "USDTieredSTO";
title = "USD Tiered STO";
/*solium-disable-next-line max-len*/
Expand All @@ -36,11 +37,10 @@ contract USDTieredSTOFactory is ModuleFactory {
function deploy(bytes _data) external returns(address) {
if(setupCost > 0)
require(polyToken.transferFrom(msg.sender, owner, setupCost), "Sufficent Allowance is not provided");
require(USDTieredSTOProxyAddress != address(0), "Proxy contract should be pre-set");
//Check valid bytes - can only call module init function
address usdTieredSTO = IUSDTieredSTOProxy(USDTieredSTOProxyAddress).deploySTO(msg.sender, address(polyToken), address(this));
address usdTieredSTO = new USDTieredSTOProxy(msg.sender, address(polyToken), logicContract);
//Checks that _data is valid (not calling anything it shouldn't)
require(Util.getSig(_data) == IUSDTieredSTOProxy(USDTieredSTOProxyAddress).getInitFunction(usdTieredSTO), "Invalid data");
require(Util.getSig(_data) == IBoot(usdTieredSTO).getInitFunction(), "Invalid data");
/*solium-disable-next-line security/no-low-level-calls*/
require(address(usdTieredSTO).call(_data), "Unsuccessfull call");
/*solium-disable-next-line security/no-block-members*/
Expand Down
82 changes: 82 additions & 0 deletions contracts/modules/STO/USDTieredSTOStorage.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
pragma solidity ^0.4.24;

import "../../interfaces/IERC20.sol";

/**
* @title Contract used to store layout for the USDTieredSTO storage
*/
contract USDTieredSTOStorage {

/////////////
// Storage //
/////////////
struct Tier {
// How many token units a buyer gets per USD in this tier (multiplied by 10**18)
uint256 rate;

// How many token units a buyer gets per USD in this tier (multiplied by 10**18) when investing in POLY up to tokensDiscountPoly
uint256 rateDiscountPoly;

// How many tokens are available in this tier (relative to totalSupply)
uint256 tokenTotal;

// How many token units are available in this tier (relative to totalSupply) at the ratePerTierDiscountPoly rate
uint256 tokensDiscountPoly;

// How many tokens have been minted in this tier (relative to totalSupply)
uint256 mintedTotal;

// How many tokens have been minted in this tier (relative to totalSupply) for each fund raise type
mapping (uint8 => uint256) minted;

// How many tokens have been minted in this tier (relative to totalSupply) at discounted POLY rate
uint256 mintedDiscountPoly;
}

mapping (bytes32 => mapping (bytes32 => string)) oracleKeys;

IERC20 public usdToken;

// Determine whether users can invest on behalf of a beneficiary
bool public allowBeneficialInvestments = false;

// Whether or not the STO has been finalized
bool public isFinalized;

// Address where ETH, POLY & DAI funds are delivered
address public wallet;

// Address of issuer reserve wallet for unsold tokens
address public reserveWallet;

// Current tier
uint256 public currentTier;

// Amount of USD funds raised
uint256 public fundsRaisedUSD;

// Amount in USD invested by each address
mapping (address => uint256) public investorInvestedUSD;

// Amount in fund raise type invested by each investor
mapping (address => mapping (uint8 => uint256)) public investorInvested;

// List of accredited investors
mapping (address => bool) public accredited;

// Default limit in USD for non-accredited investors multiplied by 10**18
uint256 public nonAccreditedLimitUSD;

// Overrides for default limit in USD for non-accredited investors multiplied by 10**18
mapping (address => uint256) public nonAccreditedLimitUSDOverride;

// Minimum investable amount in USD
uint256 public minimumInvestmentUSD;

// Final amount of tokens returned to issuer
uint256 public finalAmountReturned;

// Array of Tiers
Tier[] public tiers;

}
Loading