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

Function createDividends

CLI/commands/dividends_manager.js:376–458  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

374}
375
376async function createDividends() {
377 let dividendName = readlineSync.question(`Enter a name or title to indetify this dividend: `);
378 let dividendToken = gbl.constants.ADDRESS_ZERO;
379 let dividendSymbol = 'ETH';
380 let token;
381 if (dividendsType === 'ERC20') {
382 do {
383 dividendToken = readlineSync.question(`Enter the address of ERC20 token in which dividend will be denominated(POLY = ${polyToken.options.address}): `, {
384 limit: function (input) {
385 return web3.utils.isAddress(input);
386 },
387 limitMessage: "Must be a valid ERC20 address",
388 defaultInput: polyToken.options.address
389 });
390 token = new web3.eth.Contract(abis.erc20(), dividendToken);
391 try {
392 dividendSymbol = await token.methods.symbol().call();
393 } catch (err) {
394 console.log(chalk.red(`${dividendToken} is not a valid ERC20 token address!!`));
395 }
396 } while (dividendSymbol === 'ETH');
397 }
398 let dividendAmount = readlineSync.question(`How much ${dividendSymbol} would you like to distribute to token holders? `);
399
400 let dividendAmountBN = new web3.utils.BN(dividendAmount);
401 let issuerBalance = new web3.utils.BN(web3.utils.fromWei(await getBalance(Issuer.address, dividendToken)));
402 if (issuerBalance.lt(dividendAmountBN)) {
403 console.log(chalk.red(`You have ${issuerBalance} ${dividendSymbol}.You need ${dividendAmountBN.sub(issuerBalance)} ${dividendSymbol} more!`));
404 } else {
405 let checkpointId = await selectCheckpoint(true); // If there are no checkpoints, it must create a new one
406 let now = Math.floor(Date.now() / 1000);
407 let maturityTime = readlineSync.questionInt('Enter the dividend maturity time from which dividend can be paid (Unix Epoch time)\n(Now = ' + now + ' ): ', { defaultInput: now });
408 let defaultTime = now + gbl.constants.DURATION.minutes(10);
409 let expiryTime = readlineSync.questionInt('Enter the dividend expiry time (Unix Epoch time)\n(10 minutes from now = ' + defaultTime + ' ): ', { defaultInput: defaultTime });
410
411 let useDefaultExcluded = !readlineSync.keyInYNStrict(`Do you want to use data from 'dividends_exclusions_data.csv' for this dividend? If not, default exclusions will apply.`);
412
413 let createDividendAction;
414 if (dividendsType == 'ERC20') {
415 let approveAction = token.methods.approve(currentDividendsModule._address, web3.utils.toWei(dividendAmountBN));
416 await common.sendTransaction(approveAction);
417 if (checkpointId > 0) {
418 if (useDefaultExcluded) {
419 createDividendAction = currentDividendsModule.methods.createDividendWithCheckpoint(maturityTime, expiryTime, token.options.address, web3.utils.toWei(dividendAmountBN), checkpointId, web3.utils.toHex(dividendName));
420 } else {
421 let excluded = getExcludedFromDataFile();
422 createDividendAction = currentDividendsModule.methods.createDividendWithCheckpointAndExclusions(maturityTime, expiryTime, token.options.address, web3.utils.toWei(dividendAmountBN), checkpointId, excluded[0], web3.utils.toHex(dividendName));
423 }
424 } else {
425 if (useDefaultExcluded) {
426 createDividendAction = currentDividendsModule.methods.createDividend(maturityTime, expiryTime, token.options.address, web3.utils.toWei(dividendAmountBN), web3.utils.toHex(dividendName));
427 } else {
428 let excluded = getExcludedFromDataFile();
429 createDividendAction = currentDividendsModule.methods.createDividendWithExclusions(maturityTime, expiryTime, token.options.address, web3.utils.toWei(dividendAmountBN), excluded[0], web3.utils.toHex(dividendName));
430 }
431 }
432 let receipt = await common.sendTransaction(createDividendAction);
433 let event = common.getEventFromLogs(currentDividendsModule._jsonInterface, receipt.logs, 'ERC20DividendDeposited');

Callers 1

dividendsManagerFunction · 0.85

Calls 3

selectCheckpointFunction · 0.85
getExcludedFromDataFileFunction · 0.85
getBalanceFunction · 0.70

Tested by

no test coverage detected