@@ -181,11 +181,14 @@ const getDeploymentBytecode = async options => {
181
181
return `${ bytecode } ${ constructorArgs . replace ( / ^ 0 x / i, '' ) } ` ;
182
182
} ;
183
183
184
- /**
185
- * Creates a new snapshot or reverts to the given one
186
- * Also sets ETH balance on the given signer address
187
- */
188
- async function tenderlySnapShot ( address , ethBalance = '100' ) {
184
+ async function main ( ) {
185
+ const opts = await parseArgs ( process . argv ) . catch ( err => {
186
+ console . error ( `Error: ${ err . message } ` ) ;
187
+ process . exit ( 1 ) ;
188
+ } ) ;
189
+
190
+ const signer = await getSigner ( opts , network . name ) ;
191
+
189
192
if ( network . name === 'tenderly' ) {
190
193
const { TENDERLY_SNAPSHOT_ID } = process . env ;
191
194
if ( TENDERLY_SNAPSHOT_ID ) {
@@ -196,19 +199,10 @@ async function tenderlySnapShot(address, ethBalance = '100') {
196
199
console . info ( `Snapshot ID: ${ snapshotId } ` ) ;
197
200
process . env . TENDERLY_SNAPSHOT_ID = snapshotId ;
198
201
}
199
- await ethers . provider . send ( 'tenderly_setBalance' , [ address , ethers . utils . hexValue ( parseEther ( ethBalance ) ) ] ) ;
202
+ await ethers . provider . send ( 'tenderly_setBalance' , [ signer . address , ethers . utils . hexValue ( parseEther ( '100' ) ) ] ) ;
200
203
}
201
- }
202
-
203
- async function main ( ) {
204
- const opts = await parseArgs ( process . argv ) . catch ( err => {
205
- console . error ( `Error: ${ err . message } ` ) ;
206
- process . exit ( 1 ) ;
207
- } ) ;
208
-
209
- const signer = await getSigner ( opts , network . name ) ;
210
204
211
- await tenderlySnapShot ( signer . address ) ;
205
+ // make sure the contracts are compiled and we're not deploying an outdated artifact
212
206
await run ( 'compile' ) ;
213
207
214
208
const deploymentBytecode = await getDeploymentBytecode ( opts ) . catch ( err => {
@@ -220,11 +214,13 @@ async function main() {
220
214
const bytecode = hexToBytes ( deploymentBytecode . replace ( / ^ 0 x / i, '' ) ) ;
221
215
const bytecodeHash = bytesToHex ( keccak256 ( bytecode ) ) ;
222
216
217
+ // assemble input
223
218
const saltHex = opts . salt . toString ( 16 ) . padStart ( 64 , '0' ) ;
224
219
const input = hexToBytes ( `ff${ factory } ${ saltHex } ${ bytecodeHash } ` ) ;
225
220
const create2Hash = keccak256 ( input ) ;
226
221
const address = '0x' + bytesToHex ( create2Hash . slice ( 32 - 20 ) ) ;
227
222
223
+ // check if the expected address is the same as resulting address
228
224
if ( address . toLowerCase ( ) !== opts . address . toLowerCase ( ) ) {
229
225
throw new Error ( `Expected address to be ${ opts . address } but got ${ address } ` ) ;
230
226
}
0 commit comments