Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

Refactor and fix issues in diamond deploy script #79

Merged
merged 33 commits into from
Jun 1, 2023

Conversation

0xNeshi
Copy link
Contributor

@0xNeshi 0xNeshi commented Jun 1, 2023

Ticket(s):

Explanation of the solution

See comments below.

Instructions on making this work

  • run yarn or yarn install to install npm dependencies
  • run yarn test to verify all tests still pass
  • run npx hardhat node
  • run npx hardhat Deploy:AccountsDiamond --network localhost
  • verify deployment is successful

@0xNeshi 0xNeshi added bug Something isn't working enhancement New feature or request labels Jun 1, 2023
@0xNeshi 0xNeshi self-assigned this Jun 1, 2023
package.json Outdated
"test": "hardhat test",
"compile": "hardhat compile && yarn format",
"compile": "hardhat compile",
"clean-compile": "set -x && mv ./tasks/index.ts ./tasks/temp_index.ts && touch ./tasks/index.ts && hardhat clean && hardhat compile && mv ./tasks/temp_index.ts ./tasks/index.ts && set +x",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set -x ... set +x will enable echoing currently running commands

package.json Outdated Show resolved Hide resolved
taskArgs.registrar,
taskArgs.corestruct,
taskArgs.stringlib,
addresses.multiSig.apTeam.proxy,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These addresses should be read from the local address file.

@0xNeshi 0xNeshi force-pushed the recompile-and-update-diamond-deploy branch from 6967491 to f716fe6 Compare June 1, 2023 08:44
@@ -45,7 +45,7 @@ export default async function createFacetCuts(
facetCuts.push({
facetName: facet.name,
cut: {
facetAddress: facet.contract.address,
facetAddress: ADDRESS_ZERO,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When removing selectors from diamond, facet address must be address(0)


export default async function verify(
facetCuts: FacetCut[],
hre: HardhatRuntimeEnvironment
): Promise<void> {
logger.out("Verifying newly deployed facets...");

for (const {facetName, cut} of facetCuts) {
const facetsToVerify = facetCuts.filter((cut) => cut.cut.action !== FacetCutAction.Remove);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now removed facets need not be verified

@@ -86,7 +86,6 @@ function createEmpty(): AddressObj {
diamondInitFacet: "",
diamondLoupeFacet: "",
ownershipFacet: "",
reentrancyGuardFacet: "",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This facet is inherited by other facets, not deployed separately

import {task} from "hardhat/config";
import {getAddresses, isLocalNetwork, logger} from "utils";

task("Deploy:AccountsDiamond", "It will deploy accounts diamond contracts").setAction(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a task naming convention of Deploy:[ContractName] is as clear as the previous Deploy:deploy[ContractName] convention, without the extra "deploy" in the name.

@stevieraykatz @SovereignAndrey additionally we could update all task names to remove redundant verbs and lower-case first letter:

  • Deploy:deploy[ContractName] -> deploy:[ContractName]
  • upgrade:upgrade[ContractName] -> upgrade:[ContractName]
  • manage:[operationName] can remain the same

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sgtm

async (_, hre) => {
try {
const addresses = await getAddresses(hre);
const verify_contracts = !isLocalNetwork(hre.network);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we would ever want to NOT verify contracts deployed on mainnet/testnet, would make sense to remove the verify task param from all scripts (e.g. deployEndowmentMultiSig)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also seems fine to change default to verify = true. it can add some non neglible time to deployments since it runs a compile/compile check. leaving it optional but turned on seems like the right way to go. tasks have an optional arg type that could be used here

@@ -7,7 +7,8 @@
"format": "prettier --write './**/*.{ts,tsx,js}' --write contracts/**/*.sol",
"test": "hardhat test",
"compile": "hardhat compile && yarn format",
"deploy": "hardhat compile && hardhat run ./scripts/deploy.ts",
"clean-compile": "set -x && mv ./tasks/index.ts ./tasks/temp_index.ts && touch ./tasks/index.ts && hardhat clean && yarn compile && mv ./tasks/temp_index.ts ./tasks/index.ts && set +x",
"deploy": "yarn compile && hardhat run ./scripts/deploy.ts",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just running hardhat compile results in unformatted typechain-types/* folder. Then again, it makes little sense to even format this folder as it's auto-generated (same goes for dist/* folder and any other non-source-code folder).

@@ -7,7 +7,8 @@
"format": "prettier --write './**/*.{ts,tsx,js}' --write contracts/**/*.sol",
"test": "hardhat test",
"compile": "hardhat compile && yarn format",
"deploy": "hardhat compile && hardhat run ./scripts/deploy.ts",
"clean-compile": "set -x && mv ./tasks/index.ts ./tasks/temp_index.ts && touch ./tasks/index.ts && hardhat clean && yarn compile && mv ./tasks/temp_index.ts ./tasks/index.ts && set +x",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added @SovereignAndrey 's script for clean compile.

set -x ... set +x will enable echoing the current command being run, which could be useful in such a long chain of commands.

@0xNeshi 0xNeshi changed the title Recompile and update diamond deploy Refactor and fix issues in diamond deploy script Jun 1, 2023
@SovereignAndrey SovereignAndrey merged commit 78d52a9 into master Jun 1, 2023
@SovereignAndrey SovereignAndrey deleted the recompile-and-update-diamond-deploy branch June 1, 2023 23:19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working enhancement New feature or request
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants