-
Notifications
You must be signed in to change notification settings - Fork 115
/
increaseStake.ts
49 lines (42 loc) · 1.4 KB
/
increaseStake.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import WorkingGroupsCommandBase from '../../base/WorkingGroupsCommandBase'
import { apiModuleByGroup } from '../../Api'
import { formatBalance } from '@polkadot/util'
import chalk from 'chalk'
import ExitCodes from '../../ExitCodes'
import { isValidBalance } from '../../helpers/validation'
export default class WorkingGroupsIncreaseStake extends WorkingGroupsCommandBase {
static description = 'Increases current role (lead/worker) stake. Requires active role account to be selected.'
static args = [
{
name: 'amount',
required: true,
description: 'Amount of JOY to increase the current stake by',
},
]
static flags = {
...WorkingGroupsCommandBase.flags,
}
async run(): Promise<void> {
// Worker-only gate
const worker = await this.getRequiredWorkerContext()
const {
args: { amount },
} = this.parse(WorkingGroupsIncreaseStake)
if (!isValidBalance(amount)) {
this.error('Invalid stake amount!', { exit: ExitCodes.InvalidInput })
}
await this.sendAndFollowNamedTx(
await this.getDecodedPair(worker.roleAccount.toString()),
apiModuleByGroup[this.group],
'increaseStake',
[worker.workerId, amount]
)
this.log(
chalk.green(
`Worker ${chalk.magentaBright(worker.workerId.toString())} stake has been increased by ${chalk.magentaBright(
formatBalance(amount)
)}`
)
)
}
}