From cc933303d580c53f4bcf1209c94e8801393fd9fc Mon Sep 17 00:00:00 2001 From: Mudit Gupta Date: Wed, 28 Nov 2018 11:32:32 +0530 Subject: [PATCH 01/10] Rate changed --- contracts/modules/STO/CappedSTO.sol | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/contracts/modules/STO/CappedSTO.sol b/contracts/modules/STO/CappedSTO.sol index 60373ae37..0d79d285c 100644 --- a/contracts/modules/STO/CappedSTO.sol +++ b/contracts/modules/STO/CappedSTO.sol @@ -13,7 +13,8 @@ contract CappedSTO is ISTO, ReentrancyGuard { // Determine whether users can invest on behalf of a beneficiary bool public allowBeneficialInvestments = false; - // How many token units a buyer gets per wei / base unit of POLY + // How many token units multiplied by 10^18 a buyer gets per wei / base unit of POLY + // If rate is 10^18, buyer will get 1 token unit for every wei / base unit of poly. uint256 public rate; //How many tokens this STO will be allowed to sell to investors uint256 public cap; @@ -49,7 +50,7 @@ contract CappedSTO is ISTO, ReentrancyGuard { * @param _startTime Unix timestamp at which offering get started * @param _endTime Unix timestamp at which offering get ended * @param _cap Maximum No. of tokens for sale - * @param _rate Token units a buyer gets per wei / base unit of POLY + * @param _rate Token units multiplied by 10^18 a buyer gets per wei / base unit of POLY * @param _fundRaiseTypes Type of currency used to collect the funds * @param _fundsReceiver Ethereum account address to hold the funds */ @@ -154,6 +155,7 @@ contract CappedSTO is ISTO, ReentrancyGuard { * @return Unixtimestamp at which offering gets start. * @return Unixtimestamp at which offering ends. * @return Number of tokens this STO will be allowed to sell to investors. + * @return Token units multiplied by 10^18 a buyer gets per wei / base unit of POLY * @return Amount of funds raised * @return Number of individual investors this STO have. * @return Amount of tokens get sold. @@ -259,8 +261,10 @@ contract CappedSTO is ISTO, ReentrancyGuard { * @param _investedAmount Value in wei to be converted into tokens * @return Number of tokens that can be purchased with the specified _investedAmount */ - function _getTokenAmount(uint256 _investedAmount) internal view returns (uint256) { - return _investedAmount.mul(rate); + function _getTokenAmount(uint256 _investedAmount) internal view returns (uint256 tokenAmount) { + tokenAmount = _investedAmount.mul(rate); + tokenAmount = tokenAmount.div(uint256(10) ** 18); + return tokenAmount; } /** From 39c38f0056361eb1af299722af5e7d2fa499f842 Mon Sep 17 00:00:00 2001 From: Mudit Gupta Date: Wed, 28 Nov 2018 11:32:47 +0530 Subject: [PATCH 02/10] changelog updated --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index db3d8dcde..dc15e692e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file. [__2.1.0__](https://www.npmjs.com/package/polymath-core?activeTab=readme) __13-09-18__ +# CappedSTO 2.0.1 +* `rate` is now accepted as multiplied by 10^18 to allow settting higher price than 1ETH/POLY per token. + # USDTieredSTO 2.0.1 * Added `buyTokensView` and `getTokensMintedByTier` to USDTSTO. * Added `getSTODetails` to USDTSTO. From 236cd179fbd68706a80e77b0900f43c0da35d987 Mon Sep 17 00:00:00 2001 From: Mudit Gupta Date: Wed, 28 Nov 2018 11:36:59 +0530 Subject: [PATCH 03/10] Updated tests for rate changes --- test/b_capped_sto.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/b_capped_sto.js b/test/b_capped_sto.js index fce1ee5e5..539d91b26 100644 --- a/test/b_capped_sto.js +++ b/test/b_capped_sto.js @@ -86,7 +86,7 @@ contract("CappedSTO", accounts => { let startTime_ETH2; let endTime_ETH2; const cap = web3.utils.toWei("10000"); - const rate = 1000; + const rate = web3.utils.toWei("1000"); const E_fundRaiseType = 0; const address_zero = "0x0000000000000000000000000000000000000000"; @@ -97,7 +97,7 @@ contract("CappedSTO", accounts => { let blockNo; const P_cap = web3.utils.toWei("50000"); const P_fundRaiseType = 1; - const P_rate = 5; + const P_rate = web3.utils.toWei("5"); const cappedSTOSetupCost = web3.utils.toWei("20000", "ether"); const maxCost = cappedSTOSetupCost; const STOParameters = ["uint256", "uint256", "uint256", "uint256", "uint8[]", "address"]; @@ -298,7 +298,7 @@ contract("CappedSTO", accounts => { assert.equal(await I_CappedSTO_Array_ETH[0].startTime.call(), startTime_ETH1, "STO Configuration doesn't set as expected"); assert.equal(await I_CappedSTO_Array_ETH[0].endTime.call(), endTime_ETH1, "STO Configuration doesn't set as expected"); assert.equal((await I_CappedSTO_Array_ETH[0].cap.call()).toNumber(), cap, "STO Configuration doesn't set as expected"); - assert.equal(await I_CappedSTO_Array_ETH[0].rate.call(), rate, "STO Configuration doesn't set as expected"); + assert.equal((await I_CappedSTO_Array_ETH[0].rate.call()).toNumber(), rate, "STO Configuration doesn't set as expected"); assert.equal( await I_CappedSTO_Array_ETH[0].fundRaiseTypes.call(E_fundRaiseType), true, @@ -554,7 +554,7 @@ contract("CappedSTO", accounts => { assert.equal(await I_CappedSTO_Array_ETH[1].startTime.call(), startTime_ETH2, "STO Configuration doesn't set as expected"); assert.equal(await I_CappedSTO_Array_ETH[1].endTime.call(), endTime_ETH2, "STO Configuration doesn't set as expected"); assert.equal((await I_CappedSTO_Array_ETH[1].cap.call()).toNumber(), cap, "STO Configuration doesn't set as expected"); - assert.equal(await I_CappedSTO_Array_ETH[1].rate.call(), rate, "STO Configuration doesn't set as expected"); + assert.equal((await I_CappedSTO_Array_ETH[1].rate.call()).toNumber(), rate, "STO Configuration doesn't set as expected"); assert.equal( await I_CappedSTO_Array_ETH[1].fundRaiseTypes.call(E_fundRaiseType), true, @@ -993,8 +993,8 @@ contract("CappedSTO", accounts => { it("Should successfully invest in second STO", async () => { const polyToInvest = 1000; - const stToReceive = polyToInvest * P_rate; - + const stToReceive = (polyToInvest * P_rate)/Math.pow(10, 18); + await I_PolyToken.getTokens(polyToInvest * Math.pow(10, 18), account_investor3); let tx = await I_GeneralTransferManager.modifyWhitelist(account_investor3, P_fromTime, P_toTime, P_expiryTime, true, { From 3cb2ce258fecca500ad09203e38538bc64a84115 Mon Sep 17 00:00:00 2001 From: Mudit Gupta Date: Wed, 28 Nov 2018 11:57:33 +0530 Subject: [PATCH 04/10] Issuance test fixed --- test/i_Issuance.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/i_Issuance.js b/test/i_Issuance.js index ac1fcdd37..5cef65baf 100644 --- a/test/i_Issuance.js +++ b/test/i_Issuance.js @@ -72,7 +72,7 @@ contract("Issuance", accounts => { //let startTime; // Start time will be 5000 seconds more than the latest time //let endTime; // Add 30 days more const cap = web3.utils.toWei("10000"); - const rate = 1000; + const rate = web3.utils.toWei("1000"); const fundRaiseType = [0]; const cappedSTOSetupCost = web3.utils.toWei("20000", "ether"); const maxCost = cappedSTOSetupCost; From f62f9f782f69c931213a01d4c42234cd9d425e4a Mon Sep 17 00:00:00 2001 From: Mudit Gupta Date: Wed, 28 Nov 2018 12:39:29 +0530 Subject: [PATCH 05/10] test cases updated --- test/o_security_token.js | 2 +- test/r_concurrent_STO.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/o_security_token.js b/test/o_security_token.js index 52521181e..f475f6ab8 100644 --- a/test/o_security_token.js +++ b/test/o_security_token.js @@ -93,7 +93,7 @@ contract("SecurityToken", accounts => { let startTime; let endTime; const cap = web3.utils.toWei("10000"); - const rate = 1000; + const rate = web3.utils.toWei("1000"); const fundRaiseType = [0]; const cappedSTOSetupCost = web3.utils.toWei("20000", "ether"); const maxCost = cappedSTOSetupCost; diff --git a/test/r_concurrent_STO.js b/test/r_concurrent_STO.js index 7912658a4..cfe2767af 100644 --- a/test/r_concurrent_STO.js +++ b/test/r_concurrent_STO.js @@ -176,7 +176,7 @@ contract("Concurrent STO", accounts => { const startTime = latestTime() + duration.days(1); const endTime = latestTime() + duration.days(90); const cap = web3.utils.toWei("10000"); - const rate = 1000; + const rate = web3.utils.toWei("1000"); const fundRaiseType = [0]; const budget = 0; const maxCost = STOSetupCost; From 17f10154cb8058617ccad792302738a827774b4c Mon Sep 17 00:00:00 2001 From: Mudit Gupta Date: Wed, 28 Nov 2018 21:37:13 +0530 Subject: [PATCH 06/10] Updated comments --- contracts/modules/STO/CappedSTO.sol | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/contracts/modules/STO/CappedSTO.sol b/contracts/modules/STO/CappedSTO.sol index 0d79d285c..d85fcb3da 100644 --- a/contracts/modules/STO/CappedSTO.sol +++ b/contracts/modules/STO/CappedSTO.sol @@ -13,10 +13,11 @@ contract CappedSTO is ISTO, ReentrancyGuard { // Determine whether users can invest on behalf of a beneficiary bool public allowBeneficialInvestments = false; - // How many token units multiplied by 10^18 a buyer gets per wei / base unit of POLY + // How many token units a buyer gets (multiplied by 10^18) per wei / base unit of POLY // If rate is 10^18, buyer will get 1 token unit for every wei / base unit of poly. uint256 public rate; - //How many tokens this STO will be allowed to sell to investors + //How many token base units this STO will be allowed to sell to investors + // 1 full token = 10^decimals_of_token base units uint256 public cap; mapping (address => uint256) public investors; @@ -49,8 +50,8 @@ contract CappedSTO is ISTO, ReentrancyGuard { * @notice Function used to intialize the contract variables * @param _startTime Unix timestamp at which offering get started * @param _endTime Unix timestamp at which offering get ended - * @param _cap Maximum No. of tokens for sale - * @param _rate Token units multiplied by 10^18 a buyer gets per wei / base unit of POLY + * @param _cap Maximum No. of token base units for sale + * @param _rate Token units a buyer gets multiplied by 10^18 per wei / base unit of POLY * @param _fundRaiseTypes Type of currency used to collect the funds * @param _fundsReceiver Ethereum account address to hold the funds */ @@ -154,8 +155,8 @@ contract CappedSTO is ISTO, ReentrancyGuard { * @notice Return the STO details * @return Unixtimestamp at which offering gets start. * @return Unixtimestamp at which offering ends. - * @return Number of tokens this STO will be allowed to sell to investors. - * @return Token units multiplied by 10^18 a buyer gets per wei / base unit of POLY + * @return Number of token base units this STO will be allowed to sell to investors. + * @return Token units a buyer gets(multiplied by 10^18) per wei / base unit of POLY * @return Amount of funds raised * @return Number of individual investors this STO have. * @return Amount of tokens get sold. From 09424e0b35f95d8a2fe961adc2b9c4ccfc9e370e Mon Sep 17 00:00:00 2001 From: Victor Date: Wed, 28 Nov 2018 15:28:23 -0300 Subject: [PATCH 07/10] CLI - Fix at removing modules --- CLI/commands/token_manager.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CLI/commands/token_manager.js b/CLI/commands/token_manager.js index 6faa7ba34..98d13fd3d 100644 --- a/CLI/commands/token_manager.js +++ b/CLI/commands/token_manager.js @@ -372,11 +372,11 @@ async function listModuleOptions() { let archivedModules = allModules.filter(m => m.archived); if (archivedModules.length > 0) { - options.push('Unarchive a module'); + options.push('Unarchive a module', 'Remove a module'); } if (allModules.length > 0) { - options.push('Remove a module', 'Change module budget'); + options.push('Change module budget'); } let index = readlineSync.keyInSelect(options, chalk.yellow('What do you want to do?'), { cancel: 'Return' }); @@ -399,7 +399,7 @@ async function listModuleOptions() { await unarchiveModule(archivedModules); break; case 'Remove a module': - await removeModule(allModules); + await removeModule(archivedModules); break; case 'Change module budget': await changeBudget(allModules); From 51392544d8b5976ffb724e7f7a8d845b7db74d81 Mon Sep 17 00:00:00 2001 From: Victor Date: Wed, 28 Nov 2018 15:54:34 -0300 Subject: [PATCH 08/10] CLI - Fix on exit at token selection --- CLI/commands/sto_manager.js | 3 ++- CLI/commands/token_manager.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CLI/commands/sto_manager.js b/CLI/commands/sto_manager.js index d0fd1c3ea..d70c0ca81 100644 --- a/CLI/commands/sto_manager.js +++ b/CLI/commands/sto_manager.js @@ -870,7 +870,8 @@ async function selectToken() { options.push('Enter token symbol manually'); let index = readlineSync.keyInSelect(options, 'Select a token:', { cancel: 'Exit' }); - switch (options[index]) { + let selected = index != -1 ? options[index] : 'Exit'; + switch (selected) { case 'Enter token symbol manually': result = readlineSync.question('Enter the token symbol: '); break; diff --git a/CLI/commands/token_manager.js b/CLI/commands/token_manager.js index 98d13fd3d..fe9590f1f 100644 --- a/CLI/commands/token_manager.js +++ b/CLI/commands/token_manager.js @@ -622,7 +622,8 @@ async function selectToken() { options.push('Enter token symbol manually'); let index = readlineSync.keyInSelect(options, 'Select a token:', { cancel: 'Exit' }); - switch (options[index]) { + let selected = index != -1 ? options[index] : 'Exit'; + switch (selected) { case 'Enter token symbol manually': result = readlineSync.question('Enter the token symbol: '); break; From 81054dcf0fef34fdb6df6db2bf7c8e4291a88bae Mon Sep 17 00:00:00 2001 From: Victor Date: Wed, 28 Nov 2018 16:39:15 -0300 Subject: [PATCH 09/10] CLI - Support for not integer rates on CappedSTO --- CLI/commands/investor_portal.js | 93 ++++++++++++++++----------------- CLI/commands/sto_manager.js | 6 +-- 2 files changed, 48 insertions(+), 51 deletions(-) diff --git a/CLI/commands/investor_portal.js b/CLI/commands/investor_portal.js index 1ced21ce0..cdfa66828 100644 --- a/CLI/commands/investor_portal.js +++ b/CLI/commands/investor_portal.js @@ -9,8 +9,6 @@ var gbl = require('./common/global'); var contracts = require('./helpers/contract_addresses'); var abis = require('./helpers/contract_abis'); -const STO_KEY = 3; - let securityTokenRegistry; let securityToken; let selectedSTO; @@ -50,7 +48,7 @@ async function executeApp(investorAddress, investorPrivKey, symbol, currency, am } } if (investorAddress != "") { - User = { address: investorAddress, privateKey: investorPrivKey}; + User = { address: investorAddress, privateKey: investorPrivKey }; } else { User = Issuer; } @@ -111,7 +109,7 @@ async function inputSymbol(symbol) { if (STSymbol == "") process.exit(); STAddress = await securityTokenRegistry.methods.getSecurityTokenAddress(STSymbol).call(); - if (STAddress == "0x0000000000000000000000000000000000000000"){ + if (STAddress == "0x0000000000000000000000000000000000000000") { console.log(`Token symbol provided is not a registered Security Token. Please enter another symbol.`); } else { let securityTokenABI = abis.securityToken(); @@ -123,12 +121,12 @@ async function inputSymbol(symbol) { let generalTransferManagerABI = abis.generalTransferManager(); generalTransferManager = new web3.eth.Contract(generalTransferManagerABI, gtmModule[0]); - let stoModules = await securityToken.methods.getModulesByType(STO_KEY).call(); + let stoModules = await securityToken.methods.getModulesByType(gbl.constants.MODULES_TYPES.STO).call(); if (stoModules.length == 0) { console.log(chalk.red(`There is no STO module attached to the ${STSymbol.toUpperCase()} Token. No further actions can be taken.`)); process.exit(0); } else { - STOAddress = stoModules[0]; + STOAddress = stoModules[0]; let stoModuleData = await securityToken.methods.getModule(STOAddress).call(); selectedSTO = web3.utils.toAscii(stoModuleData[0]).replace(/\u0000/g, ''); let interfaceSTOABI = abis.stoInterface(); @@ -187,19 +185,19 @@ async function showCappedSTOInfo() { } } - let now = Math.floor(Date.now()/1000); + let now = Math.floor(Date.now() / 1000); - await generalTransferManager.methods.whitelist(User.address).call({}, function(error, result){ + await generalTransferManager.methods.whitelist(User.address).call({}, function (error, result) { displayCanBuy = result.canBuyFromSTO; displayValidKYC = parseInt(result.expiryTime) > now; }); let timeTitle; let timeRemaining; - if(now < displayStartTime){ + if (now < displayStartTime) { timeTitle = "STO starts in: "; timeRemaining = displayStartTime - now; - }else{ + } else { timeTitle = "Time remaining:"; timeRemaining = displayEndTime - now; } @@ -213,7 +211,7 @@ async function showCappedSTOInfo() { - Start Time: ${new Date(displayStartTime * 1000)} - End Time: ${new Date(displayEndTime * 1000)} - Raise Type: ${displayRaiseType} - - Rate: 1 ${displayRaiseType} = ${displayRate} ${STSymbol.toUpperCase()} + - Rate: 1 ${displayRaiseType} = ${web3.utils.fromWei(displayRate)} ${STSymbol.toUpperCase()} --------------------------------------------------------------- - ${timeTitle} ${timeRemaining} - Funds raised: ${web3.utils.fromWei(displayFundsRaised)} ${displayRaiseType} @@ -222,7 +220,7 @@ async function showCappedSTOInfo() { - Investor count: ${displayInvestorCount} `); - if(!displayCanBuy) { + if (!displayCanBuy) { console.log(chalk.red(`Your address is not approved to participate in this token sale.\n`)); process.exit(0); } else if (!displayValidKYC) { @@ -237,8 +235,7 @@ async function showCappedSTOInfo() { } } -async function showUserInfoForUSDTieredSTO() -{ +async function showUserInfoForUSDTieredSTO() { for (const fundType in gbl.constants.FUND_RAISE_TYPES) { if (await currentSTO.methods.fundRaiseTypes(gbl.constants.FUND_RAISE_TYPES[fundType]).call()) { let displayInvestorInvested = web3.utils.fromWei(await currentSTO.methods.investorInvested(User.address, gbl.constants.FUND_RAISE_TYPES[fundType]).call()); @@ -249,15 +246,15 @@ async function showUserInfoForUSDTieredSTO() 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){ + await generalTransferManager.methods.whitelist(User.address).call({}, function (error, result) { displayCanBuy = result.canBuyFromSTO; - displayValidKYC = parseInt(result.expiryTime) > Math.floor(Date.now()/1000); + displayValidKYC = parseInt(result.expiryTime) > Math.floor(Date.now() / 1000); }); - console.log(` - Whitelisted: ${(displayCanBuy)? 'YES' : 'NO'}`); - console.log(` - Valid KYC: ${(displayValidKYC)? 'YES' : 'NO'}`); + console.log(` - Whitelisted: ${(displayCanBuy) ? 'YES' : 'NO'}`); + console.log(` - Valid KYC: ${(displayValidKYC) ? 'YES' : 'NO'}`); let displayIsUserAccredited = await currentSTO.methods.accredited(User.address).call(); - console.log(` - Accredited: ${(displayIsUserAccredited)? "YES" : "NO"}`) + 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()) @@ -310,7 +307,7 @@ async function showUSDTieredSTOInfo() { displayDiscountMinted = `(${web3.utils.fromWei(mintedPerTierDiscountPoly)} ${displayTokenSymbol} at discounted rate)`; } - + let mintedPerTier = mintedPerTierPerRaiseType[gbl.constants.FUND_RAISE_TYPES[type]]; displayMintedPerTierPerType += ` @@ -318,14 +315,14 @@ async function showUSDTieredSTOInfo() { } displayTiers += ` - - Tier ${t+1}: + - Tier ${t + 1}: Tokens: ${web3.utils.fromWei(tokensPerTierTotal)} ${displayTokenSymbol} Rate: ${web3.utils.fromWei(ratePerTier)} USD per Token` - + displayDiscountTokens; + + displayDiscountTokens; - displayMintedPerTier += ` - - Tokens minted in Tier ${t+1}: ${web3.utils.fromWei(mintedPerTierTotal)} ${displayTokenSymbol}` - + displayMintedPerTierPerType; + displayMintedPerTier += ` + - Tokens minted in Tier ${t + 1}: ${web3.utils.fromWei(mintedPerTierTotal)} ${displayTokenSymbol}` + + displayMintedPerTierPerType; } let displayFundsRaisedUSD = web3.utils.fromWei(await currentSTO.methods.fundsRaisedUSD().call()); @@ -347,7 +344,7 @@ async function showUSDTieredSTOInfo() { let displayRaiseType = raiseTypes.join(' - '); - let now = Math.floor(Date.now()/1000); + let now = Math.floor(Date.now() / 1000); let timeTitle; let timeRemaining; if (now < displayStartTime) { @@ -366,18 +363,18 @@ async function showUSDTieredSTOInfo() { - End Time: ${new Date(displayEndTime * 1000)} - Raise Type: ${displayRaiseType} - Tiers: ${tiersLength}` - + displayTiers + ` + + displayTiers + ` - Minimum Investment: ${displayMinimumInvestmentUSD} USD - Default NonAccredited Limit: ${displayNonAccreditedLimitUSD} USD ----------------------------------------------------------------------- - ${timeTitle} ${timeRemaining} - Tokens Sold: ${displayTokensSold} ${displayTokenSymbol}` - + displayTokensSoldPerType + ` + + displayTokensSoldPerType + ` - Current Tier: ${displayCurrentTier}` - + displayMintedPerTier + ` + + displayMintedPerTier + ` - Investor count: ${displayInvestorCount} - Funds Raised` - + displayFundsRaisedPerType + ` + + displayFundsRaisedPerType + ` USD: ${displayFundsRaisedUSD} USD `); @@ -411,7 +408,7 @@ async function investCappedSTO(currency, amount) { } if (amt == "") process.exit(); - let rate = await currentSTO.methods.rate().call(); + let rate = web3.utils.fromWei(await currentSTO.methods.rate().call()); let cost = new BigNumber(amt).div(rate); console.log(`This investment will cost ${cost} ${raiseTypes[0]}`); @@ -422,11 +419,11 @@ async function investCappedSTO(currency, amount) { let allowance = await polyToken.methods.allowance(STOAddress, User.address).call(); if (allowance < costWei) { let approveAction = polyToken.methods.approve(STOAddress, costWei); - await common.sendTransaction(approveAction, {from: User}); + await common.sendTransaction(approveAction, { from: User }); } let actionBuyTokensWithPoly = currentSTO.methods.buyTokensWithPoly(costWei); - let receipt = await common.sendTransaction(actionBuyTokensWithPoly, {from: User}); - logTokensPurchasedCappedSTO(receipt); + let receipt = await common.sendTransaction(actionBuyTokensWithPoly, { from: User }); + logTokensPurchasedCappedSTO(receipt, 'POLY'); } else { console.log(chalk.red(`Not enough balance to Buy tokens, Require ${cost} POLY but have ${userBalance} POLY.`)); console.log(chalk.red(`Please purchase a smaller amount of tokens or access the POLY faucet to get the POLY to complete this txn.`)); @@ -434,8 +431,8 @@ async function investCappedSTO(currency, amount) { } } else { let actionBuyTokens = currentSTO.methods.buyTokens(User.address); - let receipt = await common.sendTransaction(actionBuyTokens, {from: User, value: costWei}); - logTokensPurchasedCappedSTO(receipt); + let receipt = await common.sendTransaction(actionBuyTokens, { from: User, value: costWei }); + logTokensPurchasedCappedSTO(receipt, 'ETH'); } await showTokenInfo(); } @@ -456,7 +453,7 @@ async function investUsdTieredSTO(currency, amount) { console.log(chalk.green(` Current ${type} price:\t\t ${displayPrice} USD`)); } if (raiseTypes.length > 1) { - let index = readlineSync.keyInSelect(raiseTypes, 'Choose one of the allowed raise types: ', {cancel: false}); + let index = readlineSync.keyInSelect(raiseTypes, 'Choose one of the allowed raise types: ', { cancel: false }); raiseType = raiseTypes[index]; } else { raiseType = raiseTypes[0]; @@ -470,7 +467,7 @@ async function investUsdTieredSTO(currency, amount) { let minimumInvestmentUSD = await currentSTO.methods.minimumInvestmentUSD().call(); let minimumInvestmentRaiseType = await currentSTO.methods.convertFromUSD(gbl.constants.FUND_RAISE_TYPES[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) { + limit: function (input) { return investorInvestedUSD != 0 || parseInt(input) > parseInt(web3.utils.fromWei(minimumInvestmentRaiseType)); }, limitMessage: `Amount must be greater than minimum investment (${web3.utils.fromWei(minimumInvestmentRaiseType)} ${raiseType} = ${web3.utils.fromWei(minimumInvestmentUSD)} USD)` @@ -496,10 +493,10 @@ async function investUsdTieredSTO(currency, amount) { let allowance = await polyToken.methods.allowance(STOAddress, User.address).call(); if (allowance < costWei) { let approveAction = polyToken.methods.approve(STOAddress, costWei); - await common.sendTransaction(approveAction, {from: User}); + await common.sendTransaction(approveAction, { from: User }); } let actionBuyWithPoly = currentSTO.methods.buyWithPOLYRateLimited(User.address, costWei, minTokenToBuy); - let receipt = await common.sendTransaction(actionBuyWithPoly, {from: User, factor: 2}); + let receipt = await common.sendTransaction(actionBuyWithPoly, { from: User, factor: 2 }); logTokensPurchasedUSDTieredSTO(receipt); } else { console.log(chalk.red(`Not enough balance to Buy tokens, Require ${cost} POLY but have ${userBalance} POLY.`)); @@ -512,19 +509,19 @@ async function investUsdTieredSTO(currency, amount) { let allowance = await usdToken.methods.allowance(STOAddress, User.address).call(); if (allowance < costWei) { let approveAction = usdToken.methods.approve(STOAddress, costWei); - await common.sendTransaction(approveAction, {from: User}); + await common.sendTransaction(approveAction, { from: User }); } let actionBuyWithUSD = currentSTO.methods.buyWithUSDRateLimited(User.address, costWei, minTokenToBuy); - let receipt = await common.sendTransaction(actionBuyWithUSD, {from: User, factor: 1.5}); + let receipt = await common.sendTransaction(actionBuyWithUSD, { from: User, factor: 1.5 }); logTokensPurchasedUSDTieredSTO(receipt); } else { console.log(chalk.red(`Not enough balance to Buy tokens, Require ${cost} DAI but have ${userBalance} DAI.`)); console.log(chalk.red(`Please purchase a smaller amount of tokens.`)); process.exit(); - } + } } else { let actionBuyWithETH = currentSTO.methods.buyWithETHRateLimited(User.address, minTokenToBuy); - let receipt = await common.sendTransaction(actionBuyWithETH, {from: User, value: costWei}); + let receipt = await common.sendTransaction(actionBuyWithETH, { from: User, value: costWei }); logTokensPurchasedUSDTieredSTO(receipt); } @@ -554,7 +551,7 @@ function logTokensPurchasedUSDTieredSTO(receipt) { }; } -function logTokensPurchasedCappedSTO(receipt) { +function logTokensPurchasedCappedSTO(receipt, displayRaiseType) { console.log(chalk.green(`Congratulations! The token purchase was successfully completed.`)); let events = common.getMultipleEventsFromLogs(currentSTO._jsonInterface, receipt.logs, 'TokenPurchase'); for (event of events) { @@ -567,7 +564,7 @@ function logTokensPurchasedCappedSTO(receipt) { } module.exports = { - executeApp: async function(investorAddress, investorPrivKey, symbol, currency, amount) { - return executeApp(investorAddress, investorPrivKey, symbol, currency, amount); - } + executeApp: async function (investorAddress, investorPrivKey, symbol, currency, amount) { + return executeApp(investorAddress, investorPrivKey, symbol, currency, amount); + } } diff --git a/CLI/commands/sto_manager.js b/CLI/commands/sto_manager.js index d70c0ca81..e9b44c907 100644 --- a/CLI/commands/sto_manager.js +++ b/CLI/commands/sto_manager.js @@ -200,7 +200,7 @@ async function cappedSTO_launch(stoConfig) { [cappedSTOconfig.startTime, cappedSTOconfig.endTime, web3.utils.toWei(cappedSTOconfig.cap.toString()), - cappedSTOconfig.rate, + web3.utils.toWei(cappedSTOconfig.rate.toString()), cappedSTOconfig.raiseType, cappedSTOconfig.wallet] ); @@ -219,7 +219,7 @@ async function cappedSTO_launch(stoConfig) { async function cappedSTO_status(currentSTO) { let displayStartTime = await currentSTO.methods.startTime().call(); let displayEndTime = await currentSTO.methods.endTime().call(); - let displayRate = await currentSTO.methods.rate().call(); + let displayRate = new web3.utils.BN(await currentSTO.methods.rate().call()); let displayCap = new web3.utils.BN(await currentSTO.methods.cap().call()); let displayWallet = await currentSTO.methods.wallet().call(); let displayRaiseType = await currentSTO.methods.fundRaiseTypes(gbl.constants.FUND_RAISE_TYPES.ETH).call() ? 'ETH' : 'POLY'; @@ -250,7 +250,7 @@ async function cappedSTO_status(currentSTO) { - Start Time: ${new Date(displayStartTime * 1000)} - End Time: ${new Date(displayEndTime * 1000)} - Raise Type: ${displayRaiseType} - - Rate: 1 ${displayRaiseType} = ${displayRate} ${displayTokenSymbol.toUpperCase()} + - Rate: 1 ${displayRaiseType} = ${web3.utils.fromWei(displayRate)} ${displayTokenSymbol.toUpperCase()} - Wallet: ${displayWallet} - Wallet Balance: ${displayWalletBalance} ${displayRaiseType} ----------------------------------------------- From 145fe5bfe51fded32140e3eea221c2f01278860c Mon Sep 17 00:00:00 2001 From: Victor Date: Wed, 28 Nov 2018 16:42:02 -0300 Subject: [PATCH 10/10] CLI - Minor fix --- CLI/commands/transfer_manager.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CLI/commands/transfer_manager.js b/CLI/commands/transfer_manager.js index 44ae64ca1..3b65df2e8 100644 --- a/CLI/commands/transfer_manager.js +++ b/CLI/commands/transfer_manager.js @@ -929,7 +929,8 @@ async function selectToken() { options.push('Enter token symbol manually'); let index = readlineSync.keyInSelect(options, 'Select a token:', { cancel: 'Exit' }); - switch (options[index]) { + let selected = index != -1 ? options[index] : 'Exit'; + switch (selected) { case 'Enter token symbol manually': result = readlineSync.question('Enter the token symbol: '); break;