Skip to content

Commit

Permalink
Refactor script
Browse files Browse the repository at this point in the history
  • Loading branch information
rmeissner committed Dec 26, 2021
1 parent cd2e3da commit 7059ee5
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 23 deletions.
12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,15 @@
"devDependencies": {
"@types/mocha": "^8.2.0",
"@types/node": "^14.14.21",
"solc": "0.5.8",
"hardhat": "^2.2.1",
"ts-node": "^9.1.1",
"typescript": "^4.1.3"
},
"dependencies": {
"@types/yargs": "^15.0.10",
"argv": "^0.0.2",
"axios": "^0.21.1",
"dotenv": "^8.0.0",
"ethers": "^5.1.4",
"yargs": "^16.1.1"
"hardhat": "^2.2.1",
"solc": "0.5.8",
"ts-node": "^9.1.1",
"typescript": "^4.1.3",
"yargs": "^17.3.1"
}
}
17 changes: 11 additions & 6 deletions scripts/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as path from 'path'
import { CompilerOutput, CompilerInput, compileStandardWrapper, CompilerOutputContract } from 'solc'
import { ethers } from 'ethers'
import dotenv from "dotenv";
import yargs from 'yargs/yargs';

dotenv.config()

Expand Down Expand Up @@ -64,13 +65,13 @@ async function writeBytecode(bytecode: string) {
await filesystem.writeFile(filePath, bytecode, { encoding: 'utf8', flag: 'w' })
}

async function writeFactoryDeployerTransaction(contract: CompilerOutputContract, chainId: number, overwriteGasPrice?: number) {
async function writeFactoryDeployerTransaction(contract: CompilerOutputContract, chainId: number, overwrites?: { gasPrice?: number, gasLimit?: number, nonce?: number}) {
const deploymentBytecode = contract.evm.bytecode.object

const nonce = 0
const gasPrice = overwriteGasPrice || 100*10**9
const nonce = overwrites?.nonce || 0
const gasPrice = overwrites?.gasPrice || 100*10**9
// actual gas costs last measure: 59159; we don't want to run too close though because gas costs can change in forks and we want our address to be retained
const gasLimit = 100000
const gasLimit = overwrites?.gasLimit || 100000
const value = 0
const data = arrayFromHexString(deploymentBytecode)

Expand Down Expand Up @@ -108,14 +109,18 @@ function arrayFromHexString(value: string): Uint8Array {
}

async function doStuff() {
const gasPrice = process.argv[3] ? parseInt(process.argv[3]) : undefined
const chainId: number = parseInt(process.argv[2])
const argv = yargs(process.argv.slice(3)).options({
"gasPrice": { type: "number" },
"gasLimit": { type: "number" },
"nonce": { type: "number" }
}).argv
const compilerOutput = await compileContracts()
const contract = compilerOutput.contracts['deterministic-deployment-proxy.yul']['Proxy']
await ensureDirectoryExists(path.join(__dirname, '..', 'artifacts'))
await ensureDirectoryExists(path.join(__dirname, '..', 'artifacts', `${chainId}`))
await writeBytecode(contract.evm.bytecode.object)
await writeFactoryDeployerTransaction(contract, chainId, gasPrice)
await writeFactoryDeployerTransaction(contract, chainId, argv)
}

doStuff().then(() => {
Expand Down
41 changes: 31 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,11 @@ ansi-regex@^5.0.0:
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.0.tgz#388539f55179bf39339c81af30a654d69f87cb75"
integrity sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==

ansi-regex@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304"
integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==

ansi-styles@^3.2.0, ansi-styles@^3.2.1:
version "3.2.1"
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d"
Expand Down Expand Up @@ -2664,6 +2669,15 @@ string-width@^4.1.0, string-width@^4.2.0:
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.0"

string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

string.prototype.trimend@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/string.prototype.trimend/-/string.prototype.trimend-1.0.4.tgz#e75ae90c2942c63504686c18b287b4a0b1a45f80"
Expand Down Expand Up @@ -2715,6 +2729,13 @@ strip-ansi@^6.0.0:
dependencies:
ansi-regex "^5.0.0"

strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-eof@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/strip-eof/-/strip-eof-1.0.0.tgz#bb43ff5598a6eb05d89b59fcd129c983313606bf"
Expand Down Expand Up @@ -2962,10 +2983,10 @@ [email protected], yargs-parser@^13.1.2:
camelcase "^5.0.0"
decamelize "^1.2.0"

yargs-parser@^20.2.2:
version "20.2.7"
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.7.tgz#61df85c113edfb5a7a4e36eb8aa60ef423cbc90a"
integrity sha512-FiNkvbeHzB/syOjIUxFDCnhSfzAL8R5vs40MgLFBorXACCOAEaWu0gRZl14vG8MR9AOJIZbmkjhusqBYZ3HTHw==
yargs-parser@^21.0.0:
version "21.0.0"
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-21.0.0.tgz#a485d3966be4317426dd56bdb6a30131b281dc55"
integrity sha512-z9kApYUOCwoeZ78rfRYYWdiU/iNL6mwwYlkkZfJoyMR1xps+NEBX5X7XmRpxkZHhXJ6+Ey00IwKxBBSW9FIjyA==

yargs-parser@^9.0.2:
version "9.0.2"
Expand Down Expand Up @@ -3017,18 +3038,18 @@ yargs@^11.0.0:
y18n "^3.2.1"
yargs-parser "^9.0.2"

yargs@^16.1.1:
version "16.2.0"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-16.2.0.tgz#1c82bf0f6b6a66eafce7ef30e376f49a12477f66"
integrity sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==
yargs@^17.3.1:
version "17.3.1"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.3.1.tgz#da56b28f32e2fd45aefb402ed9c26f42be4c07b9"
integrity sha512-WUANQeVgjLbNsEmGk20f+nlHgOqzRFpiGWVaBrYGYIGANIIu3lWjoyi0fNlFmJkvfhCZ6BXINe7/W2O2bV4iaA==
dependencies:
cliui "^7.0.2"
escalade "^3.1.1"
get-caller-file "^2.0.5"
require-directory "^2.1.1"
string-width "^4.2.0"
string-width "^4.2.3"
y18n "^5.0.5"
yargs-parser "^20.2.2"
yargs-parser "^21.0.0"

[email protected]:
version "3.1.1"
Expand Down

0 comments on commit 7059ee5

Please sign in to comment.