MCPcopy Create free account
hub / github.com/PolymathNetwork/polymath-core / cappedSTO_launch

Function cappedSTO_launch

CLI/commands/sto_manager.js:152–230  ·  view source on GitHub ↗
(stoConfig)

Source from the content-addressed store, hash-verified

150// Capped STO //
151////////////////
152async function cappedSTO_launch(stoConfig) {
153 console.log(chalk.blue('Launch STO - Capped STO in No. of Tokens'));
154
155 let cappedSTOFactoryABI = abis.cappedSTOFactory();
156 let cappedSTOFactoryAddress = await contracts.getModuleFactoryAddressByName(securityToken.options.address, gbl.constants.MODULES_TYPES.STO, "CappedSTO");
157 let cappedSTOFactory = new web3.eth.Contract(cappedSTOFactoryABI, cappedSTOFactoryAddress);
158 cappedSTOFactory.setProvider(web3.currentProvider);
159 let stoFee = new web3.utils.BN(await cappedSTOFactory.methods.getSetupCost().call());
160
161 let contractBalance = new web3.utils.BN(await polyToken.methods.balanceOf(securityToken._address).call());
162 if (contractBalance.lt(stoFee)) {
163 let transferAmount = stoFee.sub(contractBalance);
164 let ownerBalance = new web3.utils.BN(await polyToken.methods.balanceOf(Issuer.address).call());
165 if (ownerBalance.lt(transferAmount)) {
166 console.log(chalk.red(`\n**************************************************************************************************************************************************`));
167 console.log(chalk.red(`Not enough balance to pay the CappedSTO fee, Requires ${web3.utils.fromWei(transferAmount)} POLY but have ${web3.utils.fromWei(ownerBalance)} POLY. Access POLY faucet to get the POLY to complete this txn`));
168 console.log(chalk.red(`**************************************************************************************************************************************************\n`));
169 return;
170 } else {
171 let transferAction = polyToken.methods.transfer(securityToken._address, transferAmount);
172 let receipt = await common.sendTransaction(transferAction, { factor: 2 });
173 let event = common.getEventFromLogs(polyToken._jsonInterface, receipt.logs, 'Transfer');
174 console.log(`Number of POLY sent: ${web3.utils.fromWei(new web3.utils.BN(event._value))}`)
175 }
176 }
177
178 let oneMinuteFromNow = new web3.utils.BN((Math.floor(Date.now() / 1000) + 60));
179 let oneMonthFromNow = new web3.utils.BN((Math.floor(Date.now() / 1000) + (30 * 24 * 60 * 60)));
180
181 let cappedSTOconfig = {};
182 let useConfigFile = typeof stoConfig !== 'undefined';
183 if (!useConfigFile) {
184 cappedSTOconfig.cap = readlineSync.question('How many tokens do you plan to sell on the STO? (500.000): ');
185 if (cappedSTOconfig.cap == "") cappedSTOconfig.cap = 500000;
186
187 cappedSTOconfig.raiseType = readlineSync.question('Enter' + chalk.green(` P `) + 'for POLY raise or leave empty for Ether raise (E): ');
188 if (cappedSTOconfig.raiseType.toUpperCase() == 'P') {
189 cappedSTOconfig.raiseType = [gbl.constants.FUND_RAISE_TYPES.POLY];
190 } else {
191 cappedSTOconfig.raiseType = [gbl.constants.FUND_RAISE_TYPES.ETH];
192 }
193
194 cappedSTOconfig.rate = readlineSync.question(`Enter the rate (1 ${cappedSTOconfig.raiseType == gbl.constants.FUND_RAISE_TYPES.POLY ? 'POLY' : 'ETH'} = X ${tokenSymbol}) for the STO (1000): `);
195 if (cappedSTOconfig.rate == "") cappedSTOconfig.rate = 1000;
196
197 cappedSTOconfig.wallet = readlineSync.question('Enter the address that will receive the funds from the STO (' + Issuer.address + '): ');
198 if (cappedSTOconfig.wallet == "") cappedSTOconfig.wallet = Issuer.address;
199
200 cappedSTOconfig.startTime = readlineSync.question('Enter the start time for the STO (Unix Epoch time)\n(1 minutes from now = ' + oneMinuteFromNow + ' ): ');
201
202 cappedSTOconfig.endTime = readlineSync.question('Enter the end time for the STO (Unix Epoch time)\n(1 month from now = ' + oneMonthFromNow + ' ): ');
203 } else {
204 cappedSTOconfig = stoConfig;
205 }
206
207 if (cappedSTOconfig.startTime == "") cappedSTOconfig.startTime = oneMinuteFromNow;
208 if (cappedSTOconfig.endTime == "") cappedSTOconfig.endTime = oneMonthFromNow;
209

Callers 1

addSTOModuleFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected