forked from aragonone/court-backend
-
Notifications
You must be signed in to change notification settings - Fork 2
/
mint.js
33 lines (27 loc) · 1.23 KB
/
mint.js
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
const logger = require('@1hive/celeste-backend-shared/helpers/logger')('mint')
const { bigExp } = require('@1hive/celeste-backend-shared/helpers/numbers')
const command = 'mint'
const describe = 'Mint tokens for a certain address'
const builder = {
token: { alias: 't', describe: 'Token symbol (ANJ or FEE)', type: 'string', demand: true },
amount: { alias: 'a', describe: 'Amount to mint (without decimals)', type: 'string', demand: true },
recipient: { alias: 'r', describe: 'Recipient address (will use default address if missing)', type: 'string' },
}
const handlerAsync = async (environment, { recipient, token: symbol, amount }) => {
const court = await environment.getCourt()
const to = recipient || await court.environment.getSender()
let token
if (symbol.toLowerCase() === 'anj') token = await court.anj()
if (symbol.toLowerCase() === 'fee') token = await court.feeToken()
if (!token) throw new Error(`Minting ${symbol} is not supported yet`)
logger.info(`Minting ${symbol} ${amount} to ${to}...`)
const decimals = await token.decimals()
await token.generateTokens(to, bigExp(amount, decimals))
logger.success(`Minted ${symbol} ${amount} to ${to}`)
}
module.exports = {
command,
describe,
builder,
handlerAsync
}