From d8fd3f0b392f2a4b2010007bbf13d079b518e862 Mon Sep 17 00:00:00 2001 From: Adam Dossa Date: Wed, 19 Sep 2018 20:44:09 +0100 Subject: [PATCH 01/12] Compiles... --- contracts/modules/STO/CappedSTO.sol | 33 ++---- contracts/modules/STO/DummySTO.sol | 14 --- contracts/modules/STO/ISTO.sol | 45 +++----- contracts/modules/STO/PreSaleSTO.sol | 18 +-- contracts/modules/STO/USDTieredSTO.sol | 153 ++++++++++--------------- 5 files changed, 84 insertions(+), 179 deletions(-) diff --git a/contracts/modules/STO/CappedSTO.sol b/contracts/modules/STO/CappedSTO.sol index cf1614c8e..ac27bc120 100644 --- a/contracts/modules/STO/CappedSTO.sol +++ b/contracts/modules/STO/CappedSTO.sol @@ -58,7 +58,7 @@ contract CappedSTO is ISTO, ReentrancyGuard { uint256 _endTime, uint256 _cap, uint256 _rate, - uint8[] _fundRaiseTypes, + FundRaiseType[] _fundRaiseTypes, address _fundsReceiver ) public @@ -74,7 +74,7 @@ contract CappedSTO is ISTO, ReentrancyGuard { cap = _cap; rate = _rate; wallet = _fundsReceiver; - _configureFunding(_fundRaiseTypes); + _setFundRaiseType(_fundRaiseTypes); } /** @@ -104,7 +104,7 @@ contract CappedSTO is ISTO, ReentrancyGuard { } require(!paused); - require(fundRaiseType[uint8(FundRaiseType.ETH)], "ETH should be the mode of investment"); + require(fundRaiseTypes[uint8(FundRaiseType.ETH)], "ETH should be the mode of investment"); uint256 weiAmount = msg.value; _processTx(_beneficiary, weiAmount); @@ -119,8 +119,7 @@ contract CappedSTO is ISTO, ReentrancyGuard { */ function buyTokensWithPoly(uint256 _investedPOLY) public nonReentrant{ require(!paused); - require(fundRaiseType[uint8(FundRaiseType.POLY)], "POLY should be the mode of investment"); - require(verifyInvestment(msg.sender, _investedPOLY), "Not valid Investment"); + require(fundRaiseTypes[uint8(FundRaiseType.POLY)], "POLY should be the mode of investment"); _processTx(msg.sender, _investedPOLY); _forwardPoly(msg.sender, wallet, _investedPOLY); _postValidatePurchase(msg.sender, _investedPOLY); @@ -134,20 +133,6 @@ contract CappedSTO is ISTO, ReentrancyGuard { return totalTokensSold >= cap; } - /** - * @notice Return ETH raised by the STO - */ - function getRaisedEther() public view returns (uint256) { - return fundsRaisedETH; - } - - /** - * @notice Return POLY raised by the STO - */ - function getRaisedPOLY() public view returns (uint256) { - return fundsRaisedPOLY; - } - /** * @notice Return the total no. of investors */ @@ -179,10 +164,10 @@ contract CappedSTO is ISTO, ReentrancyGuard { endTime, cap, rate, - (fundRaiseType[uint8(FundRaiseType.POLY)]) ? fundsRaisedPOLY: fundsRaisedETH, + (fundRaiseTypes[uint8(FundRaiseType.POLY)]) ? fundsRaised[uint8(FundRaiseType.POLY)]: fundsRaised[uint8(FundRaiseType.ETH)], investorCount, totalTokensSold, - (fundRaiseType[uint8(FundRaiseType.POLY)]) + (fundRaiseTypes[uint8(FundRaiseType.POLY)]) ); } @@ -201,10 +186,10 @@ contract CappedSTO is ISTO, ReentrancyGuard { uint256 tokens = _getTokenAmount(_investedAmount); // update state - if (fundRaiseType[uint8(FundRaiseType.POLY)]) { - fundsRaisedPOLY = fundsRaisedPOLY.add(_investedAmount); + if (fundRaiseTypes[uint8(FundRaiseType.POLY)]) { + fundsRaised[uint8(FundRaiseType.POLY)] = fundsRaised[uint8(FundRaiseType.POLY)].add(_investedAmount); } else { - fundsRaisedETH = fundsRaisedETH.add(_investedAmount); + fundsRaised[uint8(FundRaiseType.ETH)] = fundsRaised[uint8(FundRaiseType.ETH)].add(_investedAmount); } totalTokensSold = totalTokensSold.add(tokens); diff --git a/contracts/modules/STO/DummySTO.sol b/contracts/modules/STO/DummySTO.sol index 73d4df22c..d030b7611 100644 --- a/contracts/modules/STO/DummySTO.sol +++ b/contracts/modules/STO/DummySTO.sol @@ -67,20 +67,6 @@ contract DummySTO is ISTO { emit LogGenerateTokens (_investor, _amount); } - /** - * @notice Return ETH raised by the STO - */ - function getRaisedEther() public view returns (uint256) { - return 0; - } - - /** - * @notice Return POLY raised by the STO - */ - function getRaisedPOLY() public view returns (uint256) { - return 0; - } - /** * @notice Return the total no. of investors */ diff --git a/contracts/modules/STO/ISTO.sol b/contracts/modules/STO/ISTO.sol index 21c08d926..b2660e8ec 100644 --- a/contracts/modules/STO/ISTO.sol +++ b/contracts/modules/STO/ISTO.sol @@ -11,8 +11,9 @@ import "openzeppelin-solidity/contracts/math/SafeMath.sol"; contract ISTO is Module, Pausable { using SafeMath for uint256; - enum FundRaiseType { ETH, POLY } - mapping (uint8 => bool) public fundRaiseType; + enum FundRaiseType { ETH, POLY, DAI } + mapping (uint8 => bool) public fundRaiseTypes; + mapping (uint8 => uint256) public fundsRaised; // Start time of the STO uint256 public startTime; @@ -20,10 +21,6 @@ contract ISTO is Module, Pausable { uint256 public endTime; // Time STO was paused uint256 public pausedTime; - // Amount of ETH funds raised - uint256 public fundsRaisedETH; - // Amount of POLY funds raised - uint256 public fundsRaisedPOLY; // Number of individual investors uint256 public investorCount; // Address where ETH & POLY funds are delivered @@ -32,7 +29,7 @@ contract ISTO is Module, Pausable { uint256 public totalTokensSold; // Event - event SetFunding(uint8[] _fundRaiseTypes); + event SetFundRaiseTypes(FundRaiseType[] _fundRaiseTypes); /** * @notice Reclaim ERC20Basic compatible tokens @@ -46,24 +43,12 @@ contract ISTO is Module, Pausable { require(token.transfer(msg.sender, balance)); } - /** - * @notice used to verify the investment, whether the investor provided an allowance to the STO or not. - * @param _beneficiary Ethereum address of the beneficiary, who intends to buy the st-20 tokens - * @param _fundsAmount Amount invested by the beneficiary - */ - function verifyInvestment(address _beneficiary, uint256 _fundsAmount) public view returns(bool) { - return polyToken.allowance(_beneficiary, address(this)) >= _fundsAmount; - } - /** * @notice Return ETH raised by the STO */ - function getRaisedEther() public view returns (uint256); - - /** - * @notice Return POLY raised by the STO - */ - function getRaisedPOLY() public view returns (uint256); + function getRaised(FundRaiseType _fundRaiseType) public view returns (uint256) { + return fundsRaised[uint8(_fundRaiseType)]; + } /** * @notice Return the total no. of investors @@ -90,18 +75,14 @@ contract ISTO is Module, Pausable { super._unpause(); } - function _configureFunding(uint8[] _fundRaiseTypes) internal { - require(_fundRaiseTypes.length > 0 && _fundRaiseTypes.length < 3, "No fund raising currencies specified"); - fundRaiseType[uint8(FundRaiseType.POLY)] = false; - fundRaiseType[uint8(FundRaiseType.ETH)] = false; + function _setFundRaiseType(FundRaiseType[] _fundRaiseTypes) internal { + // FundRaiseType[] parameter type ensures only valid values for _fundRaiseTypes + require(_fundRaiseTypes.length > 0, "Raise type not specified"); for (uint8 j = 0; j < _fundRaiseTypes.length; j++) { - require(_fundRaiseTypes[j] < 2); - fundRaiseType[_fundRaiseTypes[j]] = true; - } - if (fundRaiseType[uint8(FundRaiseType.POLY)]) { - require(address(polyToken) != address(0), "Address of the polyToken should not be 0x"); + require(!fundRaiseTypes[uint8(_fundRaiseTypes[j])], "Duplicated raise types"); + fundRaiseTypes[uint8(_fundRaiseTypes[j])] = true; } - emit SetFunding(_fundRaiseTypes); + emit SetFundRaiseTypes(_fundRaiseTypes); } } diff --git a/contracts/modules/STO/PreSaleSTO.sol b/contracts/modules/STO/PreSaleSTO.sol index f04b02570..65f1b00ad 100644 --- a/contracts/modules/STO/PreSaleSTO.sol +++ b/contracts/modules/STO/PreSaleSTO.sol @@ -42,20 +42,6 @@ contract PreSaleSTO is ISTO { return bytes4(keccak256("configure(uint256)")); } - /** - * @notice Return ETH raised by the STO - */ - function getRaisedEther() public view returns (uint256) { - return fundsRaisedETH; - } - - /** - * @notice Return POLY raised by the STO - */ - function getRaisedPOLY() public view returns (uint256) { - return fundsRaisedPOLY; - } - /** * @notice Return the total no. of investors */ @@ -93,8 +79,8 @@ contract PreSaleSTO is ISTO { ISecurityToken(securityToken).mint(_investor, _amount); investors[_investor] = investors[_investor].add(_amount); investorCount = investorCount.add(1); - fundsRaisedETH = fundsRaisedETH.add(_etherContributed); - fundsRaisedPOLY = fundsRaisedPOLY.add(_polyContributed); + fundsRaised[uint8(FundRaiseType.ETH)] = fundsRaised[uint8(FundRaiseType.ETH)].add(_etherContributed); + fundsRaised[uint8(FundRaiseType.POLY)] = fundsRaised[uint8(FundRaiseType.POLY)].add(_polyContributed); totalTokensSold = totalTokensSold.add(_amount); emit TokensAllocated(_investor, _amount); } diff --git a/contracts/modules/STO/USDTieredSTO.sol b/contracts/modules/STO/USDTieredSTO.sol index 1de215388..e6b75b973 100644 --- a/contracts/modules/STO/USDTieredSTO.sol +++ b/contracts/modules/STO/USDTieredSTO.sol @@ -22,10 +22,12 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { string public ETH_ORACLE = "EthUsdOracle"; mapping (bytes32 => mapping (bytes32 => string)) oracleKeys; + IERC20 public constant daiToken = IERC20(0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359); + // Determine whether users can invest on behalf of a beneficiary bool public allowBeneficialInvestments = false; - // Address where ETH & POLY funds are delivered + // Address where ETH, POLY & DAI funds are delivered address public wallet; // Address of issuer reserve wallet for unsold tokens @@ -46,11 +48,8 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { // How many tokens have been minted in each tier (relative to totalSupply) uint256[] public mintedPerTierTotal; - // How many tokens have been minted in each tier (relative to totalSupply) at ETH rate - uint256[] public mintedPerTierETH; - - // How many tokens have been minted in each tier (relative to totalSupply) at regular POLY rate - uint256[] public mintedPerTierRegularPoly; + // How many tokens have been minted in each tier (relative to totalSupply) for each fund raise type + mapping (uint8 => uint256[]) mintedPerTier; // How many tokens have been minted in each tier (relative to totalSupply) at discounted POLY rate uint256[] public mintedPerTierDiscountPoly; @@ -64,11 +63,8 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { // Amount in USD invested by each address mapping (address => uint256) public investorInvestedUSD; - // Amount in ETH invested by each address - mapping (address => uint256) public investorInvestedETH; - - // Amount in POLY invested by each address - mapping (address => uint256) public investorInvestedPOLY; + // 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; @@ -96,7 +92,7 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { event SetNonAccreditedLimit(address _investor, uint256 _limit); event SetAccredited(address _investor, bool _accredited); event TokenPurchase(address indexed _purchaser, address indexed _beneficiary, uint256 _tokens, uint256 _usdAmount, uint256 _tierPrice, uint8 _tier); - event FundsReceivedETH(address indexed _purchaser, address indexed _beneficiary, uint256 _usdAmount, uint256 _receivedValue, uint256 _spentValue, uint256 _rate); + event FundsReceived(address indexed _purchaser, address indexed _beneficiary, uint256 _usdAmount, FundRaiseType _fundRaiseType, uint256 _receivedValue, uint256 _spentValue, uint256 _rate); event FundsReceivedPOLY(address indexed _purchaser, address indexed _beneficiary, uint256 _usdAmount, uint256 _receivedValue, uint256 _spentValue, uint256 _rate); event ReserveTokenMint(address indexed _owner, address indexed _wallet, uint256 _tokens, uint8 _tier); @@ -125,13 +121,18 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { modifier validETH { require(_getOracle(bytes32("ETH"), bytes32("USD")) != address(0), "Invalid ETHUSD Oracle"); - require(fundRaiseType[uint8(FundRaiseType.ETH)]); + require(fundRaiseTypes[uint8(FundRaiseType.ETH)]); _; } modifier validPOLY { require(_getOracle(bytes32("POLY"), bytes32("USD")) != address(0), "Invalid ETHUSD Oracle"); - require(fundRaiseType[uint8(FundRaiseType.POLY)]); + require(fundRaiseTypes[uint8(FundRaiseType.POLY)]); + _; + } + + modifier validDAI { + require(fundRaiseTypes[uint8(FundRaiseType.DAI)]); _; } @@ -165,20 +166,26 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { uint256[] _tokensPerTierDiscountPoly, uint256 _nonAccreditedLimitUSD, uint256 _minimumInvestmentUSD, - uint8[] _fundRaiseTypes, + FundRaiseType[] _fundRaiseTypes, address _wallet, address _reserveWallet ) public onlyFactory { modifyTimes(_startTime, _endTime); + // NB - modifyFunding must come before modifyTiers + modifyFunding(_fundRaiseTypes, _ratePerTier.length); modifyTiers(_ratePerTier, _ratePerTierDiscountPoly, _tokensPerTierTotal, _tokensPerTierDiscountPoly); - modifyFunding(_fundRaiseTypes); modifyAddresses(_wallet, _reserveWallet); modifyLimits(_nonAccreditedLimitUSD, _minimumInvestmentUSD); } - function modifyFunding(uint8[] _fundRaiseTypes) public onlyFactoryOrOwner { + function modifyFunding(FundRaiseType[] _fundRaiseTypes, uint256 _numberOfTiers) public onlyFactoryOrOwner { require(now < startTime); - _configureFunding(_fundRaiseTypes); + _setFundRaiseType(_fundRaiseTypes); + mintedPerTierTotal = new uint256[](_numberOfTiers); + mintedPerTierDiscountPoly = new uint256[](_numberOfTiers); + for (uint8 i = 0; i < _fundRaiseTypes.length; i++) { + mintedPerTier[uint8(_fundRaiseTypes[i])] = new uint256[](_numberOfTiers); + } } function modifyLimits( @@ -208,10 +215,6 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { require(_tokensPerTierDiscountPoly[i] <= _tokensPerTierTotal[i], "Discounted tokens / tier <= to tokens / tier"); require(_ratePerTierDiscountPoly[i] <= _ratePerTier[i], "Discounted rate / tier <= rate / tier"); } - mintedPerTierTotal = new uint256[](_ratePerTier.length); - mintedPerTierETH = new uint256[](_ratePerTier.length); - mintedPerTierRegularPoly = new uint256[](_ratePerTier.length); - mintedPerTierDiscountPoly = new uint256[](_ratePerTier.length); ratePerTier = _ratePerTier; ratePerTierDiscountPoly = _ratePerTierDiscountPoly; tokensPerTierTotal = _tokensPerTierTotal; @@ -324,15 +327,15 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { */ function buyWithETH(address _beneficiary) public payable validETH { uint256 rate = IOracle(_getOracle(bytes32("ETH"), bytes32("USD"))).getPrice(); - (uint256 spentUSD, uint256 spentValue) = _buyTokens(_beneficiary, msg.value, rate, false); + (uint256 spentUSD, uint256 spentValue) = _buyTokens(_beneficiary, msg.value, rate, FundRaiseType.ETH); // Modify storage - investorInvestedETH[_beneficiary] = investorInvestedETH[_beneficiary].add(spentValue); - fundsRaisedETH = fundsRaisedETH.add(spentValue); + investorInvested[_beneficiary][uint8(FundRaiseType.ETH)] = investorInvested[_beneficiary][uint8(FundRaiseType.ETH)].add(spentValue); + fundsRaised[uint8(FundRaiseType.ETH)] = fundsRaised[uint8(FundRaiseType.ETH)].add(spentValue); // Forward ETH to issuer wallet wallet.transfer(spentValue); // Refund excess ETH to investor wallet msg.sender.transfer(msg.value.sub(spentValue)); - emit FundsReceivedETH(msg.sender, _beneficiary, spentUSD, msg.value, spentValue, rate); + emit FundsReceived(msg.sender, _beneficiary, spentUSD, FundRaiseType.ETH, msg.value, spentValue, rate); } /** @@ -342,22 +345,39 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { */ function buyWithPOLY(address _beneficiary, uint256 _investedPOLY) public validPOLY { uint256 rate = IOracle(_getOracle(bytes32("POLY"), bytes32("USD"))).getPrice(); - (uint256 spentUSD, uint256 spentValue) = _buyTokens(_beneficiary, _investedPOLY, rate, true); + (uint256 spentUSD, uint256 spentValue) = _buyTokens(_beneficiary, _investedPOLY, rate, FundRaiseType.POLY); // Modify storage - investorInvestedPOLY[_beneficiary] = investorInvestedPOLY[_beneficiary].add(spentValue); - fundsRaisedPOLY = fundsRaisedPOLY.add(spentValue); + investorInvested[_beneficiary][uint8(FundRaiseType.POLY)] = investorInvested[_beneficiary][uint8(FundRaiseType.POLY)].add(spentValue); + fundsRaised[uint8(FundRaiseType.POLY)] = fundsRaised[uint8(FundRaiseType.POLY)].add(spentValue); // Forward POLY to issuer wallet require(polyToken.transferFrom(msg.sender, wallet, spentValue)); - emit FundsReceivedPOLY(msg.sender, _beneficiary, spentUSD, _investedPOLY, spentValue, rate); + emit FundsReceived(msg.sender, _beneficiary, spentUSD, FundRaiseType.POLY, _investedPOLY, spentValue, rate); + } + + /** + * @notice Purchase tokens using POLY + * @param _beneficiary Address where security tokens will be sent + * @param _investedDAI Amount of POLY invested + */ + function buyWithDAI(address _beneficiary, uint256 _investedDAI) public validPOLY { + // Assume a conversion rate of 1 - 1 with USD + uint256 rate = 1 * 10**18; + (uint256 spentUSD, uint256 spentValue) = _buyTokens(_beneficiary, _investedDAI, rate, FundRaiseType.DAI); + // Modify storage + investorInvested[_beneficiary][uint8(FundRaiseType.DAI)] = investorInvested[_beneficiary][uint8(FundRaiseType.DAI)].add(spentValue); + fundsRaised[uint8(FundRaiseType.POLY)] = fundsRaised[uint8(FundRaiseType.POLY)].add(spentValue); + // Forward DAI to issuer wallet + require(daiToken.transferFrom(msg.sender, wallet, spentValue)); + emit FundsReceived(msg.sender, _beneficiary, spentUSD, FundRaiseType.DAI, _investedDAI, spentValue, rate); } /** * @notice Low level token purchase * @param _beneficiary Address where security tokens will be sent - * @param _investmentValue Amount of POLY or ETH invested - * @param _isPOLY Investment method + * @param _investmentValue Amount of POLY, ETH or DAI invested + * @param _fundRaiseType Fund raise type (POLY, ETH, DAI) */ - function _buyTokens(address _beneficiary, uint256 _investmentValue, uint256 _rate, bool _isPOLY) internal nonReentrant whenNotPaused returns(uint256, uint256) { + function _buyTokens(address _beneficiary, uint256 _investmentValue, uint256 _rate, FundRaiseType _fundRaiseType) internal nonReentrant whenNotPaused returns(uint256, uint256) { if (!allowBeneficialInvestments) { require(_beneficiary == msg.sender, "Beneficiary must match funder"); } @@ -386,7 +406,7 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { currentTier = i; // If there are tokens remaining, process investment if (mintedPerTierTotal[i] < tokensPerTierTotal[i]) - spentUSD = spentUSD.add(_calculateTier(_beneficiary, i, investedUSD.sub(spentUSD), _isPOLY)); + spentUSD = spentUSD.add(_calculateTier(_beneficiary, i, investedUSD.sub(spentUSD), _fundRaiseType)); // If all funds have been spent, exit the loop if (investedUSD == spentUSD) break; @@ -412,13 +432,13 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { return (spentUSD, spentValue); } - function _calculateTier(address _beneficiary, uint8 _tier, uint256 _investedUSD, bool _isPOLY) internal returns(uint256) { + function _calculateTier(address _beneficiary, uint8 _tier, uint256 _investedUSD, FundRaiseType _fundRaiseType) internal returns(uint256) { // First purchase any discounted tokens if POLY investment uint256 spentUSD; uint256 tierSpentUSD; uint256 tierPurchasedTokens; // Check whether there are any remaining discounted tokens - if (_isPOLY && tokensPerTierDiscountPoly[_tier] > mintedPerTierDiscountPoly[_tier]) { + if ((_fundRaiseType == FundRaiseType.POLY) && tokensPerTierDiscountPoly[_tier] > mintedPerTierDiscountPoly[_tier]) { uint256 discountRemaining = tokensPerTierDiscountPoly[_tier].sub(mintedPerTierDiscountPoly[_tier]); uint256 totalRemaining = tokensPerTierTotal[_tier].sub(mintedPerTierTotal[_tier]); if (totalRemaining < discountRemaining) @@ -433,10 +453,7 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { if ((_investedUSD > 0) && (tokensPerTierTotal[_tier].sub(mintedPerTierTotal[_tier]) > 0)) { (tierSpentUSD, tierPurchasedTokens) = _purchaseTier(_beneficiary, ratePerTier[_tier], tokensPerTierTotal[_tier].sub(mintedPerTierTotal[_tier]), _investedUSD, _tier); spentUSD = spentUSD.add(tierSpentUSD); - if (_isPOLY) - mintedPerTierRegularPoly[_tier] = mintedPerTierRegularPoly[_tier].add(tierPurchasedTokens); - else - mintedPerTierETH[_tier] = mintedPerTierETH[_tier].add(tierPurchasedTokens); + mintedPerTier[uint8(_fundRaiseType)][_tier] = mintedPerTier[uint8(_fundRaiseType)][_tier].add(tierPurchasedTokens); mintedPerTierTotal[_tier] = mintedPerTierTotal[_tier].add(tierPurchasedTokens); } return spentUSD; @@ -482,28 +499,6 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { return true; } - /** - * @notice This function converts from ETH or POLY to USD - * @param _currency Currency key - * @param _amount Value to convert to USD - * @return uint256 Value in USD - */ - function convertToUSD(bytes32 _currency, uint256 _amount) public view returns(uint256) { - uint256 rate = IOracle(_getOracle(_currency, bytes32("USD"))).getPrice(); - return DecimalMath.mul(_amount, rate); - } - - /** - * @notice This function converts from USD to ETH or POLY - * @param _currency Currency key - * @param _amount Value to convert from USD - * @return uint256 Value in ETH or POLY - */ - function convertFromUSD(bytes32 _currency, uint256 _amount) public view returns(uint256) { - uint256 rate = IOracle(_getOracle(_currency, bytes32("USD"))).getPrice(); - return DecimalMath.div(_amount, rate); - } - /** * @notice Checks whether the cap has been reached. * @return bool Whether the cap was reached @@ -515,22 +510,6 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { return (mintedPerTierTotal[mintedPerTierTotal.length - 1] == tokensPerTierTotal[tokensPerTierTotal.length - 1]); } - /** - * @notice Return ETH raised by the STO - * @return uint256 Amount of ETH raised - */ - function getRaisedEther() public view returns (uint256) { - return fundsRaisedETH; - } - - /** - * @notice Return POLY raised by the STO - * @return uint256 Amount of POLY raised - */ - function getRaisedPOLY() public view returns (uint256) { - return fundsRaisedPOLY; - } - /** * @notice Return USD raised by the STO * @return uint256 Amount of USD raised @@ -574,22 +553,10 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { * @notice Return the total no. of tokens sold for ETH * @return uint256 Total number of tokens sold for ETH */ - function getTokensSoldForETH() public view returns (uint256) { - uint256 tokensSold; - for (uint8 i = 0; i < mintedPerTierETH.length; i++) { - tokensSold = tokensSold.add(mintedPerTierETH[i]); - } - return tokensSold; - } - - /** - * @notice Return the total no. of tokens sold for POLY - * @return uint256 Total number of tokens sold for POLY - */ - function getTokensSoldForPOLY() public view returns (uint256) { + function getTokensSold(FundRaiseType _fundRaiseType) public view returns (uint256) { uint256 tokensSold; - for (uint8 i = 0; i < mintedPerTierRegularPoly.length; i++) { - tokensSold = tokensSold.add(mintedPerTierRegularPoly[i]).add(mintedPerTierDiscountPoly[i]); + for (uint8 i = 0; i < mintedPerTier[uint8(_fundRaiseType)].length; i++) { + tokensSold = tokensSold.add(mintedPerTier[uint8(_fundRaiseType)][i]); } return tokensSold; } From 2110366a35fd7ca47caa9f0eb4819a77ca475bd8 Mon Sep 17 00:00:00 2001 From: Adam Dossa Date: Wed, 19 Sep 2018 22:36:12 +0100 Subject: [PATCH 02/12] Fixes & working tests --- contracts/modules/STO/CappedSTO.sol | 7 - contracts/modules/STO/ISTO.sol | 9 +- contracts/modules/STO/USDTieredSTO.sol | 60 +++-- test/p_usd_tiered_sto.js | 317 +++++++++++++------------ 4 files changed, 207 insertions(+), 186 deletions(-) diff --git a/contracts/modules/STO/CappedSTO.sol b/contracts/modules/STO/CappedSTO.sol index ac27bc120..5bd481280 100644 --- a/contracts/modules/STO/CappedSTO.sol +++ b/contracts/modules/STO/CappedSTO.sol @@ -133,13 +133,6 @@ contract CappedSTO is ISTO, ReentrancyGuard { return totalTokensSold >= cap; } - /** - * @notice Return the total no. of investors - */ - function getNumberInvestors() public view returns (uint256) { - return investorCount; - } - /** * @notice Return the total no. of tokens sold */ diff --git a/contracts/modules/STO/ISTO.sol b/contracts/modules/STO/ISTO.sol index b2660e8ec..f3afc6c40 100644 --- a/contracts/modules/STO/ISTO.sol +++ b/contracts/modules/STO/ISTO.sol @@ -50,11 +50,6 @@ contract ISTO is Module, Pausable { return fundsRaised[uint8(_fundRaiseType)]; } - /** - * @notice Return the total no. of investors - */ - function getNumberInvestors() public view returns (uint256); - /** * @notice Return the total no. of tokens sold */ @@ -78,8 +73,10 @@ contract ISTO is Module, Pausable { function _setFundRaiseType(FundRaiseType[] _fundRaiseTypes) internal { // FundRaiseType[] parameter type ensures only valid values for _fundRaiseTypes require(_fundRaiseTypes.length > 0, "Raise type not specified"); + fundRaiseTypes[uint8(FundRaiseType.ETH)] = false; + fundRaiseTypes[uint8(FundRaiseType.POLY)] = false; + fundRaiseTypes[uint8(FundRaiseType.DAI)] = false; for (uint8 j = 0; j < _fundRaiseTypes.length; j++) { - require(!fundRaiseTypes[uint8(_fundRaiseTypes[j])], "Duplicated raise types"); fundRaiseTypes[uint8(_fundRaiseTypes[j])] = true; } emit SetFundRaiseTypes(_fundRaiseTypes); diff --git a/contracts/modules/STO/USDTieredSTO.sol b/contracts/modules/STO/USDTieredSTO.sol index e6b75b973..147ff443a 100644 --- a/contracts/modules/STO/USDTieredSTO.sol +++ b/contracts/modules/STO/USDTieredSTO.sol @@ -171,20 +171,21 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { address _reserveWallet ) public onlyFactory { modifyTimes(_startTime, _endTime); - // NB - modifyFunding must come before modifyTiers - modifyFunding(_fundRaiseTypes, _ratePerTier.length); + // NB - modifyFunding must come after modifyTiers modifyTiers(_ratePerTier, _ratePerTierDiscountPoly, _tokensPerTierTotal, _tokensPerTierDiscountPoly); + modifyFunding(_fundRaiseTypes); modifyAddresses(_wallet, _reserveWallet); modifyLimits(_nonAccreditedLimitUSD, _minimumInvestmentUSD); } - function modifyFunding(FundRaiseType[] _fundRaiseTypes, uint256 _numberOfTiers) public onlyFactoryOrOwner { + function modifyFunding(FundRaiseType[] _fundRaiseTypes) public onlyFactoryOrOwner { require(now < startTime); _setFundRaiseType(_fundRaiseTypes); - mintedPerTierTotal = new uint256[](_numberOfTiers); - mintedPerTierDiscountPoly = new uint256[](_numberOfTiers); + uint256 length = getNumberOfTiers(); + mintedPerTierTotal = new uint256[](length); + mintedPerTierDiscountPoly = new uint256[](length); for (uint8 i = 0; i < _fundRaiseTypes.length; i++) { - mintedPerTier[uint8(_fundRaiseTypes[i])] = new uint256[](_numberOfTiers); + mintedPerTier[uint8(_fundRaiseTypes[i])] = new uint256[](length); } } @@ -326,7 +327,7 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { * @param _beneficiary Address where security tokens will be sent */ function buyWithETH(address _beneficiary) public payable validETH { - uint256 rate = IOracle(_getOracle(bytes32("ETH"), bytes32("USD"))).getPrice(); + uint256 rate = getRate(FundRaiseType.ETH); (uint256 spentUSD, uint256 spentValue) = _buyTokens(_beneficiary, msg.value, rate, FundRaiseType.ETH); // Modify storage investorInvested[_beneficiary][uint8(FundRaiseType.ETH)] = investorInvested[_beneficiary][uint8(FundRaiseType.ETH)].add(spentValue); @@ -344,7 +345,7 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { * @param _investedPOLY Amount of POLY invested */ function buyWithPOLY(address _beneficiary, uint256 _investedPOLY) public validPOLY { - uint256 rate = IOracle(_getOracle(bytes32("POLY"), bytes32("USD"))).getPrice(); + uint256 rate = getRate(FundRaiseType.POLY); (uint256 spentUSD, uint256 spentValue) = _buyTokens(_beneficiary, _investedPOLY, rate, FundRaiseType.POLY); // Modify storage investorInvested[_beneficiary][uint8(FundRaiseType.POLY)] = investorInvested[_beneficiary][uint8(FundRaiseType.POLY)].add(spentValue); @@ -361,11 +362,11 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { */ function buyWithDAI(address _beneficiary, uint256 _investedDAI) public validPOLY { // Assume a conversion rate of 1 - 1 with USD - uint256 rate = 1 * 10**18; + uint256 rate = getRate(FundRaiseType.DAI); (uint256 spentUSD, uint256 spentValue) = _buyTokens(_beneficiary, _investedDAI, rate, FundRaiseType.DAI); // Modify storage investorInvested[_beneficiary][uint8(FundRaiseType.DAI)] = investorInvested[_beneficiary][uint8(FundRaiseType.DAI)].add(spentValue); - fundsRaised[uint8(FundRaiseType.POLY)] = fundsRaised[uint8(FundRaiseType.POLY)].add(spentValue); + fundsRaised[uint8(FundRaiseType.DAI)] = fundsRaised[uint8(FundRaiseType.DAI)].add(spentValue); // Forward DAI to issuer wallet require(daiToken.transferFrom(msg.sender, wallet, spentValue)); emit FundsReceived(msg.sender, _beneficiary, spentUSD, FundRaiseType.DAI, _investedDAI, spentValue, rate); @@ -447,6 +448,7 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { (spentUSD, tierPurchasedTokens) = _purchaseTier(_beneficiary, ratePerTierDiscountPoly[_tier], discountRemaining, _investedUSD, _tier); _investedUSD = _investedUSD.sub(spentUSD); mintedPerTierDiscountPoly[_tier] = mintedPerTierDiscountPoly[_tier].add(tierPurchasedTokens); + mintedPerTier[uint8(FundRaiseType.POLY)][_tier] = mintedPerTier[uint8(FundRaiseType.POLY)][_tier].add(tierPurchasedTokens); mintedPerTierTotal[_tier] = mintedPerTierTotal[_tier].add(tierPurchasedTokens); } // Now, if there is any remaining USD to be invested, purchase at non-discounted rate @@ -510,20 +512,38 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { return (mintedPerTierTotal[mintedPerTierTotal.length - 1] == tokensPerTierTotal[tokensPerTierTotal.length - 1]); } + function getRate(FundRaiseType _fundRaiseType) public view returns (uint256){ + if (_fundRaiseType == FundRaiseType.ETH) { + return IOracle(_getOracle(bytes32("ETH"), bytes32("USD"))).getPrice(); + } else if (_fundRaiseType == FundRaiseType.POLY) { + return IOracle(_getOracle(bytes32("POLY"), bytes32("USD"))).getPrice(); + } else if (_fundRaiseType == FundRaiseType.DAI) { + return 1 * 10**18; + } else { + revert("Incorrect funding"); + } + } + /** - * @notice Return USD raised by the STO - * @return uint256 Amount of USD raised + * @notice This function converts from ETH or POLY to USD + * @param _fundRaiseType Currency key + * @param _amount Value to convert to USD + * @return uint256 Value in USD */ - function getRaisedUSD() public view returns (uint256) { - return fundsRaisedUSD; + function convertToUSD(FundRaiseType _fundRaiseType, uint256 _amount) public view returns(uint256) { + uint256 rate = getRate(_fundRaiseType); + return DecimalMath.mul(_amount, rate); } /** - * @notice Return the total no. of investors - * @return uint256 Investor count + * @notice This function converts from USD to ETH or POLY + * @param _fundRaiseType Currency key + * @param _amount Value to convert from USD + * @return uint256 Value in ETH or POLY */ - function getNumberInvestors() public view returns (uint256) { - return investorCount; + function convertFromUSD(FundRaiseType _fundRaiseType, uint256 _amount) public view returns(uint256) { + uint256 rate = getRate(_fundRaiseType); + return DecimalMath.div(_amount, rate); } /** @@ -553,7 +573,7 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { * @notice Return the total no. of tokens sold for ETH * @return uint256 Total number of tokens sold for ETH */ - function getTokensSold(FundRaiseType _fundRaiseType) public view returns (uint256) { + function getTokensSoldFor(FundRaiseType _fundRaiseType) public view returns (uint256) { uint256 tokensSold; for (uint8 i = 0; i < mintedPerTier[uint8(_fundRaiseType)].length; i++) { tokensSold = tokensSold.add(mintedPerTier[uint8(_fundRaiseType)][i]); @@ -584,7 +604,7 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { function getInitFunction() public pure returns (bytes4) { //keccak256("configure(uint256,uint256,uint256[],uint256[],uint256[],uint256[],uint256,uint256,uint8[],address,address)") == //0xd31d4f2d09fc7bdefd7ea179aebde3dd53e24265c3c63e17e399bbf85fe873bf - return bytes4(keccak256("configure(uint256,uint256,uint256[],uint256[],uint256[],uint256[],uint256,uint256,uint8[],address,address)")); + return 0xd31d4f2d; } function _getOracle(bytes32 _currency, bytes32 _denominatedCurrency) internal view returns (address) { diff --git a/test/p_usd_tiered_sto.js b/test/p_usd_tiered_sto.js index 553fe006e..2247609d5 100644 --- a/test/p_usd_tiered_sto.js +++ b/test/p_usd_tiered_sto.js @@ -37,6 +37,9 @@ contract('USDTieredSTO', accounts => { let ACCREDITED2; let NONACCREDITED1; let NONACCREDITED2; + let ETH = 0; + let POLY = 1; + let DAI = 2; let MESSAGE = "Transaction Should Fail!"; const GAS_PRICE = 0; @@ -87,7 +90,7 @@ contract('USDTieredSTO', accounts => { let _tokensPerTierDiscountPoly = []; let _nonAccreditedLimitUSD = []; let _minimumInvestmentUSD = []; - let _fundRaiseTypes = []; + let _fundRaiseTypess = []; let _wallet = []; let _reserveWallet = []; @@ -100,7 +103,7 @@ contract('USDTieredSTO', accounts => { uint256[] _tokensPerTierDiscountPoly, uint256 _nonAccreditedLimitUSD, uint256 _minimumInvestmentUSD, - uint8[] _fundRaiseTypes, + uint8[] _fundRaiseTypess, address _wallet, address _reserveWallet ) */ @@ -133,7 +136,7 @@ contract('USDTieredSTO', accounts => { name: '_minimumInvestmentUSD' },{ type: 'uint8[]', - name: '_fundRaiseTypes' + name: '_fundRaiseTypess' },{ type: 'address', name: '_wallet' @@ -153,17 +156,20 @@ contract('USDTieredSTO', accounts => { let tokenToUSD = _amount.div(10**18).mul(USDTOKEN.div(10**18)).mul(10**18); // TOKEN * USD/TOKEN = USD if (_currencyTo == "USD") return tokenToUSD; - if (_currencyTo == "ETH" || _currencyTo == "POLY") - return await I_USDTieredSTO_Array[_stoID].convertFromUSD(_currencyTo, tokenToUSD); + if (_currencyTo == "ETH") { + return await I_USDTieredSTO_Array[_stoID].convertFromUSD(ETH, tokenToUSD); + } else if (_currencyTo == "POLY") { + return await I_USDTieredSTO_Array[_stoID].convertFromUSD(POLY, tokenToUSD); + } } if (_currencyFrom == "USD") { if (_currencyTo == "TOKEN") return _amount.div(USDTOKEN).mul(10**18); // USD / USD/TOKEN = TOKEN if (_currencyTo == "ETH" || _currencyTo == "POLY") - return await I_USDTieredSTO_Array[_stoID].convertFromUSD(_currencyTo, _amount); + return await I_USDTieredSTO_Array[_stoID].convertFromUSD((_currencyTo == "ETH" ? ETH : POLY), _amount); } if (_currencyFrom == "ETH" || _currencyFrom == "POLY") { - let ethToUSD = await I_USDTieredSTO_Array[_stoID].convertToUSD(_currencyTo, _amount); + let ethToUSD = await I_USDTieredSTO_Array[_stoID].convertToUSD((_currencyTo == "ETH" ? ETH : POLY), _amount); if (_currencyTo == "USD") return ethToUSD; if (_currencyTo == "TOKEN") @@ -263,19 +269,19 @@ contract('USDTieredSTO', accounts => { I_SecurityTokenRegistry = await SecurityTokenRegistry.new({from: POLYMATH }); await I_PolymathRegistry.changeAddress("SecurityTokenRegistry", I_SecurityTokenRegistry.address, {from: POLYMATH}); - + assert.notEqual( I_SecurityTokenRegistry.address.valueOf(), "0x0000000000000000000000000000000000000000", "SecurityTokenRegistry contract was not deployed", ); - + // Step 10: update the registries addresses from the PolymathRegistry contract I_SecurityTokenRegistryProxy = await SecurityTokenRegistryProxy.new({from: POLYMATH}); let bytesProxy = encodeProxyCall([I_PolymathRegistry.address, I_STFactory.address, REGFEE, REGFEE, I_PolyToken.address, POLYMATH]); await I_SecurityTokenRegistryProxy.upgradeToAndCall("1.0.0", I_SecurityTokenRegistry.address, bytesProxy, {from: POLYMATH}); I_STRProxied = await SecurityTokenRegistry.at(I_SecurityTokenRegistryProxy.address); - + // Step 10: Deploy the FeatureRegistry I_FeatureRegistry = await FeatureRegistry.new( @@ -367,14 +373,14 @@ contract('USDTieredSTO', accounts => { _tokensPerTierDiscountPoly.push([BigNumber(0),BigNumber(0)]); // [ 0, 0 ] _nonAccreditedLimitUSD.push(BigNumber(10000).mul(BigNumber(10**18))); // 10k USD _minimumInvestmentUSD.push(BigNumber(5*10**18)); // 5 USD - _fundRaiseTypes.push([0, 1]); + _fundRaiseTypess.push([0, 1]); _wallet.push(WALLET); _reserveWallet.push(RESERVEWALLET); let config = [ _startTime[stoId], _endTime[stoId], _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], - _fundRaiseTypes[stoId], _wallet[stoId], _reserveWallet[stoId] + _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId] ]; let bytesSTO = web3.eth.abi.encodeFunctionCall(functionSignature, config); @@ -411,14 +417,14 @@ contract('USDTieredSTO', accounts => { _tokensPerTierDiscountPoly.push([BigNumber(0), BigNumber(0), BigNumber(0), BigNumber(0), BigNumber(0)]); _nonAccreditedLimitUSD.push(BigNumber(10000).mul(BigNumber(10**18))); _minimumInvestmentUSD.push(BigNumber(0)); - _fundRaiseTypes.push([0, 1]); + _fundRaiseTypess.push([0, 1]); _wallet.push(WALLET); _reserveWallet.push(RESERVEWALLET); let config = [ _startTime[stoId], _endTime[stoId], _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], - _fundRaiseTypes[stoId], _wallet[stoId], _reserveWallet[stoId] + _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId] ]; let bytesSTO = web3.eth.abi.encodeFunctionCall(functionSignature, config); @@ -455,14 +461,14 @@ contract('USDTieredSTO', accounts => { _tokensPerTierDiscountPoly.push([BigNumber(100*10**18),BigNumber(25*10**18)]); // [ 100 Token, 25 Token ] _nonAccreditedLimitUSD.push(BigNumber(25*10**18)); // [ 25 USD ] _minimumInvestmentUSD.push(BigNumber(5)); - _fundRaiseTypes.push([0, 1]); + _fundRaiseTypess.push([0, 1]); _wallet.push(WALLET); _reserveWallet.push(RESERVEWALLET); let config = [ _startTime[stoId], _endTime[stoId], _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], - _fundRaiseTypes[stoId], _wallet[stoId], _reserveWallet[stoId] + _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId] ]; let bytesSTO = web3.eth.abi.encodeFunctionCall(functionSignature, config); @@ -484,14 +490,14 @@ contract('USDTieredSTO', accounts => { _tokensPerTierDiscountPoly.push([BigNumber(0),BigNumber(50*10**18)]); _nonAccreditedLimitUSD.push(BigNumber(10000).mul(BigNumber(10**18))); _minimumInvestmentUSD.push(BigNumber(0)); - _fundRaiseTypes.push([0, 1]); + _fundRaiseTypess.push([0, 1]); _wallet.push(WALLET); _reserveWallet.push(RESERVEWALLET); let config = [ _startTime[stoId], _endTime[stoId], _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], - _fundRaiseTypes[stoId], _wallet[stoId], _reserveWallet[stoId] + _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId] ]; let bytesSTO = web3.eth.abi.encodeFunctionCall(functionSignature, config); @@ -510,10 +516,10 @@ contract('USDTieredSTO', accounts => { let tokensPerTierTotal = [10]; let tokensPerTierDiscountPoly = [10]; let config = [ - [_startTime[stoId], _endTime[stoId], ratePerTier, _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypes[stoId], _wallet[stoId], _reserveWallet[stoId]], - [_startTime[stoId], _endTime[stoId], _ratePerTier[stoId], ratePerTierDiscountPoly, _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypes[stoId], _wallet[stoId], _reserveWallet[stoId]], - [_startTime[stoId], _endTime[stoId], _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], tokensPerTierTotal, _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypes[stoId], _wallet[stoId], _reserveWallet[stoId]], - [_startTime[stoId], _endTime[stoId], _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], tokensPerTierDiscountPoly, _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypes[stoId], _wallet[stoId], _reserveWallet[stoId]] + [_startTime[stoId], _endTime[stoId], ratePerTier, _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId]], + [_startTime[stoId], _endTime[stoId], _ratePerTier[stoId], ratePerTierDiscountPoly, _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId]], + [_startTime[stoId], _endTime[stoId], _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], tokensPerTierTotal, _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId]], + [_startTime[stoId], _endTime[stoId], _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], tokensPerTierDiscountPoly, _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId]] ]; for (var i = 0; i < config.length; i++) { let bytesSTO = web3.eth.abi.encodeFunctionCall(functionSignature, config[i]); @@ -532,7 +538,7 @@ contract('USDTieredSTO', accounts => { let stoId = 0; let ratePerTier = [BigNumber(10*10**16), BigNumber(0)]; - let config = [_startTime[stoId], _endTime[stoId], ratePerTier, _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypes[stoId], _wallet[stoId], _reserveWallet[stoId]]; + let config = [_startTime[stoId], _endTime[stoId], ratePerTier, _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId]]; let bytesSTO = web3.eth.abi.encodeFunctionCall(functionSignature, config); let errorThrown = false; try { @@ -548,7 +554,7 @@ contract('USDTieredSTO', accounts => { let stoId = 0; let wallet = "0x0000000000000000000000000000000000000000"; - let config = [_startTime[stoId], _endTime[stoId], _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypes[stoId], wallet, _reserveWallet[stoId]]; + let config = [_startTime[stoId], _endTime[stoId], _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypess[stoId], wallet, _reserveWallet[stoId]]; let bytesSTO = web3.eth.abi.encodeFunctionCall(functionSignature, config); let errorThrown = false; try { @@ -564,7 +570,7 @@ contract('USDTieredSTO', accounts => { let stoId = 0; let reserveWallet = "0x0000000000000000000000000000000000000000"; - let config = [_startTime[stoId], _endTime[stoId], _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypes[stoId], _wallet[stoId], reserveWallet]; + let config = [_startTime[stoId], _endTime[stoId], _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypess[stoId], _wallet[stoId], reserveWallet]; let bytesSTO = web3.eth.abi.encodeFunctionCall(functionSignature, config); let errorThrown = false; try { @@ -581,7 +587,7 @@ contract('USDTieredSTO', accounts => { let startTime = latestTime() + duration.days(35); let endTime = latestTime() + duration.days(1); - let config = [startTime, endTime, _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypes[stoId], _wallet[stoId], _reserveWallet[stoId]]; + let config = [startTime, endTime, _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId]]; let bytesSTO = web3.eth.abi.encodeFunctionCall(functionSignature, config); let errorThrown = false; try { @@ -598,7 +604,7 @@ contract('USDTieredSTO', accounts => { let startTime = latestTime() - duration.days(35); let endTime = startTime + duration.days(50); - let config = [startTime, endTime, _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypes[stoId], _wallet[stoId], _reserveWallet[stoId]]; + let config = [startTime, endTime, _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId]]; let bytesSTO = web3.eth.abi.encodeFunctionCall(functionSignature, config); let errorThrown = false; try { @@ -613,20 +619,25 @@ contract('USDTieredSTO', accounts => { describe("Test modifying configuration", async() => { - it("Should successfully change config before startTime", async() => { + it("Should successfully change config before startTime - funding", async() => { let stoId = 3; - await I_USDTieredSTO_Array[stoId].modifyFunding([0], { from: ISSUER }); - assert.equal(await I_USDTieredSTO_Array[stoId].fundRaiseType.call(0),true,"STO Configuration doesn't set as expected"); - assert.equal(await I_USDTieredSTO_Array[stoId].fundRaiseType.call(1),false,"STO Configuration doesn't set as expected"); + assert.equal(await I_USDTieredSTO_Array[stoId].fundRaiseTypes.call(0),true,"STO Configuration doesn't set as expected"); + assert.equal(await I_USDTieredSTO_Array[stoId].fundRaiseTypes.call(1),false,"STO Configuration doesn't set as expected"); await I_USDTieredSTO_Array[stoId].modifyFunding([1], { from: ISSUER }); - assert.equal(await I_USDTieredSTO_Array[stoId].fundRaiseType.call(0),false,"STO Configuration doesn't set as expected"); - assert.equal(await I_USDTieredSTO_Array[stoId].fundRaiseType.call(1),true,"STO Configuration doesn't set as expected"); + assert.equal(await I_USDTieredSTO_Array[stoId].fundRaiseTypes.call(0),false,"STO Configuration doesn't set as expected"); + assert.equal(await I_USDTieredSTO_Array[stoId].fundRaiseTypes.call(1),true,"STO Configuration doesn't set as expected"); await I_USDTieredSTO_Array[stoId].modifyFunding([0,1], { from: ISSUER }); - assert.equal(await I_USDTieredSTO_Array[stoId].fundRaiseType.call(0),true,"STO Configuration doesn't set as expected"); - assert.equal(await I_USDTieredSTO_Array[stoId].fundRaiseType.call(1),true,"STO Configuration doesn't set as expected"); + assert.equal(await I_USDTieredSTO_Array[stoId].fundRaiseTypes.call(0),true,"STO Configuration doesn't set as expected"); + assert.equal(await I_USDTieredSTO_Array[stoId].fundRaiseTypes.call(1),true,"STO Configuration doesn't set as expected"); + + + }); + + it("Should successfully change config before startTime - limits and tiers, times, addresses", async() => { + let stoId = 3; await I_USDTieredSTO_Array[stoId].modifyLimits(BigNumber(1*10**18), BigNumber(15*10**18), { from: ISSUER }); assert.equal((await I_USDTieredSTO_Array[stoId].minimumInvestmentUSD.call()).toNumber(),BigNumber(15*10**18).toNumber(),"STO Configuration doesn't set as expected"); @@ -1244,8 +1255,8 @@ contract('USDTieredSTO', accounts => { let init_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let init_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); let init_RaisedUSD = await I_USDTieredSTO_Array[stoId].fundsRaisedUSD.call(); - let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let init_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let init_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -1261,8 +1272,8 @@ contract('USDTieredSTO', accounts => { let final_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let final_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); let final_RaisedUSD = await I_USDTieredSTO_Array[stoId].fundsRaisedUSD.call(); - let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let final_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let final_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -1283,11 +1294,11 @@ contract('USDTieredSTO', accounts => { assert.equal((await I_USDTieredSTO_Array[stoId].investorCount.call()).toNumber(), 1, "Investor count not changed as expected"); assert.equal((await I_USDTieredSTO_Array[stoId].getTokensSold()).toNumber(), investment_Token.toNumber(), "getTokensSold not changed as expected"); assert.equal((await I_USDTieredSTO_Array[stoId].getTokensMinted()).toNumber(), investment_Token.toNumber(), "getTokensMinted not changed as expected"); - assert.equal((await I_USDTieredSTO_Array[stoId].getTokensSoldForETH()).toNumber(), investment_Token.toNumber(), "getTokensSoldForETH not changed as expected"); - assert.equal((await I_USDTieredSTO_Array[stoId].getTokensSoldForPOLY()).toNumber(), 0, "getTokensSoldForPOLY not changed as expected"); + assert.equal((await I_USDTieredSTO_Array[stoId].getTokensSoldFor(ETH)).toNumber(), investment_Token.toNumber(), "getTokensSoldForETH not changed as expected"); + assert.equal((await I_USDTieredSTO_Array[stoId].getTokensSoldFor(POLY)).toNumber(), 0, "getTokensSoldForPOLY not changed as expected"); assert.equal((await I_USDTieredSTO_Array[stoId].investorInvestedUSD.call(NONACCREDITED1)).toNumber(), investment_USD.toNumber(), "investorInvestedUSD not changed as expected"); - assert.equal((await I_USDTieredSTO_Array[stoId].investorInvestedETH.call(NONACCREDITED1)).toNumber(), investment_ETH.toNumber(), "investorInvestedETH not changed as expected"); - assert.equal((await I_USDTieredSTO_Array[stoId].investorInvestedPOLY.call(NONACCREDITED1)).toNumber(), 0, "investorInvestedPOLY not changed as expected"); + assert.equal((await I_USDTieredSTO_Array[stoId].investorInvested.call(NONACCREDITED1, ETH)).toNumber(), investment_ETH.toNumber(), "investorInvestedETH not changed as expected"); + assert.equal((await I_USDTieredSTO_Array[stoId].investorInvested.call(NONACCREDITED1, POLY)).toNumber(), 0, "investorInvestedPOLY not changed as expected"); }); it("should successfully buy using buyWithETH at tier 0 for NONACCREDITED1", async() => { @@ -1306,8 +1317,8 @@ contract('USDTieredSTO', accounts => { let init_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let init_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let init_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); - let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let init_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let init_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -1322,8 +1333,8 @@ contract('USDTieredSTO', accounts => { let final_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let final_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let final_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); - let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let final_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let final_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -1359,8 +1370,8 @@ contract('USDTieredSTO', accounts => { let init_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let init_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let init_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); - let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let init_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let init_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -1376,8 +1387,8 @@ contract('USDTieredSTO', accounts => { let final_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let final_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let final_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); - let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let final_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let final_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -1412,8 +1423,8 @@ contract('USDTieredSTO', accounts => { let init_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let init_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let init_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); - let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let init_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let init_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -1428,8 +1439,8 @@ contract('USDTieredSTO', accounts => { let final_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let final_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let final_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); - let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let final_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let final_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -1462,8 +1473,8 @@ contract('USDTieredSTO', accounts => { let init_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let init_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let init_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); - let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let init_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let init_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -1478,8 +1489,8 @@ contract('USDTieredSTO', accounts => { let final_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let final_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let final_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); - let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let final_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let final_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -1511,11 +1522,11 @@ contract('USDTieredSTO', accounts => { // Additional checks on getters let init_getTokensSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let init_getTokensMinted = await I_USDTieredSTO_Array[stoId].getTokensMinted(); - let init_getTokensSoldForETH = await I_USDTieredSTO_Array[stoId].getTokensSoldForETH(); - let init_getTokensSoldForPOLY = await I_USDTieredSTO_Array[stoId].getTokensSoldForPOLY(); + let init_getTokensSoldForETH = await I_USDTieredSTO_Array[stoId].getTokensSoldFor(ETH); + let init_getTokensSoldForPOLY = await I_USDTieredSTO_Array[stoId].getTokensSoldFor(POLY); let init_investorInvestedUSD = await I_USDTieredSTO_Array[stoId].investorInvestedUSD.call(ACCREDITED1); - let init_investorInvestedETH = await I_USDTieredSTO_Array[stoId].investorInvestedETH.call(ACCREDITED1); - let init_investorInvestedPOLY = await I_USDTieredSTO_Array[stoId].investorInvestedPOLY.call(ACCREDITED1); + let init_investorInvestedETH = await I_USDTieredSTO_Array[stoId].investorInvested.call(ACCREDITED1, ETH); + let init_investorInvestedPOLY = await I_USDTieredSTO_Array[stoId].investorInvested.call(ACCREDITED1, POLY); let init_TokenSupply = await I_SecurityToken.totalSupply(); let init_InvestorTokenBal = await I_SecurityToken.balanceOf(ACCREDITED1); @@ -1524,8 +1535,8 @@ contract('USDTieredSTO', accounts => { let init_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let init_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let init_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); - let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let init_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let init_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -1541,8 +1552,8 @@ contract('USDTieredSTO', accounts => { let final_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let final_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let final_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); - let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let final_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let final_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -1562,11 +1573,11 @@ contract('USDTieredSTO', accounts => { assert.equal((await I_USDTieredSTO_Array[stoId].investorCount.call()).toNumber(), 2, "Investor count not changed as expected"); assert.equal((await I_USDTieredSTO_Array[stoId].getTokensSold()).toNumber(), init_getTokensSold.add(investment_Token).toNumber(), "getTokensSold not changed as expected"); assert.equal((await I_USDTieredSTO_Array[stoId].getTokensMinted()).toNumber(), init_getTokensMinted.add(investment_Token).toNumber(), "getTokensMinted not changed as expected"); - assert.equal((await I_USDTieredSTO_Array[stoId].getTokensSoldForETH()).toNumber(), init_getTokensSoldForETH.toNumber(), "getTokensSoldForETH not changed as expected"); - assert.equal((await I_USDTieredSTO_Array[stoId].getTokensSoldForPOLY()).toNumber(), init_getTokensSoldForPOLY.add(investment_Token).toNumber(), "getTokensSoldForPOLY not changed as expected"); + assert.equal((await I_USDTieredSTO_Array[stoId].getTokensSoldFor(ETH)).toNumber(), init_getTokensSoldForETH.toNumber(), "getTokensSoldForETH not changed as expected"); + assert.equal((await I_USDTieredSTO_Array[stoId].getTokensSoldFor(POLY)).toNumber(), init_getTokensSoldForPOLY.add(investment_Token).toNumber(), "getTokensSoldForPOLY not changed as expected"); assert.equal((await I_USDTieredSTO_Array[stoId].investorInvestedUSD.call(ACCREDITED1)).toNumber(), init_investorInvestedUSD.add(investment_USD).toNumber(), "investorInvestedUSD not changed as expected"); - assert.equal((await I_USDTieredSTO_Array[stoId].investorInvestedETH.call(ACCREDITED1)).toNumber(), init_investorInvestedETH.toNumber(), "investorInvestedETH not changed as expected"); - assert.equal((await I_USDTieredSTO_Array[stoId].investorInvestedPOLY.call(ACCREDITED1)).toNumber(), init_investorInvestedPOLY.add(investment_POLY).toNumber(), "investorInvestedPOLY not changed as expected"); + assert.equal((await I_USDTieredSTO_Array[stoId].investorInvested.call(ACCREDITED1, ETH)).toNumber(), init_investorInvestedETH.toNumber(), "investorInvestedETH not changed as expected"); + assert.equal((await I_USDTieredSTO_Array[stoId].investorInvested.call(ACCREDITED1, POLY)).toNumber(), init_investorInvestedPOLY.add(investment_POLY).toNumber(), "investorInvestedPOLY not changed as expected"); }); it("should successfully modify NONACCREDITED cap for NONACCREDITED1", async() => { @@ -1602,8 +1613,8 @@ contract('USDTieredSTO', accounts => { let init_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let init_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let init_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); - let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let init_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let init_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -1619,8 +1630,8 @@ contract('USDTieredSTO', accounts => { let final_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let final_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let final_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); - let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let final_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let final_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -1648,8 +1659,8 @@ contract('USDTieredSTO', accounts => { init_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); init_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); init_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); - init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); init_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); init_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -1665,8 +1676,8 @@ contract('USDTieredSTO', accounts => { final_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); final_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); final_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); - final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); final_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); final_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -1810,8 +1821,8 @@ contract('USDTieredSTO', accounts => { let init_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let init_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let init_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); - let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let init_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let init_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -1826,8 +1837,8 @@ contract('USDTieredSTO', accounts => { let final_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let final_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let final_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); - let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let final_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let final_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -1872,8 +1883,8 @@ contract('USDTieredSTO', accounts => { let init_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let init_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let init_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); - let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let init_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let init_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -1888,8 +1899,8 @@ contract('USDTieredSTO', accounts => { let final_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let final_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let final_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); - let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let final_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let final_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -1933,8 +1944,8 @@ contract('USDTieredSTO', accounts => { let init_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let init_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let init_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); - let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let init_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let init_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -1949,8 +1960,8 @@ contract('USDTieredSTO', accounts => { let final_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let final_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let final_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); - let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let final_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let final_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -1995,8 +2006,8 @@ contract('USDTieredSTO', accounts => { let init_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let init_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let init_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); - let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let init_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let init_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -2011,8 +2022,8 @@ contract('USDTieredSTO', accounts => { let final_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let final_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let final_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); - let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let final_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let final_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -2246,8 +2257,8 @@ contract('USDTieredSTO', accounts => { let init_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let init_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); let init_RaisedUSD = await I_USDTieredSTO_Array[stoId].fundsRaisedUSD.call(); - let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let init_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let init_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -2263,8 +2274,8 @@ contract('USDTieredSTO', accounts => { let final_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let final_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); let final_RaisedUSD = await I_USDTieredSTO_Array[stoId].fundsRaisedUSD.call(); - let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let final_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let final_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -2285,11 +2296,11 @@ contract('USDTieredSTO', accounts => { assert.equal((await I_USDTieredSTO_Array[stoId].investorCount.call()).toNumber(), 1, "Investor count not changed as expected"); assert.equal((await I_USDTieredSTO_Array[stoId].getTokensSold()).toNumber(), investment_Token.toNumber(), "getTokensSold not changed as expected"); assert.equal((await I_USDTieredSTO_Array[stoId].getTokensMinted()).toNumber(), investment_Token.toNumber(), "getTokensMinted not changed as expected"); - assert.equal((await I_USDTieredSTO_Array[stoId].getTokensSoldForETH()).toNumber(), investment_Token.toNumber(), "getTokensSoldForETH not changed as expected"); - assert.equal((await I_USDTieredSTO_Array[stoId].getTokensSoldForPOLY()).toNumber(), 0, "getTokensSoldForPOLY not changed as expected"); + assert.equal((await I_USDTieredSTO_Array[stoId].getTokensSoldFor(ETH)).toNumber(), investment_Token.toNumber(), "getTokensSoldForETH not changed as expected"); + assert.equal((await I_USDTieredSTO_Array[stoId].getTokensSoldFor(POLY)).toNumber(), 0, "getTokensSoldForPOLY not changed as expected"); assert.equal((await I_USDTieredSTO_Array[stoId].investorInvestedUSD.call(NONACCREDITED1)).toNumber(), investment_USD.toNumber(), "investorInvestedUSD not changed as expected"); - assert.equal((await I_USDTieredSTO_Array[stoId].investorInvestedETH.call(NONACCREDITED1)).toNumber(), investment_ETH.toNumber(), "investorInvestedETH not changed as expected"); - assert.equal((await I_USDTieredSTO_Array[stoId].investorInvestedPOLY.call(NONACCREDITED1)).toNumber(), 0, "investorInvestedPOLY not changed as expected"); + assert.equal((await I_USDTieredSTO_Array[stoId].investorInvested.call(NONACCREDITED1, ETH)).toNumber(), investment_ETH.toNumber(), "investorInvestedETH not changed as expected"); + assert.equal((await I_USDTieredSTO_Array[stoId].investorInvested.call(NONACCREDITED1, POLY)).toNumber(), 0, "investorInvestedPOLY not changed as expected"); }); it("should successfully buy using buyWithETH at tier 0 for NONACCREDITED1", async() => { @@ -2308,8 +2319,8 @@ contract('USDTieredSTO', accounts => { let init_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let init_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let init_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); - let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let init_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let init_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -2324,8 +2335,8 @@ contract('USDTieredSTO', accounts => { let final_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let final_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let final_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); - let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let final_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let final_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -2361,8 +2372,8 @@ contract('USDTieredSTO', accounts => { let init_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let init_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let init_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); - let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let init_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let init_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -2378,8 +2389,8 @@ contract('USDTieredSTO', accounts => { let final_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let final_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let final_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); - let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let final_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let final_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -2414,8 +2425,8 @@ contract('USDTieredSTO', accounts => { let init_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let init_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let init_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); - let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let init_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let init_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -2430,8 +2441,8 @@ contract('USDTieredSTO', accounts => { let final_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let final_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let final_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); - let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let final_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let final_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -2464,8 +2475,8 @@ contract('USDTieredSTO', accounts => { let init_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let init_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let init_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); - let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let init_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let init_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -2480,8 +2491,8 @@ contract('USDTieredSTO', accounts => { let final_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let final_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let final_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); - let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let final_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let final_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -2513,11 +2524,11 @@ contract('USDTieredSTO', accounts => { // Additional checks on getters let init_getTokensSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let init_getTokensMinted = await I_USDTieredSTO_Array[stoId].getTokensMinted(); - let init_getTokensSoldForETH = await I_USDTieredSTO_Array[stoId].getTokensSoldForETH(); - let init_getTokensSoldForPOLY = await I_USDTieredSTO_Array[stoId].getTokensSoldForPOLY(); + let init_getTokensSoldForETH = await I_USDTieredSTO_Array[stoId].getTokensSoldFor(ETH); + let init_getTokensSoldForPOLY = await I_USDTieredSTO_Array[stoId].getTokensSoldFor(POLY); let init_investorInvestedUSD = await I_USDTieredSTO_Array[stoId].investorInvestedUSD.call(ACCREDITED1); - let init_investorInvestedETH = await I_USDTieredSTO_Array[stoId].investorInvestedETH.call(ACCREDITED1); - let init_investorInvestedPOLY = await I_USDTieredSTO_Array[stoId].investorInvestedPOLY.call(ACCREDITED1); + let init_investorInvestedETH = await I_USDTieredSTO_Array[stoId].investorInvested.call(ACCREDITED1, ETH); + let init_investorInvestedPOLY = await I_USDTieredSTO_Array[stoId].investorInvested.call(ACCREDITED1, POLY); let init_TokenSupply = await I_SecurityToken.totalSupply(); let init_InvestorTokenBal = await I_SecurityToken.balanceOf(ACCREDITED1); @@ -2526,8 +2537,8 @@ contract('USDTieredSTO', accounts => { let init_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let init_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let init_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); - let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let init_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let init_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -2543,8 +2554,8 @@ contract('USDTieredSTO', accounts => { let final_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let final_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let final_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); - let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let final_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let final_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -2564,11 +2575,11 @@ contract('USDTieredSTO', accounts => { assert.equal((await I_USDTieredSTO_Array[stoId].investorCount.call()).toNumber(), 2, "Investor count not changed as expected"); assert.equal((await I_USDTieredSTO_Array[stoId].getTokensSold()).toNumber(), init_getTokensSold.add(investment_Token).toNumber(), "getTokensSold not changed as expected"); assert.equal((await I_USDTieredSTO_Array[stoId].getTokensMinted()).toNumber(), init_getTokensMinted.add(investment_Token).toNumber(), "getTokensMinted not changed as expected"); - assert.equal((await I_USDTieredSTO_Array[stoId].getTokensSoldForETH()).toNumber(), init_getTokensSoldForETH.toNumber(), "getTokensSoldForETH not changed as expected"); - assert.equal((await I_USDTieredSTO_Array[stoId].getTokensSoldForPOLY()).toNumber(), init_getTokensSoldForPOLY.add(investment_Token).toNumber(), "getTokensSoldForPOLY not changed as expected"); + assert.equal((await I_USDTieredSTO_Array[stoId].getTokensSoldFor(ETH)).toNumber(), init_getTokensSoldForETH.toNumber(), "getTokensSoldForETH not changed as expected"); + assert.equal((await I_USDTieredSTO_Array[stoId].getTokensSoldFor(POLY)).toNumber(), init_getTokensSoldForPOLY.add(investment_Token).toNumber(), "getTokensSoldForPOLY not changed as expected"); assert.equal((await I_USDTieredSTO_Array[stoId].investorInvestedUSD.call(ACCREDITED1)).toNumber(), init_investorInvestedUSD.add(investment_USD).toNumber(), "investorInvestedUSD not changed as expected"); - assert.equal((await I_USDTieredSTO_Array[stoId].investorInvestedETH.call(ACCREDITED1)).toNumber(), init_investorInvestedETH.toNumber(), "investorInvestedETH not changed as expected"); - assert.equal((await I_USDTieredSTO_Array[stoId].investorInvestedPOLY.call(ACCREDITED1)).toNumber(), init_investorInvestedPOLY.add(investment_POLY).toNumber(), "investorInvestedPOLY not changed as expected"); + assert.equal((await I_USDTieredSTO_Array[stoId].investorInvested.call(ACCREDITED1, ETH)).toNumber(), init_investorInvestedETH.toNumber(), "investorInvestedETH not changed as expected"); + assert.equal((await I_USDTieredSTO_Array[stoId].investorInvested.call(ACCREDITED1, POLY)).toNumber(), init_investorInvestedPOLY.add(investment_POLY).toNumber(), "investorInvestedPOLY not changed as expected"); }); it("should successfully buy a partial amount and refund balance when reaching NONACCREDITED cap", async() => { @@ -2595,8 +2606,8 @@ contract('USDTieredSTO', accounts => { let init_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let init_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let init_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); - let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let init_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let init_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -2612,8 +2623,8 @@ contract('USDTieredSTO', accounts => { let final_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let final_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let final_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); - let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let final_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let final_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -2774,8 +2785,8 @@ contract('USDTieredSTO', accounts => { let init_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let init_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let init_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); - let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let init_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let init_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -2790,8 +2801,8 @@ contract('USDTieredSTO', accounts => { let final_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let final_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let final_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); - let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let final_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let final_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -2834,8 +2845,8 @@ contract('USDTieredSTO', accounts => { let init_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let init_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let init_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); - let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let init_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let init_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -2851,8 +2862,8 @@ contract('USDTieredSTO', accounts => { let final_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let final_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let final_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); - let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); let final_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let final_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -3075,15 +3086,15 @@ contract('USDTieredSTO', accounts => { describe("Generic", async() => { it("should get the right number of investors", async() => { - assert.equal((await I_USDTieredSTO_Array[0].investorCount.call()).toNumber(), (await I_USDTieredSTO_Array[0].getNumberInvestors()).toNumber(), "Investor count not changed as expected"); - assert.equal((await I_USDTieredSTO_Array[1].investorCount.call()).toNumber(), (await I_USDTieredSTO_Array[1].getNumberInvestors()).toNumber(), "Investor count not changed as expected"); - assert.equal((await I_USDTieredSTO_Array[2].investorCount.call()).toNumber(), (await I_USDTieredSTO_Array[2].getNumberInvestors()).toNumber(), "Investor count not changed as expected"); + assert.equal((await I_USDTieredSTO_Array[0].investorCount.call()).toNumber(), (await I_USDTieredSTO_Array[0].investorCount()).toNumber(), "Investor count not changed as expected"); + assert.equal((await I_USDTieredSTO_Array[1].investorCount.call()).toNumber(), (await I_USDTieredSTO_Array[1].investorCount()).toNumber(), "Investor count not changed as expected"); + assert.equal((await I_USDTieredSTO_Array[2].investorCount.call()).toNumber(), (await I_USDTieredSTO_Array[2].investorCount()).toNumber(), "Investor count not changed as expected"); }); it("should get the right amounts invested", async() => { - assert.equal((await I_USDTieredSTO_Array[0].fundsRaisedETH.call()).toNumber(), (await I_USDTieredSTO_Array[0].getRaisedEther()).toNumber(), "getRaisedEther not changed as expected"); - assert.equal((await I_USDTieredSTO_Array[0].fundsRaisedPOLY.call()).toNumber(), (await I_USDTieredSTO_Array[0].getRaisedPOLY()).toNumber(), "getRaisedPOLY not changed as expected"); - assert.equal((await I_USDTieredSTO_Array[0].fundsRaisedUSD.call()).toNumber(), (await I_USDTieredSTO_Array[0].getRaisedUSD()).toNumber(), "getRaisedUSD not changed as expected"); + assert.equal((await I_USDTieredSTO_Array[0].fundsRaised.call(ETH)).toNumber(), (await I_USDTieredSTO_Array[0].getRaised(0)).toNumber(), "getRaisedEther not changed as expected"); + assert.equal((await I_USDTieredSTO_Array[0].fundsRaised.call(POLY)).toNumber(), (await I_USDTieredSTO_Array[0].getRaised(1)).toNumber(), "getRaisedPOLY not changed as expected"); + assert.equal((await I_USDTieredSTO_Array[0].fundsRaisedUSD.call()).toNumber(), (await I_USDTieredSTO_Array[0].fundsRaisedUSD()).toNumber(), "fundsRaisedUSD not changed as expected"); }); }); @@ -3098,14 +3109,14 @@ contract('USDTieredSTO', accounts => { it("should get the right conversion for ETH to USD", async() => { // 20 ETH to 10000 USD let ethInWei = BigNumber(web3.utils.toWei('20', 'ether')); - let usdInWei = await I_USDTieredSTO_Array[0].convertToUSD("ETH", ethInWei); + let usdInWei = await I_USDTieredSTO_Array[0].convertToUSD(ETH, ethInWei); assert.equal(usdInWei.div(10**18).toNumber(), ethInWei.div(10**18).mul(USDETH.div(10**18)).toNumber()); }); it("should get the right conversion for POLY to USD", async() => { // 40000 POLY to 10000 USD let polyInWei = BigNumber(web3.utils.toWei('40000', 'ether')); - let usdInWei = await I_USDTieredSTO_Array[0].convertToUSD("POLY", polyInWei); + let usdInWei = await I_USDTieredSTO_Array[0].convertToUSD(POLY, polyInWei); assert.equal(usdInWei.div(10**18).toNumber(), polyInWei.div(10**18).mul(USDPOLY.div(10**18)).toNumber()); }); }); @@ -3115,14 +3126,14 @@ contract('USDTieredSTO', accounts => { it("should get the right conversion for USD to ETH", async() => { // 10000 USD to 20 ETH let usdInWei = BigNumber(web3.utils.toWei('10000', 'ether')); - let ethInWei = await I_USDTieredSTO_Array[0].convertFromUSD("ETH", usdInWei); + let ethInWei = await I_USDTieredSTO_Array[0].convertFromUSD(ETH, usdInWei); assert.equal(ethInWei.div(10**18).toNumber(), usdInWei.div(10**18).div(USDETH.div(10**18)).toNumber()); }); it("should get the right conversion for USD to POLY", async() => { // 10000 USD to 40000 POLY let usdInWei = BigNumber(web3.utils.toWei('10000', 'ether')); - let polyInWei = await I_USDTieredSTO_Array[0].convertFromUSD("POLY", usdInWei); + let polyInWei = await I_USDTieredSTO_Array[0].convertFromUSD(POLY, usdInWei); assert.equal(polyInWei.div(10**18).toNumber(), usdInWei.div(10**18).div(USDPOLY.div(10**18)).toNumber()); }); }); From 8a58536ea546858155f5d01fe906165319dda538 Mon Sep 17 00:00:00 2001 From: Adam Dossa Date: Wed, 19 Sep 2018 23:01:04 +0100 Subject: [PATCH 03/12] More test fixes --- test/b_capped_sto.js | 55 +++++++++++++++++++----------------- test/m_presale_sto.js | 4 +-- test/q_usd_tiered_sto_sim.js | 14 ++++----- 3 files changed, 38 insertions(+), 35 deletions(-) diff --git a/test/b_capped_sto.js b/test/b_capped_sto.js index f3b9ed77a..d6bc3c0ef 100644 --- a/test/b_capped_sto.js +++ b/test/b_capped_sto.js @@ -21,6 +21,9 @@ const PolyTokenFaucet = artifacts.require('./PolyTokenFaucet.sol'); const Web3 = require('web3'); const BigNumber = require('bignumber.js'); const web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")) // Hardcoded development port +let ETH = 0; +let POLY = 1; +let DAI = 2; contract('CappedSTO', accounts => { // Accounts Variable declaration @@ -224,7 +227,7 @@ contract('CappedSTO', accounts => { I_SecurityTokenRegistryProxy = await SecurityTokenRegistryProxy.new({from: account_polymath}); let bytesProxy = encodeProxyCall([I_PolymathRegistry.address, I_STFactory.address, initRegFee, initRegFee, I_PolyToken.address, account_polymath]); await I_SecurityTokenRegistryProxy.upgradeToAndCall("1.0.0", I_SecurityTokenRegistry.address, bytesProxy, {from: account_polymath}); - I_STRProxied = await SecurityTokenRegistry.at(I_SecurityTokenRegistryProxy.address); + I_STRProxied = await SecurityTokenRegistry.at(I_SecurityTokenRegistryProxy.address); // Step 10: Deploy the FeatureRegistry @@ -405,7 +408,7 @@ contract('CappedSTO', accounts => { "STO Configuration doesn't set as expected" ); assert.equal( - await I_CappedSTO_Array_ETH[0].fundRaiseType.call(E_fundRaiseType), + await I_CappedSTO_Array_ETH[0].fundRaiseTypes.call(E_fundRaiseType), true, "STO Configuration doesn't set as expected" ); @@ -514,13 +517,13 @@ contract('CappedSTO', accounts => { }); assert.equal( - (await I_CappedSTO_Array_ETH[0].getRaisedEther.call()) + (await I_CappedSTO_Array_ETH[0].getRaised.call(ETH)) .dividedBy(new BigNumber(10).pow(18)) .toNumber(), 1 ); - assert.equal(await I_CappedSTO_Array_ETH[0].getNumberInvestors.call(), 1); + assert.equal(await I_CappedSTO_Array_ETH[0].investorCount.call(), 1); assert.equal( (await I_SecurityToken_ETH.balanceOf(account_investor1)) @@ -634,13 +637,13 @@ contract('CappedSTO', accounts => { }); assert.equal( - (await I_CappedSTO_Array_ETH[0].getRaisedEther.call()) + (await I_CappedSTO_Array_ETH[0].getRaised.call(ETH)) .dividedBy(new BigNumber(10).pow(18)) .toNumber(), 10 ); - assert.equal(await I_CappedSTO_Array_ETH[0].getNumberInvestors.call(), 2); + assert.equal(await I_CappedSTO_Array_ETH[0].investorCount.call(), 2); assert.equal( (await I_SecurityToken_ETH.balanceOf(account_investor2)) @@ -686,18 +689,18 @@ contract('CappedSTO', accounts => { //console.log("WWWW",newBalance,await I_CappedSTO.fundsRaised.call(),balanceOfReceiver); let op = (BigNumber(newBalance).minus(balanceOfReceiver)).toNumber(); assert.equal( - (await I_CappedSTO_Array_ETH[0].getRaisedEther.call()).toNumber(), + (await I_CappedSTO_Array_ETH[0].getRaised.call(ETH)).toNumber(), op, "Somewhere raised money get stolen or sent to wrong wallet" ); }); it("Should get the raised amount of ether", async() => { - assert.equal(await I_CappedSTO_Array_ETH[0].getRaisedEther.call(), web3.utils.toWei('10','ether')); + assert.equal(await I_CappedSTO_Array_ETH[0].getRaised.call(ETH), web3.utils.toWei('10','ether')); }); it("Should get the raised amount of poly", async() => { - assert.equal((await I_CappedSTO_Array_ETH[0].getRaisedPOLY.call()).toNumber(), web3.utils.toWei('0','ether')); + assert.equal((await I_CappedSTO_Array_ETH[0].getRaised.call(POLY)).toNumber(), web3.utils.toWei('0','ether')); }); }); @@ -773,7 +776,7 @@ contract('CappedSTO', accounts => { "STO Configuration doesn't set as expected" ); assert.equal( - await I_CappedSTO_Array_ETH[1].fundRaiseType.call(E_fundRaiseType), + await I_CappedSTO_Array_ETH[1].fundRaiseTypes.call(E_fundRaiseType), true, "STO Configuration doesn't set as expected" ); @@ -826,13 +829,13 @@ contract('CappedSTO', accounts => { await I_CappedSTO_Array_ETH[1].buyTokens(account_investor3, { from : account_issuer, value: web3.utils.toWei('1', 'ether') }); assert.equal( - (await I_CappedSTO_Array_ETH[1].getRaisedEther.call()) + (await I_CappedSTO_Array_ETH[1].getRaised.call(ETH)) .dividedBy(new BigNumber(10).pow(18)) .toNumber(), 1 ); - assert.equal(await I_CappedSTO_Array_ETH[1].getNumberInvestors.call(), 1); + assert.equal(await I_CappedSTO_Array_ETH[1].investorCount.call(), 1); assert.equal( (await I_SecurityToken_ETH.balanceOf(account_investor3)) @@ -869,12 +872,12 @@ contract('CappedSTO', accounts => { for (var STOIndex = 2; STOIndex < MAX_MODULES; STOIndex++) { await I_CappedSTO_Array_ETH[STOIndex].buyTokens(account_investor3, { from : account_investor3, value: web3.utils.toWei('1', 'ether') }); assert.equal( - (await I_CappedSTO_Array_ETH[STOIndex].getRaisedEther.call()) + (await I_CappedSTO_Array_ETH[STOIndex].getRaised.call(ETH)) .dividedBy(new BigNumber(10).pow(18)) .toNumber(), 1 ); - assert.equal(await I_CappedSTO_Array_ETH[STOIndex].getNumberInvestors.call(), 1); + assert.equal(await I_CappedSTO_Array_ETH[STOIndex].investorCount.call(), 1); } }); }); @@ -954,7 +957,7 @@ contract('CappedSTO', accounts => { "STO Configuration doesn't set as expected" ); assert.equal( - await I_CappedSTO_Array_POLY[0].fundRaiseType.call(P_fundRaiseType), + await I_CappedSTO_Array_POLY[0].fundRaiseTypes.call(P_fundRaiseType), true, "STO Configuration doesn't set as expected" ); @@ -1002,13 +1005,13 @@ contract('CappedSTO', accounts => { ); assert.equal( - (await I_CappedSTO_Array_POLY[0].getRaisedPOLY.call()) + (await I_CappedSTO_Array_POLY[0].getRaised.call(POLY)) .dividedBy(new BigNumber(10).pow(18)) .toNumber(), 1000 ); - assert.equal(await I_CappedSTO_Array_POLY[0].getNumberInvestors.call(), 1); + assert.equal(await I_CappedSTO_Array_POLY[0].investorCount.call(), 1); assert.equal( (await I_SecurityToken_POLY.balanceOf(account_investor1)) @@ -1056,13 +1059,13 @@ contract('CappedSTO', accounts => { ); assert.equal( - (await I_CappedSTO_Array_POLY[0].getRaisedPOLY.call()) + (await I_CappedSTO_Array_POLY[0].getRaised.call(POLY)) .dividedBy(new BigNumber(10).pow(18)) .toNumber(), 10000 ); - assert.equal(await I_CappedSTO_Array_POLY[0].getNumberInvestors.call(), 2); + assert.equal(await I_CappedSTO_Array_POLY[0].investorCount.call(), 2); assert.equal( (await I_SecurityToken_POLY.balanceOf(account_investor2)) @@ -1108,7 +1111,7 @@ contract('CappedSTO', accounts => { it("Should fundRaised value equal to the raised value in the funds receiver wallet", async() => { const balanceRaised = await I_PolyToken.balanceOf.call(account_fundsReceiver); assert.equal( - (await I_CappedSTO_Array_POLY[0].getRaisedPOLY.call()).toNumber(), + (await I_CappedSTO_Array_POLY[0].getRaised.call(POLY)).toNumber(), balanceRaised, "Somewhere raised money get stolen or sent to wrong wallet" ); @@ -1245,15 +1248,15 @@ contract('CappedSTO', accounts => { }); it("Should get the raised amount of ether", async() => { - assert.equal(await I_CappedSTO_Array_POLY[0].getRaisedEther.call(), web3.utils.toWei('0','ether')); + assert.equal(await I_CappedSTO_Array_POLY[0].getRaised.call(ETH), web3.utils.toWei('0','ether')); }); it("Should get the raised amount of poly", async() => { - assert.equal((await I_CappedSTO_Array_POLY[0].getRaisedPOLY.call()).toNumber(), web3.utils.toWei('10000','ether')); + assert.equal((await I_CappedSTO_Array_POLY[0].getRaised.call(POLY)).toNumber(), web3.utils.toWei('10000','ether')); }); it("Should get the investors", async() => { - assert.equal(await I_CappedSTO_Array_POLY[0].getNumberInvestors.call(),2); + assert.equal(await I_CappedSTO_Array_POLY[0].investorCount.call(),2); }); it("Should get the listed permissions", async() => { @@ -1308,7 +1311,7 @@ contract('CappedSTO', accounts => { "STO Configuration doesn't set as expected" ); assert.equal( - await I_CappedSTO_Array_POLY[1].fundRaiseType.call(P_fundRaiseType), + await I_CappedSTO_Array_POLY[1].fundRaiseTypes.call(P_fundRaiseType), true, "STO Configuration doesn't set as expected" ); @@ -1347,13 +1350,13 @@ contract('CappedSTO', accounts => { ); assert.equal( - (await I_CappedSTO_Array_POLY[1].getRaisedPOLY.call()) + (await I_CappedSTO_Array_POLY[1].getRaised.call(POLY)) .dividedBy(new BigNumber(10).pow(18)) .toNumber(), polyToInvest ); - assert.equal(await I_CappedSTO_Array_POLY[1].getNumberInvestors.call(), 1); + assert.equal(await I_CappedSTO_Array_POLY[1].investorCount.call(), 1); assert.equal( (await I_SecurityToken_POLY.balanceOf(account_investor3)) diff --git a/test/m_presale_sto.js b/test/m_presale_sto.js index 9da7f2306..b1e003259 100644 --- a/test/m_presale_sto.js +++ b/test/m_presale_sto.js @@ -345,7 +345,7 @@ contract('PreSaleSTO', accounts => { await I_PreSaleSTO.allocateTokens(account_investor1, web3.utils.toWei('1', 'ether'), web3.utils.toWei('1', 'ether'), 0, {from: account_issuer, gas: 60000000}); assert.equal( - (await I_PreSaleSTO.getRaisedEther.call()) + (await I_PreSaleSTO.getRaised.call(0)) .dividedBy(new BigNumber(10).pow(18)) .toNumber(), 1 @@ -404,7 +404,7 @@ contract('PreSaleSTO', accounts => { await I_PreSaleSTO.allocateTokensMulti([account_investor2, account_investor3], [web3.utils.toWei('1', 'ether'), web3.utils.toWei('1', 'ether')], [0,0], [web3.utils.toWei('1000', 'ether'), web3.utils.toWei('1000', 'ether')], {from: account_issuer, gas: 60000000}); assert.equal( - (await I_PreSaleSTO.getRaisedPOLY.call()) + (await I_PreSaleSTO.getRaised.call(1)) .dividedBy(new BigNumber(10).pow(18)) .toNumber(), 2000 diff --git a/test/q_usd_tiered_sto_sim.js b/test/q_usd_tiered_sto_sim.js index d8db504d5..30774e26f 100644 --- a/test/q_usd_tiered_sto_sim.js +++ b/test/q_usd_tiered_sto_sim.js @@ -238,19 +238,19 @@ contract('USDTieredSTO', accounts => { // Step 9: Deploy the SecurityTokenRegistry I_SecurityTokenRegistry = await SecurityTokenRegistry.new({from: POLYMATH }); - + assert.notEqual( I_SecurityTokenRegistry.address.valueOf(), "0x0000000000000000000000000000000000000000", "SecurityTokenRegistry contract was not deployed", ); - + // Step 10: update the registries addresses from the PolymathRegistry contract I_SecurityTokenRegistryProxy = await SecurityTokenRegistryProxy.new({from: POLYMATH}); let bytesProxy = encodeProxyCall([I_PolymathRegistry.address, I_STFactory.address, REGFEE, REGFEE, I_PolyToken.address, POLYMATH]); await I_SecurityTokenRegistryProxy.upgradeToAndCall("1.0.0", I_SecurityTokenRegistry.address, bytesProxy, {from: POLYMATH}); I_STRProxied = await SecurityTokenRegistry.at(I_SecurityTokenRegistryProxy.address); - + // Step 10: Deploy the FeatureRegistry @@ -627,8 +627,8 @@ contract('USDTieredSTO', accounts => { let init_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let init_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); let init_RaisedUSD = await I_USDTieredSTO_Array[stoId].fundsRaisedUSD.call(); - let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(0); + let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(1); let init_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let init_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -653,8 +653,8 @@ contract('USDTieredSTO', accounts => { let final_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let final_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); let final_RaisedUSD = await I_USDTieredSTO_Array[stoId].fundsRaisedUSD.call(); - let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaisedETH.call(); - let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaisedPOLY.call(); + let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(0); + let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(1); let final_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let final_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); From 971e54a65f139746449cdf715cfcbef5a5fff1c4 Mon Sep 17 00:00:00 2001 From: Adam Dossa Date: Thu, 20 Sep 2018 08:20:41 +0100 Subject: [PATCH 04/12] More test fixes --- test/h_general_transfer_manager.js | 10 +++++----- test/i_Issuance.js | 10 +++++----- test/o_security_token.js | 4 ++-- test/r_concurrent_STO.js | 14 +++++++------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/test/h_general_transfer_manager.js b/test/h_general_transfer_manager.js index ee71123cb..da4b0ee44 100644 --- a/test/h_general_transfer_manager.js +++ b/test/h_general_transfer_manager.js @@ -207,8 +207,8 @@ contract('GeneralTransferManager', accounts => { I_SecurityTokenRegistryProxy = await SecurityTokenRegistryProxy.new({from: account_polymath}); let bytesProxy = encodeProxyCall([I_PolymathRegistry.address, I_STFactory.address, initRegFee, initRegFee, I_PolyToken.address, account_polymath]); await I_SecurityTokenRegistryProxy.upgradeToAndCall("1.0.0", I_SecurityTokenRegistry.address, bytesProxy, {from: account_polymath}); - I_STRProxied = await SecurityTokenRegistry.at(I_SecurityTokenRegistryProxy.address); - + I_STRProxied = await SecurityTokenRegistry.at(I_SecurityTokenRegistryProxy.address); + // Step 10: Deploy the FeatureRegistry I_FeatureRegistry = await FeatureRegistry.new( @@ -860,15 +860,15 @@ contract('GeneralTransferManager', accounts => { describe("Test cases for the get functions of the dummy sto", async() => { it("Should get the raised amount of ether", async() => { - assert.equal(await I_DummySTO.getRaisedEther.call(), web3.utils.toWei('0','ether')); + assert.equal(await I_DummySTO.getRaised.call(0), web3.utils.toWei('0','ether')); }); it("Should get the raised amount of poly", async() => { - assert.equal((await I_DummySTO.getRaisedPOLY.call()).toNumber(), web3.utils.toWei('0','ether')); + assert.equal((await I_DummySTO.getRaised.call(1)).toNumber(), web3.utils.toWei('0','ether')); }); it("Should get the investors", async() => { - assert.equal((await I_DummySTO.getNumberInvestors.call()).toNumber(), 2); + assert.equal((await I_DummySTO.investorCount.call()).toNumber(), 2); }); it("Should get the listed permissions", async() => { diff --git a/test/i_Issuance.js b/test/i_Issuance.js index a764fda97..f6f4cdeb7 100644 --- a/test/i_Issuance.js +++ b/test/i_Issuance.js @@ -209,7 +209,7 @@ contract('Issuance', accounts => { I_SecurityTokenRegistryProxy = await SecurityTokenRegistryProxy.new({from: account_polymath}); let bytesProxy = encodeProxyCall([I_PolymathRegistry.address, I_STFactory.address, initRegFee, initRegFee, I_PolyToken.address, account_polymath]); await I_SecurityTokenRegistryProxy.upgradeToAndCall("1.0.0", I_SecurityTokenRegistry.address, bytesProxy, {from: account_polymath}); - I_STRProxied = await SecurityTokenRegistry.at(I_SecurityTokenRegistryProxy.address); + I_STRProxied = await SecurityTokenRegistry.at(I_SecurityTokenRegistryProxy.address); // Step 10: Deploy the FeatureRegistry @@ -376,13 +376,13 @@ contract('Issuance', accounts => { }); assert.equal( - (await I_CappedSTO.getRaisedEther.call()) + (await I_CappedSTO.getRaised.call(0)) .dividedBy(new BigNumber(10).pow(18)) .toNumber(), 1 ); - assert.equal(await I_CappedSTO.getNumberInvestors.call(), 1); + assert.equal(await I_CappedSTO.investorCount.call(), 1); assert.equal( (await I_SecurityToken.balanceOf(account_investor1)) @@ -427,13 +427,13 @@ contract('Issuance', accounts => { }); assert.equal( - (await I_CappedSTO.getRaisedEther.call()) + (await I_CappedSTO.getRaised.call(0)) .dividedBy(new BigNumber(10).pow(18)) .toNumber(), 2 ); - assert.equal(await I_CappedSTO.getNumberInvestors.call(), 2); + assert.equal(await I_CappedSTO.investorCount.call(), 2); assert.equal( (await I_SecurityToken.balanceOf(account_investor2)) diff --git a/test/o_security_token.js b/test/o_security_token.js index 9f2dfd7e7..4450dd24d 100644 --- a/test/o_security_token.js +++ b/test/o_security_token.js @@ -1022,13 +1022,13 @@ contract('SecurityToken', accounts => { }); assert.equal( - (await I_CappedSTO.getRaisedEther.call()) + (await I_CappedSTO.getRaised.call(0)) .dividedBy(new BigNumber(10).pow(18)) .toNumber(), 2 ); - assert.equal(await I_CappedSTO.getNumberInvestors.call(), 2); + assert.equal(await I_CappedSTO.investorCount.call(), 2); assert.equal( (await I_SecurityToken.balanceOf(account_investor1)) diff --git a/test/r_concurrent_STO.js b/test/r_concurrent_STO.js index 635814623..612bb5b63 100644 --- a/test/r_concurrent_STO.js +++ b/test/r_concurrent_STO.js @@ -27,7 +27,7 @@ const Web3 = require('web3'); const BigNumber = require('bignumber.js'); const web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")) // Hardcoded development port -contract('SecurityToken addModule Cap', accounts => { +contract('Concurrent STO', accounts => { // Accounts variable declaration let account_polymath; let account_issuer; @@ -209,19 +209,19 @@ contract('SecurityToken addModule Cap', accounts => { // Step 9: Deploy the SecurityTokenRegistry I_SecurityTokenRegistry = await SecurityTokenRegistry.new({from: account_polymath }); - + assert.notEqual( I_SecurityTokenRegistry.address.valueOf(), "0x0000000000000000000000000000000000000000", "SecurityTokenRegistry contract was not deployed", ); - + // Step 10: update the registries addresses from the PolymathRegistry contract I_SecurityTokenRegistryProxy = await SecurityTokenRegistryProxy.new({from: account_polymath}); let bytesProxy = encodeProxyCall([I_PolymathRegistry.address, I_STFactory.address, initRegFee, initRegFee, I_PolyToken.address, account_polymath]); await I_SecurityTokenRegistryProxy.upgradeToAndCall("1.0.0", I_SecurityTokenRegistry.address, bytesProxy, {from: account_polymath}); I_STRProxied = await SecurityTokenRegistry.at(I_SecurityTokenRegistryProxy.address); - + // Step 10: Deploy the FeatureRegistry @@ -372,7 +372,7 @@ contract('SecurityToken addModule Cap', accounts => { case 0: // Capped STO ETH await I_STO_Array[STOIndex].buyTokens(account_investor1, { from : account_investor1, value: web3.utils.toWei('1', 'ether') }); - assert.equal(web3.utils.fromWei((await I_STO_Array[STOIndex].getRaisedEther.call()).toString()), 1); + assert.equal(web3.utils.fromWei((await I_STO_Array[STOIndex].getRaised.call(0)).toString()), 1); assert.equal(await I_STO_Array[STOIndex].getNumberInvestors.call(), 1); break; case 1: @@ -389,8 +389,8 @@ contract('SecurityToken addModule Cap', accounts => { case 2: // Pre Sale STO await I_STO_Array[STOIndex].allocateTokens(account_investor1, web3.utils.toWei('1000'), web3.utils.toWei('1'), 0, { from : account_issuer }); - assert.equal(web3.utils.fromWei((await I_STO_Array[STOIndex].getRaisedEther.call()).toString()), 1); - assert.equal(web3.utils.fromWei((await I_STO_Array[STOIndex].getRaisedPOLY.call()).toString()), 0); + assert.equal(web3.utils.fromWei((await I_STO_Array[STOIndex].getRaised.call(0)).toString()), 1); + assert.equal(web3.utils.fromWei((await I_STO_Array[STOIndex].getRaised.call(1)).toString()), 0); assert.equal(await I_STO_Array[STOIndex].getNumberInvestors.call(), 1); assert.equal( (await I_STO_Array[STOIndex].investors.call(account_investor1)) From dfc69add672f7fa68b048af3bc426ddbc535e060 Mon Sep 17 00:00:00 2001 From: Adam Dossa Date: Thu, 20 Sep 2018 09:30:24 +0100 Subject: [PATCH 05/12] Make usdToken configurable --- contracts/modules/STO/USDTieredSTO.sol | 50 +++---- test/p_usd_tiered_sto.js | 174 +++++++++++++++++++++++-- 2 files changed, 188 insertions(+), 36 deletions(-) diff --git a/contracts/modules/STO/USDTieredSTO.sol b/contracts/modules/STO/USDTieredSTO.sol index 147ff443a..5cfc387f5 100644 --- a/contracts/modules/STO/USDTieredSTO.sol +++ b/contracts/modules/STO/USDTieredSTO.sol @@ -22,7 +22,7 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { string public ETH_ORACLE = "EthUsdOracle"; mapping (bytes32 => mapping (bytes32 => string)) oracleKeys; - IERC20 public constant daiToken = IERC20(0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359); + IERC20 public usdToken; // Determine whether users can invest on behalf of a beneficiary bool public allowBeneficialInvestments = false; @@ -98,7 +98,8 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { event SetAddresses( address indexed _wallet, - address indexed _reserveWallet + address indexed _reserveWallet, + address indexed _usdToken ); event SetLimits( uint256 _nonAccreditedLimitUSD, @@ -167,14 +168,16 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { uint256 _nonAccreditedLimitUSD, uint256 _minimumInvestmentUSD, FundRaiseType[] _fundRaiseTypes, + address _usdToken, address _wallet, address _reserveWallet ) public onlyFactory { modifyTimes(_startTime, _endTime); - // NB - modifyFunding must come after modifyTiers + // NB - modifyTiers must come before modifyFunding modifyTiers(_ratePerTier, _ratePerTierDiscountPoly, _tokensPerTierTotal, _tokensPerTierDiscountPoly); + // NB - modifyFunding must come before modifyAddresses modifyFunding(_fundRaiseTypes); - modifyAddresses(_wallet, _reserveWallet); + modifyAddresses(_wallet, _reserveWallet, _usdToken); modifyLimits(_nonAccreditedLimitUSD, _minimumInvestmentUSD); } @@ -236,13 +239,18 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { function modifyAddresses( address _wallet, - address _reserveWallet + address _reserveWallet, + address _usdToken ) public onlyFactoryOrOwner { require(now < startTime); require(_wallet != address(0) && _reserveWallet != address(0), "0x address is not allowed"); + if (fundRaiseTypes[uint8(FundRaiseType.DAI)]) { + require(_usdToken != address(0), "0x usdToken address is not allowed"); + } wallet = _wallet; reserveWallet = _reserveWallet; - emit SetAddresses(_wallet, _reserveWallet); + usdToken = IERC20(_usdToken); + emit SetAddresses(_wallet, _reserveWallet, _usdToken); } //////////////////// @@ -345,14 +353,7 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { * @param _investedPOLY Amount of POLY invested */ function buyWithPOLY(address _beneficiary, uint256 _investedPOLY) public validPOLY { - uint256 rate = getRate(FundRaiseType.POLY); - (uint256 spentUSD, uint256 spentValue) = _buyTokens(_beneficiary, _investedPOLY, rate, FundRaiseType.POLY); - // Modify storage - investorInvested[_beneficiary][uint8(FundRaiseType.POLY)] = investorInvested[_beneficiary][uint8(FundRaiseType.POLY)].add(spentValue); - fundsRaised[uint8(FundRaiseType.POLY)] = fundsRaised[uint8(FundRaiseType.POLY)].add(spentValue); - // Forward POLY to issuer wallet - require(polyToken.transferFrom(msg.sender, wallet, spentValue)); - emit FundsReceived(msg.sender, _beneficiary, spentUSD, FundRaiseType.POLY, _investedPOLY, spentValue, rate); + _buyWithTokens(_beneficiary, _investedPOLY, FundRaiseType.POLY); } /** @@ -360,16 +361,21 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { * @param _beneficiary Address where security tokens will be sent * @param _investedDAI Amount of POLY invested */ - function buyWithDAI(address _beneficiary, uint256 _investedDAI) public validPOLY { - // Assume a conversion rate of 1 - 1 with USD - uint256 rate = getRate(FundRaiseType.DAI); - (uint256 spentUSD, uint256 spentValue) = _buyTokens(_beneficiary, _investedDAI, rate, FundRaiseType.DAI); + function buyWithUSD(address _beneficiary, uint256 _investedDAI) public validPOLY { + _buyWithTokens(_beneficiary, _investedDAI, FundRaiseType.DAI); + } + + function _buyWithTokens(address _beneficiary, uint256 _tokenAmount, FundRaiseType _fundRaiseType) internal { + require(_fundRaiseType == FundRaiseType.POLY || _fundRaiseType == FundRaiseType.DAI, "POLY & DAI supported"); + uint256 rate = getRate(_fundRaiseType); + (uint256 spentUSD, uint256 spentValue) = _buyTokens(_beneficiary, _tokenAmount, rate, _fundRaiseType); // Modify storage - investorInvested[_beneficiary][uint8(FundRaiseType.DAI)] = investorInvested[_beneficiary][uint8(FundRaiseType.DAI)].add(spentValue); - fundsRaised[uint8(FundRaiseType.DAI)] = fundsRaised[uint8(FundRaiseType.DAI)].add(spentValue); + investorInvested[_beneficiary][uint8(_fundRaiseType)] = investorInvested[_beneficiary][uint8(_fundRaiseType)].add(spentValue); + fundsRaised[uint8(_fundRaiseType)] = fundsRaised[uint8(_fundRaiseType)].add(spentValue); // Forward DAI to issuer wallet - require(daiToken.transferFrom(msg.sender, wallet, spentValue)); - emit FundsReceived(msg.sender, _beneficiary, spentUSD, FundRaiseType.DAI, _investedDAI, spentValue, rate); + IERC20 token = _fundRaiseType == FundRaiseType.POLY ? polyToken : usdToken; + require(token.transferFrom(msg.sender, wallet, spentValue)); + emit FundsReceived(msg.sender, _beneficiary, spentUSD, _fundRaiseType, _tokenAmount, spentValue, rate); } /** diff --git a/test/p_usd_tiered_sto.js b/test/p_usd_tiered_sto.js index 2247609d5..f85d079f8 100644 --- a/test/p_usd_tiered_sto.js +++ b/test/p_usd_tiered_sto.js @@ -61,6 +61,7 @@ contract('USDTieredSTO', accounts => { let I_STRProxied; let I_USDTieredSTO_Array = []; let I_PolyToken; + let I_DaiToken; let I_PolymathRegistry; // SecurityToken Details for funds raise Type ETH @@ -93,6 +94,7 @@ contract('USDTieredSTO', accounts => { let _fundRaiseTypess = []; let _wallet = []; let _reserveWallet = []; + let _usdToken = []; /* function configure( uint256 _startTime, @@ -105,7 +107,8 @@ contract('USDTieredSTO', accounts => { uint256 _minimumInvestmentUSD, uint8[] _fundRaiseTypess, address _wallet, - address _reserveWallet + address _reserveWallet, + address _usdToken ) */ const functionSignature = { name: 'configure', @@ -143,6 +146,9 @@ contract('USDTieredSTO', accounts => { },{ type: 'address', name: '_reserveWallet' + },{ + type: 'address', + name: '_usdToken' }] }; @@ -200,6 +206,7 @@ contract('USDTieredSTO', accounts => { // Step 1: Deploy the token Faucet I_PolyToken = await PolyTokenFaucet.new(); await I_PolymathRegistry.changeAddress("PolyToken", I_PolyToken.address, {from: POLYMATH}) + I_DaiToken = await PolyTokenFaucet.new(); // STEP 2: Deploy the ModuleRegistry I_ModuleRegistry = await ModuleRegistry.new(I_PolymathRegistry.address, {from:POLYMATH}); @@ -373,14 +380,15 @@ contract('USDTieredSTO', accounts => { _tokensPerTierDiscountPoly.push([BigNumber(0),BigNumber(0)]); // [ 0, 0 ] _nonAccreditedLimitUSD.push(BigNumber(10000).mul(BigNumber(10**18))); // 10k USD _minimumInvestmentUSD.push(BigNumber(5*10**18)); // 5 USD - _fundRaiseTypess.push([0, 1]); + _fundRaiseTypess.push([0, 1, 2]); _wallet.push(WALLET); _reserveWallet.push(RESERVEWALLET); + _usdToken.push(I_DaiToken.address); let config = [ _startTime[stoId], _endTime[stoId], _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], - _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId] + _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId], _usdToken[stoId] ]; let bytesSTO = web3.eth.abi.encodeFunctionCall(functionSignature, config); @@ -402,6 +410,7 @@ contract('USDTieredSTO', accounts => { assert.equal((await I_USDTieredSTO_Array[stoId].minimumInvestmentUSD.call()).toNumber(), _minimumInvestmentUSD[stoId].toNumber(), "Incorrect _minimumInvestmentUSD in config"); assert.equal((await I_USDTieredSTO_Array[stoId].wallet.call()), _wallet[stoId], "Incorrect _wallet in config"); assert.equal((await I_USDTieredSTO_Array[stoId].reserveWallet.call()), _reserveWallet[stoId], "Incorrect _reserveWallet in config"); + assert.equal((await I_USDTieredSTO_Array[stoId].usdToken.call()), _usdToken[stoId], "Incorrect _usdToken in config"); assert.equal((await I_USDTieredSTO_Array[stoId].getNumberOfTiers()), _tokensPerTierTotal[stoId].length, "Incorrect number of tiers"); assert.equal((await I_USDTieredSTO_Array[stoId].getPermissions()).length, 0, "Incorrect number of permissions"); }); @@ -420,11 +429,12 @@ contract('USDTieredSTO', accounts => { _fundRaiseTypess.push([0, 1]); _wallet.push(WALLET); _reserveWallet.push(RESERVEWALLET); + _usdToken.push(I_DaiToken.address); let config = [ _startTime[stoId], _endTime[stoId], _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], - _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId] + _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId], _usdToken[stoId] ]; let bytesSTO = web3.eth.abi.encodeFunctionCall(functionSignature, config); @@ -446,6 +456,7 @@ contract('USDTieredSTO', accounts => { assert.equal((await I_USDTieredSTO_Array[stoId].minimumInvestmentUSD.call()).toNumber(), _minimumInvestmentUSD[stoId].toNumber(), "Incorrect _minimumInvestmentUSD in config"); assert.equal((await I_USDTieredSTO_Array[stoId].wallet.call()), _wallet[stoId], "Incorrect _wallet in config"); assert.equal((await I_USDTieredSTO_Array[stoId].reserveWallet.call()), _reserveWallet[stoId], "Incorrect _reserveWallet in config"); + assert.equal((await I_USDTieredSTO_Array[stoId].usdToken.call()), _usdToken[stoId], "Incorrect _usdToken in config"); assert.equal(await I_USDTieredSTO_Array[stoId].getNumberOfTiers(), _tokensPerTierTotal[stoId].length, "Incorrect number of tiers"); assert.equal((await I_USDTieredSTO_Array[stoId].getPermissions()).length, 0, "Incorrect number of permissions"); }); @@ -464,11 +475,12 @@ contract('USDTieredSTO', accounts => { _fundRaiseTypess.push([0, 1]); _wallet.push(WALLET); _reserveWallet.push(RESERVEWALLET); + _usdToken.push(I_DaiToken.address) let config = [ _startTime[stoId], _endTime[stoId], _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], - _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId] + _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId], _usdToken[stoId] ]; let bytesSTO = web3.eth.abi.encodeFunctionCall(functionSignature, config); @@ -493,11 +505,12 @@ contract('USDTieredSTO', accounts => { _fundRaiseTypess.push([0, 1]); _wallet.push(WALLET); _reserveWallet.push(RESERVEWALLET); + _usdToken.push(I_DaiToken.address); let config = [ _startTime[stoId], _endTime[stoId], _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], - _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId] + _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId], _usdToken[stoId] ]; let bytesSTO = web3.eth.abi.encodeFunctionCall(functionSignature, config); @@ -516,10 +529,10 @@ contract('USDTieredSTO', accounts => { let tokensPerTierTotal = [10]; let tokensPerTierDiscountPoly = [10]; let config = [ - [_startTime[stoId], _endTime[stoId], ratePerTier, _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId]], - [_startTime[stoId], _endTime[stoId], _ratePerTier[stoId], ratePerTierDiscountPoly, _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId]], - [_startTime[stoId], _endTime[stoId], _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], tokensPerTierTotal, _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId]], - [_startTime[stoId], _endTime[stoId], _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], tokensPerTierDiscountPoly, _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId]] + [_startTime[stoId], _endTime[stoId], ratePerTier, _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId], _usdToken[stoId]], + [_startTime[stoId], _endTime[stoId], _ratePerTier[stoId], ratePerTierDiscountPoly, _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId], _usdToken[stoId]], + [_startTime[stoId], _endTime[stoId], _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], tokensPerTierTotal, _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId], _usdToken[stoId]], + [_startTime[stoId], _endTime[stoId], _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], tokensPerTierDiscountPoly, _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId], _usdToken[stoId]] ]; for (var i = 0; i < config.length; i++) { let bytesSTO = web3.eth.abi.encodeFunctionCall(functionSignature, config[i]); @@ -538,7 +551,7 @@ contract('USDTieredSTO', accounts => { let stoId = 0; let ratePerTier = [BigNumber(10*10**16), BigNumber(0)]; - let config = [_startTime[stoId], _endTime[stoId], ratePerTier, _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId]]; + let config = [_startTime[stoId], _endTime[stoId], ratePerTier, _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId], _usdToken[stoId]]; let bytesSTO = web3.eth.abi.encodeFunctionCall(functionSignature, config); let errorThrown = false; try { @@ -554,7 +567,7 @@ contract('USDTieredSTO', accounts => { let stoId = 0; let wallet = "0x0000000000000000000000000000000000000000"; - let config = [_startTime[stoId], _endTime[stoId], _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypess[stoId], wallet, _reserveWallet[stoId]]; + let config = [_startTime[stoId], _endTime[stoId], _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypess[stoId], wallet, _reserveWallet[stoId], _usdToken[stoId]]; let bytesSTO = web3.eth.abi.encodeFunctionCall(functionSignature, config); let errorThrown = false; try { @@ -587,7 +600,7 @@ contract('USDTieredSTO', accounts => { let startTime = latestTime() + duration.days(35); let endTime = latestTime() + duration.days(1); - let config = [startTime, endTime, _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId]]; + let config = [startTime, endTime, _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId], _usdToken[stoId]]; let bytesSTO = web3.eth.abi.encodeFunctionCall(functionSignature, config); let errorThrown = false; try { @@ -604,7 +617,7 @@ contract('USDTieredSTO', accounts => { let startTime = latestTime() - duration.days(35); let endTime = startTime + duration.days(50); - let config = [startTime, endTime, _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId]]; + let config = [startTime, endTime, _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId], _usdToken[stoId]]; let bytesSTO = web3.eth.abi.encodeFunctionCall(functionSignature, config); let errorThrown = false; try { @@ -749,6 +762,11 @@ contract('USDTieredSTO', accounts => { await I_PolyToken.approve(I_USDTieredSTO_Array[stoId].address, investment_POLY, {from: NONACCREDITED1}); await I_PolyToken.getTokens(investment_POLY, ACCREDITED1); await I_PolyToken.approve(I_USDTieredSTO_Array[stoId].address, investment_POLY, {from: ACCREDITED1}); + let investment_DAI = web3.utils.toWei('500', 'ether'); // Invest 10000 POLY + await I_DaiToken.getTokens(investment_DAI, NONACCREDITED1); + await I_DaiToken.approve(I_USDTieredSTO_Array[stoId].address, investment_DAI, {from: NONACCREDITED1}); + await I_DaiToken.getTokens(investment_DAI, ACCREDITED1); + await I_DaiToken.approve(I_USDTieredSTO_Array[stoId].address, investment_DAI, {from: ACCREDITED1}); // NONACCREDITED ETH let errorThrown1 = false; @@ -770,6 +788,16 @@ contract('USDTieredSTO', accounts => { } assert.ok(errorThrown2, 'NONACCREDITED POLY investment succeeded when it should not'); + // NONACCREDITED DAI + let errorThrown5 = false; + try { + await I_USDTieredSTO_Array[stoId].buyWithDAI(NONACCREDITED1, investment_DAI, {from: NONACCREDITED1}); + } catch(error) { + errorThrown5 = true; + ensureException(error); + } + assert.ok(errorThrown5, 'NONACCREDITED POLY investment succeeded when it should not'); + // ACCREDITED ETH let errorThrown3 = false; try { @@ -790,6 +818,16 @@ contract('USDTieredSTO', accounts => { } assert.ok(errorThrown4, 'ACCREDITED POLY investment succeeded when it should not'); + // ACCREDITED DAI + let errorThrown6 = false; + try { + await I_USDTieredSTO_Array[stoId].buyWithDAI(ACCREDITED1, investment_DAI, {from: ACCREDITED1}); + } catch(error) { + errorThrown6 = true; + ensureException(error); + } + assert.ok(errorThrown6, 'ACCREDITED POLY investment succeeded when it should not'); + await revertToSnapshot(snapId); }); @@ -819,6 +857,11 @@ contract('USDTieredSTO', accounts => { await I_PolyToken.approve(I_USDTieredSTO_Array[stoId].address, investment_POLY, {from: NONACCREDITED1}); await I_PolyToken.getTokens(investment_POLY, ACCREDITED1); await I_PolyToken.approve(I_USDTieredSTO_Array[stoId].address, investment_POLY, {from: ACCREDITED1}); + let investment_DAI = web3.utils.toWei('500', 'ether'); // Invest 10000 POLY + await I_DaiToken.getTokens(investment_DAI, NONACCREDITED1); + await I_DaiToken.approve(I_USDTieredSTO_Array[stoId].address, investment_DAI, {from: NONACCREDITED1}); + await I_DaiToken.getTokens(investment_DAI, ACCREDITED1); + await I_DaiToken.approve(I_USDTieredSTO_Array[stoId].address, investment_DAI, {from: ACCREDITED1}); // NONACCREDITED ETH let errorThrown1 = false; @@ -840,6 +883,16 @@ contract('USDTieredSTO', accounts => { } assert.ok(errorThrown2, 'NONACCREDITED POLY investment succeeded when it should not'); + // NONACCREDITED DAI + let errorThrown5 = false; + try { + await I_USDTieredSTO_Array[stoId].buyWithDAI(NONACCREDITED1, investment_DAI, {from: NONACCREDITED1}); + } catch(error) { + errorThrown5 = true; + ensureException(error); + } + assert.ok(errorThrown5, 'NONACCREDITED DAI investment succeeded when it should not'); + // ACCREDITED ETH let errorThrown3 = false; try { @@ -860,6 +913,16 @@ contract('USDTieredSTO', accounts => { } assert.ok(errorThrown4, 'ACCREDITED POLY investment succeeded when it should not'); + // ACCREDITED DAI + let errorThrown6 = false; + try { + await I_USDTieredSTO_Array[stoId].buyWithDAI(ACCREDITED1, investment_DAI, {from: ACCREDITED1}); + } catch(error) { + errorThrown6 = true; + ensureException(error); + } + assert.ok(errorThrown6, 'ACCREDITED DAI investment succeeded when it should not'); + await revertToSnapshot(snapId); }); @@ -886,12 +949,19 @@ contract('USDTieredSTO', accounts => { let investment_USD = BigNumber(2).mul(10**18); let investment_ETH = await convert(stoId, tierId, false, "USD", "ETH", investment_USD); let investment_POLY = await convert(stoId, tierId, false, "USD", "POLY", investment_USD); + let investment_DAI = investment_USD; await I_PolyToken.getTokens(investment_POLY, NONACCREDITED1); await I_PolyToken.approve(I_USDTieredSTO_Array[stoId].address, investment_POLY, {from: NONACCREDITED1}); await I_PolyToken.getTokens(investment_POLY, ACCREDITED1); await I_PolyToken.approve(I_USDTieredSTO_Array[stoId].address, investment_POLY, {from: ACCREDITED1}); + + await I_DaiToken.getTokens(investment_DAI, NONACCREDITED1); + await I_DaiToken.approve(I_USDTieredSTO_Array[stoId].address, investment_DAI, {from: NONACCREDITED1}); + await I_DaiToken.getTokens(investment_DAI, ACCREDITED1); + await I_DaiToken.approve(I_USDTieredSTO_Array[stoId].address, investment_DAI, {from: ACCREDITED1}); + // NONACCREDITED ETH let errorThrown1 = false; try { @@ -912,6 +982,16 @@ contract('USDTieredSTO', accounts => { } assert.ok(errorThrown2, 'NONACCREDITED POLY investment succeeded when it should not'); + // NONACCREDITED DAI + let errorThrown5 = false; + try { + await I_USDTieredSTO_Array[stoId].buyWithDAI(NONACCREDITED1, investment_DAI, {from: NONACCREDITED1}); + } catch(error) { + errorThrown5 = true; + ensureException(error); + } + assert.ok(errorThrown5, 'NONACCREDITED DAI investment succeeded when it should not'); + // ACCREDITED ETH let errorThrown3 = false; try { @@ -932,6 +1012,16 @@ contract('USDTieredSTO', accounts => { } assert.ok(errorThrown4, 'ACCREDITED POLY investment succeeded when it should not'); + // ACCREDITED DAI + let errorThrown6 = false; + try { + await I_USDTieredSTO_Array[stoId].buyWithDAI(ACCREDITED1, investment_DAI, {from: ACCREDITED1}); + } catch(error) { + errorThrown6 = true; + ensureException(error); + } + assert.ok(errorThrown6, 'ACCREDITED DAI investment succeeded when it should not'); + await revertToSnapshot(snapId); }); @@ -966,6 +1056,12 @@ contract('USDTieredSTO', accounts => { await I_PolyToken.getTokens(investment_POLY, ACCREDITED1); await I_PolyToken.approve(I_USDTieredSTO_Array[stoId].address, investment_POLY, {from: ACCREDITED1}); + let investment_DAI = web3.utils.toWei('500', 'ether'); // Invest 10000 POLY + await I_DaiToken.getTokens(investment_DAI, NONACCREDITED1); + await I_DaiToken.approve(I_USDTieredSTO_Array[stoId].address, investment_DAI, {from: NONACCREDITED1}); + await I_DaiToken.getTokens(investment_DAI, ACCREDITED1); + await I_DaiToken.approve(I_USDTieredSTO_Array[stoId].address, investment_DAI, {from: ACCREDITED1}); + // NONACCREDITED ETH let errorThrown1 = false; try { @@ -986,6 +1082,16 @@ contract('USDTieredSTO', accounts => { } assert.ok(errorThrown2, 'NONACCREDITED POLY investment succeeded when it should not'); + // NONACCREDITED DAI + let errorThrown5 = false; + try { + await I_USDTieredSTO_Array[stoId].buyWithDAI(NONACCREDITED1, investment_DAI, {from: NONACCREDITED1}); + } catch(error) { + errorThrown5 = true; + ensureException(error); + } + assert.ok(errorThrown5, 'NONACCREDITED DAI investment succeeded when it should not'); + // ACCREDITED ETH let errorThrown3 = false; try { @@ -1006,14 +1112,28 @@ contract('USDTieredSTO', accounts => { } assert.ok(errorThrown4, 'ACCREDITED POLY investment succeeded when it should not'); + + // ACCREDITED DAI + let errorThrown6 = false; + try { + await I_USDTieredSTO_Array[stoId].buyWithDAI(ACCREDITED1, investment_DAI, {from: ACCREDITED1}); + } catch(error) { + errorThrown6 = true; + ensureException(error); + } + assert.ok(errorThrown6, 'ACCREDITED DAI investment succeeded when it should not'); + // Unpause the STO await I_USDTieredSTO_Array[stoId].unpause({ from: ISSUER }); assert.equal(await I_USDTieredSTO_Array[stoId].paused.call(), false, 'STO did not unpause successfully'); await I_USDTieredSTO_Array[stoId].buyWithETH(NONACCREDITED1, { from: NONACCREDITED1, value: investment_ETH }); await I_USDTieredSTO_Array[stoId].buyWithPOLY(NONACCREDITED1, investment_POLY, {from: NONACCREDITED1}); + await I_USDTieredSTO_Array[stoId].buyWithDAI(NONACCREDITED1, investment_DAI, {from: NONACCREDITED1}); + await I_USDTieredSTO_Array[stoId].buyWithETH(ACCREDITED1, { from: ACCREDITED1, value: investment_ETH }); await I_USDTieredSTO_Array[stoId].buyWithPOLY(ACCREDITED1, investment_POLY, {from: ACCREDITED1}); + await I_USDTieredSTO_Array[stoId].buyWithDAI(ACCREDITED1, investment_DAI, {from: ACCREDITED1}); await revertToSnapshot(snapId); }); @@ -1046,6 +1166,12 @@ contract('USDTieredSTO', accounts => { await I_PolyToken.approve(I_USDTieredSTO_Array[stoId].address, investment_POLY, {from: NONACCREDITED1}); await I_PolyToken.getTokens(investment_POLY, ACCREDITED1); await I_PolyToken.approve(I_USDTieredSTO_Array[stoId].address, investment_POLY, {from: ACCREDITED1}); + let investment_DAI = web3.utils.toWei('500', 'ether'); // Invest 10000 POLY + await I_DaiToken.getTokens(investment_DAI, NONACCREDITED1); + await I_DaiToken.approve(I_USDTieredSTO_Array[stoId].address, investment_DAI, {from: NONACCREDITED1}); + await I_DaiToken.getTokens(investment_DAI, ACCREDITED1); + await I_DaiToken.approve(I_USDTieredSTO_Array[stoId].address, investment_DAI, {from: ACCREDITED1}); + // NONACCREDITED ETH let errorThrown1 = false; @@ -1067,6 +1193,16 @@ contract('USDTieredSTO', accounts => { } assert.ok(errorThrown2, 'NONACCREDITED POLY investment succeeded when it should not'); + // NONACCREDITED DAI + let errorThrown5 = false; + try { + await I_USDTieredSTO_Array[stoId].buyWithDAI(NONACCREDITED1, investment_DAI, {from: NONACCREDITED1}); + } catch(error) { + errorThrown5 = true; + ensureException(error); + } + assert.ok(errorThrown5, 'NONACCREDITED DAI investment succeeded when it should not'); + // ACCREDITED ETH let errorThrown3 = false; try { @@ -1087,6 +1223,16 @@ contract('USDTieredSTO', accounts => { } assert.ok(errorThrown4, 'ACCREDITED POLY investment succeeded when it should not'); + // ACCREDITED POLY + let errorThrown6 = false; + try { + await I_USDTieredSTO_Array[stoId].buyWithDAI(ACCREDITED1, investment_DAI, {from: ACCREDITED1}); + } catch(error) { + errorThrown6 = true; + ensureException(error); + } + assert.ok(errorThrown6, 'ACCREDITED DAI investment succeeded when it should not'); + await revertToSnapshot(snapId); }); From 956e4f166aaa1260c602ec75085a2203015c02aa Mon Sep 17 00:00:00 2001 From: Adam Dossa Date: Thu, 20 Sep 2018 09:41:55 +0100 Subject: [PATCH 06/12] Update tests --- contracts/modules/STO/USDTieredSTO.sol | 8 +++---- test/p_usd_tiered_sto.js | 29 +++++++++++++------------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/contracts/modules/STO/USDTieredSTO.sol b/contracts/modules/STO/USDTieredSTO.sol index 5cfc387f5..a72cc6480 100644 --- a/contracts/modules/STO/USDTieredSTO.sol +++ b/contracts/modules/STO/USDTieredSTO.sol @@ -168,9 +168,9 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { uint256 _nonAccreditedLimitUSD, uint256 _minimumInvestmentUSD, FundRaiseType[] _fundRaiseTypes, - address _usdToken, address _wallet, - address _reserveWallet + address _reserveWallet, + address _usdToken ) public onlyFactory { modifyTimes(_startTime, _endTime); // NB - modifyTiers must come before modifyFunding @@ -608,9 +608,7 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { * @return bytes4 Configure function signature */ function getInitFunction() public pure returns (bytes4) { - //keccak256("configure(uint256,uint256,uint256[],uint256[],uint256[],uint256[],uint256,uint256,uint8[],address,address)") == - //0xd31d4f2d09fc7bdefd7ea179aebde3dd53e24265c3c63e17e399bbf85fe873bf - return 0xd31d4f2d; + return 0xb0ff041e; } function _getOracle(bytes32 _currency, bytes32 _denominatedCurrency) internal view returns (address) { diff --git a/test/p_usd_tiered_sto.js b/test/p_usd_tiered_sto.js index f85d079f8..07793200d 100644 --- a/test/p_usd_tiered_sto.js +++ b/test/p_usd_tiered_sto.js @@ -669,9 +669,10 @@ contract('USDTieredSTO', accounts => { assert.equal(await I_USDTieredSTO_Array[stoId].startTime.call(),tempTime1,"STO Configuration doesn't set as expected"); assert.equal(await I_USDTieredSTO_Array[stoId].endTime.call(),tempTime2,"STO Configuration doesn't set as expected"); - await I_USDTieredSTO_Array[stoId].modifyAddresses("0x0000000000000000000000000400000000000000", "0x0000000000000000000003000000000000000000", { from: ISSUER }); + await I_USDTieredSTO_Array[stoId].modifyAddresses("0x0000000000000000000000000400000000000000", "0x0000000000000000000003000000000000000000", "0x0000000000000000000000000000000000000000", { from: ISSUER }); assert.equal(await I_USDTieredSTO_Array[stoId].wallet.call(),"0x0000000000000000000000000400000000000000","STO Configuration doesn't set as expected"); assert.equal(await I_USDTieredSTO_Array[stoId].reserveWallet.call(),"0x0000000000000000000003000000000000000000","STO Configuration doesn't set as expected"); + assert.equal(await I_USDTieredSTO_Array[stoId].usdToken.call(),"0x0000000000000000000000000000000000000000","STO Configuration doesn't set as expected"); }); it("Should fail to change config after endTime", async() => { @@ -721,7 +722,7 @@ contract('USDTieredSTO', accounts => { let errorThrown5 = false; try { - await I_USDTieredSTO_Array[stoId].modifyAddresses("0x0000000000000000000000000400000000000000", "0x0000000000000000000003000000000000000000", { from: ISSUER }); + await I_USDTieredSTO_Array[stoId].modifyAddresses("0x0000000000000000000000000400000000000000", "0x0000000000000000000003000000000000000000", I_DaiToken.address, { from: ISSUER }); } catch(error) { errorThrown5 = true; ensureException(error); @@ -791,7 +792,7 @@ contract('USDTieredSTO', accounts => { // NONACCREDITED DAI let errorThrown5 = false; try { - await I_USDTieredSTO_Array[stoId].buyWithDAI(NONACCREDITED1, investment_DAI, {from: NONACCREDITED1}); + await I_USDTieredSTO_Array[stoId].buyWithUSD(NONACCREDITED1, investment_DAI, {from: NONACCREDITED1}); } catch(error) { errorThrown5 = true; ensureException(error); @@ -821,7 +822,7 @@ contract('USDTieredSTO', accounts => { // ACCREDITED DAI let errorThrown6 = false; try { - await I_USDTieredSTO_Array[stoId].buyWithDAI(ACCREDITED1, investment_DAI, {from: ACCREDITED1}); + await I_USDTieredSTO_Array[stoId].buyWithUSD(ACCREDITED1, investment_DAI, {from: ACCREDITED1}); } catch(error) { errorThrown6 = true; ensureException(error); @@ -886,7 +887,7 @@ contract('USDTieredSTO', accounts => { // NONACCREDITED DAI let errorThrown5 = false; try { - await I_USDTieredSTO_Array[stoId].buyWithDAI(NONACCREDITED1, investment_DAI, {from: NONACCREDITED1}); + await I_USDTieredSTO_Array[stoId].buyWithUSD(NONACCREDITED1, investment_DAI, {from: NONACCREDITED1}); } catch(error) { errorThrown5 = true; ensureException(error); @@ -916,7 +917,7 @@ contract('USDTieredSTO', accounts => { // ACCREDITED DAI let errorThrown6 = false; try { - await I_USDTieredSTO_Array[stoId].buyWithDAI(ACCREDITED1, investment_DAI, {from: ACCREDITED1}); + await I_USDTieredSTO_Array[stoId].buyWithUSD(ACCREDITED1, investment_DAI, {from: ACCREDITED1}); } catch(error) { errorThrown6 = true; ensureException(error); @@ -985,7 +986,7 @@ contract('USDTieredSTO', accounts => { // NONACCREDITED DAI let errorThrown5 = false; try { - await I_USDTieredSTO_Array[stoId].buyWithDAI(NONACCREDITED1, investment_DAI, {from: NONACCREDITED1}); + await I_USDTieredSTO_Array[stoId].buyWithUSD(NONACCREDITED1, investment_DAI, {from: NONACCREDITED1}); } catch(error) { errorThrown5 = true; ensureException(error); @@ -1015,7 +1016,7 @@ contract('USDTieredSTO', accounts => { // ACCREDITED DAI let errorThrown6 = false; try { - await I_USDTieredSTO_Array[stoId].buyWithDAI(ACCREDITED1, investment_DAI, {from: ACCREDITED1}); + await I_USDTieredSTO_Array[stoId].buyWithUSD(ACCREDITED1, investment_DAI, {from: ACCREDITED1}); } catch(error) { errorThrown6 = true; ensureException(error); @@ -1085,7 +1086,7 @@ contract('USDTieredSTO', accounts => { // NONACCREDITED DAI let errorThrown5 = false; try { - await I_USDTieredSTO_Array[stoId].buyWithDAI(NONACCREDITED1, investment_DAI, {from: NONACCREDITED1}); + await I_USDTieredSTO_Array[stoId].buyWithUSD(NONACCREDITED1, investment_DAI, {from: NONACCREDITED1}); } catch(error) { errorThrown5 = true; ensureException(error); @@ -1116,7 +1117,7 @@ contract('USDTieredSTO', accounts => { // ACCREDITED DAI let errorThrown6 = false; try { - await I_USDTieredSTO_Array[stoId].buyWithDAI(ACCREDITED1, investment_DAI, {from: ACCREDITED1}); + await I_USDTieredSTO_Array[stoId].buyWithUSD(ACCREDITED1, investment_DAI, {from: ACCREDITED1}); } catch(error) { errorThrown6 = true; ensureException(error); @@ -1129,11 +1130,11 @@ contract('USDTieredSTO', accounts => { await I_USDTieredSTO_Array[stoId].buyWithETH(NONACCREDITED1, { from: NONACCREDITED1, value: investment_ETH }); await I_USDTieredSTO_Array[stoId].buyWithPOLY(NONACCREDITED1, investment_POLY, {from: NONACCREDITED1}); - await I_USDTieredSTO_Array[stoId].buyWithDAI(NONACCREDITED1, investment_DAI, {from: NONACCREDITED1}); + await I_USDTieredSTO_Array[stoId].buyWithUSD(NONACCREDITED1, investment_DAI, {from: NONACCREDITED1}); await I_USDTieredSTO_Array[stoId].buyWithETH(ACCREDITED1, { from: ACCREDITED1, value: investment_ETH }); await I_USDTieredSTO_Array[stoId].buyWithPOLY(ACCREDITED1, investment_POLY, {from: ACCREDITED1}); - await I_USDTieredSTO_Array[stoId].buyWithDAI(ACCREDITED1, investment_DAI, {from: ACCREDITED1}); + await I_USDTieredSTO_Array[stoId].buyWithUSD(ACCREDITED1, investment_DAI, {from: ACCREDITED1}); await revertToSnapshot(snapId); }); @@ -1196,7 +1197,7 @@ contract('USDTieredSTO', accounts => { // NONACCREDITED DAI let errorThrown5 = false; try { - await I_USDTieredSTO_Array[stoId].buyWithDAI(NONACCREDITED1, investment_DAI, {from: NONACCREDITED1}); + await I_USDTieredSTO_Array[stoId].buyWithUSD(NONACCREDITED1, investment_DAI, {from: NONACCREDITED1}); } catch(error) { errorThrown5 = true; ensureException(error); @@ -1226,7 +1227,7 @@ contract('USDTieredSTO', accounts => { // ACCREDITED POLY let errorThrown6 = false; try { - await I_USDTieredSTO_Array[stoId].buyWithDAI(ACCREDITED1, investment_DAI, {from: ACCREDITED1}); + await I_USDTieredSTO_Array[stoId].buyWithUSD(ACCREDITED1, investment_DAI, {from: ACCREDITED1}); } catch(error) { errorThrown6 = true; ensureException(error); From 23af0392254620af85bcacee70721dbe8623fa99 Mon Sep 17 00:00:00 2001 From: Adam Dossa Date: Thu, 20 Sep 2018 11:28:12 +0100 Subject: [PATCH 07/12] More test fixes --- test/o_security_token.js | 2 +- test/q_usd_tiered_sto_sim.js | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/test/o_security_token.js b/test/o_security_token.js index 4450dd24d..bee3242dd 100644 --- a/test/o_security_token.js +++ b/test/o_security_token.js @@ -780,7 +780,7 @@ contract('SecurityToken', accounts => { }); assert.equal( - (await I_CappedSTO.getRaisedEther.call()) + (await I_CappedSTO.getRaised.call(0)) .dividedBy(new BigNumber(10).pow(18)) .toNumber(), 1 diff --git a/test/q_usd_tiered_sto_sim.js b/test/q_usd_tiered_sto_sim.js index 30774e26f..c8b6ac17c 100644 --- a/test/q_usd_tiered_sto_sim.js +++ b/test/q_usd_tiered_sto_sim.js @@ -25,7 +25,7 @@ const web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")); const TOLERANCE = 2; // Allow balances to be off by 2 WEI for rounding purposes -contract('USDTieredSTO', accounts => { +contract('USDTieredSTO Sim', accounts => { // Accounts Variable declaration let POLYMATH; let ISSUER; @@ -59,6 +59,7 @@ contract('USDTieredSTO', accounts => { let I_SecurityToken; let I_USDTieredSTO_Array = []; let I_PolyToken; + let I_DaiToken; let I_PolymathRegistry; // SecurityToken Details for funds raise Type ETH @@ -91,6 +92,7 @@ contract('USDTieredSTO', accounts => { let _fundRaiseTypes = []; let _wallet = []; let _reserveWallet = []; + let _usdToken = []; /* function configure( uint256 _startTime, @@ -103,7 +105,8 @@ contract('USDTieredSTO', accounts => { uint256 _minimumInvestmentUSD, uint8[] _fundRaiseTypes, address _wallet, - address _reserveWallet + address _reserveWallet, + address _usdToken ) */ const functionSignature = { name: 'configure', @@ -141,6 +144,9 @@ contract('USDTieredSTO', accounts => { },{ type: 'address', name: '_reserveWallet' + },{ + type: 'address', + name: '_usdToken' }] }; @@ -170,6 +176,7 @@ contract('USDTieredSTO', accounts => { // Step 1: Deploy the token Faucet I_PolyToken = await PolyTokenFaucet.new(); await I_PolymathRegistry.changeAddress("PolyToken", I_PolyToken.address, {from: POLYMATH}) + I_DaiToken = await PolyTokenFaucet.new(); // STEP 2: Deploy the ModuleRegistry I_ModuleRegistry = await ModuleRegistry.new(I_PolymathRegistry.address, {from:POLYMATH}); @@ -351,11 +358,12 @@ contract('USDTieredSTO', accounts => { _fundRaiseTypes.push([0,1]); _wallet.push(WALLET); _reserveWallet.push(RESERVEWALLET); + _usdToken.push(I_DaiToken.address); let config = [ _startTime[stoId], _endTime[stoId], _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], - _fundRaiseTypes[stoId], _wallet[stoId], _reserveWallet[stoId] + _fundRaiseTypes[stoId], _wallet[stoId], _reserveWallet[stoId], _usdToken[stoId] ]; let bytesSTO = web3.eth.abi.encodeFunctionCall(functionSignature, config); From 660997aaae3cc4f8b57a2ce7acebe3156730691e Mon Sep 17 00:00:00 2001 From: Adam Dossa Date: Thu, 20 Sep 2018 12:33:18 +0100 Subject: [PATCH 08/12] More cleanups --- contracts/modules/STO/USDTieredSTO.sol | 6 +- test/o_security_token.js | 2 +- test/p_usd_tiered_sto.js | 237 ++++++++++++++++++++++--- test/q_usd_tiered_sto_sim.js | 11 +- test/r_concurrent_STO.js | 6 +- test/s_v130_to_v140_upgrade.js | 8 +- 6 files changed, 237 insertions(+), 33 deletions(-) diff --git a/contracts/modules/STO/USDTieredSTO.sol b/contracts/modules/STO/USDTieredSTO.sol index a72cc6480..f54f793cc 100644 --- a/contracts/modules/STO/USDTieredSTO.sol +++ b/contracts/modules/STO/USDTieredSTO.sol @@ -127,7 +127,7 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { } modifier validPOLY { - require(_getOracle(bytes32("POLY"), bytes32("USD")) != address(0), "Invalid ETHUSD Oracle"); + require(_getOracle(bytes32("POLY"), bytes32("USD")) != address(0), "Invalid POLYUSD Oracle"); require(fundRaiseTypes[uint8(FundRaiseType.POLY)]); _; } @@ -361,7 +361,7 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { * @param _beneficiary Address where security tokens will be sent * @param _investedDAI Amount of POLY invested */ - function buyWithUSD(address _beneficiary, uint256 _investedDAI) public validPOLY { + function buyWithUSD(address _beneficiary, uint256 _investedDAI) public validDAI { _buyWithTokens(_beneficiary, _investedDAI, FundRaiseType.DAI); } @@ -427,7 +427,7 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { fundsRaisedUSD = fundsRaisedUSD.add(spentUSD); } - // Calculate spent in base currency (ETH or POLY) + // Calculate spent in base currency (ETH, DAI or POLY) uint256 spentValue; if (spentUSD == 0) { spentValue = 0; diff --git a/test/o_security_token.js b/test/o_security_token.js index bee3242dd..ce24a9be0 100644 --- a/test/o_security_token.js +++ b/test/o_security_token.js @@ -786,7 +786,7 @@ contract('SecurityToken', accounts => { 1 ); - assert.equal(await I_CappedSTO.getNumberInvestors.call(), 1); + assert.equal(await I_CappedSTO.investorCount.call(), 1); assert.equal( (await I_SecurityToken.balanceOf(account_investor1)) diff --git a/test/p_usd_tiered_sto.js b/test/p_usd_tiered_sto.js index 07793200d..835aedebd 100644 --- a/test/p_usd_tiered_sto.js +++ b/test/p_usd_tiered_sto.js @@ -1,4 +1,4 @@ -import latestTime from './helpers/latestTime'; + import latestTime from './helpers/latestTime'; import { duration, ensureException, promisifyLogWatch, latestBlock } from './helpers/utils'; import { takeSnapshot, increaseTime, revertToSnapshot } from './helpers/time'; import { encodeProxyCall } from './helpers/encodeCall'; @@ -91,7 +91,7 @@ contract('USDTieredSTO', accounts => { let _tokensPerTierDiscountPoly = []; let _nonAccreditedLimitUSD = []; let _minimumInvestmentUSD = []; - let _fundRaiseTypess = []; + let _fundRaiseTypes = []; let _wallet = []; let _reserveWallet = []; let _usdToken = []; @@ -105,7 +105,7 @@ contract('USDTieredSTO', accounts => { uint256[] _tokensPerTierDiscountPoly, uint256 _nonAccreditedLimitUSD, uint256 _minimumInvestmentUSD, - uint8[] _fundRaiseTypess, + uint8[] _fundRaiseTypes, address _wallet, address _reserveWallet, address _usdToken @@ -139,7 +139,7 @@ contract('USDTieredSTO', accounts => { name: '_minimumInvestmentUSD' },{ type: 'uint8[]', - name: '_fundRaiseTypess' + name: '_fundRaiseTypes' },{ type: 'address', name: '_wallet' @@ -380,7 +380,7 @@ contract('USDTieredSTO', accounts => { _tokensPerTierDiscountPoly.push([BigNumber(0),BigNumber(0)]); // [ 0, 0 ] _nonAccreditedLimitUSD.push(BigNumber(10000).mul(BigNumber(10**18))); // 10k USD _minimumInvestmentUSD.push(BigNumber(5*10**18)); // 5 USD - _fundRaiseTypess.push([0, 1, 2]); + _fundRaiseTypes.push([0, 1, 2]); _wallet.push(WALLET); _reserveWallet.push(RESERVEWALLET); _usdToken.push(I_DaiToken.address); @@ -388,7 +388,7 @@ contract('USDTieredSTO', accounts => { let config = [ _startTime[stoId], _endTime[stoId], _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], - _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId], _usdToken[stoId] + _fundRaiseTypes[stoId], _wallet[stoId], _reserveWallet[stoId], _usdToken[stoId] ]; let bytesSTO = web3.eth.abi.encodeFunctionCall(functionSignature, config); @@ -426,7 +426,7 @@ contract('USDTieredSTO', accounts => { _tokensPerTierDiscountPoly.push([BigNumber(0), BigNumber(0), BigNumber(0), BigNumber(0), BigNumber(0)]); _nonAccreditedLimitUSD.push(BigNumber(10000).mul(BigNumber(10**18))); _minimumInvestmentUSD.push(BigNumber(0)); - _fundRaiseTypess.push([0, 1]); + _fundRaiseTypes.push([0, 1]); _wallet.push(WALLET); _reserveWallet.push(RESERVEWALLET); _usdToken.push(I_DaiToken.address); @@ -434,7 +434,7 @@ contract('USDTieredSTO', accounts => { let config = [ _startTime[stoId], _endTime[stoId], _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], - _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId], _usdToken[stoId] + _fundRaiseTypes[stoId], _wallet[stoId], _reserveWallet[stoId], _usdToken[stoId] ]; let bytesSTO = web3.eth.abi.encodeFunctionCall(functionSignature, config); @@ -472,7 +472,7 @@ contract('USDTieredSTO', accounts => { _tokensPerTierDiscountPoly.push([BigNumber(100*10**18),BigNumber(25*10**18)]); // [ 100 Token, 25 Token ] _nonAccreditedLimitUSD.push(BigNumber(25*10**18)); // [ 25 USD ] _minimumInvestmentUSD.push(BigNumber(5)); - _fundRaiseTypess.push([0, 1]); + _fundRaiseTypes.push([0, 1]); _wallet.push(WALLET); _reserveWallet.push(RESERVEWALLET); _usdToken.push(I_DaiToken.address) @@ -480,7 +480,7 @@ contract('USDTieredSTO', accounts => { let config = [ _startTime[stoId], _endTime[stoId], _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], - _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId], _usdToken[stoId] + _fundRaiseTypes[stoId], _wallet[stoId], _reserveWallet[stoId], _usdToken[stoId] ]; let bytesSTO = web3.eth.abi.encodeFunctionCall(functionSignature, config); @@ -502,7 +502,7 @@ contract('USDTieredSTO', accounts => { _tokensPerTierDiscountPoly.push([BigNumber(0),BigNumber(50*10**18)]); _nonAccreditedLimitUSD.push(BigNumber(10000).mul(BigNumber(10**18))); _minimumInvestmentUSD.push(BigNumber(0)); - _fundRaiseTypess.push([0, 1]); + _fundRaiseTypes.push([0, 1]); _wallet.push(WALLET); _reserveWallet.push(RESERVEWALLET); _usdToken.push(I_DaiToken.address); @@ -510,7 +510,7 @@ contract('USDTieredSTO', accounts => { let config = [ _startTime[stoId], _endTime[stoId], _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], - _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId], _usdToken[stoId] + _fundRaiseTypes[stoId], _wallet[stoId], _reserveWallet[stoId], _usdToken[stoId] ]; let bytesSTO = web3.eth.abi.encodeFunctionCall(functionSignature, config); @@ -529,10 +529,10 @@ contract('USDTieredSTO', accounts => { let tokensPerTierTotal = [10]; let tokensPerTierDiscountPoly = [10]; let config = [ - [_startTime[stoId], _endTime[stoId], ratePerTier, _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId], _usdToken[stoId]], - [_startTime[stoId], _endTime[stoId], _ratePerTier[stoId], ratePerTierDiscountPoly, _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId], _usdToken[stoId]], - [_startTime[stoId], _endTime[stoId], _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], tokensPerTierTotal, _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId], _usdToken[stoId]], - [_startTime[stoId], _endTime[stoId], _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], tokensPerTierDiscountPoly, _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId], _usdToken[stoId]] + [_startTime[stoId], _endTime[stoId], ratePerTier, _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypes[stoId], _wallet[stoId], _reserveWallet[stoId], _usdToken[stoId]], + [_startTime[stoId], _endTime[stoId], _ratePerTier[stoId], ratePerTierDiscountPoly, _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypes[stoId], _wallet[stoId], _reserveWallet[stoId], _usdToken[stoId]], + [_startTime[stoId], _endTime[stoId], _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], tokensPerTierTotal, _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypes[stoId], _wallet[stoId], _reserveWallet[stoId], _usdToken[stoId]], + [_startTime[stoId], _endTime[stoId], _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], tokensPerTierDiscountPoly, _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypes[stoId], _wallet[stoId], _reserveWallet[stoId], _usdToken[stoId]] ]; for (var i = 0; i < config.length; i++) { let bytesSTO = web3.eth.abi.encodeFunctionCall(functionSignature, config[i]); @@ -551,7 +551,7 @@ contract('USDTieredSTO', accounts => { let stoId = 0; let ratePerTier = [BigNumber(10*10**16), BigNumber(0)]; - let config = [_startTime[stoId], _endTime[stoId], ratePerTier, _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId], _usdToken[stoId]]; + let config = [_startTime[stoId], _endTime[stoId], ratePerTier, _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypes[stoId], _wallet[stoId], _reserveWallet[stoId], _usdToken[stoId]]; let bytesSTO = web3.eth.abi.encodeFunctionCall(functionSignature, config); let errorThrown = false; try { @@ -567,7 +567,7 @@ contract('USDTieredSTO', accounts => { let stoId = 0; let wallet = "0x0000000000000000000000000000000000000000"; - let config = [_startTime[stoId], _endTime[stoId], _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypess[stoId], wallet, _reserveWallet[stoId], _usdToken[stoId]]; + let config = [_startTime[stoId], _endTime[stoId], _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypes[stoId], wallet, _reserveWallet[stoId], _usdToken[stoId]]; let bytesSTO = web3.eth.abi.encodeFunctionCall(functionSignature, config); let errorThrown = false; try { @@ -583,7 +583,7 @@ contract('USDTieredSTO', accounts => { let stoId = 0; let reserveWallet = "0x0000000000000000000000000000000000000000"; - let config = [_startTime[stoId], _endTime[stoId], _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypess[stoId], _wallet[stoId], reserveWallet]; + let config = [_startTime[stoId], _endTime[stoId], _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypes[stoId], _wallet[stoId], reserveWallet]; let bytesSTO = web3.eth.abi.encodeFunctionCall(functionSignature, config); let errorThrown = false; try { @@ -600,7 +600,7 @@ contract('USDTieredSTO', accounts => { let startTime = latestTime() + duration.days(35); let endTime = latestTime() + duration.days(1); - let config = [startTime, endTime, _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId], _usdToken[stoId]]; + let config = [startTime, endTime, _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypes[stoId], _wallet[stoId], _reserveWallet[stoId], _usdToken[stoId]]; let bytesSTO = web3.eth.abi.encodeFunctionCall(functionSignature, config); let errorThrown = false; try { @@ -617,7 +617,7 @@ contract('USDTieredSTO', accounts => { let startTime = latestTime() - duration.days(35); let endTime = startTime + duration.days(50); - let config = [startTime, endTime, _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypess[stoId], _wallet[stoId], _reserveWallet[stoId], _usdToken[stoId]]; + let config = [startTime, endTime, _ratePerTier[stoId], _ratePerTierDiscountPoly[stoId], _tokensPerTierTotal[stoId], _tokensPerTierDiscountPoly[stoId], _nonAccreditedLimitUSD[stoId], _minimumInvestmentUSD[stoId], _fundRaiseTypes[stoId], _wallet[stoId], _reserveWallet[stoId], _usdToken[stoId]]; let bytesSTO = web3.eth.abi.encodeFunctionCall(functionSignature, config); let errorThrown = false; try { @@ -1224,7 +1224,7 @@ contract('USDTieredSTO', accounts => { } assert.ok(errorThrown4, 'ACCREDITED POLY investment succeeded when it should not'); - // ACCREDITED POLY + // ACCREDITED DAI let errorThrown6 = false; try { await I_USDTieredSTO_Array[stoId].buyWithUSD(ACCREDITED1, investment_DAI, {from: ACCREDITED1}); @@ -1279,6 +1279,11 @@ contract('USDTieredSTO', accounts => { await I_PolyToken.approve(I_USDTieredSTO_Array[stoId].address, investment_POLY, {from: NONACCREDITED1}); await I_PolyToken.getTokens(investment_POLY, ACCREDITED1); await I_PolyToken.approve(I_USDTieredSTO_Array[stoId].address, investment_POLY, {from: ACCREDITED1}); + let investment_DAI = web3.utils.toWei('500', 'ether'); // Invest 10000 POLY + await I_DaiToken.getTokens(investment_DAI, NONACCREDITED1); + await I_DaiToken.approve(I_USDTieredSTO_Array[stoId].address, investment_DAI, {from: NONACCREDITED1}); + await I_DaiToken.getTokens(investment_DAI, ACCREDITED1); + await I_DaiToken.approve(I_USDTieredSTO_Array[stoId].address, investment_DAI, {from: ACCREDITED1}); // NONACCREDITED ETH let errorThrown1 = false; @@ -1300,6 +1305,16 @@ contract('USDTieredSTO', accounts => { } assert.ok(errorThrown2, 'NONACCREDITED POLY investment succeeded when it should not'); + // NONACCREDITED DAI + let errorThrown5 = false; + try { + await I_USDTieredSTO_Array[stoId].buyWithUSD(NONACCREDITED1, investment_DAI, {from: NONACCREDITED1}); + } catch(error) { + errorThrown5 = true; + ensureException(error); + } + assert.ok(errorThrown5, 'NONACCREDITED DAI investment succeeded when it should not'); + // ACCREDITED ETH let errorThrown3 = false; try { @@ -1320,6 +1335,16 @@ contract('USDTieredSTO', accounts => { } assert.ok(errorThrown4, 'ACCREDITED POLY investment succeeded when it should not'); + // ACCREDITED DAI + let errorThrown6 = false; + try { + await I_USDTieredSTO_Array[stoId].buyWithUSD(ACCREDITED1, investment_DAI, {from: ACCREDITED1}); + } catch(error) { + errorThrown6 = true; + ensureException(error); + } + assert.ok(errorThrown6, 'ACCREDITED DAI investment succeeded when it should not'); + await revertToSnapshot(snapId); }); }); @@ -1404,6 +1429,7 @@ contract('USDTieredSTO', accounts => { let init_RaisedUSD = await I_USDTieredSTO_Array[stoId].fundsRaisedUSD.call(); let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); + let init_RaisedDAI = await I_USDTieredSTO_Array[stoId].fundsRaised.call(DAI); let init_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let init_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -1421,6 +1447,7 @@ contract('USDTieredSTO', accounts => { let final_RaisedUSD = await I_USDTieredSTO_Array[stoId].fundsRaisedUSD.call(); let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); + let final_RaisedDAI = await I_USDTieredSTO_Array[stoId].fundsRaised.call(DAI); let final_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let final_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -1434,6 +1461,7 @@ contract('USDTieredSTO', accounts => { assert.equal(final_RaisedUSD.toNumber(), init_RaisedUSD.add(investment_USD).toNumber(), "Raised USD not changed as expected"); assert.equal(final_RaisedETH.toNumber(), init_RaisedETH.add(investment_ETH).toNumber(), "Raised ETH not changed as expected"); assert.equal(final_RaisedPOLY.toNumber(), init_RaisedPOLY.toNumber(), "Raised POLY not changed as expected"); + assert.equal(final_RaisedDAI.toNumber(), init_RaisedDAI.toNumber(), "Raised POLY not changed as expected"); assert.equal(final_WalletETHBal.toNumber(), init_WalletETHBal.add(investment_ETH).toNumber(), "Wallet ETH Balance not changed as expected"); assert.equal(final_WalletPOLYBal.toNumber(), init_WalletPOLYBal.toNumber(), "Wallet POLY Balance not changed as expected"); @@ -1466,6 +1494,7 @@ contract('USDTieredSTO', accounts => { let init_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); + let init_RaisedDAI = await I_USDTieredSTO_Array[stoId].fundsRaised.call(DAI); let init_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let init_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -1482,6 +1511,7 @@ contract('USDTieredSTO', accounts => { let final_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); + let final_RaisedDAI = await I_USDTieredSTO_Array[stoId].fundsRaised.call(DAI); let final_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let final_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -1494,6 +1524,7 @@ contract('USDTieredSTO', accounts => { assert.equal(final_STOPOLYBal.toNumber(), init_STOPOLYBal.toNumber(), "STO POLY Balance not changed as expected"); assert.equal(final_RaisedETH.toNumber(), init_RaisedETH.add(investment_ETH).toNumber(), "Raised ETH not changed as expected"); assert.equal(final_RaisedPOLY.toNumber(), init_RaisedPOLY.toNumber(), "Raised POLY not changed as expected"); + assert.equal(final_RaisedDAI.toNumber(), init_RaisedDAI.toNumber(), "Raised DAI not changed as expected"); assert.equal(final_WalletETHBal.toNumber(), init_WalletETHBal.add(investment_ETH).toNumber(), "Wallet ETH Balance not changed as expected"); assert.equal(final_WalletPOLYBal.toNumber(), init_WalletPOLYBal.toNumber(), "Wallet POLY Balance not changed as expected"); }); @@ -1519,6 +1550,7 @@ contract('USDTieredSTO', accounts => { let init_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); + let init_RaisedDAI = await I_USDTieredSTO_Array[stoId].fundsRaised.call(DAI); let init_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let init_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -1536,6 +1568,7 @@ contract('USDTieredSTO', accounts => { let final_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); + let final_RaisedDAI = await I_USDTieredSTO_Array[stoId].fundsRaised.call(DAI); let final_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let final_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); @@ -1548,10 +1581,75 @@ contract('USDTieredSTO', accounts => { assert.equal(final_STOPOLYBal.toNumber(), init_STOPOLYBal.toNumber(), "STO POLY Balance not changed as expected"); assert.equal(final_RaisedETH.toNumber(), init_RaisedETH.toNumber(), "Raised ETH not changed as expected"); assert.equal(final_RaisedPOLY.toNumber(), init_RaisedPOLY.add(investment_POLY).toNumber(), "Raised POLY not changed as expected"); + assert.equal(final_RaisedDAI.toNumber(), init_RaisedDAI.toNumber(), "Raised POLY not changed as expected"); assert.equal(final_WalletETHBal.toNumber(), init_WalletETHBal.toNumber(), "Wallet ETH Balance not changed as expected"); assert.equal(final_WalletPOLYBal.toNumber(), init_WalletPOLYBal.add(investment_POLY).toNumber(), "Wallet POLY Balance not changed as expected"); }); + it("should successfully buy using buyWithUSD at tier 0 for NONACCREDITED1", async() => { + let stoId = 0; + let tierId = 0; + + let investment_Token = BigNumber(50).mul(10**18); + let investment_USD = await convert(stoId, tierId, false, "TOKEN", "USD", investment_Token); + let investment_ETH = await convert(stoId, tierId, false, "TOKEN", "ETH", investment_Token); + let investment_POLY = await convert(stoId, tierId, false, "TOKEN", "POLY", investment_Token); + let investment_DAI = investment_USD; + + await I_DaiToken.getTokens(investment_DAI, NONACCREDITED1); + await I_DaiToken.approve(I_USDTieredSTO_Array[stoId].address, investment_DAI, {from: NONACCREDITED1}); + + let init_TokenSupply = await I_SecurityToken.totalSupply(); + let init_InvestorTokenBal = await I_SecurityToken.balanceOf(NONACCREDITED1); + let init_InvestorETHBal = BigNumber(await web3.eth.getBalance(NONACCREDITED1)); + let init_InvestorPOLYBal = await I_PolyToken.balanceOf(NONACCREDITED1); + let init_InvestorDAIBal = await I_DaiToken.balanceOf(NONACCREDITED1); + let init_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); + let init_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); + let init_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); + let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); + let init_RaisedDAI = await I_USDTieredSTO_Array[stoId].fundsRaised.call(DAI); + let init_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); + let init_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); + let init_WalletDAIBal = await I_DaiToken.balanceOf(WALLET); + + // Buy With DAI + let tx2 = await I_USDTieredSTO_Array[stoId].buyWithUSD(NONACCREDITED1, investment_DAI, { from: NONACCREDITED1, gasPrice: GAS_PRICE }); + let gasCost2 = BigNumber(GAS_PRICE).mul(tx2.receipt.gasUsed); + console.log(" Gas buyWithUSD: ".grey+tx2.receipt.gasUsed.toString().grey); + + let final_TokenSupply = await I_SecurityToken.totalSupply(); + let final_InvestorTokenBal = await I_SecurityToken.balanceOf(NONACCREDITED1); + let final_InvestorETHBal = BigNumber(await web3.eth.getBalance(NONACCREDITED1)); + let final_InvestorPOLYBal = await I_PolyToken.balanceOf(NONACCREDITED1); + let final_InvestorDAIBal = await I_DaiToken.balanceOf(NONACCREDITED1); + let final_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); + let final_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); + let final_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); + let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); + let final_RaisedDAI = await I_USDTieredSTO_Array[stoId].fundsRaised.call(DAI); + let final_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); + let final_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); + let final_WalletDAIBal = await I_DaiToken.balanceOf(WALLET); + + assert.equal(final_TokenSupply.toNumber(), init_TokenSupply.add(investment_Token).toNumber(), "Token Supply not changed as expected"); + assert.equal(final_InvestorTokenBal.toNumber(), init_InvestorTokenBal.add(investment_Token).toNumber(), "Investor Token Balance not changed as expected"); + assert.equal(final_InvestorETHBal.toNumber(), init_InvestorETHBal.sub(gasCost2).toNumber(), "Investor ETH Balance not changed as expected"); + assert.equal(final_InvestorPOLYBal.toNumber(), init_InvestorPOLYBal.toNumber(), "Investor POLY Balance not changed as expected"); + assert.equal(final_InvestorDAIBal.toNumber(), init_InvestorDAIBal.sub(investment_DAI).toNumber(), "Investor DAI Balance not changed as expected"); + assert.equal(final_STOTokenSold.toNumber(), init_STOTokenSold.add(investment_Token).toNumber(), "STO Token Sold not changed as expected"); + assert.equal(final_STOETHBal.toNumber(), init_STOETHBal.toNumber(), "STO ETH Balance not changed as expected"); + assert.equal(final_STOPOLYBal.toNumber(), init_STOPOLYBal.toNumber(), "STO POLY Balance not changed as expected"); + assert.equal(final_RaisedETH.toNumber(), init_RaisedETH.toNumber(), "Raised ETH not changed as expected"); + assert.equal(final_RaisedPOLY.toNumber(), init_RaisedPOLY.toNumber(), "Raised POLY not changed as expected"); + assert.equal(final_RaisedDAI.toNumber(), init_RaisedDAI.add(investment_DAI).toNumber(), "Raised POLY not changed as expected"); + assert.equal(final_WalletETHBal.toNumber(), init_WalletETHBal.toNumber(), "Wallet ETH Balance not changed as expected"); + assert.equal(final_WalletPOLYBal.toNumber(), init_WalletPOLYBal.toNumber(), "Wallet POLY Balance not changed as expected"); + assert.equal(final_WalletDAIBal.toNumber(), init_WalletDAIBal.add(investment_DAI).toNumber(), "Wallet DAI Balance not changed as expected"); + }); + it("should successfully buy using fallback at tier 0 for ACCREDITED1", async() => { let stoId = 0; let tierId = 0; @@ -2128,6 +2226,77 @@ contract('USDTieredSTO', accounts => { assert.equal((await I_USDTieredSTO_Array[stoId].currentTier.call()).toNumber(), endTier, "currentTier not changed as expected"); }); + it("should successfully buy across tiers for ACCREDITED DAI", async() => { + let snapId = await takeSnapshot(); + let stoId = 1; + let startTier = 3; + let endTier = 4; + + assert.equal((await I_USDTieredSTO_Array[stoId].currentTier.call()).toNumber(), startTier, "currentTier not changed as expected"); + + let delta_Token = BigNumber(5).mul(10**18); // Token + let daiTier0 = await convert(stoId, startTier, false, "TOKEN", "USD", delta_Token); + let daiTier1 = await convert(stoId, endTier, false, "TOKEN", "USD", delta_Token); + console.log(daiTier0.toNumber() + ":" + daiTier1.toNumber()); + + let investment_Token = delta_Token.add(delta_Token); // 10 Token + let investment_DAI = daiTier0.add(daiTier1); + + await I_DaiToken.getTokens(investment_DAI, ACCREDITED1); + await I_DaiToken.approve(I_USDTieredSTO_Array[stoId].address, investment_DAI, {from: ACCREDITED1}); + + // Process investment + let init_TokenSupply = await I_SecurityToken.totalSupply(); + let init_InvestorTokenBal = await I_SecurityToken.balanceOf(ACCREDITED1); + let init_InvestorETHBal = BigNumber(await web3.eth.getBalance(ACCREDITED1)); + let init_InvestorPOLYBal = await I_PolyToken.balanceOf(ACCREDITED1); + let init_InvestorDAIBal = await I_DaiToken.balanceOf(ACCREDITED1); + let init_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); + let init_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); + let init_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); + let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); + let init_RaisedDAI = await I_USDTieredSTO_Array[stoId].fundsRaised.call(DAI); + let init_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); + let init_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); +console.log(investment_DAI.toNumber()); + let tx2 = await I_USDTieredSTO_Array[stoId].buyWithUSD(ACCREDITED1, investment_DAI, { from: ACCREDITED1, gasPrice: GAS_PRICE }); + let gasCost2 = BigNumber(GAS_PRICE).mul(tx2.receipt.gasUsed); + console.log(" Gas buyWithUSD: ".grey+tx2.receipt.gasUsed.toString().grey); + process.exit(0); + let final_TokenSupply = await I_SecurityToken.totalSupply(); + let final_InvestorTokenBal = await I_SecurityToken.balanceOf(ACCREDITED1); + let final_InvestorETHBal = BigNumber(await web3.eth.getBalance(ACCREDITED1)); + let final_InvestorPOLYBal = await I_PolyToken.balanceOf(ACCREDITED1); + let final_InvestorDAIBal = await I_DaiToken.balanceOf(ACCREDITED1); + let final_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); + let final_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); + let final_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); + let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(ETH); + let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(POLY); + let final_RaisedDAI = await I_USDTieredSTO_Array[stoId].fundsRaised.call(DAI); + let final_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); + let final_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); + + assert.equal(final_TokenSupply.toNumber(), init_TokenSupply.add(investment_Token).toNumber(), "Token Supply not changed as expected"); + assert.equal(final_InvestorTokenBal.toNumber(), init_InvestorTokenBal.add(investment_Token).toNumber(), "Investor Token Balance not changed as expected"); + assert.equal(final_InvestorETHBal.toNumber(), init_InvestorETHBal.sub(gasCost2).toNumber(), "Investor ETH Balance not changed as expected"); + assert.equal(final_InvestorPOLYBal.toNumber(), init_InvestorPOLYBal.toNumber(), "Investor POLY Balance not changed as expected"); + assert.equal(final_InvestorDAIBal.toNumber(), init_InvestorDAIBal.sub(investment_DAI).toNumber(), "Investor POLY Balance not changed as expected"); + assert.equal(final_STOTokenSold.toNumber(), init_STOTokenSold.add(investment_Token).toNumber(), "STO Token Sold not changed as expected"); + assert.equal(final_STOETHBal.toNumber(), init_STOETHBal.toNumber(), "STO ETH Balance not changed as expected"); + assert.equal(final_STOPOLYBal.toNumber(), init_STOPOLYBal.toNumber(), "STO POLY Balance not changed as expected"); + assert.equal(final_RaisedETH.toNumber(), init_RaisedETH.toNumber(), "Raised ETH not changed as expected"); + assert.equal(final_RaisedPOLY.toNumber(), init_RaisedPOLY.toNumber(), "Raised POLY not changed as expected"); + assert.equal(final_RaisedDAI.toNumber(), init_RaisedDAI.add(investment_DAI).toNumber(), "Raised DAI not changed as expected"); + assert.equal(final_WalletETHBal.toNumber(), init_WalletETHBal.toNumber(), "Wallet ETH Balance not changed as expected"); + assert.equal(final_WalletPOLYBal.toNumber(), init_WalletPOLYBal.add(investment_POLY).toNumber(), "Wallet POLY Balance not changed as expected"); + + // Additional Checks + assert.equal((await I_USDTieredSTO_Array[stoId].currentTier.call()).toNumber(), endTier, "currentTier not changed as expected"); + await revertToSnapshot(snapId); + }); + it("should successfully buy across tiers for ACCREDITED POLY", async() => { let stoId = 1; let startTier = 3; @@ -2223,10 +2392,14 @@ contract('USDTieredSTO', accounts => { let investment_USD = await convert(stoId, tierId, false, "TOKEN", "USD", investment_Token); let investment_ETH = await convert(stoId, tierId, false, "TOKEN", "ETH", investment_Token); let investment_POLY = await convert(stoId, tierId, false, "TOKEN", "POLY", investment_Token); + let investment_DAI = investment_USD; await I_PolyToken.getTokens(investment_POLY, NONACCREDITED1); await I_PolyToken.approve(I_USDTieredSTO_Array[stoId].address, investment_POLY, { from: NONACCREDITED1, gasPrice: GAS_PRICE }); + await I_DaiToken.getTokens(investment_DAI, NONACCREDITED1); + await I_DaiToken.approve(I_USDTieredSTO_Array[stoId].address, investment_DAI, { from: NONACCREDITED1, gasPrice: GAS_PRICE }); + assert.equal(await I_USDTieredSTO_Array[stoId].isOpen(),false,"STO is not showing correct status"); // Buy with ETH NONACCREDITED @@ -2249,6 +2422,16 @@ contract('USDTieredSTO', accounts => { } assert.ok(errorThrown2, MESSAGE); + // Buy with DAI NONACCREDITED + let errorThrown5 = false; + try { + await I_USDTieredSTO_Array[stoId].buyWithUSD(NONACCREDITED1, investment_DAI, { from: NONACCREDITED1, gasPrice: GAS_PRICE }); + } catch(error) { + errorThrown5 = true; + ensureException(error); + } + assert.ok(errorThrown5, MESSAGE); + // Buy with ETH ACCREDITED let errorThrown3 = false; try { @@ -2268,6 +2451,16 @@ contract('USDTieredSTO', accounts => { ensureException(error); } assert.ok(errorThrown4, MESSAGE); + + // Buy with DAI ACCREDITED + let errorThrown6 = false; + try { + await I_USDTieredSTO_Array[stoId].buyWithUSD(ACCREDITED1, investment_DAI, { from: ACCREDITED1, gasPrice: GAS_PRICE }); + } catch(error) { + errorThrown6 = true; + ensureException(error); + } + assert.ok(errorThrown6, MESSAGE); }); it("should fail and revert when all tiers sold out despite oracle price change", async() => { diff --git a/test/q_usd_tiered_sto_sim.js b/test/q_usd_tiered_sto_sim.js index c8b6ac17c..5407663bd 100644 --- a/test/q_usd_tiered_sto_sim.js +++ b/test/q_usd_tiered_sto_sim.js @@ -581,9 +581,11 @@ contract('USDTieredSTO Sim', accounts => { } async function investFAIL(_investor) { - let isPoly = Math.random() >= 0.5; + let isPoly = Math.random() >= 0.3; + let isDAI = Math.random() >= 0.3; let investment_POLY = BigNumber(40*10**18); // 10 USD = 40 POLY let investment_ETH = BigNumber(0.02*10**18); // 10 USD = 0.02 ETH + let investment_DAI = BigNumber(10*10**18); // 10 USD = DAI DAI let errorThrown = false; try { @@ -591,8 +593,11 @@ contract('USDTieredSTO Sim', accounts => { await I_PolyToken.getTokens(investment_POLY, _investor); await I_PolyToken.approve(I_USDTieredSTO_Array[stoId].address, investment_POLY, {from: _investor}); await I_USDTieredSTO_Array[stoId].buyWithPOLY(_investor, investment_POLY, { from: _investor, gasPrice: GAS_PRICE }); - } else - await I_USDTieredSTO_Array[stoId].buyWithETH(_investor, { from: _investor, value: investment_ETH, gasPrice: GAS_PRICE }); + } else if (isDAI) { + await I_DaiToken.getTokens(investment_DAI, _investor); + await I_DaiToken.approve(I_USDTieredSTO_Array[stoId].address, investment_DAI, {from: _investor}); + await I_USDTieredSTO_Array[stoId].buyWithUSD(_investor, investment_DAI, { from: _investor, gasPrice: GAS_PRICE }); + } else await I_USDTieredSTO_Array[stoId].buyWithETH(_investor, { from: _investor, value: investment_ETH, gasPrice: GAS_PRICE }); } catch(error) { errorThrown = true; console.log(`Purchase failed as expected: ${_investor}`.yellow); diff --git a/test/r_concurrent_STO.js b/test/r_concurrent_STO.js index 612bb5b63..477b9de40 100644 --- a/test/r_concurrent_STO.js +++ b/test/r_concurrent_STO.js @@ -373,12 +373,12 @@ contract('Concurrent STO', accounts => { // Capped STO ETH await I_STO_Array[STOIndex].buyTokens(account_investor1, { from : account_investor1, value: web3.utils.toWei('1', 'ether') }); assert.equal(web3.utils.fromWei((await I_STO_Array[STOIndex].getRaised.call(0)).toString()), 1); - assert.equal(await I_STO_Array[STOIndex].getNumberInvestors.call(), 1); + assert.equal(await I_STO_Array[STOIndex].investorCount.call(), 1); break; case 1: // Dummy STO await I_STO_Array[STOIndex].generateTokens(account_investor1, web3.utils.toWei('1000'), { from : account_issuer }); - assert.equal(await I_STO_Array[STOIndex].getNumberInvestors.call(), 1); + assert.equal(await I_STO_Array[STOIndex].investorCount.call(), 1); assert.equal( (await I_STO_Array[STOIndex].investors.call(account_investor1)) .dividedBy(new BigNumber(10).pow(18)) @@ -391,7 +391,7 @@ contract('Concurrent STO', accounts => { await I_STO_Array[STOIndex].allocateTokens(account_investor1, web3.utils.toWei('1000'), web3.utils.toWei('1'), 0, { from : account_issuer }); assert.equal(web3.utils.fromWei((await I_STO_Array[STOIndex].getRaised.call(0)).toString()), 1); assert.equal(web3.utils.fromWei((await I_STO_Array[STOIndex].getRaised.call(1)).toString()), 0); - assert.equal(await I_STO_Array[STOIndex].getNumberInvestors.call(), 1); + assert.equal(await I_STO_Array[STOIndex].investorCount.call(), 1); assert.equal( (await I_STO_Array[STOIndex].investors.call(account_investor1)) .dividedBy(new BigNumber(10).pow(18)) diff --git a/test/s_v130_to_v140_upgrade.js b/test/s_v130_to_v140_upgrade.js index 4175771b0..d60b45d2d 100644 --- a/test/s_v130_to_v140_upgrade.js +++ b/test/s_v130_to_v140_upgrade.js @@ -62,6 +62,7 @@ contract('Upgrade from v1.3.0 to v1.4.0', accounts => { // Contract Instance Declaration let I_PolymathRegistry; let I_PolyToken; + let I_DaiToken; let I_ModuleRegistry; let I_GeneralTransferManagerFactory; let I_GeneralPermissionManagerFactory; @@ -109,6 +110,7 @@ contract('Upgrade from v1.3.0 to v1.4.0', accounts => { // Step 1: Deploy the token Faucet I_PolyToken = await PolyTokenFaucet.new({from: POLYMATH}); + I_DaiToken = await PolyTokenFaucet.new({from: POLYMATH}); assert.notEqual( I_PolyToken.address.valueOf(), "0x0000000000000000000000000000000000000000", @@ -425,11 +427,12 @@ contract('Upgrade from v1.3.0 to v1.4.0', accounts => { let _fundRaiseTypes = [0, 1]; let _wallet = ISSUER1; let _reserveWallet = ISSUER1; + let _usdToken = I_DaiToken.address; let config = [ _startTime, _endTime, _ratePerTier, _ratePerTierDiscountPoly, _tokensPerTierTotal, _tokensPerTierDiscountPoly, _nonAccreditedLimitUSD, _minimumInvestmentUSD, - _fundRaiseTypes, _wallet, _reserveWallet + _fundRaiseTypes, _wallet, _reserveWallet, _usdToken ]; let functionSignature = { @@ -468,6 +471,9 @@ contract('Upgrade from v1.3.0 to v1.4.0', accounts => { },{ type: 'address', name: '_reserveWallet' + },{ + type: 'address', + name: '_usdToken' }] }; From c29b700d0b430be198e3ae0482b626d6258ef2d3 Mon Sep 17 00:00:00 2001 From: satyam Date: Thu, 20 Sep 2018 21:23:55 +0530 Subject: [PATCH 09/12] small typo fix --- contracts/modules/STO/ISTO.sol | 2 +- contracts/modules/STO/USDTieredSTO.sol | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/contracts/modules/STO/ISTO.sol b/contracts/modules/STO/ISTO.sol index f3afc6c40..7205ca2a8 100644 --- a/contracts/modules/STO/ISTO.sol +++ b/contracts/modules/STO/ISTO.sol @@ -44,7 +44,7 @@ contract ISTO is Module, Pausable { } /** - * @notice Return ETH raised by the STO + * @notice Return funds raised by the STO */ function getRaised(FundRaiseType _fundRaiseType) public view returns (uint256) { return fundsRaised[uint8(_fundRaiseType)]; diff --git a/contracts/modules/STO/USDTieredSTO.sol b/contracts/modules/STO/USDTieredSTO.sol index f54f793cc..c782932dc 100644 --- a/contracts/modules/STO/USDTieredSTO.sol +++ b/contracts/modules/STO/USDTieredSTO.sol @@ -157,6 +157,7 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { * @param _fundRaiseTypes Types of currency used to collect the funds * @param _wallet Ethereum account address to hold the funds * @param _reserveWallet Ethereum account address to receive unsold tokens + * @param _usdToken Contract address of the stable coin */ function configure( uint256 _startTime, From f2ab5ffc5a55b74112c03a267d2065d578803699 Mon Sep 17 00:00:00 2001 From: Adam Dossa Date: Thu, 20 Sep 2018 21:08:54 +0100 Subject: [PATCH 10/12] More test fixes --- contracts/modules/STO/USDTieredSTO.sol | 6 ++--- test/p_usd_tiered_sto.js | 36 ++++++++++++++------------ 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/contracts/modules/STO/USDTieredSTO.sol b/contracts/modules/STO/USDTieredSTO.sol index c782932dc..c79461e64 100644 --- a/contracts/modules/STO/USDTieredSTO.sol +++ b/contracts/modules/STO/USDTieredSTO.sol @@ -389,6 +389,7 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { if (!allowBeneficialInvestments) { require(_beneficiary == msg.sender, "Beneficiary must match funder"); } + require(isOpen(), "STO is not open"); require(_investmentValue > 0, "No funds were sent"); @@ -405,7 +406,6 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { if (investedUSD.add(investorInvestedUSD[_beneficiary]) > investorLimitUSD) investedUSD = investorLimitUSD.sub(investorInvestedUSD[_beneficiary]); } - uint256 spentUSD; // Iterate over each tier and process payment for (uint8 i = currentTier; i < ratePerTier.length; i++) { @@ -446,7 +446,7 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { uint256 tierSpentUSD; uint256 tierPurchasedTokens; // Check whether there are any remaining discounted tokens - if ((_fundRaiseType == FundRaiseType.POLY) && tokensPerTierDiscountPoly[_tier] > mintedPerTierDiscountPoly[_tier]) { + if ((_fundRaiseType == FundRaiseType.POLY) && (tokensPerTierDiscountPoly[_tier] > mintedPerTierDiscountPoly[_tier])) { uint256 discountRemaining = tokensPerTierDiscountPoly[_tier].sub(mintedPerTierDiscountPoly[_tier]); uint256 totalRemaining = tokensPerTierTotal[_tier].sub(mintedPerTierTotal[_tier]); if (totalRemaining < discountRemaining) @@ -519,7 +519,7 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { return (mintedPerTierTotal[mintedPerTierTotal.length - 1] == tokensPerTierTotal[tokensPerTierTotal.length - 1]); } - function getRate(FundRaiseType _fundRaiseType) public view returns (uint256){ + function getRate(FundRaiseType _fundRaiseType) public view returns (uint256) { if (_fundRaiseType == FundRaiseType.ETH) { return IOracle(_getOracle(bytes32("ETH"), bytes32("USD"))).getPrice(); } else if (_fundRaiseType == FundRaiseType.POLY) { diff --git a/test/p_usd_tiered_sto.js b/test/p_usd_tiered_sto.js index 835aedebd..a1b55699b 100644 --- a/test/p_usd_tiered_sto.js +++ b/test/p_usd_tiered_sto.js @@ -420,13 +420,13 @@ contract('USDTieredSTO', accounts => { _startTime.push(latestTime() + duration.days(2)); _endTime.push(_startTime[stoId] + duration.days(100)); - _ratePerTier.push([BigNumber(10*10**16), BigNumber(15*10**16), BigNumber(15*10**16), BigNumber(15*10**16), BigNumber(15*10**16)]); - _ratePerTierDiscountPoly.push([BigNumber(10*10**16), BigNumber(15*10**16), BigNumber(15*10**16), BigNumber(15*10**16), BigNumber(15*10**16)]); - _tokensPerTierTotal.push([BigNumber(5*10**18), BigNumber(10*10**18), BigNumber(10*10**18), BigNumber(10*10**18), BigNumber(50*10**18)]); - _tokensPerTierDiscountPoly.push([BigNumber(0), BigNumber(0), BigNumber(0), BigNumber(0), BigNumber(0)]); + _ratePerTier.push([BigNumber(10*10**16), BigNumber(15*10**16), BigNumber(15*10**16), BigNumber(15*10**16), BigNumber(15*10**16), BigNumber(15*10**16)]); + _ratePerTierDiscountPoly.push([BigNumber(10*10**16), BigNumber(15*10**16), BigNumber(15*10**16), BigNumber(15*10**16), BigNumber(15*10**16), BigNumber(15*10**16)]); + _tokensPerTierTotal.push([BigNumber(5*10**18), BigNumber(10*10**18), BigNumber(10*10**18), BigNumber(10*10**18), BigNumber(10*10**18), BigNumber(50*10**18)]); + _tokensPerTierDiscountPoly.push([BigNumber(0), BigNumber(0), BigNumber(0), BigNumber(0), BigNumber(0), BigNumber(0)]); _nonAccreditedLimitUSD.push(BigNumber(10000).mul(BigNumber(10**18))); _minimumInvestmentUSD.push(BigNumber(0)); - _fundRaiseTypes.push([0, 1]); + _fundRaiseTypes.push([0, 1, 2]); _wallet.push(WALLET); _reserveWallet.push(RESERVEWALLET); _usdToken.push(I_DaiToken.address); @@ -472,7 +472,7 @@ contract('USDTieredSTO', accounts => { _tokensPerTierDiscountPoly.push([BigNumber(100*10**18),BigNumber(25*10**18)]); // [ 100 Token, 25 Token ] _nonAccreditedLimitUSD.push(BigNumber(25*10**18)); // [ 25 USD ] _minimumInvestmentUSD.push(BigNumber(5)); - _fundRaiseTypes.push([0, 1]); + _fundRaiseTypes.push([0, 1, 2]); _wallet.push(WALLET); _reserveWallet.push(RESERVEWALLET); _usdToken.push(I_DaiToken.address) @@ -502,7 +502,7 @@ contract('USDTieredSTO', accounts => { _tokensPerTierDiscountPoly.push([BigNumber(0),BigNumber(50*10**18)]); _nonAccreditedLimitUSD.push(BigNumber(10000).mul(BigNumber(10**18))); _minimumInvestmentUSD.push(BigNumber(0)); - _fundRaiseTypes.push([0, 1]); + _fundRaiseTypes.push([0, 1, 2]); _wallet.push(WALLET); _reserveWallet.push(RESERVEWALLET); _usdToken.push(I_DaiToken.address); @@ -2227,7 +2227,7 @@ contract('USDTieredSTO', accounts => { }); it("should successfully buy across tiers for ACCREDITED DAI", async() => { - let snapId = await takeSnapshot(); + let stoId = 1; let startTier = 3; let endTier = 4; @@ -2237,7 +2237,6 @@ contract('USDTieredSTO', accounts => { let delta_Token = BigNumber(5).mul(10**18); // Token let daiTier0 = await convert(stoId, startTier, false, "TOKEN", "USD", delta_Token); let daiTier1 = await convert(stoId, endTier, false, "TOKEN", "USD", delta_Token); - console.log(daiTier0.toNumber() + ":" + daiTier1.toNumber()); let investment_Token = delta_Token.add(delta_Token); // 10 Token let investment_DAI = daiTier0.add(daiTier1); @@ -2259,11 +2258,12 @@ contract('USDTieredSTO', accounts => { let init_RaisedDAI = await I_USDTieredSTO_Array[stoId].fundsRaised.call(DAI); let init_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let init_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); -console.log(investment_DAI.toNumber()); + let init_WalletDAIBal = await I_DaiToken.balanceOf(WALLET); + let tx2 = await I_USDTieredSTO_Array[stoId].buyWithUSD(ACCREDITED1, investment_DAI, { from: ACCREDITED1, gasPrice: GAS_PRICE }); let gasCost2 = BigNumber(GAS_PRICE).mul(tx2.receipt.gasUsed); console.log(" Gas buyWithUSD: ".grey+tx2.receipt.gasUsed.toString().grey); - process.exit(0); + let final_TokenSupply = await I_SecurityToken.totalSupply(); let final_InvestorTokenBal = await I_SecurityToken.balanceOf(ACCREDITED1); let final_InvestorETHBal = BigNumber(await web3.eth.getBalance(ACCREDITED1)); @@ -2277,6 +2277,7 @@ console.log(investment_DAI.toNumber()); let final_RaisedDAI = await I_USDTieredSTO_Array[stoId].fundsRaised.call(DAI); let final_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let final_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); + let final_WalletDAIBal = await I_DaiToken.balanceOf(WALLET); assert.equal(final_TokenSupply.toNumber(), init_TokenSupply.add(investment_Token).toNumber(), "Token Supply not changed as expected"); assert.equal(final_InvestorTokenBal.toNumber(), init_InvestorTokenBal.add(investment_Token).toNumber(), "Investor Token Balance not changed as expected"); @@ -2290,17 +2291,18 @@ console.log(investment_DAI.toNumber()); assert.equal(final_RaisedPOLY.toNumber(), init_RaisedPOLY.toNumber(), "Raised POLY not changed as expected"); assert.equal(final_RaisedDAI.toNumber(), init_RaisedDAI.add(investment_DAI).toNumber(), "Raised DAI not changed as expected"); assert.equal(final_WalletETHBal.toNumber(), init_WalletETHBal.toNumber(), "Wallet ETH Balance not changed as expected"); - assert.equal(final_WalletPOLYBal.toNumber(), init_WalletPOLYBal.add(investment_POLY).toNumber(), "Wallet POLY Balance not changed as expected"); + assert.equal(final_WalletPOLYBal.toNumber(), init_WalletPOLYBal.toNumber(), "Wallet POLY Balance not changed as expected"); + assert.equal(final_WalletDAIBal.toNumber(), init_WalletDAIBal.add(investment_DAI).toNumber(), "Wallet POLY Balance not changed as expected"); // Additional Checks assert.equal((await I_USDTieredSTO_Array[stoId].currentTier.call()).toNumber(), endTier, "currentTier not changed as expected"); - await revertToSnapshot(snapId); + }); it("should successfully buy across tiers for ACCREDITED POLY", async() => { let stoId = 1; - let startTier = 3; - let endTier = 4; + let startTier = 4; + let endTier = 5; assert.equal((await I_USDTieredSTO_Array[stoId].currentTier.call()).toNumber(), startTier, "currentTier not changed as expected"); @@ -2361,10 +2363,12 @@ console.log(investment_DAI.toNumber()); it("should buy out the rest of the sto", async() => { let stoId = 1; - let tierId = 4; + let tierId = 5; let minted = await I_USDTieredSTO_Array[stoId].mintedPerTierTotal.call(tierId); + console.log(minted.toNumber() + ":"+ _tokensPerTierTotal[stoId][tierId]); let investment_Token = _tokensPerTierTotal[stoId][tierId].sub(minted); + console.log(investment_Token.toNumber()); let investment_ETH = await convert(stoId, tierId, false, "TOKEN", "ETH", investment_Token); let init_TokenSupply = await I_SecurityToken.totalSupply(); From d4ba6bbac795b575c21a61224484bce03cc81436 Mon Sep 17 00:00:00 2001 From: Adam Dossa Date: Thu, 20 Sep 2018 21:55:41 +0100 Subject: [PATCH 11/12] CLI fixes & USDTieredSTO Sim test --- CLI/commands/ST20Generator.js | 55 +++++++++++++++------------- CLI/commands/investor_portal.js | 30 +++++++-------- test/q_usd_tiered_sto_sim.js | 65 ++++++++++++++++++++++++++++++--- 3 files changed, 103 insertions(+), 47 deletions(-) diff --git a/CLI/commands/ST20Generator.js b/CLI/commands/ST20Generator.js index be0a2951c..c13ee3bdb 100644 --- a/CLI/commands/ST20Generator.js +++ b/CLI/commands/ST20Generator.js @@ -43,14 +43,14 @@ async function executeApp(tokenConfig, mintingConfig, stoConfig, remoteNetwork) _stoConfig = stoConfig; await global.initialize(remoteNetwork); - + common.logAsciiBull(); console.log("********************************************"); console.log("Welcome to the Command-Line ST-20 Generator."); console.log("********************************************"); console.log("The following script will create a new ST-20 according to the parameters you enter."); console.log("Issuer Account: " + Issuer.address + "\n"); - + await setup(); try { @@ -84,7 +84,7 @@ async function setup(){ cappedSTOFactory.setProvider(web3.currentProvider); usdTieredSTOFactoryAddress = await contracts.usdTieredSTOFactoryAddress(); - let usdTieredSTOFactoryABI = abis.cappedSTO(); + let usdTieredSTOFactoryABI = abis.usdTieredSTOFactory(); usdTieredSTOFactory = new web3.eth.Contract(usdTieredSTOFactoryABI, usdTieredSTOFactoryAddress); usdTieredSTOFactory.setProvider(web3.currentProvider); } catch (err) { @@ -103,11 +103,11 @@ async function step_ticker_reg(){ while (!available) { console.log(chalk.green(`\nRegistering the new token symbol requires 250 POLY & deducted from '${Issuer.address}', Current balance is ${(await currentBalance(Issuer.address))} POLY\n`)); - + if (typeof _tokenConfig !== 'undefined' && _tokenConfig.hasOwnProperty('symbol')) { tokenSymbol = _tokenConfig.symbol; } else { - tokenSymbol = readlineSync.question('Enter the symbol for your new token: '); + tokenSymbol = readlineSync.question('Enter the symbol for your new token: '); } await securityTokenRegistry.methods.getTickerDetails(tokenSymbol).call({}, function(error, result){ @@ -162,17 +162,17 @@ async function step_token_deploy(){ console.log(chalk.green(`Current balance in POLY is ${(await currentBalance(Issuer.address))}`)); console.log("\n"); console.log('\x1b[34m%s\x1b[0m',"Token Creation - Token Deployment"); - + if (typeof _tokenConfig !== 'undefined' && _tokenConfig.hasOwnProperty('name')) { tokenName = _tokenConfig.name; } else { tokenName = readlineSync.question('Enter the name for your new token: '); } if (tokenName == "") tokenName = 'default'; - + console.log("\n"); console.log('\x1b[34m%s\x1b[0m',"Select the Token divisibility type"); - + let divisibility; if (typeof _tokenConfig !== 'undefined' && _tokenConfig.hasOwnProperty('divisible')) { divisibility = _tokenConfig.divisible; @@ -211,7 +211,7 @@ async function step_Wallet_Issuance(){ console.log('\x1b[34m%s\x1b[0m',"Token Creation - Token Minting for Issuer"); console.log("Before setting up the STO, you can mint any amount of tokens that will remain under your control or you can trasfer to affiliates"); - + let multimint; if (typeof _mintingConfig !== 'undefined' && _mintingConfig.hasOwnProperty('multimint')) { multimint = _mintingConfig.multimint; @@ -224,7 +224,7 @@ async function step_Wallet_Issuance(){ let generalTransferManagerAddress = (await securityToken.methods.getModulesByName(web3.utils.toHex('GeneralTransferManager')).call())[0]; let generalTransferManagerABI = abis.generalTransferManager(); generalTransferManager = new web3.eth.Contract(generalTransferManagerABI,generalTransferManagerAddress); - + if (multimint) await multi_mint_tokens(); else { @@ -253,7 +253,7 @@ async function step_Wallet_Issuance(){ issuerTokens = readlineSync.question('How many tokens do you plan to mint for the wallet you entered? (500.000): '); } if (issuerTokens == "") issuerTokens = '500000'; - + let mintAction = securityToken.methods.mint(mintWallet, web3.utils.toWei(issuerTokens,"ether")); await common.sendTransaction(Issuer, mintAction, defaultGasPrice); } @@ -403,7 +403,7 @@ async function cappedSTO_launch() { raiseType = readlineSync.question('Enter' + chalk.green(` P `) + 'for POLY raise or leave empty for Ether raise (E):'); if (raiseType.toUpperCase() == 'P' ) { raiseType = [1]; - } else { + } else { raiseType = [0]; } } @@ -446,7 +446,7 @@ async function cappedSTO_launch() { let receipt = await common.sendTransaction(Issuer, addModuleAction, defaultGasPrice); let event = common.getEventFromLogs(securityToken._jsonInterface, receipt.logs, 'LogModuleAdded'); console.log(`STO deployed at address: ${event._module}`); - + STO_Address = event._module; let cappedSTOABI = abis.cappedSTO(); currentSTO = new web3.eth.Contract(cappedSTOABI, STO_Address); @@ -461,7 +461,7 @@ async function cappedSTO_status() { let displayRaiseType; let displayFundsRaised; let displayWalletBalance; - let raiseType = await currentSTO.methods.fundRaiseType(0).call(); + let raiseType = await currentSTO.methods.fundRaiseTypes(0).call(); if (raiseType) { displayRaiseType = 'ETH'; displayFundsRaised = await currentSTO.methods.fundsRaisedETH().call(); @@ -523,7 +523,7 @@ function fundingConfigUSDTieredSTO() { if (typeof _stoConfig !== 'undefined' && _stoConfig.hasOwnProperty('fundingType')) { selectedFunding = _stoConfig.fundingType; } else { - selectedFunding = readlineSync.question('Enter' + chalk.green(` P `) + 'for POLY raise,' + chalk.green(` E `) + 'for Ether raise or' + chalk.green(` B `) + 'for both (B): ').toUpperCase(); + selectedFunding = readlineSync.question('Enter' + chalk.green(` P `) + 'for POLY raise,' + chalk.green(` D `) + 'for DAI raise,' + chalk.green(` E `) + 'for Ether raise or' + chalk.green(` A `) + 'for all (A): ').toUpperCase(); } if (selectedFunding == 'E') { @@ -532,8 +532,11 @@ function fundingConfigUSDTieredSTO() { else if (selectedFunding == 'P') { funding.raiseType = [1]; } + else if (selectedFunding == 'D') { + funding.raiseType = [2]; + } else { - funding.raiseType = [0, 1]; + funding.raiseType = [0, 1, 2]; } return funding; @@ -619,7 +622,7 @@ function tiersConfigUSDTieredSTO(polyRaise) { defaultInput: defaultRatePerTier[i] })); } - + let isTPTDPDefined = (typeof _stoConfig !== 'undefined' && _stoConfig.hasOwnProperty('discountedTokensPerTiers') && i < _stoConfig.discountedTokensPerTiers.length); //If it's defined by config file let isRPTDPDefined = (typeof _stoConfig !== 'undefined' && _stoConfig.hasOwnProperty('discountedRatePerTiers') && i < _stoConfig.discountedRatePerTiers.length); //If it's defined by config file //If funds can be raised in POLY and discounts are defined in config file or are choosen by user @@ -635,7 +638,7 @@ function tiersConfigUSDTieredSTO(polyRaise) { defaultInput: defaultTokensPerTierDiscountPoly[i] })); } - + if (isRPTDPDefined) { tiers.ratePerTierDiscountPoly[i] = web3.utils.toWei(_stoConfig.discountedRatePerTiers[i].toString()); } else { @@ -744,7 +747,7 @@ async function usdTieredSTO_launch() { console.log(`Number of POLY sent: ${web3.utils.fromWei(new web3.utils.BN(event._value))}`) } } - + let funding = fundingConfigUSDTieredSTO(); let addresses = addressesConfigUSDTieredSTO(); let tiers = tiersConfigUSDTieredSTO(funding.raiseType.includes(1)); @@ -807,7 +810,7 @@ async function usdTieredSTO_launch() { let receipt = await common.sendTransaction(Issuer, addModuleAction, defaultGasPrice); let event = common.getEventFromLogs(securityToken._jsonInterface, receipt.logs, 'LogModuleAdded'); console.log(`STO deployed at address: ${event._module}`); - + STO_Address = event._module; let usdTieredSTOABI = abis.usdTieredSTO(); currentSTO = new web3.eth.Contract(usdTieredSTOABI,STO_Address); @@ -819,8 +822,8 @@ async function usdTieredSTO_status() { let displayCurrentTier = parseInt(await currentSTO.methods.currentTier().call()) + 1; let displayNonAccreditedLimitUSD = web3.utils.fromWei(await currentSTO.methods.nonAccreditedLimitUSD().call()); let displayMinimumInvestmentUSD = web3.utils.fromWei(await currentSTO.methods.minimumInvestmentUSD().call()); - let ethRaise = await currentSTO.methods.fundRaiseType(0).call(); - let polyRaise = await currentSTO.methods.fundRaiseType(1).call(); + let ethRaise = await currentSTO.methods.fundRaiseTypes(0).call(); + let polyRaise = await currentSTO.methods.fundRaiseTypes(1).call(); let displayWallet = await currentSTO.methods.wallet().call(); let displayReserveWallet = await currentSTO.methods.reserveWallet().call(); let displayTokensSold = web3.utils.fromWei(await currentSTO.methods.getTokensSold().call()); @@ -1001,8 +1004,8 @@ async function usdTieredSTO_configure() { console.log(chalk.red(`STO is finalized`)); } else { let options = []; - options.push('Finalize STO', - 'Change accredited account', 'Change accredited in batch', + options.push('Finalize STO', + 'Change accredited account', 'Change accredited in batch', 'Change non accredited limit for an account', 'Change non accredited limits in batch'); // If STO is not started, you can modify configuration @@ -1020,7 +1023,7 @@ async function usdTieredSTO_configure() { let reserveWallet = await currentSTO.methods.reserveWallet().call(); let isVerified = await generalTransferManager.methods.verifyTransfer(STO_Address, reserveWallet, 0, false).call(); if (isVerified == "2") { - if (readlineSync.keyInYNStrict()) { + if (readlineSync.keyInYNStrict()) { let finalizeAction = currentSTO.methods.finalize(); await common.sendTransaction(Issuer, finalizeAction, defaultGasPrice); } @@ -1102,7 +1105,7 @@ async function modfifyAddresses() { } async function modfifyTiers() { - let tiers = tiersConfigUSDTieredSTO(await currentSTO.methods.fundRaiseType(1).call()); + let tiers = tiersConfigUSDTieredSTO(await currentSTO.methods.fundRaiseTypes(1).call()); let modifyTiersAction = currentSTO.methods.modifyTiers( tiers.ratePerTier, tiers.ratePerTierDiscountPoly, diff --git a/CLI/commands/investor_portal.js b/CLI/commands/investor_portal.js index 5437b06f4..4b6e11129 100644 --- a/CLI/commands/investor_portal.js +++ b/CLI/commands/investor_portal.js @@ -104,7 +104,7 @@ async function inputSymbol(symbol) { } else { STSymbol = symbol; } - + if (STSymbol == "") process.exit(); STAddress = await securityTokenRegistry.methods.getSecurityTokenAddress(STSymbol).call(); @@ -169,8 +169,8 @@ async function investUsdTieredSTO(currency, amount) { if (typeof amount === 'undefined') { let investorInvestedUSD = web3.utils.fromWei(await currentSTO.methods.investorInvestedUSD(User.address).call()); let minimumInvestmentUSD = await currentSTO.methods.minimumInvestmentUSD().call(); - let minimumInvestmentRaiseType = await currentSTO.methods.convertFromUSD(web3.utils.fromAscii(raiseType), minimumInvestmentUSD).call(); - cost = readlineSync.question(chalk.yellow(`Enter the amount of ${raiseType} you would like to invest or press 'Enter' to exit: `), { + let minimumInvestmentRaiseType = await currentSTO.methods.convertFromUSD(web3.utils.fromAscii(raiseType), minimumInvestmentUSD).call(); + cost = readlineSync.question(chalk.yellow(`Enter the amount of ${raiseType} you would like to invest or press 'Enter' to exit: `), { limit: function(input) { return investorInvestedUSD != 0 || input > web3.utils.fromWei(minimumInvestmentRaiseType); }, @@ -229,7 +229,7 @@ async function investCappedSTO(currency, amount) { let costWei = web3.utils.toWei(cost.toString()); if (displayRaiseType == 'POLY') { - let userBalance = await polyBalance(User.address); + let userBalance = await polyBalance(User.address); if (parseInt(userBalance) >= parseInt(cost)) { let allowance = await polyToken.methods.allowance(STOAddress, User.address).call(); if (allowance < costWei) { @@ -279,17 +279,17 @@ async function showTokenInfo() { async function showUserInfoForUSDTieredSTO() { - if (await currentSTO.methods.fundRaiseType(0).call()) { + if (await currentSTO.methods.fundRaiseTypes(0).call()) { let displayInvestorInvestedETH = web3.utils.fromWei(await currentSTO.methods.investorInvestedETH(User.address).call()); console.log(` - Invested in ETH: ${displayInvestorInvestedETH} ETH`); } - if (await currentSTO.methods.fundRaiseType(1).call()) { + if (await currentSTO.methods.fundRaiseTypes(1).call()) { let displayInvestorInvestedPOLY = web3.utils.fromWei(await currentSTO.methods.investorInvestedPOLY(User.address).call()); console.log(` - Invested in POLY: ${displayInvestorInvestedPOLY} POLY`); } let displayInvestorInvestedUSD = web3.utils.fromWei(await currentSTO.methods.investorInvestedUSD(User.address).call()); console.log(` - Invested in USD: ${displayInvestorInvestedUSD} USD`); - + await generalTransferManager.methods.whitelist(User.address).call({}, function(error, result){ displayCanBuy = result.canBuyFromSTO; }); @@ -297,7 +297,7 @@ async function showUserInfoForUSDTieredSTO() let displayIsUserAccredited = await currentSTO.methods.accredited(User.address).call(); console.log(` - Accredited: ${(displayIsUserAccredited)?"YES":"NO"}`) - + if (!await currentSTO.methods.accredited(User.address).call()) { let displayOverrideNonAccreditedLimitUSD = web3.utils.fromWei(await currentSTO.methods.nonAccreditedLimitUSDOverride(User.address).call()) let displayNonAccreditedLimitUSD = displayOverrideNonAccreditedLimitUSD != 0 ? displayOverrideNonAccreditedLimitUSD : web3.utils.fromWei(await currentSTO.methods.nonAccreditedLimitUSD().call()); @@ -313,15 +313,15 @@ async function showUSDTieredSTOInfo() { let displayCurrentTier = parseInt(await currentSTO.methods.currentTier().call()) + 1; let displayNonAccreditedLimitUSD = web3.utils.fromWei(await currentSTO.methods.nonAccreditedLimitUSD().call()); let displayMinimumInvestmentUSD = web3.utils.fromWei(await currentSTO.methods.minimumInvestmentUSD().call()); - let ethRaise = await currentSTO.methods.fundRaiseType(0).call(); - let polyRaise = await currentSTO.methods.fundRaiseType(1).call(); + let ethRaise = await currentSTO.methods.fundRaiseTypes(0).call(); + let polyRaise = await currentSTO.methods.fundRaiseTypes(1).call(); let displayTokensSold = web3.utils.fromWei(await currentSTO.methods.getTokensSold().call()); let displayInvestorCount = await currentSTO.methods.investorCount().call(); let displayIsFinalized = await currentSTO.methods.isFinalized().call(); let displayIsOpen = await currentSTO.methods.isOpen().call(); let displayTokenSymbol = await securityToken.methods.symbol().call(); - let tiersLength = await currentSTO.methods.getNumberOfTiers().call(); + let tiersLength = await currentSTO.methods.investorCount().call(); let displayTiers = ""; let displayMintedPerTier = ""; @@ -333,7 +333,7 @@ async function showUSDTieredSTOInfo() { let displayMintedPerTierETH = ""; if (ethRaise) { let mintedPerTierETH = await currentSTO.methods.mintedPerTierETH(t).call(); - + displayMintedPerTierETH = ` Sold for ETH: ${web3.utils.fromWei(mintedPerTierETH)} ${displayTokenSymbol}` } @@ -367,7 +367,7 @@ async function showUSDTieredSTOInfo() { Rate: ${web3.utils.fromWei(ratePerTier, 'ether')} USD per Token` + displayDiscountTokens; displayMintedPerTier = displayMintedPerTier + ` - - Tokens minted in Tier ${t+1}: ${web3.utils.fromWei(mintedPerTierTotal)} ${displayTokenSymbol}` + - Tokens minted in Tier ${t+1}: ${web3.utils.fromWei(mintedPerTierTotal)} ${displayTokenSymbol}` + displayMintedPerTierETH + displayMintedPerTierPOLY;} @@ -379,7 +379,7 @@ async function showUSDTieredSTOInfo() { let fundsRaisedETH = web3.utils.fromWei(await currentSTO.methods.fundsRaisedETH().call()); displayFundsRaisedETH = ` ETH: ${fundsRaisedETH} ETH`; - + //Only show sold for ETH if POLY raise is allowed too if (polyRaise) { let tokensSoldETH = web3.utils.fromWei(await currentSTO.methods.getTokensSoldForETH().call()); @@ -471,7 +471,7 @@ async function showCappedSTOInfo() { let displayTokensRemaining = web3.utils.fromWei(displayCap) - web3.utils.fromWei(displayTokensSold); let displayFundsRaised; - if (await currentSTO.methods.fundRaiseType(0).call()) { + if (await currentSTO.methods.fundRaiseTypes(0).call()) { displayRaiseType = 'ETH'; displayFundsRaised = await currentSTO.methods.fundsRaisedETH().call(); } else { diff --git a/test/q_usd_tiered_sto_sim.js b/test/q_usd_tiered_sto_sim.js index 5407663bd..c12737967 100644 --- a/test/q_usd_tiered_sto_sim.js +++ b/test/q_usd_tiered_sto_sim.js @@ -355,7 +355,7 @@ contract('USDTieredSTO Sim', accounts => { ]); // [ 0 Token, 1000 Token, 1500 Token ] _nonAccreditedLimitUSD.push(BigNumber(10*10**18)); // 20 USD _minimumInvestmentUSD.push(BigNumber(0)); // 1 wei USD - _fundRaiseTypes.push([0,1]); + _fundRaiseTypes.push([0,1,2]); _wallet.push(WALLET); _reserveWallet.push(RESERVEWALLET); _usdToken.push(I_DaiToken.address); @@ -485,12 +485,14 @@ contract('USDTieredSTO Sim', accounts => { } let log_remaining = USD_remaining; - let isPoly = Math.random() >= 0.5; + let isPoly = Math.random() >= 0.33; + let isDai = Math.random() >= 0.33; let Token_counter = BigNumber(getRandomInt(1*10**10,50*10**10)).mul(10**8); let investment_USD = BigNumber(0); let investment_ETH = BigNumber(0); let investment_POLY = BigNumber(0); + let investment_DAI = BigNumber(0); let investment_Token = BigNumber(0); let Tokens_total = []; @@ -505,6 +507,8 @@ contract('USDTieredSTO Sim', accounts => { let USD_Tier; let POLY_Tier; let ETH_Tier; + let DAI_Tier; + let USD_overflow; let Token_overflow; @@ -554,8 +558,26 @@ contract('USDTieredSTO Sim', accounts => { investment_USD = investment_USD.add(USD_Tier); investment_POLY = investment_POLY.add(POLY_Tier); } + } else if (isDai) { + // 3. DAI (consume up to cap then skip to next tier) + Token_Tier = BigNumber.min([Tokens_total[tier], Token_counter]); + USD_Tier = Token_Tier.mul(_ratePerTier[stoId][tier].div(10**18)); + if (USD_Tier.gte(USD_remaining)) { + USD_overflow = USD_Tier.sub(USD_remaining); + Token_overflow = USD_overflow.mul(10**18).div(_ratePerTier[stoId][tier]); + USD_Tier = USD_Tier.sub(USD_overflow); + Token_Tier = Token_Tier.sub(Token_overflow); + Token_counter = BigNumber(0); + } + DAI_Tier = USD_Tier.round(0); + USD_remaining = USD_remaining.sub(USD_Tier); + Tokens_total[tier] = Tokens_total[tier].sub(Token_Tier); + Token_counter = Token_counter.sub(Token_Tier); + investment_Token = investment_Token.add(Token_Tier); + investment_USD = investment_USD.add(USD_Tier); + investment_DAI = investment_USD; } else { - // 3. ETH (consume up to cap then skip to next tier) + // 4. ETH (consume up to cap then skip to next tier) Token_Tier = BigNumber.min([Tokens_total[tier], Token_counter]); USD_Tier = Token_Tier.mul(_ratePerTier[stoId][tier].div(10**18)); if (USD_Tier.gte(USD_remaining)) { @@ -577,7 +599,7 @@ contract('USDTieredSTO Sim', accounts => { tier++ } - await processInvestment(_investor, investment_Token, investment_USD, investment_POLY, investment_ETH, isPoly, log_remaining, Tokens_total, Tokens_discount, tokensSold); + await processInvestment(_investor, investment_Token, investment_USD, investment_POLY, investment_DAI, investment_ETH, isPoly, isDai, log_remaining, Tokens_total, Tokens_discount, tokensSold); } async function investFAIL(_investor) { @@ -596,7 +618,7 @@ contract('USDTieredSTO Sim', accounts => { } else if (isDAI) { await I_DaiToken.getTokens(investment_DAI, _investor); await I_DaiToken.approve(I_USDTieredSTO_Array[stoId].address, investment_DAI, {from: _investor}); - await I_USDTieredSTO_Array[stoId].buyWithUSD(_investor, investment_DAI, { from: _investor, gasPrice: GAS_PRICE }); + await I_USDTieredSTO_Array[stoId].buyWithUSD(_investor, investment_DAI, { from: _investor, gasPrice: GAS_PRICE }); } else await I_USDTieredSTO_Array[stoId].buyWithETH(_investor, { from: _investor, value: investment_ETH, gasPrice: GAS_PRICE }); } catch(error) { errorThrown = true; @@ -606,10 +628,11 @@ contract('USDTieredSTO Sim', accounts => { assert.ok(errorThrown, MESSAGE); } - async function processInvestment(_investor, investment_Token, investment_USD, investment_POLY, investment_ETH, isPoly, log_remaining, Tokens_total, Tokens_discount, tokensSold) { + async function processInvestment(_investor, investment_Token, investment_USD, investment_POLY, investment_DAI, investment_ETH, isPoly, isDai, log_remaining, Tokens_total, Tokens_discount, tokensSold) { investment_Token = investment_Token.round(0); investment_USD = investment_USD.round(0); investment_POLY = investment_POLY.round(0); + investment_DAI = investment_DAI.round(0); investment_ETH = investment_ETH.round(0); console.log(` ------------------- New Investment ------------------- @@ -621,6 +644,7 @@ contract('USDTieredSTO Sim', accounts => { Token Investment: ${investment_Token.div(10**18)} USD Investment: ${investment_USD.div(10**18)} POLY Investment: ${investment_POLY.div(10**18)} + DAI Investment: ${investment_DAI.div(10**18)} ETH Investment: ${investment_ETH.div(10**18)} ------------------------------------------------------ `); @@ -628,6 +652,9 @@ contract('USDTieredSTO Sim', accounts => { if (isPoly) { await I_PolyToken.getTokens(investment_POLY, _investor); await I_PolyToken.approve(I_USDTieredSTO_Array[stoId].address, investment_POLY, {from: _investor}); + } else if (isDai) { + await I_DaiToken.getTokens(investment_DAI, _investor); + await I_DaiToken.approve(I_USDTieredSTO_Array[stoId].address, investment_DAI, {from: _investor}); } // console.log(await I_USDTieredSTO_Array[stoId].isOpen()); @@ -636,14 +663,18 @@ contract('USDTieredSTO Sim', accounts => { let init_InvestorTokenBal = await I_SecurityToken.balanceOf(_investor); let init_InvestorETHBal = BigNumber(await web3.eth.getBalance(_investor)); let init_InvestorPOLYBal = await I_PolyToken.balanceOf(_investor); + let init_InvestorDAIBal = await I_DaiToken.balanceOf(_investor); let init_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let init_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let init_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); + let init_STODAIBal = await I_DaiToken.balanceOf(I_USDTieredSTO_Array[stoId].address); let init_RaisedUSD = await I_USDTieredSTO_Array[stoId].fundsRaisedUSD.call(); let init_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(0); let init_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(1); + let init_RaisedDAI = await I_USDTieredSTO_Array[stoId].fundsRaised.call(2); let init_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let init_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); + let init_WalletDAIBal = await I_DaiToken.balanceOf(WALLET); let tx; let gasCost = BigNumber(0); @@ -652,24 +683,33 @@ contract('USDTieredSTO Sim', accounts => { tx = await I_USDTieredSTO_Array[stoId].buyWithPOLY(_investor, investment_POLY, { from: _investor, gasPrice: GAS_PRICE }); gasCost = BigNumber(GAS_PRICE).mul(tx.receipt.gasUsed); console.log(`buyWithPOLY: ${investment_Token.div(10**18)} tokens for ${investment_POLY.div(10**18)} POLY by ${_investor}`.yellow); + } else if (isDai && investment_DAI.gt(10)) { + tx = await I_USDTieredSTO_Array[stoId].buyWithUSD(_investor, investment_DAI, { from: _investor, gasPrice: GAS_PRICE }); + gasCost = BigNumber(GAS_PRICE).mul(tx.receipt.gasUsed); + console.log(`buyWithUSD: ${investment_Token.div(10**18)} tokens for ${investment_DAI.div(10**18)} DAI by ${_investor}`.yellow); } else if (investment_ETH.gt(0)) { tx = await I_USDTieredSTO_Array[stoId].buyWithETH(_investor, { from: _investor, value: investment_ETH, gasPrice: GAS_PRICE }); gasCost = BigNumber(GAS_PRICE).mul(tx.receipt.gasUsed); console.log(`buyWithETH: ${investment_Token.div(10**18)} tokens for ${investment_ETH.div(10**18)} ETH by ${_investor}`.yellow); } + console.log(investment_POLY.toNumber()); let final_TokenSupply = await I_SecurityToken.totalSupply(); let final_InvestorTokenBal = await I_SecurityToken.balanceOf(_investor); let final_InvestorETHBal = BigNumber(await web3.eth.getBalance(_investor)); let final_InvestorPOLYBal = await I_PolyToken.balanceOf(_investor); + let final_InvestorDAIBal = await I_DaiToken.balanceOf(_investor); let final_STOTokenSold = await I_USDTieredSTO_Array[stoId].getTokensSold(); let final_STOETHBal = BigNumber(await web3.eth.getBalance(I_USDTieredSTO_Array[stoId].address)); let final_STOPOLYBal = await I_PolyToken.balanceOf(I_USDTieredSTO_Array[stoId].address); + let final_STODAIBal = await I_DaiToken.balanceOf(I_USDTieredSTO_Array[stoId].address); let final_RaisedUSD = await I_USDTieredSTO_Array[stoId].fundsRaisedUSD.call(); let final_RaisedETH = await I_USDTieredSTO_Array[stoId].fundsRaised.call(0); let final_RaisedPOLY = await I_USDTieredSTO_Array[stoId].fundsRaised.call(1); + let final_RaisedDAI = await I_USDTieredSTO_Array[stoId].fundsRaised.call(2); let final_WalletETHBal = BigNumber(await web3.eth.getBalance(WALLET)); let final_WalletPOLYBal = await I_PolyToken.balanceOf(WALLET); + let final_WalletDAIBal = await I_DaiToken.balanceOf(WALLET); // console.log('init_TokenSupply: '+init_TokenSupply.div(10**18).toNumber()); // console.log('final_TokenSupply: '+final_TokenSupply.div(10**18).toNumber()); @@ -687,6 +727,19 @@ contract('USDTieredSTO Sim', accounts => { assert.closeTo(final_RaisedPOLY.toNumber(), init_RaisedPOLY.add(investment_POLY).toNumber(), TOLERANCE, "Raised POLY not changed as expected"); assert.closeTo(final_WalletETHBal.toNumber(), init_WalletETHBal.toNumber(), TOLERANCE, "Wallet ETH Balance not changed as expected"); assert.closeTo(final_WalletPOLYBal.toNumber(), init_WalletPOLYBal.add(investment_POLY).toNumber(), TOLERANCE, "Wallet POLY Balance not changed as expected"); + } else if (isDai) { + assert.closeTo(final_TokenSupply.toNumber(), init_TokenSupply.add(investment_Token).toNumber(), TOLERANCE, "Token Supply not changed as expected"); + assert.closeTo(final_InvestorTokenBal.toNumber(), init_InvestorTokenBal.add(investment_Token).toNumber(), TOLERANCE, "Investor Token Balance not changed as expected"); + assert.closeTo(final_InvestorETHBal.toNumber(), init_InvestorETHBal.sub(gasCost).toNumber(), TOLERANCE, "Investor ETH Balance not changed as expected"); + assert.closeTo(final_InvestorDAIBal.toNumber(), init_InvestorDAIBal.sub(investment_DAI).toNumber(), TOLERANCE, "Investor DAI Balance not changed as expected"); + assert.closeTo(final_STOTokenSold.toNumber(), init_STOTokenSold.add(investment_Token).toNumber(), TOLERANCE, "STO Token Sold not changed as expected"); + assert.closeTo(final_STOETHBal.toNumber(), init_STOETHBal.toNumber(), TOLERANCE, "STO ETH Balance not changed as expected"); + assert.closeTo(final_STODAIBal.toNumber(), init_STODAIBal.toNumber(), TOLERANCE, "STO DAI Balance not changed as expected"); + assert.closeTo(final_RaisedUSD.toNumber(), init_RaisedUSD.add(investment_USD).toNumber(), TOLERANCE, "Raised USD not changed as expected"); + assert.closeTo(final_RaisedETH.toNumber(), init_RaisedETH.toNumber(), TOLERANCE, "Raised ETH not changed as expected"); + assert.closeTo(final_RaisedDAI.toNumber(), init_RaisedDAI.add(investment_DAI).toNumber(), TOLERANCE, "Raised DAI not changed as expected"); + assert.closeTo(final_WalletETHBal.toNumber(), init_WalletETHBal.toNumber(), TOLERANCE, "Wallet ETH Balance not changed as expected"); + assert.closeTo(final_WalletDAIBal.toNumber(), init_WalletDAIBal.add(investment_DAI).toNumber(), TOLERANCE, "Wallet DAI Balance not changed as expected"); } else { assert.closeTo(final_TokenSupply.toNumber(), init_TokenSupply.add(investment_Token).toNumber(), TOLERANCE, "Token Supply not changed as expected"); assert.closeTo(final_InvestorTokenBal.toNumber(), init_InvestorTokenBal.add(investment_Token).toNumber(), TOLERANCE, "Investor Token Balance not changed as expected"); From 475544f979fe9177c526430ee6dc133538e1e23f Mon Sep 17 00:00:00 2001 From: Adam Dossa Date: Thu, 20 Sep 2018 22:55:18 +0100 Subject: [PATCH 12/12] CLI fixes --- CLI/commands/ST20Generator.js | 90 +++++++++++++++++----- CLI/commands/helpers/contract_addresses.js | 5 ++ contracts/modules/STO/USDTieredSTO.sol | 4 +- 3 files changed, 78 insertions(+), 21 deletions(-) diff --git a/CLI/commands/ST20Generator.js b/CLI/commands/ST20Generator.js index c13ee3bdb..0588e7b27 100644 --- a/CLI/commands/ST20Generator.js +++ b/CLI/commands/ST20Generator.js @@ -22,10 +22,14 @@ const regFee = 250; const cappedSTOFee = 20000; const usdTieredSTOFee = 100000; const tokenDetails = ""; +const ETH = 0; +const POLY = 1; +const DAI = 2; //////////////////////// // Artifacts let securityTokenRegistry; let polyToken; +let daiToken; let securityToken; let generalTransferManager; let currentSTO; @@ -78,6 +82,10 @@ async function setup(){ polyToken = new web3.eth.Contract(polytokenABI, polytokenAddress); polyToken.setProvider(web3.currentProvider); + //TODO: Use proper DAI token here + daiToken = new web3.eth.Contract(polytokenABI, polytokenAddress); + daiToken.setProvider(web3.currentProvider); + cappedSTOFactoryAddress = await contracts.cappedSTOFactoryAddress(); let cappedSTOFactoryABI = abis.cappedSTOFactory(); cappedSTOFactory = new web3.eth.Contract(cappedSTOFactoryABI, cappedSTOFactoryAddress); @@ -464,11 +472,11 @@ async function cappedSTO_status() { let raiseType = await currentSTO.methods.fundRaiseTypes(0).call(); if (raiseType) { displayRaiseType = 'ETH'; - displayFundsRaised = await currentSTO.methods.fundsRaisedETH().call(); + displayFundsRaised = await currentSTO.methods.fundsRaised(ETH).call(); displayWalletBalance = web3.utils.fromWei(await web3.eth.getBalance(displayWallet)); } else { displayRaiseType = 'POLY'; - displayFundsRaised = await currentSTO.methods.fundsRaisedPOLY().call(); + displayFundsRaised = await currentSTO.methods.fundsRaised(POLY).call(); displayWalletBalance = await currentBalance(displayWallet); } let displayTokensSold = await currentSTO.methods.totalTokensSold().call(); @@ -753,7 +761,7 @@ async function usdTieredSTO_launch() { let tiers = tiersConfigUSDTieredSTO(funding.raiseType.includes(1)); let limits = limitsConfigUSDTieredSTO(); let times = timesConfigUSDTieredSTO(); - + let polytokenAddress = await contracts.polyToken(); let bytesSTO = web3.eth.abi.encodeFunctionCall( { name: 'configure', type: 'function', @@ -791,6 +799,9 @@ async function usdTieredSTO_launch() { },{ type: 'address', name: '_reserveWallet' + },{ + type: 'address', + name: '_usdToken' } ] }, [times.startTime, @@ -803,7 +814,8 @@ async function usdTieredSTO_launch() { limits.minimumInvestmentUSD, funding.raiseType, addresses.wallet, - addresses.reserveWallet + addresses.reserveWallet, + polytokenAddress ]); let addModuleAction = securityToken.methods.addModule(usdTieredSTOFactoryAddress, bytesSTO, new BigNumber(stoFee).times(new BigNumber(10).pow(18)), 0); @@ -824,6 +836,7 @@ async function usdTieredSTO_status() { let displayMinimumInvestmentUSD = web3.utils.fromWei(await currentSTO.methods.minimumInvestmentUSD().call()); let ethRaise = await currentSTO.methods.fundRaiseTypes(0).call(); let polyRaise = await currentSTO.methods.fundRaiseTypes(1).call(); + let daiRaise = await currentSTO.methods.fundRaiseTypes(2).call(); let displayWallet = await currentSTO.methods.wallet().call(); let displayReserveWallet = await currentSTO.methods.reserveWallet().call(); let displayTokensSold = web3.utils.fromWei(await currentSTO.methods.getTokensSold().call()); @@ -842,11 +855,17 @@ async function usdTieredSTO_status() { let displayMintedPerTierETH = ""; if (ethRaise) { - let mintedPerTierETH = await currentSTO.methods.mintedPerTierETH(t).call(); + let mintedPerTierETH = await currentSTO.methods.mintedPerTier(0, t).call(); displayMintedPerTierETH = ` Sold for ETH: ${web3.utils.fromWei(mintedPerTierETH)} ${displayTokenSymbol}` } + if (daiRaise) { + let mintedPerTierDAI = await currentSTO.methods.mintedPerTier(2, t).call(); + + displayMintedPerTierDAI = ` + Sold for DAI: ${web3.utils.fromWei(mintedPerTierDAI)} ${displayTokenSymbol}` + } let displayMintedPerTierPOLY = ""; let displayDiscountTokens = ""; @@ -865,7 +884,7 @@ async function usdTieredSTO_status() { displayDiscountMinted = `(${web3.utils.fromWei(mintedPerTierDiscountPoly)} ${displayTokenSymbol} at discounted rate)`; } - let mintedPerTierRegularPOLY = await currentSTO.methods.mintedPerTierRegularPoly(t).call(); + let mintedPerTierRegularPOLY = await currentSTO.methods.mintedPerTier(1, t).call(); let mintedPerTierPOLYTotal = new BigNumber(web3.utils.fromWei(mintedPerTierRegularPOLY)).add(new BigNumber(web3.utils.fromWei(mintedPerTierDiscountPoly))); displayMintedPerTierPOLY = ` Sold for POLY: ${mintedPerTierPOLYTotal} ${displayTokenSymbol} ${displayDiscountMinted}` @@ -879,7 +898,8 @@ async function usdTieredSTO_status() { displayMintedPerTier = displayMintedPerTier + ` - Tokens minted in Tier ${t+1}: ${web3.utils.fromWei(mintedPerTierTotal)} ${displayTokenSymbol}` + displayMintedPerTierETH - + displayMintedPerTierPOLY; + + displayMintedPerTierPOLY + + displayMintedPerTierDAI; } let displayFundsRaisedUSD = web3.utils.fromWei(await currentSTO.methods.fundsRaisedUSD().call()); @@ -891,24 +911,25 @@ async function usdTieredSTO_status() { if (ethRaise) { let balance = await web3.eth.getBalance(displayWallet); let walletBalanceETH = web3.utils.fromWei(balance, "ether"); - let walletBalanceETH_USD = web3.utils.fromWei(await currentSTO.methods.convertToUSD(web3.utils.fromAscii('ETH'), balance).call()); + let walletBalanceETH_USD = web3.utils.fromWei(await currentSTO.methods.convertToUSD(ETH, balance).call()); displayWalletBalanceETH = ` Balance ETH: ${walletBalanceETH} ETH (${walletBalanceETH_USD} USD)`; balance = await web3.eth.getBalance(displayReserveWallet); let reserveWalletBalanceETH = web3.utils.fromWei(balance,"ether"); - let reserveWalletBalanceETH_USD = web3.utils.fromWei(await currentSTO.methods.convertToUSD(web3.utils.fromAscii('ETH'), balance).call()); + let reserveWalletBalanceETH_USD = web3.utils.fromWei(await currentSTO.methods.convertToUSD(ETH, balance).call()); displayReserveWalletBalanceETH = ` Balance ETH: ${reserveWalletBalanceETH} ETH (${reserveWalletBalanceETH_USD} USD)`; - let fundsRaisedETH = web3.utils.fromWei(await currentSTO.methods.fundsRaisedETH().call()); + let fundsRaisedETH = web3.utils.fromWei(await currentSTO.methods.fundsRaised(ETH).call()); displayFundsRaisedETH = ` ETH: ${fundsRaisedETH} ETH`; - //Only show sold for ETH if POLY raise is allowed too - if (polyRaise) { - let tokensSoldETH = web3.utils.fromWei(await currentSTO.methods.getTokensSoldForETH().call()); + //Only show sold for ETH if POLY / DAI raise is allowed too + if (polyRaise || daiRaise) { + let tokensSoldETH = web3.utils.fromWei(await currentSTO.methods.getTokensSoldFor(0).call()); displayTokensSoldETH = ` Sold for ETH: ${tokensSoldETH} ${displayTokenSymbol}`; } + } let displayWalletBalancePOLY = ''; @@ -917,27 +938,54 @@ async function usdTieredSTO_status() { let displayTokensSoldPOLY = ''; if (polyRaise) { let walletBalancePOLY = await currentBalance(displayWallet); - let walletBalancePOLY_USD = web3.utils.fromWei(await currentSTO.methods.convertToUSD(web3.utils.fromAscii('POLY'), web3.utils.toWei(walletBalancePOLY.toString())).call()); + let walletBalancePOLY_USD = web3.utils.fromWei(await currentSTO.methods.convertToUSD(POLY, web3.utils.toWei(walletBalancePOLY.toString())).call()); displayWalletBalancePOLY = ` Balance POLY ${walletBalancePOLY} POLY (${walletBalancePOLY_USD} USD)`; let reserveWalletBalancePOLY = await currentBalance(displayReserveWallet); - let reserveWalletBalancePOLY_USD = web3.utils.fromWei(await currentSTO.methods.convertToUSD(web3.utils.fromAscii('POLY'), web3.utils.toWei(reserveWalletBalancePOLY.toString())).call()); + let reserveWalletBalancePOLY_USD = web3.utils.fromWei(await currentSTO.methods.convertToUSD(POLY, web3.utils.toWei(reserveWalletBalancePOLY.toString())).call()); displayReserveWalletBalancePOLY = ` Balance POLY ${reserveWalletBalancePOLY} POLY (${reserveWalletBalancePOLY_USD} USD)`; - let fundsRaisedPOLY = web3.utils.fromWei(await currentSTO.methods.fundsRaisedPOLY().call()); + let fundsRaisedPOLY = web3.utils.fromWei(await currentSTO.methods.fundsRaised(POLY).call()); displayFundsRaisedPOLY = ` POLY: ${fundsRaisedPOLY} POLY`; //Only show sold for POLY if ETH raise is allowed too - if (ethRaise) { - let tokensSoldPOLY = web3.utils.fromWei(await currentSTO.methods.getTokensSoldForPOLY().call()); + if (ethRaise || daiRaise) { + let tokensSoldPOLY = web3.utils.fromWei(await currentSTO.methods.getTokensSoldFor(1).call()); displayTokensSoldPOLY = ` Sold for POLY: ${tokensSoldPOLY} ${displayTokenSymbol}`; } } + let displayWalletBalanceDAI = ''; + let displayReserveWalletBalanceDAI = ''; + let displayFundsRaisedDAI = ''; + let displayTokensSoldDAI = ''; + if (daiRaise) { + let walletBalanceDAI = await currentBalance(displayWallet); + let walletBalanceDAI_USD = web3.utils.fromWei(await currentSTO.methods.convertToUSD(DAI, web3.utils.toWei(walletBalanceDAI.toString())).call()); + displayWalletBalanceDAI = ` + Balance DAI ${walletBalanceDAI} DAI (${walletBalanceDAI_USD} USD)`; + let reserveWalletBalanceDAI = await currentBalance(displayReserveWallet); + let reserveWalletBalanceDAI_USD = web3.utils.fromWei(await currentSTO.methods.convertToUSD(DAI, web3.utils.toWei(reserveWalletBalanceDAI.toString())).call()); + displayReserveWalletBalanceDAI = ` + Balance DAI ${reserveWalletBalanceDAI} DAI (${reserveWalletBalanceDAI_USD} USD)`; + let fundsRaisedDAI = web3.utils.fromWei(await currentSTO.methods.fundsRaised(DAI).call()); + displayFundsRaisedDAI = ` + DAI: ${fundsRaisedDAI} DAI`; + + //Only show sold for DAI if ETH raise is allowed too + if (ethRaise || polyRaise) { + let tokensSoldDAI = web3.utils.fromWei(await currentSTO.methods.getTokensSoldFor(1).call()); + displayTokensSoldDAI = ` + Sold for DAI: ${tokensSoldDAI} ${displayTokenSymbol}`; + } + } + let displayRaiseType; - if (ethRaise && polyRaise) { + if (daiRaise && ethRaise && polyRaise) { + displayRaiseType = "DAI and ETH and POLY"; + } else if (ethRaise && polyRaise) { displayRaiseType = "ETH and POLY"; } else if (ethRaise) { displayRaiseType = "ETH"; @@ -972,9 +1020,11 @@ async function usdTieredSTO_status() { - Non Accredited Limit: ${displayNonAccreditedLimitUSD} USD - Wallet: ${displayWallet}` + displayWalletBalanceETH + + displayWalletBalanceDAI + displayWalletBalancePOLY + ` - Reserve Wallet: ${displayReserveWallet}` + displayReserveWalletBalanceETH + + displayReserveWalletBalanceDAI + displayReserveWalletBalancePOLY + ` -------------------------------------- @@ -982,12 +1032,14 @@ async function usdTieredSTO_status() { - Is Finalized: ${displayIsFinalized} - Tokens Sold: ${displayTokensSold} ${displayTokenSymbol}` + displayTokensSoldETH + + displayTokensSoldDAI + displayTokensSoldPOLY + ` - Current Tier: ${displayCurrentTier}` + displayMintedPerTier + ` - Investor count: ${displayInvestorCount} - Funds Raised` + displayFundsRaisedETH + + displayFundsRaisedDAI + displayFundsRaisedPOLY + ` USD: ${displayFundsRaisedUSD} USD `); diff --git a/CLI/commands/helpers/contract_addresses.js b/CLI/commands/helpers/contract_addresses.js index c9e366581..199645f9a 100644 --- a/CLI/commands/helpers/contract_addresses.js +++ b/CLI/commands/helpers/contract_addresses.js @@ -77,6 +77,11 @@ module.exports = { else return JSON.parse(require('fs').readFileSync('./build/contracts/CappedSTOFactory.json').toString()).networks[networkId].address; }, + daiToken: async function() { + //TODO: Add a proper test DAI token here + let polymathRegistry = await getPolymathRegistry(); + return await polymathRegistry.methods.getAddress("PolyToken").call(); + }, usdTieredSTOFactoryAddress: async function() { let networkId = await web3.eth.net.getId(); if (networkId == 1) diff --git a/contracts/modules/STO/USDTieredSTO.sol b/contracts/modules/STO/USDTieredSTO.sol index c79461e64..16113c188 100644 --- a/contracts/modules/STO/USDTieredSTO.sol +++ b/contracts/modules/STO/USDTieredSTO.sol @@ -49,7 +49,7 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { uint256[] public mintedPerTierTotal; // How many tokens have been minted in each tier (relative to totalSupply) for each fund raise type - mapping (uint8 => uint256[]) mintedPerTier; + mapping (uint8 => uint256[]) public mintedPerTier; // How many tokens have been minted in each tier (relative to totalSupply) at discounted POLY rate uint256[] public mintedPerTierDiscountPoly; @@ -157,7 +157,7 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { * @param _fundRaiseTypes Types of currency used to collect the funds * @param _wallet Ethereum account address to hold the funds * @param _reserveWallet Ethereum account address to receive unsold tokens - * @param _usdToken Contract address of the stable coin + * @param _usdToken Contract address of the stable coin */ function configure( uint256 _startTime,