| 585 | } |
| 586 | |
| 587 | async 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 |
| 615 | async function getBalance(address, tokenAddress) { |