-
Notifications
You must be signed in to change notification settings - Fork 133
/
Copy pathset_can_burn.ts
47 lines (41 loc) · 1.7 KB
/
set_can_burn.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
/**
* Set canBurn addresses script
* PRIVATE_KEY="private key" ts-node scripts/set_can_burn.ts "network" "path to file with separated by ','" "token controller address"
*/
import fs from 'fs'
import { providers, Wallet } from 'ethers'
import {
TokenController,
TokenController__factory,
TrueCurrency__factory,
} from 'contracts'
export const txnArgs = { gasLimit: 60_000, gasPrice: 90_000_000_000 }
export const setCanBurn = async (wallet: Wallet, controller: TokenController, accounts: string[]) => {
let nonce = await wallet.getTransactionCount()
const token = TrueCurrency__factory.connect(await controller.token(), wallet)
const pendingTransactions = []
for (const address of accounts) {
if (await token.canBurn(address) === true) {
console.log(`${address} canBurn is set to true, skipping`)
continue
}
pendingTransactions.push((await controller.setCanBurn(address, true, { ...txnArgs, nonce })).wait()
.then(() => console.log(`Done: ${address} can burn`))
.catch((err) => console.error(`Failed for ${address}`, err)),
)
nonce++
}
await Promise.all(pendingTransactions)
}
export const parseAccounts = (text: string): string[] =>
text
.split(',')
.filter((address) => address.length > 0)
.map((address) => address.trim())
if (require.main === module) {
const provider = new providers.InfuraProvider(process.argv[2], '81447a33c1cd4eb09efb1e8c388fb28e')
const wallet = new Wallet(process.env.PRIVATE_KEY, provider)
const controller = TokenController__factory.connect(process.argv[4], wallet)
const addresses = parseAccounts(fs.readFileSync(process.argv[3]).toString())
setCanBurn(wallet, controller, addresses).then(() => console.log('Done.'))
}