Skip to content

Commit 2d07c10

Browse files
committed
refactor: code clean up
1 parent d646e84 commit 2d07c10

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

scripts/create2/deploy.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,14 @@ const getDeploymentBytecode = async options => {
181181
return `${bytecode}${constructorArgs.replace(/^0x/i, '')}`;
182182
};
183183

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+
189192
if (network.name === 'tenderly') {
190193
const { TENDERLY_SNAPSHOT_ID } = process.env;
191194
if (TENDERLY_SNAPSHOT_ID) {
@@ -196,19 +199,10 @@ async function tenderlySnapShot(address, ethBalance = '100') {
196199
console.info(`Snapshot ID: ${snapshotId}`);
197200
process.env.TENDERLY_SNAPSHOT_ID = snapshotId;
198201
}
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'))]);
200203
}
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);
210204

211-
await tenderlySnapShot(signer.address);
205+
// make sure the contracts are compiled and we're not deploying an outdated artifact
212206
await run('compile');
213207

214208
const deploymentBytecode = await getDeploymentBytecode(opts).catch(err => {
@@ -220,11 +214,13 @@ async function main() {
220214
const bytecode = hexToBytes(deploymentBytecode.replace(/^0x/i, ''));
221215
const bytecodeHash = bytesToHex(keccak256(bytecode));
222216

217+
// assemble input
223218
const saltHex = opts.salt.toString(16).padStart(64, '0');
224219
const input = hexToBytes(`ff${factory}${saltHex}${bytecodeHash}`);
225220
const create2Hash = keccak256(input);
226221
const address = '0x' + bytesToHex(create2Hash.slice(32 - 20));
227222

223+
// check if the expected address is the same as resulting address
228224
if (address.toLowerCase() !== opts.address.toLowerCase()) {
229225
throw new Error(`Expected address to be ${opts.address} but got ${address}`);
230226
}

0 commit comments

Comments
 (0)