increaseStake.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import WorkingGroupsCommandBase from '../../base/WorkingGroupsCommandBase'
  2. import { apiModuleByGroup } from '../../Api'
  3. import { Balance } from '@polkadot/types/interfaces'
  4. import { formatBalance } from '@polkadot/util'
  5. import { positiveInt } from '../../validators/common'
  6. import chalk from 'chalk'
  7. import ExitCodes from '../../ExitCodes'
  8. import { createParamOptions } from '../../helpers/promptOptions'
  9. export default class WorkingGroupsIncreaseStake extends WorkingGroupsCommandBase {
  10. static description = 'Increases current role (lead/worker) stake. Requires active role account to be selected.'
  11. static flags = {
  12. ...WorkingGroupsCommandBase.flags,
  13. }
  14. async run() {
  15. const account = await this.getRequiredSelectedAccount()
  16. // Worker-only gate
  17. const worker = await this.getRequiredWorker()
  18. if (!worker.stake) {
  19. this.error('Cannot increase stake. No associated role stake profile found!', { exit: ExitCodes.InvalidInput })
  20. }
  21. this.log(chalk.white('Current stake: ', formatBalance(worker.stake)))
  22. const balance = (await this.promptForParam(
  23. 'Balance',
  24. createParamOptions('amount', undefined, positiveInt())
  25. )) as Balance
  26. await this.requestAccountDecoding(account)
  27. await this.sendAndFollowNamedTx(account, apiModuleByGroup[this.group], 'increaseStake', [worker.workerId, balance])
  28. this.log(
  29. chalk.green(
  30. `Worker ${chalk.white(worker.workerId.toNumber())} stake has been increased by ${chalk.white(
  31. formatBalance(balance)
  32. )}`
  33. )
  34. )
  35. }
  36. }