diff --git a/CLI/commands/ST20Generator.js b/CLI/commands/ST20Generator.js index be0a2951c..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; @@ -43,14 +47,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 { @@ -78,13 +82,17 @@ 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); 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 +111,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 +170,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 +219,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 +232,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 +261,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 +411,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 +454,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,14 +469,14 @@ 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(); + 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(); @@ -523,7 +531,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 +540,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 +630,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 +646,7 @@ function tiersConfigUSDTieredSTO(polyRaise) { defaultInput: defaultTokensPerTierDiscountPoly[i] })); } - + if (isRPTDPDefined) { tiers.ratePerTierDiscountPoly[i] = web3.utils.toWei(_stoConfig.discountedRatePerTiers[i].toString()); } else { @@ -744,13 +755,13 @@ 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)); let limits = limitsConfigUSDTieredSTO(); let times = timesConfigUSDTieredSTO(); - + let polytokenAddress = await contracts.polyToken(); let bytesSTO = web3.eth.abi.encodeFunctionCall( { name: 'configure', type: 'function', @@ -788,6 +799,9 @@ async function usdTieredSTO_launch() { },{ type: 'address', name: '_reserveWallet' + },{ + type: 'address', + name: '_usdToken' } ] }, [times.startTime, @@ -800,14 +814,15 @@ 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); 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 +834,9 @@ 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 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()); @@ -839,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 = ""; @@ -862,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}` @@ -876,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()); @@ -888,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 = ''; @@ -914,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"; @@ -969,9 +1020,11 @@ async function usdTieredSTO_status() { - Non Accredited Limit: ${displayNonAccreditedLimitUSD} USD - Wallet: ${displayWallet}` + displayWalletBalanceETH + + displayWalletBalanceDAI + displayWalletBalancePOLY + ` - Reserve Wallet: ${displayReserveWallet}` + displayReserveWalletBalanceETH + + displayReserveWalletBalanceDAI + displayReserveWalletBalancePOLY + ` -------------------------------------- @@ -979,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 `); @@ -1001,8 +1056,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 +1075,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 +1157,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/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/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/contracts/modules/STO/CappedSTO.sol b/contracts/modules/STO/CappedSTO.sol index cf1614c8e..5bd481280 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,27 +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 - */ - function getNumberInvestors() public view returns (uint256) { - return investorCount; - } - /** * @notice Return the total no. of tokens sold */ @@ -179,10 +157,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 +179,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..7205ca2a8 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 @@ -47,29 +44,12 @@ contract ISTO is Module, Pausable { } /** - * @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 + * @notice Return funds raised by the STO */ - function verifyInvestment(address _beneficiary, uint256 _fundsAmount) public view returns(bool) { - return polyToken.allowance(_beneficiary, address(this)) >= _fundsAmount; + function getRaised(FundRaiseType _fundRaiseType) public view returns (uint256) { + return fundsRaised[uint8(_fundRaiseType)]; } - /** - * @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); - - /** - * @notice Return the total no. of investors - */ - function getNumberInvestors() public view returns (uint256); - /** * @notice Return the total no. of tokens sold */ @@ -90,18 +70,16 @@ 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"); + 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[j] < 2); - fundRaiseType[_fundRaiseTypes[j]] = true; - } - if (fundRaiseType[uint8(FundRaiseType.POLY)]) { - require(address(polyToken) != address(0), "Address of the polyToken should not be 0x"); + 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..16113c188 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 usdToken; + // 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[]) public 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,13 +92,14 @@ 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); event SetAddresses( address indexed _wallet, - address indexed _reserveWallet + address indexed _reserveWallet, + address indexed _usdToken ); event SetLimits( uint256 _nonAccreditedLimitUSD, @@ -125,13 +122,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(_getOracle(bytes32("POLY"), bytes32("USD")) != address(0), "Invalid POLYUSD Oracle"); + require(fundRaiseTypes[uint8(FundRaiseType.POLY)]); + _; + } + + modifier validDAI { + require(fundRaiseTypes[uint8(FundRaiseType.DAI)]); _; } @@ -155,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, @@ -165,20 +168,29 @@ contract USDTieredSTO is ISTO, ReentrancyGuard { uint256[] _tokensPerTierDiscountPoly, uint256 _nonAccreditedLimitUSD, uint256 _minimumInvestmentUSD, - uint8[] _fundRaiseTypes, + FundRaiseType[] _fundRaiseTypes, address _wallet, - address _reserveWallet + address _reserveWallet, + address _usdToken ) public onlyFactory { modifyTimes(_startTime, _endTime); + // 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); } - function modifyFunding(uint8[] _fundRaiseTypes) public onlyFactoryOrOwner { + function modifyFunding(FundRaiseType[] _fundRaiseTypes) public onlyFactoryOrOwner { require(now < startTime); - _configureFunding(_fundRaiseTypes); + _setFundRaiseType(_fundRaiseTypes); + 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[](length); + } } function modifyLimits( @@ -208,10 +220,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; @@ -232,13 +240,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); } //////////////////// @@ -323,16 +336,16 @@ 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 spentUSD, uint256 spentValue) = _buyTokens(_beneficiary, msg.value, rate, false); + uint256 rate = getRate(FundRaiseType.ETH); + (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); } /** @@ -341,26 +354,42 @@ 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 spentUSD, uint256 spentValue) = _buyTokens(_beneficiary, _investedPOLY, rate, true); + _buyWithTokens(_beneficiary, _investedPOLY, FundRaiseType.POLY); + } + + /** + * @notice Purchase tokens using POLY + * @param _beneficiary Address where security tokens will be sent + * @param _investedDAI Amount of POLY invested + */ + function buyWithUSD(address _beneficiary, uint256 _investedDAI) public validDAI { + _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 - investorInvestedPOLY[_beneficiary] = investorInvestedPOLY[_beneficiary].add(spentValue); - fundsRaisedPOLY = fundsRaisedPOLY.add(spentValue); - // Forward POLY to issuer wallet - require(polyToken.transferFrom(msg.sender, wallet, spentValue)); - emit FundsReceivedPOLY(msg.sender, _beneficiary, spentUSD, _investedPOLY, spentValue, rate); + investorInvested[_beneficiary][uint8(_fundRaiseType)] = investorInvested[_beneficiary][uint8(_fundRaiseType)].add(spentValue); + fundsRaised[uint8(_fundRaiseType)] = fundsRaised[uint8(_fundRaiseType)].add(spentValue); + // Forward DAI to issuer wallet + IERC20 token = _fundRaiseType == FundRaiseType.POLY ? polyToken : usdToken; + require(token.transferFrom(msg.sender, wallet, spentValue)); + emit FundsReceived(msg.sender, _beneficiary, spentUSD, _fundRaiseType, _tokenAmount, 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"); } + require(isOpen(), "STO is not open"); require(_investmentValue > 0, "No funds were sent"); @@ -377,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++) { @@ -386,7 +414,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; @@ -400,7 +428,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; @@ -412,13 +440,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) @@ -427,16 +455,14 @@ 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 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 +508,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,36 +519,38 @@ 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; + 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); } /** @@ -574,22 +580,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 getTokensSoldFor(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; } @@ -615,9 +609,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 bytes4(keccak256("configure(uint256,uint256,uint256[],uint256[],uint256[],uint256[],uint256,uint256,uint8[],address,address)")); + return 0xb0ff041e; } function _getOracle(bytes32 _currency, bytes32 _denominatedCurrency) internal view returns (address) { 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/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/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/o_security_token.js b/test/o_security_token.js index 9f2dfd7e7..ce24a9be0 100644 --- a/test/o_security_token.js +++ b/test/o_security_token.js @@ -780,13 +780,13 @@ contract('SecurityToken', 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)) @@ -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/p_usd_tiered_sto.js b/test/p_usd_tiered_sto.js index 553fe006e..a1b55699b 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'; @@ -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; @@ -58,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 @@ -90,6 +94,7 @@ contract('USDTieredSTO', accounts => { let _fundRaiseTypes = []; let _wallet = []; let _reserveWallet = []; + let _usdToken = []; /* function configure( uint256 _startTime, @@ -102,7 +107,8 @@ contract('USDTieredSTO', accounts => { uint256 _minimumInvestmentUSD, uint8[] _fundRaiseTypes, address _wallet, - address _reserveWallet + address _reserveWallet, + address _usdToken ) */ const functionSignature = { name: 'configure', @@ -140,6 +146,9 @@ contract('USDTieredSTO', accounts => { },{ type: 'address', name: '_reserveWallet' + },{ + type: 'address', + name: '_usdToken' }] }; @@ -153,17 +162,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") @@ -194,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}); @@ -263,19 +276,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 +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 - _fundRaiseTypes.push([0, 1]); + _fundRaiseTypes.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], - _fundRaiseTypes[stoId], _wallet[stoId], _reserveWallet[stoId] + _fundRaiseTypes[stoId], _wallet[stoId], _reserveWallet[stoId], _usdToken[stoId] ]; let bytesSTO = web3.eth.abi.encodeFunctionCall(functionSignature, config); @@ -396,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"); }); @@ -405,20 +420,21 @@ 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); 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); @@ -440,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"); }); @@ -455,14 +472,15 @@ 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) 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); @@ -484,14 +502,15 @@ 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); 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); @@ -510,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], _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], _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]); @@ -532,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], _fundRaiseTypes[stoId], _wallet[stoId], _reserveWallet[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 { @@ -548,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], _fundRaiseTypes[stoId], wallet, _reserveWallet[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 { @@ -581,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], _fundRaiseTypes[stoId], _wallet[stoId], _reserveWallet[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 { @@ -598,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], _fundRaiseTypes[stoId], _wallet[stoId], _reserveWallet[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 { @@ -613,20 +632,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"); @@ -645,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() => { @@ -697,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); @@ -738,6 +763,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; @@ -759,6 +789,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 POLY investment succeeded when it should not'); + // ACCREDITED ETH let errorThrown3 = false; try { @@ -779,6 +819,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 POLY investment succeeded when it should not'); + await revertToSnapshot(snapId); }); @@ -808,6 +858,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; @@ -829,6 +884,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 { @@ -849,6 +914,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); }); @@ -875,12 +950,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 { @@ -901,6 +983,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 { @@ -921,6 +1013,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); }); @@ -955,6 +1057,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 { @@ -975,6 +1083,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 { @@ -995,14 +1113,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].buyWithUSD(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].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].buyWithUSD(ACCREDITED1, investment_DAI, {from: ACCREDITED1}); await revertToSnapshot(snapId); }); @@ -1035,6 +1167,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; @@ -1056,6 +1194,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 { @@ -1076,6 +1224,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); }); @@ -1121,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; @@ -1142,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 { @@ -1162,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); }); }); @@ -1244,8 +1427,9 @@ 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_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); @@ -1261,8 +1445,9 @@ 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_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); @@ -1276,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"); @@ -1283,11 +1469,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 +1492,9 @@ 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_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); @@ -1322,8 +1509,9 @@ 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_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); @@ -1336,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"); }); @@ -1359,8 +1548,9 @@ 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_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); @@ -1376,8 +1566,9 @@ 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_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); @@ -1390,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; @@ -1412,8 +1668,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 +1684,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 +1718,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 +1734,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 +1767,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 +1780,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 +1797,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 +1818,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 +1858,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 +1875,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 +1904,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 +1921,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 +2066,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 +2082,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 +2128,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 +2144,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 +2189,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 +2205,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); @@ -1970,13 +2226,86 @@ 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 POLY", async() => { + it("should successfully buy across tiers for ACCREDITED DAI", async() => { + 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); + + 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); + 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); + + 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); + 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 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.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"); + + }); + + it("should successfully buy across tiers for ACCREDITED POLY", async() => { + let stoId = 1; + let startTier = 4; + let endTier = 5; + + 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 polyTier0 = await convert(stoId, startTier, false, "TOKEN", "POLY", delta_Token); let polyTier1 = await convert(stoId, endTier, false, "TOKEN", "POLY", delta_Token); @@ -1995,8 +2324,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 +2340,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); @@ -2034,10 +2363,12 @@ contract('USDTieredSTO', accounts => { 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(); @@ -2065,10 +2396,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 @@ -2091,6 +2426,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 { @@ -2110,6 +2455,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() => { @@ -2246,8 +2601,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 +2618,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 +2640,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 +2663,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 +2679,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 +2716,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 +2733,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 +2769,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 +2785,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 +2819,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 +2835,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 +2868,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 +2881,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 +2898,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 +2919,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 +2950,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 +2967,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 +3129,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 +3145,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 +3189,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 +3206,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 +3430,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 +3453,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 +3470,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()); }); }); diff --git a/test/q_usd_tiered_sto_sim.js b/test/q_usd_tiered_sto_sim.js index d8db504d5..c12737967 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}); @@ -238,19 +245,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 @@ -348,14 +355,15 @@ contract('USDTieredSTO', 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); 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); @@ -477,12 +485,14 @@ contract('USDTieredSTO', 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 = []; @@ -497,6 +507,8 @@ contract('USDTieredSTO', accounts => { let USD_Tier; let POLY_Tier; let ETH_Tier; + let DAI_Tier; + let USD_overflow; let Token_overflow; @@ -546,8 +558,26 @@ contract('USDTieredSTO', 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)) { @@ -569,13 +599,15 @@ contract('USDTieredSTO', 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) { - 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 { @@ -583,8 +615,11 @@ contract('USDTieredSTO', 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); @@ -593,10 +628,11 @@ contract('USDTieredSTO', 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 ------------------- @@ -608,6 +644,7 @@ contract('USDTieredSTO', 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)} ------------------------------------------------------ `); @@ -615,6 +652,9 @@ contract('USDTieredSTO', 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()); @@ -623,14 +663,18 @@ contract('USDTieredSTO', 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].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_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); @@ -639,24 +683,33 @@ contract('USDTieredSTO', 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].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_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()); @@ -674,6 +727,19 @@ contract('USDTieredSTO', 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"); diff --git a/test/r_concurrent_STO.js b/test/r_concurrent_STO.js index 635814623..477b9de40 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,13 +372,13 @@ 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(await I_STO_Array[STOIndex].getNumberInvestors.call(), 1); + assert.equal(web3.utils.fromWei((await I_STO_Array[STOIndex].getRaised.call(0)).toString()), 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)) @@ -389,9 +389,9 @@ 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(await I_STO_Array[STOIndex].getNumberInvestors.call(), 1); + 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].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' }] };