Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deploy: Delta production deployment scripts #631

Merged
merged 14 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions doc/upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ After deployment, a file in the `deployments` directory containing the latest ad
Verify the contract code on arbiscan.io.

```
npx hardhat etherscan-verify --network arbitrumMainnet --license MIT --sleep
npx hardhat verify --network arbitrumMainnet DEPLOYED_CONTRACT_ADDRESS "Constructor argument 1" ...
```

The `etherscan-verify` task might return an error for certain contracts. If this happens, an alternative approach is to generate a single "flattened" (contains code from all files that the contract depends on) `.sol` file that can be manually submitted on arbiscan.io.
The `verify` task might return an error for certain contracts. If this happens, an alternative approach is to generate a single "flattened" (contains code from all files that the contract depends on) `.sol` file that can be manually submitted on arbiscan.io.

```
npx hardhat flatten contracts/bonding/BondingManager.sol > flattened.sol
```

You can use https://arbiscan.io/verifyContract to manually submit contract code for public verification.

- The compiler config (i.e. version, optimizer runs, etc.) can be found in `hardhat.config.ts` under `solidity.compilers`.
- The compiler config (i.e. version, optimizer runs, etc.) can be found in `hardhat.config.ts` under `solidity.compilers`.
- For Compiler Type, select "Solidity (Single File)".
- For Open Source License Type, select "MIT"

Expand All @@ -52,6 +52,16 @@ You can also use Tenderly to manually submit contract code for [private verifica

If you see an error related to multiple SPDX license identifiers, remove all SPDX license identifiers from `flattened.sol` except for a single one.

## Task

Alternatively, you can also run the `etherscan-verify-deployments` task from this repository available as a `yarn` script:
victorges marked this conversation as resolved.
Show resolved Hide resolved

```
yarn etherscan-verify --network arbitrumMainnet Contract1 Contract2 ...
```

Additionally, you can omit the contract names to verify all the contracts deployed on the specified network.

## View Contract Diff

Use the contract diff checker at https://arbiscan.io/contractdiffchecker to view the code diff between the current and new target implementation contracts in order to check that the verified code at address of the new target implementation contract contains the expected changes.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"deploy": "npx hardhat deploy --tags Contracts,Poll",
"deploy:poll": "npx hardhat deploy --tags Poll",
"deploy:contracts": "npx hardhat deploy --tags Contracts",
"etherscan-verify": "npx hardhat etherscan-verify-deployments",
"lint": "yarn eslint && yarn solhint",
"eslint:fix": "eslint . --ext .js,.ts --fix",
"eslint": "eslint . --ext .js,.ts",
Expand Down
95 changes: 95 additions & 0 deletions tasks/etherscan-verify-deployment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import {Address} from "hardhat-deploy/types"
import {Etherscan} from "@nomicfoundation/hardhat-verify/etherscan"
import {task} from "hardhat/config"
import https from "https"
import {HardhatRuntimeEnvironment} from "hardhat/types"

task(
"etherscan-verify-deployments",
"Verifies all contracts in the deployments folder"
)
.addVariadicPositionalParam("contracts", "List of contracts to verify")
.setAction(async (taskArgs, hre) => {
const etherscan = await etherscanClient(hre)
let deployments = Object.entries(await hre.deployments.all())

console.log(`Read ${deployments.length} deployments from environment`)

if (taskArgs.contracts?.length) {
deployments = deployments.filter(([name]) =>
taskArgs.contracts.includes(name)
)
const names = deployments.map(t => t[0]).join(", ")
console.log(
`Filtered to ${deployments.length} contracts (${names})`
)
}

for (const [name, deployment] of deployments) {
console.log() // newline

const address = deployment.address
const constructorArguments = deployment.args

console.log(
`Verifying ${name} at ${address} constructed with (${constructorArguments})`
)
await hre.run("verify:verify", {address, constructorArguments})

if (name.endsWith("Proxy") && name !== "ManagerProxy") {
const targetName = name.replace("Proxy", "Target")
const target = await hre.deployments.get(targetName)

console.log(
`Verifying as proxy to ${targetName} at ${target.address}`
)
await verifyProxyContract(etherscan, address, target.address)
}
}
})

async function etherscanClient({config, network}: HardhatRuntimeEnvironment) {
const apiKey = config.etherscan.apiKey
const chainConfig = await Etherscan.getCurrentChainConfig(
network.name,
network.provider,
[]
)
return Etherscan.fromChainConfig(apiKey, chainConfig)
}

function verifyProxyContract(
etherscan: Etherscan,
proxyAddress: Address,
targetAddress: Address
) {
const url = new URL(etherscan.apiUrl)
if (url.protocol !== "https:") {
throw new Error("Etherscan API URL must use HTTPS")
}

const options = {
hostname: url.hostname,
path:
url.pathname +
`?module=contract&action=verifyproxycontract&address=${proxyAddress}` +
`&expectedimplementation=${targetAddress}&apikey=${etherscan.apiKey}`,
method: "GET"
}

return new Promise<void>((resolve, reject) => {
const req = https.request(options, res => {
if (res.statusCode === 200) {
return resolve()
}

reject(
new Error(
`Failed to verify proxy contract: ${res.statusCode} ${res.statusMessage}`
)
)
})
req.on("error", reject)
req.end()
})
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"outDir": "dist",
"resolveJsonModule": true
},
"include": ["./scripts", "./test", "./deploy", "./utils"],
"include": ["./scripts", "./test", "./deploy", "./utils", "./tasks"],
"files": ["./hardhat.config.ts"]
}