Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
93 changes: 45 additions & 48 deletions CLI/commands/investor_portal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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;
}
Expand All @@ -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}
Expand All @@ -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) {
Expand All @@ -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());
Expand All @@ -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())
Expand Down Expand Up @@ -310,22 +307,22 @@ async function showUSDTieredSTOInfo() {

displayDiscountMinted = `(${web3.utils.fromWei(mintedPerTierDiscountPoly)} ${displayTokenSymbol} at discounted rate)`;
}


let mintedPerTier = mintedPerTierPerRaiseType[gbl.constants.FUND_RAISE_TYPES[type]];
displayMintedPerTierPerType += `
Sold for ${type}:\t\t ${web3.utils.fromWei(mintedPerTier)} ${displayTokenSymbol} ${displayDiscountMinted}`;
}

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());
Expand All @@ -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) {
Expand All @@ -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
`);

Expand Down Expand Up @@ -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]}`);

Expand All @@ -422,20 +419,20 @@ 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.`));
process.exit();
}
} 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();
}
Expand All @@ -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];
Expand All @@ -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)`
Expand All @@ -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.`));
Expand All @@ -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);
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
}
9 changes: 5 additions & 4 deletions CLI/commands/sto_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,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]
);
Expand All @@ -223,7 +223,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';
Expand Down Expand Up @@ -254,7 +254,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}
-----------------------------------------------
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions CLI/commands/token_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,11 +429,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' });
Expand All @@ -456,7 +456,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);
Expand Down Expand Up @@ -676,7 +676,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;
Expand Down
3 changes: 2 additions & 1 deletion CLI/commands/transfer_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,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;
Expand Down
Loading