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

Function addDividendsModule

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

Source from the content-addressed store, hash-verified

585}
586
587async function addDividendsModule() {
588 let availableModules = await moduleRegistry.methods.getModulesByTypeAndToken(gbl.constants.MODULES_TYPES.DIVIDENDS, securityToken.options.address).call();
589 let options = await Promise.all(availableModules.map(async function (m) {
590 let moduleFactoryABI = abis.moduleFactory();
591 let moduleFactory = new web3.eth.Contract(moduleFactoryABI, m);
592 return web3.utils.hexToUtf8(await moduleFactory.methods.name().call());
593 }));
594
595 let index = readlineSync.keyInSelect(options, 'Which dividends module do you want to add? ', { cancel: 'Return' });
596 if (index != -1 && readlineSync.keyInYNStrict(`Are you sure you want to add ${options[index]} module? `)) {
597 let wallet = readlineSync.question('Enter the account address to receive reclaimed dividends and tax: ', {
598 limit: function (input) {
599 return web3.utils.isAddress(input);
600 },
601 limitMessage: "Must be a valid address",
602 });
603 let configureFunction = abis.erc20DividendCheckpoint().find(o => o.name === 'configure' && o.type === 'function');
604 let bytes = web3.eth.abi.encodeFunctionCall(configureFunction, [wallet]);
605
606 let selectedDividendFactoryAddress = await contracts.getModuleFactoryAddressByName(securityToken.options.address, gbl.constants.MODULES_TYPES.DIVIDENDS, options[index]);
607 let addModuleAction = securityToken.methods.addModule(selectedDividendFactoryAddress, bytes, 0, 0);
608 let receipt = await common.sendTransaction(addModuleAction);
609 let event = common.getEventFromLogs(securityToken._jsonInterface, receipt.logs, 'ModuleAdded');
610 console.log(chalk.green(`Module deployed at address: ${event._module} `));
611 }
612}
613
614// Helper functions
615async function getBalance(address, tokenAddress) {

Callers 1

executeAppFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected