1
1
'use strict' ;
2
2
3
3
const fs = require ( 'fs' ) ;
4
- const { gray, yellow, red, cyan } = require ( 'chalk' ) ;
5
- const Web3 = require ( 'web3' ) ;
6
- const w3utils = require ( 'web3-utils' ) ;
4
+ const { gray, yellow, red, cyan, green } = require ( 'chalk' ) ;
5
+ const ethers = require ( 'ethers' ) ;
7
6
8
7
const {
9
8
toBytes32,
9
+ getUsers,
10
10
constants : { CONFIG_FILENAME , DEPLOYMENT_FILENAME } ,
11
11
} = require ( '../../..' ) ;
12
12
@@ -18,9 +18,10 @@ const {
18
18
loadConnections,
19
19
confirmAction,
20
20
stringify,
21
- performTransactionalStepWeb3,
22
21
} = require ( '../util' ) ;
23
22
23
+ const { performTransactionalStep } = require ( '../command-utils/transact' ) ;
24
+
24
25
const DEFAULTS = {
25
26
network : 'kovan' ,
26
27
gasLimit : 3e5 ,
@@ -34,6 +35,8 @@ const removeSynths = async ({
34
35
gasLimit = DEFAULTS . gasLimit ,
35
36
synthsToRemove = [ ] ,
36
37
yes,
38
+ useFork,
39
+ dryRun = false ,
37
40
privateKey,
38
41
} ) => {
39
42
ensureNetwork ( network ) ;
@@ -74,19 +77,29 @@ const removeSynths = async ({
74
77
75
78
const { providerUrl, privateKey : envPrivateKey , etherscanLinkPrefix } = loadConnections ( {
76
79
network,
80
+ useFork,
77
81
} ) ;
78
82
79
83
// allow local deployments to use the private key passed as a CLI option
80
84
if ( network !== 'local' || ! privateKey ) {
81
85
privateKey = envPrivateKey ;
82
86
}
83
87
84
- const web3 = new Web3 ( new Web3 . providers . HttpProvider ( providerUrl ) ) ;
85
- web3 . eth . accounts . wallet . add ( privateKey ) ;
86
- const account = web3 . eth . accounts . wallet [ 0 ] . address ;
87
- console . log ( gray ( `Using account with public key ${ account } ` ) ) ;
88
+ const provider = new ethers . providers . JsonRpcProvider ( providerUrl ) ;
89
+ let wallet ;
90
+ if ( useFork ) {
91
+ const account = getUsers ( { network, user : 'owner' } ) . address ; // protocolDAO
92
+ wallet = provider . getSigner ( account ) ;
93
+ } else {
94
+ wallet = new ethers . Wallet ( privateKey , provider ) ;
95
+ }
96
+ if ( ! wallet . address ) wallet . address = wallet . _address ;
97
+
98
+ console . log ( gray ( `Using account with public key ${ wallet . address } ` ) ) ;
88
99
console . log ( gray ( `Using gas of ${ gasPrice } GWEI with a max of ${ gasLimit } ` ) ) ;
89
100
101
+ console . log ( gray ( 'Dry-run:' ) , dryRun ? green ( 'yes' ) : yellow ( 'no' ) ) ;
102
+
90
103
if ( ! yes ) {
91
104
try {
92
105
await confirmAction (
@@ -104,14 +117,16 @@ const removeSynths = async ({
104
117
}
105
118
}
106
119
107
- const Synthetix = new web3 . eth . Contract (
120
+ const Synthetix = new ethers . Contract (
121
+ deployment . targets [ 'Synthetix' ] . address ,
108
122
deployment . sources [ 'Synthetix' ] . abi ,
109
- deployment . targets [ 'Synthetix' ] . address
123
+ wallet
110
124
) ;
111
125
112
- const Issuer = new web3 . eth . Contract (
126
+ const Issuer = new ethers . Contract (
127
+ deployment . targets [ 'Issuer' ] . address ,
113
128
deployment . sources [ 'Issuer' ] . abi ,
114
- deployment . targets [ 'Issuer' ] . address
129
+ wallet
115
130
) ;
116
131
117
132
// deep clone these configurations so we can mutate and persist them
@@ -124,9 +139,9 @@ const removeSynths = async ({
124
139
`Synth${ currencyKey } `
125
140
] ;
126
141
const { abi : synthABI } = deployment . sources [ synthSource ] ;
127
- const Synth = new web3 . eth . Contract ( synthABI , synthAddress ) ;
142
+ const Synth = new ethers . Contract ( synthAddress , synthABI , wallet ) ;
128
143
129
- const currentSynthInSNX = await Synthetix . methods . synths ( toBytes32 ( currencyKey ) ) . call ( ) ;
144
+ const currentSynthInSNX = await Synthetix . synths ( toBytes32 ( currencyKey ) ) ;
130
145
131
146
if ( synthAddress !== currentSynthInSNX ) {
132
147
console . error (
@@ -141,7 +156,7 @@ const removeSynths = async ({
141
156
}
142
157
143
158
// now check total supply (is required in Synthetix.removeSynth)
144
- const totalSupply = w3utils . fromWei ( await Synth . methods . totalSupply ( ) . call ( ) ) ;
159
+ const totalSupply = ethers . utils . formatEther ( await Synth . totalSupply ( ) ) ;
145
160
if ( Number ( totalSupply ) > 0 ) {
146
161
console . error (
147
162
red (
@@ -155,32 +170,36 @@ const removeSynths = async ({
155
170
}
156
171
157
172
// perform transaction if owner of Synthetix or append to owner actions list
158
- await performTransactionalStepWeb3 ( {
159
- account,
160
- contract : 'Issuer' ,
161
- target : Issuer ,
162
- write : 'removeSynth' ,
163
- writeArg : toBytes32 ( currencyKey ) ,
164
- gasLimit,
165
- gasPrice,
166
- etherscanLinkPrefix,
167
- ownerActions,
168
- ownerActionsFile,
169
- encodeABI : network === 'mainnet' ,
170
- } ) ;
171
-
172
- // now update the config and deployment JSON files
173
- const contracts = [ 'Proxy' , 'TokenState' , 'Synth' ] . map ( name => `${ name } ${ currencyKey } ` ) ;
174
- for ( const contract of contracts ) {
175
- delete updatedConfig [ contract ] ;
176
- delete updatedDeployment . targets [ contract ] ;
173
+ if ( dryRun ) {
174
+ console . log ( green ( 'Would attempt to remove the synth:' , currencyKey ) ) ;
175
+ } else {
176
+ await performTransactionalStep ( {
177
+ account : wallet ,
178
+ contract : 'Issuer' ,
179
+ target : Issuer ,
180
+ write : 'removeSynth' ,
181
+ writeArg : toBytes32 ( currencyKey ) ,
182
+ gasLimit,
183
+ gasPrice,
184
+ etherscanLinkPrefix,
185
+ ownerActions,
186
+ ownerActionsFile,
187
+ encodeABI : network === 'mainnet' ,
188
+ } ) ;
189
+
190
+ // now update the config and deployment JSON files
191
+ const contracts = [ 'Proxy' , 'TokenState' , 'Synth' ] . map ( name => `${ name } ${ currencyKey } ` ) ;
192
+ for ( const contract of contracts ) {
193
+ delete updatedConfig [ contract ] ;
194
+ delete updatedDeployment . targets [ contract ] ;
195
+ }
196
+ fs . writeFileSync ( configFile , stringify ( updatedConfig ) ) ;
197
+ fs . writeFileSync ( deploymentFile , stringify ( updatedDeployment ) ) ;
198
+
199
+ // and update the synths.json file
200
+ updatedSynths = updatedSynths . filter ( ( { name } ) => name !== currencyKey ) ;
201
+ fs . writeFileSync ( synthsFile , stringify ( updatedSynths ) ) ;
177
202
}
178
- fs . writeFileSync ( configFile , stringify ( updatedConfig ) ) ;
179
- fs . writeFileSync ( deploymentFile , stringify ( updatedDeployment ) ) ;
180
-
181
- // and update the synths.json file
182
- updatedSynths = updatedSynths . filter ( ( { name } ) => name !== currencyKey ) ;
183
- fs . writeFileSync ( synthsFile , stringify ( updatedSynths ) ) ;
184
203
}
185
204
} ;
186
205
@@ -197,6 +216,13 @@ module.exports = {
197
216
. option ( '-g, --gas-price <value>' , 'Gas price in GWEI' , 1 )
198
217
. option ( '-l, --gas-limit <value>' , 'Gas limit' , 1e6 )
199
218
. option ( '-n, --network <value>' , 'The network to run off.' , x => x . toLowerCase ( ) , 'kovan' )
219
+ . option ( '-r, --dry-run' , 'Dry run - no changes transacted' )
220
+ . option (
221
+ '-k, --use-fork' ,
222
+ 'Perform the deployment on a forked chain running on localhost (see fork command).' ,
223
+ false
224
+ )
225
+ . option ( '-y, --yes' , 'Dont prompt, just reply yes.' )
200
226
. option (
201
227
'-s, --synths-to-remove <value>' ,
202
228
'The list of synths to remove' ,
0 commit comments