This repository has been archived by the owner on Mar 14, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
deployTokenHolder.js
136 lines (120 loc) · 4.36 KB
/
deployTokenHolder.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
'use strict';
/**
* @fileoverview Nodejs Program to deploy TokenHolder Contract.
* See perform method for sample code.
*
* Contract: https://github.com/OpenSTFoundation/openst-contracts/blob/v0.9.4/contracts/TokenHolder.sol
* @author kedar@ost.com (Kedar Chandrayan)
*/
const PerformerBase = require('./PerformerBase');
class Performer extends PerformerBase {
constructor(program) {
super(program);
let config = this.getSetupConfig();
let openST = this.openST;
//Set the deployer params.
this.deployParams = {
from: config.deployerAddress,
gasPrice: config.gasPrice,
gas: config.gas
};
this.eip20Address = program.eip20Address;
this.tokenRulesAddress = program.tokenRules;
this.requirement = program.requirement;
this.wallets = program.wallets;
this.validate();
this.log('EIP20 Address:', this.eip20Address);
this.log('TokenRules Address:', this.tokenRulesAddress);
this.log('requirement', this.requirement);
this.log('wallets', this.wallets.join(','));
}
perform() {
//1. Create a deployer.
let deployer = new this.openST.Deployer(this.deployParams);
//2. Deploy MockToken.
this.log('Deploying TokenHolder Contract');
deployer
.deployTokenHolder(this.eip20Address, this.tokenRulesAddress, this.wallets, this.requirement)
.then((receipt) => {
this.logReceipt(receipt);
if (receipt.status && receipt.contractAddress) {
this.exitWithoutError('TokenHolder Contract Address:', receipt.contractAddress);
} else {
this.exitWithError('Failed to deploy TokenHolder. See receipt for details.');
}
})
.catch((reason) => {
this.logError(reason);
this.exitWithError('Failed to deploy contract. See error for details.');
});
}
validate() {
let openST = this.openST;
let web3 = openST.web3();
let utils = web3.utils;
if (!utils.isAddress(this.eip20Address)) {
let error = 'Invalid EIP20 Contract Address. Please provide EIP20 contract address using -e or --eip20-address flag.';
this.exitWithError(error);
return;
}
if (!utils.isAddress(this.tokenRulesAddress)) {
let error = 'Invalid TokenRules Contract Address. Please provide TokenRules contract address using -t or --token-rules-address flag.';
this.exitWithError(error);
return;
}
let bnRequirement;
try {
bnRequirement = utils.toBN(this.requirement);
if (bnRequirement.isZero()) {
let err = new Error('Requirement can not be zero.');
throw err;
}
} catch (e) {
this.logError(e);
let error = 'Invlaid requirement. Please provide requirement using -r or --requirement flag';
this.exitWithError(error);
return;
}
let wallets = this.wallets || [],
len = wallets.length;
if (bnRequirement.cmp(utils.toBN(len)) > 0) {
let error = new Error(`Please provide atleast ${bnRequirement.toString(10)} wallet address(s) using -w or --wallets flag.`);
this.exitWithError(error);
return;
}
while (len--) {
let wAddress = wallets[len];
if (!utils.isAddress(wAddress)) {
let error = `Invlaid Wallet Address ${wAddress}. Please provide wallet addresses using -w or --wallets flag`;
this.exitWithError(error);
return;
}
}
}
}
function parseWalletList(val) {
let a = val.split(',');
for (let i = 0; i < a.length; i++) {
a[i] = a[i].trim();
}
return a;
}
const program = PerformerBase.getProgram();
program
.option('--eip20-address [eip20Address]', 'EIP20 Token contract address')
.option('--token-rules [tokenRules]', 'TokenRules contract address')
.option('--requirement [requirement]', 'Requirement for the multisig operations', parseInt)
.option('--wallets <items>', 'Comma-Separated (without space) List of wallet addresses', parseWalletList);
program.on('--help', function() {
console.log('');
console.log(' Example:');
console.log('');
console.log(
' node deployTokenHolder.js --eip20-address 0x7F8d92283Fa96f9F2FE1596e718584F8aCA70264 --token-rules 0xa502c51c8213A4e61Dc59dF914e252EB6354A8c0 --requirement 2 --wallets 0xbba2c47be3add4fd302d9a8122442ca9d65ad9a3,0x39e76d2c955462674cd2dab10dbf46135dd2af24'
);
console.log('');
console.log('');
});
program.parse(process.argv);
let performer = new Performer(program);
performer.perform();