-
Notifications
You must be signed in to change notification settings - Fork 12
/
celo.ts
48 lines (40 loc) · 1.67 KB
/
celo.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
import { Flags } from '@oclif/core'
import BigNumber from 'bignumber.js'
import { BaseCommand } from '../../base'
import { newCheckBuilder } from '../../utils/checks'
import { displaySendTx } from '../../utils/cli'
import { CustomFlags } from '../../utils/command'
export default class TransferCelo extends BaseCommand {
static description =
'Transfer CELO to a specified address. (Note: this is the equivalent of the old transfer:gold)'
static flags = {
...BaseCommand.flags,
from: CustomFlags.address({ required: true, description: 'Address of the sender' }),
to: CustomFlags.address({ required: true, description: 'Address of the receiver' }),
value: Flags.string({ required: true, description: 'Amount to transfer (in wei)' }),
comment: Flags.string({ description: 'Transfer comment' }),
}
static examples = [
'celo --from 0xa0Af2E71cECc248f4a7fD606F203467B500Dd53B --to 0x5409ed021d9299bf6814279a6a1411a7e866a631 --value 10000000000000000000',
]
async run() {
const kit = await this.getKit()
const res = await this.parse(TransferCelo)
const from: string = res.flags.from
const to: string = res.flags.to
const value = new BigNumber(res.flags.value)
kit.defaultAccount = from
const celoToken = await kit.contracts.getGoldToken()
await newCheckBuilder(this)
.isNotSanctioned(from)
.isNotSanctioned(to)
.hasEnoughCelo(from, value)
.runChecks()
await (res.flags.comment
? displaySendTx(
'transferWithComment',
celoToken.transferWithComment(to, value.toFixed(), res.flags.comment)
)
: displaySendTx('transfer', celoToken.transfer(to, value.toFixed())))
}
}